1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.enduser.panels;
20
21 import org.apache.syncope.client.enduser.SyncopeEnduserSession;
22 import org.apache.syncope.client.enduser.rest.UserRequestRestClient;
23 import org.apache.syncope.client.ui.commons.panels.NotificationPanel;
24 import org.apache.syncope.client.ui.commons.panels.SyncopeFormPanel;
25 import org.apache.syncope.common.lib.SyncopeClientException;
26 import org.apache.syncope.common.lib.to.ProvisioningResult;
27 import org.apache.syncope.common.lib.to.UserRequest;
28 import org.apache.syncope.common.lib.to.UserRequestForm;
29 import org.apache.syncope.common.lib.to.UserTO;
30 import org.apache.syncope.common.lib.types.ExecStatus;
31 import org.apache.wicket.ajax.AjaxRequestTarget;
32 import org.apache.wicket.ajax.markup.html.AjaxLink;
33 import org.apache.wicket.ajax.markup.html.form.AjaxButton;
34 import org.apache.wicket.markup.html.WebMarkupContainer;
35 import org.apache.wicket.markup.html.basic.Label;
36 import org.apache.wicket.markup.html.form.Form;
37 import org.apache.wicket.markup.html.panel.Fragment;
38 import org.apache.wicket.markup.html.panel.Panel;
39 import org.apache.wicket.spring.injection.annot.SpringBean;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 public class UserRequestDetails extends Panel {
44
45 private static final long serialVersionUID = -2447602429647965090L;
46
47 protected static final Logger LOG = LoggerFactory.getLogger(UserRequestDetails.class);
48
49 protected static final String USER_REQUEST_ERROR = "user_request_error";
50
51 @SpringBean
52 protected UserRequestRestClient userRequestRestClient;
53
54 public UserRequestDetails(
55 final String id,
56 final UserRequest userRequest,
57 final WebMarkupContainer container,
58 final NotificationPanel notificationPanel) {
59
60 super(id);
61
62 UserRequestForm formTO = userRequest.getHasForm()
63 ? userRequestRestClient.getForm(
64 SyncopeEnduserSession.get().getSelfTO().getUsername(),
65 userRequest.getTaskId()).orElse(null)
66 : null;
67
68 if (formTO == null || formTO.getProperties() == null || formTO.getProperties().isEmpty()) {
69 add(new Fragment("fragContainer", "formDetails", UserRequestDetails.this)
70 .add(new Label("executionId", userRequest.getExecutionId()))
71 .add(new Label("startTime", userRequest.getStartTime())));
72 } else {
73 Form<Void> form = new Form<>("userRequestWrapForm");
74
75 form.add(new SyncopeFormPanel<>("userRequestFormPanel", formTO));
76
77 form.add(new AjaxButton("submit") {
78
79 private static final long serialVersionUID = 4284361595033427185L;
80
81 @Override
82 protected void onSubmit(final AjaxRequestTarget target) {
83 try {
84 userRequestRestClient.claimForm(formTO.getTaskId());
85 ProvisioningResult<UserTO> result = userRequestRestClient.submitForm(formTO);
86
87 if (result.getPropagationStatuses().stream().
88 anyMatch(p -> ExecStatus.FAILURE == p.getStatus()
89 || ExecStatus.NOT_ATTEMPTED == p.getStatus())) {
90
91 SyncopeEnduserSession.get().error(getString(USER_REQUEST_ERROR));
92 notificationPanel.refresh(target);
93 }
94
95 target.add(container);
96 } catch (SyncopeClientException sce) {
97 LOG.error("Unable to submit user request form for BPMN process [{}]",
98 formTO.getBpmnProcess(), sce);
99 SyncopeEnduserSession.get().error(getString(USER_REQUEST_ERROR));
100 notificationPanel.refresh(target);
101 }
102 }
103
104 }.setOutputMarkupId(true));
105
106 add(new Fragment("fragContainer", "formProperties", UserRequestDetails.this).add(form));
107 }
108
109 add(new AjaxLink<Void>("delete") {
110
111 private static final long serialVersionUID = 3669569969172391336L;
112
113 @Override
114 public void onClick(final AjaxRequestTarget target) {
115 userRequestRestClient.cancelRequest(userRequest.getExecutionId(), null);
116 target.add(container);
117 }
118 });
119 }
120 }