syncope-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgrosso <...@git.apache.org>
Subject [GitHub] syncope pull request #50: Fixes [SYNCOPE-1145]
Date Tue, 11 Jul 2017 11:03:57 GMT
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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message