import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.workflow.WorkflowCommon;
-
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
-
import org.jboss.resteasy.util.HttpResponseCodes;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
protected String lookupParentCSID(String parentspecifier, String method,
String op, UriInfo uriInfo) throws Exception {
- CsidAndShortIdentifier tempResult = lookupParentCSIDAndShortIdentifer(
+ CsidAndShortIdentifier tempResult = lookupParentCSIDAndShortIdentifer(null,
parentspecifier, method, op, uriInfo);
return tempResult.CSID;
}
private CsidAndShortIdentifier lookupParentCSIDAndShortIdentifer(
- String parentspecifier,
+ ServiceContext itemServiceCtx,
+ String parentSpecifier,
String method,
String op,
UriInfo uriInfo)
throws Exception {
CsidAndShortIdentifier result = new CsidAndShortIdentifier();
- Specifier parentSpec = getSpecifier(parentspecifier, method, op);
+ 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;
parentShortIdentifier = parentSpec.value;
String whereClause = RefNameServiceUtils.buildWhereForAuthByName(authorityCommonSchemaName, parentSpec.value);
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getServiceName(), uriInfo);
- parentcsid = getRepositoryClient(ctx).findDocCSID(null, ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
+ CoreSessionInterface repoSession = null;
+ if (itemServiceCtx != null) {
+ repoSession = (CoreSessionInterface) itemServiceCtx.getCurrentRepositorySession(); // We want to use the thread's current repo session
+ }
+ parentcsid = getRepositoryClient(ctx).findDocCSID(repoSession, ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item?
}
+
result.CSID = parentcsid;
result.shortIdentifier = parentShortIdentifier;
return result;
*/
@GET
@Path("{csid}/sync")
- public Response synchronize(
+ public byte[] synchronize(
@Context Request request,
@Context UriInfo ui,
@PathParam("csid") String csid) {
- PoxPayloadOut result = null;
+ byte[] result;
+ boolean neededSync = false;
+ PoxPayloadOut payloadOut = null;
Specifier specifier;
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
specifier = getSpecifier(csid, "getAuthority", "GET");
-
- getRepositoryClient(ctx).synchronize(ctx, specifier, handler);
- result = ctx.getOutput();
-
+ neededSync = getRepositoryClient(ctx).synchronize(ctx, specifier, handler);
+ payloadOut = ctx.getOutput();
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.SYNC_FAILED, csid);
}
- if (result == null) {
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed, the requested Authority specifier:" + specifier + ": was not found.").type(
- "text/plain").build();
+ //
+ // If a sync was needed and was successful, return a copy of the updated resource. Acts like an UPDATE.
+ //
+ if (neededSync == true) {
+ result = payloadOut.getBytes();
+ } else {
+ result = String.format("Authority resource '%s' was already in sync with shared authority server.",
+ specifier.value).getBytes();
+ Response response = Response.status(Response.Status.NOT_MODIFIED).entity(result).type("text/plain").build();
throw new CSWebApplicationException(response);
}
-
- return Response.status(Response.Status.OK).entity(
- "Synchronization completed, the requested Authority specifier:" + specifier.value + ": was synchronized.").type(
- "text/plain").build();
+
+ return result;
}
/**
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), input, resourceMap, uriInfo);
// Note: must have the parentShortId, to do the create.
- CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(parentspecifier, "createAuthorityItem", "CREATE_ITEM", null);
+ CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(null, parentspecifier, "createAuthorityItem", "CREATE_ITEM", null);
DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler =
createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx =
(RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(getItemServiceName(), resourceMap, uriInfo);
- JaxRsContext jaxRsContext = new JaxRsContext(request, uriInfo); // REM - Why are we setting this? Who is using the getter?
+ JaxRsContext jaxRsContext = new JaxRsContext(request, uriInfo); // Needed for getting account permissions part of the payload
ctx.setJaxRsContext(jaxRsContext);
// We omit the parentShortId, only needed when doing a create...
return authRefList;
}
+ /**
+ * Synchronizes the authority and its terms with a Shared Authority Server (SAS).
+ *
+ * @param specifier either CSIDs and/or one of the urn forms
+ *
+ * @return the authority item if it was synchronized with SAS
+ */
+ @GET
+ @Path("{csid}/items/{itemcsid}/sync")
+ public byte[] synchronizeItem(
+ @Context ResourceMap resourceMap,
+ @Context Request request,
+ @Context UriInfo uriInfo,
+ @PathParam("csid") String parentIdentifier,
+ @PathParam("itemcsid") String itemIdentifier
+ ) {
+ byte[] result;
+ boolean neededSync = false;
+ PoxPayloadOut payloadOut = null;
+ AuthorityItemSpecifier specifier;
+ CsidAndShortIdentifier parent;
+
+ try {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), null, resourceMap, uriInfo);
+ parent = lookupParentCSIDAndShortIdentifer(null, parentIdentifier, "syncAuthorityItem(parent)", "SYNC_ITEM", null);
+ AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
+ Specifier parentSpecifier = getSpecifier(parent.CSID, "getAuthority", "GET");
+ Specifier itemSpecifier = getSpecifier(itemIdentifier, "getAuthorityItem", "GET");
+ specifier = new AuthorityItemSpecifier(parentSpecifier, itemSpecifier);
+ neededSync = getRepositoryClient(ctx).synchronize(ctx, specifier, handler);
+ payloadOut = ctx.getOutput();
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.SYNC_FAILED, itemIdentifier);
+ }
+
+ //
+ // If a sync was needed and was successful, return a copy of the updated resource. Acts like an UPDATE.
+ //
+ if (neededSync == true) {
+ result = payloadOut.getBytes();
+ } else {
+ result = String.format("Authority item resource '%s' was already in sync with shared authority server.",
+ itemIdentifier).getBytes();
+ Response response = Response.status(Response.Status.NOT_MODIFIED).entity(result).type("text/plain").build();
+ throw new CSWebApplicationException(response);
+ }
+
+ return result;
+ }
+
/**
* Update authorityItem.
*
public byte[] updateAuthorityItem(
@Context ResourceMap resourceMap,
@Context UriInfo uriInfo,
- @PathParam("csid") String parentspecifier,
- @PathParam("itemcsid") String itemspecifier,
+ @PathParam("csid") String parentSpecifier,
+ @PathParam("itemcsid") String itemSpecifier,
String xmlPayload) {
PoxPayloadOut result = null;
+
try {
PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
- // 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
- CsidAndShortIdentifier csidAndShortId = lookupParentCSIDAndShortIdentifer(parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null);
- String parentcsid = csidAndShortId.CSID;
- String parentShortId = csidAndShortId.shortIdentifier;
-
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), theUpdate, resourceMap, uriInfo);
- String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx);
-
- // We omit the parentShortId, only needed when doing a create...
- DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createItemDocumentHandler(ctx, parentcsid, parentShortId);
- getRepositoryClient(ctx).update(ctx, itemcsid, handler);
- result = ctx.getOutput();
-
+ result = updateAuthorityItem(null, resourceMap, uriInfo, parentSpecifier, itemSpecifier, theUpdate, true); // passing TRUE so parent authority rev num increases
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED);
}
+
return result.getBytes();
}
+
+ public PoxPayloadOut updateAuthorityItem(
+ ServiceContext itemServiceCtx, // Ok to be null
+ ResourceMap resourceMap,
+ UriInfo uriInfo,
+ String parentspecifier,
+ String itemspecifier,
+ PoxPayloadIn theUpdate,
+ boolean shouldUpdateParentRev) throws Exception {
+ PoxPayloadOut result = null;
+
+ CsidAndShortIdentifier csidAndShortId = lookupParentCSIDAndShortIdentifer(itemServiceCtx, parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null);
+ String parentcsid = csidAndShortId.CSID;
+ String parentShortId = csidAndShortId.shortIdentifier;
+ //
+ // If the itemServiceCtx context is not null, use it. Otherwise, create a new context
+ //
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = itemServiceCtx;
+ if (ctx == null) {
+ ctx = createServiceContext(getItemServiceName(), theUpdate, resourceMap, uriInfo);
+ }
+ String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx); //use itemServiceCtx if it is not null
+
+ // We omit the parentShortId, only needed when doing a create...
+ AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, parentShortId);
+ handler.setShouldUpdateParentRevNumber(shouldUpdateParentRev);
+ getRepositoryClient(ctx).update(ctx, itemcsid, handler);
+ result = ctx.getOutput();
+
+ return result;
+ }
/**
* Delete authorityItem.
import org.collectionspace.services.client.VocabularyClient;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.ResourceMap;
+import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.api.RefName.Authority;
import org.collectionspace.services.common.api.RefNameUtils;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
+import org.collectionspace.services.common.vocabulary.AuthorityResource;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm;
import org.collectionspace.services.config.service.ObjectPartType;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.Assert;
/**
* AuthorityDocumentModelHandler
}
@Override
- public void handleSync(DocumentWrapper<Specifier> wrapDoc) throws Exception {
-
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
- Specifier specifier = wrapDoc.getWrappedObject();
+ public boolean handleSync(DocumentWrapper<Object> wrapDoc) throws Exception {
+ boolean result = false;
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
+ Specifier specifier = (Specifier) wrapDoc.getWrappedObject();
//
// Get the rev number of the authority so we can compare with rev number of shared authority
//
DocumentModel docModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, specifier);
- Long rev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.REV);
- String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- String refName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.REF_NAME);
- AuthorityInfo authorityInfo = RefNameUtils.parseAuthorityInfo(refName);
+ Long rev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV);
+ String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+ String refName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REF_NAME);
//
// Using the short ID of the local authority, created a URN specifier to retrieve the SAS authority
//
Specifier sasSpecifier = new Specifier(SpecifierForm.URN_NAME, RefNameUtils.createShortIdRefName(shortId));
- Long sasRev = getRevFromSASInstance(sasSpecifier);
+ PoxPayloadIn sasPayloadIn = getPayloadIn(ctx, sasSpecifier);
+
+ Long sasRev = getRevision(sasPayloadIn);
+ if (sasRev > rev) {
+ ResourceMap resourceMap = ctx.getResourceMap();
+ String resourceName = ctx.getClient().getServiceName();
+ AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(resourceName);
+ PoxPayloadOut payloadOut = authorityResource.update(ctx, resourceMap, null, docModel.getName(), sasPayloadIn);
+ if (payloadOut != null) {
+ ctx.setOutput(payloadOut);
+ result = true;
+ }
+ }
+
+ return result;
+ }
- AuthorityClient client = ctx.getAuthorityClient();
- Response res = client.read(sasSpecifier.value);
+ private PoxPayloadIn getPayloadIn(ServiceContext ctx, Specifier specifier) throws Exception {
+ PoxPayloadIn result = null;
+
+ AuthorityClient client = (AuthorityClient) ctx.getClient();
+ Response res = client.read(specifier.value);
try {
int statusCode = res.getStatus();
logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
}
- PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType())); // Get the entire response!
-
- PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
- if (payloadInputPart != null) {
-// result = (client.getc) payloadInputPart.getBody();
- }
- Document document = input.getDOMDocument();
- Element rootElement = document.getRootElement();
-
+ result = new PoxPayloadIn((String)res.readEntity(getEntityResponseType())); // Get the entire response!
} finally {
res.close();
}
-
- }
-
- private Long getRevFromSASInstance(Specifier specifier) {
- Long result = null;
-
- VocabularyClient client = new VocabularyClient();
- String uri = getUri(specifier);
return result;
}
repoSession = nuxeoRepoClient.getRepositorySession(ctx);
DocumentWrapper<DocumentModel> wrapDoc = nuxeoRepoClient.getDocFromCsid(ctx, repoSession, authCSID);
DocumentModel docModel = wrapDoc.getWrappedObject();
+ if (docModel == null) {
+ throw new DocumentNotFoundException(String.format("Could not find authority resource with CSID='%s'.", authCSID));
+ }
shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
} catch (ClientException ce) {
throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce);
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.common.UriTemplateRegistry;
import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.api.RefNameUtils;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
import org.collectionspace.services.common.api.Tools;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityInfo;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextImpl;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.document.DocumentHandler.Action;
import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityResource;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm;
import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.config.service.ObjectPartType;
import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Collections;
extends NuxeoDocumentModelHandler<AICommon> {
private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
- private String authorityItemCommonSchemaName;
+
+ protected String authorityCommonSchemaName;
+ protected String authorityItemCommonSchemaName;
private String authorityItemTermGroupXPathBase;
+ private boolean shouldUpdateParentRevNumber = true;
/**
* inVocabulary is the parent Authority for this context
*/
private final static String LIST_SUFFIX = "List";
private final static String ZERO_OR_MORE_ANY_CHAR_REGEX = ".*";
- public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
+ public AuthorityItemDocumentModelHandler(String authorityCommonSchemaName, String authorityItemCommonSchemaName) {
this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
}
abstract public String getParentCommonSchemaName();
+
+ public boolean getShouldUpdateParentRevNumber() {
+ return this.shouldUpdateParentRevNumber;
+ }
+
+ public void setShouldUpdateParentRevNumber(boolean flag) {
+ this.shouldUpdateParentRevNumber = flag;
+ }
@Override
protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
return list;
}
+ private PoxPayloadIn getPayloadIn(AuthorityItemSpecifier specifier) throws Exception {
+ PoxPayloadIn result = null;
+
+ ServiceContext parentCtx = new MultipartServiceContextImpl(this.getAuthorityServicePath());
+ AuthorityClient client = (AuthorityClient) parentCtx.getClient();
+ Response res = client.readItem(specifier.getParentSpecifier().value, specifier.getItemSpecifier().value);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
+ }
+
+ result = new PoxPayloadIn((String)res.readEntity(getEntityResponseType())); // Get the entire response!
+ } finally {
+ res.close();
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean handleSync(DocumentWrapper<Object> wrapDoc) throws Exception {
+ boolean result = false;
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
+ AuthorityItemSpecifier authorityItemSpecifier = (AuthorityItemSpecifier) wrapDoc.getWrappedObject();
+ //
+ // Get the rev number of the authority item so we can compare with rev number of shared authority
+ //
+ DocumentModel itemDocModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), getAuthorityItemCommonSchemaName(),
+ authorityItemSpecifier.getItemSpecifier());
+ if (itemDocModel == null) {
+ throw new DocumentNotFoundException(String.format("Could not find authority item resource with CSID='%s'",
+ authorityItemSpecifier.getItemSpecifier().value));
+ }
+ Long itemRev = (Long) NuxeoUtils.getProperyValue(itemDocModel, AuthorityItemJAXBSchema.REV);
+ String itemShortId = (String) NuxeoUtils.getProperyValue(itemDocModel, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+ String itemRefName = (String) NuxeoUtils.getProperyValue(itemDocModel, AuthorityItemJAXBSchema.REF_NAME);
+ //
+ // Now get the Authority (the parent) information
+ //
+ DocumentModel authorityDocModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName,
+ authorityItemSpecifier.getParentSpecifier());
+ Long authorityRev = (Long) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.REV);
+ String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+ String authorityRefName = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.REF_NAME);
+ AuthorityInfo authorityInfo = RefNameUtils.parseAuthorityInfo(authorityRefName);
+ //
+ // Using the short IDs of the local authority and item, create URN specifiers to retrieve the SAS authority item
+ //
+ Specifier sasAuthoritySpecifier = new Specifier(SpecifierForm.URN_NAME, RefNameUtils.createShortIdRefName(authorityShortId));
+ Specifier sasItemSpecifier = new Specifier(SpecifierForm.URN_NAME, RefNameUtils.createShortIdRefName(itemShortId));
+ AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(sasAuthoritySpecifier, sasItemSpecifier);
+ // Get the shared authority server's copy
+ PoxPayloadIn sasPayloadIn = getPayloadIn(sasAuthorityItemSpecifier);
+
+ Long sasRev = getRevision(sasPayloadIn);
+ if (sasRev > itemRev) {
+ ResourceMap resourceMap = ctx.getResourceMap();
+ String resourceName = this.getAuthorityServicePath();
+ AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(resourceName);
+ PoxPayloadOut payloadOut = authorityResource.updateAuthorityItem(ctx,
+ resourceMap,
+ null,
+ authorityDocModel.getName(), // parent's CSID
+ itemDocModel.getName(), // item's CSID
+ sasPayloadIn, // the payload from the SAS
+ false); // don't update the parent's revision number
+ if (payloadOut != null) {
+ ctx.setOutput(payloadOut);
+ result = true;
+ }
+ }
+
+ return result;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
*/
//
// Next, update the inAuthority (the parent's) rev number
//
- DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), getInAuthority());
- Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV);
- parentRev++;
- inAuthorityDocModel.setProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV, parentRev);
- getRepositorySession().saveDocument(inAuthorityDocModel);
+ if (this.shouldUpdateParentRevNumber == true) {
+ DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), getInAuthority());
+ Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV);
+ parentRev++;
+ inAuthorityDocModel.setProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV, parentRev);
+ getRepositorySession().saveDocument(inAuthorityDocModel);
+ }
}
/**
extends AuthorityItemDocumentModelHandler<CitationsCommon> {
public CitationDocumentModelHandler() {
- super(CitationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(CitationAuthorityClient.SERVICE_COMMON_PART_NAME, CitationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
@PathParam("csid") String csid,
String xmlPayload) {
PoxPayloadOut result = null;
+
ensureCSID(csid, UPDATE);
try {
PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate, uriInfo);
- ctx.setResourceMap(resourceMap);
- if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {
- ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists
- }
- result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override.
+ result = update(parentCtx, resourceMap, uriInfo, csid, theUpdate);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid);
}
+
return result.getBytes();
}
+
+ /**
+ * This method is used to synchronize data with the SAS (Shared Authority Server).
+ *
+ * @param parentCtx
+ * @param resourceMap
+ * @param uriInfo
+ * @param csid
+ * @param theUpdate
+ * @return
+ * @throws Exception
+ */
+ public PoxPayloadOut update(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, // REM: 4/6/2016 - Some sub-classes will override this method -e.g., MediaResource does.
+ ResourceMap resourceMap,
+ UriInfo uriInfo,
+ String csid,
+ PoxPayloadIn theUpdate) throws Exception {
+ PoxPayloadOut result = null;
+
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate, uriInfo);
+ ctx.setResourceMap(resourceMap);
+ if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {
+ ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists
+ }
+ result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override.
+
+ return result;
+ }
/** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput) */
protected PoxPayloadOut update(String csid,
- PoxPayloadIn theUpdate,
+ PoxPayloadIn theUpdate, // not used in this method, but could be used by an overriding method
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)
throws Exception {
DocumentHandler handler = createDocumentHandler(ctx);
return tenantBindingConfigReader;
}
+ public ResourceMap getJaxRSResourceMap() {
+ ResourceMap result;
+
+ result = ResteasyProviderFactory.getContextData(ResourceMap.class);
+
+ return result;
+ }
+
/**
* Populate a registry of URI templates by querying each resource
* for its own entries in the registry.
private synchronized void populateUriTemplateRegistry() {
if (uriTemplateRegistry.isEmpty()) {
NuxeoBasedResource resource = null;
- ResourceMap resourceMap = ResteasyProviderFactory.getContextData(ResourceMap.class);
+ ResourceMap resourceMap = getJaxRSResourceMap();
for (Map.Entry<String, NuxeoBasedResource> entry : resourceMap.entrySet()) {
resource = entry.getValue();
Map<UriTemplateRegistryKey, StoredValuesUriTemplate> entries =
}
@Override
- public AuthorityClient getAuthorityClient() throws Exception {
+ public AuthorityClient getClient() throws Exception {
AuthorityClient result = authorityClient;
if (authorityClient == null) {
final Logger logger = LoggerFactory.getLogger(MultipartServiceContextImpl.class);
private String repositoryWorkspaceName;
+
+ public MultipartServiceContextImpl(String serviceName)
+ throws DocumentException, UnauthorizedException {
+ super(serviceName, null);
+ setOutput(new PoxPayloadOut(serviceName));
+ }
+
/**
* Instantiates a new multipart service context impl.
*
* @return the map of service names to resource classes.
*/
public ResourceMap getResourceMap() {
- return resourceMap;
+ ResourceMap result = resourceMap;
+
+ if (result == null) {
+ result = ServiceMain.getInstance().getJaxRSResourceMap();
+ }
+
+ return result;
}
/**
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;
-import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.ValidatorHandler;
public void setRepositoryDomain(RepositoryDomainType repositoryDomain);
- public AuthorityClient getAuthorityClient() throws Exception;
+ public CollectionSpaceClient getClient() throws Exception;
}
* @see org.collectionspace.services.common.document.DocumentHandler#handle(org.collectionspace.services.common.document.DocumentHandler.Action, org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- final public void handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
+ final public boolean handle(Action action, DocumentWrapper<?> wrapDoc) throws Exception {
+ boolean result = true;
+
switch (action) {
case CREATE:
handleCreate((DocumentWrapper<WT>) wrapDoc);
break;
case SYNC:
- handleSync((DocumentWrapper<Specifier>) wrapDoc);
+ result = handleSync((DocumentWrapper<Object>) wrapDoc);
break;
case WORKFLOW:
Thread.dumpStack();
break;
}
+
+ return result;
}
/* (non-Javadoc)
* @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void handleSync(DocumentWrapper<Specifier> wrapDoc) throws Exception {
+ public boolean handleSync(DocumentWrapper<Object> wrapDoc) throws Exception {
// Do nothing. Subclasses can override if they want/need to.
+ return true;
}
break;
case SYNC:
- completeSync((DocumentWrapper<Specifier>) wrapDoc);
+ completeSync((DocumentWrapper<Object>) wrapDoc);
break;
case WORKFLOW:
* @see org.collectionspace.services.common.document.DocumentHandler#completeDelete(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void completeSync(DocumentWrapper<Specifier> wrapDoc) throws Exception {
+ public void completeSync(DocumentWrapper<Object> wrapDoc) throws Exception {
}
/* (non-Javadoc)
* @param doc wrapped doc
* @throws Exception
*/
- public void handle(Action action, DocumentWrapper<?> docWrap) throws Exception;
+ public boolean handle(Action action, DocumentWrapper<?> docWrap) throws Exception;
/**
* handleCreate processes documents before creating document in repository
* @param wrapDoc
* @throws Exception
*/
- void handleSync(DocumentWrapper<Specifier> wrapDoc) throws Exception;
+ boolean handleSync(DocumentWrapper<Object> wrapDoc) throws Exception;
/**
*
* @param wrapDoc
* @throws Exception
*/
- void completeSync(DocumentWrapper<Specifier> wrapDoc) throws Exception;
+ void completeSync(DocumentWrapper<Object> wrapDoc) throws Exception;
}
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.TransactionException;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
import org.collectionspace.services.lifecycle.TransitionDef;
throws BadRequestException, DocumentNotFoundException, DocumentException;
/*
- * Ask a resource to synchronize itself with a shared server resource
+ * Ask a resource to synchronize itself with a shared server resource. Returns "TRUE" if sync was needed.
*/
- void synchronize(ServiceContext ctx, Specifier specifier, DocumentHandler handler)
+ boolean synchronize(ServiceContext ctx, Object specifier, DocumentHandler handler)
+ throws DocumentNotFoundException, TransactionException,
+ DocumentException;
+
+ /*
+ * Ask an item resource (e.g., an Authority or Vocabulary items) to synchronize itself with a shared server resource. Returns "TRUE" if sync was needed.
+ */
+ boolean synchronizeItem(ServiceContext ctx, AuthorityItemSpecifier itemSpecifier, DocumentHandler handler)
throws DocumentNotFoundException, TransactionException,
DocumentException;
import org.collectionspace.services.common.document.JaxbUtils;
import org.collectionspace.services.common.document.TransactionException;
import org.collectionspace.services.common.storage.StorageClient;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
import org.collectionspace.services.common.context.ServiceContextProperties;
import org.collectionspace.services.common.context.ServiceContext;
}
@Override
- public void synchronize(ServiceContext ctx, Specifier specifier,
+ public boolean synchronize(ServiceContext ctx, Object specifier,
DocumentHandler handler) throws DocumentNotFoundException,
TransactionException, DocumentException {
// TODO Auto-generated method stub
// Do nothing. Subclasses can override if they want/need to.
+ return true;
}
+
+ @Override
+ public boolean synchronizeItem(ServiceContext ctx, AuthorityItemSpecifier itemSpecifier,
+ DocumentHandler handler) throws DocumentNotFoundException,
+ TransactionException, DocumentException {
+ // TODO Auto-generated method stub
+ // Do nothing. Subclasses can override if they want/need to.
+ return true;
+ }
+
}
this.value = value;
}
}
+
+ public static class AuthorityItemSpecifier {
+ private Specifier parentSpecifier;
+ private Specifier itemSpecifier;
+
+ public AuthorityItemSpecifier(Specifier parentSpecifier, Specifier itemSpecifier) {
+ this.parentSpecifier = parentSpecifier;
+ this.itemSpecifier = itemSpecifier;
+ }
+
+ public Specifier getParentSpecifier() {
+ return this.parentSpecifier;
+ }
+
+ public Specifier getItemSpecifier() {
+ return this.itemSpecifier;
+ }
+ }
public static class AuthRefConfigInfo {
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.common.ReflectionMapper;
+import org.collectionspace.services.common.XmlTools;
import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.config.ServiceConfigUtils;
import org.collectionspace.services.nuxeo.client.java.CommonList;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-
+import org.dom4j.Document;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
this.commonPart = commonPart;
}
+ /**
+ * The entity type expected from the JAX-RS Response object. By default it is of type String. Child classes
+ * can override this if they need to.
+ */
+ protected Class<String> getEntityResponseType() {
+ return String.class;
+ }
+
+ protected Long getRevision(PoxPayloadIn payloadIn) {
+ Long result = null;
+
+ Document document = payloadIn.getDOMDocument();
+ String xmlRev = XmlTools.getElementValue(document, "//rev");
+ result = Long.valueOf(xmlRev);
+
+ return result;
+ }
+
/**
* Subclass DocHandlers may override this method to control exact creation of the common list.
* This class instantiates an AbstractCommonList from the classname returned by getDocHandlerParams().AbstractCommonListClassname.
import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
import org.collectionspace.services.common.config.TenantBindingUtils;
import org.collectionspace.services.common.storage.PreparedStatementBuilder;
+import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
import org.collectionspace.services.config.tenant.TenantBindingType;
import org.collectionspace.services.config.tenant.RepositoryDomainType;
}
@Override
- public void synchronize(ServiceContext ctx, Specifier specifier, DocumentHandler handler)
+ public boolean synchronize(ServiceContext ctx, Object specifier, DocumentHandler handler)
throws DocumentNotFoundException, TransactionException, DocumentException {
+ boolean result = false;
+
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "RepositoryJavaClient.get: handler is missing");
+ }
+ CoreSessionInterface repoSession = null;
+ try {
+ handler.prepare(Action.SYNC);
+ repoSession = getRepositorySession(ctx);
+ ((DocumentModelHandler) handler).setRepositorySession(repoSession);
+ DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(specifier);
+ result = handler.handle(Action.SYNC, wrapDoc);
+ handler.complete(Action.SYNC, wrapDoc);
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new NuxeoDocumentException(e);
+ } finally {
+ if (repoSession != null) {
+ releaseRepositorySession(ctx, repoSession);
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean synchronizeItem(ServiceContext ctx, AuthorityItemSpecifier itemSpecifier, DocumentHandler handler)
+ throws DocumentNotFoundException, TransactionException, DocumentException {
+ boolean result = false;
+
if (handler == null) {
throw new IllegalArgumentException(
"RepositoryJavaClient.get: handler is missing");
handler.prepare(Action.SYNC);
repoSession = getRepositorySession(ctx);
((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentWrapper<Specifier> wrapDoc = new DocumentWrapperImpl<Specifier>(specifier);
- handler.handle(Action.SYNC, wrapDoc);
+ DocumentWrapper<AuthorityItemSpecifier> wrapDoc = new DocumentWrapperImpl<AuthorityItemSpecifier>(itemSpecifier);
+ result = handler.handle(Action.SYNC, wrapDoc);
handler.complete(Action.SYNC, wrapDoc);
} catch (IllegalArgumentException iae) {
throw iae;
releaseRepositorySession(ctx, repoSession);
}
}
+
+ return result;
}
/**
// To get a connection to the Nuxeo repo, we need either a valid ServiceContext instance or a repository name
//
if (ctx != null) {
- repoName = ctx.getRepositoryName(); // Notice we are overriding the passed in 'repoName' since we have a valid service context passed in to us
- repoSession = (CoreSessionInterface) ctx.getCurrentRepositorySession(); // Look to see if one exists in the context before creating one
+ repoSession = (CoreSessionInterface) ctx.getCurrentRepositorySession(); // First see if the context already has a repo session
+ if (repoSession == null) {
+ repoName = ctx.getRepositoryName(); // Notice we are overriding the passed in 'repoName' since we have a valid service context passed in to us
+ }
} else if (repoName == null || repoName.trim().isEmpty()) {
String errMsg = String.format("We can't get a connection to the Nuxeo repo because the service context passed in was null and no repository name was passed in either.");
logger.error(errMsg);
//
query.append(/*IQueryManager.SEARCH_QUALIFIER_AND +*/ " WHERE " + CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA + ":"
+ CollectionSpaceClient.COLLECTIONSPACE_CORE_TENANTID
- + " = " + queryContext.getTenantId());
+ + " = " + "'" + queryContext.getTenantId() + "'");
//
// Finally, append the incoming where clause
//
extends AuthorityItemDocumentModelHandler<ConceptsCommon> {
public ConceptDocumentModelHandler() {
- super(ConceptAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(ConceptAuthorityClient.SERVICE_COMMON_PART_NAME, ConceptAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<LocationsCommon> {
public LocationDocumentModelHandler() {
- super(LocationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(LocationAuthorityClient.SERVICE_COMMON_PART_NAME, LocationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<MaterialsCommon> {
public MaterialDocumentModelHandler() {
- super(MaterialAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(MaterialAuthorityClient.SERVICE_COMMON_PART_NAME, MaterialAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<OrganizationsCommon> {
public OrganizationDocumentModelHandler() {
- super(OrgAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(OrgAuthorityClient.SERVICE_COMMON_PART_NAME, OrgAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<PersonsCommon> {
public PersonDocumentModelHandler() {
- super(PersonAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(PersonAuthorityClient.SERVICE_COMMON_PART_NAME, PersonAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<PlacesCommon> {
public PlaceDocumentModelHandler() {
- super(PlaceAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(PlaceAuthorityClient.SERVICE_COMMON_PART_NAME, PlaceAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<TaxonCommon> {
public TaxonDocumentModelHandler() {
- super(TaxonomyAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(TaxonomyAuthorityClient.SERVICE_COMMON_PART_NAME, TaxonomyAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<VocabularyitemsCommon> {
public VocabularyItemDocumentModelHandler() {
- super(VocabularyClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(VocabularyClient.SERVICE_COMMON_PART_NAME, VocabularyClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override
extends AuthorityItemDocumentModelHandler<WorksCommon> {
public WorkDocumentModelHandler() {
- super(WorkAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
+ super(WorkAuthorityClient.SERVICE_COMMON_PART_NAME, WorkAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME);
}
@Override