Revision 46885
Added by Michele Artini almost 7 years ago
MsroController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.controllers; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
|
|
3 | 6 |
import org.apache.commons.logging.Log; |
4 | 7 |
import org.apache.commons.logging.LogFactory; |
5 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
18 | 21 |
import eu.dnetlib.msro.workflows.util.WorkflowDispatcher; |
19 | 22 |
import eu.dnetlib.services.BaseService; |
20 | 23 |
import eu.dnetlib.services.async.AsyncMethodException; |
24 |
import eu.dnetlib.services.async.AsyncRunnable; |
|
21 | 25 |
import eu.dnetlib.services.async.AsyncServerCallback; |
22 | 26 |
import eu.dnetlib.services.async.HasAsyncMethods; |
23 | 27 |
|
... | ... | |
32 | 36 |
private WorkflowDispatcher dispatcher; |
33 | 37 |
|
34 | 38 |
@Override |
35 |
public void processMethod(final String method, final String jsonParams, final AsyncServerCallback callback) throws AsyncMethodException {
|
|
39 |
public AsyncRunnable prepareThread(final String method, final String jsonParams, final AsyncServerCallback callback) throws AsyncMethodException {
|
|
36 | 40 |
final ObjectMapper mapper = new ObjectMapper(); |
37 | 41 |
|
38 |
try { |
|
39 |
switch (method) { |
|
40 |
case "startWorkflow": |
|
41 |
dispatcher.startWorkflow(mapper.readValue(jsonParams, Workflow.class), getBaseUrl()); |
|
42 |
break; |
|
43 |
case "startWorkflowTemplate": |
|
44 |
dispatcher.startWorkflowTemplate(mapper.readValue(jsonParams, WorkflowTemplate.class), getBaseUrl()); |
|
45 |
break; |
|
46 |
default: |
|
47 |
log.warn("Invalid method: " + method); |
|
48 |
throw new AsyncMethodException("Invalid method: " + method); |
|
42 |
return new AsyncRunnable() { |
|
43 |
|
|
44 |
@Override |
|
45 |
public Map<String, String> prepare() { |
|
46 |
return new HashMap<>(); |
|
49 | 47 |
} |
50 |
} catch (final Throwable e) { |
|
51 |
log.warn("Error executing method: " + method, e); |
|
52 |
throw new AsyncMethodException("Error executing method: " + method, e); |
|
53 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void execute() throws AsyncMethodException { |
|
51 |
final WorkflowRef ref; |
|
52 |
try { |
|
53 |
switch (method) { |
|
54 |
case "startWorkflow": |
|
55 |
dispatcher.startWorkflow(mapper.readValue(jsonParams, Workflow.class), getBaseUrl()); |
|
56 |
break; |
|
57 |
case "startWorkflowTemplate": |
|
58 |
dispatcher.startWorkflowTemplate(mapper.readValue(jsonParams, WorkflowTemplate.class), getBaseUrl()); |
|
59 |
break; |
|
60 |
default: |
|
61 |
log.warn("Invalid method: " + method); |
|
62 |
throw new AsyncMethodException("Invalid method: " + method); |
|
63 |
} |
|
64 |
} catch (final Throwable e) { |
|
65 |
log.warn("Error executing method: " + method, e); |
|
66 |
throw new AsyncMethodException("Error executing method: " + method, e); |
|
67 |
} |
|
68 |
} |
|
69 |
}; |
|
70 |
|
|
54 | 71 |
} |
55 | 72 |
|
56 | 73 |
@RequestMapping("startWorkflow") |
Also available in: Unified diff
Partial response of async methods