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.common.lib.SyncopeClientException;
25 import org.apache.syncope.common.lib.to.ProvisioningResult;
26 import org.apache.syncope.common.lib.to.UserRequest;
27 import org.apache.syncope.common.lib.to.UserRequestForm;
28 import org.apache.syncope.common.lib.to.UserTO;
29 import org.apache.syncope.common.lib.types.ExecStatus;
30 import org.apache.syncope.ext.client.common.ui.panels.UserRequestFormPanel;
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 UserRequestFormPanel("userRequestFormPanel", formTO, false) {
76
77 private static final long serialVersionUID = 3617895525072546591L;
78
79 @Override
80 protected void viewDetails(final AjaxRequestTarget target) {
81
82 }
83 });
84
85 form.add(new AjaxButton("submit") {
86
87 private static final long serialVersionUID = 4284361595033427185L;
88
89 @Override
90 protected void onSubmit(final AjaxRequestTarget target) {
91 try {
92 userRequestRestClient.claimForm(formTO.getTaskId());
93 ProvisioningResult<UserTO> result = userRequestRestClient.submitForm(formTO);
94
95 if (result.getPropagationStatuses().stream().
96 anyMatch(p -> ExecStatus.FAILURE == p.getStatus()
97 || ExecStatus.NOT_ATTEMPTED == p.getStatus())) {
98
99 SyncopeEnduserSession.get().error(getString(USER_REQUEST_ERROR));
100 notificationPanel.refresh(target);
101 }
102
103 target.add(container);
104 } catch (SyncopeClientException sce) {
105 LOG.error("Unable to submit user request form for BPMN process [{}]",
106 formTO.getBpmnProcess(), sce);
107 SyncopeEnduserSession.get().error(getString(USER_REQUEST_ERROR));
108 notificationPanel.refresh(target);
109 }
110 }
111
112 }.setOutputMarkupId(true));
113
114 add(new Fragment("fragContainer", "formProperties", UserRequestDetails.this).add(form));
115 }
116
117 add(new AjaxLink<Void>("delete") {
118
119 private static final long serialVersionUID = 3669569969172391336L;
120
121 @Override
122 public void onClick(final AjaxRequestTarget target) {
123 userRequestRestClient.cancelRequest(userRequest.getExecutionId(), null);
124 target.add(container);
125 }
126 });
127 }
128 }