#LOG.INFO Adding constraint to the relations table to prevent duplicate relationships
#TEST:
-#SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = 'relations_common' AND constraint_name = 'relations_unique';
+SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = 'relations_common' AND constraint_name = 'relations_unique';
#IF: emptyResult
-#ALTER TABLE relations_common add CONSTRAINT relations_unique UNIQUE (subjectcsid, subjectrefname, relationshiptype, objectcsid, objectrefname);
+ALTER TABLE relations_common add CONSTRAINT relations_unique UNIQUE (subjectcsid, subjectrefname, relationshiptype, objectcsid, objectrefname, active);
* The Interface RelationJAXBSchema.
*/
public interface RelationJAXBSchema {
-
+
// The Nuxeo root element name for the relation entity.
/** The Constant REL_ROOT_ELEM_NAME. */
final static String REL_ROOT_ELEM_NAME = "relationtype";
- // Need to fix conflict between the Nuxeo XSD and the JAX-B XSD for the "relation" entity
-
+ // Need to fix conflict between the Nuxeo XSD and the JAX-B XSD for the
+ // "relation" entity
+
/** The Constant CSID. */
final static String CSID = "csid";
-
+
/** The Constant RELATIONSHIP_TYPE. */
final static String RELATIONSHIP_TYPE = "relationshipType";
-
+
/** The Constant RELATIONSHIP_TYPE_DISPLAYNAME. */
final static String RELATIONSHIP_TYPE_DISPLAYNAME = "predicateDisplayName";
-
- final static String RELATIONSHIP_META_TYPE = "relationshipMetaType";
+ final static String RELATIONSHIP_ACTIVE = "active";
+ final static String RELATIONSHIP_META_TYPE = "relationshipMetaType";
- final static String SUBJECT_URI = "subjectUri";
- final static String SUBJECT_CSID = IRelationsManager.SUBJECT;
- final static String SUBJECT_REFNAME = IRelationsManager.SUBJECT_REFNAME;
- final static String SUBJECT_DOCTYPE = "subjectDocumentType";
+ final static String SUBJECT_URI = "subjectUri";
+ final static String SUBJECT_CSID = IRelationsManager.SUBJECT;
+ final static String SUBJECT_REFNAME = IRelationsManager.SUBJECT_REFNAME;
+ final static String SUBJECT_DOCTYPE = "subjectDocumentType";
- final static String OBJECT_URI = "objectUri";
- final static String OBJECT_CSID = IRelationsManager.OBJECT;
- final static String OBJECT_REFNAME = IRelationsManager.OBJECT_REFNAME;
- final static String OBJECT_DOCTYPE = "objectDocumentType";
+ final static String OBJECT_URI = "objectUri";
+ final static String OBJECT_CSID = IRelationsManager.OBJECT;
+ final static String OBJECT_REFNAME = IRelationsManager.OBJECT_REFNAME;
+ final static String OBJECT_DOCTYPE = "objectDocumentType";
}
-
-
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.common.ServiceException;
import org.collectionspace.services.common.ServiceMain;
*
* @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#handleWorkflowTransition(org.collectionspace.services.common.document.DocumentWrapper, org.collectionspace.services.lifecycle.TransitionDef)
*/
- public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
- throws Exception {
+ public void handleWorkflowTransition(ServiceContext ctx, DocumentWrapper<DocumentModel> wrapDoc,
+ TransitionDef transitionDef) throws Exception {
if (subjectOrObjectInWorkflowState(wrapDoc, WorkflowClient.WORKFLOWSTATE_LOCKED) == true) {
- throw new ServiceException(HttpURLConnection.HTTP_FORBIDDEN,
- "Cannot change a relationship if either end of it is in the workflow state: " + WorkflowClient.WORKFLOWSTATE_LOCKED);
+ throw new ServiceException(HttpURLConnection.HTTP_FORBIDDEN,
+ "Cannot change a relationship if either end of it is in the workflow state: "
+ + WorkflowClient.WORKFLOWSTATE_LOCKED);
+ } else {
+ //
+ // Toggle the 'active' flag of the relationship record -needed to correctly apply a uniqueness constrain on rows in the relations_common table
+ //
+ String transitionName = transitionDef.getName();
+ if (transitionName.equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_UNDELETE)) {
+ DocumentModel doc = wrapDoc.getWrappedObject();
+ doc.setProperty(RelationClient.SERVICE_COMMONPART_NAME, RelationJAXBSchema.RELATIONSHIP_ACTIVE, Boolean.TRUE);
+ } else if (transitionName.equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_DELETE)) {
+ DocumentModel doc = wrapDoc.getWrappedObject();
+ doc.setProperty(RelationClient.SERVICE_COMMONPART_NAME, RelationJAXBSchema.RELATIONSHIP_ACTIVE, Boolean.FALSE);
+ }
}
+
}
@Override