From 957ea7168d01797310bf2fa1f1ecf2983133f69a Mon Sep 17 00:00:00 2001 From: remillet Date: Mon, 2 May 2016 18:25:26 -0700 Subject: [PATCH] CSPACE-5262: Setting up for app layer change that will auto-initialize default vocabs and auths. --- .../common/vocabulary/AuthorityResource.java | 68 ++++++++++--------- .../services/client/AuthorityClientImpl.java | 5 -- .../services/client/AuthorityProxy.java | 4 +- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 81e0bd860..a7eeab8e4 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -350,13 +350,13 @@ public abstract class AuthorityResource } /** - * 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 PoxPayloadOut payloadOut = null; Specifier specifier; - try { - ServiceContext 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 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 * * @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, diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java index 564f00478..bba117095 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java @@ -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; /* diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java index 77654dd54..de0e15824 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java @@ -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); -- 2.47.3