From: Patrick Schmitz Date: Fri, 27 Aug 2010 06:33:10 +0000 (+0000) Subject: CSPACE-2542 Modified the handling of Authorities to support range of specifiers for... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=0375706b6099aa7dcd057bb98f96fdcabdc8ac86;p=tmp%2Fjakarta-migration.git CSPACE-2542 Modified the handling of Authorities to support range of specifiers for authority and item, across operations. Modified authorities that support contact sub-resources to support all specifier forms for the authority and item, across operations. Refactored the AuthorityResource classes for the authorities that support contact sub-resources, to simplify code and ensure consistent support. --- 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 index 4d822cee1..4b4b31793 100644 --- 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 @@ -78,14 +78,63 @@ import org.slf4j.LoggerFactory; public abstract class AuthorityResource extends AbstractMultiPartCollectionSpaceResourceImpl { - private Class authCommonClass; - private Class resourceClass; - private String authorityCommonSchemaName; - private String authorityItemCommonSchemaName; + protected Class authCommonClass; + protected Class resourceClass; + protected String authorityCommonSchemaName; + protected String authorityItemCommonSchemaName; final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); - + + final static String URN_PREFIX = "urn:cspace:"; + final static int URN_PREFIX_LEN = URN_PREFIX.length(); + final static String URN_PREFIX_NAME = "name("; + final static int URN_NAME_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_NAME.length(); + final static String URN_PREFIX_ID = "id("; + final static int URN_ID_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_ID.length(); + final Logger logger = LoggerFactory.getLogger(AuthorityResource.class); + + public enum SpecifierForm { CSID, URN_NAME }; + + public class Specifier { + public SpecifierForm form; + public String value; + Specifier(SpecifierForm form, String value) { + this.form = form; + this.value = value; + } + } + + protected Specifier getSpecifier(String specifierIn, String method, String op) throws WebApplicationException { + if (logger.isDebugEnabled()) { + logger.debug("getSpecifier called by: "+method+" with specifier: "+specifierIn); + } + if (specifierIn != null) { + if(!specifierIn.startsWith(URN_PREFIX)) { + // We'll assume it is a CSID and complain if it does not match + return new Specifier(SpecifierForm.CSID, specifierIn); + } else { + if(specifierIn.startsWith(URN_PREFIX_NAME, URN_PREFIX_LEN)) { + int closeParen = specifierIn.indexOf(')', URN_NAME_PREFIX_LEN); + if(closeParen>=0) { + return new Specifier(SpecifierForm.URN_NAME, + specifierIn.substring(URN_NAME_PREFIX_LEN, closeParen)); + } + } else if(specifierIn.startsWith(URN_PREFIX_ID, URN_PREFIX_LEN)) { + int closeParen = specifierIn.indexOf(')', URN_ID_PREFIX_LEN); + if(closeParen>=0) { + return new Specifier(SpecifierForm.CSID, + specifierIn.substring(URN_ID_PREFIX_LEN, closeParen)); + } + } + } + } + logger.error(method+": bad or missing specifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + op+" failed on bad or missing Authority specifier").type( + "text/plain").build(); + throw new WebApplicationException(response); + } /** * Instantiates a new Authority resource. @@ -97,7 +146,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { this.authorityCommonSchemaName = authorityCommonSchemaName; this.authorityItemCommonSchemaName = authorityItemCommonSchemaName; } - + public abstract String getItemServiceName(); /* (non-Javadoc) @@ -176,32 +225,49 @@ AbstractMultiPartCollectionSpaceResourceImpl { throw new WebApplicationException(response); } } + + protected String buildWhereForAuthByName(String name) { + return authorityCommonSchemaName+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ + "='"+name+"'"; + } + + protected String buildWhereForAuthItemByName(String name, String parentcsid) { + return + authorityItemCommonSchemaName+ + ":"+AuthorityItemJAXBSchema.SHORT_IDENTIFIER+ + "='"+name+"' AND " + + authorityItemCommonSchemaName + ":" + + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + + "'" + parentcsid + "'"; + } /** * Gets the authority. * - * @param csid the csid + * @param specifier either a CSID or one of the urn forms * * @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); - } + public MultipartOutput getAuthority(@PathParam("csid") String specifier) { MultipartOutput result = null; try { + Specifier spec = getSpecifier(specifier, "getAuthority", "GET"); ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).get(ctx, csid, handler); + if(spec.form==SpecifierForm.CSID) { + if (logger.isDebugEnabled()) { + logger.debug("getAuthority with csid=" + spec.value); + } + getRepositoryClient(ctx).get(ctx, spec.value, handler); + } else { + String whereClause = buildWhereForAuthByName(spec.value); + 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( @@ -212,7 +278,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { logger.debug("getAuthority", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Authority csid=" + csid).type( + "Get failed on Authority specifier=" + specifier).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { @@ -226,7 +292,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Authority CSID:" + csid + ": was not found.").type( + "Get failed, the requested Authority specifier:" + specifier + ": was not found.").type( "text/plain").build(); throw new WebApplicationException(response); } @@ -234,70 +300,6 @@ AbstractMultiPartCollectionSpaceResourceImpl { 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. * @@ -344,22 +346,20 @@ AbstractMultiPartCollectionSpaceResourceImpl { @PUT @Path("{csid}") public MultipartOutput updateAuthority( - @PathParam("csid") String csid, + @PathParam("csid") String specifier, 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 { + Specifier spec = getSpecifier(specifier, "updateAuthority", "UPDATE"); ServiceContext ctx = createServiceContext(theUpdate); DocumentHandler handler = createDocumentHandler(ctx); + String csid; + if(spec.form==SpecifierForm.CSID) { + csid = spec.value; + } else { + String whereClause = buildWhereForAuthByName(spec.value); + csid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } getRepositoryClient(ctx).update(ctx, csid, handler); result = (MultipartOutput) ctx.getOutput(); } catch (UnauthorizedException ue) { @@ -371,7 +371,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { logger.debug("caught exception in updateAuthority", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Authority csid=" + csid).type( + "Update failed on Authority specifier=" + specifier).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { @@ -428,17 +428,26 @@ AbstractMultiPartCollectionSpaceResourceImpl { } /************************************************************************* - * AuthorityItem parts - this is a sub-resource of Authority - * @param parentcsid - * @param input + * Create an AuthorityItem - this is a sub-resource of Authority + * @param parentspecifier either a CSID or one of the urn forms + * @param input the payload * @return Authority item response *************************************************************************/ @POST @Path("{csid}/items") - public Response createAuthorityItem(@PathParam("csid") String parentcsid, MultipartInput input) { + public Response createAuthorityItem(@PathParam("csid") String specifier, MultipartInput input) { try { - ServiceContext ctx = createServiceContext(getItemServiceName(), - input); + ServiceContext ctx = null; + Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM"); + String parentcsid; + if(spec.form==SpecifierForm.CSID) { + parentcsid = spec.value; + } else { + String whereClause = buildWhereForAuthByName(spec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName(), input); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); String itemcsid = getRepositoryClient(ctx).create(ctx, handler); UriBuilder path = UriBuilder.fromResource(resourceClass); @@ -466,39 +475,41 @@ AbstractMultiPartCollectionSpaceResourceImpl { /** * Gets the authority item. * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * * @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); - } + @PathParam("csid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier) { MultipartOutput result = null; try { + Specifier parentSpec = getSpecifier(parentspecifier, "getAuthorityItem(parent)", "GET_ITEM"); + Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItem(item)", "GET_ITEM"); // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).get(ctx, itemcsid, handler); + if(itemSpec.form==SpecifierForm.CSID) { + getRepositoryClient(ctx).get(ctx, itemSpec.value, handler); + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + DocumentFilter myFilter = new DocumentFilter(itemWhereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + } // TODO should we assert that the item is in the passed vocab? result = (MultipartOutput) ctx.getOutput(); } catch (UnauthorizedException ue) { @@ -510,7 +521,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { logger.debug("getAuthorityItem", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on AuthorityItem csid=" + itemcsid).type( + "Get failed on AuthorityItem specifier=" + itemspecifier).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { @@ -523,169 +534,22 @@ AbstractMultiPartCollectionSpaceResourceImpl { } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested AuthorityItem CSID:" + itemcsid + ": was not found.").type( + "Get failed, the requested AuthorityItem specifier:" + itemspecifier + ": 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+"' AND " - + authorityItemCommonSchemaName + ":" - + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" - + "'" + parentcsid + "'"; - - 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); - } - String authWhereClause = - authorityCommonSchemaName+ - ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+parentspecifier+"'"; - if (logger.isDebugEnabled()) { - logger.debug("getAuthorityItemByNameInNamedAuthority with parentspecifier=" - + parentspecifier + " and itemspecifier=" + itemspecifier); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(getServiceName()); - String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, authWhereClause); - String itemWhereClause = - authorityItemCommonSchemaName+ - ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+itemspecifier+"' AND " - + authorityItemCommonSchemaName + ":" - + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" - + "'" + parentcsid + "'"; - // Now that we have to create the service context for the Items, not the main service - ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = new DocumentFilter(itemWhereClause, 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. + * Gets the authorityItem list for the specified authority + * If partialPerm is specified, keywords will be ignored. * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui + * @param specifier either a CSID or one of the urn forms + * @param partialTerm if non-null, matches partial terms + * @param keywords if non-null, matches terms in the keyword index for items + * @param ui passed to include additional parameters, like pagination controls * * @return the authorityItem list */ @@ -693,15 +557,24 @@ AbstractMultiPartCollectionSpaceResourceImpl { @Path("{csid}/items") @Produces("application/xml") public AuthItemCommonList getAuthorityItemList( - @PathParam("csid") String parentcsid, + @PathParam("csid") String specifier, @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, @Context UriInfo ui) { try { + Specifier spec = getSpecifier(specifier, "getAuthorityItemList", "LIST"); MultivaluedMap queryParams = ui.getQueryParameters(); // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); + ServiceContext ctx = null; + String parentcsid; + if(spec.form==SpecifierForm.CSID) { + parentcsid = spec.value; + } else { + String whereClause = buildWhereForAuthByName(spec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); DocumentFilter myFilter = handler.getDocumentFilter(); myFilter.setWhereClause( @@ -740,49 +613,6 @@ AbstractMultiPartCollectionSpaceResourceImpl { } } - - /** - * 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, - @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, - @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, keywords, 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 @@ -790,8 +620,8 @@ AbstractMultiPartCollectionSpaceResourceImpl { * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. * @param parentcsid * - * @param csid the parent csid - * @param itemcsid the person csid + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param ui the ui * * @return the info for the referencing objects @@ -800,28 +630,36 @@ AbstractMultiPartCollectionSpaceResourceImpl { @Path("{csid}/items/{itemcsid}/refObjs") @Produces("application/xml") public AuthorityRefDocList getReferencingObjects( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, @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(); + Specifier parentSpec = getSpecifier(parentspecifier, + "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS"); + Specifier itemSpec = getSpecifier(itemspecifier, + "getReferencingObjects(item)", "GET_ITEM_REF_OBJS"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName(), queryParams); + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } // 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(); @@ -848,8 +686,8 @@ AbstractMultiPartCollectionSpaceResourceImpl { logger.debug("getReferencingObjects", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "GetReferencingObjects failed with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( + "GetReferencingObjects failed with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { // Includes DocumentException @@ -862,7 +700,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { } if (authRefDocList == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Item CSID:" + itemcsid + ": was not found.").type( + "Get failed, the requested Item CSID:" + itemspecifier + ": was not found.").type( "text/plain").build(); throw new WebApplicationException(response); } @@ -870,12 +708,11 @@ AbstractMultiPartCollectionSpaceResourceImpl { } /** - * Gets the authority refs for an Authority item. - * @param parentcsid + * Gets the authority terms used in the indicated Authority item. * - * @param csid The authority (parent) CSID. - * @param itemcsid The item CSID. - * @param ui + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param ui passed to include additional parameters, like pagination controls * * @return the authority refs for the Authority item. */ @@ -883,16 +720,35 @@ AbstractMultiPartCollectionSpaceResourceImpl { @Path("{csid}/items/{itemcsid}/authorityrefs") @Produces("application/xml") public AuthorityRefList getAuthorityItemAuthorityRefs( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, @Context UriInfo ui) { AuthorityRefList authRefList = null; try { + Specifier parentSpec = getSpecifier(parentspecifier, "getAuthorityItemAuthRefs(parent)", "GET_ITEM_AUTH_REFS"); + Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS"); + // 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); + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName(), queryParams); RemoteDocumentModelHandlerImpl handler = (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid); + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, itemcsid); List authRefFields = @@ -919,8 +775,8 @@ AbstractMultiPartCollectionSpaceResourceImpl { /** * Update authorityItem. * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param theUpdate the the update * * @return the multipart output @@ -928,31 +784,35 @@ AbstractMultiPartCollectionSpaceResourceImpl { @PUT @Path("{csid}/items/{itemcsid}") public MultipartOutput updateAuthorityItem( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, 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 { + Specifier parentSpec = getSpecifier(parentspecifier, + "updateAuthorityItem(parent)", "UPDATE_ITEM"); + Specifier itemSpec = getSpecifier(itemspecifier, + "updateAuthorityItem(item)", "UPDATE_ITEM"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + ctx = createServiceContext(getItemServiceName(), theUpdate); + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } // 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(); @@ -969,7 +829,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { logger.debug("caught DNF exception in updateAuthorityItem", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on AuthorityItem csid=" + itemcsid).type( + "Update failed on AuthorityItem csid=" + itemspecifier).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { @@ -1033,4 +893,5 @@ AbstractMultiPartCollectionSpaceResourceImpl { throw new WebApplicationException(response); } } + } diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java new file mode 100644 index 000000000..a1218f11f --- /dev/null +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -0,0 +1,489 @@ +/** + * 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.contact; + +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.AuthorityResource; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityResource.Specifier; +import org.collectionspace.services.common.vocabulary.AuthorityResource.SpecifierForm; +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.contact.ContactResource; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.contact.ContactJAXBSchema; +import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; +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.common.query.QueryManager; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.jboss.remoting.samples.chat.exceptions.InvalidArgumentException; +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 AuthorityResourceWithContacts. + */ +@Path("/vocabularies") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public abstract class AuthorityResourceWithContacts extends + AuthorityResource { + + /** The contact resource. */ + private ContactResource contactResource = new ContactResource(); + + final Logger logger = LoggerFactory.getLogger(AuthorityResourceWithContacts.class); + + /** + * Instantiates a new Authority resource. + */ + public AuthorityResourceWithContacts( + Class authCommonClass, Class resourceClass, + String authorityCommonSchemaName, String authorityItemCommonSchemaName) { + super(authCommonClass, resourceClass, + authorityCommonSchemaName, authorityItemCommonSchemaName); + } + + public abstract String getItemServiceName(); + + /** + * Gets the contact service name. + * + * @return the contact service name + */ + public String getContactServiceName() { + return contactResource.getServiceName(); + } + + /** + * Creates the contact document handler. + * + * @param ctx the ctx + * @param inAuthority the in authority + * @param inItem the in item + * + * @return the document handler + * + * @throws Exception the exception + */ + private DocumentHandler createContactDocumentHandler( + ServiceContext ctx, String inAuthority, + String inItem) throws Exception { + + ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler( + ctx, + ctx.getCommonPartLabel(getContactServiceName()), + ContactsCommon.class); + docHandler.setInAuthority(inAuthority); + docHandler.setInItem(inItem); + + return docHandler; + } + + /************************************************************************* + * Contact parts - this is a sub-resource of the AuthorityItem + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param input + * @return contact + *************************************************************************/ + @POST + @Path("{parentcsid}/items/{itemcsid}/contacts") + public Response createContact( + @PathParam("parentcsid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, + MultipartInput input) { + try { + Specifier parentSpec = getSpecifier(parentspecifier, + "createContact(parent)", "CREATE_ITEM_CONTACT"); + Specifier itemSpec = getSpecifier(itemspecifier, + "createContact(item)", "CREATE_ITEM_CONTACT"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + ctx = createServiceContext(getItemServiceName()); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } + // Note that we have to create the service context and document + // handler for the Contact service, not the main service. + ctx = createServiceContext(getContactServiceName(), input); + DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); + String csid = getRepositoryClient(ctx).create(ctx, handler); + UriBuilder path = UriBuilder.fromResource(resourceClass); + path.path("" + parentcsid + "/items/" + itemcsid + "/contacts/" + 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 createContact", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR) + .entity("Attempt to create Contact failed.") + .type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + /** + * Gets the contact list. + * + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param ui the ui + * + * @return the contact list + */ + @GET + @Produces({"application/xml"}) + @Path("{parentcsid}/items/{itemcsid}/contacts/") + public ContactsCommonList getContactList( + @PathParam("parentcsid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, + @Context UriInfo ui) { + ContactsCommonList contactObjectList = new ContactsCommonList(); + try { + Specifier parentSpec = getSpecifier(parentspecifier, + "createContact(parent)", "CREATE_ITEM_CONTACT"); + Specifier itemSpec = getSpecifier(itemspecifier, + "createContact(item)", "CREATE_ITEM_CONTACT"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + ctx = createServiceContext(getItemServiceName()); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } + MultivaluedMap queryParams = ui.getQueryParameters(); + ctx = createServiceContext(getContactServiceName(), queryParams); + DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); + DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); + myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + + ContactJAXBSchema.IN_AUTHORITY + + "='" + parentcsid + "'" + + IQueryManager.SEARCH_QUALIFIER_AND + + ContactJAXBSchema.CONTACTS_COMMON + ":" + + ContactJAXBSchema.IN_ITEM + + "='" + itemcsid + "'" ); + getRepositoryClient(ctx).getFiltered(ctx, handler); + contactObjectList = (ContactsCommonList) 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 getContactsList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return contactObjectList; + } + + /** + * Gets the contact. + * + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param csid the csid + * + * @return the contact + */ + @GET + @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") + public MultipartOutput getContact( + @PathParam("parentcsid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, + @PathParam("csid") String csid) { + MultipartOutput result = null; + try { + Specifier parentSpec = getSpecifier(parentspecifier, + "getContact(parent)", "GET_ITEM_CONTACT"); + Specifier itemSpec = getSpecifier(itemspecifier, + "getContact(item)", "GET_ITEM_CONTACT"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + ctx = createServiceContext(getItemServiceName()); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } + // Note that we have to create the service context and document + // handler for the Contact service, not the main service. + ctx = createServiceContext(getContactServiceName()); + DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); + 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("getContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.") + .type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getContact", e); + } + Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Get contact 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 Contact CSID:" + csid + ": was not found.") + .type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + + } + + /** + * Update contact. + * + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param csid the csid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") + public MultipartOutput updateContact( + @PathParam("parentcsid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, + @PathParam("csid") String csid, + MultipartInput theUpdate) { + MultipartOutput result = null; + try { + Specifier parentSpec = getSpecifier(parentspecifier, + "updateContact(parent)", "UPDATE_ITEM_CONTACT"); + Specifier itemSpec = getSpecifier(itemspecifier, + "updateContact(item)", "UPDATE_ITEM_CONTACT"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + ctx = createServiceContext(getItemServiceName()); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } + // Note that we have to create the service context and document + // handler for the Contact service, not the main service. + ctx = createServiceContext(getContactServiceName(), theUpdate); + DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); + 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 updateContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Contact csid=" + itemspecifier).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 contact. + * + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms + * @param csid the csid + * + * @return the response + */ + @DELETE + @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") + public Response deleteContact( + @PathParam("parentcsid") String parentspecifier, + @PathParam("itemcsid") String itemspecifier, + @PathParam("csid") String csid) { + try { + Specifier parentSpec = getSpecifier(parentspecifier, + "updateContact(parent)", "UPDATE_ITEM_CONTACT"); + Specifier itemSpec = getSpecifier(itemspecifier, + "updateContact(item)", "UPDATE_ITEM_CONTACT"); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = null; + String parentcsid; + if(parentSpec.form==SpecifierForm.CSID) { + parentcsid = parentSpec.value; + } else { + String whereClause = buildWhereForAuthByName(parentSpec.value); + ctx = createServiceContext(getServiceName()); + parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + } + String itemcsid; + if(itemSpec.form==SpecifierForm.CSID) { + itemcsid = itemSpec.value; + } else { + String itemWhereClause = + buildWhereForAuthItemByName(itemSpec.value, parentcsid); + ctx = createServiceContext(getItemServiceName()); + itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); + } + // Note that we have to create the service context for the + // Contact service, not the main service. + ctx = createServiceContext(getContactServiceName()); + 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 deleteContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Delete failed, the requested Contact CSID:" + csid + ": was not found.") + .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/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java index e2fe04e30..bf5145db6 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -307,6 +307,12 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { return orgAuthorityProxy.deleteItem(vcsid, csid); } + /*************************************************************************** + * + * Contact sub-resource interfaces + * + ***************************************************************************/ + /** * Creates the contact. * @@ -320,6 +326,49 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { return orgAuthorityProxy.createContact(parentcsid, itemcsid, multipart); } + /** + * Creates the contact. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @param multipart + * @return the client response + */ + public ClientResponse createContactForNamedItem( + String parentcsid, + String itemspecifier, + MultipartOutput multipart) { + return orgAuthorityProxy.createContactForNamedItem(parentcsid, itemspecifier, multipart); + } + /** + * Creates the contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @param multipart + * @return the client response + */ + public ClientResponse createContactForItemInNamedAuthority( + String parentspecifier, + String itemcsid, + MultipartOutput multipart) { + return orgAuthorityProxy.createContactForItemInNamedAuthority(parentspecifier, itemcsid, multipart); + } + /** + * Creates the contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param multipart + * @return the client response + */ + public ClientResponse createContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + MultipartOutput multipart) { + return orgAuthorityProxy.createContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, multipart); + } + /** * Read contact. * @@ -332,6 +381,52 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { String itemcsid, String csid) { return orgAuthorityProxy.readContact(parentcsid, itemcsid, csid); } + + /** + * Read contact. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid + * @return the client response + */ + public ClientResponse readContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid){ + return orgAuthorityProxy.readContactForNamedItem(parentcsid, itemspecifier, csid); + } + + /** + * Read contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @param csid + * @return the client response + */ + public ClientResponse readContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid){ + return orgAuthorityProxy.readContactInNamedAuthority(parentspecifier, itemcsid, csid); + } + + /** + * Read contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid + * @return the client response + */ + public ClientResponse readContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid){ + return orgAuthorityProxy.readContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, csid); + } + /** * Read contact list. @@ -344,6 +439,46 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { String itemcsid) { return orgAuthorityProxy.readContactList(parentcsid, itemcsid); } + + /** + * Read contact list. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @return the client response + */ + public ClientResponse readContactListForNamedItem( + String parentcsid, + String itemspecifier){ + return orgAuthorityProxy.readContactList(parentcsid, itemspecifier); + } + + /** + * Read contact list. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @return the client response + */ + public ClientResponse readContactListForItemInNamedAuthority( + String parentspecifier, + String itemcsid){ + return orgAuthorityProxy.readContactList(parentspecifier, itemcsid); + } + + /** + * Read contact list. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @return the client response + */ + public ClientResponse readContactListForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier){ + return orgAuthorityProxy.readContactList(parentspecifier, itemspecifier); + } + /** * Update contact. @@ -358,6 +493,58 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { String itemcsid, String csid, MultipartOutput multipart) { return orgAuthorityProxy.updateContact(parentcsid, itemcsid, csid, multipart); } + + /** + * Update contact. + * + * @param parentcsid the parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid, + MultipartOutput multipart) { + return orgAuthorityProxy.updateContactForNamedItem(parentcsid, itemspecifier, csid, multipart); + } + + /** + * Update contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid the itemcsid + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid, + MultipartOutput multipart) { + return orgAuthorityProxy.updateContactInNamedAuthority(parentspecifier, itemcsid, csid, multipart); + } + + /** + * Update contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid, + MultipartOutput multipart) { + return orgAuthorityProxy.updateContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, csid, multipart); + } + /** * Delete contact. @@ -372,5 +559,53 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { return orgAuthorityProxy.deleteContact(parentcsid, itemcsid, csid); } + + /** + * Delete contact. + * + * @param parentcsid the parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid) { + return orgAuthorityProxy.deleteContactForNamedItem(parentcsid, + itemspecifier, csid); + } + + /** + * Delete contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid the itemcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid) { + return orgAuthorityProxy.deleteContactInNamedAuthority(parentspecifier, + itemcsid, csid); + } + + /** + * Delete contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid) { + return orgAuthorityProxy.deleteContactForNamedItemInNamedAuthority(parentspecifier, + itemspecifier, csid); + } } diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java index 162c58572..3b2f939b2 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java @@ -141,6 +141,24 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { ClientResponse readContactList( @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid); + @GET + @Produces({"application/xml"}) + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse readContactListForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier); + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/") + ClientResponse readContactListForItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid); + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse readContactListForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier); //(C)reate Contact @POST @@ -149,6 +167,24 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, MultipartOutput multipart); + @POST + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse createContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + MultipartOutput multipart); + @POST + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/") + ClientResponse createContactForItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + MultipartOutput multipart); + @POST + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse createContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + MultipartOutput multipart); //(R)ead Contact @GET @@ -157,6 +193,24 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid); + @GET + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse readContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); + @GET + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse readContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + @GET + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse readContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); //(U)pdate Contact @PUT @@ -166,6 +220,27 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid, MultipartOutput multipart); + @PUT + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse updateContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid, + MultipartOutput multipart); + @PUT + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse updateContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid, + MultipartOutput multipart); + @PUT + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse updateContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid, + MultipartOutput multipart); //(D)elete Contact @DELETE @@ -174,5 +249,23 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid); + @DELETE + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse deleteContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); + @DELETE + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse deleteContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + @DELETE + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse deleteContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); } 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 1ce48b157..a8da5723a 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 @@ -23,50 +23,12 @@ */ package org.collectionspace.services.organization; -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.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.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.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.query.IQueryManager; -import org.collectionspace.services.common.repository.RepositoryClient; -import org.collectionspace.services.contact.ContactResource; -import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; -import org.collectionspace.services.contact.ContactJAXBSchema; -import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; -import org.collectionspace.services.common.security.UnauthorizedException; -import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.contact.AuthorityResourceWithContacts; import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler; -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; @@ -77,7 +39,7 @@ import org.slf4j.LoggerFactory; @Consumes("multipart/mixed") @Produces("multipart/mixed") public class OrgAuthorityResource extends - AuthorityResource { private final static String orgAuthorityServiceName = "orgauthorities"; @@ -88,9 +50,6 @@ public class OrgAuthorityResource extends final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class); - /** The contact resource. */ - private ContactResource contactResource = new ContactResource(); - /** * Instantiates a new org authority resource. */ @@ -123,327 +82,4 @@ public class OrgAuthorityResource extends public Class getCommonPartClass() { return OrgauthoritiesCommon.class; } - - /** - * Gets the contact service name. - * - * @return the contact service name - */ - public String getContactServiceName() { - return contactResource.getServiceName(); - } - - /** - * Creates the contact document handler. - * - * @param ctx the ctx - * @param inAuthority the in authority - * @param inItem the in item - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createContactDocumentHandler( - ServiceContext ctx, String inAuthority, - String inItem) throws Exception { - - ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler( - ctx, - ctx.getCommonPartLabel(getContactServiceName()), - ContactsCommon.class); - docHandler.setInAuthority(inAuthority); - docHandler.setInItem(inItem); - - return docHandler; - } - - /************************************************************************* - * Contact parts - this is a sub-resource of Organization (or "item") - * @param parentcsid - * @param itemcsid - * @param input - * @return contact - *************************************************************************/ - @POST - @Path("{parentcsid}/items/{itemcsid}/contacts") - public Response createContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput input) { - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName(), input); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - String csid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class); - path.path("" + parentcsid + "/items/" + itemcsid + "/contacts/" + 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 createContact", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR) - .entity("Attempt to create Contact failed.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - - /** - * Gets the contact list. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param ui the ui - * - * @return the contact list - */ - @GET - @Produces({"application/xml"}) - @Path("{parentcsid}/items/{itemcsid}/contacts/") - public ContactsCommonList getContactList( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - ContactsCommonList contactObjectList = new ContactsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getContactServiceName(), - queryParams); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); - myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_AUTHORITY + - "='" + parentcsid + "'" + - IQueryManager.SEARCH_QUALIFIER_AND + - ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_ITEM + - "='" + itemcsid + "'" ); - getRepositoryClient(ctx).getFiltered(ctx, handler); - contactObjectList = (ContactsCommonList) 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 getContactsList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return contactObjectList; - } - - /** - * Gets the contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * - * @return the contact - */ - @GET - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public MultipartOutput getContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid) { - MultipartOutput result = null; - if (logger.isDebugEnabled()) { - logger.debug("getContact with parentCsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName()); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - 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("getContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getContact", e); - } - Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Get contact 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 Contact CSID:" + csid + ": was not found.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - - } - - /** - * Update contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public MultipartOutput updateContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateContact with parentcsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - if (parentcsid == null || parentcsid.trim().isEmpty()) { - logger.error("updateContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || itemcsid.trim().isEmpty()) { - logger.error("updateContact: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (csid == null || csid.trim().isEmpty()) { - logger.error("updateContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName(), theUpdate); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - 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 updateContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Contact 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 contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public Response deleteContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid) { - if (logger.isDebugEnabled()) { - logger.debug("deleteContact with parentCsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - if (parentcsid == null || parentcsid.trim().isEmpty()) { - logger.error("deleteContact: missing parentcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || itemcsid.trim().isEmpty()) { - logger.error("deleteContact: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (csid == null || csid.trim().isEmpty()) { - logger.error("deleteContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the - // Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName()); - 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 deleteContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Delete failed, the requested Contact CSID:" + csid + ": was not found.") - .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/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java index 4e9ef1fea..8e8cd940e 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java @@ -27,6 +27,13 @@ package org.collectionspace.services.client; //import javax.ws.rs.PathParam; +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.core.Response; //import org.collectionspace.services.common.authorityref.AuthorityRefList; @@ -46,6 +53,22 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; /** * The Class PersonAuthorityClient. */ +/** + * @author pschmitz + * + */ +/** + * @author pschmitz + * + */ +/** + * @author pschmitz + * + */ +/** + * @author pschmitz + * + */ public class PersonAuthorityClient extends AbstractServiceClientImpl { /* (non-Javadoc) @@ -296,6 +319,12 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.deleteItem(vcsid, csid); } + /*************************************************************************** + * + * Contact sub-resource interfaces + * + ***************************************************************************/ + /** * Creates the contact. * @@ -309,6 +338,49 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.createContact(parentcsid, itemcsid, multipart); } + /** + * Creates the contact. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @param multipart + * @return the client response + */ + public ClientResponse createContactForNamedItem( + String parentcsid, + String itemspecifier, + MultipartOutput multipart) { + return personAuthorityProxy.createContactForNamedItem(parentcsid, itemspecifier, multipart); + } + /** + * Creates the contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @param multipart + * @return the client response + */ + public ClientResponse createContactForItemInNamedAuthority( + String parentspecifier, + String itemcsid, + MultipartOutput multipart) { + return personAuthorityProxy.createContactForItemInNamedAuthority(parentspecifier, itemcsid, multipart); + } + /** + * Creates the contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param multipart + * @return the client response + */ + public ClientResponse createContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + MultipartOutput multipart) { + return personAuthorityProxy.createContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, multipart); + } + /** * Read contact. * @@ -321,6 +393,52 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { String itemcsid, String csid) { return personAuthorityProxy.readContact(parentcsid, itemcsid, csid); } + + /** + * Read contact. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid + * @return the client response + */ + public ClientResponse readContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid){ + return personAuthorityProxy.readContactForNamedItem(parentcsid, itemspecifier, csid); + } + + /** + * Read contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @param csid + * @return the client response + */ + public ClientResponse readContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid){ + return personAuthorityProxy.readContactInNamedAuthority(parentspecifier, itemcsid, csid); + } + + /** + * Read contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid + * @return the client response + */ + public ClientResponse readContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid){ + return personAuthorityProxy.readContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, csid); + } + /** * Read contact list. @@ -333,6 +451,46 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { String itemcsid) { return personAuthorityProxy.readContactList(parentcsid, itemcsid); } + + /** + * Read contact list. + * + * @param parentcsid + * @param itemspecifier (shortIdentifier) + * @return the client response + */ + public ClientResponse readContactListForNamedItem( + String parentcsid, + String itemspecifier){ + return personAuthorityProxy.readContactList(parentcsid, itemspecifier); + } + + /** + * Read contact list. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid + * @return the client response + */ + public ClientResponse readContactListForItemInNamedAuthority( + String parentspecifier, + String itemcsid){ + return personAuthorityProxy.readContactList(parentspecifier, itemcsid); + } + + /** + * Read contact list. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @return the client response + */ + public ClientResponse readContactListForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier){ + return personAuthorityProxy.readContactList(parentspecifier, itemspecifier); + } + /** * Update contact. @@ -347,6 +505,58 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { String itemcsid, String csid, MultipartOutput multipart) { return personAuthorityProxy.updateContact(parentcsid, itemcsid, csid, multipart); } + + /** + * Update contact. + * + * @param parentcsid the parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid, + MultipartOutput multipart) { + return personAuthorityProxy.updateContactForNamedItem(parentcsid, itemspecifier, csid, multipart); + } + + /** + * Update contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid the itemcsid + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid, + MultipartOutput multipart) { + return personAuthorityProxy.updateContactInNamedAuthority(parentspecifier, itemcsid, csid, multipart); + } + + /** + * Update contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid, + MultipartOutput multipart) { + return personAuthorityProxy.updateContactForNamedItemInNamedAuthority(parentspecifier, itemspecifier, csid, multipart); + } + /** * Delete contact. @@ -361,5 +571,53 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.deleteContact(parentcsid, itemcsid, csid); } + + /** + * Delete contact. + * + * @param parentcsid the parentcsid + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactForNamedItem( + String parentcsid, + String itemspecifier, + String csid) { + return personAuthorityProxy.deleteContactForNamedItem(parentcsid, + itemspecifier, csid); + } + + /** + * Delete contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemcsid the itemcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactInNamedAuthority( + String parentspecifier, + String itemcsid, + String csid) { + return personAuthorityProxy.deleteContactInNamedAuthority(parentspecifier, + itemcsid, csid); + } + + /** + * Delete contact. + * + * @param parentspecifier (shortIdentifier) + * @param itemspecifier (shortIdentifier) + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContactForNamedItemInNamedAuthority( + String parentspecifier, + String itemspecifier, + String csid) { + return personAuthorityProxy.deleteContactForNamedItemInNamedAuthority(parentspecifier, + itemspecifier, csid); + } } diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java index 8acd9e80b..e0d3335bd 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java @@ -124,13 +124,31 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @Path("/{vcsid}/items/{csid}") ClientResponse deleteItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); - // List Contacts + // List Contacts @GET @Produces({"application/xml"}) @Path("/{parentcsid}/items/{itemcsid}/contacts/") ClientResponse readContactList( @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid); + @GET + @Produces({"application/xml"}) + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse readContactListForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier); + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/") + ClientResponse readContactListForItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid); + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse readContactListForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier); //(C)reate Contact @POST @@ -139,6 +157,24 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, MultipartOutput multipart); + @POST + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse createContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + MultipartOutput multipart); + @POST + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/") + ClientResponse createContactForItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + MultipartOutput multipart); + @POST + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/") + ClientResponse createContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + MultipartOutput multipart); //(R)ead Contact @GET @@ -147,6 +183,24 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid); + @GET + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse readContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); + @GET + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse readContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + @GET + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse readContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); //(U)pdate Contact @PUT @@ -156,6 +210,27 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid, MultipartOutput multipart); + @PUT + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse updateContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid, + MultipartOutput multipart); + @PUT + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse updateContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid, + MultipartOutput multipart); + @PUT + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse updateContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid, + MultipartOutput multipart); //(D)elete Contact @DELETE @@ -164,5 +239,22 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid, @PathParam("csid") String csid); - + @DELETE + @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse deleteContactForNamedItem( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); + @DELETE + @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/{csid}") + ClientResponse deleteContactInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + @DELETE + @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/{csid}") + ClientResponse deleteContactForNamedItemInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier, + @PathParam("csid") String csid); } 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 8e4ee59c0..001a77550 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 @@ -23,49 +23,13 @@ */ package org.collectionspace.services.person; -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.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.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; -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.vocabulary.RefNameServiceUtils; -import org.collectionspace.services.contact.ContactResource; -import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; -import org.collectionspace.services.contact.ContactJAXBSchema; -import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; +import org.collectionspace.services.contact.AuthorityResourceWithContacts; import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler; -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; @@ -76,7 +40,7 @@ import org.slf4j.LoggerFactory; @Consumes("multipart/mixed") @Produces("multipart/mixed") public class PersonAuthorityResource extends - AuthorityResource { private final static String personAuthorityServiceName = "personauthorities"; @@ -86,12 +50,6 @@ public class PersonAuthorityResource extends private final static String PERSONS_COMMON = "persons_common"; 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(); - - /** The contact resource. */ - private ContactResource contactResource = new ContactResource(); /** * Instantiates a new person authority resource. @@ -124,325 +82,4 @@ public class PersonAuthorityResource extends return PersonauthoritiesCommon.class; } - /** - * Gets the contact service name. - * - * @return the contact service name - */ - public String getContactServiceName() { - return contactResource.getServiceName(); - } - - /** - * Creates the contact document handler. - * - * @param ctx the ctx - * @param inAuthority the in authority - * @param inItem the in item - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createContactDocumentHandler( - ServiceContext ctx, String inAuthority, - String inItem) throws Exception { - ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler(ctx, - ctx.getCommonPartLabel(getContactServiceName()), - ContactsCommon.class); - docHandler.setInAuthority(inAuthority); - docHandler.setInItem(inItem); - - return docHandler; - } - - /** - * *********************************************************************** - * Contact parts - this is a sub-resource of Person (or "item") - * ***********************************************************************. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param input the input - * @return the response - */ - @POST - @Path("{parentcsid}/items/{itemcsid}/contacts") - public Response createContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput input) { - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName(), input); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - String csid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class); - path.path("" + parentcsid + "/items/" + itemcsid + "/contacts/" + 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 createContact", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR) - .entity("Attempt to create Contact failed.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the contact list. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param ui the ui - * - * @return the contact list - */ - @GET - @Produces({"application/xml"}) - @Path("{parentcsid}/items/{itemcsid}/contacts/") - public ContactsCommonList getContactList( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - ContactsCommonList contactObjectList = new ContactsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getContactServiceName(), - queryParams); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - handler.getDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_AUTHORITY + - "='" + parentcsid + "'" + - " AND " + - ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_ITEM + - "='" + itemcsid + "'" ); - getRepositoryClient(ctx).getFiltered(ctx, handler); - contactObjectList = (ContactsCommonList) 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 getContactsList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return contactObjectList; - } - - /** - * Gets the contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * - * @return the contact - */ - @GET - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public MultipartOutput getContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid) { - MultipartOutput result = null; - if (logger.isDebugEnabled()) { - logger.debug("getContact with parentCsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName()); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - 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("getContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getContact", e); - } - Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Get contact 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 Contact CSID:" + csid + ": was not found.") - .type("text/plain").build(); - throw new WebApplicationException(response); - } - - return result; - } - - /** - * Update contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public MultipartOutput updateContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateContact with parentcsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - if (parentcsid == null || parentcsid.trim().isEmpty()) { - logger.error("updateContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || itemcsid.trim().isEmpty()) { - logger.error("updateContact: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (csid == null || csid.trim().isEmpty()) { - logger.error("updateContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Contact=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context and document - // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName(), - theUpdate); - DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - 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 updateContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Contact 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 contact. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}") - public Response deleteContact( - @PathParam("parentcsid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @PathParam("csid") String csid) { - if (logger.isDebugEnabled()) { - logger.debug("deleteContact with parentCsid=" + parentcsid + - " itemcsid=" + itemcsid + " csid=" + csid); - } - if (parentcsid == null || parentcsid.trim().isEmpty()) { - logger.error("deleteContact: missing parentcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || itemcsid.trim().isEmpty()) { - logger.error("deleteContact: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (csid == null || csid.trim().isEmpty()) { - logger.error("deleteContact: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete contact failed on csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the - // Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName()); - 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 deleteContact", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Delete failed, the requested Contact CSID:" + csid + ": was not found.") - .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); - } - } }