View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.enduser.pages;
20  
21  import java.io.Serializable;
22  import java.util.stream.Collectors;
23  import org.apache.syncope.client.enduser.BookmarkablePageLinkBuilder;
24  import org.apache.syncope.client.enduser.SyncopeWebApplication;
25  import org.apache.syncope.client.enduser.commons.EnduserConstants;
26  import org.apache.syncope.client.enduser.panels.ResultPanel;
27  import org.apache.syncope.client.ui.commons.Constants;
28  import org.apache.syncope.client.ui.commons.status.StatusUtils;
29  import org.apache.syncope.common.lib.to.ProvisioningResult;
30  import org.apache.syncope.common.lib.to.UserTO;
31  import org.apache.syncope.common.lib.types.ExecStatus;
32  import org.apache.wicket.markup.html.WebMarkupContainer;
33  import org.apache.wicket.markup.html.WebPage;
34  import org.apache.wicket.markup.html.basic.Label;
35  import org.apache.wicket.markup.html.link.BookmarkablePageLink;
36  import org.apache.wicket.markup.html.panel.Fragment;
37  import org.apache.wicket.request.mapper.parameter.PageParameters;
38  
39  public class SelfResult extends BasePage {
40  
41      private static final long serialVersionUID = 3804053409052140145L;
42  
43      private static final String RESULT_PAGE = "page.resultPage";
44  
45      public SelfResult(final PageParameters parameters) {
46          this(null, parameters);
47      }
48  
49      @SuppressWarnings("unchecked")
50      public SelfResult(final ProvisioningResult<UserTO> provisioningResult, final PageParameters parameters) {
51          super(parameters, RESULT_PAGE);
52  
53          WebMarkupContainer content = new WebMarkupContainer("content");
54          content.setOutputMarkupId(true);
55          contentWrapper.add(content);
56          Class<? extends WebPage> page;
57          try {
58              page = (Class<? extends WebPage>) Class.forName(parameters.get(EnduserConstants.LANDING_PAGE).
59                      toString("org.apache.syncope.client.enduser.pages.Login"));
60          } catch (ClassNotFoundException e) {
61              LOG.debug("Login page not found", e);
62              page = Login.class;
63          }
64          if (page.equals(Login.class)) {
65              BookmarkablePageLink<WebPage> login =
66                      new BookmarkablePageLink<>("login", Login.class);
67              content.add(login.setOutputMarkupId(true));
68              disableSidebar();
69          } else {
70              content.add(BookmarkablePageLinkBuilder.build("login", page));
71          }
72  
73          content.add(new Label("resultTitle", parameters.get(Constants.NOTIFICATION_TITLE_PARAM).toString()));
74          content.add(new Label("resultMessage", parameters.get(Constants.NOTIFICATION_MSG_PARAM).toString()));
75          Fragment statusFragment = new Fragment("statusIcon",
76                  provisioningResult != null
77                          && SyncopeWebApplication.get().isReportPropagationErrors()
78                          && provisioningResult.getPropagationStatuses().stream()
79                          .anyMatch(ps -> ExecStatus.SUCCESS != ps.getStatus())
80                          ? "errorIcon" : "successIcon", content);
81          // add also details about failed propagations, if enbaled by property enduser.showPropErrors
82          if (provisioningResult != null
83                  && provisioningResult.getPropagationStatuses().stream()
84                  .anyMatch(ps -> ExecStatus.SUCCESS != ps.getStatus())) {
85              statusFragment.add(new ResultPanel("propagationErrors",
86                      (Serializable) provisioningResult.getPropagationStatuses().stream()
87                              .filter(ps -> ExecStatus.SUCCESS != ps.getStatus())
88                              .map(ps -> StatusUtils.getStatusBean(provisioningResult.getEntity(), ps.getResource(),
89                                      ps.getAfterObj(), false)).collect(Collectors.toList()), getPageReference())
90                      .setOutputMarkupId(true)
91                      .setVisible(SyncopeWebApplication.get().isReportPropagationErrorDetails()));
92          }
93          content.add(statusFragment);
94      }
95  }