From: Aron Roberts Date: Thu, 5 May 2011 23:51:51 +0000 (+0000) Subject: CSPACE-3865: Initial clone of Storage Location Authority service to create new Taxono... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=20985c3a88f9154f587be2636d6445c94cdd2ecc;p=tmp%2Fjakarta-migration.git CSPACE-3865: Initial clone of Storage Location Authority service to create new Taxonomy Authority service. Cloned mechanistically to this point; 3rdparty and jaxb modules build, but not client or service. --- diff --git a/services/taxonomy/3rdparty/build.xml b/services/taxonomy/3rdparty/build.xml new file mode 100644 index 000000000..69bb682cc --- /dev/null +++ b/services/taxonomy/3rdparty/build.xml @@ -0,0 +1,131 @@ + + + + taxonomy service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/build.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/build.xml new file mode 100644 index 000000000..cbab3fe50 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/build.xml @@ -0,0 +1,149 @@ + + + + taxonomy nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/pom.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/pom.xml new file mode 100644 index 000000000..96ce75032 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/pom.xml @@ -0,0 +1,37 @@ + + + org.collectionspace.services + org.collectionspace.services.taxonomy.3rdparty + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy.3rdparty.nuxeo + services.taxonomy.3rdparty.nuxeo + jar + + Taxonomy Nuxeo Document Type + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/META-INF/MANIFEST.MF b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..c2fc4ef13 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: NuxeoCS +Bundle-SymbolicName: org.collectionspace.taxonomy;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +Require-Bundle: org.nuxeo.runtime, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.core, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.platform.types.api, + org.nuxeo.ecm.platform.versioning.api, + org.nuxeo.ecm.platform.ui, + org.nuxeo.ecm.platform.forms.layout.client, + org.nuxeo.ecm.platform.ws, + org.collectionspace.collectionspace_core +Provide-Package: org.collectionspace.taxonomy +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/life-cycle-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..bff576881 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..8bbdd72b6 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,408 @@ + + + + + + ${bundle.fileName} + + + + + nuxeo.war + /nuxeo + + + + + + + + + + + + Seam Context Filter + /ws/FileManageWS + + + + Seam Context Filter + /DocumentManagerWS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{currentServerLocation.name}/#{currentTabAction.label} + + + + Create new document in #{currentDocument.name} + + + + Create new document in #{currentDocument.name} + + + + breadcrumb=command.user_dashboard + + + + breadcrumb=command.manageMembers + + + + breadcrumb=command.manageMembers + + + + breadcrumb=title.orgauthorities + + + + breadcrumb=command.advancedSearch + + + + + + en + en_GB + en_US + fr + de + es + it + ar + ru + ja + vn + + + messages + + + + config/addWorkspace.jpdl.xml + + + + + + generic_error_page + /generic_error_page.xhtml + + + + + generic_message_page + /generic_message_page.xhtml + + + + + home + /nxstartup.xhtml + + + + + user_login + /login.xhtml + + + + + user_logout + /logout.xhtml + + + + + view_servers + /view_servers.xhtml + + + + + + + view_domains + /view_domains.xhtml + + + + + select_document_type + /select_document_type.xhtml + + + + + create_document + /create_document.xhtml + + + + + edit_document + /edit_document.xhtml + + + + + view_documents + /view_documents.xhtml + + + + + create_file + /create_file.xhtml + + + + + create_workspace_wizard + /createWorkspaceWizard.xhtml + + + + + send_email + /document_email.xhtml + + + + + + view_workspaces + /view_workspaces.xhtml + + + + + + create_domain + /create_domain.xhtml + + + + + + edit_domain + /edit_domain.xhtml + + + + + + create_workspace + /create_workspace.xhtml + + + + + + edit_workspace + /edit_workspace.xhtml + + + + + + + members_management + /members_management.xhtml + + + + + view_users + /view_users.xhtml + + + + + view_many_users + /view_many_users.xhtml + + + + + edit_user + /edit_user.xhtml + + + + + edit_user_password + /edit_user_password.xhtml + + + + + view_user + /view_user.xhtml + + + + + create_user + /create_user.xhtml + + + + + view_groups + /view_groups.xhtml + + + + + view_group + /view_group.xhtml + + + + + edit_group + /edit_group.xhtml + + + + + create_group + /create_group.xhtml + + + + + view_orgauthorities + /view_orgauthorities.xhtml + + + + + view_orgauthority + /view_orgauthority.xhtml + + + + + + + search_form + /search/search_form.xhtml + + + + + search_results_nxql + /search/search_results_nxql.xhtml + + + + + search_results_advanced + + /search/search_results_advanced.xhtml + + + + + + search_results_simple + /search/search_results_simple.xhtml + + + + + + + clipboard + /incl/clipboard.xhtml + + + + + user_dashboard + /user_dashboard.xhtml + + + + + select_workspace_template + /select_workspace_template.xhtml + + + + + pdf_generation_error + /pdf_generation_error.xhtml + + + + + mass_edit + /massedit_documents.xhtml + + + + + mass_edit_confirm + /massedit_documents_preview.xhtml + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..2c6ca5c92 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,53 @@ + + + + + + + view_documents + + + heading + cstaxonomyauthority + + + + + + Taxonomyauthority + + + + + + Taxonomyauthority + + + + + + + + + view_documents + + + heading + taxonomy + + + + + + Taxonomy + + + + + + Taxonomy + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..1d4665ae6 --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + displayName + shortIdentifier + refName + vocabType + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + shortIdentifier + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + vocabType + + + dataInputText + + + + + + + + + + + + + inAuthority + shortIdentifier + refName + displayName + displayNameComputed + taxonFullName + taxonRank + + + + + + + true + + inAuthority + + + dataInputText + + + + + + + + true + + shortIdentifier + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + displayName + + + dataInputText + + + + + + + + + true + + displayNameComputed + + + dataInputText + + + + + + + + true + + taxonFullName + + + dataInputText + + + + + + + + true + + taxonRank + + + dataInputText + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/life-cycle-contrib.xml b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/life-cycle-contrib.xml new file mode 100644 index 000000000..1b202499a --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/OSGI-INF/life-cycle-contrib.xml @@ -0,0 +1,12 @@ + + + + + + default + default + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomy_common.xsd b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomy_common.xsd new file mode 100644 index 000000000..d4e124eda --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomy_common.xsd @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomyauthority_common.xsd b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomyauthority_common.xsd new file mode 100644 index 000000000..0a9b6fa9a --- /dev/null +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxonomyauthority_common.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/3rdparty/pom.xml b/services/taxonomy/3rdparty/pom.xml new file mode 100644 index 000000000..8d1bfcbf2 --- /dev/null +++ b/services/taxonomy/3rdparty/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services + org.collectionspace.services.taxonomy + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy.3rdparty + services.taxonomy.3rdparty + pom + + 3rd party build for taxonomy service + + + + nuxeo-platform-cs-taxonomy + + diff --git a/services/taxonomy/build.xml b/services/taxonomy/build.xml new file mode 100644 index 000000000..9c4b825bb --- /dev/null +++ b/services/taxonomy/build.xml @@ -0,0 +1,134 @@ + + + + Taxonomy Authority service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/client/pom.xml b/services/taxonomy/client/pom.xml new file mode 100644 index 000000000..f7980be08 --- /dev/null +++ b/services/taxonomy/client/pom.xml @@ -0,0 +1,91 @@ + + + + org.collectionspace.services + org.collectionspace.services.taxonomy + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy.client + services.taxonomy.client + + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.taxonomy.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.contact.client + ${project.version} + + + + org.testng + testng + 5.6 + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-taxonomy-client + + + + + 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 new file mode 100644 index 000000000..9dd8a311f --- /dev/null +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java @@ -0,0 +1,97 @@ +/** + * TaxonomyAuthorityClient.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision$ + * $LastChangedDate$ + * + * 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 © 2009 {Contributing Institution} + * + * 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 + */ +package org.collectionspace.services.client; + +import javax.ws.rs.PathParam; +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.TaxonomyCommonList; +import org.collectionspace.services.client.TaxonomyAuthorityProxy; + +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * The Class TaxonomyAuthorityClient. + */ +public class TaxonomyAuthorityClient extends AuthorityClientImpl { + public static final String SERVICE_NAME = "taxonomyauthorities"; + 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; + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "taxon"; + public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME; + // + // Payload Part/Schema part names + // + public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; + public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME + + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + public String getItemCommonPartName() { + return getCommonPartName(SERVICE_ITEM_NAME); + } + + @Override + public Class getProxyClass() { + return TaxonomyAuthorityProxy.class; + } + + /* + * Proxied service calls. + */ + + /** + * @return list + * @see org.collectionspace.services.client.TaxonomyAuthorityProxy#readList() + */ + public ClientResponse readList() { + return getProxy().readList(); + } +} 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 new file mode 100644 index 000000000..79588b838 --- /dev/null +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityProxy.java @@ -0,0 +1,312 @@ +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; + } + + /** + * @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.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/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java new file mode 100644 index 000000000..5190d9935 --- /dev/null +++ b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java @@ -0,0 +1,1467 @@ +/** + * 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.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.client.AuthorityClient; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.client.ContactClientUtils; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.client.TaxonomyAuthorityClient; +import org.collectionspace.services.client.TaxonomyAuthorityClientUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.taxonomy.TaxonomyauthoritiesCommon; +import org.collectionspace.services.taxonomy.TaxonomyauthoritiesCommonList; +import org.collectionspace.services.taxonomy.TaxonomyCommon; +import org.collectionspace.services.taxonomy.TaxonomyCommonList; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +/** + * TaxonomyAuthorityServiceTest, carries out tests against a + * deployed and running TaxonomyAuthority Service. + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class! + + /** The logger. */ + private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class); + + @Override + public String getServicePathComponent() { + return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return TaxonomyAuthorityClient.SERVICE_NAME; + } + + public String getItemServicePathComponent() { + return AuthorityClient.ITEMS; + } + + // Instance variables specific to this test. + +// /** The SERVICE path component. */ +// final String SERVICE_PATH_COMPONENT = "taxonomyauthorities"; +// +// /** The ITEM service path component. */ +// final String ITEM_SERVICE_PATH_COMPONENT = "items"; +// +// /** The CONTACT service path component. */ +// final String CONTACT_SERVICE_PATH_COMPONENT = "contacts"; + + final String TEST_NAME = "Shelf 1"; + final String TEST_SHORTID = "shelf1"; + final String TEST_CONDITION_NOTE = "Basically clean"; + final String TEST_CONDITION_NOTE_DATE = "June 11, 1979"; + final String TEST_SECURITY_NOTE = "Kind of safe"; + final String TEST_ACCESS_NOTE = "Only right-thinkers may see"; + final String TEST_ADDRESS = "123 Main Street, Anytown USA"; + // TODO Make loc type be a controlled vocab term. + final String TEST_LOCATION_TYPE = "Shelf"; + // TODO Make status type be a controlled vocab term. + final String TEST_STATUS = "Approved"; + + /** The known resource id. */ + private String knownResourceId = null; + private String knownResourceShortIdentifer = null; + private String knownResourceRefName = null; + private String knownTaxonomyTypeRefName = null; + private String knownItemResourceId = null; + private String knownItemResourceShortIdentifer = null; + private String knownContactResourceId = null; + + /** The n items to create in list. */ + private int nItemsToCreateInList = 3; + + /** The all resource ids created. */ + private List allResourceIdsCreated = new ArrayList(); + + /** The all item resource ids created. */ + private Map allItemResourceIdsCreated = + new HashMap(); + + protected void setKnownResource( String id, String shortIdentifer, + String refName ) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; + } + + protected void setKnownItemResource( String id, String shortIdentifer ) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() { + return new TaxonomyAuthorityClient(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + return response.getEntity(TaxonomyCommonList.class); + } + + @Override + protected PoxPayloadOut createInstance(String identifier) { + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + String shortId = identifier; + String displayName = "displayName-" + shortId; + String baseRefName = + TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null); + PoxPayloadOut multipart = + TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( + displayName, shortId, client.getCommonPartName()); + return multipart; + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"create"}) + public void create(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup, such as initializing the type of service request + // (e.g. CREATE, DELETE), its valid and expected status codes, and + // its associated HTTP method name (e.g. POST, DELETE). + setupCreate(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + String shortId = createIdentifier(); + String displayName = "displayName-" + shortId; + String baseRefName = + TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null); + + PoxPayloadOut multipart = + TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( + displayName, shortId, client.getCommonPartName()); + String newID = null; + ClientResponse res = client.create(multipart); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + newID = TaxonomyAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); + } + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + setKnownResource( newID, shortId, baseRefName ); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(newID); + } + + /** + * Creates the item. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"create"}) + public void createItem(String testName) { + if(logger.isDebugEnabled()){ + logger.debug(testBanner(testName, CLASS_NAME)); + } + setupCreate(); + createItemInAuthority(knownResourceId, knownResourceRefName); + } + + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param authRefName the auth ref name + * @return the string + */ + private String createItemInAuthority(String vcsid, String authRefName) { + + final String testName = "createItemInAuthority("+vcsid+","+authRefName+")"; + if(logger.isDebugEnabled()){ + logger.debug(testBanner(testName, CLASS_NAME)); + } + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + Map shelf1Map = new HashMap(); + // TODO Make loc type and status be controlled vocabs. + shelf1Map.put(TaxonomyJAXBSchema.NAME, TEST_NAME); + shelf1Map.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + shelf1Map.put(TaxonomyJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); + shelf1Map.put(TaxonomyJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); + shelf1Map.put(TaxonomyJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); + shelf1Map.put(TaxonomyJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE); + shelf1Map.put(TaxonomyJAXBSchema.ADDRESS, TEST_ADDRESS); + shelf1Map.put(TaxonomyJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + shelf1Map.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS); + + String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid, + authRefName, shelf1Map, client ); + + // Store the ID returned from the first item resource created + // for additional tests below. + if (knownItemResourceId == null){ + setKnownItemResource(newID, TEST_SHORTID); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownItemResourceId=" + newID); + } + } + + // Store the IDs from any item resources created + // by tests, along with the IDs of their parents, so these items + // can be deleted after all tests have been run. + allItemResourceIdsCreated.put(newID, vcsid); + + return newID; + } + + + + // Failure outcomes + + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + + // --------------------------------------------------------------- + // CRUD tests : CREATE LIST tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnGroups = {"create"}) + public void createList(String testName) throws Exception { + for (int i = 0; i < nItemsToCreateInList; i++) { + create(testName); + } + } + + /** + * Creates the item list. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createList"}) + public void createItemList(String testName) throws Exception { + // Add items to the initially-created, known parent record. + for (int j = 0; j < nItemsToCreateInList; j++) { + createItem(testName); + } + } + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) + public void read(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + String newID = null; + ClientResponse res = client.read(knownResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyauthoritiesCommon taxonomyAuthority = + (TaxonomyauthoritiesCommon) extractPart(input, + client.getCommonPartName(), TaxonomyauthoritiesCommon.class); + Assert.assertNotNull(taxonomyAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + /** + * Read by name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) + public void readByName(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME)); + } + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readByName(knownResourceShortIdentifer); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyauthoritiesCommon taxonomyAuthority = (TaxonomyauthoritiesCommon) extractPart(input, + client.getCommonPartName(), TaxonomyauthoritiesCommon.class); + Assert.assertNotNull(taxonomyAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + + /** + * Read item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) + public void readItem(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a taxonomy. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(taxonomy); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(taxonomy, TaxonomyCommon.class)); + } + Assert.assertEquals(taxonomy.getInAuthority(), knownResourceId); + } finally { + res.releaseConnection(); + } + + } + + /** + * Verify item display name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem", "updateItem"}) + public void verifyItemDisplayName(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdate(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether taxonomy has expected displayName. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(taxonomy); + String displayName = taxonomy.getDisplayName(); + // Make sure displayName matches computed form + String expectedDisplayName = + TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); + Assert.assertNotNull(displayName, expectedDisplayName); + + // Update the shortName and verify the computed name is updated. + taxonomy.setCsid(null); + taxonomy.setDisplayNameComputed(true); + taxonomy.setName("updated-" + TEST_NAME); + expectedDisplayName = + TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon updatedTaxonomy = + (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(updatedTaxonomy); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedTaxonomy.getName(), taxonomy.getName(), + "Updated ForeName in Taxonomy did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedTaxonomy.getDisplayName(), expectedDisplayName, + "Updated ForeName in Taxonomy not reflected in computed DisplayName."); + + // Now Update the displayName, not computed and verify the computed name is overriden. + taxonomy.setDisplayNameComputed(false); + expectedDisplayName = "TestName"; + taxonomy.setDisplayName(expectedDisplayName); + + // Submit the updated resource to the service and store the response. + output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + updatedTaxonomy = + (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(updatedTaxonomy); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedTaxonomy.isDisplayNameComputed(), false, + "Updated displayNameComputed in Taxonomy did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedTaxonomy.getDisplayName(), + expectedDisplayName, + "Updated DisplayName (not computed) in Taxonomy not stored."); + } finally { + res.releaseConnection(); + } + } + + /** + * Verify illegal item display name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"verifyItemDisplayName"}) + public void verifyIllegalItemDisplayName(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + // FIXME: create a setup configuration for this operation. + setupUpdateWithWrongXmlSchema(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + // Check whether Taxonomy has expected displayName. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(taxonomy); + // Try to Update with computed false and no displayName + taxonomy.setDisplayNameComputed(false); + taxonomy.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + + // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) + public void readNonExistent(String testName) { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.read(NON_EXISTENT_ID); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + /** + * Read item non existent. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"readItem"}) + public void readItemNonExistent(String testName) { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + + // --------------------------------------------------------------- + // CRUD tests : READ_LIST tests + // --------------------------------------------------------------- + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnGroups = {"createList", "read"}) + public void readList(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.readList(); + try { + TaxonomyauthoritiesCommonList list = res.getEntity(); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + List items = + list.getTaxonomyauthorityListItem(); + int i = 0; + for (TaxonomyauthoritiesCommonList.TaxonomyauthorityListItem item : items) { + String csid = item.getCsid(); + logger.debug(testName + ": list-item[" + i + "] csid=" + + csid); + logger.debug(testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + readItemList(csid, null); + i++; + } + } + } finally { + res.releaseConnection(); + } + } + + /** + * Read item list. + */ + @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) + public void readItemList() { + String testName = "readItemList"; + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + readItemList(knownResourceId, null); + } + + /** + * Read item list by authority name. + */ + @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) + public void readItemListByAuthorityName() { + String testName = "readItemListByAuthorityName"; + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + readItemList(null, knownResourceShortIdentifer); + } + + /** + * Read item list. + * + * @param vcsid the vcsid + * @param name the name + */ + private void readItemList(String vcsid, String shortId) { + + String testName = "readItemList"; + + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = null; + if(vcsid!= null) { + res = client.readItemList(vcsid, null, null); + } else if(shortId!= null) { + res = client.readItemListForNamedAuthority(shortId, null, null); + } else { + Assert.fail("readItemList passed null csid and name!"); + } + try { + TaxonomyCommonList list = res.getEntity(); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + List items = + list.getTaxonomyListItem(); + int nItemsReturned = items.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if(logger.isDebugEnabled()){ + logger.debug(testName + ": Expected " + + nExpectedItems +" items; got: "+nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + int i = 0; + for (TaxonomyCommonList.TaxonomyListItem item : items) { + Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); + Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); + // Optionally output additional data about list members for debugging. + boolean showDetails = true; + if (showDetails && logger.isDebugEnabled()) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(" " + testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(" " + testName + ": list-item[" + i + "] URI=" + + item.getUri()); + } + i++; + } + } finally { + res.releaseConnection(); + } + } + + + // Failure outcomes + // None at present. + + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnGroups = {"read", "readList"}) + public void update(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdate(); + + // Retrieve the contents of a resource to update. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.read(knownResourceId); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyauthoritiesCommon taxonomyAuthority = (TaxonomyauthoritiesCommon) extractPart(input, + client.getCommonPartName(), TaxonomyauthoritiesCommon.class); + Assert.assertNotNull(taxonomyAuthority); + + // Update the contents of this resource. + taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName()); + taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated TaxonomyAuthority"); + logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); + res.releaseConnection(); + res = client.update(knownResourceId, output); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + TaxonomyauthoritiesCommon updatedTaxonomyAuthority = + (TaxonomyauthoritiesCommon) extractPart(input, + client.getCommonPartName(), TaxonomyauthoritiesCommon.class); + Assert.assertNotNull(updatedTaxonomyAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(), + taxonomyAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } finally { + res.releaseConnection(); + } + } + + /** + * Update item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update"}) + public void updateItem(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdate(); + + // Retrieve the contents of a resource to update. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = + client.readItem(knownResourceId, knownItemResourceId); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Taxonomy to update with ID: " + + knownItemResourceId + + " in TaxonomyAuthority: " + knownResourceId ); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(taxonomy); + + // Update the contents of this resource. + taxonomy.setCsid(null); + taxonomy.setName("updated-" + taxonomy.getName()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Taxonomy"); + logger.debug(objectAsXmlString(taxonomy, + TaxonomyCommon.class)); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + TaxonomyCommon updatedTaxonomy = + (TaxonomyCommon) extractPart(input, + client.getItemCommonPartName(), TaxonomyCommon.class); + Assert.assertNotNull(updatedTaxonomy); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedTaxonomy.getName(), taxonomy.getName(), + "Data in updated Taxonomy did not match submitted data."); + } finally { + res.releaseConnection(); + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ +@Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID(s) used when creating the request payload may be arbitrary. + // The only relevant ID may be the one used in update(), below. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + String displayName = "displayName-NON_EXISTENT_ID"; + PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance( + displayName, "nonEx", client.getCommonPartName()); + ClientResponse res = + client.update(NON_EXISTENT_ID, multipart); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + /** + * Update non existent item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) + public void updateNonExistentItem(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + Map nonexMap = new HashMap(); + nonexMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME); + nonexMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, "nonEx"); + nonexMap.put(TaxonomyJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + nonexMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS); + PoxPayloadOut multipart = + TaxonomyAuthorityClientUtils.createTaxonomyInstance( + TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"), + nonexMap, client.getItemCommonPartName() ); + ClientResponse res = + client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + // Success outcomes + + // Note: delete sub-resources in ascending hierarchical order, + // before deleting their parents. + + /** + * Delete item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"}) + groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) + public void deleteItem(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupDelete(); + + if(logger.isDebugEnabled()){ + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId); + } + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = + client.deleteItem(knownResourceId, knownItemResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + public void delete(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupDelete(); + + if(logger.isDebugEnabled()){ + logger.debug("parentcsid =" + knownResourceId); + } + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.delete(knownResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.delete(NON_EXISTENT_ID); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + /** + * Delete non existent item. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + public void deleteNonExistentItem(String testName) { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + + // --------------------------------------------------------------- + // Utility tests : tests of code used in tests above + // --------------------------------------------------------------- + /** + * Tests the code for manually submitting data that is used by several + * of the methods above. + */ + @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(knownResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + + } + + /** + * Test item submit request. + */ + @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) + public void testItemSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getItemResourceURL(knownResourceId, knownItemResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + + } + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + + @AfterClass(alwaysRun=true) + public void cleanUp() { + String noTest = System.getProperty("noTestCleanup"); + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + String parentResourceId; + String itemResourceId; + // Clean up contact resources. + TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); + parentResourceId = knownResourceId; + // Clean up item resources. + for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + itemResourceId = entry.getKey(); + parentResourceId = entry.getValue(); + // Note: Any non-success responses from the delete operation + // below are ignored and not reported. + ClientResponse res = + client.deleteItem(parentResourceId, itemResourceId); + res.releaseConnection(); + } + // Clean up parent resources. + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses from the delete operation + // below are ignored and not reported. + ClientResponse res = client.delete(resourceId); + res.releaseConnection(); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ + + /** + * Returns the root URL for the item service. + * + * This URL consists of a base URL for all services, followed by + * a path component for the owning parent, followed by the + * path component for the items. + * + * @param parentResourceIdentifier An identifier (such as a UUID) for the + * parent authority resource of the relevant item resource. + * + * @return The root URL for the item service. + */ + protected String getItemServiceRootURL(String parentResourceIdentifier) { + return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent(); + } + + /** + * Returns the URL of a specific item resource managed by a service, and + * designated by an identifier (such as a universally unique ID, or UUID). + * + * @param parentResourceIdentifier An identifier (such as a UUID) for the + * parent authority resource of the relevant item resource. + * + * @param itemResourceIdentifier An identifier (such as a UUID) for an + * item resource. + * + * @return The URL of a specific item resource managed by a service. + */ + protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) { + return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; + } + + +} diff --git a/services/taxonomy/client/src/test/resources/log4j.properties b/services/taxonomy/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..148a3e865 --- /dev/null +++ b/services/taxonomy/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO diff --git a/services/taxonomy/jaxb/pom.xml b/services/taxonomy/jaxb/pom.xml new file mode 100644 index 000000000..4fdc1c124 --- /dev/null +++ b/services/taxonomy/jaxb/pom.xml @@ -0,0 +1,52 @@ + + + + org.collectionspace.services + org.collectionspace.services.taxonomy + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy.jaxb + services.taxonomy.jaxb + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + com.sun.xml.bind + jaxb-impl + + + org.jvnet.jaxb2-commons + property-listener-injector + + + org.jvnet.jaxb2_commons + runtime + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-taxonomy-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + 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 new file mode 100644 index 000000000..15fe3af5d --- /dev/null +++ b/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonomyJAXBSchema.java @@ -0,0 +1,16 @@ +/** + * + */ +package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; + +/** + * @author pschmitz + * + */ +public interface TaxonomyJAXBSchema extends AuthorityItemJAXBSchema { + final static String LOCATIONS_COMMON = "taxonomy_common"; + final static String FULL_NAME = "fullName"; + +} + diff --git a/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd b/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd new file mode 100644 index 000000000..51ad5e27a --- /dev/null +++ b/services/taxonomy/jaxb/src/main/resources/taxonomy_common.xsd @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/jaxb/src/main/resources/taxonomyauthority_common.xsd b/services/taxonomy/jaxb/src/main/resources/taxonomyauthority_common.xsd new file mode 100644 index 000000000..eedbdefb8 --- /dev/null +++ b/services/taxonomy/jaxb/src/main/resources/taxonomyauthority_common.xsd @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/taxonomy/pom.xml b/services/taxonomy/pom.xml new file mode 100644 index 000000000..22eed2ca8 --- /dev/null +++ b/services/taxonomy/pom.xml @@ -0,0 +1,32 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy + services.taxonomy + pom + + + + org.collectionspace.services + org.collectionspace.services.authority + true + ${project.version} + + + + + jaxb + service + 3rdparty + client + + + + diff --git a/services/taxonomy/service/pom.xml b/services/taxonomy/service/pom.xml new file mode 100644 index 000000000..f1fde402d --- /dev/null +++ b/services/taxonomy/service/pom.xml @@ -0,0 +1,145 @@ + + + + org.collectionspace.services + org.collectionspace.services.taxonomy + 1.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.taxonomy.service + services.taxonomy.service + jar + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.taxonomy.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.taxonomy.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.contact.service + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + commons-beanutils + commons-beanutils + 1.6.1 + + + + commons-logging + commons-logging + 1.1 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + + + jboss-remoting + jboss + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + + + collectionspace-services-taxonomy + + + + + diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java new file mode 100644 index 000000000..41291600f --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java @@ -0,0 +1,126 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy; + +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.client.TaxonomyAuthorityClient; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.MultipartServiceContextFactory; +import org.collectionspace.services.common.context.MultipartServiceContextImpl; +import org.collectionspace.services.common.context.ServiceBindingUtils; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.BadRequestException; +import org.collectionspace.services.common.document.DocumentException; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.repository.RepositoryClient; +import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.vocabulary.AuthorityResource; +import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; +import org.collectionspace.services.common.vocabulary.RefNameUtils; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.taxonomy.nuxeo.TaxonomyDocumentModelHandler; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class TaxonomyAuthorityResource. + */ +@Path(TaxonomyAuthorityClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") +public class TaxonomyAuthorityResource + extends AuthorityResource { + + private final static String taxonomyAuthorityServiceName = "taxonomyauthorities"; + private final static String LOCATIONAUTHORITIES_COMMON = "taxonomyauthority_common"; + + private final static String taxonomyServiceName = "taxonomy"; + private final static String LOCATIONS_COMMON = "taxonomy_common"; + + /** The logger. */ + final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityResource.class); + //FIXME retrieve client type from configuration + /** The Constant CLIENT_TYPE. */ + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + /** + * Instantiates a new taxonomy authority resource. + */ + public TaxonomyAuthorityResource() { + super(TaxonomyauthoritiesCommon.class, TaxonomyAuthorityResource.class, + LOCATIONAUTHORITIES_COMMON, LOCATIONS_COMMON); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() + */ + @Override + public String getServiceName() { + return taxonomyAuthorityServiceName; + } + + /** + * Gets the item service name. + * + * @return the item service name + */ + public String getItemServiceName() { + return taxonomyServiceName; + } + + @Override + public Class getCommonPartClass() { + return TaxonomyauthoritiesCommon.class; + } +} diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityConstants.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityConstants.java new file mode 100644 index 000000000..deb3896ee --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityConstants.java @@ -0,0 +1,35 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy.nuxeo; + +/** + * TaxonomyAuthorityConstants processes CollectionObject document + * + */ +public class TaxonomyAuthorityConstants { + + public final static String NUXEO_DOCTYPE = "TaxonomyAuthority"; + public final static String NUXEO_SCHEMA_NAME = "taxonomyauthority"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-TaxonomyAuthority"; +} diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityDocumentModelHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityDocumentModelHandler.java new file mode 100644 index 000000000..482b0251d --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyAuthorityDocumentModelHandler.java @@ -0,0 +1,106 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon; +import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList; +import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList.TaxonomyauthorityListItem; + +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TaxonomyAuthorityDocumentModelHandler + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class TaxonomyAuthorityDocumentModelHandler + extends AuthorityDocumentModelHandler { + + /** + * Common part schema label + */ + private static final String COMMON_PART_LABEL = "taxonomyauthority_common"; + + public TaxonomyAuthorityDocumentModelHandler() { + super(COMMON_PART_LABEL); + } + + @Override + public TaxonomyauthorityCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + TaxonomyauthorityCommonList coList = extractPagingInfo(new TaxonomyauthorityCommonList(), + wrapDoc); + AbstractCommonList commonList = (AbstractCommonList) coList; + commonList.setFieldsReturned("displayName|refName|shortIdentifier|vocabType|uri|csid"); + + //FIXME: iterating over a long list of documents is not a long term + //strategy...need to change to more efficient iterating in future + List list = coList.getTaxonomyauthorityListItem(); + String label = getServiceContext().getCommonPartLabel(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + TaxonomyauthorityListItem ilistItem = new TaxonomyauthorityListItem(); + ilistItem.setDisplayName((String) docModel.getProperty(label, + AuthorityJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(label, + AuthorityJAXBSchema.REF_NAME)); + ilistItem.setShortIdentifier((String) docModel.getProperty(label, + AuthorityJAXBSchema.SHORT_IDENTIFIER)); + ilistItem.setVocabType((String) docModel.getProperty(label, + AuthorityJAXBSchema.VOCAB_TYPE)); + String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri(getServiceContextPath() + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + + return coList; + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return TaxonomyAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java new file mode 100644 index 000000000..2274aa8e1 --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java @@ -0,0 +1,35 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy.nuxeo; + +/** + * TaxonomyConstants provides constants for Taxonomy documents + * + */ +public class TaxonomyConstants { + + public final static String NUXEO_DOCTYPE = "Taxonomy"; + public final static String NUXEO_SCHEMA_NAME = "taxonomy"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Taxonomy"; +} diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyDocumentModelHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyDocumentModelHandler.java new file mode 100644 index 000000000..d67d2f14d --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyDocumentModelHandler.java @@ -0,0 +1,184 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy.nuxeo; + +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.service.ObjectPartType; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.taxonomy.TaxonomyCommon; +import org.collectionspace.services.taxonomy.TaxonomyCommonList; +import org.collectionspace.services.taxonomy.TaxonomyCommonList.TaxonomyListItem; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TaxonomyDocumentModelHandler + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +/** + * @author pschmitz + * + */ +public class TaxonomyDocumentModelHandler + extends AuthorityItemDocumentModelHandler { + + /** The logger. */ + private final Logger logger = LoggerFactory.getLogger(TaxonomyDocumentModelHandler.class); + /** + * Common part schema label + */ + private static final String COMMON_PART_LABEL = "taxonomy_common"; + + public TaxonomyDocumentModelHandler() { + super(COMMON_PART_LABEL); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleDisplayNames(wrapDoc.getWrappedObject()); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + super.handleUpdate(wrapDoc); + handleDisplayNames(wrapDoc.getWrappedObject()); + } + + /** + * Handle display name. + * + * @param docModel the doc model + * @throws Exception the exception + */ + private void handleDisplayNames(DocumentModel docModel) throws Exception { + String commonPartLabel = getServiceContext().getCommonPartLabel("taxonomy"); + Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, + TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED); + Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, + TaxonomyJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED); + if(displayNameComputed==null) + displayNameComputed = true; + if(shortDisplayNameComputed==null) + shortDisplayNameComputed = true; + if (displayNameComputed || shortDisplayNameComputed) { + String displayName = prepareDefaultDisplayName( + (String)docModel.getProperty(commonPartLabel, TaxonomyJAXBSchema.NAME )); + if (displayNameComputed) { + docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.DISPLAY_NAME, + displayName); + } + if (shortDisplayNameComputed) { + docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.SHORT_DISPLAY_NAME, + displayName); + } + } + } + + /** + * Produces a default displayName from the basic name and dates fields. + * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which + * duplicates this logic, until we define a service-general utils package + * that is neither client nor service specific. + * @param foreName + * @param middleName + * @param surName + * @param birthDate + * @param deathDate + * @return + * @throws Exception + */ + private static String prepareDefaultDisplayName( + String name ) throws Exception { + StringBuilder newStr = new StringBuilder(); + newStr.append(name); + return newStr.toString(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public TaxonomyCommonList extractCommonPartList( + DocumentWrapper wrapDoc) throws Exception { + TaxonomyCommonList coList = extractPagingInfo(new TaxonomyCommonList(), wrapDoc); + AbstractCommonList commonList = (AbstractCommonList) coList; + commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid"); + List list = coList.getTaxonomyListItem(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + String commonPartLabel = getServiceContext().getCommonPartLabel( + "taxonomy"); + while (iter.hasNext()) { + DocumentModel docModel = iter.next(); + TaxonomyListItem ilistItem = new TaxonomyListItem(); + ilistItem.setDisplayName((String) docModel.getProperty( + commonPartLabel, AuthorityItemJAXBSchema.DISPLAY_NAME)); + ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.SHORT_IDENTIFIER)); + ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.REF_NAME)); + String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri("/taxonomyauthorities/" + inAuthority + "/items/" + + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + + return coList; + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return TaxonomyConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyValidatorHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyValidatorHandler.java new file mode 100644 index 000000000..f6c7355a7 --- /dev/null +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyValidatorHandler.java @@ -0,0 +1,77 @@ +/** + * 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 2009 University of California at Berkeley + + * 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.taxonomy.nuxeo; + +import org.collectionspace.services.taxonomy.TaxonomyCommon; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class TaxonomyValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(TaxonomyValidatorHandler.class); + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + if(logger.isDebugEnabled()) { + logger.debug("validate() action=" + action.name()); + } + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + TaxonomyCommon taxonomy = (TaxonomyCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + TaxonomyCommon.class); + String msg = ""; + boolean invalid = false; + if(!taxonomy.isDisplayNameComputed() && (taxonomy.getDisplayName()==null)) { + invalid = true; + msg += "displayName must be non-null if displayNameComputed is false!"; + } + /* + if(action.equals(Action.CREATE)) { + //create specific validation here + } else if(action.equals(Action.UPDATE)) { + //update specific validation here + } + */ + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +}