From: Aron Roberts Date: Fri, 6 May 2011 00:43:53 +0000 (+0000) Subject: CSPACE-3865: Additional tweaks following clone of Storage Location to Taxonomy. Most... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=cff2729e596eeb26574c490f4ecd7868b7d4b515;p=tmp%2Fjakarta-migration.git CSPACE-3865: Additional tweaks following clone of Storage Location to Taxonomy. Most of client module builds, save for client test of service. --- diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java index 9dd8a311f..9a31bdcdc 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java @@ -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 { - public static final String SERVICE_NAME = "taxonomyauthorities"; +public class TaxonomyAuthorityClient extends AuthorityClientImpl { + 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 readList() { + public ClientResponse 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 index 000000000..b539b7e9f --- /dev/null +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java @@ -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 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 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 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 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 res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) 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(); + } + + + +} diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java index 79588b838..80fb93dd0 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java @@ -1,312 +1,67 @@ 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 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 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 { + + // List Taxonomyauthority + @GET + ClientResponse 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 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 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 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 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 res) { - MultivaluedMap mvm = res.getMetadata(); - String uri = (String) ((ArrayList) 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 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 readIncludeDeleted( + @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); + + @Override + @GET + @Produces({"application/xml"}) + ClientResponse keywordSearchIncludeDeleted( + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, + @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); } diff --git a/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java b/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java index 15fe3af5d..9f6129920 100644 --- a/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java +++ b/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java @@ -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"; } diff --git a/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd b/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd index 51ad5e27a..e9b27429b 100644 --- a/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd +++ b/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd @@ -14,7 +14,7 @@ - + @@ -75,7 +75,7 @@ - +