Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 33e3809

Browse files
committed
Merge pull request #2 from cmihaly/master
Incorporate batch API method
2 parents e7904ed + 0e05879 commit 33e3809

File tree

7 files changed

+412
-4
lines changed

7 files changed

+412
-4
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
classes
2+
.classpath
3+
*.jar
4+
.project
5+
.settings

build.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<project default="jar">
3+
<path id="java-api.classpath">
4+
<pathelement location="classes"/>
5+
<pathelement location="lib/ws-commons-util-1.0.2.jar"/>
6+
<pathelement location="lib/xmlrpc-client-3.1.3.jar"/>
7+
<pathelement location="lib/xmlrpc-common-3.1.3.jar"/>
8+
<pathelement location="lib/ws-commons-java5-1.0.1.jar"/>
9+
</path>
10+
<target name="clean">
11+
<delete dir="classes"/>
12+
</target>
13+
14+
<target depends="clean" name="compile">
15+
<mkdir dir="classes"/>
16+
<javac srcdir="src" destdir="classes" executable=" /sw/os/swhouse/javajdk_1.4/bin/javac" compiler="javac1.4" source="1.4" target="1.4">
17+
<classpath refid="java-api.classpath"/>
18+
</javac>
19+
</target>
20+
21+
<target depends="compile" name="jar">
22+
<jar destfile="shotgun_client.jar">
23+
<fileset dir="classes">
24+
<include name="com/shotgunsoftware/*.class"/>
25+
</fileset>
26+
<manifest>
27+
<attribute name="Built-By" value="${user.name}"/>
28+
</manifest>
29+
</jar>
30+
</target>
31+
</project>

src/BatchExample.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import java.net.URL;
2+
import java.util.ArrayList;
3+
import java.util.HashMap;
4+
import java.util.Iterator;
5+
import java.util.Map;
6+
import java.util.Properties;
7+
8+
import com.shotgunsoftware.*;
9+
10+
class BatchExample {
11+
private static final String SHOTGUN_SERVER;
12+
private static final String SCRIPT_KEY;
13+
private static final String SCRIPT_NAME;
14+
15+
private static final String DEFAULT_SHOTGUN_SERVER = "http://shotgun-dev.fas.fa.disney.com/api3";
16+
private static final String DEFAULT_SHOTGUN_KEY = "4b5a0063ed0bba6fea045b7eff7b77a9375353d5";
17+
private static final String DEFAULT_SCRIPT_NAME = "testScript";
18+
19+
static {
20+
SHOTGUN_SERVER = (System.getProperty("SHOTGUN_SERVER") != null) ? (String) System.getProperty("SHOTGUN_SERVER") : DEFAULT_SHOTGUN_SERVER;
21+
SCRIPT_KEY = (System.getProperty("SCRIPT_KEY") != null) ? (String) System.getProperty("SCRIPT_KEY") : DEFAULT_SHOTGUN_KEY;
22+
SCRIPT_NAME = (System.getProperty("SCRIPT_NAME") != null) ? (String) System.getProperty("SCRIPT_NAME") : DEFAULT_SCRIPT_NAME;
23+
}
24+
25+
26+
public static void main(String[] args) {
27+
try {
28+
URL u = new URL(SHOTGUN_SERVER);
29+
Shotgun s = new Shotgun(u, SCRIPT_NAME, SCRIPT_KEY);
30+
31+
BatchRequest[] req = new BatchRequest[3];
32+
33+
HashMap asset = new HashMap();
34+
asset.put("type", "Asset");
35+
asset.put("id", new Integer(23182));
36+
37+
HashMap step = new HashMap();
38+
step.put("type", "Step");
39+
step.put("id", new Integer(10));
40+
41+
HashMap project = new HashMap();
42+
project.put("type", "Project");
43+
project.put("id", new Integer(77));
44+
45+
HashMap data = new HashMap();
46+
data.put("content", "New Batch Test Tast1");
47+
data.put("entity", asset);
48+
data.put("sg_status_list", "pre");
49+
data.put("step", step);
50+
data.put("project", project);
51+
52+
req[0] = new BatchRequest("Task");
53+
req[0].create(data);
54+
req[0] = new BatchRequest("Task");
55+
req[0].create(data);
56+
57+
data = new HashMap();
58+
data.put("content", "New Batch Test Tast2");
59+
data.put("entity", asset);
60+
data.put("sg_status_list", "wrk");
61+
data.put("step", step);
62+
data.put("project", project);
63+
64+
req[1] = new BatchRequest("Task");
65+
req[1].create(data);
66+
67+
data = new HashMap();
68+
data.put("content", "New Batch Test Tast3");
69+
data.put("entity", asset);
70+
data.put("sg_status_list", "cmpt");
71+
data.put("step", step);
72+
data.put("project", project);
73+
74+
req[2] = new BatchRequest("Task");
75+
req[2].create(data);
76+
77+
Object[] r = s.batch(req);
78+
data = new HashMap();
79+
data.put("sg_status_list", "omt");
80+
for (int index = 0; index < r.length; index++) {
81+
req[index] = new BatchRequest("Task");
82+
req[index].update((Integer) ((Map) r[index]).get("id"), data);
83+
}
84+
r = s.batch(req);
85+
for (int index = 0; index < r.length; index++) {
86+
req[index] = new BatchRequest("Task");
87+
req[index].delete((Integer) ((Map)r[index]).get("id"));
88+
}
89+
r = s.batch(req);
90+
91+
int i = 4;
92+
93+
// Object[] assets = (Object[])r.get("assets");
94+
// for (int index = 0; index < assets.length; index++)
95+
// System.out.print(assets[index].toString());
96+
// System.out.println();
97+
} catch ( Exception e ) {
98+
System.out.println(e.getMessage());
99+
}
100+
}
101+
}
102+

src/SchemaExample.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.net.URL;
2+
import java.util.HashMap;
3+
import java.util.Iterator;
4+
import java.util.Map;
5+
import java.util.Properties;
6+
7+
import com.shotgunsoftware.*;
8+
9+
class SchemaExample {
10+
private static final String SHOTGUN_SERVER;
11+
private static final String SCRIPT_KEY;
12+
private static final String SCRIPT_NAME;
13+
14+
private static final String DEFAULT_SHOTGUN_SERVER = "http://shotgun-dev.fas.fa.disney.com/api3";
15+
private static final String DEFAULT_SHOTGUN_KEY = "4b5a0063ed0bba6fea045b7eff7b77a9375353d5";
16+
private static final String DEFAULT_SCRIPT_NAME = "testScript";
17+
18+
static {
19+
SHOTGUN_SERVER = (System.getProperty("SHOTGUN_SERVER") != null) ? (String) System.getProperty("SHOTGUN_SERVER") : DEFAULT_SHOTGUN_SERVER;
20+
SCRIPT_KEY = (System.getProperty("SCRIPT_KEY") != null) ? (String) System.getProperty("SCRIPT_KEY") : DEFAULT_SHOTGUN_KEY;
21+
SCRIPT_NAME = (System.getProperty("SCRIPT_NAME") != null) ? (String) System.getProperty("SCRIPT_NAME") : DEFAULT_SCRIPT_NAME;
22+
}
23+
24+
25+
public static void main(String[] args) {
26+
try {
27+
URL u = new URL(SHOTGUN_SERVER);
28+
Shotgun s = new Shotgun(u, SCRIPT_NAME, SCRIPT_KEY);
29+
30+
Map schema = s.schema_read();
31+
System.out.println(schema);
32+
Map fields = s.schema_field_read("Shot", null);
33+
int i = 4;
34+
35+
for (Iterator it = fields.keySet().iterator(); it.hasNext(); ) {
36+
String key = (String) it.next();
37+
System.out.println("Key: " + key + " Value: " + fields.get(key));
38+
}
39+
String field_name = s.schema_field_create("Shot", "number", "schema_create_test", null);
40+
System.out.println(field_name);
41+
Map props = new HashMap();
42+
props.put("name", "Test Number Field Renamed");
43+
props.put("description","this is only a test");
44+
boolean success = s.schema_field_update("Shot", field_name, props);
45+
System.out.println(Boolean.toString(success));
46+
success = s.schema_field_delete("Shot", field_name);
47+
System.out.println(Boolean.toString(success));
48+
// Map schema = s.schema_read();
49+
} catch ( Exception e ) {
50+
System.out.println(e.getMessage());
51+
}
52+
}
53+
}
54+

src/UpdateExample.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,27 @@ public static void main(String[] args) {
3333

3434
Map r = s.update(ur);
3535
Object[] assets = (Object[])r.get("assets");
36-
System.out.println(java.util.Arrays.toString(assets));
36+
for (int index = 0; index < assets.length; index++)
37+
System.out.print(assets[index].toString());
38+
System.out.println();
3739

3840
// Now let's re-run the update in "remove" mode.
3941
modes.put("assets", "remove");
4042

4143
r = s.update(ur);
4244
assets = (Object[])r.get("assets");
43-
System.out.println(java.util.Arrays.toString(assets));
45+
for (int index = 0; index < assets.length; index++)
46+
System.out.print(assets[index].toString());
47+
System.out.println();
4448

4549
// Add it back in for the next step.
4650
modes.put("assets", "add");
4751

4852
r = s.update(ur);
4953
assets = (Object[])r.get("assets");
50-
System.out.println(java.util.Arrays.toString(assets));
54+
for (int index = 0; index < assets.length; index++)
55+
System.out.print(assets[index].toString());
56+
System.out.println();
5157

5258
// Now set a field on the connection between the Shot and Asset. To do this,
5359
// we need to pass the desired asset to the request.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.shotgunsoftware;
2+
3+
import java.util.Map;
4+
import java.util.HashMap;
5+
import java.util.Set;
6+
7+
/**
8+
* The specification for an Update request.
9+
*
10+
* @author Matt Daw
11+
* @version 1.0
12+
*/
13+
public class BatchRequest {
14+
String entityType;
15+
Integer entityId;
16+
Map data;
17+
Set returnFields;
18+
String requestType;
19+
20+
/**
21+
* Sole Constructor
22+
*
23+
* @param entityType the type of entity to update
24+
* @param entityId the id of entity to update
25+
*/
26+
public BatchRequest(String entityType) {
27+
this.entityType = entityType;
28+
this.entityId = null;
29+
this.data = new HashMap();
30+
this.requestType = null;
31+
}
32+
33+
/**
34+
* Specify entity values to create.
35+
*
36+
* @param data map of field name to field value
37+
*/
38+
public void create(Map data, Set returnFields) {
39+
this.data = data;
40+
this.requestType = "create";
41+
this.returnFields = returnFields;
42+
}
43+
44+
public void create(Map data) {
45+
create(data, null);
46+
}
47+
48+
/**
49+
* Specify entity values to create.
50+
*
51+
* @param data map of field name to field value
52+
*/
53+
public void update(Integer entityId, Map data) {
54+
this.entityId = entityId;
55+
this.data = data;
56+
this.requestType = "update";
57+
}
58+
/**
59+
* Specify entity values to create.
60+
*
61+
* @param data map of field name to field value
62+
*/
63+
public void delete(Integer entityId) {
64+
this.entityId = entityId;
65+
this.requestType = "delete";
66+
67+
}
68+
69+
}

0 commit comments

Comments
 (0)