From: seb Date: Mon, 6 May 2013 08:35:19 +0000 (+0200) Subject: Citation Authority X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=065c1f35f7eca726472132606c28f7ba6a8f24b3;p=tmp%2Fjakarta-migration.git Citation Authority --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 9052aaa46..cc698ca19 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -234,6 +234,11 @@ org.collectionspace.services org.collectionspace.services.person.service + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.citation.service ${project.version} diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index ccea44fb7..04b42e33f 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -49,6 +49,7 @@ import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.vocabulary.VocabularyResource; import org.collectionspace.services.organization.OrgAuthorityResource; import org.collectionspace.services.person.PersonAuthorityResource; +import org.collectionspace.services.citation.CitationAuthorityResource; //import org.collectionspace.services.query.QueryResource; @@ -100,6 +101,7 @@ public class CollectionSpaceJaxRsApplication extends Application addResourceToMapAndSingletons(new VocabularyResource()); addResourceToMapAndSingletons(new PersonAuthorityResource()); + addResourceToMapAndSingletons(new CitationAuthorityResource()); addResourceToMapAndSingletons(new OrgAuthorityResource()); addResourceToMapAndSingletons(new LocationAuthorityResource()); addResourceToMapAndSingletons(new ConceptAuthorityResource()); diff --git a/services/citation/.classpath b/services/citation/.classpath new file mode 100644 index 000000000..d18316afc --- /dev/null +++ b/services/citation/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/services/citation/.project b/services/citation/.project new file mode 100644 index 000000000..0d6e32b7d --- /dev/null +++ b/services/citation/.project @@ -0,0 +1,29 @@ + + + org.collectionspace.services.citation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/citation/3rdparty/.classpath b/services/citation/3rdparty/.classpath new file mode 100644 index 000000000..d18316afc --- /dev/null +++ b/services/citation/3rdparty/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/services/citation/3rdparty/.project b/services/citation/3rdparty/.project new file mode 100644 index 000000000..6f2a74af4 --- /dev/null +++ b/services/citation/3rdparty/.project @@ -0,0 +1,29 @@ + + + org.collectionspace.services.citation.3rdparty + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/citation/3rdparty/build.xml b/services/citation/3rdparty/build.xml new file mode 100644 index 000000000..56bf81e21 --- /dev/null +++ b/services/citation/3rdparty/build.xml @@ -0,0 +1,135 @@ + + + + citation service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/build.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/build.xml new file mode 100644 index 000000000..ccba13ef9 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/build.xml @@ -0,0 +1,145 @@ + + + + citation nuxeo document type for smk tenant + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/pom.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/pom.xml new file mode 100644 index 000000000..76e08c3ff --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/pom.xml @@ -0,0 +1,57 @@ + + + org.collectionspace.services + org.collectionspace.services.citation.3rdparty + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.3rdparty.smk.nuxeo + services.citation.3rdparty.smk.nuxeo + jar + + Citation Nuxeo Document Type for smk tenant + + + + citations_smk + 5 + smk + + + + + + ../../../../3rdparty/nuxeo/nuxeo-doctype/src/main/resources + true + + + ../../../../3rdparty/nuxeo/nuxeo-doctype-custom/src/main/resources + true + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + target/classes/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/src/main/resources/schemas/citations_smk.xsd b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/src/main/resources/schemas/citations_smk.xsd new file mode 100644 index 000000000..5d173e6f0 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation-smk/src/main/resources/schemas/citations_smk.xsd @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/build.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/build.xml new file mode 100644 index 000000000..a6a31ecb7 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/build.xml @@ -0,0 +1,145 @@ + + + + citation nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/pom.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/pom.xml new file mode 100644 index 000000000..8768fce21 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/pom.xml @@ -0,0 +1,43 @@ + + + org.collectionspace.services + org.collectionspace.services.citation.3rdparty + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.3rdparty.nuxeo + services.citation.3rdparty.nuxeo + jar + + Citation Nuxeo Document Type + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/META-INF/MANIFEST.MF b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..9beebb68b --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/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.citation;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.citation +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/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..5d36ef005 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + citations_common:citationTermGroupList/0/termDisplayName + citations_common:refName + citations_common:shortIdentifier + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..270abbd5f --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,10 @@ + + + + + + ${bundle.fileName} + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..e853ae36c --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,55 @@ + + + + + + + view_documents + + + heading + collectionspace_core + cscitationauthority + + + + + + Citationauthority + + + + + + Citationauthority + + + + + + + + + view_documents + + + heading + collectionspace_core + citation + + + + + + Citation + + + + + + Citation + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..750ac9d0f --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + displayName + shortIdentifier + refName + vocabType + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + shortIdentifier + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + vocabType + + + dataInputText + + + + + + + + + + + + + displayName + shortIdentifier + refName + inAuthority + termStatus + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + shortIdentifier + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + inAuthority + + + dataInputText + + + + + + + + true + + termStatus + + + dataInputText + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/life-cycle-contrib.xml b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/life-cycle-contrib.xml new file mode 100644 index 000000000..f9a212a96 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/OSGI-INF/life-cycle-contrib.xml @@ -0,0 +1,12 @@ + + + + + + ${Lifecycle} + ${Lifecycle} + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citationauthorities_common.xsd b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citationauthorities_common.xsd new file mode 100644 index 000000000..3e72fafec --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citationauthorities_common.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citations_common.xsd b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citations_common.xsd new file mode 100644 index 000000000..476c312d9 --- /dev/null +++ b/services/citation/3rdparty/nuxeo-platform-cs-citation/src/main/resources/schemas/citations_common.xsd @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/3rdparty/pom.xml b/services/citation/3rdparty/pom.xml new file mode 100644 index 000000000..8210f5e70 --- /dev/null +++ b/services/citation/3rdparty/pom.xml @@ -0,0 +1,31 @@ + + + + org.collectionspace.services + org.collectionspace.services.citation + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.3rdparty + services.citation.3rdparty + pom + + 3rd party build for citation service + + + + citation + Citation + citations_common + Tenant + + + + nuxeo-platform-cs-citation + nuxeo-platform-cs-citation-smk + + diff --git a/services/citation/build.xml b/services/citation/build.xml new file mode 100644 index 000000000..c64e93901 --- /dev/null +++ b/services/citation/build.xml @@ -0,0 +1,132 @@ + + + + citation service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/client/pom.xml b/services/citation/client/pom.xml new file mode 100644 index 000000000..aa731d5e8 --- /dev/null +++ b/services/citation/client/pom.xml @@ -0,0 +1,97 @@ + + + + org.collectionspace.services + org.collectionspace.services.citation + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.client + services.citation.client + + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.authority.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.citation.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 + + + + 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-citation-client + + + + + diff --git a/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClient.java b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClient.java new file mode 100644 index 000000000..e1cb8a419 --- /dev/null +++ b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClient.java @@ -0,0 +1,79 @@ +/** + * CitationAuthorityClient.java + * + * 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, 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 + */ +package org.collectionspace.services.client; + +import org.collectionspace.services.citation.CitationsCommon; + +/** + * The Class CitationAuthorityClient. + */ +public class CitationAuthorityClient extends AuthorityWithContactsClientImpl { + + public static final String SERVICE_NAME = "citationauthorities"; + 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; + public static final String TERM_INFO_GROUP_XPATH_BASE = "citationTermGroupList"; + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "citations"; + 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_PAYLOAD_NAME); + } + + @Deprecated // Use getItemCommonPartName() instead + public String getCommonPartItemName() { + return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME); + } + + @Override + public Class getProxyClass() { + return CitationAuthorityProxy.class; + } + + @Override + public String getInAuthority(CitationsCommon item) { + return item.getInAuthority(); + } + + @Override + public void setInAuthority(CitationsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } +} diff --git a/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java new file mode 100644 index 000000000..c2eb57e8b --- /dev/null +++ b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java @@ -0,0 +1,420 @@ +/** + * CitationAuthorityClientUtils.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 java.util.*; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.CitationJAXBSchema; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.citation.CitationTermGroup; +import org.collectionspace.services.citation.CitationTermGroupList; +import org.collectionspace.services.citation.CitationsCommon; +import org.collectionspace.services.citation.CitationauthoritiesCommon; +import org.jboss.resteasy.client.ClientResponse; +//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.collectionspace.services.citation.StructuredDateGroup; + +/** + * The Class CitationAuthorityClientUtils. + */ +public class CitationAuthorityClientUtils { + + /** The Constant logger. */ + private static final Logger logger = + LoggerFactory.getLogger(CitationAuthorityClientUtils.class); + private static final ServiceRequestType READ_REQ = ServiceRequestType.READ; + + /** + * @param csid the id of the CitationAuthority + * @param client if null, creates a new client + * @return + */ + public static String getAuthorityRefName(String csid, CitationAuthorityClient client){ + if (client == null) { + client = new CitationAuthorityClient(); + } + ClientResponse res = client.read(csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + CitationauthoritiesCommon citationAuthority = + (CitationauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input, + client.getCommonPartName(), CitationauthoritiesCommon.class); + if(citationAuthority == null) { + throw new RuntimeException("Null citationAuthority returned from service."); + } + return citationAuthority.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + /** + * @param csid the id of the CitationAuthority + * @param client if null, creates a new client + * @return + */ + public static String getCitationRefName(String inAuthority, String csid, CitationAuthorityClient client){ + if ( client == null) { + client = new CitationAuthorityClient(); + } + ClientResponse res = client.readItem(inAuthority, csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + CitationsCommon citation = + (CitationsCommon) CollectionSpaceClientUtils.extractPart(input, + client.getItemCommonPartName(), CitationsCommon.class); + if (citation == null) { + throw new RuntimeException("Null citation returned from service."); + } + return citation.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + /** + * Creates the citation authority instance. + * + * @param displayName the display name + * @param shortIdentifier the short Id + * @param headerLabel the header label + * @return the multipart output + */ + public static PoxPayloadOut createCitationAuthorityInstance( + String displayName, String shortIdentifier, String headerLabel ) { + CitationauthoritiesCommon citationAuthority = new CitationauthoritiesCommon(); + citationAuthority.setDisplayName(displayName); + citationAuthority.setShortIdentifier(shortIdentifier); + //String refName = createCitationAuthRefName(shortIdentifier, displayName); + //citationAuthority.setRefName(refName); + citationAuthority.setVocabType("CitationAuthority"); + PoxPayloadOut multipart = new PoxPayloadOut(CitationAuthorityClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(citationAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, citationAuthority common ", + citationAuthority, CitationauthoritiesCommon.class); + } + + return multipart; + } + + /** + * Creates a citation instance. + * + * @param inAuthority the owning authority + * @param citationAuthRefName the owning Authority ref name + * @param citationInfo the citation info + * @param headerLabel the header label + * @return the multipart output + */ + public static PoxPayloadOut createCitationInstance(String inAuthority, + String citationAuthRefName, + Map citationInfo, + List terms, + String headerLabel){ + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } + final Map> EMPTY_CITATION_REPEATABLES_INFO = + new HashMap>(); + return createCitationInstance(inAuthority, null /*citationAuthRefName*/, + citationInfo, terms, EMPTY_CITATION_REPEATABLES_INFO, headerLabel); + } + + /** + * Creates a citation instance. + * + * @param inAuthority the owning authority + * @param citationAuthRefName the owning Authority ref name + * @param citationInfo the citation info + * @param terms a list of Citation terms + * @param citationRepeatablesInfo names and values of repeatable scalar fields in the Citation record + * @param headerLabel the header label + * @return the multipart output + */ + public static PoxPayloadOut createCitationInstance(String inAuthority, + String citationAuthRefName, Map citationInfo, + List terms, + Map> citationRepeatablesInfo, String headerLabel){ + CitationsCommon citation = new CitationsCommon(); + citation.setInAuthority(inAuthority); + String shortId = citationInfo.get(CitationJAXBSchema.SHORT_IDENTIFIER); + if (shortId == null || shortId.isEmpty()) { + throw new IllegalArgumentException("shortIdentifier cannot be null or empty"); + } + citation.setShortIdentifier(shortId); + + String value; + List values = null; + + // Set values in the Term Information Group + CitationTermGroupList termList = new CitationTermGroupList(); + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } + termList.getCitationTermGroup().addAll(terms); + citation.setCitationTermGroupList(termList); + + PoxPayloadOut multipart = new PoxPayloadOut(CitationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(citation, + MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, citation common ", citation, CitationsCommon.class); + } + + return multipart; + } + + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param citationAuthorityRefName the citation authority ref name + * @param citationMap the citation map. CitationJAXBSchema.SHORT_IDENTIFIER is REQUIRED. + * @param client the client + * @return the string + */ + public static String createItemInAuthority(String vcsid, + String citationAuthorityRefName, Map citationMap, + List terms, Map> citationRepeatablesMap, + CitationAuthorityClient 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 = ""; + if (terms !=null && terms.size() > 0) { + displayName = terms.get(0).getTermDisplayName(); + } + + if(logger.isDebugEnabled()){ + logger.debug("Creating item with display name: \"" + displayName + +"\" in citationAuthority: \"" + vcsid +"\""); + } + PoxPayloadOut multipart = + createCitationInstance(vcsid, null /*citationAuthorityRefName*/, + citationMap, terms, citationRepeatablesMap, client.getItemCommonPartName()); + + String result = null; + ClientResponse res = client.createItem(vcsid, multipart); + try { + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+citationMap.get(CitationJAXBSchema.SHORT_IDENTIFIER) + +"\" in citationAuthority: \"" + vcsid //citationAuthorityRefName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+citationMap.get(CitationJAXBSchema.SHORT_IDENTIFIER) + +"\" in citationAuthority: \"" + vcsid /*citationAuthorityRefName*/ +"\", Status:"+ statusCode); + } + + result = extractId(res); + } finally { + res.releaseConnection(); + } + + return result; + } + + /** + * Creates the citationAuthority ref name. + * + * @param shortId the citationAuthority shortIdentifier + * @param displaySuffix displayName to be appended, if non-null + * @return the string + */ + /* + public static String createCitationAuthRefName(String shortId, String displaySuffix) { + String refName = "urn:cspace:org.collectionspace.demo:citationauthority:name(" + +shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; + return refName; + } + */ + + /** + * Creates the citation ref name. + * + * @param citationAuthRefName the citation auth ref name + * @param shortId the citation shortIdentifier + * @param displaySuffix displayName to be appended, if non-null + * @return the string + */ + /* + public static String createCitationRefName( + String citationAuthRefName, String shortId, String displaySuffix) { + String refName = citationAuthRefName+":citation:name("+shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; + return refName; + } + */ + + /** + * Extract id. + * + * @param res the res + * @return the string + */ + public static String extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + // FIXME: This may throw an NPE if the Location: header isn't present + String uri = (String) ((ArrayList) mvm.get("Location")).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 CitationDocumentModelHandler.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 display name + */ + public static String prepareDefaultDisplayName( + String foreName, String middleName, String surName, + String birthDate, String deathDate) { + StringBuilder newStr = new StringBuilder(); + final String sep = " "; + final String dateSep = "-"; + List nameStrings = + Arrays.asList(foreName, middleName, surName); + boolean firstAdded = false; + for(String partStr : nameStrings ){ + if(null != partStr ) { + if(firstAdded) { + newStr.append(sep); + } + newStr.append(partStr); + firstAdded = true; + } + } + // Now we add the dates. In theory could have dates with no name, but that is their problem. + boolean foundBirth = false; + if(null != birthDate) { + if(firstAdded) { + newStr.append(sep); + } + newStr.append(birthDate); + newStr.append(dateSep); // Put this in whether there is a death date or not + foundBirth = true; + } + if(null != deathDate) { + if(!foundBirth) { + if(firstAdded) { + newStr.append(sep); + } + newStr.append(dateSep); + } + newStr.append(deathDate); + } + return newStr.toString(); + } + + public static List getTermGroupInstance(String identifier) { + if (Tools.isBlank(identifier)) { + identifier = getGeneratedIdentifier(); + } + List terms = new ArrayList(); + CitationTermGroup term = new CitationTermGroup(); + term.setTermDisplayName(identifier); + term.setTermName(identifier); + terms.add(term); + return terms; + } + + private static String getGeneratedIdentifier() { + return "id" + new Date().getTime(); + } + +} diff --git a/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityProxy.java b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityProxy.java new file mode 100644 index 000000000..015830de1 --- /dev/null +++ b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityProxy.java @@ -0,0 +1,15 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * @version $Revision:$ + */ +@Path(CitationAuthorityClient.SERVICE_PATH + "/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface CitationAuthorityProxy extends AuthorityWithContactsProxy { + +} diff --git a/services/citation/installer/build.xml b/services/citation/installer/build.xml new file mode 100644 index 000000000..e82327368 --- /dev/null +++ b/services/citation/installer/build.xml @@ -0,0 +1,61 @@ + + + + citation service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/jaxb/pom.xml b/services/citation/jaxb/pom.xml new file mode 100644 index 000000000..02b67aa1b --- /dev/null +++ b/services/citation/jaxb/pom.xml @@ -0,0 +1,46 @@ + + + + org.collectionspace.services + org.collectionspace.services.citation + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.jaxb + services.citation.jaxb + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.authority.jaxb + true + ${project.version} + + + + + collectionspace-services-citation-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/citation/jaxb/src/main/java/org/collectionspace/services/CitationJAXBSchema.java b/services/citation/jaxb/src/main/java/org/collectionspace/services/CitationJAXBSchema.java new file mode 100644 index 000000000..fb5453bc2 --- /dev/null +++ b/services/citation/jaxb/src/main/java/org/collectionspace/services/CitationJAXBSchema.java @@ -0,0 +1,14 @@ +/** + * + */ +package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; + +/** + * @author pschmitz + * + */ +public interface CitationJAXBSchema extends AuthorityItemJAXBSchema { + final static String CITATIONS_COMMON = "citations_common"; +} + diff --git a/services/citation/jaxb/src/main/resources/citation_common.xsd b/services/citation/jaxb/src/main/resources/citation_common.xsd new file mode 100644 index 000000000..0fd3cf6ac --- /dev/null +++ b/services/citation/jaxb/src/main/resources/citation_common.xsd @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/jaxb/src/main/resources/citationauthority_common.xsd b/services/citation/jaxb/src/main/resources/citationauthority_common.xsd new file mode 100644 index 000000000..68d63d161 --- /dev/null +++ b/services/citation/jaxb/src/main/resources/citationauthority_common.xsd @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/citation/jaxb/src/main/resources/citations_smk.xsd b/services/citation/jaxb/src/main/resources/citations_smk.xsd new file mode 100644 index 000000000..ede4e251b --- /dev/null +++ b/services/citation/jaxb/src/main/resources/citations_smk.xsd @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/citation/pom.xml b/services/citation/pom.xml new file mode 100644 index 000000000..0cbb03e8d --- /dev/null +++ b/services/citation/pom.xml @@ -0,0 +1,43 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation + services.citation + pom + + + + + + + jaxb + service + 3rdparty + client + + + + + samples + + sample + + + + + + diff --git a/services/citation/service/pom.xml b/services/citation/service/pom.xml new file mode 100644 index 000000000..44f134558 --- /dev/null +++ b/services/citation/service/pom.xml @@ -0,0 +1,133 @@ + + + + org.collectionspace.services + org.collectionspace.services.citation + 3.2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.citation.service + services.citation.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.authority.service + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.citation.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.citation.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.contact.service + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + + + + + 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 + + + + + + + + collectionspace-services-citation + + + + + diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/CitationAuthorityResource.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/CitationAuthorityResource.java new file mode 100644 index 000000000..45b7d75e8 --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/CitationAuthorityResource.java @@ -0,0 +1,71 @@ +/** + * 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.citation; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import org.collectionspace.services.client.CitationAuthorityClient; +import org.collectionspace.services.contact.AuthorityResourceWithContacts; +import org.collectionspace.services.citation.nuxeo.CitationDocumentModelHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CitationAuthorityResource + * + * Handles, dispatches, and returns responses to RESTful requests related to + * Citation authority-related resources. + */ +@Path(CitationAuthorityClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") +public class CitationAuthorityResource extends AuthorityResourceWithContacts { + + final Logger logger = LoggerFactory.getLogger(CitationAuthorityResource.class); + + public CitationAuthorityResource() { + super(CitationauthoritiesCommon.class, CitationAuthorityResource.class, + CitationAuthorityClient.SERVICE_COMMON_PART_NAME, CitationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); + } + + @Override + public String getServiceName() { + return CitationAuthorityClient.SERVICE_NAME; + } + + @Override + public String getItemServiceName() { + return CitationAuthorityClient.SERVICE_ITEM_NAME; + } + + @Override + public String getItemTermInfoGroupXPathBase() { + return CitationAuthorityClient.TERM_INFO_GROUP_XPATH_BASE; + } + + @Override + public Class getCommonPartClass() { + return CitationauthoritiesCommon.class; + } +} diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityConstants.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityConstants.java new file mode 100644 index 000000000..746cf116a --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityConstants.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.citation.nuxeo; + +/** + * CitationAuthorityConstants processes CollectionObject document + * + */ +public class CitationAuthorityConstants { + + public final static String NUXEO_DOCTYPE = "CitationAuthority"; + public final static String NUXEO_SCHEMA_NAME = "citationauthority"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-CitationAuthority"; +} diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityDocumentModelHandler.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityDocumentModelHandler.java new file mode 100644 index 000000000..a78cdd0b2 --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityDocumentModelHandler.java @@ -0,0 +1,57 @@ +/** + * 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.citation.nuxeo; + +import org.collectionspace.services.citation.CitationauthoritiesCommon; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; + +/** + * CitationAuthorityDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class CitationAuthorityDocumentModelHandler + extends AuthorityDocumentModelHandler { + + /** + * Common part schema label + */ + private static final String COMMON_PART_LABEL = "citationauthorities_common"; + + public CitationAuthorityDocumentModelHandler() { + super(COMMON_PART_LABEL); + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return CitationAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityValidatorHandler.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityValidatorHandler.java new file mode 100644 index 000000000..e4314e1c0 --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationAuthorityValidatorHandler.java @@ -0,0 +1,96 @@ +/** + * 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.citation.nuxeo; + +import java.util.regex.Pattern; + +import org.collectionspace.services.citation.CitationauthoritiesCommon; +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; + +/** + * CitationAuthorityValidatorHandler + * + * Validates data supplied when attempting to create and/or update CitationAuthority records. + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class CitationAuthorityValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(CitationAuthorityValidatorHandler.class); + private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + if (logger.isDebugEnabled()) { + logger.debug("validate() action=" + action.name()); + } + + // Bail out if the validation action is for delete. + if (action.equals(Action.DELETE)) { + return; + } + + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + CitationauthoritiesCommon citationAuth = + (CitationauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + CitationauthoritiesCommon.class); + String msg = ""; + boolean invalid = false; + + if(citationAuth != null) { // No guarantee that there is a common part in every post/update. + // Validation specific to creates or updates + if (action.equals(Action.CREATE)) { + String shortId = citationAuth.getShortIdentifier(); + // Per CSPACE-2215, shortIdentifier values that are null (missing) + // oe the empty string are now legally accepted in create payloads. + // In either of those cases, a short identifier will be synthesized from + // a display name or supplied in another manner. + if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) { + invalid = true; + msg += "shortIdentifier must only contain standard word characters"; + } + } else if (action.equals(Action.UPDATE)) { + } + } + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +} diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationConstants.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationConstants.java new file mode 100644 index 000000000..a7c140780 --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationConstants.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.citation.nuxeo; + +/** + * CitationConstants processes CollectionObject document + * + */ +public class CitationConstants { + + public final static String NUXEO_DOCTYPE = "Citation"; + public final static String NUXEO_SCHEMA_NAME = "citation"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Citation"; +} diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationDocumentModelHandler.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationDocumentModelHandler.java new file mode 100644 index 000000000..1ac55ec9a --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationDocumentModelHandler.java @@ -0,0 +1,74 @@ +/** + * 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.citation.nuxeo; + +import java.util.Arrays; +import java.util.List; + +import org.collectionspace.services.client.CitationAuthorityClient; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; +import org.collectionspace.services.CitationJAXBSchema; +import org.collectionspace.services.citation.CitationsCommon; +import org.nuxeo.ecm.core.api.DocumentModel; + +/** + * CitationDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +/** + * @author pschmitz + * + */ +public class CitationDocumentModelHandler + extends AuthorityItemDocumentModelHandler { + + /** The logger. */ + //private final Logger logger = LoggerFactory.getLogger(CitationDocumentModelHandler.class); + /** + * Common part schema label + */ + private static final String COMMON_PART_LABEL = "citations_common"; + + public CitationDocumentModelHandler() { + super(COMMON_PART_LABEL); + } + + @Override + public String getAuthorityServicePath(){ + return CitationAuthorityClient.SERVICE_PATH_COMPONENT; // CSPACE-3932 + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return CitationConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationValidatorHandler.java b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationValidatorHandler.java new file mode 100644 index 000000000..398795ef7 --- /dev/null +++ b/services/citation/service/src/main/java/org/collectionspace/services/citation/nuxeo/CitationValidatorHandler.java @@ -0,0 +1,144 @@ +/** + * 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.citation.nuxeo; + +import java.util.List; +import java.util.regex.Pattern; +import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandlerImpl; +import org.collectionspace.services.citation.CitationTermGroup; +import org.collectionspace.services.citation.CitationTermGroupList; +import org.collectionspace.services.citation.CitationsCommon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CitationValidatorHandler + * + * Performs validation when making requests related to Citation records. + * As an example, you can modify this class to customize validation of + * payloads supplied in requests to create and/or update records. + */ +public class CitationValidatorHandler extends ValidatorHandlerImpl { + + final Logger logger = LoggerFactory.getLogger(CitationValidatorHandler.class); + // 'Bad pattern' for shortIdentifiers matches any non-word characters + private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); + private static final String SHORT_ID_BAD_CHARS_ERROR = + "shortIdentifier must only contain standard word characters"; + private static final String HAS_NO_TERMS_ERROR = + "Authority items must contain at least one term."; + private static final String TERM_HAS_EMPTY_DISPLAYNAME_ERROR = + "Each term group in an authority item must contain " + + "a non-empty display name."; + + @Override + protected Class getCommonPartClass() { + return CitationsCommon.class; + } + + @Override + protected void handleCreate() throws InvalidDocumentException { + CitationsCommon citation = (CitationsCommon) getCommonPart(); + // No guarantee that there is a common part in every post/update. + if (citation != null) { + try { + String shortId = citation.getShortIdentifier(); + if (shortId != null) { + CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR); + } + CS_ASSERT(containsAtLeastOneTerm(citation), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainDisplayName(citation), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); + } catch (AssertionError e) { + if (logger.isErrorEnabled()) { + logger.error(e.getMessage(), e); + } + throw new InvalidDocumentException(e.getMessage(), e); + } + } + } + + @Override + protected void handleGet() throws InvalidDocumentException { + } + + @Override + protected void handleGetAll() throws InvalidDocumentException { + } + + @Override + protected void handleUpdate() throws InvalidDocumentException { + CitationsCommon citation = (CitationsCommon) getCommonPart(); + // No guarantee that there is a common part in every post/update. + if (citation != null) { + try { + // shortIdentifier is among a set of fields that are + // prevented from being changed on an update, and thus + // we don't need to check its value here. + CS_ASSERT(containsAtLeastOneTerm(citation), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainDisplayName(citation), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); + } catch (AssertionError e) { + if (logger.isErrorEnabled()) { + logger.error(e.getMessage(), e); + } + throw new InvalidDocumentException(e.getMessage(), e); + } + } + } + + @Override + protected void handleDelete() throws InvalidDocumentException { + } + + private boolean shortIdentifierContainsOnlyValidChars(String shortId) { + // Check whether any characters match the 'bad' pattern + if (SHORT_ID_BAD_PATTERN.matcher(shortId).find()) { + return false; + } + return true; + } + + private boolean containsAtLeastOneTerm(CitationsCommon citation) { + CitationTermGroupList termGroupList = citation.getCitationTermGroupList(); + if (termGroupList == null) { + return false; + } + List termGroups = termGroupList.getCitationTermGroup(); + if ((termGroups == null) || (termGroups.isEmpty())) { + return false; + } + return true; + } + + private boolean allTermsContainDisplayName(CitationsCommon citation) { + CitationTermGroupList termGroupList = citation.getCitationTermGroupList(); + List termGroups = termGroupList.getCitationTermGroup(); + for (CitationTermGroup termGroup : termGroups) { + if (Tools.isBlank(termGroup.getTermDisplayName())) { + return false; + } + } + return true; + } +} diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index ed2da9e89..ca6aa72c8 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -2018,6 +2018,166 @@ + + + + + default-domain + org.collectionspace.services.citation.nuxeo.CitationAuthorityDocumentModelHandler + + + + + displayName + displayName + + + refName + refName + + + shortIdentifier + shortIdentifier + + + vocabType + vocabType + + + + + org.collectionspace.services.citation.nuxeo.CitationAuthorityValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + citationauthorities_common + displayname + + + citationauthorities_common + shortidentifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + default-domain + org.collectionspace.services.citation.nuxeo.CitationDocumentModelHandler + + + true + + + + termDisplayName + citationTermGroupList/[0]/termDisplayName + + + + + org.collectionspace.services.citation.nuxeo.CitationValidatorHandler + + org.collectionspace.services.common.init.AddIndices + + + citations_common + inauthority + + + citationtermgroup + termdisplayname + + + citations_common + shortidentifier + + + + + + objectNameProperty + citationTermGroupList/[0]/termDisplayName + + + objectNumberProperty + shortIdentifier + + + + + + + + + + + + + + + + termRef + citationTermGroupList/*/termType + + + termRef + citationTermGroupList/*/termLanguage + + + termRef + citationTermGroupList/*/termStatus + + + + + + + + + + + + + + + diff --git a/services/pom.xml b/services/pom.xml index cb107a96e..45650fee3 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -51,6 +51,7 @@ vocabulary organization person + citation id collectionobject servicegroup diff --git a/services/relation/service/pom.xml b/services/relation/service/pom.xml index 771bca59b..23a3d2bc6 100644 --- a/services/relation/service/pom.xml +++ b/services/relation/service/pom.xml @@ -44,6 +44,13 @@ org.collectionspace.services.person.client ${project.version} + + + org.collectionspace.services + org.collectionspace.services.citation.client + ${project.version} + + org.collectionspace.services org.collectionspace.services.organization.client diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index 2b5e22c14..ae35a6713 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -52,6 +52,7 @@ import org.collectionspace.services.relation.RelationsDocListItem; // HACK HACK HACK import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.CitationAuthorityClient; import org.collectionspace.services.client.OrgAuthorityClient; import org.collectionspace.services.client.LocationAuthorityClient; import org.collectionspace.services.client.TaxonomyAuthorityClient; @@ -478,6 +479,8 @@ public class RelationDocumentModelHandler // HACK - Use startsWith to allow for extension of schemas. if(docType.startsWith("Person")) common_schema = PersonAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME; + else if(docType.startsWith("Citation")) + common_schema = CitationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME; else if(docType.startsWith("Organization")) common_schema = OrgAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME; else if(docType.startsWith("Locationitem"))