@Consumes("application/xml")
@Produces("application/xml")
public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemCommonList, AuthItemHandler>
- //extends ResourceBase {
- extends AbstractMultiPartCollectionSpaceResourceImpl {
+ extends ResourceBase {
+ //extends AbstractMultiPartCollectionSpaceResourceImpl {
protected Class<AuthCommon> authCommonClass;
protected Class<?> resourceClass;
public abstract String getItemServiceName();
- /* (non-Javadoc)
- * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
- */
@Override
protected String getVersionString() {
- /** The last change revision. */
- final String lastChangeRevision = "$LastChangedRevision: 2617 $";
- return lastChangeRevision;
+ return "$LastChangedRevision: 2617 $";
}
- /* (non-Javadoc)
- * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
- */
@Override
public Class<AuthCommon> getCommonPartClass() {
return authCommonClass;
docHandler.setInAuthority(inAuthority);
docHandler.setAuthorityRefNameBase(authorityRefNameBase);
- return (DocumentHandler)docHandler;
+ return docHandler;
}
public String getAuthShortIdentifier(
AuthorityDocumentModelHandler<?,?> handler =
(AuthorityDocumentModelHandler<?,?>)createDocumentHandler(ctx);
shortIdentifier = handler.getShortIdentifier(wrapDoc, authorityCommonSchemaName);
- } catch (DocumentNotFoundException dnfe) {
- throw dnfe;
- } catch (IllegalArgumentException iae) {
- throw iae;
- } catch (DocumentException de) {
- throw de;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Caught exception ", e);
return authority.toString();
}
+ public static class CsidAndShortIdentifier {
+ String CSID;
+ String shortIdentifier;
+ }
+ public String lookupParentCSID (String parentspecifier, String method, String op, MultivaluedMap<String, String> queryParams)
+ throws Exception {
+ CsidAndShortIdentifier tempResult = lookupParentCSIDAndShortIdentifer(parentspecifier, method, op, queryParams);
+ return tempResult.CSID;
+ }
+
+ public CsidAndShortIdentifier lookupParentCSIDAndShortIdentifer (String parentspecifier, String method, String op, MultivaluedMap<String, String> queryParams)
+ throws Exception {
+ CsidAndShortIdentifier result = new CsidAndShortIdentifier();
+ Specifier parentSpec = getSpecifier(parentspecifier, method, op);
+ // Note that we have to create the service context for the Items, not the main service
+ String parentcsid;
+ String parentShortIdentifier;
+ if(parentSpec.form==SpecifierForm.CSID) {
+ parentShortIdentifier = null;
+ parentcsid = parentSpec.value;
+ // Uncomment when app layer is ready to integrate
+ // parentShortIdentifier = FETCH_SHORT_ID;
+ } else {
+ parentShortIdentifier = parentSpec.value;
+ String whereClause = buildWhereForAuthByName(parentSpec.value);
+ ServiceContext ctx = createServiceContext(getServiceName(), queryParams);
+ parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
+ }
+ result.CSID = parentcsid;
+ return result;
+ }
+
+ public String lookupItemCSID (String itemspecifier, String parentcsid, String method, String op, ServiceContext ctx)
+ throws DocumentException {
+ String itemcsid;
+ Specifier itemSpec = getSpecifier(itemspecifier, method, op);
+ if(itemSpec.form==SpecifierForm.CSID) {
+ itemcsid = itemSpec.value;
+ } else {
+ String itemWhereClause = buildWhereForAuthItemByName(itemSpec.value, parentcsid);
+ itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause); //FIXME: REM - Should we be looking for the 'wf_deleted' query param and filtering on it?
+ }
+ return itemcsid;
+ }
- /**
- * Creates the authority.
- *
- * @return the response
- */
@POST
public Response createAuthority(String xmlPayload) {
try {
*/
@GET
@Path("{csid}")
- public byte[] getAuthority(
+ @Override
+ public byte[] get( // getAuthority(
@Context UriInfo ui,
@PathParam("csid") String specifier) {
PoxPayloadOut result = null;
try {
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- Specifier spec = getSpecifier(specifier, "getAuthority", "GET");
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
- DocumentHandler handler = createDocumentHandler(ctx);
- if(spec.form == SpecifierForm.CSID) {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+ DocumentHandler handler = createDocumentHandler(ctx);
+
+ Specifier spec = getSpecifier(specifier, "getAuthority", "GET");
+ if(spec.form == SpecifierForm.CSID) {
if (logger.isDebugEnabled()) {
logger.debug("getAuthority with csid=" + spec.value);
}
getRepositoryClient(ctx).get(ctx, handler);
}
result = ctx.getOutput();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("getAuthority", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed on Authority specifier=" + specifier).type(
- "text/plain").build();
- throw new WebApplicationException(response);
+
} catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("getAuthority", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
- throw new WebApplicationException(response);
+ throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier);
}
if (result == null) {
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
return (AuthCommonList) handler.getCommonPartList();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in getAuthorityList", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
- throw new WebApplicationException(response);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.GET_FAILED);
}
}
@DELETE
@Path("{csid}")
public Response deleteAuthority(@PathParam("csid") String csid) {
-
if (logger.isDebugEnabled()) {
logger.debug("deleteAuthority with csid=" + csid);
}
- if (csid == null || "".equals(csid)) {
- logger.error("deleteAuthority: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on Authority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
try {
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+ ensureCSID(csid, ServiceMessages.DELETE_FAILED, "Authority.csid");
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("caught exception in deleteAuthority", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Delete failed on Authority csid=" + csid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
} catch (Exception e) {
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
- throw new WebApplicationException(response);
+ throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid);
}
-
}
/*************************************************************************
@Path("{csid}/items")
public Response createAuthorityItem(@Context UriInfo ui, @PathParam("csid") String specifier, String xmlPayload) {
try {
-
PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
- Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM");
- String parentcsid;
- String parentShortIdentifier;
- if(spec.form==SpecifierForm.CSID) {
- parentcsid = spec.value;
- // Uncomment when app layer is ready to integrate
- // parentShortIdentifier = FETCH_SHORT_ID;
- parentShortIdentifier = null;
- } else {
- parentShortIdentifier = spec.value;
- String whereClause = buildWhereForAuthByName(spec.value);
- ctx = createServiceContext(getServiceName());
- parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
- }
- ctx = createServiceContext(getItemServiceName(), input);
+ ServiceContext ctx = createServiceContext(getItemServiceName(), input);
ctx.setUriInfo(ui); //Laramie
- // Note: must have the parentShortId, to do the create.
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, parentShortIdentifier);
+
+ // Note: must have the parentShortId, to do the create.
+ CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(specifier,"createAuthorityItem", "CREATE_ITEM", null);
+ DocumentHandler handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(resourceClass);
- path.path(parentcsid + "/items/" + itemcsid);
+ path.path(parent.CSID + "/items/" + itemcsid);
Response response = Response.created(path.build()).build();
-
- //updateRelations(ui, itemcsid, input);
-
return response;
} catch (Exception e) {
- //TODO: if e is 400 type error, then call throwWebAppException(400,...);
throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
}
}
return result.getBytes();
}
-
+
/**
* Gets the authority item.
*
try {
JaxRsContext jaxRsContext = new JaxRsContext(request, ui);
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ String parentcsid = lookupParentCSID(parentspecifier, "getAuthorityItem(parent)", "GET_ITEM", queryParams);
- 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
- RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
- String parentcsid;
- if(parentSpec.form==SpecifierForm.CSID) {
- parentcsid = parentSpec.value;
- } else {
- String whereClause = buildWhereForAuthByName(parentSpec.value);
- ctx = (RemoteServiceContext)createServiceContext(getServiceName(), queryParams);
- parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
- }
+ RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
ctx = (RemoteServiceContext)createServiceContext(getItemServiceName(), queryParams);
ctx.setJaxRsContext(jaxRsContext);
ctx.setUriInfo(ui); //ARG! must pass this or subsequent calls will not have a ui.
// We omit the parentShortId, only needed when doing a create...
- DocumentHandler handler = createItemDocumentHandler(ctx,
- parentcsid, null);
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
+
+ Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItem(item)", "GET_ITEM");
if(itemSpec.form==SpecifierForm.CSID) {
getRepositoryClient(ctx).get(ctx, itemSpec.value, handler);
} else {
return result.getBytes();
}
-
/**
* Gets the authorityItem list for the specified authority
* If partialPerm is specified, keywords will be ignored.
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
@Context UriInfo ui) {
try {
- Specifier spec = getSpecifier(specifier, "getAuthorityItemList", "LIST");
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- // Note that docType defaults to the ServiceName, so we're fine with that.
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
- String parentcsid;
- if(spec.form==SpecifierForm.CSID) {
- parentcsid = spec.value;
- } else {
- String whereClause = buildWhereForAuthByName(spec.value);
- ctx = createServiceContext(getServiceName(), queryParams);
- parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
- }
+ // Note that docType defaults to the ServiceName, so we're fine with that.
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
+
+ String parentcsid = lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams);
+
ctx = createServiceContext(getItemServiceName(), queryParams);
// We omit the parentShortId, only needed when doing a create...
DocumentHandler handler = createItemDocumentHandler(ctx,
AuthorityRefDocList authRefDocList = null;
try {
MultivaluedMap<String, String> 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<PoxPayloadIn, PoxPayloadOut> ctx = null;
- String parentcsid;
- if(parentSpec.form==SpecifierForm.CSID) {
- parentcsid = parentSpec.value;
- } else {
- String whereClause = buildWhereForAuthByName(parentSpec.value);
- ctx = createServiceContext(getServiceName(), queryParams);
- parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); //FIXME: REM - If the parent is soft-deleted should we still try to find the item?
- }
- 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); //FIXME: REM - Should we be looking for the 'wf_deleted' query param and filtering on it?
- }
- // Note that we have to create the service context for the Items, not the main service
+
+ String parentcsid = lookupParentCSID(parentspecifier, "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS", queryParams);
+
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), queryParams);
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS", ctx);
+
+ // Note that we have to create the service context for the Items, not the main service
// We omit the parentShortId, only needed when doing a create...
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
RepositoryClient repoClient = getRepositoryClient(ctx);
@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<String, String> queryParams = ui.getQueryParameters();
ServiceContext<PoxPayloadIn, PoxPayloadOut> 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 parentcsid = lookupParentCSID(parentspecifier, "getAuthorityItemAuthRefs(parent)", "GET_ITEM_AUTH_REFS", queryParams);
+
ctx = createServiceContext(getItemServiceName(), queryParams);
- // We omit the parentShortId, only needed when doing a create...
+ // We omit the parentShortId, only needed when doing a create...
RemoteDocumentModelHandlerImpl handler =
- (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx,
- parentcsid, null);
- String itemcsid;
- if(itemSpec.form==SpecifierForm.CSID) {
- itemcsid = itemSpec.value;
- } else {
- String itemWhereClause =
- buildWhereForAuthItemByName(itemSpec.value, parentcsid);
- itemcsid = getRepositoryClient(ctx).findDocCSID(ctx, itemWhereClause);
- }
- DocumentWrapper<DocumentModel> docWrapper =
- getRepositoryClient(ctx).getDoc(ctx, itemcsid);
+ (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid, null);
+
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS", ctx);
+
+ DocumentWrapper<DocumentModel> docWrapper = getRepositoryClient(ctx).getDoc(ctx, itemcsid);
List<String> authRefFields =
((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(
ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES);
PoxPayloadOut result = null;
try {
PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
- 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<PoxPayloadIn, PoxPayloadOut> 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
+ // Note that we have to create the service context for the Items, not the main service
+ //Laramie CSPACE-3175. passing null for queryParams, because prior to this refactor, the code moved to lookupParentCSID in this instance called the version of getServiceContext() that passes null
+ String parentcsid = lookupParentCSID(parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null);
+
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), theUpdate);
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx);
+
// We omit the parentShortId, only needed when doing a create...
- DocumentHandler handler = createItemDocumentHandler(ctx,
- parentcsid, null);
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null);
ctx.setUriInfo(ui);
getRepositoryClient(ctx).update(ctx, itemcsid, handler);
result = ctx.getOutput();
- //PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
- //updateRelations(itemcsid, input);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED);
}
public Response deleteAuthorityItem(
@PathParam("csid") String parentcsid,
@PathParam("itemcsid") String itemcsid) {
- try{
- if (logger.isDebugEnabled()) {
- logger.debug("deleteAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
-
- if (parentcsid == null || "".equals(parentcsid)) {
- logger.error("deleteVocabularyItem: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on AuthorityItem parentcsid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if (itemcsid == null || "".equals(itemcsid)) {
- logger.error("deleteVocabularyItem: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on AuthorityItem=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- }catch (Throwable t){
- System.out.println("ERROR in setting up DELETE: "+t);
+ //try{
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
}
- try {
+ try {
+ ensureCSID(parentcsid, ServiceMessages.DELETE_FAILED, "AuthorityItem.parentcsid");
+ ensureCSID(itemcsid, ServiceMessages.DELETE_FAILED, "AuthorityItem.itemcsid");
+ //Laramie, removing this catch, since it will surely fail below, since itemcsid or parentcsid will be null.
+ // }catch (Throwable t){
+ // System.out.println("ERROR in setting up DELETE: "+t);
+ // }
+ // try {
// Note that we have to create the service context for the Items, not the main service
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName());
+ ServiceContext ctx = createServiceContext(getItemServiceName());
getRepositoryClient(ctx).delete(ctx, itemcsid);
return Response.status(HttpResponseCodes.SC_OK).build();
- } catch (Exception e) {
+ } catch (Exception e) {
throw bigReThrow(e, ServiceMessages.DELETE_FAILED + " itemcsid: " + itemcsid+ " parentcsid:" + parentcsid);
}
}
public abstract class AuthorityResourceWithContacts<AuthCommon, AuthCommonList, AuthItemCommonList, AuthItemHandler> extends //FIXME: REM - Why is this resource in this package instead of somewhere in 'common'?
AuthorityResource<AuthCommon, AuthCommonList, AuthItemCommonList, AuthItemHandler> {
- /** The contact resource. */
private ContactResource contactResource = new ContactResource(); // Warning: ContactResource is a singleton.
final Logger logger = LoggerFactory.getLogger(AuthorityResourceWithContacts.class);
- /**
- * Instantiates a new Authority resource.
- */
public AuthorityResourceWithContacts(
Class<AuthCommon> authCommonClass, Class<?> resourceClass,
String authorityCommonSchemaName, String 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<PoxPayloadIn, PoxPayloadOut> 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
String xmlPayload) {
try {
PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
- Specifier parentSpec = getSpecifier(parentspecifier,
- "createContact(authority)", "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<PoxPayloadIn, PoxPayloadOut> 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);
- }
+ String parentcsid = lookupParentCSID(parentspecifier, "createContact(authority)", "CREATE_ITEM_CONTACT", null);
+
+ ServiceContext itemCtx = createServiceContext(getItemServiceName());
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "createContact(item)", "CREATE_ITEM_CONTACT", itemCtx);
+
// Note that we have to create the service context and document
// handler for the Contact service, not the main service.
- ctx = createServiceContext(getContactServiceName(), input);
+ ServiceContext 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 (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("createContact", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND)
- .entity("Create Contact failed; one of the requested specifiers for authority:"
- +parentspecifier+": and item:"+itemspecifier+": was not found.")
- .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);
+ throw bigReThrow(e,
+ "Create Contact failed; one of the requested specifiers for authority:"
+ +parentspecifier+": and item:"+itemspecifier+": was not found.",
+ itemspecifier);
}
-
}
/**
@Context UriInfo ui) {
ContactsCommonList contactObjectList = new ContactsCommonList();
try {
- Specifier parentSpec = getSpecifier(parentspecifier,
- "getContactList(parent)", "GET_CONTACT_LIST");
- Specifier itemSpec = getSpecifier(itemspecifier,
- "getContactList(item)", "GET_CONTACT_LIST");
- // Note that we have to create the service context for the Items, not the main service
- ServiceContext<PoxPayloadIn, PoxPayloadOut> 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);
- }
+ String parentcsid = lookupParentCSID(parentspecifier, "getContactList(parent)", "GET_CONTACT_LIST", null);
+
+ ServiceContext itemCtx = createServiceContext(getItemServiceName());
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContactList(item)", "GET_CONTACT_LIST", itemCtx);
+
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- ctx = createServiceContext(getContactServiceName(), queryParams);
+ ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams);
DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
myFilter.appendWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
IQueryManager.SEARCH_QUALIFIER_AND); // "AND" this clause to any existing
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 (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("getContactList", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND)
- .entity("Get ContactList failed; one of the requested specifiers for authority:"
- +parentspecifier+": and item:"+itemspecifier+": was not found.")
- .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);
+ throw bigReThrow(e,
+ "Get ContactList failed; one of the requested specifiers for authority:"
+ +parentspecifier+": and item:"+itemspecifier+": was not found.",
+ itemspecifier);
}
return contactObjectList;
}
@PathParam("csid") String csid) {
PoxPayloadOut 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<PoxPayloadIn, PoxPayloadOut> 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());
+ String parentcsid = lookupParentCSID(parentspecifier, "getContact(parent)", "GET_ITEM_CONTACT", null);
+
+ ServiceContext itemCtx = createServiceContext(getItemServiceName());
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContact(item)", "GET_ITEM_CONTACT", itemCtx);
+
+ // Note that we have to create the service context and document handler for the Contact service, not the main service.
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getContactServiceName());
DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
getRepositoryClient(ctx).get(ctx, csid, handler);
result = 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 +
- ": or one of the specifiers for authority:"+parentspecifier+
- ": and item:"+itemspecifier+": 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);
+ throw bigReThrow(e, "Get failed, the requested Contact CSID:" + csid +
+ ": or one of the specifiers for authority:"+parentspecifier+
+ ": and item:"+itemspecifier+": was not found.",
+ csid);
}
if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND)
throw new WebApplicationException(response);
}
return result.toXML();
-
}
/**
* @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
PoxPayloadOut result = null;
try {
PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
- Specifier parentSpec = getSpecifier(parentspecifier,
- "updateContact(authority)", "UPDATE_CONTACT");
- Specifier itemSpec = getSpecifier(itemspecifier,
- "updateContact(item)", "UPDATE_CONTACT");
- // Note that we have to create the service context for the Items, not the main service
+ String parentcsid = lookupParentCSID(parentspecifier, "updateContact(authority)", "UPDATE_CONTACT", null);
+
+ ServiceContext itemCtx = createServiceContext(getItemServiceName());
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateContact(item)", "UPDATE_CONTACT", itemCtx);
+
ServiceContext<PoxPayloadIn, PoxPayloadOut> 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.
+ // 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 = 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, the requested Contact CSID:" + csid +
- ": or one of the specifiers for authority:"+parentspecifier+
- ": and item:"+itemspecifier+": was not found.")
- .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);
+ throw bigReThrow(e, "Update failed, the requested Contact CSID:" + csid +
+ ": or one of the specifiers for authority:"+parentspecifier+
+ ": and item:"+itemspecifier+": was not found.",
+ csid);
}
return result.toXML();
}
@PathParam("itemcsid") String itemspecifier,
@PathParam("csid") String csid) {
try {
- Specifier parentSpec = getSpecifier(parentspecifier,
- "deleteContact(authority)", "DELETE_CONTACT");
- Specifier itemSpec = getSpecifier(itemspecifier,
- "deleteContact(item)", "DELETE_CONTACT");
- // Note that we have to create the service context for the Items, not the main service
+ String parentcsid = lookupParentCSID(parentspecifier, "deleteContact(authority)", "DELETE_CONTACT", null);
+
+ ServiceContext itemCtx = createServiceContext(getItemServiceName());
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "deleteContact(item)", "DELETE_CONTACT", itemCtx);
+ //NOTE: itemcsid is not used below. Leaving the above call in for possible side effects??? CSPACE-3175
+
ServiceContext<PoxPayloadIn, PoxPayloadOut> 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.
+ // 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 +
- ": or one of the specifiers for authority:"+parentspecifier+
- ": and item:"+itemspecifier+": 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);
+ } catch (Exception e) {
+ throw bigReThrow(e, "DELETE failed, the requested Contact CSID:" + csid +
+ ": or one of the specifiers for authority:"+parentspecifier+
+ ": and item:"+itemspecifier+": was not found.", csid);
}
}