forked from shotgunsoftware/java-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateExample.java
More file actions
77 lines (61 loc) · 2.94 KB
/
UpdateExample.java
File metadata and controls
77 lines (61 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import com.shotgunsoftware.*;
class UpdateExample {
public static void main(String[] args) {
try {
URL u = new URL("http://yourshotgunserver.com/api3/");
Shotgun s = new Shotgun(u, "kp_testing", "9e795d3df53d1aea43b61f7c4a8dfa93c29c4ead");
HashMap asset = new HashMap();
asset.put("type", "Asset");
asset.put("id", new Integer(638));
ArrayList l = new ArrayList();
l.add(asset);
HashMap data = new HashMap();
data.put("sg_status_list", "ip");
data.put("assets", l);
// Shot.assets is a multi-entity column so we have three options for the update: set/add/remove.
// For this example, let's add the asset. Note that if you don't pass a mode, the default is set,
// which will overwrite the existing values.
HashMap modes = new HashMap();
modes.put("assets", "add");
UpdateRequest ur = new UpdateRequest("Shot", new Integer(1520));
ur.setData(data);
ur.setMultiEntityUpdateModes(modes);
Map r = s.update(ur);
Object[] assets = (Object[])r.get("assets");
for (int index = 0; index < assets.length; index++)
System.out.print(assets[index].toString());
System.out.println();
// Now let's re-run the update in "remove" mode.
modes.put("assets", "remove");
r = s.update(ur);
assets = (Object[])r.get("assets");
for (int index = 0; index < assets.length; index++)
System.out.print(assets[index].toString());
System.out.println();
// Add it back in for the next step.
modes.put("assets", "add");
r = s.update(ur);
assets = (Object[])r.get("assets");
for (int index = 0; index < assets.length; index++)
System.out.print(assets[index].toString());
System.out.println();
// Now set a field on the connection between the Shot and Asset. To do this,
// we need to pass the desired asset to the request.
HashMap parents = new HashMap();
parents.put("assets.AssetShotConnection.sg_test_assetinshot_field", asset);
data = new HashMap();
data.put("assets.AssetShotConnection.sg_test_assetinshot_field", "test");
ur = new UpdateRequest("Shot", new Integer(1520));
ur.setData(data);
ur.setMultiEntityParents(parents);
r = s.update(ur);
System.out.println(r);
} catch ( Exception e ) {
System.out.println(e.getMessage());
}
}
}