]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-473: Added constraint on relations_common table. Now need to update the tests...
authorRichard Millet <remillet@yahoo.com>
Sat, 17 Nov 2018 05:36:42 +0000 (21:36 -0800)
committerRichard Millet <remillet@yahoo.com>
Mon, 26 Nov 2018 21:23:57 +0000 (13:23 -0800)
3rdparty/nuxeo/nuxeo-server/7.10-HF17/config/vcsconfig.sql.txt
services/common/src/main/java/org/collectionspace/services/common/relation/RelationJAXBSchema.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index e9bb4bd728a51e754499887feba73ba926a396be..ba241564031038bd51e6afe0e52012ee72b679f7 100644 (file)
@@ -34,7 +34,7 @@ ALTER TABLE batch_common add CONSTRAINT batchname_unique UNIQUE (name);
 #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);
index b125cc06912e117e556553cade2e5535c2fca001..4a8ceda3da99c57936a9b06d5553403ffcb83753 100644 (file)
@@ -32,33 +32,32 @@ import org.collectionspace.services.client.IRelationsManager;
  * 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";
 
 }
-
-
index 6cd9d0120295c671e5ea427a0d54dd2dc55b8651..d5b757470264d711e49c112708c5ed32c6795f7d 100644 (file)
@@ -29,6 +29,7 @@ import java.net.HttpURLConnection;
 
 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;
@@ -122,12 +123,26 @@ public class RelationDocumentModelHandler
         * 
         * @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