[
https://issues.apache.org/jira/browse/SYNCOPE-1145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16082049#comment-16082049
]
ASF GitHub Bot commented on SYNCOPE-1145:
-----------------------------------------
Github user ilgrosso commented on a diff in the pull request:
https://github.com/apache/syncope/pull/50#discussion_r126657809
--- Diff:
client/console/src/main/java/org/apache/syncope/client/console/panels/HistoryConfDetails.java
---
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.panels;
+
+import static
org.apache.syncope.client.console.panels.AbstractModalPanel.LOG;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.Predicate;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.layout.ConsoleLayoutInfo;
+import org.apache.syncope.client.console.pages.BasePage;
+import
org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
+import
org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel;
+import
org.apache.syncope.client.console.wicket.markup.html.form.JsonDiffEditorPanel;
+import
org.apache.syncope.client.console.wicket.markup.html.form.JsonEditorPanel;
+import org.apache.syncope.common.lib.to.AbstractHistoryConf;
+import org.apache.syncope.common.lib.to.ConnInstanceHistoryConfTO;
+import org.apache.syncope.common.lib.to.ResourceHistoryConfTO;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.PropertyModel;
+
+public class HistoryConfDetails<T extends AbstractHistoryConf> extends
MultilevelPanel.SecondLevel {
+
+ private static final long serialVersionUID = -7400543686272100483L;
+
+ private final T currentHistoryConfTO;
+
+ private List<T> availableHistoryConfTOs;
+
+ private AbstractModalPanel jsonEditorPanel;
+
+ public HistoryConfDetails(final BaseModal<?> baseModal, final T
currentHistoryConfTO,
+ final PageReference pageRef, final List<T>
availableHistoryConfTOs) {
+ super();
+
+ CollectionUtils.filter(availableHistoryConfTOs, new Predicate<T>()
{
+
+ @Override
+ public boolean evaluate(final T object) {
+ return
!object.getKey().equals(currentHistoryConfTO.getKey());
+ }
+ });
+ this.availableHistoryConfTOs = availableHistoryConfTOs;
+ this.currentHistoryConfTO = currentHistoryConfTO;
+
+ Form form = initDropdownDiffConfForm();
+ add(form);
+ if (availableHistoryConfTOs.isEmpty()) {
+ form.setVisible(false);
+ } else {
+ form.setVisible(true);
+ }
+
+ initSingleContent();
+ }
+
+ private void showConfigurationSinglePanel() {
+ final ConsoleLayoutInfo info = getJSONInfo(currentHistoryConfTO);
+
+ jsonEditorPanel = new JsonEditorPanel(null, new
PropertyModel<String>(info, "content"), Boolean.TRUE, null) {
+
+ private static final long serialVersionUID =
-8927036362466990179L;
+
+ @Override
+ public void onSubmit(final AjaxRequestTarget target, final
Form<?> form) {
+ try {
+ modal.close(target);
+ } catch (Exception e) {
+ LOG.error("While updating console layout info for
history configuration {}", info.getKey(), e);
+
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
+ ? e.getClass().getName() : e.getMessage());
+ }
+ ((BasePage)
pageRef.getPage()).getNotificationPanel().refresh(target);
+ }
+ };
+ jsonEditorPanel.setOutputMarkupId(Boolean.TRUE);
+
+ addOrReplace(jsonEditorPanel);
+ }
+
+ private void initSingleContent() {
+ showConfigurationSinglePanel();
+ }
+
+ private void initMultipleContent(final List<T> historyConfTOs) {
+ showConfigurationDiffPanel(historyConfTOs);
+ }
+
+ private void showConfigurationDiffPanel(final List<T> historyConfTOs) {
+ final List<ConsoleLayoutInfo> infos = new ArrayList<>();
+ for (T historyConfTO : historyConfTOs) {
+ infos.add(getJSONInfo(historyConfTO));
+ }
+
+ jsonEditorPanel = new JsonDiffEditorPanel(null, new
PropertyModel<String>(infos.get(0), "content"),
+ new PropertyModel<String>(infos.get(1), "content"), null) {
+
+ private static final long serialVersionUID =
-8927036362466990179L;
+
+ @Override
+ public void onSubmit(final AjaxRequestTarget target, final
Form<?> form) {
+ try {
+ modal.close(target);
+ } catch (Exception e) {
+ LOG.error("While updating console layout info for
history configurations {}", infos, e);
+
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
+ ? e.getClass().getName() : e.getMessage());
+ }
+ ((BasePage)
pageRef.getPage()).getNotificationPanel().refresh(target);
+ }
+ };
+
+ replace(jsonEditorPanel);
+ }
+
+ private ConsoleLayoutInfo getJSONInfo(final T historyConfTO) {
+ Object conf = null; // current configuration instance
+ String key = "";
+ if (historyConfTO instanceof ConnInstanceHistoryConfTO) {
+ ConnInstanceHistoryConfTO historyConf =
ConnInstanceHistoryConfTO.class.cast(historyConfTO);
+ conf = historyConf.getConnInstanceTO();
+ key = historyConf.getKey();
+ } else if (historyConfTO instanceof ResourceHistoryConfTO) {
+ ResourceHistoryConfTO historyConf =
ResourceHistoryConfTO.class.cast(historyConfTO);
+ conf = historyConf.getResourceTO();
+ key = historyConf.getKey();
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+ String json = "";
+ try {
+ json = mapper.writeValueAsString(conf);
+ } catch (IOException ex) {
+ LOG.error("Error converting objects to JSON", ex);
+ }
+
+ ConsoleLayoutInfo info = new ConsoleLayoutInfo(key);
+ info.setContent(json);
+
+ return info;
+ }
+
+ private Map<String, String> getDropdownNamesMap(final List<T>
historyConfTOs) {
+ Map<String, String> historyConfMap = new HashMap<>();
+ if (currentHistoryConfTO instanceof ConnInstanceHistoryConfTO) {
+ for (T historyConfValue : historyConfTOs) {
+ ConnInstanceHistoryConfTO historyConf =
ConnInstanceHistoryConfTO.class.cast(historyConfValue);
+ historyConfMap.put(historyConf.getKey(),
+ historyConf.getCreator() + " - " +
historyConf.getCreation().toString() + " - " + historyConf.
+ getKey());
+ }
+ } else if (currentHistoryConfTO instanceof ResourceHistoryConfTO) {
+ for (T historyConfValue : historyConfTOs) {
+ ResourceHistoryConfTO historyConf =
ResourceHistoryConfTO.class.cast(historyConfValue);
+ historyConfMap.put(historyConf.getKey(),
+ historyConf.getCreator() + " - " +
historyConf.getCreation().toString() + " - " + historyConf.
+ getKey());
+ }
+ }
+ return historyConfMap;
+ }
+
+ private Form initDropdownDiffConfForm() {
+ final Form form = new Form("form");
+ form.setModel(new CompoundPropertyModel(currentHistoryConfTO));
+ form.setOutputMarkupId(Boolean.TRUE);
+
+ final Map<String, String> namesMap =
getDropdownNamesMap(availableHistoryConfTOs);
+ List<String> keys = new ArrayList<>(namesMap.keySet());
+ final AjaxDropDownChoicePanel dd = new AjaxDropDownChoicePanel<>(
--- End diff --
Please use meaningful variable names.
> Connector and Resource configuration versioning
> -----------------------------------------------
>
> Key: SYNCOPE-1145
> URL: https://issues.apache.org/jira/browse/SYNCOPE-1145
> Project: Syncope
> Issue Type: New Feature
> Components: common, console, core
> Reporter: Francesco Chicchiriccò
> Assignee: Francesco Chicchiriccò
> Fix For: 2.0.5, 2.1.0
>
>
> It often happens that, while playing with Connectors' and Resources'
> configuration, everything works up until a certain point, then some
> misconfiguration happens and errors start appearing.
> In such situations, it would be handy to have a simple mechanism to revert to
> a previous (working) situation.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)