From: Aron Roberts Date: Fri, 4 Jan 2013 23:00:44 +0000 (-0800) Subject: CSPACE-5728: Added abstract class on top of batch invocable interface, based largely... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=b0707cc5f6726dfd9c2a4a0b539f3c75ff5e9420;p=tmp%2Fjakarta-migration.git CSPACE-5728: Added abstract class on top of batch invocable interface, based largely on Ray's work in creating such a class for the UC Berkeley Botanical Garden implementation. --- 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 b6c6e3607..64db074a9 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 @@ -1,114 +1,50 @@ package org.collectionspace.services.batch.nuxeo; -import java.util.ArrayList; -import java.util.List; -import javax.ws.rs.core.Response; -import org.collectionspace.services.batch.BatchInvocable; -import org.collectionspace.services.common.ResourceMap; -import org.collectionspace.services.common.invocable.InvocationContext; -import org.collectionspace.services.common.invocable.InvocationResults; +import java.util.Arrays; +import org.collectionspace.services.batch.AbstractBatchInvocable; +import org.collectionspace.services.common.api.Tools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class UpdateObjectLocationBatchJob implements BatchInvocable { +public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { + final String CLASSNAME = this.getClass().getSimpleName(); final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationBatchJob.class); - private static ArrayList invocationModes = null; - private InvocationContext context; - private int completionStatus; - private ResourceMap resourceMap; - private InvocationResults results; - private InvocationError errorInfo; - protected final int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); - protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode(); - protected final int INT_ERROR_STATUS = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); + // Initialization tasks public UpdateObjectLocationBatchJob() { - UpdateObjectLocationBatchJob.setupClassStatics(); - context = null; - completionStatus = STATUS_UNSTARTED; - resourceMap = null; - results = new InvocationResults(); - errorInfo = null; - } - - private static void setupClassStatics() { - if (invocationModes == null) { - invocationModes = new ArrayList(1); - invocationModes.add(INVOCATION_MODE_SINGLE); - // invocationModes.add(INVOCATION_MODE_LIST); - } - } - - /** - * @return a set of modes that this plugin can support on invocation. Must - * be non-empty. - */ - public List getSupportedInvocationModes() { - return UpdateObjectLocationBatchJob.invocationModes; - } - - /** - * Sets the invocation context for the batch job. Called before run(). - * - * @param context an instance of InvocationContext. - */ - public void setInvocationContext(InvocationContext context) { - this.context = context; - } - - /** - * Sets the invocation context for the batch job. Called before run(). - * - * @param context an instance of InvocationContext. - */ - public void setResourceMap(ResourceMap resourceMap) { - this.resourceMap = resourceMap; + setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE)); } /** * The main work logic of the batch job. Will be called after setContext. */ + @Override public void run() { - completionStatus = STATUS_MIN_PROGRESS; + setCompletionStatus(STATUS_MIN_PROGRESS); try { // FIXME: Placeholder during early development if (logger.isInfoEnabled()) { - logger.info("Invoking " + this.getClass().getSimpleName() + " ..."); + logger.info("Invoking " + CLASSNAME + " ..."); + logger.info("Invocation context is: " + getInvocationContext().getMode()); } + if (!requestedInvocationModeIsSupported()) { + setInvocationModeNotSupportedResult(); + } + String csid; + if (requestIsForInvocationModeSingle()) { + csid = getInvocationContext().getSingleCSID(); + if (Tools.isBlank(csid)) { + throw new Exception("Could not find required CSID value in the context for this batch job."); + } + logger.info("CSID value is: " + csid); + } + String docType = getInvocationContext().getDocType(); } catch (Exception e) { - completionStatus = STATUS_ERROR; - errorInfo = new InvocationError(INT_ERROR_STATUS, - "UpdateObjectLocationBatchJob problem: " + e.getLocalizedMessage()); - results.setUserNote(errorInfo.getMessage()); + String errMsg = "Error encountered in " + CLASSNAME + ": " + e.getLocalizedMessage(); + setErrorResult(errMsg); } - } - - /** - * @return one of the STATUS_* constants, or a value from 1-99 to indicate - * progress. Implementations need not support partial completion (progress) - * values, and can transition from STATUS_MIN_PROGRESS to STATUS_COMPLETE. - */ - public int getCompletionStatus() { - return completionStatus; - } - - /** - * @return information about the batch job actions and results - */ - public InvocationResults getResults() { - if (completionStatus != STATUS_COMPLETE) { - return null; - } - return results; - } - - /** - * @return a user-presentable note when an error occurs in batch processing. - * Will only be called if getCompletionStatus() returns STATUS_ERROR. - */ - public InvocationError getErrorInfo() { - return errorInfo; + setCompletionStatus(STATUS_COMPLETE); } }