This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
BatchExample.java
102 lines (82 loc) · 3.7 KB
/
BatchExample.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import com.shotgunsoftware.*;
class BatchExample {
private static final String SHOTGUN_SERVER;
private static final String SCRIPT_KEY;
private static final String SCRIPT_NAME;
private static final String DEFAULT_SHOTGUN_SERVER = "http://my-example.shotgunstudio.com/api3";
private static final String DEFAULT_SHOTGUN_KEY = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
private static final String DEFAULT_SCRIPT_NAME = "testScript";
static {
SHOTGUN_SERVER = (System.getProperty("SHOTGUN_SERVER") != null) ? (String) System.getProperty("SHOTGUN_SERVER") : DEFAULT_SHOTGUN_SERVER;
SCRIPT_KEY = (System.getProperty("SCRIPT_KEY") != null) ? (String) System.getProperty("SCRIPT_KEY") : DEFAULT_SHOTGUN_KEY;
SCRIPT_NAME = (System.getProperty("SCRIPT_NAME") != null) ? (String) System.getProperty("SCRIPT_NAME") : DEFAULT_SCRIPT_NAME;
}
public static void main(String[] args) {
try {
URL u = new URL(SHOTGUN_SERVER);
Shotgun s = new Shotgun(u, SCRIPT_NAME, SCRIPT_KEY);
BatchRequest[] req = new BatchRequest[3];
HashMap asset = new HashMap();
asset.put("type", "Asset");
asset.put("id", new Integer(23182));
HashMap step = new HashMap();
step.put("type", "Step");
step.put("id", new Integer(10));
HashMap project = new HashMap();
project.put("type", "Project");
project.put("id", new Integer(77));
HashMap data = new HashMap();
data.put("content", "New Batch Test Tast1");
data.put("entity", asset);
data.put("sg_status_list", "pre");
data.put("step", step);
data.put("project", project);
req[0] = new BatchRequest("Task");
req[0].create(data);
req[0] = new BatchRequest("Task");
req[0].create(data);
data = new HashMap();
data.put("content", "New Batch Test Tast2");
data.put("entity", asset);
data.put("sg_status_list", "wrk");
data.put("step", step);
data.put("project", project);
req[1] = new BatchRequest("Task");
req[1].create(data);
data = new HashMap();
data.put("content", "New Batch Test Tast3");
data.put("entity", asset);
data.put("sg_status_list", "cmpt");
data.put("step", step);
data.put("project", project);
req[2] = new BatchRequest("Task");
req[2].create(data);
Object[] r = s.batch(req);
data = new HashMap();
data.put("sg_status_list", "omt");
for (int index = 0; index < r.length; index++) {
req[index] = new BatchRequest("Task");
req[index].update((Integer) ((Map) r[index]).get("id"), data);
}
r = s.batch(req);
for (int index = 0; index < r.length; index++) {
req[index] = new BatchRequest("Task");
req[index].delete((Integer) ((Map)r[index]).get("id"));
}
r = s.batch(req);
int i = 4;
// Object[] assets = (Object[])r.get("assets");
// for (int index = 0; index < assets.length; index++)
// System.out.print(assets[index].toString());
// System.out.println();
} catch ( Exception e ) {
System.out.println(e.getMessage());
}
}
}