Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classes
.classpath
*.jar
.project
.settings
31 changes: 31 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<project default="jar">
<path id="java-api.classpath">
<pathelement location="classes"/>
<pathelement location="lib/ws-commons-util-1.0.2.jar"/>
<pathelement location="lib/xmlrpc-client-3.1.3.jar"/>
<pathelement location="lib/xmlrpc-common-3.1.3.jar"/>
<pathelement location="lib/ws-commons-java5-1.0.1.jar"/>
</path>
<target name="clean">
<delete dir="classes"/>
</target>

<target depends="clean" name="compile">
<mkdir dir="classes"/>
<javac srcdir="src" destdir="classes" executable=" /sw/os/swhouse/javajdk_1.4/bin/javac" compiler="javac1.4" source="1.4" target="1.4">
<classpath refid="java-api.classpath"/>
</javac>
</target>

<target depends="compile" name="jar">
<jar destfile="shotgun_client.jar">
<fileset dir="classes">
<include name="com/shotgunsoftware/*.class"/>
</fileset>
<manifest>
<attribute name="Built-By" value="${user.name}"/>
</manifest>
</jar>
</target>
</project>
102 changes: 102 additions & 0 deletions src/BatchExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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://shotgun-dev.fas.fa.disney.com/api3";
private static final String DEFAULT_SHOTGUN_KEY = "4b5a0063ed0bba6fea045b7eff7b77a9375353d5";
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());
}
}
}

54 changes: 54 additions & 0 deletions src/SchemaExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import com.shotgunsoftware.*;

class SchemaExample {
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://shotgun-dev.fas.fa.disney.com/api3";
private static final String DEFAULT_SHOTGUN_KEY = "4b5a0063ed0bba6fea045b7eff7b77a9375353d5";
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);

Map schema = s.schema_read();
System.out.println(schema);
Map fields = s.schema_field_read("Shot", null);
int i = 4;

for (Iterator it = fields.keySet().iterator(); it.hasNext(); ) {
String key = (String) it.next();
System.out.println("Key: " + key + " Value: " + fields.get(key));
}
String field_name = s.schema_field_create("Shot", "number", "schema_create_test", null);
System.out.println(field_name);
Map props = new HashMap();
props.put("name", "Test Number Field Renamed");
props.put("description","this is only a test");
boolean success = s.schema_field_update("Shot", field_name, props);
System.out.println(Boolean.toString(success));
success = s.schema_field_delete("Shot", field_name);
System.out.println(Boolean.toString(success));
// Map schema = s.schema_read();
} catch ( Exception e ) {
System.out.println(e.getMessage());
}
}
}

12 changes: 9 additions & 3 deletions src/UpdateExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ public static void main(String[] args) {

Map r = s.update(ur);
Object[] assets = (Object[])r.get("assets");
System.out.println(java.util.Arrays.toString(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");
System.out.println(java.util.Arrays.toString(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");
System.out.println(java.util.Arrays.toString(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.
Expand Down
69 changes: 69 additions & 0 deletions src/com/shotgunsoftware/BatchRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.shotgunsoftware;

import java.util.Map;
import java.util.HashMap;
import java.util.Set;

/**
* The specification for an Update request.
*
* @author Matt Daw
* @version 1.0
*/
public class BatchRequest {
String entityType;
Integer entityId;
Map data;
Set returnFields;
String requestType;

/**
* Sole Constructor
*
* @param entityType the type of entity to update
* @param entityId the id of entity to update
*/
public BatchRequest(String entityType) {
this.entityType = entityType;
this.entityId = null;
this.data = new HashMap();
this.requestType = null;
}

/**
* Specify entity values to create.
*
* @param data map of field name to field value
*/
public void create(Map data, Set returnFields) {
this.data = data;
this.requestType = "create";
this.returnFields = returnFields;
}

public void create(Map data) {
create(data, null);
}

/**
* Specify entity values to create.
*
* @param data map of field name to field value
*/
public void update(Integer entityId, Map data) {
this.entityId = entityId;
this.data = data;
this.requestType = "update";
}
/**
* Specify entity values to create.
*
* @param data map of field name to field value
*/
public void delete(Integer entityId) {
this.entityId = entityId;
this.requestType = "delete";

}

}
Loading