From 0cfef55837bd7796340266fa418e0f668da910cf Mon Sep 17 00:00:00 2001 From: remillet Date: Wed, 27 Apr 2016 11:51:02 -0700 Subject: [PATCH] CSPACE-6937-A: Adding API to allow client to check whether or not an authority supports synchronization. --- .../common/vocabulary/AuthorityResource.java | 21 +++++++++++++--- .../services/client/AuthorityClient.java | 8 +++++-- .../services/client/AuthorityClientImpl.java | 24 +++++++++++++++++-- .../services/client/AuthorityProxy.java | 5 ++++ .../config/src/main/resources/service.xsd | 1 + 5 files changed, 52 insertions(+), 7 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 4ba1a8707..74f95a625 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 @@ -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 } } + 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 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 try { ServiceContext 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); } // diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java index a55aadd46..9ae1208c4 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java @@ -64,8 +64,12 @@ public interface AuthorityClient /* * Synchronization methods */ - Response syncByName(String name); - + + public Response syncByName(String name); + + public Response sync(String identifier); + + public boolean supportsSync(); /* * READ/GET by name method 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 903c76f83..2059a59d5 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 @@ -78,12 +78,32 @@ public abstract class AuthorityClientImpl +