]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5262: Setting up for app layer change that will auto-initialize default vocabs...
authorremillet <remillet@yahoo.com>
Tue, 3 May 2016 01:25:26 +0000 (18:25 -0700)
committerremillet <remillet@yahoo.com>
Tue, 3 May 2016 01:25:26 +0000 (18:25 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java

index 81e0bd860076ee2e0b0d5c4f225b78523d363efe..a7eeab8e456ce9b37c466220673f72d17e680d35 100644 (file)
@@ -350,13 +350,13 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     }
 
     /**
-     * Synchronizes the authority and its terms with a Shared Authority Server.
+     * Synchronizes the authority and its items/terms with a Shared Authority Server.
      * 
      * @param specifier either a CSID or one of the urn forms
      * 
      * @return the authority
      */
-    @GET
+    @POST
     @Path("{csid}/sync")
     public byte[] synchronize(
             @Context Request request,
@@ -367,35 +367,41 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         PoxPayloadOut payloadOut = null;
         Specifier specifier;
         
-        try {
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
-            /*
-             * Make sure this authority service supports synchronization
-             */
-            if (supportsReplicating(ctx.getTenantId(), ctx.getServiceName()) == false) {
-               throw new DocumentException(Response.Status.FORBIDDEN.getStatusCode());
-            }
-            AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
-            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, identifier);
-        }
-
         //
-        // If a sync was needed and was successful, return a copy of the updated resource.  Acts like an UPDATE.
+        // Prevent multiple SAS synchronizations from occurring simultaneously by synchronizing this method.
         //
-        if (neededSync == true) {
-               result = payloadOut.getBytes();
-        } else {
-               result = String.format("Authority resource '%s' was already in sync with shared authority server.",
-                               specifier.value).getBytes();
-               Response response = Response.status(Response.Status.NOT_MODIFIED).entity(result).type("text/plain").build();
-            throw new CSWebApplicationException(response);
-        }
-                return result;
+       synchronized(AuthorityResource.class) {        
+               try {
+                   ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+                   /*
+                    * Make sure this authority service supports synchronization
+                    */
+                   if (supportsReplicating(ctx.getTenantId(), ctx.getServiceName()) == false) {
+                       throw new DocumentException(Response.Status.FORBIDDEN.getStatusCode());
+                   }
+                   AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
+                   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, identifier);
+               }
+       
+               //
+               // If a sync was needed and was successful, return a copy of the updated resource.  Acts like an UPDATE.
+               //
+               if (neededSync == true) {
+                       result = payloadOut.getBytes();
+               } else {
+                       result = String.format("Authority resource '%s' was already in sync with shared authority server.",
+                                       specifier.value).getBytes();
+                       Response response = Response.status(Response.Status.NOT_MODIFIED).entity(result).type("text/plain").build();
+                   throw new CSWebApplicationException(response);
+               }
+       }
+               
+       return result;
     }
         
     /**
@@ -1172,9 +1178,9 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
      * 
      * @param specifier either CSIDs and/or one of the urn forms
      * 
-     * @return the authority item if it was synchronized with SAS
+     * @return the authority item if it was updated/synchronized with SAS item; otherwise empty
      */
-    @GET
+    @POST
     @Path("{csid}/items/{itemcsid}/sync")
     public byte[] synchronizeItem(
                @Context ResourceMap resourceMap,
index 564f00478d74b1c3e0d4cf5be249670c19c81417..bba11709573c65f5d80c6d69c76cebc323107c18 100644 (file)
@@ -1,11 +1,6 @@
 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;
 
 /*
index 77654dd541699944f8706682dd1cf39cc8cae402..de0e158241ab8b17837f0de1a84bef3b8e0ad2d9 100644 (file)
@@ -79,12 +79,12 @@ public interface AuthorityProxy extends CollectionSpaceCommonListPoxProxy {
      */
     
     // Sync by name
-    @GET
+    @POST
     @Path("/urn:cspace:name({name})/sync")
     Response syncByName(@PathParam("name") String name);
     
     // Sync by name or CSID
-    @GET
+    @POST
     @Path("/{identifier}/sync")
     public Response sync(@PathParam("identifier") String identifier);