]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6953: First set of changes to support authority items' relationship syncing.
authorremillet <remillet@yahoo.com>
Mon, 16 May 2016 20:37:14 +0000 (13:37 -0700)
committerremillet <remillet@yahoo.com>
Mon, 16 May 2016 20:37:14 +0000 (13:37 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java
services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java

index 758ee4e1ec660c6d5fc746dc2c0fc3cf428a930c..2ea1c6211bf722309d68e024df99a66f5d151f2e 100644 (file)
@@ -1123,7 +1123,8 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     private PoxPayloadOut synchronizeItem(
                ServiceContext ctx,
             String parentIdentifier,
-            String itemIdentifier) throws Exception {
+            String itemIdentifier,
+            boolean syncHierarchicalRelationships) throws Exception {
        PoxPayloadOut result = null;
         AuthorityItemSpecifier specifier;
        boolean neededSync = false;
@@ -1132,6 +1133,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier);
         handler.setIsProposed(AuthorityServiceUtils.NOT_PROPOSED); // In case it was formally locally proposed, clear the proposed flag
         handler.setIsSASItem(AuthorityServiceUtils.SAS_ITEM); // Since we're sync'ing, this is now a SAS controlled item
+        handler.setShouldSyncHierarchicalRelationships(syncHierarchicalRelationships);
         // Create an authority item specifier
         Specifier parentSpecifier = Specifier.getSpecifier(parent.CSID, "getAuthority", "GET");
         Specifier itemSpecifier = Specifier.getSpecifier(itemIdentifier, "getAuthorityItem", "GET");
@@ -1158,7 +1160,8 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     public PoxPayloadOut synchronizeItemWithExistingContext(
                ServiceContext existingCtx,
             String parentIdentifier,
-            String itemIdentifier
+            String itemIdentifier,
+            boolean syncHierarchicalRelationships
             ) throws Exception {
        PoxPayloadOut result = null;
        
@@ -1168,7 +1171,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         if (existingCtx.getCurrentRepositorySession() != null) {
                ctx.setCurrentRepositorySession(existingCtx.getCurrentRepositorySession());
         }
-        result = synchronizeItem(ctx, parentIdentifier, itemIdentifier);
+        result = synchronizeItem(ctx, parentIdentifier, itemIdentifier, syncHierarchicalRelationships);
        
        return result;
     }
@@ -1193,7 +1196,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), null, resourceMap, uriInfo);
-            payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier);
+            payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier, true);
             if (payloadOut != null) {
                neededSync = true;
             }
index 3a92dfa9c46f57fd4949f146845a4231f64538c9..c3b72271f935931555e4e59b28d9e42d057fcd06 100644 (file)
@@ -78,12 +78,14 @@ public class AuthorityServiceUtils {
     //
     // Makes a call to the SAS server for a authority item payload
     //    
-    static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
+    static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType, boolean syncHierarchicalRelationships) throws Exception {
        PoxPayloadIn result = null;
        
        ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
         AuthorityClient client = (AuthorityClient) parentCtx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
-        Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
+        Response res = client.readNamedItemInNamedAuthority(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue(),
+                       AuthorityClient.INCLUDE_DELETED_ITEMS, syncHierarchicalRelationships);
+        
         try {
                int statusCode = res.getStatus();
        
index 40a590db53a9e1c591a6af41639c2d8ce58f20ae..4a7e7865fd8d6a74c07e8430c4903c914fbee492 100644 (file)
@@ -423,7 +423,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        //
        //
        try {
-               PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier);
+               PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier, false);
                if (theUpdate != null) {
                        result = 0; // means we needed to sync this item with SAS
                        logger.debug(String.format("Sync'd authority item parent='%s' id='%s with SAS.  Updated payload is: \n%s",
@@ -452,12 +452,12 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        //
        // WARNING: THIS CODE IS NOT IMPLEMENTED YET
        //
-       return result;
+       if (result == -1) return result;
        //
        // Using the item refname (with no local CSID), create specifiers that we'll use to find the local versions
        //
        
-       /*
+       
        AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(itemRefName);
        String parentIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.inAuthority.name);
        String itemIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.name);
@@ -481,7 +481,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        //
        //
        try {
-               PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier);
+               PoxPayloadOut theUpdate = authorityResource.synchronizeItemWithExistingContext(ctx, parentIdentifier, itemIdentifier, true);
                if (theUpdate != null) {
                        result = 0; // means we needed to sync this item with SAS
                        logger.debug(String.format("Sync'd authority item parent='%s' id='%s with SAS.  Updated payload is: \n%s",
@@ -494,7 +494,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        }
        
        return result; // -1 = no sync needed/possible, 0 = sync'd, 1 = created new item
-       */
+       
        
     }    
     
index fdcf0c5d529ff77082cbe950e0f0c54945fb7be8..38cff706a9b33774493a6823d337fa413a0a6589 100644 (file)
@@ -90,6 +90,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     protected String authorityItemCommonSchemaName;
     private String authorityItemTermGroupXPathBase;
     
+    private boolean syncHierarchicalRelationships = false;
     private boolean isProposed = false; // used by local authority to propose a new shared item. Allows local deployments to use new terms until they become official
     private boolean isSAS = false; // used to indicate if the authority item originated as a SAS item
     private boolean shouldUpdateRevNumber = true; // by default we should update the revision number -not true on synchronization with SAS
@@ -143,6 +144,17 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
        this.shouldUpdateRevNumber = flag;
     }
 
+    //
+    // Getter and Setter for deciding if we need to synch hierarchical relationships
+    //
+    public boolean getShouldSyncHierarchicalRelationships() {
+       return this.syncHierarchicalRelationships;
+    }
+    
+    public void setShouldSyncHierarchicalRelationships(boolean flag) {
+       this.syncHierarchicalRelationships = flag;
+    }
+
     @Override
     public void prepareSync() throws Exception {
        this.setShouldUpdateRevNumber(AuthorityServiceUtils.DONT_UPDATE_REV);  // Never update rev nums on sync operations
@@ -437,7 +449,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER);
         String localParentCsid = authorityDocModel.getName();
         //
-        // Using the short IDs of the local authority and item, create URN specifiers to retrieve the SAS authority item
+        // Using the short IDs of the local authority and item, create URN specifiers and retrieve the SAS authority item
         //
         AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(SpecifierForm.URN_NAME, authorityShortId, itemShortId);
         // Get the shared authority server's copy
index 4a8d5666f2d81e39cd4b57657f8c03c2c5c21ce4..d95b94480ed6f70834c1a235ee2ff004fc1e1e06 100644 (file)
@@ -19,6 +19,9 @@ public interface AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P e
     public static final String TERM_DISPLAY_NAME = "termDisplayName";
     public static final String VOCAB_DISPLAY_NAME = "displayName";
     public static final String REF_NAME = "refName";
+    
+    public static final Boolean INCLUDE_DELETED_ITEMS = true;
+    public static final Boolean INCLUDE_RELATIONS = true;
 
        /*
         * Basic CRUD operations
@@ -118,7 +121,16 @@ public interface AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P e
      */
     public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId);
     
-    public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted);
+    /**
+     * Read a named item in a named authority.
+     * 
+     * @param authShortId
+     * @param itemShortId
+     * @param includeDeleted
+     * @param includeRelations
+     * @return
+     */
+    public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted, Boolean includeRelations);
     
     /**
      * Read item list, filtering by partial term match, or keywords. Only one of
index 77bb53b38a3dc941b60c9d9a94d907ef19a5f20e..c2a805a4503e3084cd9dbb02ceb4c4b901f8e793 100644 (file)
@@ -12,6 +12,8 @@ public abstract class AuthorityClientImpl<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_
        implements AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P> {
 
        private static final String INCLUDE_DELETE_TRUE = Boolean.TRUE.toString();
+       private static final String INCLUDE_RELATIONS_TRUE = Boolean.TRUE.toString();
+       private static final String INCLUDE_RELATIONS_FALSE = Boolean.FALSE.toString();
        
        /*
         * Basic CRUD proxied methods
@@ -167,12 +169,12 @@ public abstract class AuthorityClientImpl<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_
      */
     @Override
        public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
-        return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, INCLUDE_DELETE_TRUE);
+        return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, INCLUDE_DELETE_TRUE, INCLUDE_RELATIONS_FALSE);
     }
 
     @Override
-       public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted) {
-        return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, includeDeleted.toString());
+       public Response readNamedItemInNamedAuthority(String authShortId, String itemShortId, Boolean includeDeleted, Boolean includeRelations) {
+        return getProxy().readNamedItemInNamedAuthority(authShortId, itemShortId, includeDeleted.toString(), includeRelations.toString());
     }
 
     /**
index 0fa2f351ae601ff89c7b334de617eba5188abe8c..dec6f470d42d88be67e6e63578a8b75dacb30817 100644 (file)
@@ -12,6 +12,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.workflow.WorkflowClient;
+import org.collectionspace.services.common.api.CommonAPI;
 
 /*
  * ILT = Item list type
@@ -123,7 +124,8 @@ public interface AuthorityProxy extends CollectionSpaceCommonListPoxProxy {
     @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})")
     Response readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, 
                @PathParam("itemspecifier") String itemspecifier,
-               @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState);
+               @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState,
+               @QueryParam(CommonAPI.showRelations_QP) String showRelations);
     
     /*
      * Item subresource List methods
index 263fe5efed62c1253b95795b0501986e204ed2b0..c8f1f697649f5afae41589195cdc3cf327a2df5b 100644 (file)
@@ -10,11 +10,11 @@ public class CommonAPI {
     public static String getVersionString(){
         return COMMON_API;
     }
-    public static String AuthorityItemCSID_REPLACE="${itemCSID}";
+    public static final String AuthorityItemCSID_REPLACE="${itemCSID}";
 
-    public static String showRelations_QP = "showRelations";
-    public static String showSiblings_QP = "showSiblings";
-    public static String showAllRelations_QP = "showAllRelations";
+    public static final String showRelations_QP = "showRelations";
+    public static final String showSiblings_QP = "showSiblings";
+    public static final String showAllRelations_QP = "showAllRelations";
     
        public static final String GENERATE_BUNDLES = "core";
        public static final String GENERATE_BINDINGS = "delta";
index 2a368922e2f6be605ff4a0a654946022be51354c..d4dcd462c2a93f35354e6d5e78da33f57a606bfc 100644 (file)
@@ -104,7 +104,7 @@ public class RelationResource extends NuxeoBasedResource {
                String objectType) throws CSWebApplicationException {
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
-            if (parentCtx != null) { // If the parent context has an open repository session then use it
+            if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { // If the parent context has a non-null and open repository session then use it
                ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession());
             }
             DocumentHandler handler = createDocumentHandler(ctx);