From 2917f15d932bee92dbe3f0b97fb8e12cc1ce6c2e Mon Sep 17 00:00:00 2001 From: remillet Date: Thu, 9 Feb 2017 15:28:01 -0800 Subject: [PATCH] CSPACE-7069: Added query params to force sycn and normalize term references to use preferred terms. --- .../AuthorityItemDocumentModelHandler.java | 2 +- .../services/client/IClientQueryParams.java | 2 + .../context/AbstractServiceContextImpl.java | 42 +++++++++++++++++++ .../common/context/ServiceContext.java | 14 +++++++ .../vocabulary/RefNameServiceUtils.java | 14 +++++-- .../client/java/DocumentModelHandler.java | 7 ++++ 6 files changed, 77 insertions(+), 4 deletions(-) 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 2d6f74a3c..b8ca7f449 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 @@ -569,7 +569,7 @@ public abstract class AuthorityItemDocumentModelHandler // // If the shared authority item is newer, update our local copy // - if (sasRev > localItemRev || localIsProposed) { + if (sasRev > localItemRev || localIsProposed || ctx.shouldForceSync()) { sasPayloadIn = AuthorityServiceUtils.filterRefnameDomains(ctx, sasPayloadIn); // We need to filter the domain name part of any and all refnames in the payload AuthorityResource authorityResource = (AuthorityResource) ctx.getResource(getAuthorityServicePath()); PoxPayloadOut payloadOut = authorityResource.updateAuthorityItem(ctx, diff --git a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java index 455e446b4..52c4ee623 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java @@ -33,4 +33,6 @@ public interface IClientQueryParams { public static final String ORDER_BY_PARAM = "sortBy"; public static final String IMPORT_TIMEOUT_PARAM = "impTimout"; public static final String UPDATE_CORE_VALUES = "updateCoreValues"; + public static final String FORCE_REFNAME_UPDATES = "forceRefnameUpdates"; + public static final String FORCE_SYCN = "forceSync"; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 9679a7177..0978b77ed 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -220,6 +220,28 @@ public abstract class AbstractServiceContextImpl return recordUpdates; } + /** + * Default value is 'FALSE' + * If this returns true, it means that the refname values in referencing objects (records that reference authority or vocabulary terms) will be updated + * regardless of their current value. This is sometimes needed when refname values become stale for one of several reasons. + * @return + */ + @Override + public boolean shouldForceUpdateRefnameReferences() { + boolean forceUpdates = false; + + MultivaluedMap queryParams = getQueryParams(); + String paramValue = queryParams.getFirst(IClientQueryParams.FORCE_REFNAME_UPDATES); + if (paramValue != null && paramValue.equalsIgnoreCase(Boolean.TRUE.toString())) { // Find our if the caller wants us to force refname updates + forceUpdates = true; + } else if (paramValue != null && paramValue.equals(Long.toString(1))) { + forceUpdates = true; + } + + return forceUpdates; + } + + /* (non-Javadoc) * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel() */ @@ -866,4 +888,24 @@ public abstract class AbstractServiceContextImpl public void setRepositoryDomain(RepositoryDomainType repositoryDomain) { this.repositoryDomain = repositoryDomain; } + + /** + * Check for a query parameter that indicates if we should force a sync even if the revision numbers indicate otherwise. + * @return + */ + @Override + public boolean shouldForceSync() { + boolean forceSync = false; + + MultivaluedMap queryParams = getQueryParams(); + String paramValue = queryParams.getFirst(IClientQueryParams.FORCE_SYCN); + if (paramValue != null && paramValue.equalsIgnoreCase(Boolean.TRUE.toString())) { // Find our if the caller wants us to force refname updates + forceSync = true; + } else if (paramValue != null && paramValue.equals(Long.toString(1))) { + forceSync = true; + } + + return forceSync; + } + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index 2eea17d9a..206d7ef5a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -102,6 +102,7 @@ public interface ServiceContext { /** * Returns TRUE unless the "recordUpdates" query param is set with a value of either "false", "FALSE", or "0" + * If set to false, core schema values (i.e. updated-at, updated-by, etc) won't be changed on updates. * @return */ public boolean shouldUpdateCoreValues(); @@ -381,6 +382,19 @@ public interface ServiceContext { */ public CollectionSpaceResource getResource( String serviceName) throws Exception; + + /** + * If this returns true, it means that the refname values in referencing objects (records that reference authority or vocabulary terms) will be updated + * regardless of their current value. This is sometimes needed when refname values become stale for one of several reasons. + * @return + */ + public boolean shouldForceUpdateRefnameReferences(); + + /** + * Check for a query parameter that indicates if we should force a sync even if the revision numbers indicate otherwise. + * @return + */ + public boolean shouldForceSync(); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index e692420dc..aa623abc7 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -594,7 +594,7 @@ public class RefNameServiceUtils { // Only match complete refNames - unless and until we decide how to resolve changes // to NPTs we will defer that and only change PTs or refNames as passed in. - int nRefsFoundThisPage = processRefObjsDocListForUpdate(docList, ctx.getTenantId(), oldRefName, + int nRefsFoundThisPage = processRefObjsDocListForUpdate(ctx, docList, ctx.getTenantId(), oldRefName, queriedServiceBindings, authRefFieldsByService, // Perform the refName updates on the list of document models newRefName); if (nRefsFoundThisPage > 0) { @@ -747,13 +747,21 @@ public class RefNameServiceUtils { } private static int processRefObjsDocListForUpdate( + ServiceContext ctx, DocumentModelList docList, String tenantId, String refName, Map queriedServiceBindings, Map> authRefFieldsByService, String newAuthorityRefName) { - return processRefObjsDocList(docList, tenantId, refName, false, queriedServiceBindings, + boolean matchBaseOnly = false; + + if (ctx.shouldForceUpdateRefnameReferences() == true) { + refName = RefNameUtils.stripAuthorityTermDisplayName(refName); + matchBaseOnly = true; + } + + return processRefObjsDocList(docList, tenantId, refName, matchBaseOnly, queriedServiceBindings, authRefFieldsByService, null, 0, 0, newAuthorityRefName); } @@ -881,7 +889,7 @@ public class RefNameServiceUtils { ilistItem.setDocName( ServiceBindingUtils.getMappedFieldInDoc(sb, ServiceBindingUtils.OBJ_NAME_PROP, docModel)); } - // Now, we have to loop over the authRefFieldsByService to figure + // Now, we have to loop over the authRefFieldsByService to figure out // out which field(s) matched this. List matchingAuthRefFields = authRefFieldsByService.get(docType); if (matchingAuthRefFields == null || matchingAuthRefFields.isEmpty()) { diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index ba8eef040..0f4442248 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -330,6 +330,13 @@ public abstract class DocumentModelHandler protected boolean hasRefNameUpdate() { boolean result = false; + // + // Check to see if the request contains a query parameter asking us to force a refname update + // + if (getServiceContext().shouldForceUpdateRefnameReferences() == true) { + return true; + } + if (Tools.notBlank(newRefNameOnUpdate) && Tools.notBlank(oldRefNameOnUpdate)) { // CSPACE-6372: refNames are different if: // - any part of the refName is different, using a case insensitive comparison, or -- 2.47.3