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.console.tasks;
20  
21  import com.fasterxml.jackson.databind.JsonNode;
22  import com.fasterxml.jackson.databind.json.JsonMapper;
23  import java.io.IOException;
24  import org.apache.commons.lang3.tuple.Pair;
25  import org.apache.syncope.client.console.panels.MultilevelPanel;
26  import org.apache.syncope.client.console.wicket.markup.html.form.JsonEditorPanel;
27  import org.apache.syncope.common.lib.to.PropagationTaskTO;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.model.PropertyModel;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  /**
34   * Task attributes details.
35   */
36  public class PropagationDataView extends MultilevelPanel.SecondLevel {
37  
38      private static final long serialVersionUID = -4110576026663173545L;
39  
40      private static final Logger LOG = LoggerFactory.getLogger(AnyPropagationTasks.class);
41  
42      private static final JsonMapper MAPPER = JsonMapper.builder().findAndAddModules().build();
43  
44      public PropagationDataView(final PropagationTaskTO taskTO) {
45          super();
46  
47          Pair<String, String> info = Pair.of(taskTO.getEntityKey(), getJSONInfo(taskTO));
48          JsonEditorPanel jsonPanel =
49                  new JsonEditorPanel(null, new PropertyModel<>(info, "value"), true, null) {
50  
51              private static final long serialVersionUID = -8927036362466990179L;
52  
53              @Override
54              public void onSubmit(final AjaxRequestTarget target) {
55                  modal.close(target);
56              }
57          };
58  
59          add(jsonPanel);
60      }
61  
62      private static String getJSONInfo(final PropagationTaskTO taskTO) {
63          String json = "";
64          try {
65              JsonNode list = MAPPER.readTree(taskTO.getPropagationData());
66              json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(list);
67          } catch (IOException ex) {
68              LOG.error("Error converting objects to JSON", ex);
69          }
70  
71          return json;
72      }
73  }