1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.resources;
20
21 import java.io.IOException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.apache.cxf.common.util.UrlUtils;
26 import org.apache.syncope.client.console.rest.BpmnProcessRestClient;
27 import org.apache.syncope.client.ui.commons.annotations.Resource;
28 import org.apache.syncope.common.lib.to.BpmnProcess;
29 import org.apache.wicket.util.io.IOUtils;
30
31
32
33
34 @Resource(key = "bpmnProcessPUT", path = "/bpmnProcessPUT")
35 public class BpmnProcessPUTResource extends AbstractBpmnProcessResource {
36
37 private static final long serialVersionUID = 2964542005207297944L;
38
39 public BpmnProcessPUTResource(final BpmnProcessRestClient bpmnProcessRestClient) {
40 super(bpmnProcessRestClient);
41 }
42
43 @Override
44 protected ResourceResponse newResourceResponse(final Attributes attributes) {
45 String definition = null;
46 try {
47 HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
48 String requestBody = IOUtils.toString(request.getInputStream());
49 String[] split = requestBody.split("&");
50 for (int i = 0; i < split.length && definition == null; i++) {
51 String keyValue = split[i];
52 if (keyValue.startsWith("json_xml=")) {
53 definition = UrlUtils.urlDecode(keyValue.split("=")[1]);
54 }
55 }
56 } catch (IOException e) {
57 LOG.error("Could not extract BPMN process", e);
58 }
59
60 BpmnProcess toSet = getBpmnProcess(attributes);
61
62 if (definition == null || toSet == null) {
63 return new ResourceResponse().setStatusCode(Response.Status.BAD_REQUEST.getStatusCode()).
64 setError(Response.Status.BAD_REQUEST.getStatusCode(),
65 "Could not extract BPMN process' model id and / or definition");
66 }
67
68 try {
69 bpmnProcessRestClient.setDefinition(MediaType.APPLICATION_JSON_TYPE, toSet.getKey(), definition);
70 return new ResourceResponse().setStatusCode(Response.Status.NO_CONTENT.getStatusCode());
71 } catch (Exception e) {
72 LOG.error("While updating BPMN process", e);
73 return new ResourceResponse().setStatusCode(Response.Status.BAD_REQUEST.getStatusCode()).
74 setError(Response.Status.BAD_REQUEST.getStatusCode(),
75 "While updating BPMN process: " + e.getMessage());
76 }
77 }
78 }