From 3a76ac78c7d6d74572dd0760e6373f2fbffb1ae8 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 9 Jan 2013 16:23:26 -0800 Subject: [PATCH] CSPACE-5728: Added single- and list-mode batch tests to XmlReplay master, at least for now. Added convenience methods to get list CSIDs and parameters from the batch invocation context. --- .../batch/batch-invoke-updateobjloc-list.xml | 4 +- .../batch-invoke-updateobjloc-single.xml | 2 +- .../test-data/xmlreplay/xml-replay-master.xml | 4 +- .../batch/AbstractBatchInvocable.java | 62 +++++++++---------- .../nuxeo/UpdateObjectLocationBatchJob.java | 29 ++++----- 5 files changed, 48 insertions(+), 53 deletions(-) diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-list.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-list.xml index 0d36993fe..4ca90476f 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-list.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-list.xml @@ -6,10 +6,10 @@ CollectionObject - + ${collectionObject1CSID} ${collectionObject2CSID} - + some key diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-single.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-single.xml index 755f5917d..beb1ccfa1 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-single.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-single.xml @@ -6,7 +6,7 @@ CollectionObject ${collectionObjectCSID} - + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml index 6de5391ce..c0608a741 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml @@ -42,8 +42,10 @@ - + + + diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java index 02c5ddb2a..b2252572a 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/AbstractBatchInvocable.java @@ -53,38 +53,6 @@ public abstract class AbstractBatchInvocable implements BatchInvocable { this.errorInfo = null; } - protected void logInvocationContext() { - if (logger.isInfoEnabled()) { - logger.info("Invocation mode=" + this.getInvocationContext().getMode()); - logger.info("Invocation doc type=" + this.getInvocationContext().getDocType()); - logger.info("Invocation single CSID=" + this.getInvocationContext().getSingleCSID()); - logger.info("Invocation group CSID=" + this.getInvocationContext().getGroupCSID()); - InvocationContext.ListCSIDs lcsids = this.getInvocationContext().getListCSIDs(); - if (lcsids == null) { - logger.info("Invocation list CSIDs are null."); - } else { - List csidsList = lcsids.getCsid(); - if (csidsList != null) { - for (String listcsid : csidsList) { - logger.info("List CSID=" + listcsid); - } - } - } - InvocationContext.Params params = this.getInvocationContext().getParams(); - if (params == null) { - logger.info("Invocation list Params are null."); - } else { - List paramsList = params.getParam(); - if (paramsList != null) { - for (InvocationContext.Params.Param param : paramsList) { - logger.info("Param key=" + param.getKey()); - logger.info("Param value=" + param.getValue()); - } - } - } - } - } - @Override public List getSupportedInvocationModes() { return invocationModes; @@ -155,6 +123,36 @@ public abstract class AbstractBatchInvocable implements BatchInvocable { return (INVOCATION_MODE_NO_CONTEXT.equalsIgnoreCase(getInvocationContext().getMode()) ? true : false); } + protected List getListCsids() { + List emptyCsidsList = Collections.emptyList(); + InvocationContext.ListCSIDs lcsids = getInvocationContext().getListCSIDs(); + if (lcsids == null) { + return emptyCsidsList; + } else { + List csidsList = lcsids.getCsid(); + if (csidsList == null) { + return emptyCsidsList; + } else { + return csidsList; + } + } + } + + protected List getParams() { + List emptyParamsList = Collections.emptyList(); + InvocationContext.Params params = this.getInvocationContext().getParams(); + if (params == null) { + return emptyParamsList; + } else { + List paramsList = params.getParam(); + if (paramsList == null) { + return emptyParamsList; + } else { + return paramsList; + } + } + } + protected void setErrorResult(String message) { setErrorResult(message, INT_ERROR_STATUS); } diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java index cf9cbf427..737efe6be 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java @@ -64,32 +64,28 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { try { - logInvocationContext(); - List csids = new ArrayList(); if (requestIsForInvocationModeSingle()) { String singleCsid = getInvocationContext().getSingleCSID(); - if (Tools.notBlank(singleCsid)) { + if (Tools.isBlank(singleCsid)) { + throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT); + } else { csids.add(singleCsid); } } else if (requestIsForInvocationModeList()) { - InvocationContext.ListCSIDs invListCsids = getInvocationContext().getListCSIDs(); - if (invListCsids == null) { - throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT); - } - List listCsids = invListCsids.getCsid(); - if (listCsids == null || listCsids.isEmpty()) { + List listCsids = getListCsids(); + if (listCsids.isEmpty()) { throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT); } csids.addAll(listCsids); } else if (requestIsForInvocationModeGroup()) { - String groupCsid = getInvocationContext().getGroupCSID(); - // FIXME: Get individual CSIDs from the group - // and add them to the list - } - - if (csids.isEmpty()) { - throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT); + // Currently not supported + // FIXME: Get individual CSIDs, if any, from the group + // String groupCsid = getInvocationContext().getGroupCSID(); + // ... + } else if (requestIsForInvocationModeNoContext()) { + // Currently not supported + // FIXME: Add code to invoke batch job on every active CollectionObject } // Update the computed current location field for each CollectionObject @@ -299,5 +295,4 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { getResults().setNumAffected(numAffected); return getResults(); } - } -- 2.47.3