]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6937-A: Adding API to allow client to check whether or not an authority suppor...
authorremillet <remillet@yahoo.com>
Wed, 27 Apr 2016 18:51:02 +0000 (11:51 -0700)
committerremillet <remillet@yahoo.com>
Wed, 27 Apr 2016 18:51:02 +0000 (11:51 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.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/config/src/main/resources/service.xsd

index 4ba1a8707a641086670da959d3ce5399c7f1075b..74f95a625cf8e15b8af667eb89f528c290984dfd 100644 (file)
@@ -77,6 +77,7 @@ import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentMod
 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
 import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;
 import org.collectionspace.services.config.ClientType;
+import org.collectionspace.services.config.service.ServiceBindingType;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
@@ -339,6 +340,14 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
        }
     }
 
+    protected boolean supportsSync(String tenantId, String serviceName) {
+       boolean result = false;
+       
+        ServiceBindingType sb = getTenantBindingsReader().getServiceBinding(tenantId, getServiceName());
+        result = sb.isSupportsSynchronization();
+        
+        return result;
+    }
 
     /**
      * Synchronizes the authority and its terms with a Shared Authority Server.
@@ -352,7 +361,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     public byte[] synchronize(
             @Context Request request,
             @Context UriInfo ui,
-            @PathParam("csid") String csid) {
+            @PathParam("csid") String identifier) {
        byte[] result;
        boolean neededSync = false;
         PoxPayloadOut payloadOut = null;
@@ -360,13 +369,19 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+            /*
+             * Make sure this authority service supports synchronization
+             */
+            if (supportsSync(ctx.getTenantId(), ctx.getServiceName()) == false) {
+               throw new DocumentException(Response.Status.FORBIDDEN.getStatusCode());
+            }
             AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
-            specifier = Specifier.getSpecifier(csid, "getAuthority", "GET");
+            specifier = Specifier.getSpecifier(identifier, "getAuthority", "GET");
             handler.setShouldUpdateRevNumber(AuthorityServiceUtils.DONT_UPDATE_REV); // Never update rev number on sync calls
             neededSync = getRepositoryClient(ctx).synchronize(ctx, specifier, handler);
             payloadOut = ctx.getOutput();
         } catch (Exception e) {
-            throw bigReThrow(e, ServiceMessages.SYNC_FAILED, csid);
+            throw bigReThrow(e, ServiceMessages.SYNC_FAILED, identifier);
         }
 
         //
index a55aadd46b8a71e157b6073173b578ba065fd543..9ae1208c4d5b1f04b1d03fec85608a1d39418281 100644 (file)
@@ -64,8 +64,12 @@ public interface AuthorityClient<AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
     /*
      * Synchronization methods
      */
-    Response syncByName(String name);
-
+    
+    public Response syncByName(String name);
+    
+    public Response sync(String identifier);
+    
+    public boolean supportsSync();
     
     /*
      * READ/GET by name method
index 903c76f83017cb3880f113e6a8f3607f2981a5a8..2059a59d5a8f241d083d01f494a77ab2bbbd6798 100644 (file)
@@ -78,12 +78,32 @@ public abstract class AuthorityClientImpl<AUTHORITY_ITEM_TYPE, P extends Authori
     }
     
     /*
-     * Synchronization method
+     * Synchronization methods
      */
+    
+    @Override
     public Response syncByName(String name) {
        return getProxy().syncByName(name);
     }
-
+    
+    @Override
+    public Response sync(String identifier) {
+       return getProxy().sync(identifier);
+    }
+    
+    @Override
+    public boolean supportsSync() {
+       boolean result = true;
+       
+       Response response = getProxy().sync("-1"); // Check to see if the Authority (in general) supports sync for any of its instances
+       int status = response.getStatus();
+       if (status == Response.Status.FORBIDDEN.getStatusCode()) {
+               result = false;
+       }
+       
+       return result;
+    }
+    
     /*
      * 
      */
index 4102d548f2bbb90c73c519d1e02b8a7448603ff6..2f1500e3385ef315a478973e5dbece9923a7cd56 100644 (file)
@@ -83,6 +83,11 @@ public interface AuthorityProxy extends CollectionSpaceCommonListPoxProxy {
     @Path("/urn:cspace:name({name})/sync")
     Response syncByName(@PathParam("name") String name);
     
+    // Sync by name or CSID
+    @GET
+    @Path("/{identifier}/sync")
+    public Response sync(String identifier);
+    
     /*
      * READ/GET Methods
      */
index 79cbb15dc5ef083e6f6f10fb6650a251a1be6959..03ac2f0726f11d4dbb2216449d361f7724e072d7 100644 (file)
@@ -60,6 +60,7 @@
         <xs:attribute name="name" type="xs:string" use="required"/>
         <xs:attribute name="type" type="xs:string" use="optional"/>
         <xs:attribute name="version" type="types:VersionType" use="required"/>
+        <xs:attribute name="supportsSynchronization" type="xs:boolean" default="false"/>
     </xs:complexType>
 
     <!--