From: Aron Roberts Date: Wed, 2 Dec 2009 02:41:54 +0000 (+0000) Subject: CSPACE-644: Added skeleton of Sample build component for CollectionObject service. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=aa3725aadb506901651e20a8a2eaaf5d9a36e99c;p=tmp%2Fjakarta-migration.git CSPACE-644: Added skeleton of Sample build component for CollectionObject service. --- diff --git a/services/collectionobject/sample/pom.xml b/services/collectionobject/sample/pom.xml new file mode 100644 index 000000000..1c16455e6 --- /dev/null +++ b/services/collectionobject/sample/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.collectionobjects.client.samples + pom + 1.0 + collectionobjects.client.samples + + + sample + + + diff --git a/services/collectionobject/sample/sample/pom.xml b/services/collectionobject/sample/sample/pom.xml new file mode 100644 index 000000000..07fe21f0a --- /dev/null +++ b/services/collectionobject/sample/sample/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.collectionobject.client.sample + jar + 1.0 + collectionobject.client.sample + + + + org.collectionspace.services + org.collectionspace.services.collectionobject.jaxb + 1.0 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + org.collectionspace.services + org.collectionspace.services.collectionobject.client + 1.0 + + + + + + libs-releases-local + libs-releases-local + http://source.collectionspace.org:8081/artifactory/libs-releases-local + + true + + + false + + + + + libs-snapshots-local + libs-snapshots-local + http://source.collectionspace.org:8081/artifactory/libs-snapshots-local + + false + + + true + + + + collectionspace-releases + collectionspace-releases + http://source.collectionspace.org:8081/artifactory/public-nuxeo + + true + + + false + + + + collectionspace-snapshots + collectionspace-snapshots + http://source.collectionspace.org:8081/artifactory/public-snapshot-nuxeo + + false + + + true + + + + + + collectionobject-client-sample + + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package + + + jar-with-dependencies + + + + org.collectionspace.services.collectionobject.client.sample.Sample + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + 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 index 000000000..8b1d0cc74 --- /dev/null +++ b/services/collectionobject/sample/sample/src/main/java/org/collectionspace/services/collectionobject/client/sample/Sample.java @@ -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 res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) 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 index 000000000..e4f17a8e4 --- /dev/null +++ b/services/collectionobject/sample/sample/src/main/resources/collectionspace-client.properties @@ -0,0 +1,6 @@ +#url of the collectionspace server +cspace.url=http://173.45.237.99:8180/cspace-services/ +cspace.ssl=false +cspace.auth=false +cspace.user=test +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 index 000000000..d2890cbe8 --- /dev/null +++ b/services/collectionobject/sample/sample/src/main/resources/log4j.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +