]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3865: Additional tweaks following clone of Storage Location to Taxonomy. Most...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 6 May 2011 00:43:53 +0000 (00:43 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 6 May 2011 00:43:53 +0000 (00:43 +0000)
services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java
services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java [new file with mode: 0644]
services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java
services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java
services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd

index 9dd8a311fd62700c0455604454ca2fbe0dfe526c..9a31bdcdc3637cbe8c0c5bd2eb2f85aea5f0fd61 100644 (file)
@@ -32,7 +32,7 @@ import javax.ws.rs.core.Response;
 //import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.contact.ContactsCommonList;
-import org.collectionspace.services.taxonomy.TaxonomyauthoritiesCommonList;
+import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList;
 import org.collectionspace.services.taxonomy.TaxonomyCommonList;
 import org.collectionspace.services.client.TaxonomyAuthorityProxy;
 
@@ -45,8 +45,8 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
 /**
  * The Class TaxonomyAuthorityClient.
  */
-public class TaxonomyAuthorityClient extends AuthorityClientImpl<TaxonomyauthoritiesCommonList, TaxonomyCommonList, TaxonomyAuthorityProxy> {
-       public static final String SERVICE_NAME = "taxonomyauthorities";
+public class TaxonomyAuthorityClient extends AuthorityClientImpl<TaxonomyauthorityCommonList, TaxonomyCommonList, TaxonomyAuthorityProxy> {
+       public static final String SERVICE_NAME = "Taxonomyauthority";
        public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;       
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
@@ -91,7 +91,7 @@ public class TaxonomyAuthorityClient extends AuthorityClientImpl<Taxonomyauthori
      * @return list
      * @see org.collectionspace.services.client.TaxonomyAuthorityProxy#readList()
      */
-    public ClientResponse<TaxonomyauthoritiesCommonList> readList() {
+    public ClientResponse<TaxonomyauthorityCommonList> readList() {
         return getProxy().readList();
     }
 }
diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java
new file mode 100644 (file)
index 0000000..b539b7e
--- /dev/null
@@ -0,0 +1,294 @@
+package org.collectionspace.services.client;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.io.FileUtils;
+import org.collectionspace.services.TaxonomyJAXBSchema;
+import org.collectionspace.services.client.test.ServiceRequestType;
+import org.collectionspace.services.taxonomy.TaxonomyCommon;
+import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
+import org.dom4j.DocumentException;
+import org.jboss.resteasy.client.ClientResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+
+public class TaxonomyAuthorityClientUtils {
+    private static final Logger logger =
+        LoggerFactory.getLogger(TaxonomyAuthorityClientUtils.class);
+
+    /**
+     * Creates a new Taxonomy Authority
+     * @param displayName      The displayName used in UI, etc.
+     * @param refName          The proper refName for this authority
+     * @param headerLabel      The common part label
+     * @return The PoxPayloadOut payload for the create call
+     */
+    public static PoxPayloadOut createTaxonomyauthorityInstance(
+               String displayName, String shortIdentifier, String headerLabel ) {
+        TaxonomyauthorityCommon Taxonomyauthority = new TaxonomyauthorityCommon();
+        Taxonomyauthority.setDisplayName(displayName);
+        Taxonomyauthority.setShortIdentifier(shortIdentifier);
+        String refName = createTaxonomyAuthRefName(shortIdentifier, displayName);
+        Taxonomyauthority.setRefName(refName);
+        Taxonomyauthority.setVocabType("Taxonomyauthority"); //FIXME: REM - Should this really be hard-coded?
+        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
+        PayloadOutputPart commonPart = multipart.addPart(Taxonomyauthority, MediaType.APPLICATION_XML_TYPE);
+        commonPart.setLabel(headerLabel);
+
+        if(logger.isDebugEnabled()){
+               logger.debug("to be created, Taxonomyauthority common ", 
+                                       Taxonomyauthority, TaxonomyauthorityCommon.class);
+        }
+
+        return multipart;
+    }
+
+    /**
+     * @param taxonomyRefName  The proper refName for this authority
+     * @param taxonomyInfo the properties for the new Taxonomy. Can pass in one condition
+     *                                                 note and date string.
+     * @param headerLabel      The common part label
+     * @return The PoxPayloadOut payload for the create call
+     */
+    public static PoxPayloadOut createTaxonomyInstance( 
+               String taxonomyAuthRefName, Map<String, String> taxonomyInfo, 
+                               String headerLabel){
+        TaxonomyCommon taxonomy = new TaxonomyCommon();
+       String shortId = taxonomyInfo.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER);
+       String displayName = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME);
+       taxonomy.setShortIdentifier(shortId);
+       String taxonomyRefName = createTaxonomyRefName(taxonomyAuthRefName, shortId, displayName);
+               taxonomy.setRefName(taxonomyRefName);
+               String value = null;
+       value = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
+       boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); 
+       taxonomy.setDisplayNameComputed(displayNameComputed);
+        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.FULL_NAME))!=null)
+               taxonomy.setTaxonFullName(value);
+        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.TAXON_RANK))!=null)
+               taxonomy.setTaxonRank(value);
+        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.TERM_STATUS))!=null)
+               taxonomy.setTermStatus(value);
+
+        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+        PayloadOutputPart commonPart = multipart.addPart(taxonomy,
+            MediaType.APPLICATION_XML_TYPE);
+        commonPart.setLabel(headerLabel);
+
+        if(logger.isDebugEnabled()){
+               logger.debug("to be created, taxonomy common ", taxonomy, TaxonomyCommon.class);
+        }
+
+        return multipart;
+    }
+    
+    /**
+     * @param vcsid CSID of the authority to create a new taxonomy in
+     * @param TaxonomyauthorityRefName The refName for the authority
+     * @param taxonomyMap the properties for the new Taxonomy
+     * @param client the service client
+     * @return the CSID of the new item
+     */
+    public static String createItemInAuthority(String vcsid, 
+               String TaxonomyauthorityRefName, Map<String,String> taxonomyMap,
+               TaxonomyAuthorityClient client ) {
+       // Expected status code: 201 Created
+       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+       // Type of service request being tested
+       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+       
+       String displayName = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME);
+       String displayNameComputedStr = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
+       boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true");
+       if( displayName == null ) {
+               if(!displayNameComputed) {
+                       throw new RuntimeException(
+                       "CreateItem: Must supply a displayName if displayNameComputed is set to false.");
+               }
+               displayName = 
+                       prepareDefaultDisplayName(
+                       taxonomyMap.get(TaxonomyJAXBSchema.FULL_NAME));
+       }
+       
+       if(logger.isDebugEnabled()){
+               logger.debug("Import: Create Item: \""+displayName
+                               +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName +"\"");
+       }
+       PoxPayloadOut multipart = 
+               createTaxonomyInstance( TaxonomyauthorityRefName,
+                       taxonomyMap, client.getItemCommonPartName() );
+       String newID = null;
+       ClientResponse<Response> res = client.createItem(vcsid, multipart);
+        try {
+               int statusCode = res.getStatus();
+       
+               if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+                       throw new RuntimeException("Could not create Item: \""
+                                       +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
+                                       +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName
+                                       +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+               }
+               if(statusCode != EXPECTED_STATUS_CODE) {
+                       throw new RuntimeException("Unexpected Status when creating Item: \""
+                                       +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
+                                       +"\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName +"\", Status:"+ statusCode);
+               }
+               newID = extractId(res);
+        } finally {
+               res.releaseConnection();
+        }
+
+       return newID;
+    }
+
+    public static PoxPayloadOut createTaxonomyInstance(
+               String commonPartXML, String headerLabel)  throws DocumentException {
+        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
+        PayloadOutputPart commonPart = multipart.addPart(commonPartXML,
+            MediaType.APPLICATION_XML_TYPE);
+        commonPart.setLabel(headerLabel);
+
+        if(logger.isDebugEnabled()){
+               logger.debug("to be created, taxonomy common ", commonPartXML);
+        }
+
+        return multipart;
+    }
+    
+    public static String createItemInAuthority(String vcsid,
+               String commonPartXML,
+               TaxonomyAuthorityClient client ) throws DocumentException {
+       // Expected status code: 201 Created
+       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+       // Type of service request being tested
+       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+       
+       PoxPayloadOut multipart = 
+               createTaxonomyInstance(commonPartXML, client.getItemCommonPartName());
+       String newID = null;
+       ClientResponse<Response> res = client.createItem(vcsid, multipart);
+        try {
+               int statusCode = res.getStatus();
+       
+               if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+                       throw new RuntimeException("Could not create Item: \""+commonPartXML
+                                       +"\" in Taxonomyauthority: \"" + vcsid
+                                       +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+               }
+               if(statusCode != EXPECTED_STATUS_CODE) {
+                       throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML
+                                       +"\" in Taxonomyauthority: \"" + vcsid +"\", Status:"+ statusCode);
+               }
+               newID = extractId(res);
+        } finally {
+               res.releaseConnection();
+        }
+
+       return newID;
+    }
+    
+    /**
+     * Creates the from xml file.
+     *
+     * @param fileName the file name
+     * @return new CSID as string
+     * @throws Exception the exception
+     */
+    private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName, 
+               TaxonomyAuthorityClient client) throws Exception {
+        byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName));
+        String commonPartXML = new String(b);
+       return createItemInAuthority(vcsid, commonPartXML, client );
+    }    
+
+    /**
+     * Creates the Taxonomyauthority ref name.
+     *
+     * @param shortId the Taxonomyauthority shortIdentifier
+     * @param displaySuffix displayName to be appended, if non-null
+     * @return the string
+     */
+    public static String createTaxonomyAuthRefName(String shortId, String displaySuffix) {
+       String refName = "urn:cspace:org.collectionspace.demo:taxonomyauthority:name("
+                       +shortId+")";
+               if(displaySuffix!=null&&!displaySuffix.isEmpty())
+                       refName += "'"+displaySuffix+"'";
+       return refName;
+    }
+
+    /**
+     * Creates the taxonomy ref name.
+     *
+     * @param taxonomyAuthRefName the Taxonomyauthority ref name
+     * @param shortId the taxonomy shortIdentifier
+     * @param displaySuffix displayName to be appended, if non-null
+     * @return the string
+     */
+    public static String createTaxonomyRefName(
+                                               String taxonomyAuthRefName, String shortId, String displaySuffix) {
+       String refName = taxonomyAuthRefName+":taxonomy:name("+shortId+")";
+               if(displaySuffix!=null&&!displaySuffix.isEmpty())
+                       refName += "'"+displaySuffix+"'";
+       return refName;
+    }
+
+    public static String extractId(ClientResponse<Response> res) {
+        MultivaluedMap<String, Object> mvm = res.getMetadata();
+        String uri = (String) ((ArrayList<Object>) mvm.get("Taxonomy")).get(0);
+        if(logger.isDebugEnabled()){
+               logger.debug("extractId:uri=" + uri);
+        }
+        String[] segments = uri.split("/");
+        String id = segments[segments.length - 1];
+        if(logger.isDebugEnabled()){
+               logger.debug("id=" + id);
+        }
+        return id;
+    }
+    
+    /**
+     * 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.
+     */
+    public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
+        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
+                requestType.validStatusCodesAsString();
+    }
+
+
+    
+    /**
+     * Produces a default displayName from the basic name and dates fields.
+     * @see TaxonomyDocumentModelHandler.prepareDefaultDisplayName() which
+     * duplicates this logic, until we define a service-general utils package
+     * that is neither client nor service specific.
+     * @param name     
+     * @return
+     */
+    public static String prepareDefaultDisplayName(
+               String name ) {
+       StringBuilder newStr = new StringBuilder();
+                       newStr.append(name);
+               return newStr.toString();
+    }
+    
+
+
+}
index 79588b8382f3bbe3dab9d82999b2a9df1565016a..80fb93dd0c76f48f1b6d747a0ac3e42fcfd7cc63 100644 (file)
 package org.collectionspace.services.client;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
-import org.apache.commons.io.FileUtils;
-import org.collectionspace.services.TaxonomyJAXBSchema;
-import org.collectionspace.services.client.test.ServiceRequestType;
-import org.collectionspace.services.taxonomy.TaxonomyCommon;
-import org.collectionspace.services.taxonomy.ConditionGroupList;
-import org.collectionspace.services.taxonomy.ConditionGroup;
-import org.collectionspace.services.taxonomy.TaxonomyauthoritiesCommon;
-import org.dom4j.DocumentException;
 import org.jboss.resteasy.client.ClientResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-
-public class TaxonomyAuthorityClientUtils {
-    private static final Logger logger =
-        LoggerFactory.getLogger(TaxonomyAuthorityClientUtils.class);
-
-    /**
-     * Creates a new Taxonomy Authority
-     * @param displayName      The displayName used in UI, etc.
-     * @param refName          The proper refName for this authority
-     * @param headerLabel      The common part label
-     * @return The PoxPayloadOut payload for the create call
-     */
-    public static PoxPayloadOut createTaxonomyAuthorityInstance(
-               String displayName, String shortIdentifier, String headerLabel ) {
-        TaxonomyauthoritiesCommon taxonomyAuthority = new TaxonomyauthoritiesCommon();
-        taxonomyAuthority.setDisplayName(displayName);
-        taxonomyAuthority.setShortIdentifier(shortIdentifier);
-        String refName = createTaxonomyAuthRefName(shortIdentifier, displayName);
-        taxonomyAuthority.setRefName(refName);
-        taxonomyAuthority.setVocabType("TaxonomyAuthority"); //FIXME: REM - Should this really be hard-coded?
-        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
-        PayloadOutputPart commonPart = multipart.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
-        commonPart.setLabel(headerLabel);
-
-        if(logger.isDebugEnabled()){
-               logger.debug("to be created, taxonomyAuthority common ", 
-                                       taxonomyAuthority, TaxonomyauthoritiesCommon.class);
-        }
-
-        return multipart;
-    }
-
-    /**
-     * @param taxonomyRefName  The proper refName for this authority
-     * @param taxonomyInfo the properties for the new Taxonomy. Can pass in one condition
-     *                                                 note and date string.
-     * @param headerLabel      The common part label
-     * @return The PoxPayloadOut payload for the create call
-     */
-    public static PoxPayloadOut createTaxonomyInstance( 
-               String taxonomyAuthRefName, Map<String, String> taxonomyInfo, 
-                               String headerLabel){
-        TaxonomyCommon taxonomy = new TaxonomyCommon();
-       String shortId = taxonomyInfo.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER);
-       String displayName = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME);
-       taxonomy.setShortIdentifier(shortId);
-       String taxonomyRefName = createTaxonomyRefName(taxonomyAuthRefName, shortId, displayName);
-               taxonomy.setRefName(taxonomyRefName);
-               String value = null;
-       value = taxonomyInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
-       boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); 
-       taxonomy.setDisplayNameComputed(displayNameComputed);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.NAME))!=null)
-               taxonomy.setName(value);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.CONDITION_NOTE))!=null) {
-            ConditionGroupList conditionGroupList = new ConditionGroupList();
-            List<ConditionGroup> conditionGroups = conditionGroupList.getConditionGroup();
-            ConditionGroup conditionGroup = new ConditionGroup();
-            conditionGroup.setConditionNote(value);
-            if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.CONDITION_NOTE_DATE))!=null)
-               conditionGroup.setConditionNoteDate(value);
-            conditionGroups.add(conditionGroup);
-            taxonomy.setConditionGroupList(conditionGroupList);
-        }
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.SECURITY_NOTE))!=null)
-               taxonomy.setSecurityNote(value);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.ACCESS_NOTE))!=null)
-               taxonomy.setAccessNote(value);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.LOCATION_TYPE))!=null)
-               taxonomy.setTaxonomyType(value);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.ADDRESS))!=null)
-               taxonomy.setAddress(value);
-        if((value = (String)taxonomyInfo.get(TaxonomyJAXBSchema.TERM_STATUS))!=null)
-               taxonomy.setTermStatus(value);
-
-        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
-        PayloadOutputPart commonPart = multipart.addPart(taxonomy,
-            MediaType.APPLICATION_XML_TYPE);
-        commonPart.setLabel(headerLabel);
-
-        if(logger.isDebugEnabled()){
-               logger.debug("to be created, taxonomy common ", taxonomy, TaxonomyCommon.class);
-        }
-
-        return multipart;
-    }
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import org.collectionspace.services.client.workflow.WorkflowClient;
+import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList;
+import org.collectionspace.services.taxonomy.TaxonomyCommonList;
+
+/**
+ * @version $Revision$
+ * ILT = Item list type
+ * LT = List type
+ */
+@Path(TaxonomyAuthorityClient.SERVICE_PATH + "/")
+@Produces("application/xml")
+@Consumes("application/xml")
+public interface TaxonomyAuthorityProxy extends AuthorityProxy<TaxonomyauthorityCommonList, TaxonomyCommonList> {
+
+    // List Taxonomyauthority
+    @GET
+    ClientResponse<TaxonomyauthorityCommonList> readList();
     
-    /**
-     * @param vcsid CSID of the authority to create a new taxonomy in
-     * @param taxonomyAuthorityRefName The refName for the authority
-     * @param taxonomyMap the properties for the new Taxonomy
-     * @param client the service client
-     * @return the CSID of the new item
+    /*
+     * List results that must be overridden for the RESTEasy proxy generation to work correctly.
      */
-    public static String createItemInAuthority(String vcsid, 
-               String taxonomyAuthorityRefName, Map<String,String> taxonomyMap,
-               TaxonomyAuthorityClient client ) {
-       // Expected status code: 201 Created
-       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
-       // Type of service request being tested
-       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-       
-       String displayName = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME);
-       String displayNameComputedStr = taxonomyMap.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
-       boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true");
-       if( displayName == null ) {
-               if(!displayNameComputed) {
-                       throw new RuntimeException(
-                       "CreateItem: Must supply a displayName if displayNameComputed is set to false.");
-               }
-               displayName = 
-                       prepareDefaultDisplayName(
-                       taxonomyMap.get(TaxonomyJAXBSchema.NAME));
-       }
-       
-       if(logger.isDebugEnabled()){
-               logger.debug("Import: Create Item: \""+displayName
-                               +"\" in taxonomyAuthority: \"" + taxonomyAuthorityRefName +"\"");
-       }
-       PoxPayloadOut multipart = 
-               createTaxonomyInstance( taxonomyAuthorityRefName,
-                       taxonomyMap, client.getItemCommonPartName() );
-       String newID = null;
-       ClientResponse<Response> res = client.createItem(vcsid, multipart);
-        try {
-               int statusCode = res.getStatus();
-       
-               if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
-                       throw new RuntimeException("Could not create Item: \""
-                                       +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
-                                       +"\" in taxonomyAuthority: \"" + taxonomyAuthorityRefName
-                                       +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-               }
-               if(statusCode != EXPECTED_STATUS_CODE) {
-                       throw new RuntimeException("Unexpected Status when creating Item: \""
-                                       +taxonomyMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER)
-                                       +"\" in taxonomyAuthority: \"" + taxonomyAuthorityRefName +"\", Status:"+ statusCode);
-               }
-               newID = extractId(res);
-        } finally {
-               res.releaseConnection();
-        }
-
-       return newID;
-    }
-
-    public static PoxPayloadOut createTaxonomyInstance(
-               String commonPartXML, String headerLabel)  throws DocumentException {
-        PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
-        PayloadOutputPart commonPart = multipart.addPart(commonPartXML,
-            MediaType.APPLICATION_XML_TYPE);
-        commonPart.setLabel(headerLabel);
-
-        if(logger.isDebugEnabled()){
-               logger.debug("to be created, taxonomy common ", commonPartXML);
-        }
-
-        return multipart;
-    }
     
-    public static String createItemInAuthority(String vcsid,
-               String commonPartXML,
-               TaxonomyAuthorityClient client ) throws DocumentException {
-       // Expected status code: 201 Created
-       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
-       // Type of service request being tested
-       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-       
-       PoxPayloadOut multipart = 
-               createTaxonomyInstance(commonPartXML, client.getItemCommonPartName());
-       String newID = null;
-       ClientResponse<Response> res = client.createItem(vcsid, multipart);
-        try {
-               int statusCode = res.getStatus();
-       
-               if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
-                       throw new RuntimeException("Could not create Item: \""+commonPartXML
-                                       +"\" in taxonomyAuthority: \"" + vcsid
-                                       +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-               }
-               if(statusCode != EXPECTED_STATUS_CODE) {
-                       throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML
-                                       +"\" in taxonomyAuthority: \"" + vcsid +"\", Status:"+ statusCode);
-               }
-               newID = extractId(res);
-        } finally {
-               res.releaseConnection();
-        }
-
-       return newID;
-    }
+    // List Items matching a partial term or keywords.
+    @Override
+       @GET
+    @Produces({"application/xml"})
+    @Path("/{csid}/items/")
+    ClientResponse<TaxonomyCommonList> readItemList(
+               @PathParam("csid") String vcsid,
+            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+            @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
+            @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);
     
-    /**
-     * Creates the from xml file.
-     *
-     * @param fileName the file name
-     * @return new CSID as string
-     * @throws Exception the exception
-     */
-    private String createItemInAuthorityFromXmlFile(String vcsid, String commonPartFileName, 
-               TaxonomyAuthorityClient client) throws Exception {
-        byte[] b = FileUtils.readFileToByteArray(new File(commonPartFileName));
-        String commonPartXML = new String(b);
-       return createItemInAuthority(vcsid, commonPartXML, client );
-    }    
-
-    /**
-     * Creates the taxonomyAuthority ref name.
-     *
-     * @param shortId the taxonomyAuthority shortIdentifier
-     * @param displaySuffix displayName to be appended, if non-null
-     * @return the string
-     */
-    public static String createTaxonomyAuthRefName(String shortId, String displaySuffix) {
-       String refName = "urn:cspace:org.collectionspace.demo:taxonomyauthority:name("
-                       +shortId+")";
-               if(displaySuffix!=null&&!displaySuffix.isEmpty())
-                       refName += "'"+displaySuffix+"'";
-       return refName;
-    }
-
-    /**
-     * Creates the taxonomy ref name.
-     *
-     * @param taxonomyAuthRefName the taxonomyAuthority ref name
-     * @param shortId the taxonomy shortIdentifier
-     * @param displaySuffix displayName to be appended, if non-null
-     * @return the string
-     */
-    public static String createTaxonomyRefName(
-                                               String taxonomyAuthRefName, String shortId, String displaySuffix) {
-       String refName = taxonomyAuthRefName+":taxonomy:name("+shortId+")";
-               if(displaySuffix!=null&&!displaySuffix.isEmpty())
-                       refName += "'"+displaySuffix+"'";
-       return refName;
-    }
-
-    public static String extractId(ClientResponse<Response> res) {
-        MultivaluedMap<String, Object> mvm = res.getMetadata();
-        String uri = (String) ((ArrayList<Object>) mvm.get("Taxonomy")).get(0);
-        if(logger.isDebugEnabled()){
-               logger.debug("extractId:uri=" + uri);
-        }
-        String[] segments = uri.split("/");
-        String id = segments[segments.length - 1];
-        if(logger.isDebugEnabled()){
-               logger.debug("id=" + id);
-        }
-        return id;
-    }
+    // List Items for a named authority matching a partial term or keywords.
+    @Override
+       @GET
+    @Produces({"application/xml"})
+    @Path("/urn:cspace:name({specifier})/items/")
+    ClientResponse<TaxonomyCommonList> readItemListForNamedAuthority(
+               @PathParam("specifier") String specifier,
+            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+            @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
+            @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);
     
-    /**
-     * 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.
-     */
-    public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
-        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +
-                requestType.validStatusCodesAsString();
-    }
-
-
-    
-    /**
-     * Produces a default displayName from the basic name and dates fields.
-     * @see TaxonomyDocumentModelHandler.prepareDefaultDisplayName() which
-     * duplicates this logic, until we define a service-general utils package
-     * that is neither client nor service specific.
-     * @param name     
-     * @return
-     */
-    public static String prepareDefaultDisplayName(
-               String name ) {
-       StringBuilder newStr = new StringBuilder();
-                       newStr.append(name);
-               return newStr.toString();
-    }
-    
-
-
+    @Override
+       @GET
+    @Produces({"application/xml"})
+    ClientResponse<TaxonomyauthorityCommonList> readIncludeDeleted(
+            @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);    
+    @Override
+    @GET
+    @Produces({"application/xml"})
+    ClientResponse<TaxonomyauthorityCommonList> keywordSearchIncludeDeleted(
+               @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
+            @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);   
 }
index 15fe3af5df087c053ee119027b233d288ba84c53..9f61299208d81fe88e0619cb483d0373411cc4ac 100644 (file)
@@ -9,8 +9,9 @@ import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
  *
  */
 public interface TaxonomyJAXBSchema extends AuthorityItemJAXBSchema {
-       final static String LOCATIONS_COMMON = "taxonomy_common";
+       final static String TAXONOMY_COMMON = "taxonomy_common";
        final static String FULL_NAME = "fullName";
+       final static String TAXON_RANK = "taxonRank";
 
 }
 
index 51ad5e27ad653025a8b204c29d3e41bd2f337318..e9b27429b047423c27c0dc919d97283c090249f3 100644 (file)
@@ -14,7 +14,7 @@
     <!-- See http://wiki.collectionspace.org/display/collectionspace/Taxonomy+Service+Home -->    
     
     <!-- Taxonomy -->
-    <xs:element name="taxonomies_common">
+    <xs:element name="taxonomy_common">
         <xs:complexType>
             <xs:sequence>
                 <!--  Common identifier -->
@@ -75,7 +75,7 @@
     </xs:complexType>
     
     <!-- Taxonomy instances, as in nuxeo repository -->
-    <xs:element name="taxonomies-common-list">
+    <xs:element name="taxonomy-common-list">
         <xs:complexType>
             <xs:complexContent>
                 <xs:extension base="abstractCommonListItem">