]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-841, DRYD-855: Merging in UCB contributions to post-v6.0 master branch.
authorRichard Millet <remillet@yahoo.com>
Tue, 28 Apr 2020 22:46:15 +0000 (15:46 -0700)
committerRichard Millet <remillet@yahoo.com>
Tue, 28 Apr 2020 22:46:15 +0000 (15:46 -0700)
28 files changed:
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/batch/service/pom.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchInvocable.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/ClearLocationLabelRequestBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/ClearPotTagLabelRequestBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/ClearVoucherLabelRequestBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateAndLinkLoanOutBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/CreateVoucherBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/FormatVoucherNameBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/MergeAuthorityItemsBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/ReindexFullTextBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/TestBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateDeadFlagBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateRareFlagBatchJob.java
services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/loanout/client/src/main/resources/log4j2-surefire.xml [new file with mode: 0644]
services/person/client/src/main/resources/log4j2-surefire.xml [new file with mode: 0644]
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyConstants.java

index b29414e992252ded12bb11751d8109dea669379c..d3c47014bad4e8ea3e53178bb2722c0a3b53338f 100644 (file)
@@ -1335,6 +1335,14 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         return authRefDocList;
     }
 
+    public AuthorityRefDocList getReferencingObjects(
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> existingContext,
+            String parentspecifier,
+            String itemspecifier,
+            UriInfo uriInfo) throws Exception {
+        return getReferencingObjects(existingContext, parentspecifier, itemspecifier, uriInfo, PAGE_NUM_FROM_QUERYPARAMS, PAGE_SIZE_FROM_QUERYPARAMS, true, true);
+    }
+
     public AuthorityRefDocList getReferencingObjects(
             ServiceContext<PoxPayloadIn, PoxPayloadOut> existingContext,
             String parentspecifier,
index 4330feab8128ac3fdcf202125f391ca6e8a55ebe..b5aa244ab63d9a4acaf5ec84f5988667073faa9a 100644 (file)
             <artifactId>org.collectionspace.services.taxonomy.service</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.vocabulary.service</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.group.service</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
         <!-- External dependencies -->
+        
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index d608b39f5ec399619d361061bdcd170ce6912f16..2942a85c005b4138afe2afaeffb12425695d92ad 100644 (file)
@@ -15,4 +15,6 @@ public interface BatchInvocable extends Invocable {
        public CoreSessionInterface getRepoSession();
 
        public String getTenantId();
+       
+    public void run(BatchCommon batchCommon);
 }
index 3762dfa4704077f31e28c799a3d9b9296ad1aa12..497de9e07b47e5fb11c4b52237734c2b3e3b4364 100644 (file)
@@ -7,6 +7,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
@@ -15,6 +17,7 @@ import javax.ws.rs.core.UriInfo;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 
+import org.collectionspace.services.batch.BatchCommon;
 import org.collectionspace.services.batch.AbstractBatchInvocable;
 import org.collectionspace.services.client.CollectionObjectClient;
 import org.collectionspace.services.client.CollectionSpaceClient;
@@ -59,6 +62,19 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
 
        private Map<String, String> authorityServiceNamesByDocType;
 
+       @SuppressWarnings("unchecked")
+       protected static <T> Set<T> convertListToSet(List<T> list) 
+    { 
+        // create a set from the List 
+        return (Set<T>) list.stream().collect(Collectors.toSet()); 
+    }
+       
+       @Override
+       public void run(BatchCommon batchCommon) {
+               String errMsg = String.format("%s class does not support run(BatchCommon batchCommon) method.", getClass().getName());
+               throw new java.lang.UnsupportedOperationException(errMsg);
+       }
+
        protected String getFieldXml(Map<String, String> fields, String fieldName) {
                return getFieldXml(fieldName, fields.get(fieldName));
        }
@@ -95,7 +111,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                        "</document>";
 
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(RelationClient.SERVICE_NAME);
-               Response response = resource.create(getResourceMap(), null, createRelationPayload);
+               Response response = resource.create(getServiceContext(), getResourceMap(), null, createRelationPayload);
 
                if (response.getStatus() == CREATED_STATUS) {
                        relationCsid = CollectionSpaceClientUtils.extractId(response);
@@ -121,7 +137,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
         */
        protected List<RelationListItem> findRelated(String subjectCsid, String subjectDocType, String predicate, String objectCsid, String objectDocType) throws URISyntaxException {
                RelationResource relationResource = (RelationResource) getResourceMap().get(RelationClient.SERVICE_NAME);
-               RelationsCommonList relationList = relationResource.getList(createRelationSearchUriInfo(subjectCsid, subjectDocType, predicate, objectCsid, objectDocType));
+               RelationsCommonList relationList = relationResource.getList(getServiceContext(), createRelationSearchUriInfo(subjectCsid, subjectDocType, predicate, objectCsid, objectDocType));
 
                return relationList.getRelationListItem();
        }
@@ -213,7 +229,11 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                        String csid = uriParts[4];
 
                        if (items.equals("items")) {
-                               payload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
+                               try {
+                                       payload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
+                               } catch (Exception e) {
+                                       payload = null;
+                               }
                        }
                }
 
@@ -222,10 +242,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
 
        protected PoxPayloadOut findByCsid(String serviceName, String csid) throws URISyntaxException, DocumentException {
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(serviceName);
-               byte[] outputBytes = (byte[]) resource.get(null, null, createUriInfo(), csid).getEntity();
-
-               PoxPayloadOut payload = new PoxPayloadOut(outputBytes);
-
+               PoxPayloadOut payload = resource.getWithParentCtx(getServiceContext(), csid);
                return payload;
        }
 
@@ -244,11 +261,11 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
        protected List<String> findAll(String serviceName, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(serviceName);
 
-               return findAll(resource, pageSize, pageNum, null);
+               return findAll(resource, pageSize, pageNum, sortBy);
        }
 
        protected List<String> findAll(NuxeoBasedResource resource, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
-               AbstractCommonList list = resource.getList(createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
+               AbstractCommonList list = resource.getList(getServiceContext(), createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
                List<String> csids = new ArrayList<String>();
 
                if (list instanceof RelationsCommonList) {
@@ -282,7 +299,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
        }
 
        protected List<String> getVocabularyCsids(AuthorityResource<?, ?> resource) throws URISyntaxException {
-               AbstractCommonList vocabularyList = resource.getAuthorityList(createDeleteFilterUriInfo());
+               AbstractCommonList vocabularyList = resource.getAuthorityList(getServiceContext(), createDeleteFilterUriInfo());
                List<String> csids = new ArrayList<String>();
 
                for (AbstractCommonList.ListItem item : vocabularyList.getListItem()) {
@@ -297,18 +314,18 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                return csids;
        }
 
-       protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum) throws URISyntaxException, DocumentException {
+       protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum) throws Exception {
                return findAllAuthorityItems(serviceName, vocabularyCsid, pageSize, pageNum, null);
        }
 
-       protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
+       protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws Exception {
                AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
 
                return findAllAuthorityItems(resource, vocabularyCsid, pageSize, pageNum, sortBy);
        }
 
-       protected List<String> findAllAuthorityItems(AuthorityResource<?, ?> resource, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
-               AbstractCommonList list = resource.getAuthorityItemList(vocabularyCsid, createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
+       protected List<String> findAllAuthorityItems(AuthorityResource<?, ?> resource, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws Exception {
+               AbstractCommonList list = resource.getAuthorityItemList(getServiceContext(), vocabularyCsid, createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
                List<String> csids = new ArrayList<String>();
 
                for (AbstractCommonList.ListItem item : list.getListItem()) {
@@ -333,7 +350,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
 
                        try {
                                itemPayload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
-                       } catch (CSWebApplicationException e) {
+                       } catch (Exception e) {
                                itemPayload = null;
                        }
 
@@ -345,11 +362,9 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                return itemPayload;
        }
 
-       protected PoxPayloadOut findAuthorityItemByCsid(String serviceName, String vocabularyCsid, String csid) throws URISyntaxException, DocumentException {
+       protected PoxPayloadOut findAuthorityItemByCsid(String serviceName, String vocabularyCsid, String csid) throws URISyntaxException, DocumentException, Exception {
                AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
-               byte[] response = resource.getAuthorityItem(null, createDeleteFilterUriInfo(), getResourceMap(), vocabularyCsid, csid);
-
-               PoxPayloadOut payload = new PoxPayloadOut(response);
+               PoxPayloadOut payload = resource.getAuthorityItemWithExistingContext(getServiceContext(), createDeleteFilterUriInfo(), getResourceMap(), vocabularyCsid, csid);
 
                return payload;
        }
@@ -373,37 +388,42 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                return authorityServiceNamesByDocType.get(authorityDocType);
        }
 
+       protected PoxPayloadOut findTaxonByCsid(String csid, String vocabularyCsid) throws URISyntaxException, DocumentException, Exception {
+               return findAuthorityItemByCsid(TaxonomyAuthorityClient.SERVICE_NAME, vocabularyCsid, csid);
+       }
+
        protected PoxPayloadOut findTaxonByCsid(String csid) throws URISyntaxException, DocumentException {
                return findAuthorityItemByCsid(TaxonomyAuthorityClient.SERVICE_NAME, csid);
        }
-
-       protected PoxPayloadOut findAuthorityItemByShortId(String serviceName, String vocabularyShortId, String itemShortId) throws URISyntaxException, DocumentException {
+       
+       protected PoxPayloadOut findAuthorityItemByShortId(String serviceName, String vocabularyShortId, String itemShortId) throws URISyntaxException, DocumentException, Exception {
                AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
-               byte[] response = resource.getAuthorityItem(null, createDeleteFilterUriInfo(), getResourceMap(), "urn:cspace:name(" + vocabularyShortId + ")", "urn:cspace:name(" + itemShortId + ")");
-
-               PoxPayloadOut payload = new PoxPayloadOut(response);
+               PoxPayloadOut payload = resource.getAuthorityItemWithExistingContext(getServiceContext(), createDeleteFilterUriInfo(), getResourceMap(), 
+                               "urn:cspace:name(" + vocabularyShortId + ")", "urn:cspace:name(" + itemShortId + ")");
 
                return payload;
        }
 
-       protected PoxPayloadOut findAuthorityItemByRefName(String serviceName, String refName) throws URISyntaxException, DocumentException {
+       protected PoxPayloadOut findAuthorityItemByRefName(String serviceName, String refName) throws URISyntaxException, DocumentException, Exception {
                RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
-
+               if (item == null) {
+                       return null;
+               }
                String vocabularyShortId = item.getParentShortIdentifier();
                String itemShortId = item.getShortIdentifier();
 
                return findAuthorityItemByShortId(serviceName, vocabularyShortId, itemShortId);
        }
 
-       protected PoxPayloadOut findPlaceByRefName(String refName) throws URISyntaxException, DocumentException {
+       protected PoxPayloadOut findPlaceByRefName(String refName) throws URISyntaxException, DocumentException, Exception {
                return findAuthorityItemByRefName(PlaceAuthorityClient.SERVICE_NAME, refName);
        }
 
-       protected PoxPayloadOut findTaxonByRefName(String refName) throws URISyntaxException, DocumentException {
+       protected PoxPayloadOut findTaxonByRefName(String refName) throws URISyntaxException, DocumentException, Exception {
                return findAuthorityItemByRefName(TaxonomyAuthorityClient.SERVICE_NAME, refName);
        }
 
-       protected List<AuthorityRefDocList.AuthorityRefDocItem> findReferencingFields(String serviceName, String parentCsid, String csid, String type, int pageNum, int pageSize) throws URISyntaxException {
+       protected List<AuthorityRefDocList.AuthorityRefDocItem> findReferencingFields(String serviceName, String parentCsid, String csid, String type, int pageNum, int pageSize) throws Exception {
                AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
 
                // The pageNum and pageSize params don't work right for the refobj request.
@@ -411,7 +431,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                // contain repeats of items already returned on the previous page. Any
                // code that uses this function should be aware of this.
 
-               AuthorityRefDocList refDocList = resource.getReferencingObjects(parentCsid, csid, createRefSearchFilterUriInfo(type, pageNum, pageSize));
+               AuthorityRefDocList refDocList = resource.getReferencingObjects(getServiceContext(), parentCsid, csid, createRefSearchFilterUriInfo(type, pageNum, pageSize));
 
                return refDocList.getAuthorityRefDocItem();
        }
@@ -433,9 +453,9 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
         *                    Only records that reference the given item in the specified field are returned.
         *                    If null, returns records that reference the item in any field.
         * @return            A List containing the csids of referencing records.
-        * @throws URISyntaxException
+        * @throws Exception 
         */
-       protected List<String> findReferencingObjects(String serviceName, String parentCsid, String csid, String type, String sourceField) throws URISyntaxException {
+       protected List<String> findReferencingObjects(String serviceName, String parentCsid, String csid, String type, String sourceField) throws Exception {
                logger.debug("findReferencingObjects serviceName=" + serviceName + " parentCsid=" + parentCsid + " csid=" + csid + " type=" + type + " sourceField=" + sourceField);
 
                List<AuthorityRefDocList.AuthorityRefDocItem> items = findReferencingFields(serviceName, parentCsid, csid, type, 0, 0);
@@ -456,7 +476,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                return csids;
        }
 
-       protected List<String> findReferencingObjects(String serviceName, String csid, String type, String sourceField) throws URISyntaxException, DocumentException {
+       protected List<String> findReferencingObjects(String serviceName, String csid, String type, String sourceField) throws Exception {
                logger.debug("findReferencingObjects serviceName=" + serviceName + " csid=" + csid + " type=" + type + " sourceField=" + sourceField);
 
                List<String> vocabularyCsids = getVocabularyCsids(serviceName);
@@ -479,11 +499,11 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable {
                return findReferencingObjects(serviceName, parentCsid, csid, type, sourceField);
        }
 
-       protected List<String> findReferencingCollectionObjects(String serviceName, String csid, String sourceField) throws URISyntaxException, DocumentException {
+       protected List<String> findReferencingCollectionObjects(String serviceName, String csid, String sourceField) throws Exception {
                return findReferencingObjects(serviceName, csid, ServiceBindingUtils.SERVICE_TYPE_OBJECT, sourceField);
        }
 
-       protected List<String> findReferencingCollectionObjects(String serviceName, String vocabularyShortId, String csid, String sourceField) throws URISyntaxException, DocumentException {
+       protected List<String> findReferencingCollectionObjects(String serviceName, String vocabularyShortId, String csid, String sourceField) throws Exception {
                return findReferencingObjects(serviceName, "urn:cspace:name(" + vocabularyShortId + ")", csid, ServiceBindingUtils.SERVICE_TYPE_OBJECT, sourceField);
        }
 
index d02241f6f000900d34cb28ac40a85cdede7e8354..096e4033b7a68daa533d265f58c1e6e15deb1c92 100644 (file)
@@ -296,7 +296,7 @@ public class BatchDocumentModelHandler extends NuxeoDocumentModelHandler<BatchCo
                                }
                        }
        
-                       batchInstance.run();
+                       batchInstance.run(batchCommon);
                        int status = batchInstance.getCompletionStatus();
                        if (status == Invocable.STATUS_ERROR) {
                                InvocationError error = batchInstance.getErrorInfo();
index 0d726d4c3dfbcbb4140c71c8d8e62020a64f696f..4b64312f9c2c7cdbcd18cfd9557e295183b44cd1 100644 (file)
@@ -8,11 +8,14 @@ import java.util.List;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.client.MovementClient;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.VocabularyClient;
 import org.collectionspace.services.common.NuxeoBasedResource;
 import org.collectionspace.services.common.invocable.InvocationResults;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.movement.MovementResource;
 import org.collectionspace.services.movement.nuxeo.MovementBotGardenConstants;
+import org.collectionspace.services.vocabulary.nuxeo.VocabularyConstants;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -23,16 +26,16 @@ public class ClearLocationLabelRequestBatchJob extends AbstractBatchJob {
        public ClearLocationLabelRequestBatchJob() {
                setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST, INVOCATION_MODE_NO_CONTEXT));
        }
-       
+
        @Override
        public void run() {
                setCompletionStatus(STATUS_MIN_PROGRESS);
-               
+
                try {
                        /*
                         * For now, treat any mode as if it were no context.
                         */
-                       
+
                        setResults(clearLabelRequests());
                        setCompletionStatus(STATUS_COMPLETE);
                }
@@ -42,10 +45,10 @@ public class ClearLocationLabelRequestBatchJob extends AbstractBatchJob {
                }
        }
 
-       public InvocationResults clearLabelRequests() throws URISyntaxException  {
+       public InvocationResults clearLabelRequests() throws Exception  {
                List<String> movementCsids = findLabelRequests();
                InvocationResults results = null;
-               
+
                if (movementCsids.size() > 0) {
                        results = clearLabelRequests(movementCsids);
                }
@@ -53,37 +56,40 @@ public class ClearLocationLabelRequestBatchJob extends AbstractBatchJob {
                        results = new InvocationResults();
                        results.setUserNote("No label requests found");
                }
-               
+
                return results;
        }
-       
-       public InvocationResults clearLabelRequests(String movementCsid) throws URISyntaxException  {
+
+       public InvocationResults clearLabelRequests(String movementCsid) throws Exception  {
                return clearLabelRequests(Arrays.asList(movementCsid));
        }
-       
-       public InvocationResults clearLabelRequests(List<String> movementCsids) throws URISyntaxException  {
+
+       public InvocationResults clearLabelRequests(List<String> movementCsids) throws Exception  {
                InvocationResults results = new InvocationResults();
                long numAffected = 0;
-                               
+
                for (String movementCsid : movementCsids) {
                        clearLabelRequest(movementCsid);
                        numAffected = numAffected + 1;
                }
-               
+
                results.setNumAffected(numAffected);
                results.setUserNote("Removed " + numAffected + " label " + (numAffected == 1 ? "request" : "requests"));
 
                return results;
        }
-       
-       private void clearLabelRequest(String movementCsid) throws URISyntaxException {
+
+       private void clearLabelRequest(String movementCsid) throws Exception {
                logger.debug("clear label request: movementCsid=" + movementCsid);
+               
+               PoxPayloadOut payloadout = findAuthorityItemByRefName(VocabularyClient.SERVICE_NAME, MovementBotGardenConstants.OTHER_ACTION_CODE);
+               String termDisplayName = getFieldValue(payloadout, VocabularyConstants.DISPLAY_NAME_SCHEMA_NAME, VocabularyConstants.DISPLAY_NAME_FIELD_NAME);          
 
-               final String updatePayload = 
+               final String updatePayload =
                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                        "<document name=\"movements\">" +
                                "<ns2:movements_common xmlns:ns2=\"http://collectionspace.org/services/movement\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
-                                       getFieldXml("reasonForMove", MovementBotGardenConstants.OTHER_ACTION_CODE) +
+                                       getFieldXml("reasonForMove", MovementBotGardenConstants.OTHER_ACTION_CODE + String.format("'%s'", termDisplayName)) +
                                "</ns2:movements_common>" +
                                "<ns2:movements_botgarden xmlns:ns2=\"http://collectionspace.org/services/movement/local/botgarden\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
                                        getFieldXml("labelRequested", MovementBotGardenConstants.LABEL_REQUESTED_NO_VALUE) +
@@ -92,15 +98,15 @@ public class ClearLocationLabelRequestBatchJob extends AbstractBatchJob {
                                        getFieldXml("labelCount", "") +
                                "</ns2:movements_botgarden>" +
                        "</document>";
-                               
+
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(MovementClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), movementCsid, updatePayload);
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), movementCsid, updatePayload);
        }
-       
+
        private List<String> findLabelRequests() throws URISyntaxException {
                List<String> csids = new ArrayList<String>();
                MovementResource movementResource = (MovementResource) getResourceMap().get(MovementClient.SERVICE_NAME);
-               AbstractCommonList movementList = movementResource.getList(createLabelRequestSearchUriInfo());
+               AbstractCommonList movementList = movementResource.getList(getServiceContext(), createLabelRequestSearchUriInfo());
 
                for (AbstractCommonList.ListItem item : movementList.getListItem()) {
                        for (org.w3c.dom.Element element : item.getAny()) {
@@ -116,6 +122,6 @@ public class ClearLocationLabelRequestBatchJob extends AbstractBatchJob {
 
        private UriInfo createLabelRequestSearchUriInfo() throws URISyntaxException {
                return createKeywordSearchUriInfo(MovementBotGardenConstants.LABEL_REQUESTED_SCHEMA_NAME, MovementBotGardenConstants.LABEL_REQUESTED_FIELD_NAME,
-                               MovementBotGardenConstants.LABEL_REQUESTED_YES_VALUE);          
+                               MovementBotGardenConstants.LABEL_REQUESTED_YES_VALUE);
        }
-}
\ No newline at end of file
+}
index 3da909574d92db503aa439a2ea238e3857e4a1a9..9448844d3cc1a43aef4ecf653d9106bfc3d648ac 100644 (file)
@@ -87,13 +87,13 @@ public class ClearPotTagLabelRequestBatchJob extends AbstractBatchJob {
                        "</document>";
                                
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(PottagClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), potTagCsid, updatePayload);
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), potTagCsid, updatePayload);
        }
        
        private List<String> findLabelRequests() throws URISyntaxException {
                List<String> csids = new ArrayList<String>();
                PottagResource potTagResource = (PottagResource) getResourceMap().get(PottagClient.SERVICE_NAME);
-               AbstractCommonList potTagList = potTagResource.getList(createLabelRequestSearchUriInfo());
+               AbstractCommonList potTagList = potTagResource.getList(getServiceContext(), createLabelRequestSearchUriInfo());
 
                for (AbstractCommonList.ListItem item : potTagList.getListItem()) {
                        for (org.w3c.dom.Element element : item.getAny()) {
index c48c5d338200007a5c896b20deea542f0f620abf..71b8119db38de352cf461e0f9ceb35515b4f2a8c 100644 (file)
@@ -87,13 +87,13 @@ public class ClearVoucherLabelRequestBatchJob extends AbstractBatchJob {
                        "</document>";
                                
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(LoanoutClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), loanoutCsid, updatePayload);
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), loanoutCsid, updatePayload);
        }
        
        private List<String> findLabelRequests() throws URISyntaxException {
                List<String> csids = new ArrayList<String>();
                LoanoutResource loanoutResource = (LoanoutResource) getResourceMap().get(LoanoutClient.SERVICE_NAME);
-               AbstractCommonList loanoutList = loanoutResource.getList(createLabelRequestSearchUriInfo());
+               AbstractCommonList loanoutList = loanoutResource.getList(getServiceContext(), createLabelRequestSearchUriInfo());
 
                for (AbstractCommonList.ListItem item : loanoutList.getListItem()) {
                        for (org.w3c.dom.Element element : item.getAny()) {
index 0b94859e06a05381c96cbb077ed88c17676d1315..bcec0088ae760e7995cd9c960e8a45fdbed53d20 100644 (file)
@@ -6,6 +6,7 @@ import java.util.List;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.batch.BatchCommon;
 import org.collectionspace.services.client.CollectionSpaceClientUtils;
 import org.collectionspace.services.common.NuxeoBasedResource;
 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
@@ -23,6 +24,11 @@ public class CreateAndLinkLoanOutBatchJob extends AbstractBatchInvocable {
         setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST));
        }
        
+       @Override
+       public void run(BatchCommon batchCommon) {
+               run(); // Ignore batchCommon since it's not needed
+       }
+
        /**
         * The main work logic of the batch job. Will be called after setContext.
         */
index 6a23c190c80a29c3a24cb7715a0516475168f446..17606f1a5e5deed7511b308a9d994e539ecbafbe 100644 (file)
@@ -72,11 +72,11 @@ public class CreateVoucherBatchJob extends AbstractBatchJob {
                }
        }
 
-       public InvocationResults createVoucherFromCataloging(String collectionObjectCsid) throws ResourceException, URISyntaxException, DocumentException {
+       public InvocationResults createVoucherFromCataloging(String collectionObjectCsid) throws Exception {
                return createVoucherFromCataloging(collectionObjectCsid, null);
        }
        
-       public InvocationResults createVoucherFromCataloging(String collectionObjectCsid, String movementCsid) throws ResourceException, URISyntaxException, DocumentException {
+       public InvocationResults createVoucherFromCataloging(String collectionObjectCsid, String movementCsid) throws Exception {
                InvocationResults results = new InvocationResults();
 
                PoxPayloadOut collectionObjectPayload = findCollectionObjectByCsid(collectionObjectCsid);
@@ -119,14 +119,14 @@ public class CreateVoucherBatchJob extends AbstractBatchJob {
                        logger.debug("relations created: forwardRelationCsid=" + forwardRelationCsid + " backwardRelationCsid=" + backwardRelationCsid);
                        
                        results.setNumAffected(1);
-                       results.setPrimaryURICreated("loanout.html?csid=" + voucherCsid);
+                       results.setPrimaryURICreated("/loansout/" + voucherCsid);
                        results.setUserNote("Voucher created");
                }
                
                return results;
        }
        
-       private String getFieldCollectionNote(PoxPayloadOut collectionObjectPayload) throws URISyntaxException, DocumentException {
+       private String getFieldCollectionNote(PoxPayloadOut collectionObjectPayload) throws Exception {
                String placeNote = "";
                String reverseFieldCollectionPlace = getReverseFieldCollectionPlace(collectionObjectPayload);
                
@@ -159,7 +159,7 @@ public class CreateVoucherBatchJob extends AbstractBatchJob {
                return collectionNote;
        }
        
-       private String getReverseFieldCollectionPlace(PoxPayloadOut collectionObjectPayload) throws URISyntaxException, DocumentException {
+       private String getReverseFieldCollectionPlace(PoxPayloadOut collectionObjectPayload) throws Exception {
                String reverseDisplayName = null;
                String fieldCollectionPlaceRefName = getFieldValue(collectionObjectPayload, CollectionObjectBotGardenConstants.FIELD_COLLECTION_PLACE_SCHEMA_NAME, 
                                CollectionObjectBotGardenConstants.FIELD_COLLECTION_PLACE_FIELD_NAME);          
@@ -230,7 +230,7 @@ public class CreateVoucherBatchJob extends AbstractBatchJob {
                return annotation;
        }
        
-       public InvocationResults createVoucherFromCurrentLocation(String movementCsid) throws ResourceException, URISyntaxException, DocumentException {
+       public InvocationResults createVoucherFromCurrentLocation(String movementCsid) throws Exception {
                long numAffected = 0;
                String primaryUriCreated = null;
                
@@ -275,7 +275,7 @@ public class CreateVoucherBatchJob extends AbstractBatchJob {
                        "</document>";
 
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(LoanoutClient.SERVICE_NAME);
-               Response response = resource.create(getResourceMap(), null, createVoucherPayload);
+               Response response = resource.create(getServiceContext(), getResourceMap(), null, createVoucherPayload);
 
                if (response.getStatus() == CREATED_STATUS) {
                        voucherCsid = CollectionSpaceClientUtils.extractId(response);
index eb7be0a42d14eff033ac9c06b9ce142861d232de..cbe43949f3c13d39f9d2ab759a20c416d8a9ddf5 100644 (file)
@@ -104,7 +104,7 @@ public class FormatVoucherNameBatchJob extends AbstractBatchJob {
        private List<String> findLabelRequests() throws URISyntaxException {
                List<String> csids = new ArrayList<String>();
                LoanoutResource loanoutResource = (LoanoutResource) getResourceMap().get(LoanoutClient.SERVICE_NAME);
-               AbstractCommonList loanoutList = loanoutResource.getList(createLabelRequestSearchUriInfo());
+               AbstractCommonList loanoutList = loanoutResource.getList(getServiceContext(), createLabelRequestSearchUriInfo());
 
                for (AbstractCommonList.ListItem item : loanoutList.getListItem()) {
                        for (org.w3c.dom.Element element : item.getAny()) {
@@ -197,7 +197,7 @@ public class FormatVoucherNameBatchJob extends AbstractBatchJob {
                        "</document>";
                        
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(LoanoutClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), loanoutCsid, updatePayload);         
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), loanoutCsid, updatePayload);            
        }
        
        private UriInfo createLabelRequestSearchUriInfo() throws URISyntaxException {
index b0c01bbde6aaa6bb47b9333f974019281a1a4477..8faf41a1043bc40c6e49d02b30771fe84fbaf49e 100644 (file)
@@ -129,11 +129,11 @@ public class MergeAuthorityItemsBatchJob extends AbstractBatchJob {
                }
        }
 
-       public InvocationResults merge(String docType, String target, String sourceCsid) throws URISyntaxException, DocumentException {
+       public InvocationResults merge(String docType, String target, String sourceCsid) throws Exception {
                return merge(docType, target, new LinkedHashSet<String>(Arrays.asList(sourceCsid)));
        }
 
-       public InvocationResults merge(String docType, String target, Set<String> sourceCsids) throws URISyntaxException, DocumentException {
+       public InvocationResults merge(String docType, String target, Set<String> sourceCsids) throws Exception {
                logger.debug("Merging docType=" + docType + " target=" + target + " sourceCsids=" + StringUtils.join(sourceCsids, ","));
 
                String serviceName = getAuthorityServiceNameForDocType(docType);
@@ -159,7 +159,7 @@ public class MergeAuthorityItemsBatchJob extends AbstractBatchJob {
                return merge(docType, targetItemPayload, sourceItemPayloads);
        }
 
-       private InvocationResults merge(String docType, PoxPayloadOut targetItemPayload, List<PoxPayloadOut> sourceItemPayloads) throws URISyntaxException, DocumentException {
+       private InvocationResults merge(String docType, PoxPayloadOut targetItemPayload, List<PoxPayloadOut> sourceItemPayloads) throws Exception {
                int numAffected = 0;
                List<String> userNotes = new ArrayList<String>();
 
@@ -228,7 +228,7 @@ public class MergeAuthorityItemsBatchJob extends AbstractBatchJob {
                return results;
        }
 
-       private InvocationResults updateReferences(String serviceName, String inAuthority, String sourceCsid, String sourceRefName, String targetRefName) throws URISyntaxException, DocumentException {
+       private InvocationResults updateReferences(String serviceName, String inAuthority, String sourceCsid, String sourceRefName, String targetRefName) throws Exception {
                logger.debug("Updating references: serviceName=" + serviceName + " inAuthority=" + inAuthority + " sourceCsid=" + sourceCsid + " sourceRefName=" + sourceRefName + " targetRefName=" + targetRefName);
 
                String sourceDisplayName = RefNameUtils.getDisplayName(sourceRefName);
index 1d662e62944cc02d94aadedf3cd9b43e4c027fc4..c130170c2be841767eb810fd1d856b85b3008297 100644 (file)
@@ -8,7 +8,8 @@ package org.collectionspace.services.batch.nuxeo;
 import java.io.File;
 import java.io.Serializable;
 import java.lang.reflect.Field;
-import java.security.Principal;
+import java.net.URISyntaxException;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -20,6 +21,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.collectionspace.services.batch.BatchCommon;
 import org.collectionspace.services.common.CollectionSpaceResource;
 import org.collectionspace.services.common.NuxeoBasedResource;
 import org.collectionspace.services.common.StoredValuesUriTemplate;
@@ -29,11 +31,12 @@ import org.collectionspace.services.common.invocable.InvocationContext.ListCSIDs
 import org.collectionspace.services.common.invocable.InvocationContext.Params.Param;
 import org.collectionspace.services.common.invocable.InvocationResults;
 import org.collectionspace.services.common.vocabulary.AuthorityResource;
+
+import org.dom4j.DocumentException;
 import org.nuxeo.ecm.core.api.AbstractSession;
 import org.nuxeo.ecm.core.api.CoreSession;
 import org.nuxeo.ecm.core.api.IterableQueryResult;
 import org.nuxeo.ecm.core.api.NuxeoException;
-import org.nuxeo.ecm.core.api.NuxeoPrincipal;
 import org.nuxeo.ecm.core.event.EventService;
 import org.nuxeo.ecm.core.query.QueryFilter;
 import org.nuxeo.ecm.core.query.sql.NXQL;
@@ -84,9 +87,77 @@ public class ReindexFullTextBatchJob extends AbstractBatchJob {
 
                log.debug("stop file directory is " + stopFileDirectory);
        }
+       
+       //
+       // Since the ReindexFullTextBatchJob class deals with transactions differently than other batch jobs, we need to
+       // override this method to ensure there is an active transaction.
+       //
+       @Override
+       protected List<String> getVocabularyCsids(AuthorityResource<?, ?> resource) throws URISyntaxException {
+               boolean tx = false;
+               if (TransactionHelper.isTransactionActive() == false) {
+                       tx = TransactionHelper.startTransaction();
+               }
+
+               try {
+                       return super.getVocabularyCsids(resource);
+               } finally {
+                       if (tx) {
+                               TransactionHelper.commitOrRollbackTransaction();
+                       }
+               }
+       }
+
+       //
+       // Since the ReindexFullTextBatchJob class deals with transactions differently than other batch jobs, we need to
+       // override this method to ensure there is an active transaction.
+       //
+       @Override
+       protected List<String> findAll(NuxeoBasedResource resource, int pageSize, int pageNum, String sortBy)
+                       throws URISyntaxException, DocumentException {
+               boolean tx = false;
+               if (TransactionHelper.isTransactionActive() == false) {
+                       tx = TransactionHelper.startTransaction();
+               }
+               
+               try {
+                       return super.findAll(resource, pageSize, pageNum, sortBy);
+               } finally {
+                       if (tx) {
+                               TransactionHelper.commitOrRollbackTransaction();
+                       }
+               }
+       }
+
+       //
+       // Since the ReindexFullTextBatchJob class deals with transactions differently than other batch jobs, we need to
+       // override this method to ensure there is an active transaction.
+       //
+       @Override
+       protected List<String> findAllAuthorityItems(AuthorityResource<?, ?> resource, String vocabularyCsid, int pageSize, int pageNum, String sortBy)
+                       throws URISyntaxException, Exception {
+               boolean tx = false;
+               if (TransactionHelper.isTransactionActive() == false) {
+                       tx = TransactionHelper.startTransaction();
+               }
+               
+               try {
+                       return super.findAllAuthorityItems(resource, vocabularyCsid, pageSize, pageNum, sortBy);
+               } finally {
+                       if (tx) {
+                               TransactionHelper.commitOrRollbackTransaction();
+                       }
+               }
+       }
+
 
        @Override
        public void run() {
+               run(null);
+       }
+
+       @Override
+       public void run(BatchCommon batchCommon) {
                setCompletionStatus(STATUS_MIN_PROGRESS);
 
                numAffected = 0;
@@ -175,6 +246,16 @@ public class ReindexFullTextBatchJob extends AbstractBatchJob {
                                        }
                                }
 
+                               //
+                               // If docTypes is empty, we should use the <forDocTypes> list from the resource/payload
+                               //
+                               if (docTypes.isEmpty() == true && batchCommon != null) {
+                                       List<String> payloadDocTypes = batchCommon.getForDocTypes().getForDocType();
+                                       if (payloadDocTypes != null && !payloadDocTypes.isEmpty()) {
+                                               docTypes = convertListToSet(payloadDocTypes);
+                                       }
+                               }
+
                                initResourceMap();
                                reindexDocuments(docTypes);
                        }
index 0358cf9f1206e700366aaf221e4e273637326cec..58e75f036067c7fc4afcdf1bacc7f40092affca2 100644 (file)
@@ -3,6 +3,7 @@ package org.collectionspace.services.batch.nuxeo;
 import java.util.Arrays;
 
 import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.batch.BatchCommon;
 
 public class TestBatchJob extends AbstractBatchInvocable {
 
@@ -16,5 +17,9 @@ public class TestBatchJob extends AbstractBatchInvocable {
        public void run() {
                // An empty batch job used just for testing.
        }
-
+       
+       @Override
+       public void run(BatchCommon batchCommon) {
+               // An empty batch job used just for testing.
+       }
 }
index c1b2f3849332c92417f3401951b0c54dc82b8625..34c8e434d7f3e8a893c4e21a4a6524e69d08578c 100644 (file)
@@ -229,6 +229,6 @@ public class UpdateDeadFlagBatchJob extends AbstractBatchJob {
                        "</document>";
                
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(CollectionObjectClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), collectionObjectCsid, updatePayload);
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), collectionObjectCsid, updatePayload);
        }
 }
index ee1d2011dfd93e8b3a5a634a8db47fba248525c7..e5b97d128be6559606f11e6fd57613879d56e840 100644 (file)
@@ -14,6 +14,7 @@ import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.batch.BatchCommon;
 import org.collectionspace.services.client.AbstractCommonListUtils;
 import org.collectionspace.services.client.CollectionObjectClient;
 import org.collectionspace.services.client.IClientQueryParams;
@@ -74,6 +75,12 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
                 INVOCATION_MODE_GROUP, INVOCATION_MODE_NO_CONTEXT));
     }
 
+       @Override
+       public void run(BatchCommon batchCommon) {
+               String errMsg = String.format("%s class does not support run(BatchCommon batchCommon) method.", getClass().getName());
+               throw new java.lang.UnsupportedOperationException(errMsg);
+       }
+
     /**
      * The main work logic of the batch job. Will be called after setContext.
      */
@@ -395,19 +402,23 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             logger.trace("Update payload: " + "\n" + collectionObjectUpdatePayload);
         }
         
+        //
+        // Update the record and save the response for debugging message
+        //
         UriInfo uriInfo = this.setupQueryParamForUpdateRecords(); // Determines if we'll updated the updateAt and updatedBy core values
+        byte[] responseBytes = collectionObjectResource.update(getServiceContext(), resourcemap, uriInfo, collectionObjectCsid,
+                collectionObjectUpdatePayload);
+        numUpdated++;
+
         if (logger.isDebugEnabled()) {
-               byte[] responseBytes = collectionObjectResource.update(resourcemap, uriInfo, collectionObjectCsid,
-                       collectionObjectUpdatePayload);
                logger.debug(String.format("Batch resource: Resonse from collectionobject (cataloging record) update: %s", new String(responseBytes)));
         }
-        numUpdated++;
         
         if (logger.isTraceEnabled()) {
             logger.trace("Computed current location value for CollectionObject " + collectionObjectCsid
                     + " was set to " + computedCurrentLocation);
-
         }
+
         return numUpdated;
     }
     
@@ -434,7 +445,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
        PoxPayloadOut result = null;
        
        try {
-                       result = resource.getResourceFromCsid(null, createUriInfo(), csid);
+                       result = resource.getWithParentCtx(getServiceContext(), csid);
                } catch (Exception e) {
                        String msg = String.format("UpdateObjectLocation batch job could find/get resource CSID='%s' of type '%s'",
                                        csid, resource.getServiceName());
@@ -521,7 +532,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             throws URISyntaxException, DocumentException {
         boolean isDeleted = false;
         
-        byte[] workflowResponse = resource.getWorkflow(createUriInfo(), collectionObjectCsid);
+        byte[] workflowResponse = resource.getWorkflowWithExistingContext(getServiceContext(), createUriInfo(), collectionObjectCsid);
         if (workflowResponse != null) {
             PoxPayloadOut payloadOut = new PoxPayloadOut(workflowResponse);
             String workflowState =
@@ -562,7 +573,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
         }
         // The 'resource' type used here identifies the record type of the
         // related records to be retrieved
-        AbstractCommonList relatedRecords = resource.getList(uriInfo);
+        AbstractCommonList relatedRecords = resource.getList(getServiceContext(), uriInfo);
         if (logger.isTraceEnabled()) {
             logger.trace("Identified " + relatedRecords.getTotalItems()
                     + " record(s) related to the object record via direction " + relationshipDirection + " with CSID " + csid);
@@ -665,7 +676,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
         
         while (morePages == true) {
                uriInfo = addFilterForPageSize(uriInfo, currentPage, pageSize);
-               AbstractCommonList collectionObjects = collectionObjectResource.getList(uriInfo);
+               AbstractCommonList collectionObjects = collectionObjectResource.getList(getServiceContext(), uriInfo);
                appendItemsToCsidsList(noContextCsids, collectionObjects);
                
                if (collectionObjects.getItemsInPage() == pageSize) { // We know we're at the last page when the number of items returned in the last request is less than the page size.
index 85c4ca5eb8a6fea70d09a1d95f426777103a9bd7..2aba0f0209707eafcb72502ca3281a647ff00bb0 100644 (file)
@@ -107,11 +107,12 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
         * 
         * @param taxonCsid             The csid of the taxon record
         * @return
-        * @throws URISyntaxException
-        * @throws DocumentException
+        * @throws Exception 
         */
-       public InvocationResults updateReferencingRareFlags(String taxonCsid, String vocabularyCsid) throws URISyntaxException, DocumentException {
-               PoxPayloadOut taxonPayload = findTaxonByCsid(taxonCsid);
+       public InvocationResults updateReferencingRareFlags(String taxonCsid, String vocabularyCsid) throws Exception {
+               PoxPayloadOut taxonPayload = vocabularyCsid == null
+                               ? findTaxonByCsid(taxonCsid)
+                               : findTaxonByCsid(taxonCsid, vocabularyCsid);
                String taxonRefName = getFieldValue(taxonPayload, TaxonConstants.REFNAME_SCHEMA_NAME, TaxonConstants.REFNAME_FIELD_NAME);
 
                RefName.AuthorityItem item = RefName.AuthorityItem.parse(taxonRefName);
@@ -153,10 +154,9 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
         * 
         * @param collectionObjectCsid  The csid of the collectionobject
         * @return
-        * @throws URISyntaxException
-        * @throws DocumentException
+        * @throws Exception 
         */
-       public InvocationResults updateRareFlag(String collectionObjectCsid) throws URISyntaxException, DocumentException {
+       public InvocationResults updateRareFlag(String collectionObjectCsid) throws Exception {
                PoxPayloadOut collectionObjectPayload = findCollectionObjectByCsid(collectionObjectCsid);
                
                return updateRareFlag(collectionObjectPayload);
@@ -170,10 +170,9 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
         * 
         * @param collectionObjectPayload       The payload representing the collectionobject
         * @return
-        * @throws URISyntaxException
-        * @throws DocumentException
+        * @throws Exception 
         */
-       public InvocationResults updateRareFlag(PoxPayloadOut collectionObjectPayload) throws URISyntaxException, DocumentException {
+       public InvocationResults updateRareFlag(PoxPayloadOut collectionObjectPayload) throws Exception {
                InvocationResults results = new InvocationResults();
 
                String uri = this.getFieldValue(collectionObjectPayload, CollectionObjectBotGardenConstants.URI_SCHEMA_NAME, 
@@ -271,10 +270,9 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
         * 
         * @param collectionObjectCsids         The csids of the collectionobjects
         * @return
-        * @throws URISyntaxException
-        * @throws DocumentException
+        * @throws Exception
         */
-       public InvocationResults updateRareFlags(List<String> collectionObjectCsids) throws URISyntaxException, DocumentException {
+       public InvocationResults updateRareFlags(List<String> collectionObjectCsids) throws Exception {
                int numSubmitted = collectionObjectCsids.size();
                long numAffected = 0;
                
@@ -296,10 +294,9 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
         * Updates the rare flags of all collectionobjects.
         * 
         * @return
-        * @throws URISyntaxException
-        * @throws DocumentException
+        * @throws Exception
         */
-       public InvocationResults updateAllRareFlags() throws URISyntaxException, DocumentException {
+       public InvocationResults updateAllRareFlags() throws Exception {
                long numFound = 0;
                long numAffected = 0;
                
@@ -346,6 +343,6 @@ public class UpdateRareFlagBatchJob extends AbstractBatchJob {
                        "</document>";
                
                NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(CollectionObjectClient.SERVICE_NAME);
-               resource.update(getResourceMap(), createUriInfo(), collectionObjectCsid, updatePayload);
+               resource.update(getServiceContext(), getResourceMap(), createUriInfo(), collectionObjectCsid, updatePayload);
        }
 }
index 13802afe5216141469f45eb106865b496a7e29fd..7d5909d2bc73ce2f45c6d33583f85f1bbb7be414 100644 (file)
@@ -41,10 +41,13 @@ public class RefNameUtils {
 
     private final Logger logger = LoggerFactory.getLogger(RefNameUtils.class);
 
-    public static final String URN_PREFIX = "urn:cspace:";
-    public static final int URN_PREFIX_LEN = 11;
+    public static final String SEPARATOR = ":";
+    public static final String URN_PREFIX = "urn";
+    public static final String URN_CSPACE = "cspace";
+    public static final String URN_CSPACE_PREFIX = URN_PREFIX + SEPARATOR + URN_CSPACE + SEPARATOR; // "urn:cspace:"
+    public static final int URN_PREFIX_LEN = URN_CSPACE_PREFIX.length();
     public static final String URN_NAME_PREFIX = "urn:cspace:name(";
-    public static final int URN_NAME_PREFIX_LEN = 16;
+    public static final int URN_NAME_PREFIX_LEN = URN_NAME_PREFIX.length();
     public static final String NAME_SPECIFIER = "name";
     public static final String ID_SPECIFIER = "id";
     
@@ -64,9 +67,19 @@ public class RefNameUtils {
     private static final int INSTANCE_DISPLAYNAME_TOKEN = 2;// optional displayName suffix
     private static final int INSTANCE_TOKENS_MIN = 2;
     private static final int INSTANCE_TOKENS_MAX = 3;
-    public static final String SEPARATOR = ":";
 
-    public static class AuthorityInfo {
+       public static String domainToPhrase(String domain) {
+               String result = "";
+               
+               String[] split = domain.split("\\.", 0);
+               for (String token : split) {
+                       result = result + token + ' ';
+               }
+               
+               return result.trim();
+       }
+
+       public static class AuthorityInfo {
         private final Logger logger = LoggerFactory.getLogger(AuthorityInfo.class);
        private static int MIN_TOKENS = 3;
         public String domain;
@@ -197,14 +210,14 @@ public class RefNameUtils {
 
     public static AuthorityInfo parseAuthorityInfo(String refName)
             throws IllegalArgumentException {
-       if(refName==null || !refName.startsWith(URN_PREFIX))
+       if(refName==null || !refName.startsWith(URN_CSPACE_PREFIX))
                throw new IllegalArgumentException( "Null or invalid refName syntax");
        String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_REFNAME_TOKENS);
        return new AuthorityInfo(refNameTokens);
     }
 
        public static AuthorityTermInfo parseAuthorityTermInfo(String refName) throws IllegalArgumentException {
-               if (refName == null || !refName.startsWith(URN_PREFIX)) {
+               if (refName == null || !refName.startsWith(URN_CSPACE_PREFIX)) {
                        throw new IllegalArgumentException("Null or invalid refName syntax");
                }
                String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_ITEM_REFNAME_TOKENS);
@@ -213,12 +226,12 @@ public class RefNameUtils {
 
     public static String stripAuthorityTermDisplayName(String refName)
             throws IllegalArgumentException {
-       if(refName==null || !refName.startsWith(URN_PREFIX))
+       if(refName==null || !refName.startsWith(URN_CSPACE_PREFIX))
                throw new IllegalArgumentException( "Null or invalid refName syntax");
        String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_ITEM_REFNAME_TOKENS);
        int rightParen = refNameTokens[ITEM_INSTANCE_TOKEN].indexOf(')');
        refNameTokens[ITEM_INSTANCE_TOKEN] = refNameTokens[ITEM_INSTANCE_TOKEN].substring(0, rightParen+1);
-       return URN_PREFIX + implodeStringArray(refNameTokens, SEPARATOR);
+       return URN_CSPACE_PREFIX + implodeStringArray(refNameTokens, SEPARATOR);
     }
 
     public static String implodeStringArray(String tokens[], String separator) {
index 74e3bc8fbe7ecfcc13f94e90c6ff5b2fa5aa9a7b..57948fcade94b7e4653d0fc67c447fe866762138 100644 (file)
@@ -176,6 +176,13 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
     public byte[] getWorkflow(
                @Context UriInfo uriInfo,
             @PathParam("csid") String csid) {
+        return getWorkflowWithExistingContext(null, uriInfo, csid);
+    }
+
+    public byte[] getWorkflowWithExistingContext(
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> existingContext,
+            UriInfo uriInfo,
+            String csid) {
         PoxPayloadOut result = null;
 
         try {
@@ -183,6 +190,9 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
             String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName();
 
             MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo);
+            if (existingContext != null && existingContext.getCurrentRepositorySession() != null) {
+               ctx.setCurrentRepositorySession(existingContext.getCurrentRepositorySession()); // Reuse the current repo session if one exists
+            }
             WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);
             ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace
             getRepositoryClient(ctx).get(ctx, csid, handler);
index 7fe0f5ddef4a2c74b6188c64589f0be6bf1144d5..ec8de6f6f0a16b96049fd0227d4faee467160b39 100644 (file)
@@ -474,7 +474,8 @@ public abstract class NuxeoBasedResource
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
             if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {
                 ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists
-            }            DocumentHandler handler = createDocumentHandler(ctx);
+            }
+            DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
             return list;
index e3f2fd6a9764bcccd4203a40de08eea3e24b6d45..42de8cf371bce2f00a1bd878e536ecf3bbb96a07 100644 (file)
@@ -54,7 +54,7 @@ public class SecurityContextImpl implements SecurityContext {
             // If anonymous access is being attempted, then a tenant ID needs to be set as a query param
             //
             if (uriInfo == null) {
-                String errMsg = "Anonymous access attempted with null UriInfo.";
+                       String errMsg = "Anonymous access attempted with missing or invalid tenant ID query or path paramter. A null 'UriInfo' instance was passed into the service context constructor.";
                 logger.warn(errMsg);
                 throw new UnauthorizedException(errMsg);
             }
index a67fa584d7fcbd50021d8459efa7d1fcc0ad69ec..84548e3f6b5cc2e9c4f297318a925cc60e67c1b3 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Map;
 
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.context.AbstractServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -18,6 +19,9 @@ import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.collect.AbstractIterator;
 
 /**
@@ -32,6 +36,7 @@ import com.google.common.collect.AbstractIterator;
  * 
  */
 public class LazyAuthorityRefDocList extends DocumentModelListImpl {
+    private static final Logger logger = LoggerFactory.getLogger(LazyAuthorityRefDocList.class);
        private static final long serialVersionUID = 1L;
        
        private ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx;
@@ -197,8 +202,9 @@ public class LazyAuthorityRefDocList extends DocumentModelListImpl {
                        
                        try {
                                nextPageDocList = fetchPage(nextPageNum, false, true);
+                       } catch(DocumentException e) {
+                               logger.error(e.getMessage());
                        }
-                       catch(DocumentException e) {}
                        
                        if (nextPageDocList == null || nextPageDocList.size() == 0) {
                                // There are no more pages.
index 3d07d672aa51924b706a765224e19610219327d9..c23781154bfe9e1cfb95b411e97d0067f39c083f 100644 (file)
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import javax.ws.rs.core.Response;
 
@@ -44,8 +45,10 @@ import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.IRelationsManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.Profiler;
 import org.collectionspace.services.common.CSWebApplicationException;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.ServletTools;
 import org.collectionspace.services.common.StoredValuesUriTemplate;
 import org.collectionspace.services.common.UriTemplateFactory;
 import org.collectionspace.services.common.UriTemplateRegistry;
@@ -429,7 +432,8 @@ public class RefNameServiceUtils {
                     authRefFieldsByService,
                     filter.getWhereClause(), 
                     null, // orderByClause
-                    2*pageSize,
+                    2, // pageScale
+                    pageSize,
                     useDefaultOrderByClause,
                     computeTotal);
 
@@ -454,7 +458,7 @@ public class RefNameServiceUtils {
                String strippedRefName = RefNameUtils.stripAuthorityTermDisplayName(refName);
                
                // *** Need to pass in pagination info here. 
-            int nRefsFound = processRefObjsDocListForList(docList, ctx.getTenantId(), strippedRefName, 
+            long nRefsFound = processRefObjsDocListForList(docList, ctx.getTenantId(), strippedRefName, 
                        queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"
                     list, pageSize, pageNum);
                
@@ -554,7 +558,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(ctx, docList, ctx.getTenantId(), oldRefName, 
+                long nRefsFoundThisPage = processRefObjsDocListForUpdate(ctx, docList, ctx.getTenantId(), oldRefName, 
                                queriedServiceBindings, authRefFieldsByService, // Perform the refName updates on the list of document models
                         newRefName);
                 if (nRefsFoundThisPage > 0) {
@@ -589,6 +593,7 @@ public class RefNameServiceUtils {
             Map<String, List<AuthRefConfigInfo>> authRefFieldsByService,
             String whereClauseAdditions,
             String orderByClause,
+            int pageScale,
             int pageSize,
             boolean useDefaultOrderByClause,
             boolean computeTotal) throws DocumentException, DocumentNotFoundException {
@@ -603,7 +608,7 @@ public class RefNameServiceUtils {
                                authRefFieldsByService,
                                whereClauseAdditions, 
                                orderByClause,
-                               pageSize, 
+                               pageSize*pageScale
                                useDefaultOrderByClause, 
                                computeTotal);
     }
@@ -642,24 +647,88 @@ public class RefNameServiceUtils {
         if (query == null) { // found no authRef fields - nothing to query
             return null;
         }
+        
         // Additional qualifications, like workflow state
         if (Tools.notBlank(whereClauseAdditions)) {
             query += " AND " + whereClauseAdditions;
         }
+        
         // Now we have to issue the search
-        NuxeoRepositoryClientImpl nuxeoRepoClient = (NuxeoRepositoryClientImpl) repoClient;
-        DocumentWrapper<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(
+        DocumentModelList docList = findDocs(
+                       repoClient,
                 ctx,
                 repoSession,
                 docTypes, 
                 query, 
-                orderByClause, 
-                pageNum, 
-                pageSize, 
+                orderByClause,
+                pageNum,
+                pageSize,
                 useDefaultOrderByClause, 
                 computeTotal);
-        // Now we gather the info for each document into the list and return
-        DocumentModelList docList = docListWrapper.getWrappedObject();
+
+        return docList;
+    }
+    
+    private static final DocumentModelList findDocs(
+               RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+            CoreSessionInterface repoSession,
+            List<String> docTypes,
+            String query,
+            String orderByClause,
+            int pageNum,
+            int pageSize,
+            boolean useDefaultOrderByClause,
+            boolean computeTotal)
+            throws DocumentNotFoundException, DocumentException {
+        Profiler profiler = new Profiler(query, 0);
+
+        // Start timing.
+        profiler.start();
+        UUID uuid = UUID.randomUUID();
+
+        // Write a CSV-delimited message to the performance log,
+        // in a format intended to be interoperable with those
+        // generated by other system layers.
+        String csvMsg =
+                profiler.getStartTime()
+                + "," + uuid.toString()
+                + "," + query
+                + "," + pageNum
+                + "," + pageSize
+                + "," + Thread.currentThread().getName();
+       final boolean FORMAT_LOG_MESSAGE = false;
+       profiler.log(csvMsg, FORMAT_LOG_MESSAGE);
+
+       // Now we have to issue the search
+       NuxeoRepositoryClientImpl nuxeoRepoClient = (NuxeoRepositoryClientImpl) repoClient;
+       DocumentWrapper<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(
+               ctx,
+               repoSession,
+               docTypes, 
+               query, 
+               orderByClause,
+               pageNum,
+               pageSize,
+               useDefaultOrderByClause, 
+               computeTotal);
+       // Now we gather the info for each document into the list and return
+       DocumentModelList docList = docListWrapper.getWrappedObject();
+
+        // Stop timing and log performance-related metrics.
+        profiler.stop();
+
+        csvMsg =
+                profiler.getStopTime()
+                + "," + uuid.toString()
+                + "," + query
+                + "," + pageNum
+                + "," + pageSize
+                + "," + Thread.currentThread().getName();
+        profiler.log(csvMsg, FORMAT_LOG_MESSAGE);
+
+        profiler.reset();
+       
         return docList;
     }
     
@@ -699,22 +768,26 @@ public class RefNameServiceUtils {
         if (fFirst) { // found no authRef fields - nothing to query
             return null;
         }
-        // We used to build a complete matches query, but that was too complex.
-        // Just build a keyword query based upon some key pieces - the urn syntax elements and the shortID
-        // Note that this will also match the Item itself, but that will get filtered out when
+
+        // Note that this will also match the term item itself, but that will get filtered out when
         // we compute actual matches.
         AuthorityTermInfo authTermInfo = RefNameUtils.parseAuthorityTermInfo(refName);
+        
+        // Example refname: urn:cspace:pahma.cspace.berkeley.edu:personauthorities:name(person):item:name(ReneRichie1586477168934)
+        // Corresponding phrase: "urn cspace pahma cspace berkeley edu personauthorities name person item name ReneRichie1586477168934
+        
+        String refnamePhrase = String.format("urn cspace %s %s name %s item name %s",
+                       RefNameUtils.domainToPhrase(authTermInfo.inAuthority.domain),
+                       authTermInfo.inAuthority.resource,
+                       authTermInfo.inAuthority.name,
+                       authTermInfo.name
+                       );
+        refnamePhrase = String.format("\"%s\"", refnamePhrase); // surround the phase in double quotes to indicate this is a NXQL phrase search
 
-        String keywords = RefNameUtils.URN_PREFIX
-                + " AND " + (authTermInfo.inAuthority.name != null
-                ? authTermInfo.inAuthority.name : authTermInfo.inAuthority.csid)
-                + " AND " + (authTermInfo.name != null
-                ? authTermInfo.name : authTermInfo.csid); // REM - This seems likely to cause trouble?  We should consider searching for the full refname -excluding the display name suffix?
-
-        String whereClauseStr = QueryManager.createWhereClauseFromKeywords(keywords);
+        String whereClauseStr = QueryManager.createWhereClauseFromKeywords(refnamePhrase);
 
         if (logger.isTraceEnabled()) {
-            logger.trace("The 'where' clause to find refObjs is: ", whereClauseStr);
+            logger.trace("The 'where' clause to find refObjs is: ", refnamePhrase);
         }
 
         return whereClauseStr;
@@ -727,7 +800,7 @@ public class RefNameServiceUtils {
                return result;
        }
 
-    private static int processRefObjsDocListForUpdate(
+    private static long processRefObjsDocListForUpdate(
                ServiceContext ctx,
             DocumentModelList docList,
             String tenantId,
@@ -746,7 +819,7 @@ public class RefNameServiceUtils {
                        authRefFieldsByService, null, 0, 0, newAuthorityRefName);
     }
                        
-    private static int processRefObjsDocListForList(
+    private static long processRefObjsDocListForList(
             DocumentModelList docList,
             String tenantId,
             String refName,
@@ -767,7 +840,7 @@ public class RefNameServiceUtils {
      * an open session, and caller must release Session after calling this.
      *
      */
-    private static int processRefObjsDocList(
+    private static long processRefObjsDocList(
             DocumentModelList docList,
             String tenantId,
             String refName,
@@ -779,16 +852,24 @@ public class RefNameServiceUtils {
             String newAuthorityRefName) {
         UriTemplateRegistry registry = ServiceMain.getInstance().getUriTemplateRegistry();
         Iterator<DocumentModel> iter = docList.iterator();
-        int nRefsFoundTotal = 0;
+        long nRefsFoundTotal = 0;
+        long nRefsFalsePositives = 0;
         boolean foundSelf = false;
+        boolean warningLogged = false;
 
         // When paginating results, we have to guess at the total. First guess is the number of docs returned
         // by the query. However, this returns some false positives, so may be high. 
         // In addition, we can match multiple fields per doc, so this may be low. Fun, eh?
-        int nDocsReturnedInQuery = (int)docList.totalSize();
-        int nDocsProcessed = 0;
-        int firstItemInPage = pageNum*pageSize;
+        long nDocsReturnedInQuery = (int)docList.totalSize();
+        long nDocsProcessed = 0;
+        long firstItemInPage = pageNum*pageSize;
         while (iter.hasNext()) {
+               if (!warningLogged && (float)nRefsFalsePositives / nDocsReturnedInQuery > 0.5) {
+                       warningLogged = true;
+                       String msg = String.format("When searching for documents referencing the term '%s', more than 1/2 of the results were false-positives.",
+                                       refName);
+                       logger.warn(msg);
+               }
             DocumentModel docModel = iter.next();
             AuthorityRefDocList.AuthorityRefDocItem ilistItem;
 
@@ -811,9 +892,10 @@ public class RefNameServiceUtils {
                 if (newAuthorityRefName != null) {
                     throw new InternalError("processRefObjsDocList() called with both an itemList and a new RefName!");
                 }
-                if(firstItemInPage > 100) {
-                       logger.warn("Processing a large offset (size:{}, num:{}) for refObjs - will be expensive!!!",
-                                               pageSize, pageNum);
+                if (firstItemInPage > 100) {
+                       String msg = String.format("Processing a large offset for records referencing (term:%s, size:%d, num:%d) - will be expensive!!!",
+                                       refName, pageSize, pageNum);
+                       logger.warn(msg);
                 }
                 // Note that we have to go through check all the fields to determine the actual page start
                 ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();
@@ -877,9 +959,6 @@ public class RefNameServiceUtils {
                 throw new RuntimeException(
                         "getAuthorityRefDocs: internal logic error: can't fetch authRefFields for DocType.");
             }
-            //String authRefAncestorField = "";
-            //String authRefDescendantField = "";
-            //String sourceField = "";
 
             ArrayList<RefNameServiceUtils.AuthRefInfo> foundProps = new ArrayList<RefNameServiceUtils.AuthRefInfo>();
             try {
@@ -911,12 +990,13 @@ public class RefNameServiceUtils {
                                        :refName.equals(docRefName)) {
                                // We found the self for an item
                                foundSelf = true;
-                               logger.debug("getAuthorityRefDocs: Result: "
+                               logger.trace("getAuthorityRefDocs: Result: "
                                                                + docType + " [" + NuxeoUtils.getCsid(docModel)
                                                                + "] appears to be self for: ["
                                                                + refName + "]");
                        } else {
-                               logger.debug("getAuthorityRefDocs: Result: "
+                               nRefsFalsePositives++;
+                               logger.trace("getAuthorityRefDocs: Result: "
                                                                + docType + " [" + NuxeoUtils.getCsid(docModel)
                                                                + "] does not reference ["
                                                                + refName + "]");
@@ -926,24 +1006,34 @@ public class RefNameServiceUtils {
                throw new RuntimeException(
                                "getAuthorityRefDocs: Problem fetching values from repo: " + ce.getLocalizedMessage());
             }
+
             nDocsProcessed++;
+
             // Done processing that doc. Are we done with the whole page?
             // Note pageSize <=0 means do them all
-            if((pageSize > 0) && ((nRefsFoundTotal-firstItemInPage)>=pageSize)) {
+            if ((pageSize > 0) && ((nRefsFoundTotal - firstItemInPage) >= pageSize)) {
                // Quitting early, so we need to estimate the total. Assume one per doc
                // for the rest of the docs we matched in the query
-               int unprocessedDocs = nDocsReturnedInQuery - nDocsProcessed;
-               if(unprocessedDocs>0) {
+               long unprocessedDocs = nDocsReturnedInQuery - nDocsProcessed;
+               if (unprocessedDocs > 0) {
                        // We generally match ourselves in the keyword search. If we already saw ourselves
                        // then do not try to correct for this. Otherwise, decrement the total.
                        // Yes, this is fairly goofy, but the whole estimation mechanism is goofy. 
-                       if(!foundSelf)
+                       if (!foundSelf)
                                unprocessedDocs--;
                        nRefsFoundTotal += unprocessedDocs;
                }
                break;
             }
         } // close while(iterator)
+        
+        // Log a final warning if we find too many false-positives.
+        if ((float)nRefsFalsePositives / nDocsReturnedInQuery > 0.33) {
+               String msg = String.format("Found %d false-positives and %d only true references the refname:%s",
+                               nRefsFalsePositives, nRefsFoundTotal, refName);
+               logger.warn(msg);
+        }
+
         return nRefsFoundTotal;
     }
 
index cfaec64c4713566e628689cbf3a56d65b436a78c..e036d7f41fc85f69cbf65d56275a4923e9230b15 100644 (file)
@@ -1053,7 +1053,8 @@ public class NuxeoUtils {
                try {
                        result = docModel.getPropertyValue(propertyName);
                } catch (NullPointerException npe) {
-                       result = null;
+                       logger.warn(String.format("Could not get a value for the property '%s' in Nuxeo document with CSID '%s'.",
+                                       propertyName, docModel != null ? docModel.getName() : "<null>"));
                }
 
                return result;
diff --git a/services/loanout/client/src/main/resources/log4j2-surefire.xml b/services/loanout/client/src/main/resources/log4j2-surefire.xml
new file mode 100644 (file)
index 0000000..bf74484
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+       This config is used by the maven surefire plugin (for tests), as configured in services/pom.xml.
+       For runtime logging config, see services/JaxRsServiceProvider/src/main/resources/log4j2.xml.
+-->
+<Configuration status="WARN">
+       <Properties>
+               <Property name="logPattern">%d %-5p [%t] [%c:%L] %m%n</Property>
+       </Properties>
+
+       <Appenders>
+               <Console name="ConsoleAppender" target="SYSTEM_OUT">
+                       <PatternLayout pattern="${logPattern}" />
+               </Console>
+
+               <File name="LogFileAppender" append="false" fileName="target/test.log">
+                       <PatternLayout pattern="${logPattern}" />
+               </File>
+       </Appenders>
+
+       <Loggers>
+               <Root level="DEBUG">
+                       <AppenderRef ref="ConsoleAppender"/>
+                       <AppenderRef ref="LogFileAppender" />
+               </Root>
+
+               <Logger name="httpclient" level="INFO" />
+               <Logger name="org.apache" level="INFO" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadIn" level="DEBUG" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadOut" level="DEBUG" />
+               <Logger name="org.collectionspace" level="DEBUG" />
+               <Logger name="org.jboss.resteasy" level="INFO" />
+       </Loggers>
+</Configuration>
diff --git a/services/person/client/src/main/resources/log4j2-surefire.xml b/services/person/client/src/main/resources/log4j2-surefire.xml
new file mode 100644 (file)
index 0000000..bf74484
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+       This config is used by the maven surefire plugin (for tests), as configured in services/pom.xml.
+       For runtime logging config, see services/JaxRsServiceProvider/src/main/resources/log4j2.xml.
+-->
+<Configuration status="WARN">
+       <Properties>
+               <Property name="logPattern">%d %-5p [%t] [%c:%L] %m%n</Property>
+       </Properties>
+
+       <Appenders>
+               <Console name="ConsoleAppender" target="SYSTEM_OUT">
+                       <PatternLayout pattern="${logPattern}" />
+               </Console>
+
+               <File name="LogFileAppender" append="false" fileName="target/test.log">
+                       <PatternLayout pattern="${logPattern}" />
+               </File>
+       </Appenders>
+
+       <Loggers>
+               <Root level="DEBUG">
+                       <AppenderRef ref="ConsoleAppender"/>
+                       <AppenderRef ref="LogFileAppender" />
+               </Root>
+
+               <Logger name="httpclient" level="INFO" />
+               <Logger name="org.apache" level="INFO" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadIn" level="DEBUG" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadOut" level="DEBUG" />
+               <Logger name="org.collectionspace" level="DEBUG" />
+               <Logger name="org.jboss.resteasy" level="INFO" />
+       </Loggers>
+</Configuration>
index 0a179a0781f9f74118ea33999b18340ff9b75715..277eb74a2182cc64ea2e071bf7db138c250d9823 100644 (file)
@@ -255,14 +255,17 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler<Report
                //
                if (!Tools.isEmpty(invContext.getOutputMIME())) {
                        outMimeType.append(invContext.getOutputMIME());
-               }
-               if (outMimeType == null || Tools.isEmpty(outMimeType.toString())) {
-               String reportOutputMime = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.OUTPUT_MIME); //docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME);
-                       if (!Tools.isEmpty(reportOutputMime)) {
-                               outMimeType.append(reportOutputMime);
-                       } else {
-                               outMimeType.append(ReportClient.DEFAULT_REPORT_OUTPUT_MIME);
-                       }
+               } else if (Tools.isEmpty(outMimeType.toString()) && params.containsKey("OutputMIME")) {
+                       // See UCB - https://github.com/cspace-deployment/services/pull/140/files
+                       outMimeType.append(params.get("OutputMIME"));
+               } else {
+                       // Use the default
+                       String reportOutputMime = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.OUTPUT_MIME); //docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME);
+                       if (!Tools.isEmpty(reportOutputMime)) {
+                               outMimeType.append(reportOutputMime);
+                       } else {
+                               outMimeType.append(ReportClient.DEFAULT_REPORT_OUTPUT_MIME);
+                       }
                }
                } catch (PropertyException pe) {
                        if (logger.isDebugEnabled()) {
index bded5e86b8b26ae2cc7da9344b0cedd98778d7bf..a0b1d2d87900498662bb2869562d58292621122c 100644 (file)
@@ -23,6 +23,8 @@
  */
 package org.collectionspace.services.vocabulary.nuxeo;
 
+import org.collectionspace.services.client.VocabularyClient;
+
 /**
  * VocabularyConstants processes CollectionObject document
  *
@@ -32,4 +34,10 @@ public class VocabularyConstants {
     public final static String NUXEO_DOCTYPE = "Vocabulary";
     public final static String NUXEO_SCHEMA_NAME = "vocabulary";
     public final static String NUXEO_DC_TITLE = "CollectionSpace-Vocabulary";
+    
+       public static final String COMMON_SCHEMA_NAME = VocabularyClient.SERVICE_COMMON_PART_NAME;
+       public final static String COMMON_ITEM_SCHEMA_NAME = VocabularyClient.SERVICE_ITEM_COMMON_PART_NAME;
+    
+    public final static String DISPLAY_NAME_SCHEMA_NAME = COMMON_ITEM_SCHEMA_NAME;
+    public final static String DISPLAY_NAME_FIELD_NAME = "displayName";
 }