1 package org.collectionspace.services.batch.nuxeo;
3 import java.util.ArrayList;
5 import javax.ws.rs.core.Response;
6 import org.collectionspace.services.batch.BatchInvocable;
7 import org.collectionspace.services.common.ResourceMap;
8 import org.collectionspace.services.common.invocable.InvocationContext;
9 import org.collectionspace.services.common.invocable.InvocationResults;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 public class UpdateObjectLocationBatchJob implements BatchInvocable {
15 final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationBatchJob.class);
16 private static ArrayList<String> invocationModes = null;
17 private InvocationContext context;
18 private int completionStatus;
19 private ResourceMap resourceMap;
20 private InvocationResults results;
21 private InvocationError errorInfo;
22 protected final int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
23 protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode();
24 protected final int INT_ERROR_STATUS = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
26 public UpdateObjectLocationBatchJob() {
27 UpdateObjectLocationBatchJob.setupClassStatics();
29 completionStatus = STATUS_UNSTARTED;
31 results = new InvocationResults();
35 private static void setupClassStatics() {
36 if (invocationModes == null) {
37 invocationModes = new ArrayList<String>(1);
38 invocationModes.add(INVOCATION_MODE_SINGLE);
39 // invocationModes.add(INVOCATION_MODE_LIST);
44 * @return a set of modes that this plugin can support on invocation. Must
47 public List<String> getSupportedInvocationModes() {
48 return UpdateObjectLocationBatchJob.invocationModes;
52 * Sets the invocation context for the batch job. Called before run().
54 * @param context an instance of InvocationContext.
56 public void setInvocationContext(InvocationContext context) {
57 this.context = context;
61 * Sets the invocation context for the batch job. Called before run().
63 * @param context an instance of InvocationContext.
65 public void setResourceMap(ResourceMap resourceMap) {
66 this.resourceMap = resourceMap;
70 * The main work logic of the batch job. Will be called after setContext.
73 completionStatus = STATUS_MIN_PROGRESS;
76 // FIXME: Placeholder during early development
77 if (logger.isInfoEnabled()) {
78 logger.info("Invoking " + this.getClass().getSimpleName() + " ...");
80 } catch (Exception e) {
81 completionStatus = STATUS_ERROR;
82 errorInfo = new InvocationError(INT_ERROR_STATUS,
83 "UpdateObjectLocationBatchJob problem: " + e.getLocalizedMessage());
84 results.setUserNote(errorInfo.getMessage());
89 * @return one of the STATUS_* constants, or a value from 1-99 to indicate
90 * progress. Implementations need not support partial completion (progress)
91 * values, and can transition from STATUS_MIN_PROGRESS to STATUS_COMPLETE.
93 public int getCompletionStatus() {
94 return completionStatus;
98 * @return information about the batch job actions and results
100 public InvocationResults getResults() {
101 if (completionStatus != STATUS_COMPLETE) {
108 * @return a user-presentable note when an error occurs in batch processing.
109 * Will only be called if getCompletionStatus() returns STATUS_ERROR.
111 public InvocationError getErrorInfo() {