]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b6c6e36079df3805360b6dfb99a286468ac126a3
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.batch.nuxeo;
2
3 import java.util.ArrayList;
4 import java.util.List;
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;
12
13 public class UpdateObjectLocationBatchJob implements BatchInvocable {
14
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();
25
26     public UpdateObjectLocationBatchJob() {
27         UpdateObjectLocationBatchJob.setupClassStatics();
28         context = null;
29         completionStatus = STATUS_UNSTARTED;
30         resourceMap = null;
31         results = new InvocationResults();
32         errorInfo = null;
33     }
34
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);
40         }
41     }
42
43     /**
44      * @return a set of modes that this plugin can support on invocation. Must
45      * be non-empty.
46      */
47     public List<String> getSupportedInvocationModes() {
48         return UpdateObjectLocationBatchJob.invocationModes;
49     }
50
51     /**
52      * Sets the invocation context for the batch job. Called before run().
53      *
54      * @param context an instance of InvocationContext.
55      */
56     public void setInvocationContext(InvocationContext context) {
57         this.context = context;
58     }
59
60     /**
61      * Sets the invocation context for the batch job. Called before run().
62      *
63      * @param context an instance of InvocationContext.
64      */
65     public void setResourceMap(ResourceMap resourceMap) {
66         this.resourceMap = resourceMap;
67     }
68
69     /**
70      * The main work logic of the batch job. Will be called after setContext.
71      */
72     public void run() {
73         completionStatus = STATUS_MIN_PROGRESS;
74
75         try {
76             // FIXME: Placeholder during early development
77             if (logger.isInfoEnabled()) {
78                  logger.info("Invoking " + this.getClass().getSimpleName() + " ...");
79             }
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());
85         }
86     }
87
88     /**
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.
92      */
93     public int getCompletionStatus() {
94         return completionStatus;
95     }
96
97     /**
98      * @return information about the batch job actions and results
99      */
100     public InvocationResults getResults() {
101         if (completionStatus != STATUS_COMPLETE) {
102             return null;
103         }
104         return results;
105     }
106
107     /**
108      * @return a user-presentable note when an error occurs in batch processing.
109      * Will only be called if getCompletionStatus() returns STATUS_ERROR.
110      */
111     public InvocationError getErrorInfo() {
112         return errorInfo;
113     }
114 }