From 40a2a7abc5288a9c3559f203a6d9bc4702a5035d Mon Sep 17 00:00:00 2001 From: remillet Date: Mon, 16 May 2016 13:37:14 -0700 Subject: [PATCH] CSPACE-6953: First set of changes to support authority items' relationship syncing. --- .../common/vocabulary/AuthorityResource.java | 11 +++++++---- .../common/vocabulary/AuthorityServiceUtils.java | 6 ++++-- .../nuxeo/AuthorityDocumentModelHandler.java | 10 +++++----- .../nuxeo/AuthorityItemDocumentModelHandler.java | 14 +++++++++++++- .../services/client/AuthorityClient.java | 14 +++++++++++++- .../services/client/AuthorityClientImpl.java | 8 +++++--- .../services/client/AuthorityProxy.java | 4 +++- .../services/common/api/CommonAPI.java | 8 ++++---- .../services/common/relation/RelationResource.java | 2 +- 9 files changed, 55 insertions(+), 22 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 758ee4e1e..2ea1c6211 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 @@ -1123,7 +1123,8 @@ public abstract class AuthorityResource 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 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 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 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 try { ServiceContext ctx = createServiceContext(getItemServiceName(), null, resourceMap, uriInfo); - payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier); + payloadOut = this.synchronizeItem(ctx, parentIdentifier, itemIdentifier, true); if (payloadOut != null) { neededSync = true; } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java index 3a92dfa9c..c3b72271f 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java @@ -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(); diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 40a590db5..4a7e7865f 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -423,7 +423,7 @@ public abstract class AuthorityDocumentModelHandler // // 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 // // 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 // // 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 } return result; // -1 = no sync needed/possible, 0 = sync'd, 1 = created new item - */ + } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index fdcf0c5d5..38cff706a 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -90,6 +90,7 @@ public abstract class AuthorityItemDocumentModelHandler 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 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 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 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 4a8d5666f..d95b94480 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 @@ -19,6 +19,9 @@ public interface AuthorityClient { 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 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); -- 2.47.3