#CATEGORY: afterTableCreation
-#
-# Add a unique constraint to the shortidentifier column of the vocabularies_common table.
-#
-LOG.INFO Adding a unique constraint to the shortidentifier column of the vocabularies_common table
-
-#TEST:
-SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = 'vocabularies_common' AND constraint_name = 'shortid_unique';
-
-#IF: emptyResult
-ALTER TABLE vocabularies_common add CONSTRAINT shortid_unique UNIQUE (shortidentifier);
-
-#
-# Add a unique constraint to the shortidentifier column of the persons_common table.
-#
-LOG.INFO Adding a unique constraint to the shortidentifier column of the persons_common table
-
-#TEST:
-SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = 'persons_common' AND constraint_name = 'persons_shortid_unique';
-
-#IF: emptyResult
-ALTER TABLE persons_common add CONSTRAINT persons_shortid_unique UNIQUE (shortidentifier);
-
-
#
# Add a unique constraint to the report 'name' column of the reports_common table.
#
uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getItemDocType(tenantId), UriTemplateFactory.ITEM));
}
return uriRegistryEntriesMap;
- }
-
+ }
}
// 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);
+ String authorityCsid = docModel.getName();
Long localRev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV);
String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
//
ctx.setOutput(payloadOut);
result = true;
}
+ //
+ // We need to transition the authority into a replicated state now that we've sync'd it.
+ //
+ authorityResource.updateWorkflowWithTransition(ctx, authorityCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE);
}
return result;
*/
@Override
public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
- // Update the revision number
- updateRevNumbers(wrapDoc);
+ if (this.getShouldUpdateRevNumber() == true) { // We don't update the rev number of synchronization requests
+ updateRevNumbers(wrapDoc);
+ }
}
@Override
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.citation.CitationauthoritiesCommon;
import org.collectionspace.services.citation.CitationsCommon;
/**
* The Class CitationAuthorityClient.
*/
-public class CitationAuthorityClient extends AuthorityClientImpl<CitationsCommon, CitationAuthorityProxy> {
+public class CitationAuthorityClient extends AuthorityClientImpl<CitationauthoritiesCommon, CitationsCommon, CitationAuthorityProxy> {
public static final String SERVICE_NAME = "citationauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
package org.collectionspace.services.client;
-import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
-import org.jboss.resteasy.client.ClientResponse;
-import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
-import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.jaxb.AbstractCommonList;
/*
* ILT - Authority item list type
* P - Proxy type
*/
-public interface AuthorityClient<AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
+public interface AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
extends CollectionSpacePoxClient<AbstractCommonList, P> {
/** The uri path element for items in an authority */
public static String ITEMS = "items"; //used to construct uri's in service paths for authorities.
public static final String SHORT_IDENTIFIER = "shortIdentifier";
+ public static final String IN_AUTHORITY = "inAuthority";
public static final String TERM_DISPLAY_NAME = "termDisplayName";
public static final String VOCAB_DISPLAY_NAME = "displayName";
public static final String REF_NAME = "refName";
// Get the inAuthorityCsid (the item's parent)
String getInAuthority(AUTHORITY_ITEM_TYPE item);
-
+
// Get the inAuthorityCsid (the item's parent)
void setInAuthority(AUTHORITY_ITEM_TYPE item, String inAuthorityCsid);
//(U)pdate Item
Response updateItem(String vcsid, String csid, PoxPayloadOut poxPayloadOut);
+
+ //(U)pdate Item
+ Response updateNamedItemInNamedAuthority(String authShortId, String itemShortId, PoxPayloadOut poxPayloadOut);
//(D)elete Item
Response deleteItem(String vcsid, String csid);
package org.collectionspace.services.client;
import javax.ws.rs.core.Response;
+
import org.collectionspace.services.jaxb.AbstractCommonList;
/*
* P - Proxy type
*/
-public abstract class AuthorityClientImpl<AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
+public abstract class AuthorityClientImpl<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
extends AbstractPoxServiceClientImpl<AbstractCommonList, P, AUTHORITY_ITEM_TYPE>
- implements AuthorityClient<AUTHORITY_ITEM_TYPE, P> {
+ implements AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P> {
private static final String INCLUDE_DELETE_TRUE = Boolean.TRUE.toString();
public Response updateItem(String vcsid, String csid, PoxPayloadOut poxPayloadOut) {
return getProxy().updateItem(vcsid, csid, poxPayloadOut.getBytes());
}
+
+ @Override
+ public Response updateNamedItemInNamedAuthority(String authShortId, String itemShortId, PoxPayloadOut poxPayloadOut) {
+ return getProxy().updateNamedItemInNamedAuthority(authShortId, itemShortId, poxPayloadOut.getBytes());
+ }
//(D)elete Item
@Override
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
-import org.jboss.resteasy.client.ClientResponse;
import org.collectionspace.services.client.workflow.WorkflowClient;
-import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
-import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.jaxb.AbstractCommonList;
/*
* ILT = Item list type
@PUT
@Path("/{vcsid}/items/{csid}")
Response updateItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid, byte[] xmlPayload);
+
+ //(U)pdate Item
+ @PUT
+ @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})")
+ Response updateNamedItemInNamedAuthority(@PathParam("specifier")String specifier,
+ @PathParam("itemspecifier")String itemspecifier, byte[] xmlPayload);
//(D)elete Item
@DELETE
package org.collectionspace.services.client;
public class GenericAuthorityClientImpl extends
- AuthorityClientImpl<Object, AuthorityProxy> {
+ AuthorityClientImpl<Object, Object, AuthorityProxy> {
@Override
public String getItemCommonPartName() {
package org.collectionspace.services.client.test;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.XmlTools;
+import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.dom4j.Document;
import org.slf4j.Logger;
protected String knownAuthorityWithItems = null;
protected String knownAuthorityWithItemsIdentifier = null;
- protected static final String SAS_IDENTIFIER = "SAS";
+ protected static final String SAS_IDENTIFIER = "SAS";
+
+ private static final int SAS_ITEMLIST_SIZE = 5;
protected String knownSASAuthorityResourceId = null;
protected String knownSASAuthorityResourceIdentifier = null;
+ protected List<String> knownSASItemIdentifiersList = new ArrayList<String>();
protected String knownSASItemResourceId = null;
protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
setupUpdate();
// Submit the request to the service and store the response.
- AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
- (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
+ AuthorityClient client = (AuthorityClient)this.getClientInstance();
Response res = client.readItem(knownResourceId, knownItemResourceId);
AUTHORITY_ITEM_TYPE vitem = null;
try {
/**
* Sync the local with the SAS
+ * @throws Exception
*/
- @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
- public void syncWithSAS(String testName) {
+ @Test(dataProvider = "testName", dependsOnMethods = {"createSASItemList", "CRUDTests"})
+ public void syncWithSAS(String testName) throws Exception {
//
// First check to see if the authority supports synchronization.
//
Response response = client.syncByName(knownSASAuthorityResourceIdentifier); // Notice we're using the Short ID (short ID is the same on the local and SAS)
try {
int statusCode = response.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ } finally {
+ response.close();
+ }
+
+ //
+ // Check to see if the parent authority (local) is in the "Replicated" state.
+ //
+ setupRead();
+ response = client.readByName(knownSASAuthorityResourceIdentifier); // Notice we're using the Short ID (short ID is the same on the local and SAS)
+ try {
+ int statusCode = response.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ String workflowState = this.extractAuthorityWorkflowState(response);
+ Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // After a sync, the parent should be in the "Replicated" state
+ } finally {
+ response.close();
+ }
+
+ }
+
+ /**
+ * Check to make sure the sync with the SAS returned the correct number of items as well as items
+ * with the correct short IDs.
+ *
+ */
+ @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSAS", "CRUDTests"})
+ public void veryifySyncWithSAS(String testName) {
+ // Perform setup.
+ setupReadList();
+
+ // Submit the request to the service and store the response.
+ AuthorityClient client = (AuthorityClient) getClientInstance();
+ Response res = null;
+ res = client.readItemListForNamedAuthority(knownSASAuthorityResourceIdentifier, null, null);
+
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
if (logger.isDebugEnabled()) {
- logger.debug(testName + ": HTTP status = " + statusCode);
+ logger.debug(" " + testName + ": status = " + statusCode);
}
Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
invalidStatusCodeMessage(testRequestType, statusCode));
Assert.assertEquals(statusCode, testExpectedStatusCode);
+
+ AbstractCommonList list = res.readEntity(AbstractCommonList.class);
+ List<AbstractCommonList.ListItem> items = list.getListItem();
+ int nItemsReturned = items.size();
+ long nItemsTotal = list.getTotalItems();
+ if (logger.isDebugEnabled()) {
+ logger.debug(" " + testName + ": Expected "
+ + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
+ }
+ Assert.assertEquals(nItemsTotal, SAS_ITEMLIST_SIZE);
+
+ for (AbstractCommonList.ListItem item : items) {
+ String shortId = AbstractCommonListUtils.ListItemGetElementValue(
+ item, AuthorityClient.SHORT_IDENTIFIER);
+ Assert.assertTrue(knownSASItemIdentifiersList.contains(shortId)); // The local short ID should be in SAS list
+
+ String workflowState = AbstractCommonListUtils.ListItemGetElementValue(
+ item, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
+ Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // Workflow state must show up in a "replicated" state
+
+ String refName = AbstractCommonListUtils.ListItemGetElementValue(
+ item, AuthorityClient.REF_NAME);
+ Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
+ String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.TERM_DISPLAY_NAME);
+ String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.VOCAB_DISPLAY_NAME);
+ // One of these names needs to be set.
+ Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
+ }
+
+ if(logger.isTraceEnabled()){
+ AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
+ }
} finally {
- response.close();
+ res.close();
}
}
* @param testName
*/
@Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
- public void createSASItem(String testName) {
+ public void createSASItemList(String testName) {
//
// First check to see if the authority supports synchronization.
//
// Perform setup.
setupCreate();
- String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
- String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
+ for (int i = 0; i < SAS_ITEMLIST_SIZE; i++) {
+ String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
+ String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
+
+ // Store the ID returned from the first item resource created
+ // for additional tests below.
+ if (knownSASItemResourceId == null) {
+ knownSASItemResourceId = newID;
+ if (null != testName && logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
+ }
+ }
+
+ knownSASItemIdentifiersList.add(shortId);
- // Store the ID returned from the first item resource created
- // for additional tests below.
- if (knownSASItemResourceId == null) {
- knownSASItemResourceId = newID;
- if (null != testName && logger.isDebugEnabled()) {
- logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
- }
+ //
+ // Keep track of the SAS authority items we create, so we can delete them from
+ // the *local* authority after we perform a sync operation. We need to keep track
+ // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
+ //
+ this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
}
- //
- // Keep track of the SAS authority items we create, so we can delete them from
- // the *local* authority after we perform a sync operation. We need to keep track
- // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
- //
- this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
+
}
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
return result;
}
+
/**
* Extracts the short ID from a service request payload
* @return
* @throws Exception
*/
- public String extractAuthorityShortId(Response res) throws Exception {
+ protected String extractAuthorityShortId(Response res) throws Exception {
String result = null;
PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
result = XmlTools.getElementValue(document, "//" + AuthorityClient.SHORT_IDENTIFIER);
return result;
- }
+ }
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
AUTHORITY_ITEM_TYPE theUpdate = null;
// Retrieve the contents of a resource to update.
- AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
- (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
+ AuthorityClient client = (AuthorityClient)this.getClientInstance();
Response res = client.readItem(knownResourceId, knownItemResourceId);
try {
if (logger.isDebugEnabled()) {
}
}
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"readItem", "CRUDTests", "veryifySyncWithSAS"})
+ public void updateLocalItemWithSync(String testName) throws Exception {
+ // Perform setup.
+ setupUpdate();
+ AUTHORITY_ITEM_TYPE theUpdate = null;
+
+ // Retrieve the contents of a shared authority item that we're going to update.
+ AUTHORITY_ITEM_TYPE sasAuthorityItem = null;
+ AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
+ Response res = sasClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceIdentifier, knownSASItemIdentifiersList.get(0));
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
+
+ sasAuthorityItem = extractItemCommonPartValue(res); // This is a SAS authority item
+ Assert.assertNotNull(sasAuthorityItem);
+ } finally {
+ res.close();
+ }
+
+ // Update the contents of this authority item so we can post an UPDATE to the server
+ theUpdate = updateItemInstance(sasAuthorityItem);
+
+ // Submit the updated authority item and check the response.
+ PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
+ res = sasClient.updateNamedItemInNamedAuthority(knownSASAuthorityResourceIdentifier, knownSASItemIdentifiersList.get(0), output);
+ AUTHORITY_ITEM_TYPE updatedAuthorityItem = null;
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+
+ // Retrieve the updated authority item and verify that its contents exist.
+ updatedAuthorityItem = extractItemCommonPartValue(res);
+ Assert.assertNotNull(updatedAuthorityItem);
+
+ compareUpdatedItemInstances(theUpdate, updatedAuthorityItem);
+ } finally {
+ res.close();
+ }
+
+ // Synchronize the item's parent authority and verify the update we just made
+ // to the SAS appears locally
+ setupSync();
+ AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
+ Response response = localClient.syncByName(knownSASAuthorityResourceIdentifier); // Notice we're using the Short ID (short ID is the same on the local and SAS)
+ try {
+ int statusCode = response.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ } finally {
+ response.close();
+ }
+
+ setupRead();
+ res = localClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceIdentifier, knownSASItemIdentifiersList.get(0));
+ try {
+ Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
+ AUTHORITY_ITEM_TYPE syncedAuthorityItem = extractItemCommonPartValue(res);
+ Assert.assertNotNull(syncedAuthorityItem);
+ compareUpdatedItemInstances(sasAuthorityItem, updatedAuthorityItem);
+ } finally {
+ res.close();
+ }
+ }
+
protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
/* (non-Javadoc)
// Submit the request to the service and store the response.
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in update(), below.
- AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
- (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
+ AuthorityClient client = (AuthorityClient)this.getClientInstance();
PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
try {
import javax.ws.rs.core.Response;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.AbstractCommonListUtils;
+import org.collectionspace.services.client.XmlTools;
+import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.dom4j.Document;
import org.jboss.resteasy.client.ClientResponse;
import org.testng.Assert;
return list.getTotalItems();
}
+ /**
+ * Extracts the workflow state of PoxPayloadIn
+ *
+ * @param res
+ * @return
+ * @throws Exception
+ */
+ protected String extractAuthorityWorkflowState(PoxPayloadIn input) throws Exception {
+ String result = null;
+
+ Document document = input.getDOMDocument();
+ result = XmlTools.getElementValue(document, "//" + WorkflowClient.WORKFLOWSTATE_XML_ELEMENT_NAME);
+
+ return result;
+ }
+
+ /**
+ * Extracts the workflow state of a response payload
+ *
+ * @param res
+ * @return
+ * @throws Exception
+ */
+ protected String extractAuthorityWorkflowState(Response res) throws Exception {
+ String result = null;
+
+ PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
+ result = extractAuthorityWorkflowState(input);
+
+ return result;
+ }
+
/**
* The entity type expected from the JAX-RS Response object
*/
package org.collectionspace.services.client.test;
import java.io.File;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.TypeVariable;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.workflow.WorkflowCommon;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.workflow.WorkflowClient;
-import org.jboss.resteasy.client.ClientResponse;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
-
-import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
/**
//
Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);
}
-
}
return result;
}
- /*
- * We should change this code. The RepositoryClient (from call to getRepositoryClient) should support a call doWorkflowTransition() instead.
- */
- //FIXME: This method is almost identical to the method org.collectionspace.services.common.vocabulary.updateWorkflowWithTransition() so
- // they should be consolidated -be DRY (don't repeat yourself).
+ public PoxPayloadOut updateWorkflowWithTransition(ServiceContext existingContext,
+ String csid,
+ String transition) {
- @PUT
- @Path("{csid}" + WorkflowClient.SERVICE_PATH + "/" + "{transition}")
- public byte[] updateWorkflowWithTransition(
- @Context UriInfo uriInfo,
- @PathParam("csid") String csid,
- @PathParam("transition") String transition) {
PoxPayloadOut result = null;
try {
+ MultipartServiceContext ctx = (MultipartServiceContext)existingContext;
//
// Create an empty workflow_commons input part and set it into a new "workflow" sub-resource context
PoxPayloadIn input = new PoxPayloadIn(WorkflowClient.SERVICE_PAYLOAD_NAME, new WorkflowCommon(),
WorkflowClient.SERVICE_COMMONPART_NAME);
- MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input, uriInfo);
+ ctx.setInput(input);
// Create a service context and document handler for the parent resource.
- ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(uriInfo);
- DocumentHandler targetDocHandler = this.createDocumentHandler(parentCtx);
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(ctx.getUriInfo());
+ DocumentHandler targetDocHandler = createDocumentHandler(parentCtx);
ctx.setProperty(WorkflowClient.TARGET_DOCHANDLER, targetDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method
// When looking for the document, we need to use the parent's workspace name -not the "workflow" workspace name
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
}
+
+ return result;
+
+ }
+
+ /*
+ * We should consider changing this code. The RepositoryClient (from call to getRepositoryClient) could support a call doWorkflowTransition() instead?
+ */
+ @PUT
+ @Path("{csid}" + WorkflowClient.SERVICE_PATH + "/" + "{transition}")
+ public byte[] updateWorkflowWithTransition(
+ @Context UriInfo uriInfo,
+ @PathParam("csid") String csid,
+ @PathParam("transition") String transition) {
+ PoxPayloadOut result = null;
+
+ try {
+ ServiceContext ctx = (ServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo);
+ result = this.updateWorkflowWithTransition(ctx, csid, transition);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
+ }
+
return result.getBytes();
}
public static final String SERVICE_TYPE_OBJECT = "object";
public static final String SERVICE_TYPE_PROCEDURE = "procedure";
public static final String SERVICE_TYPE_AUTHORITY = "authority";
+ public static final String SERVICE_TYPE_VOCABULARY = "vocabulary";
public static final String SERVICE_TYPE_UTILITY = "utility";
public static final String SERVICE_TYPE_SECURITY = "security";
public static final String SERVICE_COMMONPART_ID = "1";
private final static String INDEX_SEP = "_";
private final static String INDEX_SUFFIX = INDEX_SEP + "idx";
private final static String SHORT_ID = AuthorityClient.SHORT_IDENTIFIER.toLowerCase();
+ private final static String IN_AUTHORITY = AuthorityClient.IN_AUTHORITY.toLowerCase();
+
+ private final static String AUTHORITY_TYPE = ServiceBindingUtils.SERVICE_TYPE_AUTHORITY;
+ private final static String VOCABULARY_TYPE = ServiceBindingUtils.SERVICE_TYPE_VOCABULARY;
/** See the class javadoc for this class: it shows the syntax supported in the configuration params.
* @return
* @throws Exception
*/
- private boolean shortIdConstraintExists(String dataSourceName,
+ private boolean shortIdConstraintExists(ServiceBindingType sbt,
+ String dataSourceName,
String repositoryName,
String cspaceInstanceId,
String tableName) throws Exception {
return result;
}
- private boolean createShortIdConstraint(String dataSourceName,
+ private boolean createShortIdConstraint(ServiceBindingType sbt,
+ String dataSourceName,
String repositoryName,
String cspaceInstanceId,
String tableName) {
DatabaseProductType databaseProductType = JDBCTools.getDatabaseProductType(dataSourceName, repositoryName);
if (databaseProductType == DatabaseProductType.POSTGRESQL) {
String constraintName = String.format("%s_%s_unique", tableName, SHORT_ID);
- sql = String.format("ALTER TABLE %s add CONSTRAINT %s UNIQUE (%s)",
- tableName, constraintName, SHORT_ID);
+ //
+ // Check if we've got a parent or an item. Parents need the constraint on the short id, but items
+ // have the constraint on the combined shortidentifier and inauthority (parent's CSID) columns
+ //
+ String serviceType = sbt.getType();
+ if (serviceType.equalsIgnoreCase(AUTHORITY_TYPE) || serviceType.equalsIgnoreCase(VOCABULARY_TYPE)) {
+ sql = String.format("ALTER TABLE %s add CONSTRAINT %s UNIQUE (%s, %s)", // constraint for an item
+ tableName, constraintName, SHORT_ID, IN_AUTHORITY);
+ } else {
+ sql = String.format("ALTER TABLE %s add CONSTRAINT %s UNIQUE (%s)", // constraint for a parent
+ tableName, constraintName, SHORT_ID);
+ }
} else {
errorMsg = String.format("Database server type '%s' is not supported by CollectionSpace. Could not create constraint on column '%s' of table '%s'.",
databaseProductType.getName(), SHORT_ID, tableName);
//
// If the constraint doesn't exist, create it.
//
- if (shortIdConstraintExists(dataSourceName, repositoryName, cspaceInstanceId, tableName) == false) {
- if (createShortIdConstraint(dataSourceName, repositoryName, cspaceInstanceId, tableName) == true) {
+ if (shortIdConstraintExists(sbt, dataSourceName, repositoryName, cspaceInstanceId, tableName) == false) {
+ if (createShortIdConstraint(sbt, dataSourceName, repositoryName, cspaceInstanceId, tableName) == true) {
logger.info(String.format("Created uniqueness constraint on '%s' column of table '%s' in repository '%s'.",
SHORT_ID, tableName, repositoryName));
} else {
+ " AND " + (authTermInfo.inAuthority.name != null
? authTermInfo.inAuthority.name : authTermInfo.inAuthority.csid)
+ " AND " + (authTermInfo.name != null
- ? authTermInfo.name : authTermInfo.csid); // REM - This seems likely to cause trouble. We should consider searching for the full refname -excluding the display name suffix
+ ? authTermInfo.name : authTermInfo.csid); // REM - This seems likely to cause trouble? We should consider searching for the full refname -excluding the display name suffix?
String whereClauseStr = QueryManager.createWhereClauseFromKeywords(keywords);
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.document.DocumentException;
+import org.apache.http.HttpStatus;
+
+import org.nuxeo.ecm.core.api.ConcurrentUpdateException;
import org.nuxeo.ecm.core.api.WrappedException;
public class NuxeoDocumentException extends DocumentException {
public NuxeoDocumentException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
+ if (cause instanceof ConcurrentUpdateException) {
+ this.setErrorCode(HttpStatus.SC_CONFLICT); // HttpStatus.CONFLICT_409
+ }
}
private static String getExceptionClassName(Throwable exception) {
@Override
public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
throws Exception {
- // Do nothing by default, but children can override if they want. The real workflow transition happens in the WorkflowDocumemtModelHandler class
+ // Do nothing by default, but children can override if they want. The real workflow transition happens in the WorkflowDocumentModelHandler class
}
@Override
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.concept.ConceptauthoritiesCommon;
import org.collectionspace.services.concept.ConceptsCommon;
/**
* The Class ConceptAuthorityClient.
*/
-public class ConceptAuthorityClient extends AuthorityClientImpl<ConceptsCommon, ConceptAuthorityProxy> {
+public class ConceptAuthorityClient extends AuthorityClientImpl<ConceptauthoritiesCommon, ConceptsCommon, ConceptAuthorityProxy> {
public static final String SERVICE_NAME = "conceptauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
* ILT - Authority item list type
* P - Proxy type
*/
-public interface AuthorityWithContactsClient<AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
- extends AuthorityClient<AUTHORITY_ITEM_TYPE, P> {
+public interface AuthorityWithContactsClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
+ extends AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P> {
/**
* Creates the contact.
*
* ILT - Authority item list type
* P - Proxy type
*/
-public abstract class AuthorityWithContactsClientImpl<AUTHORITY_ITEM_TYPE, P extends AuthorityWithContactsProxy>
- extends AuthorityClientImpl<AUTHORITY_ITEM_TYPE, P>
- implements AuthorityWithContactsClient<AUTHORITY_ITEM_TYPE, P> {
+public abstract class AuthorityWithContactsClientImpl<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P extends AuthorityWithContactsProxy>
+ extends AuthorityClientImpl<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P>
+ implements AuthorityWithContactsClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P> {
public AuthorityWithContactsClientImpl(String clientPropertiesFilename) {
super(clientPropertiesFilename);
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.location.LocationauthoritiesCommon;
import org.collectionspace.services.location.LocationsCommon;
/**
* The Class LocationAuthorityClient.
*/
-public class LocationAuthorityClient extends AuthorityClientImpl<LocationsCommon, LocationAuthorityProxy> {
+public class LocationAuthorityClient extends AuthorityClientImpl<LocationauthoritiesCommon, LocationsCommon, LocationAuthorityProxy> {
public static final String SERVICE_NAME = "locationauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.material.MaterialauthoritiesCommon;
import org.collectionspace.services.material.MaterialsCommon;
/**
* The Class MaterialAuthorityClient.
*/
-public class MaterialAuthorityClient extends AuthorityClientImpl<MaterialsCommon, MaterialAuthorityProxy> {
+public class MaterialAuthorityClient extends AuthorityClientImpl<MaterialauthoritiesCommon, MaterialsCommon, MaterialAuthorityProxy> {
public static final String SERVICE_NAME = "materialauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
package org.collectionspace.services.client;
import org.collectionspace.services.organization.OrganizationsCommon;
+import org.collectionspace.services.organization.OrgauthoritiesCommon;
/**
* The Class OrgAuthorityClient.
*/
-public class OrgAuthorityClient extends AuthorityWithContactsClientImpl<OrganizationsCommon, OrgAuthorityProxy> {
+public class OrgAuthorityClient extends AuthorityWithContactsClientImpl<OrgauthoritiesCommon, OrganizationsCommon, OrgAuthorityProxy> {
public static final String SERVICE_NAME = "orgauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.person.PersonauthoritiesCommon;
import org.collectionspace.services.person.PersonsCommon;
/**
* The Class PersonAuthorityClient.
*/
-public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<PersonsCommon, PersonAuthorityProxy> {
+public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<PersonauthoritiesCommon, PersonsCommon, PersonAuthorityProxy> {
public static final String SERVICE_NAME = "personauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.place.PlaceauthoritiesCommon;
import org.collectionspace.services.place.PlacesCommon;
/**
* The Class PlaceAuthorityClient.
*/
-public class PlaceAuthorityClient extends AuthorityClientImpl<PlacesCommon, PlaceAuthorityProxy> {
+public class PlaceAuthorityClient extends AuthorityClientImpl<PlaceauthoritiesCommon, PlacesCommon, PlaceAuthorityProxy> {
public static final String SERVICE_NAME = "placeauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
package org.collectionspace.services.client;
import org.collectionspace.services.taxonomy.TaxonCommon;
+import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
/**
* The Class TaxonomyAuthorityClient.
*/
-public class TaxonomyAuthorityClient extends AuthorityClientImpl<TaxonCommon, TaxonomyAuthorityProxy> {
+public class TaxonomyAuthorityClient extends AuthorityClientImpl<TaxonomyauthorityCommon, TaxonCommon, TaxonomyAuthorityProxy> {
public static final String SERVICE_NAME = "taxonomyauthority";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.vocabulary.VocabulariesCommon;
import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
/**
* The Class VocabularyClient.
*/
-public class VocabularyClient extends AuthorityClientImpl<VocabularyitemsCommon, VocabularyProxy> {
+public class VocabularyClient extends AuthorityClientImpl<VocabulariesCommon, VocabularyitemsCommon, VocabularyProxy> {
public static final String SERVICE_NAME = "vocabularies";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
*/
package org.collectionspace.services.client;
+import org.collectionspace.services.work.WorkauthoritiesCommon;
import org.collectionspace.services.work.WorksCommon;
/**
* The Class WorkAuthorityClient.
*/
-public class WorkAuthorityClient extends AuthorityClientImpl<WorksCommon, WorkAuthorityProxy> {
+public class WorkAuthorityClient extends AuthorityClientImpl<WorkauthoritiesCommon, WorksCommon, WorkAuthorityProxy> {
public static final String SERVICE_NAME = "workauthorities";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;