]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-644: Added skeleton of Sample build component for CollectionObject service.
authorAron Roberts <aron@socrates.berkeley.edu>
Wed, 2 Dec 2009 02:41:54 +0000 (02:41 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Wed, 2 Dec 2009 02:41:54 +0000 (02:41 +0000)
services/collectionobject/sample/pom.xml [new file with mode: 0644]
services/collectionobject/sample/sample/pom.xml [new file with mode: 0644]
services/collectionobject/sample/sample/src/main/java/org/collectionspace/services/collectionobject/client/sample/Sample.java [new file with mode: 0644]
services/collectionobject/sample/sample/src/main/resources/collectionspace-client.properties [new file with mode: 0644]
services/collectionobject/sample/sample/src/main/resources/log4j.xml [new file with mode: 0644]

diff --git a/services/collectionobject/sample/pom.xml b/services/collectionobject/sample/pom.xml
new file mode 100644 (file)
index 0000000..1c16455
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.collectionspace.services</groupId>
+    <artifactId>org.collectionspace.services.collectionobjects.client.samples</artifactId>
+    <packaging>pom</packaging>
+    <version>1.0</version>
+    <name>collectionobjects.client.samples</name>
+
+    <modules>
+        <module>sample</module>
+    </modules>
+</project>
+
diff --git a/services/collectionobject/sample/sample/pom.xml b/services/collectionobject/sample/sample/pom.xml
new file mode 100644 (file)
index 0000000..07fe21f
--- /dev/null
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.collectionspace.services</groupId>
+    <artifactId>org.collectionspace.services.collectionobject.client.sample</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0</version>
+    <name>collectionobject.client.sample</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.collectionobject.jaxb</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.client</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.collectionobject.client</artifactId>
+            <version>1.0</version>
+        </dependency>
+    </dependencies>
+    
+    <repositories>
+        <repository>
+            <id>libs-releases-local</id>
+            <name>libs-releases-local</name>
+            <url>http://source.collectionspace.org:8081/artifactory/libs-releases-local</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>            
+        </repository>
+        
+        <repository>
+            <id>libs-snapshots-local</id>
+            <name>libs-snapshots-local</name>
+            <url>http://source.collectionspace.org:8081/artifactory/libs-snapshots-local</url>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>            
+        </repository>
+        <repository>
+            <id>collectionspace-releases</id>
+            <name>collectionspace-releases</name>
+            <url>http://source.collectionspace.org:8081/artifactory/public-nuxeo</url>            
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>            
+        </repository>
+        <repository>
+            <id>collectionspace-snapshots</id>
+            <name>collectionspace-snapshots</name>
+            <url>http://source.collectionspace.org:8081/artifactory/public-snapshot-nuxeo</url>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+    </repositories>    
+    
+    <build>
+        <finalName>collectionobject-client-sample</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>attached</goal>
+                        </goals>
+                        <phase>package</phase>
+                        <configuration>
+                            <descriptorRefs>
+                                <descriptorRef>jar-with-dependencies</descriptorRef>
+                            </descriptorRefs>
+                            <archive>
+                                <manifest>
+                                    <mainClass>org.collectionspace.services.collectionobject.client.sample.Sample</mainClass>
+                                </manifest>
+                            </archive>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+
diff --git a/services/collectionobject/sample/sample/src/main/java/org/collectionspace/services/collectionobject/client/sample/Sample.java b/services/collectionobject/sample/sample/src/main/java/org/collectionspace/services/collectionobject/client/sample/Sample.java
new file mode 100644 (file)
index 0000000..8b1d0cc
--- /dev/null
@@ -0,0 +1,133 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright (c)) 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.collectionspace.services.collectionobject.client.sample;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+import org.apache.log4j.BasicConfigurator;
+import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.test.ServiceRequestType;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Sample, sample client code for creating and accessing 
+ * CollectionObject records.
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class Sample {
+    private static final Logger logger =
+        LoggerFactory.getLogger(Sample.class);
+
+    // Instance variables specific to this test.
+    private CollectionObjectClient client = new CollectionObjectClient();
+    final String SERVICE_PATH_COMPONENT = "collectionobjects";
+
+
+    // ---------------------------------------------------------------
+    // Create
+    // ---------------------------------------------------------------
+
+
+    // ---------------------------------------------------------------
+    // Read
+    // ---------------------------------------------------------------
+
+    // ---------------------------------------------------------------
+    // Delete
+    // ---------------------------------------------------------------
+
+    // ---------------------------------------------------------------
+    // Utility methods
+    // ---------------------------------------------------------------
+
+    private Object extractPart(MultipartInput input, String label,
+        Class clazz) throws Exception {
+        Object obj = null;
+        for(InputPart part : input.getParts()){
+            String partLabel = part.getHeaders().getFirst("label");
+            if(label.equalsIgnoreCase(partLabel)){
+                String partStr = part.getBodyAsString();
+                if(logger.isDebugEnabled()){
+                    logger.debug("extracted part str=\n" + partStr);
+                }
+                obj = part.getBody(clazz, null);
+                if(logger.isDebugEnabled()){
+                    logger.debug("extracted part obj=\n", obj, clazz);
+                }
+                break;
+            }
+        }
+        return obj;
+    }
+
+    /**
+     * Returns an error message indicating that the status code returned by a
+     * specific call to a service does not fall within a set of valid status
+     * codes for that service.
+     *
+     * @param serviceRequestType  A type of service request (e.g. CREATE, DELETE).
+     *
+     * @param statusCode  The invalid status code that was returned in the response,
+     *                    from submitting that type of request to the service.
+     *
+     * @return An error message.
+     */
+    protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
+        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
+                requestType.validStatusCodesAsString();
+    }
+
+    protected String extractId(ClientResponse<Response> res) {
+        MultivaluedMap<String, Object> mvm = res.getMetadata();
+        String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);
+        if(logger.isDebugEnabled()){
+               logger.info("extractId:uri=" + uri);
+        }
+        String[] segments = uri.split("/");
+        String id = segments[segments.length - 1];
+        if(logger.isDebugEnabled()){
+               logger.debug("id=" + id);
+        }
+        return id;
+    }
+    
+    public static void main(String[] args) {
+               
+    }
+
+}
diff --git a/services/collectionobject/sample/sample/src/main/resources/collectionspace-client.properties b/services/collectionobject/sample/sample/src/main/resources/collectionspace-client.properties
new file mode 100644 (file)
index 0000000..e4f17a8
--- /dev/null
@@ -0,0 +1,6 @@
+#url of the collectionspace server\r
+cspace.url=http://173.45.237.99:8180/cspace-services/\r
+cspace.ssl=false\r
+cspace.auth=false\r
+cspace.user=test\r
+cspace.password=test
\ No newline at end of file
diff --git a/services/collectionobject/sample/sample/src/main/resources/log4j.xml b/services/collectionobject/sample/sample/src/main/resources/log4j.xml
new file mode 100644 (file)
index 0000000..d2890cb
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+       <appender name="console" class="org.apache.log4j.ConsoleAppender">
+               <param name="Target" value="System.out" />
+               <layout class="org.apache.log4j.TTCCLayout">
+                       <param name="DateFormat" value="ISO8601" />
+               </layout>
+       </appender>
+
+       <logger name="org.apache.commons.httpclient" additivity="false">
+               <level value="warn" />
+               <appender-ref ref="console" />
+       </logger>
+
+       <logger name="httpclient.wire" additivity="false">
+               <level value="info" />
+               <appender-ref ref="console" />
+       </logger>
+
+<!--
+       <logger name="org.collectionspace.services.collectionobject.client.sample.Sample" additivity="false">
+               <level value="debug" />
+               <appender-ref ref="console" />
+       </logger>
+-->
+
+       <root>
+               <priority value="debug" />
+               <appender-ref ref="console" />
+       </root>
+
+</log4j:configuration>
+
+
+
+