From 2109bea9a1d7ed92b55758be39cfcb816d082a60 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Sat, 3 Jul 2010 04:35:22 +0000 Subject: [PATCH] NOJIRA - Refactored autorities support. Fixed several inconsistencies, and simplified the code. Still some more to do to port this to Location, and to make authRefs and refObjs support more consistent. --- .../main/config/services/tenant-bindings.xml | 6 + .../common/vocabulary/AuthorityResource.java | 1020 +++++++++++++++++ .../AuthorityItemDocumentModelHandler.java | 25 + services/organization/jaxb/pom.xml | 5 + .../services/OrgAuthorityJAXBSchema.java | 19 - .../OrgAuthorityListItemJAXBSchema.java | 10 - .../services/OrganizationJAXBSchema.java | 8 +- .../OrganizationListItemJAXBSchema.java | 8 - .../organization/OrgAuthorityResource.java | 942 +-------------- .../OrgAuthorityDocumentModelHandler.java | 98 +- .../OrganizationDocumentModelHandler.java | 113 +- services/person/jaxb/pom.xml | 5 + .../services/PersonAuthorityJAXBSchema.java | 19 - .../PersonAuthorityListItemJAXBSchema.java | 10 - .../services/PersonJAXBSchema.java | 8 +- .../services/PersonListItemJAXBSchema.java | 8 - .../person/PersonAuthorityResource.java | 882 +------------- .../PersonAuthorityDocumentModelHandler.java | 79 +- .../nuxeo/PersonDocumentModelHandler.java | 101 +- .../vocabulary/VocabularyResource.java | 684 +---------- .../nuxeo/VocabularyDocumentModelHandler.java | 63 - .../VocabularyItemDocumentModelHandler.java | 11 +- 22 files changed, 1166 insertions(+), 2958 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java delete mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java delete mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java delete mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java delete mode 100644 services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java delete mode 100644 services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityListItemJAXBSchema.java delete mode 100644 services/person/jaxb/src/main/java/org/collectionspace/services/PersonListItemJAXBSchema.java diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index e36d28c28..aa0ee1df5 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -330,6 +330,9 @@ /vocabularies/*/items/ + + /vocabularies/*/items/*/refObjs + default-domain @@ -1502,6 +1505,9 @@ /personauthorities/*/items/ + + /personauthorities/*/items/*/authorityrefs/ + /personauthorities/*/items/*/refObjs diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java new file mode 100644 index 000000000..312f24823 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -0,0 +1,1020 @@ +/** + * 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.common.vocabulary; + +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.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; +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.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.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.query.IQueryManager; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class VocabularyResource. + */ +@Path("/vocabularies") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public abstract class AuthorityResource extends +AbstractMultiPartCollectionSpaceResourceImpl { + + private Class authCommonClass; + private Class resourceClass; + private String authorityCommonSchemaName; + private String authorityItemCommonSchemaName; + + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + final Logger logger = LoggerFactory.getLogger(AuthorityResource.class); + + /** + * Instantiates a new Authority resource. + */ + public AuthorityResource(Class authCommonClass, Class resourceClass, + String authorityCommonSchemaName, String authorityItemCommonSchemaName) { + this.authCommonClass = authCommonClass; + this.resourceClass = resourceClass; + this.authorityCommonSchemaName = authorityCommonSchemaName; + this.authorityItemCommonSchemaName = authorityItemCommonSchemaName; + } + + public abstract String getItemServiceName(); + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() + */ + @Override + protected String getVersionString() { + /** The last change revision. */ + final String lastChangeRevision = "$LastChangedRevision: 2617 $"; + return lastChangeRevision; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() + */ + @Override + public Class getCommonPartClass() { + return authCommonClass; + } + + /** + * Creates the item document handler. + * + * @param ctx the ctx + * @param inVocabulary the in vocabulary + * + * @return the document handler + * + * @throws Exception the exception + */ + public DocumentHandler createItemDocumentHandler( + ServiceContext ctx, + String inAuthority) + throws Exception { + AuthItemHandler docHandler; + + docHandler = (AuthItemHandler)createDocumentHandler(ctx, + ctx.getCommonPartLabel(getItemServiceName()), + authCommonClass); + ((AuthorityItemDocumentModelHandler)docHandler).setInAuthority(inAuthority); + + return (DocumentHandler)docHandler; + } + + /** + * Creates the authority. + * + * @param input the input + * + * @return the response + */ + @POST + public Response createAuthority(MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(input); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + UriBuilder path = UriBuilder.fromResource(resourceClass); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createVocabulary", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the authority. + * + * @param csid the csid + * + * @return the authority + */ + @GET + @Path("{csid}") + public MultipartOutput getAuthority(@PathParam("csid") String csid) { + if (csid == null) { + logger.error("getAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (logger.isDebugEnabled()) { + logger.debug("getAuthority with path(id)=" + csid); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Authority CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + + return result; + } + + /** + * Gets the authority by name. + * + * @param specifier the specifier + * + * @return the authority + */ + @GET + @Path("urn:cspace:name({specifier})") + public MultipartOutput getAuthorityByName(@PathParam("specifier") String specifier) { + if (specifier == null) { + logger.error("getAuthorityByName: missing name!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Authority (missing specifier)").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + authorityCommonSchemaName+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ + "='"+specifier+"'"; + // We only get a single doc - if there are multiple, + // it is an error in use. + + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityByName with name=" + specifier); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityByName", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Authority spec=" + specifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityByName", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Authority spec:" + specifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Finds and populates the authority list. + * + * @param ui the ui + * + * @return the authority list + */ + @GET + @Produces("application/xml") + public AuthCommonList getAuthorityList(@Context UriInfo ui) { + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + DocumentFilter myFilter = handler.getDocumentFilter(); + String nameQ = queryParams.getFirst("refName"); + if (nameQ != null) { + myFilter.setWhereClause(authorityCommonSchemaName+":refName='" + nameQ + "'"); + } + getRepositoryClient(ctx).getFiltered(ctx, handler); + return (AuthCommonList) handler.getCommonPartList(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Update authority. + * + * @param csid the csid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}") + public MultipartOutput updateAuthority( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(theUpdate); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).update(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in updateAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Delete authority. + * + * @param csid the csid + * + * @return the response + */ + @DELETE + @Path("{csid}") + public Response deleteAuthority(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + ServiceContext ctx = createServiceContext(); + getRepositoryClient(ctx).delete(ctx, csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Authority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + /************************************************************************* + * AuthorityItem parts - this is a sub-resource of Authority + * @param parentcsid + * @param input + * @return Authority item response + *************************************************************************/ + @POST + @Path("{csid}/items") + public Response createAuthorityItem(@PathParam("csid") String parentcsid, MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(getItemServiceName(), + input); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + String itemcsid = getRepositoryClient(ctx).create(ctx, handler); + UriBuilder path = UriBuilder.fromResource(resourceClass); + path.path(parentcsid + "/items/" + itemcsid); + Response response = Response.created(path.build()).build(); + return response; + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createAuthorityItem", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the authority item. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * + * @return the authority item + */ + @GET + @Path("{csid}/items/{itemcsid}") + public MultipartOutput getAuthorityItem( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("getAuthorityItem: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on AuthorityItem csid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("getAuthorityItem: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on AuthorityItem itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).get(ctx, itemcsid, handler); + // TODO should we assert that the item is in the passed vocab? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItem", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on AuthorityItem csid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItem", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested AuthorityItem CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the authority item by name. + * + * @param parentcsid the parentcsid + * @param itemspecifier the shortId of the person + * + * @return the authority item + */ + @GET + @Path("{csid}/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getAuthorityItemByName( + @PathParam("csid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier) { + if (parentcsid == null || "".equals(parentcsid) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getAuthorityItemByName: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on AuthorityItem with parentcsid=" + + parentcsid + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + authorityItemCommonSchemaName+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByName with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByName", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on AuthorityItem itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByName", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested AuthorityItem itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the AuthorityItem by name, in a named authority. + * + * @param parentspecifier the shortId of the parent + * @param itemspecifier the shortId of the person + * + * @return the person + */ + @GET + @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getAuthorityItemByNameInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier) { + if (parentspecifier == null || "".equals(parentspecifier) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getAuthorityItemByNameInNamedAuthority: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on AuthorityItem with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + // TODO REWRITE to get the CSID for the parent by name, and then call getAuthorityItemByName + String whereClause = + authorityItemCommonSchemaName+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByNameInNamedAuthority with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + // HACK HACK Since we do not use the parent CSID yet this should work. + DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByNameInNamedAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on AuthorityItem itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemByNameInNamedAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested AuthorityItem itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the authorityItem list. + * + * @param parentcsid the parentcsid + * @param partialTerm the partial term + * @param ui the ui + * + * @return the authorityItem list + */ + @GET + @Path("{csid}/items") + @Produces("application/xml") + public AuthItemCommonList getAuthorityItemList( + @PathParam("csid") String parentcsid, + @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, + @Context UriInfo ui) { + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + // Note that docType defaults to the ServiceName, so we're fine with that. + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = handler.getDocumentFilter(); + myFilter.setWhereClause( + authorityItemCommonSchemaName + ":" + + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + + "'" + parentcsid + "'"); + + // AND vocabularyitems_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = authorityItemCommonSchemaName + ":" + + AuthorityItemJAXBSchema.DISPLAY_NAME + + IQueryManager.SEARCH_LIKE + + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); + } + if (logger.isDebugEnabled()) { + logger.debug("getAuthorityItemList filtered WHERE clause: " + + myFilter.getWhereClause()); + } + getRepositoryClient(ctx).getFiltered(ctx, handler); + return (AuthItemCommonList) handler.getCommonPartList(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityItemList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + + /** + * Gets the authorityItem list using the shortIdentifier. + * + * @param specifier the shortIdentifier + * @param partialTerm the partial term + * @param ui the ui + * + * @return the authorityItem list + */ + @GET + @Path("urn:cspace:name({specifier})/items") + @Produces("application/xml") + public AuthItemCommonList getAuthorityItemListByAuthName( + @PathParam("specifier") String specifier, + @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, + @Context UriInfo ui) { + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + String whereClause = + authorityCommonSchemaName+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ + "='"+specifier+"'"; + // Need to get an Authority by name + ServiceContext ctx = createServiceContext(queryParams); + String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + return getAuthorityItemList(parentcsid, partialTerm, ui); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getVocabularyItemListByVocabName", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + /** + * Gets the entities referencing this Authority item instance. The service type + * can be passed as a query param "type", and must match a configured type + * for the service bindings. If not set, the type defaults to + * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. + * @param parentcsid + * + * @param csid the parent csid + * @param itemcsid the person csid + * @param ui the ui + * + * @return the info for the referencing objects + */ + @GET + @Path("{csid}/items/{itemcsid}/refObjs") + @Produces("application/xml") + public AuthorityRefDocList getReferencingObjects( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @Context UriInfo ui) { + AuthorityRefDocList authRefDocList = null; + if (logger.isDebugEnabled()) { + logger.debug("getReferencingObjects with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid) + || itemcsid == null || "".equals(itemcsid)) { + logger.error("getReferencingObjects: missing parentcsid or itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on ReferencingObjects with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = + createServiceContext(getItemServiceName(), queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + RepositoryClient repoClient = getRepositoryClient(ctx); + DocumentFilter myFilter = handler.getDocumentFilter(); + String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; + List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); + if (list != null) { + serviceType = list.get(0); + } + DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); + DocumentModel docModel = docWrapper.getWrappedObject(); + String refName = (String)docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME); + + authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx, + repoClient, + serviceType, + refName, + myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ ); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getReferencingObjects", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "GetReferencingObjects failed with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { // Includes DocumentException + if (logger.isDebugEnabled()) { + logger.debug("GetReferencingObjects", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (authRefDocList == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Item CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return authRefDocList; + } + + /** + * Gets the authority refs for an Authority item. + * @param parentcsid + * + * @param csid The authority (parent) CSID. + * @param itemcsid The item CSID. + * @param ui + * + * @return the authority refs for the Authority item. + */ + @GET + @Path("{csid}/items/{itemcsid}/authorityrefs") + @Produces("application/xml") + public AuthorityRefList getAuthorityItemAuthorityRefs( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @Context UriInfo ui) { + AuthorityRefList authRefList = null; + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = + createServiceContext(getItemServiceName(), queryParams); + RemoteDocumentModelHandlerImpl handler = + (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid); + DocumentWrapper docWrapper = + getRepositoryClient(ctx).getDoc(ctx, itemcsid); + List authRefFields = + ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues( + ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES); + authRefList = handler.getAuthorityRefs(docWrapper, authRefFields); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Failed to retrieve authority references: reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityRefs", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to retrieve authority references").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } + + + + /** + * Update authorityItem. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}/items/{itemcsid}") + public MultipartOutput updateAuthorityItem( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("updateVocabularyItem: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on AuthorityItem parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("updateVocabularyItem: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on AuthorityItem=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName(), + theUpdate); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).update(ctx, itemcsid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught DNF exception in updateAuthorityItem", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on AuthorityItem csid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Delete authorityItem. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * + * @return the response + */ + @DELETE + @Path("{csid}/items/{itemcsid}") + public Response deleteAuthorityItem( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("deleteAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("deleteVocabularyItem: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on AuthorityItem parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("deleteVocabularyItem: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on AuthorityItem=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + getRepositoryClient(ctx).delete(ctx, itemcsid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteAuthorityItem", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on AuthorityItem itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 3901cc4eb..8e6b51d31 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -29,6 +29,7 @@ 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.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.DocumentModel; /** @@ -40,6 +41,8 @@ import org.nuxeo.ecm.core.api.DocumentModel; public abstract class AuthorityItemDocumentModelHandler extends RemoteDocumentModelHandlerImpl { + private String authorityItemCommonSchemaName; + //private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class); /** * item is used to stash JAXB object to use when handle is called @@ -56,6 +59,10 @@ public abstract class AuthorityItemDocumentModelHandler * inVocabulary is the parent Authority for this context */ protected String inAuthority; + + public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) { + this.authorityItemCommonSchemaName = authorityItemCommonSchemaName; + } public String getInAuthority() { return inAuthority; @@ -109,6 +116,23 @@ public abstract class AuthorityItemDocumentModelHandler throw new UnsupportedOperationException(); } + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType) + */ + @Override + protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) + throws Exception { + Map unQObjectProperties = super.extractPart(docModel, schema, partMeta); + + // Add the CSID to the common part + if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) { + String csid = NuxeoUtils.extractId(docModel.getPathAsString()); + unQObjectProperties.put("csid", csid); + } + + return unQObjectProperties; + } + /** * Filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that * the parent link remains untouched. @@ -120,6 +144,7 @@ public abstract class AuthorityItemDocumentModelHandler Map objectProps, ObjectPartType partMeta) { super.filterReadOnlyPropertiesForPart(objectProps, partMeta); objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY); + objectProps.remove(AuthorityItemJAXBSchema.CSID); } } diff --git a/services/organization/jaxb/pom.xml b/services/organization/jaxb/pom.xml index e26b84844..f2ab25e5b 100644 --- a/services/organization/jaxb/pom.xml +++ b/services/organization/jaxb/pom.xml @@ -14,6 +14,11 @@ services.organization.jaxb + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + com.sun.xml.bind jaxb-impl diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java deleted file mode 100644 index 05844ad2b..000000000 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * - */ -package org.collectionspace.services; - -/** - * @author pschmitz - * - */ -public interface OrgAuthorityJAXBSchema { - final static String ORGAUTHORITIES_COMMON = "orgauthorities_common"; - final static String DISPLAY_NAME = "displayName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String REF_NAME = "refName"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; -} - - diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java deleted file mode 100644 index 800acbd8a..000000000 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.collectionspace.services; - -public interface OrgAuthorityListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java index 21efbd036..08e6f88ec 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java @@ -2,18 +2,14 @@ * */ package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; /** * @author pschmitz * */ -public interface OrganizationJAXBSchema { +public interface OrganizationJAXBSchema extends AuthorityJAXBSchema { final static String ORGANIZATIONS_COMMON="organizations_common"; - final static String CSID = "csid"; - final static String IN_AUTHORITY = "inAuthority"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String DISPLAY_NAME = "displayName"; final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; final static String SHORT_NAME = "shortName"; final static String LONG_NAME = "longName"; diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java deleted file mode 100644 index 86653cf18..000000000 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.collectionspace.services; - -public interface OrganizationListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 6bdba2eac..41c8ad9c3 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -33,7 +33,6 @@ 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; @@ -41,17 +40,11 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.OrgAuthorityJAXBSchema; -import org.collectionspace.services.OrganizationJAXBSchema; -import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; -import org.collectionspace.services.common.ClientType; -import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.vocabulary.AuthorityResource; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; 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.MultipartServiceContextFactory; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.BadRequestException; @@ -84,19 +77,22 @@ import org.slf4j.LoggerFactory; @Consumes("multipart/mixed") @Produces("multipart/mixed") public class OrgAuthorityResource extends - AbstractMultiPartCollectionSpaceResourceImpl { + AuthorityResource { /** The Constant orgAuthorityServiceName. */ private final static String orgAuthorityServiceName = "orgauthorities"; + private final static String ORGAUTHORITIES_COMMON = "orgauthorities_common"; /** The Constant organizationServiceName. */ private final static String organizationServiceName = "organizations"; + private final static String ORGANIZATIONS_COMMON = "organizations_common"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class); //FIXME retrieve client type from configuration /** The Constant CLIENT_TYPE. */ - final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + //final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); /** The contact resource. */ private ContactResource contactResource = new ContactResource(); @@ -105,19 +101,10 @@ public class OrgAuthorityResource extends * Instantiates a new org authority resource. */ public OrgAuthorityResource() { - // do nothing + super(OrgauthoritiesCommon.class, OrgAuthorityResource.class, + ORGAUTHORITIES_COMMON, ORGANIZATIONS_COMMON); } - /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() - */ - @Override - protected String getVersionString() { - /** The last change revision. */ - final String lastChangeRevision = "$LastChangedRevision$"; - return lastChangeRevision; - } - /* (non-Javadoc) * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() */ @@ -126,14 +113,6 @@ public class OrgAuthorityResource extends return orgAuthorityServiceName; } - /* (non-Javadoc) - * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() - */ - @Override - public Class getCommonPartClass() { - return OrgauthoritiesCommon.class; - } - /** * Gets the item service name. * @@ -143,6 +122,14 @@ public class OrgAuthorityResource extends return organizationServiceName; } + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() + */ + @Override + public Class getCommonPartClass() { + return OrgauthoritiesCommon.class; + } + /** * Gets the contact service name. * @@ -152,28 +139,6 @@ public class OrgAuthorityResource extends return contactResource.getServiceName(); } - /** - * Creates the item document handler. - * - * @param ctx the ctx - * @param inAuthority the in authority - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createItemDocumentHandler( - ServiceContext ctx, - String inAuthority) throws Exception { - OrganizationDocumentModelHandler docHandler = (OrganizationDocumentModelHandler)createDocumentHandler( - ctx, - ctx.getCommonPartLabel(getItemServiceName()), - OrganizationsCommon.class); - docHandler.setInAuthority(inAuthority); - - return docHandler; - } - /** * Creates the contact document handler. * @@ -199,879 +164,6 @@ public class OrgAuthorityResource extends return docHandler; } - /** - * Creates the org authority. - * - * @param input the input - * - * @return the response - */ - @POST - public Response createOrgAuthority(MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(input); - DocumentHandler handler = createDocumentHandler(ctx); - String csid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class); - path.path("" + csid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createOrgAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the org authority by name. - * - * @param specifier the specifier - * - * @return the org authority by name - */ - @GET - @Path("urn:cspace:name({specifier})") - public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) { - if (specifier == null) { - logger.error("getOrgAuthority: missing name!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on OrgAuthority (missing specifier)").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+ - ":"+OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+specifier+"'"; - // We only get a single doc - if there are multiple, - // it is an error in use. - - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority with name=" + specifier); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on OrgAuthority spec=" + specifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested OrgAuthority spec:" + specifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the entities referencing this Organization instance. The service type - * can be passed as a query param "type", and must match a configured type - * for the service bindings. If not set, the type defaults to - * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. - * @param parentcsid - * - * @param csid the parent csid - * @param itemcsid the person csid - * @param ui the ui - * - * @return the info for the referencing objects - */ - @GET - @Path("{csid}/items/{itemcsid}/refObjs") - @Produces("application/xml") - public AuthorityRefDocList getReferencingObjects( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - AuthorityRefDocList authRefDocList = null; - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid) - || itemcsid == null || "".equals(itemcsid)) { - logger.error("getPerson: missing parentcsid or itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Person with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - RepositoryClient repoClient = getRepositoryClient(ctx); - DocumentFilter myFilter = handler.getDocumentFilter(); - String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; - List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); - if (list != null) { - serviceType = list.get(0); - } - DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); - DocumentModel docModel = docWrapper.getWrappedObject(); - String refName = (String)docModel.getPropertyValue(OrganizationJAXBSchema.REF_NAME); - - authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx, - repoClient, - serviceType, - refName, - myFilter.getPageSize(), myFilter.getStartPage(), true ); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "GetReferencingObjects failed with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { // Includes DocumentException - if (logger.isDebugEnabled()) { - logger.debug("GetReferencingObjects", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (authRefDocList == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return authRefDocList; - } - - - /** - * Gets the org authority. - * - * @param csid the csid - * - * @return the org authority - */ - @GET - @Path("{csid}") - public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) { - if (csid == null) { - logger.error("getOrgAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority with path(id)=" + csid); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).get(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getOrgAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested OrgAuthority CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the org authority list. - * - * @param ui the ui - * - * @return the org authority list - */ - @GET - @Produces("application/xml") - public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) { - OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = handler.getDocumentFilter(); - String nameQ = queryParams.getFirst("refName"); - if (nameQ != null) { - myFilter.setWhereClause("orgauthorities_common:refName='" + nameQ + "'"); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - orgAuthorityObjectList = (OrgauthoritiesCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getOrgAuthorityList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return orgAuthorityObjectList; - } - - /** - * Update org authority. - * - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}") - public MultipartOutput updateOrgAuthority( - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateOrgAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("updateOrgAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(theUpdate); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in updateOrgAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete org authority. - * - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{csid}") - public Response deleteOrgAuthority(@PathParam("csid") String csid) { - - if (logger.isDebugEnabled()) { - logger.debug("deleteOrgAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("deleteOrgAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - ServiceContext ctx = createServiceContext(); - getRepositoryClient(ctx).delete(ctx, csid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteOrgAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on OrgAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /************************************************************************* - * Organization parts - this is a sub-resource of OrgAuthority - * @param parentcsid - * @param input - * @return org response - *************************************************************************/ - @POST - @Path("{csid}/items") - public Response createOrganization(@PathParam("csid") String parentcsid, MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(getItemServiceName(), - input); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - String itemcsid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class); - path.path(parentcsid + "/items/" + itemcsid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createOrganization", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the organization. - * @param parentcsid - * - * @param csid The organization authority (parent) CSID. - * @param itemcsid The organization item CSID. - * - * @return the organization. - */ - @GET - @Path("{csid}/items/{itemcsid}") - public MultipartOutput getOrganization( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("getOrganization: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Organization csid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("getOrganization: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Organization itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).get(ctx, itemcsid, handler); - // TODO should we assert that the item is in the passed orgAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganization", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Organization csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganization", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Organization CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person by name. - * - * @param parentcsid the parentcsid - * @param itemspecifier the shrotId of the person - * - * @return the person - */ - @GET - @Path("{csid}/items/urn:cspace:name({itemspecifier})") - public MultipartOutput getOrganizationByName( - @PathParam("csid") String parentcsid, - @PathParam("itemspecifier") String itemspecifier) { - if (parentcsid == null || "".equals(parentcsid) - || itemspecifier == null || "".equals(itemspecifier)) { - logger.error("getOrganizationByName: missing parentcsid or itemspecifier!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Organization with parentcsid=" - + parentcsid + " and itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - OrganizationJAXBSchema.ORGANIZATIONS_COMMON+ - ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+ - "='"+itemspecifier+"'"; - if (logger.isDebugEnabled()) { - logger.debug("getOrganizationByName with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - // TODO should we assert that the item is in the passed personAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganization", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Organization itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganizationByName", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Organization itemspecifier:" + itemspecifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person by name, in a named authority. - * - * @param parentspecifier the shortId of the parent - * @param itemspecifier the shortId of the person - * - * @return the person - */ - @GET - @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})") - public MultipartOutput getOrganizationByNameInNamedAuthority( - @PathParam("parentspecifier") String parentspecifier, - @PathParam("itemspecifier") String itemspecifier) { - if (parentspecifier == null || "".equals(parentspecifier) - || itemspecifier == null || "".equals(itemspecifier)) { - logger.error("getOrganizationByNameInNamedAuthority: missing parentcsid or itemspecifier!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Organization with parentspecifier=" - + parentspecifier + " and itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - OrganizationJAXBSchema.ORGANIZATIONS_COMMON+ - ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+ - "='"+itemspecifier+"'"; - if (logger.isDebugEnabled()) { - logger.debug("getOrganizationByNameInNamedAuthority with parentspecifier=" - + parentspecifier + " and itemspecifier=" + itemspecifier); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - // HACK HACK Since we do not use the parent CSID yet this should work. - DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - // TODO should we assert that the item is in the passed personAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganizationByNameInNamedAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Person itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getOrganizationByNameInNamedAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the authority refs for an Organization item. - * @param parentcsid - * - * @param csid The organization authority (parent) CSID. - * @param itemcsid The organization item CSID. - * @param ui - * - * @return the authority refs for the Organization item. - */ - @GET - @Path("{csid}/items/{itemcsid}/authorityrefs") - @Produces("application/xml") - public AuthorityRefList getOrganizationAuthorityRefs( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - AuthorityRefList authRefList = null; - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = - createServiceContext(getItemServiceName(), queryParams); - RemoteDocumentModelHandlerImpl handler = - (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid); - DocumentWrapper docWrapper = - getRepositoryClient(ctx).getDoc(ctx, itemcsid); - List authRefFields = - ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues( - ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES); - authRefList = handler.getAuthorityRefs(docWrapper, authRefFields); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Failed to retrieve authority references: reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getAuthorityRefs", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to retrieve authority references").type("text/plain").build(); - throw new WebApplicationException(response); - } - return authRefList; - } - - /** - * Gets the organization list. - * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui - * - * @return the organization list - */ - @GET - @Path("{csid}/items") - @Produces("application/xml") - public OrganizationsCommonList getOrganizationList( - @PathParam("csid") String parentcsid, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - OrganizationsCommonList organizationObjectList = new OrganizationsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); - myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + - ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" + - "'" + parentcsid + "'"); - - // AND organizations_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = OrganizationJAXBSchema.ORGANIZATIONS_COMMON + - ":" + OrganizationJAXBSchema.DISPLAY_NAME + - " LIKE " + "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getOrganizationList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return organizationObjectList; - } - - /** - * Gets the organization list by auth name. - * - * @param parentSpecifier the parent specifier - * @param partialTerm the partial term - * @param ui the ui - * - * @return the organization list by auth name - */ - @GET - @Path("urn:cspace:name({specifier})/items") - @Produces("application/xml") - public OrganizationsCommonList getOrganizationListByAuthName( - @PathParam("specifier") String parentSpecifier, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - OrganizationsCommonList personObjectList = new OrganizationsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - String whereClause = - OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+ - ":" + OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='" + parentSpecifier+"'"; - // Need to get an Authority by name - ServiceContext ctx = createServiceContext(queryParams); - String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); - return getOrganizationList(parentcsid, partialTerm, ui); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getOrganizationListByAuthName", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Update organization. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}/items/{itemcsid}") - public MultipartOutput updateOrganization( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("updateOrganization: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Organization parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("updateOrganization: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Organization=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - theUpdate); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).update(ctx, itemcsid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in updateOrganization", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Organization csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete organization. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the response - */ - @DELETE - @Path("{csid}/items/{itemcsid}") - public Response deleteOrganization( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("deleteOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("deleteOrganization: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Organization parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("deleteOrganization: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Organization=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - getRepositoryClient(ctx).delete(ctx, itemcsid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteOrganization", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Organization itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - /************************************************************************* * Contact parts - this is a sub-resource of Organization (or "item") * @param parentcsid diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java index 341440b8b..97f6de58b 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java @@ -26,20 +26,18 @@ package org.collectionspace.services.organization.nuxeo; import java.util.Iterator; import java.util.List; -import org.collectionspace.services.OrgAuthorityJAXBSchema; -import org.collectionspace.services.common.document.DocumentHandler.Action; -import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrgauthoritiesCommonList; import org.collectionspace.services.organization.OrgauthoritiesCommonList.OrgauthorityListItem; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; 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; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; /** * OrgAuthorityDocumentModelHandler @@ -48,75 +46,10 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class OrgAuthorityDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { - - /** The logger. */ - private final Logger logger = LoggerFactory.getLogger(OrgAuthorityDocumentModelHandler.class); - /** - * orgAuthority is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private OrgauthoritiesCommon orgAuthority; - /** - * orgAuthorityList is stashed when handle is called - * for ACTION.GET_ALL - */ - private OrgauthoritiesCommonList orgAuthorityList; - - - /** - * getCommonPart get associated orgAuthority - * @return - */ - @Override - public OrgauthoritiesCommon getCommonPart() { - return orgAuthority; - } - - /** - * setCommonPart set associated orgAuthority - * @param orgAuthority - */ - @Override - public void setCommonPart(OrgauthoritiesCommon orgAuthority) { - this.orgAuthority = orgAuthority; - } - - /** - * getCommonPartList get associated orgAuthority (for index/GET_ALL) - * @return - */ - @Override - public OrgauthoritiesCommonList getCommonPartList() { - return orgAuthorityList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(OrgauthoritiesCommonList orgAuthorityList) { - this.orgAuthorityList = orgAuthorityList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public OrgauthoritiesCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(OrgauthoritiesCommon orgAuthorityObject, - DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } + extends AuthorityDocumentModelHandler { + //private final Logger logger = LoggerFactory.getLogger(OrgAuthorityDocumentModelHandler.class); + /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) */ @@ -125,17 +58,18 @@ public class OrgAuthorityDocumentModelHandler OrgauthoritiesCommonList coList = this.extractPagingInfo(new OrgauthoritiesCommonList(), wrapDoc); List list = coList.getOrgauthorityListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); + String label = getServiceContext().getCommonPartLabel(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); OrgauthorityListItem ilistItem = new OrgauthorityListItem(); - ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - OrgAuthorityJAXBSchema.DISPLAY_NAME)); - ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - OrgAuthorityJAXBSchema.REF_NAME)); - ilistItem.setShortIdentifier((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - OrgAuthorityJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - OrgAuthorityJAXBSchema.VOCAB_TYPE)); + 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 = NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri(getServiceContextPath() + id); ilistItem.setCsid(id); diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java index 9977af8ad..d78da2e50 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java @@ -27,12 +27,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.OrganizationJAXBSchema; -import org.collectionspace.services.common.context.MultipartServiceContext; -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.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.organization.OrganizationsCommon; import org.collectionspace.services.organization.OrganizationsCommonList; @@ -49,48 +47,18 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class OrganizationDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityItemDocumentModelHandler { /** The logger. */ private final Logger logger = LoggerFactory.getLogger(OrganizationDocumentModelHandler.class); /** * Common part schema label */ - private static final String COMMON_PART_LABEL = "organizations_common"; - /** - * organization is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private OrganizationsCommon organization; - /** - * organizationList is stashed when handle is called - * for ACTION.GET_ALL - */ - private OrganizationsCommonList organizationList; + private static final String COMMON_PART_LABEL = "organizations_common"; - /** - * inAuthority is the parent OrgAuthority for this context - */ - private String inAuthority; - - /** - * Gets the in authority. - * - * @return the in authority - */ - public String getInAuthority() { - return inAuthority; - } - - /** - * Sets the in authority. - * - * @param inAuthority the new in authority - */ - public void setInAuthority(String inAuthority) { - this.inAuthority = inAuthority; - } - + public OrganizationDocumentModelHandler() { + super(COMMON_PART_LABEL); + } /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) @@ -160,75 +128,6 @@ public class OrganizationDocumentModelHandler return newStr.toString(); } - /** - * getCommonPart get associated organization - * @return - */ - @Override - public OrganizationsCommon getCommonPart() { - return organization; - } - - /** - * setCommonPart set associated organization - * @param organization - */ - @Override - public void setCommonPart(OrganizationsCommon organization) { - this.organization = organization; - } - - /** - * getCommonPartList get associated organization (for index/GET_ALL) - * @return - */ - @Override - public OrganizationsCommonList getCommonPartList() { - return organizationList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(OrganizationsCommonList organizationList) { - this.organizationList = organizationList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType) - */ - @Override - protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) - throws Exception { - Map unQObjectProperties = super.extractPart(docModel, schema, partMeta); - - // Add the CSID to the common part - if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) { - String csid = NuxeoUtils.extractId(docModel.getPathAsString()); - unQObjectProperties.put("csid", csid); - } - - return unQObjectProperties; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public OrganizationsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(OrganizationsCommon organizationObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) */ diff --git a/services/person/jaxb/pom.xml b/services/person/jaxb/pom.xml index 4add0919a..2c2ae77f1 100644 --- a/services/person/jaxb/pom.xml +++ b/services/person/jaxb/pom.xml @@ -14,6 +14,11 @@ services.person.jaxb + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + com.sun.xml.bind jaxb-impl diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java deleted file mode 100644 index 691f44f76..000000000 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * - */ -package org.collectionspace.services; - -/** - * @author pschmitz - * - */ -public interface PersonAuthorityJAXBSchema { - final static String PERSONAUTHORITIES_COMMON = "personauthorities_common"; - final static String DISPLAY_NAME = "displayName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String REF_NAME = "refName"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; -} - - diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityListItemJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityListItemJAXBSchema.java deleted file mode 100644 index d64c58081..000000000 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityListItemJAXBSchema.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.collectionspace.services; - -public interface PersonAuthorityListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java index ad4fdf305..353ea4d2b 100644 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java +++ b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java @@ -2,18 +2,14 @@ * */ package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; /** * @author pschmitz * */ -public interface PersonJAXBSchema { +public interface PersonJAXBSchema extends AuthorityJAXBSchema { final static String PERSONS_COMMON = "persons_common"; - final static String CSID = "csid"; - final static String IN_AUTHORITY = "inAuthority"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String REF_NAME = "refName"; - final static String DISPLAY_NAME = "displayName"; final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; final static String FORE_NAME = "foreName"; final static String MIDDLE_NAME = "middleName"; diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonListItemJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonListItemJAXBSchema.java deleted file mode 100644 index 0f501c83a..000000000 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonListItemJAXBSchema.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.collectionspace.services; - -public interface PersonListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 22326fc43..1bd72fa85 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -33,7 +33,6 @@ 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; @@ -41,11 +40,8 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.PersonAuthorityJAXBSchema; -import org.collectionspace.services.PersonJAXBSchema; -import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; -import org.collectionspace.services.common.ClientType; -import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.vocabulary.AuthorityResource; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; @@ -57,7 +53,6 @@ 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.RefNameServiceUtils; -import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactsCommonList; @@ -81,19 +76,19 @@ import org.slf4j.LoggerFactory; @Consumes("multipart/mixed") @Produces("multipart/mixed") public class PersonAuthorityResource extends - AbstractMultiPartCollectionSpaceResourceImpl { + AuthorityResource { - /** The Constant personAuthorityServiceName. */ private final static String personAuthorityServiceName = "personauthorities"; - - /** The Constant personServiceName. */ + private final static String PERSONAUTHORITIES_COMMON = "personauthorities_common"; + private final static String personServiceName = "persons"; + private final static String PERSONS_COMMON = "persons_common"; - /** The logger. */ final Logger logger = LoggerFactory.getLogger(PersonAuthorityResource.class); //FIXME retrieve client type from configuration /** The Constant CLIENT_TYPE. */ - final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + //final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); /** The contact resource. */ private ContactResource contactResource = new ContactResource(); @@ -102,19 +97,10 @@ public class PersonAuthorityResource extends * Instantiates a new person authority resource. */ public PersonAuthorityResource() { - // do nothing + super(PersonauthoritiesCommon.class, PersonAuthorityResource.class, + PERSONAUTHORITIES_COMMON, PERSONS_COMMON); } - /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() - */ - @Override - protected String getVersionString() { - /** The last change revision. */ - final String lastChangeRevision = "$LastChangedRevision$"; - return lastChangeRevision; - } - /* (non-Javadoc) * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() */ @@ -123,20 +109,21 @@ public class PersonAuthorityResource extends return personAuthorityServiceName; } - @Override - public Class getCommonPartClass() { - return PersonauthoritiesCommon.class; - } - /** * Gets the item service name. * * @return the item service name */ + @Override public String getItemServiceName() { return personServiceName; } + @Override + public Class getCommonPartClass() { + return PersonauthoritiesCommon.class; + } + /** * Gets the contact service name. * @@ -146,26 +133,6 @@ public class PersonAuthorityResource extends return contactResource.getServiceName(); } - /** - * Creates the item document handler. - * - * @param ctx the ctx - * @param inAuthority the in authority - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createItemDocumentHandler(ServiceContext ctx, - String inAuthority) throws Exception { - PersonDocumentModelHandler docHandler = (PersonDocumentModelHandler)createDocumentHandler(ctx, - ctx.getCommonPartLabel(getItemServiceName()), - PersonsCommon.class); - docHandler.setInAuthority(inAuthority); - - return docHandler; - } - /** * Creates the contact document handler. * @@ -189,823 +156,6 @@ public class PersonAuthorityResource extends return docHandler; } - /** - * Creates the person authority. - * - * @param input the input - * - * @return the response - */ - @POST - public Response createPersonAuthority(MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(input); - DocumentHandler handler = createDocumentHandler(ctx); - String csid = getRepositoryClient(ctx).create(ctx, handler); - //personAuthorityObject.setCsid(csid); - UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class); - path.path("" + csid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createPersonAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the person authority by name. - * - * @param specifier the specifier - * - * @return the person authority by name - */ - @GET - @Path("urn:cspace:name({specifier})") - public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) { - if (specifier == null) { - logger.error("getPersonAuthority: missing name!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on PersonAuthority (missing specifier)").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+ - ":"+PersonAuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+specifier+"'"; - // We only get a single doc - if there are multiple, - // it is an error in use. - - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthorityByName with name=" + specifier); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthorityByName", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on PersonAuthority spec=" + specifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthorityByName", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested PersonAuthority spec:" + specifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the entities referencing this Person instance. The service type - * can be passed as a query param "type", and must match a configured type - * for the service bindings. If not set, the type defaults to - * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. - * @param parentcsid - * - * @param csid the parent csid - * @param itemcsid the person csid - * @param ui the ui - * - * @return the info for the referencing objects - */ - @GET - @Path("{csid}/items/{itemcsid}/refObjs") - @Produces("application/xml") - public AuthorityRefDocList getReferencingObjects( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - AuthorityRefDocList authRefDocList = null; - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid) - || itemcsid == null || "".equals(itemcsid)) { - logger.error("getPerson: missing parentcsid or itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Person with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - RepositoryClient repoClient = getRepositoryClient(ctx); - DocumentFilter myFilter = handler.getDocumentFilter(); - String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; - List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); - if (list != null) { - serviceType = list.get(0); - } - DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); - DocumentModel docModel = docWrapper.getWrappedObject(); - String refName = (String)docModel.getPropertyValue(PersonJAXBSchema.REF_NAME); - - authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx, - repoClient, - serviceType, - refName, - myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ ); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "GetReferencingObjects failed with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { // Includes DocumentException - if (logger.isDebugEnabled()) { - logger.debug("GetReferencingObjects", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (authRefDocList == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return authRefDocList; - } - - @GET - @Path("{csid}") - public MultipartOutput getPersonAuthority(@PathParam("csid") String csid) { - if (csid == null) { - logger.error("getPersonAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority with path(id)=" + csid); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).get(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested PersonAuthority CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person authority list. - * - * @param ui the ui - * - * @return the person authority list - */ - @GET - @Produces("application/xml") - public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) { - PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); - String nameQ = queryParams.getFirst("refName"); - if (nameQ != null) { - handler.getDocumentFilter().setWhereClause("personauthorities_common:refName='" + nameQ + "'"); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getPersonAuthorityList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return personAuthorityObjectList; - } - - /** - * Update person authority. - * - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}") - public MultipartOutput updatePersonAuthority( - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updatePersonAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("updatePersonAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(theUpdate); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caugth exception in updatePersonAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete person authority. - * - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{csid}") - public Response deletePersonAuthority(@PathParam("csid") String csid) { - - if (logger.isDebugEnabled()) { - logger.debug("deletePersonAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("deletePersonAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - ServiceContext ctx = createServiceContext(); - getRepositoryClient(ctx).delete(ctx, csid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deletePersonAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on PersonAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * *********************************************************************** - * Person parts - this is a sub-resource of PersonAuthority - * ***********************************************************************. - * - * @param parentcsid the parentcsid - * @param input the input - * @return the response - */ - @POST - @Path("{csid}/items") - public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(getItemServiceName(), input); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - String itemcsid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class); - path.path(parentcsid + "/items/" + itemcsid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createPerson", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the person. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the person - */ - @GET - @Path("{csid}/items/{itemcsid}") - public MultipartOutput getPerson( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("getPerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid) - || itemcsid == null || "".equals(itemcsid)) { - logger.error("getPerson: missing parentcsid or itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Person with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).get(ctx, itemcsid, handler); - // TODO should we assert that the item is in the passed personAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getPerson", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Person csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getPerson", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person by name. - * - * @param parentcsid the parentcsid - * @param itemspecifier the shrotId of the person - * - * @return the person - */ - @GET - @Path("{csid}/items/urn:cspace:name({itemspecifier})") - public MultipartOutput getPersonByName( - @PathParam("csid") String parentcsid, - @PathParam("itemspecifier") String itemspecifier) { - if (parentcsid == null || "".equals(parentcsid) - || itemspecifier == null || "".equals(itemspecifier)) { - logger.error("getPersonByName: missing parentcsid or itemspecifier!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Person with parentcsid=" - + parentcsid + " and itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - PersonJAXBSchema.PERSONS_COMMON+ - ":"+PersonJAXBSchema.SHORT_IDENTIFIER+ - "='"+itemspecifier+"'"; - if (logger.isDebugEnabled()) { - logger.debug("getPerson with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - // TODO should we assert that the item is in the passed personAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getPerson", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Person itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getPerson", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person by name, in a named authority. - * - * @param parentspecifier the shortId of the parent - * @param itemspecifier the shortId of the person - * - * @return the person - */ - @GET - @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})") - public MultipartOutput getPersonByNameInNamedAuthority( - @PathParam("parentspecifier") String parentspecifier, - @PathParam("itemspecifier") String itemspecifier) { - if (parentspecifier == null || "".equals(parentspecifier) - || itemspecifier == null || "".equals(itemspecifier)) { - logger.error("getPersonByNameInNamedAuthority: missing parentcsid or itemspecifier!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Person with parentspecifier=" - + parentspecifier + " and itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - PersonJAXBSchema.PERSONS_COMMON+ - ":"+PersonJAXBSchema.SHORT_IDENTIFIER+ - "='"+itemspecifier+"'"; - if (logger.isDebugEnabled()) { - logger.debug("getPersonByNameInNamedAuthority with parentspecifier=" - + parentspecifier + " and itemspecifier=" + itemspecifier); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - // HACK HACK Since we do not use the parent CSID yet this should work. - DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - // TODO should we assert that the item is in the passed personAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonByNameInNamedAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Person itemspecifier=" + itemspecifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getPersonByNameInNamedAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the person list. - * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui - * - * @return the person list - */ - @GET - @Path("{csid}/items") - @Produces("application/xml") - public PersonsCommonList getPersonList( - @PathParam("csid") String parentcsid, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - PersonsCommonList personObjectList = new PersonsCommonList(); - try { - // Note that docType defaults to the ServiceName, so we're fine with that. - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" - handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + - PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); - - // AND persons_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" + - PersonJAXBSchema.DISPLAY_NAME + - " LIKE " + - "'%" + partialTerm + "%'"; - handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - personObjectList = (PersonsCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getPersonList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return personObjectList; - } - - - /** - * Gets the person list by auth name. - * - * @param parentSpecifier the parent specifier - * @param partialTerm the partial term - * @param ui the ui - * - * @return the person list by auth name - */ - @GET - @Path("urn:cspace:name({specifier})/items") - @Produces("application/xml") - public PersonsCommonList getPersonListByAuthName( - @PathParam("specifier") String parentSpecifier, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - PersonsCommonList personObjectList = new PersonsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON + - ":" + PersonAuthorityJAXBSchema.SHORT_IDENTIFIER + - "='" + parentSpecifier+"'"; - // Need to get an Authority by name - ServiceContext ctx = createServiceContext(queryParams); - String parentcsid = - getRepositoryClient(ctx).findDocCSID(ctx, whereClause); - return getPersonList(parentcsid, partialTerm, ui); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getPersonList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Update person. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}/items/{itemcsid}") - public MultipartOutput updatePerson( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updatePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("updatePerson: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Person parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("updatePerson: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Person=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - theUpdate); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).update(ctx, itemcsid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in updatePerson", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Person csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete person. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the response - */ - @DELETE - @Path("{csid}/items/{itemcsid}") - public Response deletePerson( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("deletePerson with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("deletePerson: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Person parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("deletePerson: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Person=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - getRepositoryClient(ctx).delete(ctx, itemcsid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deletePerson", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Person itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - /** * *********************************************************************** * Contact parts - this is a sub-resource of Person (or "item") diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityDocumentModelHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityDocumentModelHandler.java index 887f46e1f..188cdbfc8 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityDocumentModelHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityDocumentModelHandler.java @@ -26,15 +26,13 @@ package org.collectionspace.services.person.nuxeo; import java.util.Iterator; import java.util.List; -import org.collectionspace.services.PersonAuthorityJAXBSchema; -import org.collectionspace.services.common.document.DocumentHandler.Action; -import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.person.PersonauthoritiesCommon; import org.collectionspace.services.person.PersonauthoritiesCommonList; import org.collectionspace.services.person.PersonauthoritiesCommonList.PersonauthorityListItem; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; -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; @@ -48,63 +46,9 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class PersonAuthorityDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityDocumentModelHandler { private final Logger logger = LoggerFactory.getLogger(PersonAuthorityDocumentModelHandler.class); - /** - * personAuthority is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private PersonauthoritiesCommon personAuthority; - /** - * personAuthorityList is stashed when handle is called - * for ACTION.GET_ALL - */ - private PersonauthoritiesCommonList personAuthorityList; - - - /** - * getCommonPart get associated personAuthority - * @return - */ - @Override - public PersonauthoritiesCommon getCommonPart() { - return personAuthority; - } - - /** - * setCommonPart set associated personAuthority - * @param personAuthority - */ - @Override - public void setCommonPart(PersonauthoritiesCommon personAuthority) { - this.personAuthority = personAuthority; - } - - /** - * getCommonPartList get associated personAuthority (for index/GET_ALL) - * @return - */ - @Override - public PersonauthoritiesCommonList getCommonPartList() { - return personAuthorityList; - } - - @Override - public void setCommonPartList(PersonauthoritiesCommonList personAuthorityList) { - this.personAuthorityList = personAuthorityList; - } - - @Override - public PersonauthoritiesCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - public void fillCommonPart(PersonauthoritiesCommon personAuthorityObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } @Override public PersonauthoritiesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { @@ -115,17 +59,18 @@ public class PersonAuthorityDocumentModelHandler //strategy...need to change to more efficient iterating in future List list = coList.getPersonauthorityListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); + String label = getServiceContext().getCommonPartLabel(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); PersonauthorityListItem ilistItem = new PersonauthorityListItem(); - ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - PersonAuthorityJAXBSchema.DISPLAY_NAME)); - ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - PersonAuthorityJAXBSchema.REF_NAME)); - ilistItem.setShortIdentifier((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - PersonAuthorityJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - PersonAuthorityJAXBSchema.VOCAB_TYPE)); + 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 = NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri(getServiceContextPath() + id); ilistItem.setCsid(id); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java index 1e1ef6d81..cf3b5e124 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java @@ -24,17 +24,14 @@ package org.collectionspace.services.person.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.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.PersonJAXBSchema; -import org.collectionspace.services.common.document.InvalidDocumentException; -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.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.person.PersonsCommon; import org.collectionspace.services.person.PersonsCommonList; @@ -43,8 +40,8 @@ import org.collectionspace.services.person.PersonsCommonList.PersonListItem; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; /** * PersonDocumentModelHandler @@ -57,49 +54,18 @@ import org.slf4j.LoggerFactory; * */ public class PersonDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityItemDocumentModelHandler { /** The logger. */ - private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class); + //private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class); /** * Common part schema label */ private static final String COMMON_PART_LABEL = "persons_common"; - /** - * person is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private PersonsCommon person; - /** - * personList is stashed when handle is called - * for ACTION.GET_ALL - */ - private PersonsCommonList personList; - - /** - * inAuthority is the parent OrgAuthority for this context - */ - private String inAuthority; - - /** - * Gets the in authority. - * - * @return the in authority - */ - public String getInAuthority() { - return inAuthority; - } - - /** - * Sets the in authority. - * - * @param inAuthority the new in authority - */ - public void setInAuthority(String inAuthority) { - this.inAuthority = inAuthority; - } - + public PersonDocumentModelHandler() { + super(COMMON_PART_LABEL); + } /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) @@ -197,40 +163,6 @@ public class PersonDocumentModelHandler return newStr.toString(); } - /** - * getCommonPart get associated person - * @return - */ - @Override - public PersonsCommon getCommonPart() { - return person; - } - - /** - * setCommonPart set associated person - * @param person - */ - @Override - public void setCommonPart(PersonsCommon person) { - this.person = person; - } - - /** - * getCommonPartList get associated person (for index/GET_ALL) - * @return - */ - @Override - public PersonsCommonList getCommonPartList() { - return personList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(PersonsCommonList personList) { - this.personList = personList; - } /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType) @@ -249,23 +181,6 @@ public class PersonDocumentModelHandler return unQObjectProperties; } - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public PersonsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(PersonsCommon personObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) */ diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 6f285fb76..595db523b 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -41,6 +41,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityResource; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -64,39 +65,26 @@ import org.slf4j.LoggerFactory; @Path("/vocabularies") @Consumes("multipart/mixed") @Produces("multipart/mixed") -public class VocabularyResource extends - AbstractMultiPartCollectionSpaceResourceImpl { +public class VocabularyResource extends + AuthorityResource { - /** The Constant vocabularyServiceName. */ private final static String vocabularyServiceName = "vocabularies"; private final static String VOCABULARIES_COMMON = "vocabularies_common"; - /** The Constant vocabularyItemServiceName. */ private final static String vocabularyItemServiceName = "vocabularyitems"; private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(VocabularyResource.class); - //FIXME retrieve client type from configuration - /** The Constant CLIENT_TYPE. */ - final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); - /** - * Instantiates a new vocabulary resource. - */ - public VocabularyResource() { - // do nothing - } - - /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() - */ - @Override - protected String getVersionString() { - /** The last change revision. */ - final String lastChangeRevision = "$LastChangedRevision$"; - return lastChangeRevision; - } + /** + * Instantiates a new VocabularyResource. + */ + public VocabularyResource() { + super(VocabulariesCommon.class, VocabularyResource.class, + VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON); + } /* (non-Javadoc) * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() @@ -106,656 +94,22 @@ public class VocabularyResource extends return vocabularyServiceName; } - /* (non-Javadoc) - * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() - */ - @Override - public Class getCommonPartClass() { - return VocabulariesCommon.class; - } - /** * Gets the item service name. * * @return the item service name */ + @Override public String getItemServiceName() { return vocabularyItemServiceName; } - /** - * Creates the item document handler. - * - * @param ctx the ctx - * @param inVocabulary the in vocabulary - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createItemDocumentHandler( - ServiceContext ctx, - String inVocabulary) - throws Exception { - VocabularyItemDocumentModelHandler docHandler; - - docHandler = (VocabularyItemDocumentModelHandler)createDocumentHandler(ctx, - ctx.getCommonPartLabel(getItemServiceName()), - VocabularyitemsCommon.class); - docHandler.setInAuthority(inVocabulary); - - return docHandler; - } - - /** - * Creates the vocabulary. - * - * @param input the input - * - * @return the response - */ - @POST - public Response createVocabulary(MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(input); - DocumentHandler handler = createDocumentHandler(ctx); - String csid = getRepositoryClient(ctx).create(ctx, handler); - //vocabularyObject.setCsid(csid); - UriBuilder path = UriBuilder.fromResource(VocabularyResource.class); - path.path("" + csid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createVocabulary", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the vocabulary. - * - * @param csid the csid - * - * @return the vocabulary - */ - @GET - @Path("{csid}") - public MultipartOutput getVocabulary(@PathParam("csid") String csid) { -// String idValue = null; - if (csid == null) { - logger.error("getVocabulary: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (logger.isDebugEnabled()) { - logger.debug("getVocabulary with path(id)=" + csid); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).get(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabulary", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabulary", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Vocabulary CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - - return result; - } - - /** - * Gets the vocabulary by name. - * - * @param specifier the specifier - * - * @return the vocabulary - */ - @GET - @Path("urn:cspace:name({specifier})") - public MultipartOutput getVocabularyByName(@PathParam("specifier") String specifier) { - if (specifier == null) { - logger.error("getVocabularyByName: missing name!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Vocabulary (missing specifier)").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - VOCABULARIES_COMMON+ - ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+specifier+"'"; - // We only get a single doc - if there are multiple, - // it is an error in use. - - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyByName with name=" + specifier); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyByName", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Vocabulary spec=" + specifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyByName", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Vocabulary spec:" + specifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the vocabulary list. - * - * @param ui the ui - * - * @return the vocabulary list - */ - @GET - @Produces("application/xml") - public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) { - VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = handler.getDocumentFilter(); - String nameQ = queryParams.getFirst("refName"); - if (nameQ != null) { - myFilter.setWhereClause("vocabularies_common:refName='" + nameQ + "'"); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getVocabularyList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return vocabularyObjectList; - } + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() + */ + @Override + public Class getCommonPartClass() { + return VocabulariesCommon.class; + } - /** - * Update vocabulary. - * - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}") - public MultipartOutput updateVocabulary( - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateVocabulary with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("updateVocabulary: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(theUpdate); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caugth exception in updateVocabulary", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete vocabulary. - * - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{csid}") - public Response deleteVocabulary(@PathParam("csid") String csid) { - - if (logger.isDebugEnabled()) { - logger.debug("deleteVocabulary with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("deleteVocabulary: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - ServiceContext ctx = createServiceContext(); - getRepositoryClient(ctx).delete(ctx, csid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteVocabulary", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Vocabulary csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - - /************************************************************************* - * VocabularyItem parts - this is a sub-resource of Vocabulary - * @param parentcsid - * @param input - * @return vocab item response - *************************************************************************/ - @POST - @Path("{csid}/items") - public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(getItemServiceName(), - input); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - String itemcsid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(VocabularyResource.class); - path.path(parentcsid + "/items/" + itemcsid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createVocabularyItem", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the vocabulary item. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the vocabulary item - */ - @GET - @Path("{csid}/items/{itemcsid}") - public MultipartOutput getVocabularyItem( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("getVocabularyItem: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on VocabularyItem csid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("getVocabularyItem: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on VocabularyItem itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).get(ctx, itemcsid, handler); - // TODO should we assert that the item is in the passed vocab? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyItem", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on VocabularyItem csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyItem", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the vocabulary item list. - * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui - * - * @return the vocabulary item list - */ - @GET - @Path("{csid}/items") - @Produces("application/xml") - public VocabularyitemsCommonList getVocabularyItemList( - @PathParam("csid") String parentcsid, - @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.getDocumentFilter(); - myFilter.setWhereClause( - VOCABULARYITEMS_COMMON + ":" - + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" - + "'" + parentcsid + "'"); - - // AND vocabularyitems_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = VOCABULARYITEMS_COMMON + ":" - + AuthorityItemJAXBSchema.DISPLAY_NAME - + IQueryManager.SEARCH_LIKE - + "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - if (logger.isDebugEnabled()) { - logger.debug("getVocabularyItemList filtered WHERE clause: " - + myFilter.getWhereClause()); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getVocabularyItemList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return vocabularyItemObjectList; - } - - - /** - * Gets the vocabulary item list. - * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui - * - * @return the vocabulary item list - */ - @GET - @Path("urn:cspace:name({specifier})/items") - @Produces("application/xml") - public VocabularyitemsCommonList getVocabularyItemListByVocabName( - @PathParam("specifier") String specifier, - @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - String whereClause = - VOCABULARIES_COMMON+ - ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+specifier+"'"; - // Need to get an Authority by name - ServiceContext ctx = createServiceContext(queryParams); - String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); - return getVocabularyItemList(parentcsid, partialTerm, ui); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getVocabularyItemListByVocabName", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - - - - /** - * Update vocabulary item. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}/items/{itemcsid}") - public MultipartOutput updateVocabularyItem( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("updateVocabularyItem: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on VocabularyItem parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("updateVocabularyItem: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on VocabularyItem=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - theUpdate); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).update(ctx, itemcsid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught DNF exception in updateVocabularyItem", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on VocabularyItem csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete vocabulary item. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the response - */ - @DELETE - @Path("{csid}/items/{itemcsid}") - public Response deleteVocabularyItem( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("deleteVocabularyItem: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on VocabularyItem parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("deleteVocabularyItem: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on VocabularyItem=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - getRepositoryClient(ctx).delete(ctx, itemcsid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteVocabulary", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on VocabularyItem itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } } diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java index ecb3222d3..1ee7ed359 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java @@ -50,69 +50,6 @@ public class VocabularyDocumentModelHandler /** The logger. */ private final Logger logger = LoggerFactory.getLogger(VocabularyDocumentModelHandler.class); - /** - * vocabulary is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - //private VocabulariesCommon vocabulary; - /** - * vocabularyList is stashed when handle is called - * for ACTION.GET_ALL - */ - //private VocabulariesCommonList vocabularyList; - - - /** - * getCommonPart get associated vocabulary - * @return - @Override - public VocabulariesCommon getCommonPart() { - return vocabulary; - } - */ - - /** - * setCommonPart set associated vocabulary - * @param vocabulary - @Override - public void setCommonPart(VocabulariesCommon vocabulary) { - this.vocabulary = vocabulary; - } - */ - - /** - * getCommonPartList get associated vocabulary (for index/GET_ALL) - * @return - @Override - public VocabulariesCommonList getCommonPartList() { - return vocabularyList; - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - @Override - public void setCommonPartList(VocabulariesCommonList vocabularyList) { - this.vocabularyList = vocabularyList; - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - @Override - public VocabulariesCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - */ - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - @Override - public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - */ /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java index d759a2e68..8585c63ec 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java @@ -25,13 +25,9 @@ package org.collectionspace.services.vocabulary.nuxeo; import java.util.Iterator; import java.util.List; -//import java.util.Map; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; -//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.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.vocabulary.VocabularyitemsCommon; @@ -53,6 +49,13 @@ public class VocabularyItemDocumentModelHandler private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class); + private static final String COMMON_PART_LABEL = "vocabularyitems_common"; + + public VocabularyItemDocumentModelHandler() { + super(COMMON_PART_LABEL); + } + + @Override public VocabularyitemsCommonList extractCommonPartList( DocumentWrapper wrapDoc) throws Exception { -- 2.47.3