From c482a810acc1df1c2f709cc020dac98502f8077f Mon Sep 17 00:00:00 2001 From: remillet Date: Mon, 11 Apr 2016 13:01:28 -0700 Subject: [PATCH] CSPACE-6935: Simple sync'ing now working. Still missing hard delete and soft delete syncs. --- .../common/vocabulary/AuthorityResource.java | 28 +++++++++++-------- .../nuxeo/AuthorityDocumentModelHandler.java | 3 +- .../java/RemoteDocumentModelHandlerImpl.java | 7 ++--- .../AuthorityResourceWithContacts.java | 10 +++---- 4 files changed, 25 insertions(+), 23 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 806bad1e5..1daf48f46 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 @@ -207,9 +207,11 @@ public abstract class AuthorityResource if (parentShortIdentifier == null) { authorityRefNameBase = null; } else { - ServiceContext parentCtx = - createServiceContext(getServiceName()); - if (parentShortIdentifier.equals(FETCH_SHORT_ID)) { + ServiceContext parentCtx = createServiceContext(getServiceName()); + if (parentShortIdentifier.equals(FETCH_SHORT_ID)) { // We need to fetch this from the repo + if (ctx.getCurrentRepositorySession() != null) { + parentCtx.setCurrentRepositorySession(ctx.getCurrentRepositorySession()); // We need to use the current repo session if one exists + } // Get from parent document parentShortIdentifier = getAuthShortIdentifier(parentCtx, inAuthority); } @@ -228,20 +230,20 @@ public abstract class AuthorityResource return docHandler; } - public String getAuthShortIdentifier( - ServiceContext ctx, String authCSID) + public String getAuthShortIdentifier(ServiceContext ctx, String authCSID) throws DocumentNotFoundException, DocumentException { String shortIdentifier = null; + try { - AuthorityDocumentModelHandler handler = - (AuthorityDocumentModelHandler) createDocumentHandler(ctx); - shortIdentifier = handler.getShortIdentifier(authCSID, authorityCommonSchemaName); + AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler) createDocumentHandler(ctx); + shortIdentifier = handler.getShortIdentifier(ctx, authCSID, authorityCommonSchemaName); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception ", e); } throw new DocumentException(e); } + return shortIdentifier; } @@ -308,7 +310,7 @@ public abstract class AuthorityResource return result; } - public String lookupItemCSID(String itemspecifier, String parentcsid, String method, String op, ServiceContext ctx) + public String lookupItemCSID(ServiceContext ctx, String itemspecifier, String parentcsid, String method, String op) throws DocumentException { String itemcsid; Specifier itemSpec = getSpecifier(itemspecifier, method, op); @@ -962,7 +964,7 @@ public abstract class AuthorityResource MultivaluedMap queryParams = ctx.getQueryParams(); String parentcsid = lookupParentCSID(parentspecifier, "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS", uriInfo); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS", ctx); + String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS"); List serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); if(serviceTypes == null || serviceTypes.isEmpty()) { @@ -1013,7 +1015,7 @@ public abstract class AuthorityResource DocumentModelHandler handler = (DocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null /*no parent short ID*/); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS", ctx); + String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS"); List authRefsInfo = RefNameServiceUtils.getConfiguredAuthorityRefs(ctx); authRefList = handler.getAuthorityRefs(itemcsid, authRefsInfo); @@ -1174,7 +1176,9 @@ public abstract class AuthorityResource if (ctx == null) { ctx = createServiceContext(getItemServiceName(), theUpdate, resourceMap, uriInfo); } - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx); //use itemServiceCtx if it is not null + ctx.setInput(theUpdate); + + String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM"); //use itemServiceCtx if it is not null // We omit the parentShortId, only needed when doing a create... AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, parentShortId); 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 18c4ea89e..08637d068 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 @@ -470,12 +470,11 @@ public abstract class AuthorityDocumentModelHandler return result; } - public String getShortIdentifier(String authCSID, String schemaName) throws Exception { + public String getShortIdentifier(ServiceContext ctx, String authCSID, String schemaName) throws Exception { String shortIdentifier = null; CoreSessionInterface repoSession = null; boolean releaseSession = false; - ServiceContext ctx = this.getServiceContext(); RepositoryClientImpl nuxeoRepoClient = (RepositoryClientImpl)this.getRepositoryClient(ctx); try { repoSession = nuxeoRepoClient.getRepositorySession(ctx); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 83de91744..a70327bea 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -393,8 +393,8 @@ public abstract class RemoteDocumentModelHandlerImpl DocumentModel docModel = wrapDoc.getWrappedObject(); MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); PoxPayloadIn input = ctx.getInput(); - if (input.getParts().isEmpty()) { - String msg = "No payload found!"; + if (input == null || input.getParts().isEmpty()) { + String msg = String.format("No payload found for '%s' action.", action); logger.error(msg + "Ctx=" + getServiceContext().toString()); throw new BadRequestException(msg); } @@ -418,8 +418,7 @@ public abstract class RemoteDocumentModelHandlerImpl continue; } fillPart(part, docModel, partMeta, action, ctx); - }//rof - + } } /** diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java index b0fe84edd..ec136e99e 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -123,7 +123,7 @@ public abstract class AuthorityResourceWithContacts String parentcsid = lookupParentCSID(parentspecifier, "createContact(authority)", "CREATE_ITEM_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "createContact(item)", "CREATE_ITEM_CONTACT", itemCtx); + String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "createContact(item)", "CREATE_ITEM_CONTACT"); // Note that we have to create the service context and document // handler for the Contact service, not the main service. @@ -166,7 +166,7 @@ public abstract class AuthorityResourceWithContacts String parentcsid = lookupParentCSID(parentspecifier, "getContactList(parent)", "GET_CONTACT_LIST", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContactList(item)", "GET_CONTACT_LIST", itemCtx); + String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "getContactList(item)", "GET_CONTACT_LIST"); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid, uriInfo); DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); @@ -210,7 +210,7 @@ public abstract class AuthorityResourceWithContacts String parentcsid = lookupParentCSID(parentspecifier, "getContact(parent)", "GET_ITEM_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContact(item)", "GET_ITEM_CONTACT", itemCtx); + String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "getContact(item)", "GET_ITEM_CONTACT"); // Note that we have to create the service context and document handler for the Contact service, not the main service. ServiceContext ctx = createServiceContext(getContactServiceName()); @@ -252,7 +252,7 @@ public abstract class AuthorityResourceWithContacts String parentcsid = lookupParentCSID(parentspecifier, "updateContact(authority)", "UPDATE_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateContact(item)", "UPDATE_CONTACT", itemCtx); + String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "updateContact(item)", "UPDATE_CONTACT"); ServiceContext ctx = null; // Note that we have to create the service context and document handler for the Contact service, not the main service. @@ -288,7 +288,7 @@ public abstract class AuthorityResourceWithContacts String parentcsid = lookupParentCSID(parentspecifier, "deleteContact(authority)", "DELETE_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); - String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "deleteContact(item)", "DELETE_CONTACT", itemCtx); + String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "deleteContact(item)", "DELETE_CONTACT"); //NOTE: itemcsid is not used below. Leaving the above call in for possible side effects??? CSPACE-3175 ServiceContext ctx = null; -- 2.47.3