http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationPanel.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationPanel.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationPanel.java new file mode 100644 index 0000000..8624d26 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationPanel.java @@ -0,0 +1,119 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.ajax.AjaxEventBehavior; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.feedback.FeedbackMessage; +import org.apache.wicket.feedback.IFeedbackMessageFilter; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.Model; + +public class NotificationPanel extends FeedbackPanel { + + private static final long serialVersionUID = 5895940553202128621L; + + private static final String CSS_CLASS = "notificationpanel"; + + private static final String DEFAULT_ADDITIONAL_CSS_CLASS = "notificationpanel_top_right"; + + private final String additionalCSSClass; + + public NotificationPanel(final String id) { + this(id, null, null); + } + + public NotificationPanel(final String id, final String additionalCSSClass, + final IFeedbackMessageFilter feedbackMessageFilter) { + + super(id, feedbackMessageFilter); + + this.add(new AjaxEventBehavior(Constants.ON_CLICK) { + + private static final long serialVersionUID = -7133385027739964990L; + + @Override + protected void onEvent(final AjaxRequestTarget target) { + target.appendJavaScript( + "setTimeout(\"$('div#" + getMarkupId() + "').fadeOut('normal')\", 0);"); + } + }); + + this.additionalCSSClass = StringUtils.isBlank(additionalCSSClass) + ? DEFAULT_ADDITIONAL_CSS_CLASS + : additionalCSSClass; + + // set custom markup id and ouput it, to find the component later on in the js function + setMarkupId(id); + setOutputMarkupId(true); + + // Add the additional cssClass and hide the element by default + add(new AttributeModifier("class", new Model<String>(CSS_CLASS + " " + this.additionalCSSClass))); + add(new AttributeModifier("style", new Model<String>("opacity: 0;"))); + } + + /** + * Method to refresh the notification panel. + * + * If there are any feedback messages for the user, find the gravest level, format the notification panel + * accordingly and show it. + * + * @param target AjaxRequestTarget to add panel and the calling javascript function + */ + public void refresh(final AjaxRequestTarget target) { + // any feedback at all in the current form? + if (anyMessage()) { + int highestFeedbackLevel = FeedbackMessage.INFO; + + // any feedback with the given level? + if (anyMessage(FeedbackMessage.WARNING)) { + highestFeedbackLevel = FeedbackMessage.WARNING; + } + if (anyMessage(FeedbackMessage.ERROR)) { + highestFeedbackLevel = FeedbackMessage.ERROR; + } + + // add the css classes to the notification panel, + // including the border css which represents the highest level of feedback + add(new AttributeModifier("class", + new Model<String>(CSS_CLASS + + " " + additionalCSSClass + + " notificationpanel_border_" + highestFeedbackLevel))); + + // refresh the panel and call the js function with the panel markup id + // and the total count of messages + target.add(this); + if (anyMessage(FeedbackMessage.ERROR)) { + target.appendJavaScript( + "$('div#" + getMarkupId() + "').fadeTo('normal', 1.0);"); + } else { + target.appendJavaScript( + "showNotification('" + getMarkupId() + "', " + getCurrentMessages().size() + ");"); + } + } + } + + @Override + protected String getCSSClass(final FeedbackMessage message) { + return "notificationpanel_row_" + message.getLevelAsString(); + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationTasks.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationTasks.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationTasks.java new file mode 100644 index 0000000..d7f52e1 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/NotificationTasks.java @@ -0,0 +1,254 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.pages.NotificationTaskModalPage; +import org.apache.syncope.client.console.pages.Tasks; +import org.apache.syncope.client.console.pages.Tasks.TasksProvider; +import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.ActionColumn; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.NotificationTaskTO; +import org.apache.wicket.Component; +import org.apache.wicket.Page; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.event.IEvent; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.StringResourceModel; +import org.apache.wicket.request.http.WebResponse; + +public class NotificationTasks extends AbstractTasks { + + private static final long serialVersionUID = 4984337552918213290L; + + private int paginatorRows; + + private WebMarkupContainer container; + + private boolean operationResult = false; + + private ModalWindow window; + + private AjaxDataTablePanel<AbstractTaskTO, String> table; + + public NotificationTasks(final String id, final PageReference pageRef) { + super(id, pageRef); + + container = new WebMarkupContainer("container"); + container.setOutputMarkupId(true); + add(container); + + add(window = new ModalWindow("taskWin")); + + paginatorRows = prefMan.getPaginatorRows(getWebRequest(), Constants.PREF_NOTIFICATION_TASKS_PAGINATOR_ROWS); + + table = Tasks.updateTaskTable( + getColumns(), + new TasksProvider<NotificationTaskTO>(restClient, paginatorRows, getId(), NotificationTaskTO.class), + container, + 0, + pageRef, + restClient); + + container.add(table); + + window.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + target.add(container); + if (operationResult) { + info(getString(Constants.OPERATION_SUCCEEDED)); + target.add(getPage().get(Constants.FEEDBACK)); + operationResult = false; + } + } + }); + + window.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + window.setInitialHeight(WIN_HEIGHT); + window.setInitialWidth(WIN_WIDTH); + window.setCookieName(VIEW_TASK_WIN_COOKIE_NAME); + + @SuppressWarnings("rawtypes") + final Form paginatorForm = new Form("PaginatorForm"); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final DropDownChoice rowsChooser = new DropDownChoice("rowsChooser", new PropertyModel(this, "paginatorRows"), + prefMan.getPaginatorChoices()); + + rowsChooser.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + prefMan.set(getWebRequest(), (WebResponse) getResponse(), + Constants.PREF_NOTIFICATION_TASKS_PAGINATOR_ROWS, String.valueOf(paginatorRows)); + + table = Tasks.updateTaskTable( + getColumns(), + new TasksProvider<NotificationTaskTO>(restClient, paginatorRows, getId(), + NotificationTaskTO.class), + container, + table == null ? 0 : (int) table.getCurrentPage(), + pageRef, + restClient); + + target.add(container); + } + }); + + paginatorForm.add(rowsChooser); + add(paginatorForm); + } + + private List<IColumn<AbstractTaskTO, String>> getColumns() { + final List<IColumn<AbstractTaskTO, String>> columns = new ArrayList<>(); + + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("key", this, null), "key", "key")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("sender", this, null), "sender", "sender")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("recipients", this, null), "recipients", "recipients")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("subject", this, null), "subject", "subject")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("traceLevel", this, null), "traceLevel", "traceLevel")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("latestExecStatus", this, null), "latestExecStatus", "latestExecStatus")); + + columns.add(new ActionColumn<AbstractTaskTO, String>(new StringResourceModel("actions", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public ActionLinksPanel getActions(final String componentId, final IModel<AbstractTaskTO> model) { + + final AbstractTaskTO taskTO = model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + + window.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + return new NotificationTaskModalPage(taskTO); + } + }); + + window.show(target); + } + }, ActionLink.ActionType.EDIT, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.startExecution(taskTO.getKey(), false); + getSession().info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + target.add(container); + } + }, ActionLink.ActionType.EXECUTE, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.delete(taskTO.getKey(), NotificationTaskTO.class); + info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.DELETE, TASKS); + + return panel; + } + + @Override + public Component getHeader(String componentId) { + final ActionLinksPanel panel = new ActionLinksPanel(componentId, new Model(), pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -7978723352517770644L; + + @Override + public void onClick(final AjaxRequestTarget target) { + if (target != null) { + target.add(table); + } + } + }, ActionLink.ActionType.RELOAD, TASKS, "list"); + + return panel; + } + }); + + return columns; + } + + @Override + public void onEvent(final IEvent<?> event) { + if (event.getPayload() instanceof AbstractSearchResultPanel.EventDataWrapper) { + ((AbstractSearchResultPanel.EventDataWrapper) event.getPayload()).getTarget().add(container); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PlainAttrsPanel.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PlainAttrsPanel.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PlainAttrsPanel.java new file mode 100644 index 0000000..b0517b0 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PlainAttrsPanel.java @@ -0,0 +1,395 @@ +/* + * 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 java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.AttrLayoutType; +import org.apache.syncope.client.console.commons.JexlHelpUtils; +import org.apache.syncope.client.console.commons.Mode; +import org.apache.syncope.client.console.panels.AttrTemplatesPanel.GroupAttrTemplatesChange; +import org.apache.syncope.client.console.rest.ConfigurationRestClient; +import org.apache.syncope.client.console.rest.GroupRestClient; +import org.apache.syncope.client.console.rest.SchemaRestClient; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.DateTextFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.DateTimeFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.SpinnerFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.list.AltListView; +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.to.ConfTO; +import org.apache.syncope.common.lib.to.MembershipTO; +import org.apache.syncope.common.lib.to.PlainSchemaTO; +import org.apache.syncope.common.lib.to.GroupTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.AttrSchemaType; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.event.IEvent; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.IChoiceRenderer; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.spring.injection.annot.SpringBean; + +public class PlainAttrsPanel extends Panel { + + private static final long serialVersionUID = 552437609667518888L; + + @SpringBean + private SchemaRestClient schemaRestClient; + + @SpringBean + private ConfigurationRestClient confRestClient; + + @SpringBean + private GroupRestClient groupRestClient; + + private final AbstractAttributableTO entityTO; + + private final Mode mode; + + private final AttrTemplatesPanel attrTemplates; + + private Map<String, PlainSchemaTO> schemas = new LinkedHashMap<>(); + + public <T extends AbstractAttributableTO> PlainAttrsPanel(final String id, final T entityTO, + final Form<?> form, final Mode mode) { + + this(id, entityTO, form, mode, null); + } + + public <T extends AbstractAttributableTO> PlainAttrsPanel(final String id, final T entityTO, + final Form<?> form, final Mode mode, final AttrTemplatesPanel attrTemplates) { + + super(id); + this.entityTO = entityTO; + this.mode = mode; + this.attrTemplates = attrTemplates; + this.setOutputMarkupId(true); + + setSchemas(); + setAttrs(); + + add(new AltListView<AttrTO>("schemas", new PropertyModel<List<? extends AttrTO>>(entityTO, "attrs")) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void populateItem(final ListItem<AttrTO> item) { + final AttrTO attributeTO = (AttrTO) item.getDefaultModelObject(); + + final WebMarkupContainer jexlHelp = JexlHelpUtils.getJexlHelpWebContainer("jexlHelp"); + + final AjaxLink<Void> questionMarkJexlHelp = JexlHelpUtils.getAjaxLink(jexlHelp, "questionMarkJexlHelp"); + item.add(questionMarkJexlHelp); + questionMarkJexlHelp.add(jexlHelp); + + if (mode != Mode.TEMPLATE) { + questionMarkJexlHelp.setVisible(false); + } + + item.add(new Label("name", attributeTO.getSchema())); + + final FieldPanel panel = getFieldPanel(schemas.get(attributeTO.getSchema()), form, attributeTO); + + if (mode == Mode.TEMPLATE || !schemas.get(attributeTO.getSchema()).isMultivalue()) { + item.add(panel); + } else { + item.add(new MultiFieldPanel<String>( + "panel", new PropertyModel<List<String>>(attributeTO, "values"), panel)); + } + } + } + ); + } + + private void setSchemas() { + AttrTO attrLayout = null; + List<PlainSchemaTO> schemaTOs; + + if (entityTO instanceof GroupTO) { + final GroupTO groupTO = (GroupTO) entityTO; + + attrLayout = confRestClient.readAttrLayout(AttrLayoutType.valueOf(mode, AttributableType.GROUP)); + schemaTOs = schemaRestClient.getSchemas(AttributableType.GROUP); + Set<String> allowed; + if (attrTemplates == null) { + allowed = new HashSet<>(groupTO.getGPlainAttrTemplates()); + } else { + allowed = new HashSet<>(attrTemplates.getSelected(AttrTemplatesPanel.Type.gPlainAttrTemplates)); + if (groupTO.isInheritTemplates() && groupTO.getParent() != 0) { + allowed.addAll(groupRestClient.read(groupTO.getParent()).getGPlainAttrTemplates()); + } + } + schemaRestClient.filter(schemaTOs, allowed, true); + } else if (entityTO instanceof UserTO) { + attrLayout = confRestClient.readAttrLayout(AttrLayoutType.valueOf(mode, AttributableType.USER)); + schemaTOs = schemaRestClient.getSchemas(AttributableType.USER); + } else if (entityTO instanceof MembershipTO) { + attrLayout = confRestClient.readAttrLayout(AttrLayoutType.valueOf(mode, AttributableType.MEMBERSHIP)); + schemaTOs = schemaRestClient.getSchemas(AttributableType.MEMBERSHIP); + Set<String> allowed = new HashSet<>( + groupRestClient.read(((MembershipTO) entityTO).getGroupKey()).getMPlainAttrTemplates()); + schemaRestClient.filter(schemaTOs, allowed, true); + } else { + schemas = new TreeMap<>(); + schemaTOs = schemaRestClient.getSchemas(AttributableType.CONFIGURATION); + for (Iterator<PlainSchemaTO> it = schemaTOs.iterator(); it.hasNext();) { + PlainSchemaTO schemaTO = it.next(); + for (AttrLayoutType type : AttrLayoutType.values()) { + if (type.getConfKey().equals(schemaTO.getKey())) { + it.remove(); + } + } + } + } + + schemas.clear(); + + if (attrLayout != null && mode != Mode.TEMPLATE && !(entityTO instanceof ConfTO)) { + // 1. remove attributes not selected for display + schemaRestClient.filter(schemaTOs, attrLayout.getValues(), true); + // 2. sort remainig attributes according to configuration, e.g. attrLayout + final Map<String, Integer> attrLayoutMap = new HashMap<>(attrLayout.getValues().size()); + for (int i = 0; i < attrLayout.getValues().size(); i++) { + attrLayoutMap.put(attrLayout.getValues().get(i), i); + } + Collections.sort(schemaTOs, new Comparator<PlainSchemaTO>() { + + @Override + public int compare(final PlainSchemaTO schema1, final PlainSchemaTO schema2) { + int value = 0; + + if (attrLayoutMap.get(schema1.getKey()) > attrLayoutMap.get(schema2.getKey())) { + value = 1; + } else if (attrLayoutMap.get(schema1.getKey()) < attrLayoutMap.get(schema2.getKey())) { + value = -1; + } + + return value; + } + }); + } + for (PlainSchemaTO schemaTO : schemaTOs) { + schemas.put(schemaTO.getKey(), schemaTO); + } + } + + private void setAttrs() { + final List<AttrTO> entityData = new ArrayList<>(); + + final Map<String, AttrTO> attrMap = entityTO.getPlainAttrMap(); + + for (PlainSchemaTO schema : schemas.values()) { + final AttrTO attributeTO = new AttrTO(); + attributeTO.setSchema(schema.getKey()); + + if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) { + attributeTO.getValues().add(""); + + // is important to set readonly only after values setting + attributeTO.setReadonly(schema.isReadonly()); + } else { + attributeTO.getValues().addAll(attrMap.get(schema.getKey()).getValues()); + } + entityData.add(attributeTO); + } + + entityTO.getPlainAttrs().clear(); + entityTO.getPlainAttrs().addAll(entityData); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private FieldPanel getFieldPanel(final PlainSchemaTO schemaTO, final Form form, final AttrTO attributeTO) { + final boolean required = mode == Mode.TEMPLATE + ? false + : schemaTO.getMandatoryCondition().equalsIgnoreCase("true"); + + final boolean readOnly = mode == Mode.TEMPLATE ? false : schemaTO.isReadonly(); + + final AttrSchemaType type = mode == Mode.TEMPLATE ? AttrSchemaType.String : schemaTO.getType(); + + final FieldPanel panel; + switch (type) { + case Boolean: + panel = new AjaxCheckBoxPanel("panel", schemaTO.getKey(), new Model<Boolean>()); + panel.setRequired(required); + break; + + case Date: + final String dataPattern = schemaTO.getConversionPattern() == null + ? SyncopeConstants.DEFAULT_DATE_PATTERN + : schemaTO.getConversionPattern(); + + if (dataPattern.contains("H")) { + panel = new DateTimeFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), dataPattern); + + if (required) { + panel.addRequiredLabel(); + ((DateTimeFieldPanel) panel).setFormValidator(form); + } + panel.setStyleSheet("ui-widget-content ui-corner-all"); + } else { + panel = new DateTextFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), dataPattern); + + if (required) { + panel.addRequiredLabel(); + } + } + break; + + case Enum: + panel = new AjaxDropDownChoicePanel<String>("panel", schemaTO.getKey(), new Model<String>()); + ((AjaxDropDownChoicePanel<String>) panel).setChoices(getEnumeratedValues(schemaTO)); + + if (StringUtils.isNotBlank(schemaTO.getEnumerationKeys())) { + ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() { + + private static final long serialVersionUID = -3724971416312135885L; + + private final Map<String, String> valueMap = getEnumeratedKeyValues(schemaTO); + + @Override + public String getDisplayValue(final String value) { + return valueMap.get(value) == null ? value : valueMap.get(value); + } + + @Override + public String getIdValue(final String value, final int i) { + return value; + } + }); + } + + if (required) { + panel.addRequiredLabel(); + } + break; + + case Long: + panel = new SpinnerFieldPanel<Long>("panel", schemaTO.getKey(), + Long.class, new Model<Long>(), null, null); + + if (required) { + panel.addRequiredLabel(); + } + break; + + case Double: + panel = new SpinnerFieldPanel<Double>("panel", schemaTO.getKey(), + Double.class, new Model<Double>(), null, null); + + if (required) { + panel.addRequiredLabel(); + } + break; + + case Binary: + panel = new BinaryFieldPanel("panel", schemaTO.getKey(), new Model<String>(), + schemas.containsKey(schemaTO.getKey()) + ? schemas.get(schemaTO.getKey()).getMimeType() + : null); + + if (required) { + panel.addRequiredLabel(); + } + break; + + default: + panel = new AjaxTextFieldPanel("panel", schemaTO.getKey(), new Model<String>()); + + if (required) { + panel.addRequiredLabel(); + } + } + + panel.setReadOnly(readOnly); + panel.setNewModel(attributeTO.getValues()); + + return panel; + } + + private Map<String, String> getEnumeratedKeyValues(final PlainSchemaTO schemaTO) { + final Map<String, String> res = new HashMap<>(); + + final String[] values = StringUtils.isBlank(schemaTO.getEnumerationValues()) + ? new String[0] + : schemaTO.getEnumerationValues().split(SyncopeConstants.ENUM_VALUES_SEPARATOR); + + final String[] keys = StringUtils.isBlank(schemaTO.getEnumerationKeys()) + ? new String[0] + : schemaTO.getEnumerationKeys().split(SyncopeConstants.ENUM_VALUES_SEPARATOR); + + for (int i = 0; i < values.length; i++) { + res.put(values[i].trim(), keys.length > i ? keys[i].trim() : null); + } + + return res; + } + + private List<String> getEnumeratedValues(final PlainSchemaTO schemaTO) { + final List<String> res = new ArrayList<>(); + + final String[] values = StringUtils.isBlank(schemaTO.getEnumerationValues()) + ? new String[0] + : schemaTO.getEnumerationValues().split(SyncopeConstants.ENUM_VALUES_SEPARATOR); + + for (String value : values) { + res.add(value.trim()); + } + + return res; + } + + @Override + public void onEvent(final IEvent<?> event) { + if ((event.getPayload() instanceof GroupAttrTemplatesChange)) { + final GroupAttrTemplatesChange update = (GroupAttrTemplatesChange) event.getPayload(); + if (attrTemplates != null && update.getType() == AttrTemplatesPanel.Type.gPlainAttrTemplates) { + setSchemas(); + setAttrs(); + update.getTarget().add(this); + } + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PoliciesPanel.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PoliciesPanel.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PoliciesPanel.java new file mode 100644 index 0000000..4d66eda --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PoliciesPanel.java @@ -0,0 +1,343 @@ +/* + * 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 java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.PreferenceManager; +import org.apache.syncope.client.console.commons.SortableDataProviderComparator; +import org.apache.syncope.client.console.commons.XMLRolesReader; +import org.apache.syncope.client.console.pages.BasePage; +import org.apache.syncope.client.console.pages.PolicyModalPage; +import org.apache.syncope.client.console.rest.PolicyRestClient; +import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxLink; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractPolicyTO; +import org.apache.syncope.common.lib.to.AccountPolicyTO; +import org.apache.syncope.common.lib.to.PasswordPolicyTO; +import org.apache.syncope.common.lib.to.SyncPolicyTO; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.wicket.Page; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder; +import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.request.http.WebResponse; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PoliciesPanel extends Panel { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(PoliciesPanel.class); + + private static final int MODAL_WIN_HEIGHT = 400; + + private static final int MODAL_WIN_WIDTH = 1000; + + private static final long serialVersionUID = -6804066913177804275L; + + @SpringBean + private PolicyRestClient policyRestClient; + + @SpringBean + protected XMLRolesReader xmlRolesReader; + + @SpringBean + private PreferenceManager prefMan; + + private final PageReference pageRef; + + private final int paginatorRows = prefMan.getPaginatorRows(getWebRequest(), Constants.PREF_POLICY_PAGINATOR_ROWS); + + protected boolean modalResult = false; + + private final PolicyType policyType; + + public PoliciesPanel(final String id, final PageReference pageRef, final PolicyType policyType) { + super(id); + this.pageRef = pageRef; + this.policyType = policyType; + + // Modal window for editing user attributes + final ModalWindow mwindow = new ModalWindow("editModalWin"); + mwindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + mwindow.setInitialHeight(MODAL_WIN_HEIGHT); + mwindow.setInitialWidth(MODAL_WIN_WIDTH); + mwindow.setCookieName("policy-modal"); + add(mwindow); + + // Container for user list + final WebMarkupContainer container = new WebMarkupContainer("container"); + container.setOutputMarkupId(true); + add(container); + + setWindowClosedCallback(mwindow, container); + + final List<IColumn<AbstractPolicyTO, String>> columns = new ArrayList<>(); + + columns.add(new PropertyColumn<AbstractPolicyTO, String>(new ResourceModel("key"), "key", "key")); + + columns.add(new PropertyColumn<AbstractPolicyTO, String>( + new ResourceModel("description"), "description", "description")); + + columns.add(new AbstractColumn<AbstractPolicyTO, String>(new ResourceModel("type")) { + + private static final long serialVersionUID = 8263694778917279290L; + + @Override + public void populateItem(final Item<ICellPopulator<AbstractPolicyTO>> cellItem, final String componentId, + final IModel<AbstractPolicyTO> model) { + + cellItem.add(new Label(componentId, getString(model.getObject().getType().name()))); + } + }); + + columns.add(new AbstractColumn<AbstractPolicyTO, String>(new ResourceModel("actions", "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem(final Item<ICellPopulator<AbstractPolicyTO>> cellItem, final String componentId, + final IModel<AbstractPolicyTO> model) { + + final AbstractPolicyTO policyTO = model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + + mwindow.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Page createPage() { + return new PolicyModalPage(pageRef, mwindow, policyTO); + } + }); + + mwindow.show(target); + } + }, ActionLink.ActionType.EDIT, "Policies"); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + policyRestClient.delete(policyTO.getKey(), policyTO.getClass()); + info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException e) { + error(getString(Constants.OPERATION_ERROR)); + + LOG.error("While deleting policy {}({})", + policyTO.getKey(), policyTO.getDescription(), e); + } + + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.DELETE, "Policies"); + + cellItem.add(panel); + } + }); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("datatable", columns, + new PolicyDataProvider(), paginatorRows); + + container.add(table); + + final AjaxLink<Void> createButton = new ClearIndicatingAjaxLink<Void>("createLink", pageRef) { + + private static final long serialVersionUID = -7978723352517770644L; + + @Override + protected void onClickInternal(final AjaxRequestTarget target) { + mwindow.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Page createPage() { + return new PolicyModalPage(pageRef, mwindow, getPolicyTOInstance(policyType)); + } + }); + + mwindow.show(target); + } + }; + + add(createButton); + + MetaDataRoleAuthorizationStrategy.authorize( + createButton, ENABLE, xmlRolesReader.getEntitlement("Policies", "create")); + + @SuppressWarnings("rawtypes") + final Form paginatorForm = new Form("PaginatorForm"); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final DropDownChoice rowsChooser = new DropDownChoice("rowsChooser", new PropertyModel(this, "paginatorRows"), + prefMan.getPaginatorChoices()); + + rowsChooser.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + prefMan.set(getWebRequest(), (WebResponse) getResponse(), Constants.PREF_POLICY_PAGINATOR_ROWS, String + .valueOf(paginatorRows)); + table.setItemsPerPage(paginatorRows); + + target.add(container); + } + }); + + paginatorForm.add(rowsChooser); + add(paginatorForm); + } + + private void setWindowClosedCallback(final ModalWindow window, final WebMarkupContainer container) { + window.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + target.add(container); + BasePage configuration = ((BasePage) pageRef.getPage()); + if (configuration.isModalResult()) { + info(getString(Constants.OPERATION_SUCCEEDED)); + configuration.getFeedbackPanel().refresh(target); + configuration.setModalResult(false); + } + } + }); + } + + private class PolicyDataProvider extends SortableDataProvider<AbstractPolicyTO, String> { + + private static final long serialVersionUID = -6976327453925166730L; + + private final SortableDataProviderComparator<AbstractPolicyTO> comparator; + + public PolicyDataProvider() { + super(); + + //Default sorting + setSort("description", SortOrder.ASCENDING); + + comparator = new SortableDataProviderComparator<AbstractPolicyTO>(this); + } + + @Override + public long size() { + return policyRestClient.getPolicies(policyType, true).size(); + } + + @Override + public Iterator<AbstractPolicyTO> iterator(final long first, final long count) { + final List<AbstractPolicyTO> policies = policyRestClient.getPolicies(policyType, true); + + Collections.sort(policies, comparator); + + return policies.subList((int) first, (int) first + (int) count).iterator(); + } + + @Override + public IModel<AbstractPolicyTO> model(final AbstractPolicyTO object) { + return new CompoundPropertyModel<AbstractPolicyTO>(object); + } + } + + private AbstractPolicyTO getPolicyTOInstance(final PolicyType policyType) { + AbstractPolicyTO policyTO; + switch (policyType) { + case GLOBAL_ACCOUNT: + policyTO = new AccountPolicyTO(true); + break; + + case ACCOUNT: + policyTO = new AccountPolicyTO(); + break; + + case GLOBAL_PASSWORD: + policyTO = new PasswordPolicyTO(true); + break; + + case PASSWORD: + policyTO = new PasswordPolicyTO(); + break; + + case GLOBAL_SYNC: + policyTO = new SyncPolicyTO(true); + break; + + case SYNC: + default: + policyTO = new SyncPolicyTO(); + } + + return policyTO; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PolicyBeanPanel.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PolicyBeanPanel.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PolicyBeanPanel.java new file mode 100644 index 0000000..a55be9f --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PolicyBeanPanel.java @@ -0,0 +1,340 @@ +/* + * 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 java.beans.PropertyDescriptor; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.rest.PolicyRestClient; +import org.apache.syncope.client.console.rest.SchemaRestClient; +import org.apache.syncope.client.console.wicket.markup.html.form.AbstractFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxPalettePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.SpinnerFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.list.AltListView; +import org.apache.syncope.common.lib.annotation.ClassList; +import org.apache.syncope.common.lib.annotation.SchemaList; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.PolicySpec; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.LoadableDetachableModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.model.util.ListModel; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; +import org.springframework.util.ReflectionUtils.FieldCallback; +import org.springframework.util.ReflectionUtils.FieldFilter; + +public class PolicyBeanPanel extends Panel { + + private static final long serialVersionUID = -3035998190456928143L; + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(PolicyBeanPanel.class); + + @SpringBean + private SchemaRestClient schemaRestClient; + + @SpringBean + private PolicyRestClient policyRestClient; + + final IModel<List<String>> userSchemas = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = -2012833443695917883L; + + @Override + protected List<String> load() { + return schemaRestClient.getPlainSchemaNames(AttributableType.USER); + } + }; + + final IModel<List<String>> groupSchemas = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return schemaRestClient.getPlainSchemaNames(AttributableType.GROUP); + } + }; + + final IModel<List<String>> correlationRules = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return policyRestClient.getCorrelationRuleClasses(); + } + }; + + public PolicyBeanPanel(final String id, final PolicySpec policy) { + super(id); + + final List<FieldWrapper> items = new ArrayList<>(); + ReflectionUtils.doWithFields(policy.getClass(), new FieldCallback() { + + @Override + public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException { + FieldWrapper fieldWrapper = new FieldWrapper(); + fieldWrapper.setName(field.getName()); + fieldWrapper.setType(field.getType()); + + final SchemaList schemaList = field.getAnnotation(SchemaList.class); + fieldWrapper.setSchemaList(schemaList); + + final ClassList classList = field.getAnnotation(ClassList.class); + fieldWrapper.setClassList(classList); + + items.add(fieldWrapper); + } + }, + new FieldFilter() { + + @Override + public boolean matches(final Field field) { + return !Modifier.isStatic(field.getModifiers()) && !"serialVersionUID".equals(field.getName()); + } + }); + + final ListView<FieldWrapper> policies = new AltListView<FieldWrapper>("policies", items) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected void populateItem(final ListItem<FieldWrapper> item) { + final FieldWrapper field = item.getModelObject(); + + final PropertyDescriptor propDesc = BeanUtils.getPropertyDescriptor(policy.getClass(), field.getName()); + + item.add(new Label("label", new ResourceModel(field.getName()))); + + AbstractFieldPanel component; + try { + if (field.getClassList() != null) { + component = new AjaxDropDownChoicePanel("field", field.getName(), new PropertyModel(policy, + field.getName())); + + final List<String> rules = correlationRules.getObject(); + + if (rules != null && !rules.isEmpty()) { + ((AjaxDropDownChoicePanel) component).setChoices(correlationRules.getObject()); + } + + item.add(component); + + item.add(getActivationControl( + component, + propDesc.getReadMethod().invoke(policy, new Object[] {}) != null, + null, + null)); + + } else if (field.getType().isEnum()) { + component = new AjaxDropDownChoicePanel("field", field.getName(), new PropertyModel(policy, + field.getName())); + + final Serializable[] values = (Serializable[]) field.getType().getEnumConstants(); + + if (values != null && values.length > 0) { + ((AjaxDropDownChoicePanel) component).setChoices(Arrays.asList(values)); + } + + item.add(component); + + item.add(getActivationControl( + component, + (Enum<?>) propDesc.getReadMethod().invoke(policy, new Object[] {}) != null, + values[0], + values[0])); + + } else if (ClassUtils.isAssignable(Boolean.class, field.getType())) { + item.add(new AjaxCheckBoxPanel("check", field.getName(), + new PropertyModel<Boolean>(policy, field.getName()))); + + item.add(new Label("field", new Model(null))); + } else if (Collection.class.isAssignableFrom(field.getType())) { + if (field.getSchemaList() != null) { + final List<String> values = new ArrayList<>(); + if (field.getName().charAt(0) == 'r') { + values.addAll(groupSchemas.getObject()); + + if (field.getSchemaList().extended()) { + values.add("name"); + } + } else { + values.addAll(userSchemas.getObject()); + + if (field.getSchemaList().extended()) { + values.add("key"); + values.add("username"); + } + } + + component = new AjaxPalettePanel("field", new PropertyModel(policy, field.getName()), + new ListModel<>(values)); + item.add(component); + + Collection<?> collection = (Collection) propDesc.getReadMethod().invoke(policy); + item.add(getActivationControl(component, + !collection.isEmpty(), new ArrayList<String>(), new ArrayList<String>())); + } else { + final FieldPanel panel = new AjaxTextFieldPanel("panel", field.getName(), + new Model<String>(null)); + panel.setRequired(true); + + component = new MultiFieldPanel<String>("field", + new PropertyModel(policy, field.getName()), panel); + + item.add(component); + + final List<String> reinitializedValue = new ArrayList<String>(); + + reinitializedValue.add(""); + + item.add(getActivationControl(component, + !((Collection) propDesc.getReadMethod().invoke(policy, new Object[] {})).isEmpty(), + new ArrayList<String>(), (Serializable) reinitializedValue)); + } + } else if (ClassUtils.isAssignable(Number.class, field.getType())) { + component = new SpinnerFieldPanel<Number>("field", field.getName(), + (Class<Number>) field.getType(), new PropertyModel<Number>(policy, field.getName()), + null, null); + item.add(component); + + item.add(getActivationControl(component, + (Integer) propDesc.getReadMethod().invoke(policy, new Object[] {}) > 0, 0, 0)); + } else if (field.getType().equals(String.class)) { + component = new AjaxTextFieldPanel("field", field.getName(), + new PropertyModel(policy, field.getName())); + + item.add(component); + + item.add(getActivationControl(component, + propDesc.getReadMethod().invoke(policy, new Object[] {}) != null, null, null)); + } else { + item.add(new AjaxCheckBoxPanel("check", field.getName(), new Model())); + item.add(new Label("field", new Model(null))); + } + } catch (Exception e) { + LOG.error("Error retrieving policy fields", e); + } + } + }; + + add(policies); + } + + private <T extends Serializable> AjaxCheckBoxPanel getActivationControl(final AbstractFieldPanel<T> panel, + final Boolean checked, final T defaultModelObject, final T reinitializedValue) { + + final AjaxCheckBoxPanel check = new AjaxCheckBoxPanel("check", "check", new Model<Boolean>(checked)); + + panel.setEnabled(checked); + + check.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (check.getModelObject()) { + panel.setEnabled(true); + panel.setModelObject(reinitializedValue); + } else { + panel.setModelObject(defaultModelObject); + panel.setEnabled(false); + } + + target.add(panel); + } + }); + + return check; + } + + private static class FieldWrapper implements Serializable { + + private static final long serialVersionUID = -6770429509752964215L; + + private Class<?> type; + + private String name; + + private transient SchemaList schemaList; + + private transient ClassList classList; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Class<?> getType() { + return type; + } + + public void setType(final Class<?> type) { + this.type = type; + } + + public SchemaList getSchemaList() { + return schemaList; + } + + public void setSchemaList(final SchemaList schemaList) { + this.schemaList = schemaList; + } + + public ClassList getClassList() { + return classList; + } + + public void setClassList(ClassList classList) { + this.classList = classList; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PropagationTasks.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PropagationTasks.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PropagationTasks.java new file mode 100644 index 0000000..41fdb03 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PropagationTasks.java @@ -0,0 +1,264 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.pages.PropagationTaskModalPage; +import org.apache.syncope.client.console.pages.Tasks; +import org.apache.syncope.client.console.pages.Tasks.TasksProvider; +import org.apache.syncope.client.console.panels.AbstractSearchResultPanel.EventDataWrapper; +import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.ActionColumn; +import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.DatePropertyColumn; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.PropagationTaskTO; +import org.apache.wicket.Component; +import org.apache.wicket.Page; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.event.IEvent; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.StringResourceModel; +import org.apache.wicket.request.http.WebResponse; + +/** + * Tasks page. + */ +public class PropagationTasks extends AbstractTasks { + + private static final long serialVersionUID = 4984337552918213290L; + + private int paginatorRows; + + private WebMarkupContainer container; + + private boolean operationResult = false; + + private ModalWindow window; + + private AjaxDataTablePanel<AbstractTaskTO, String> table; + + public PropagationTasks(final String id, final PageReference pageRef) { + super(id, pageRef); + + container = new WebMarkupContainer("container"); + container.setOutputMarkupId(true); + add(container); + + add(window = new ModalWindow("taskWin")); + + paginatorRows = prefMan.getPaginatorRows(getWebRequest(), Constants.PREF_PROPAGATION_TASKS_PAGINATOR_ROWS); + + table = Tasks.updateTaskTable( + getColumns(), + new TasksProvider<PropagationTaskTO>(restClient, paginatorRows, getId(), PropagationTaskTO.class), + container, + 0, + pageRef, + restClient); + + window.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + target.add(container); + if (operationResult) { + info(getString(Constants.OPERATION_SUCCEEDED)); + target.add(getPage().get(Constants.FEEDBACK)); + operationResult = false; + } + } + }); + + window.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + window.setInitialHeight(WIN_HEIGHT); + window.setInitialWidth(WIN_WIDTH); + window.setCookieName(VIEW_TASK_WIN_COOKIE_NAME); + + @SuppressWarnings("rawtypes") + Form paginatorForm = new Form("PaginatorForm"); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final DropDownChoice rowsChooser = new DropDownChoice( + "rowsChooser", new PropertyModel(this, "paginatorRows"), prefMan.getPaginatorChoices()); + + rowsChooser.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + prefMan.set(getWebRequest(), (WebResponse) getResponse(), + Constants.PREF_PROPAGATION_TASKS_PAGINATOR_ROWS, String.valueOf(paginatorRows)); + + table = Tasks.updateTaskTable( + getColumns(), + new TasksProvider<>(restClient, paginatorRows, getId(), PropagationTaskTO.class), + container, + table == null ? 0 : (int) table.getCurrentPage(), + pageRef, + restClient); + + target.add(container); + } + }); + + paginatorForm.add(rowsChooser); + add(paginatorForm); + } + + private List<IColumn<AbstractTaskTO, String>> getColumns() { + final List<IColumn<AbstractTaskTO, String>> columns = new ArrayList<>(); + + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("key", this, null), "key", "key")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("resource", this, null), "resource", "resource")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("accountId", this, null), "accountId", "accountId")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("propagationMode", this, null), "propagationMode", "propagationMode")); + columns.add(new PropertyColumn<AbstractTaskTO, String>(new StringResourceModel( + "propagationOperation", this, null), "propagationOperation", "propagationOperation")); + columns.add(new DatePropertyColumn<AbstractTaskTO>( + new StringResourceModel("startDate", this, null), "startDate", "startDate")); + columns.add(new DatePropertyColumn<AbstractTaskTO>( + new StringResourceModel("endDate", this, null), "endDate", "endDate")); + columns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("latestExecStatus", this, null), "latestExecStatus", "latestExecStatus")); + columns.add(new ActionColumn<AbstractTaskTO, String>(new StringResourceModel("actions", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public ActionLinksPanel getActions(final String componentId, final IModel<AbstractTaskTO> model) { + + final AbstractTaskTO taskTO = model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + + window.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + return new PropagationTaskModalPage(taskTO); + } + }); + + window.show(target); + } + }, ActionLink.ActionType.EDIT, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.startExecution(taskTO.getKey(), false); + getSession().info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + target.add(container); + } + }, ActionLink.ActionType.EXECUTE, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.delete(taskTO.getKey(), PropagationTaskTO.class); + info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.DELETE, TASKS); + + return panel; + } + + @Override + public Component getHeader(final String componentId) { + final ActionLinksPanel panel = new ActionLinksPanel(componentId, new Model(), pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -7978723352517770644L; + + @Override + public void onClick(final AjaxRequestTarget target) { + if (target != null) { + target.add(table); + } + } + }, ActionLink.ActionType.RELOAD, TASKS, "list"); + + return panel; + } + }); + + return columns; + } + + @Override + public void onEvent(final IEvent<?> event) { + if (event.getPayload() instanceof EventDataWrapper) { + ((EventDataWrapper) event.getPayload()).getTarget().add(container); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PushTasksPanel.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PushTasksPanel.java b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PushTasksPanel.java new file mode 100644 index 0000000..a93000d --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/panels/PushTasksPanel.java @@ -0,0 +1,184 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.pages.PushTaskModalPage; +import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.ActionColumn; +import org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table.DatePropertyColumn; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.PushTaskTO; +import org.apache.syncope.common.lib.to.SyncTaskTO; +import org.apache.wicket.Component; +import org.apache.wicket.Page; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.StringResourceModel; + +public class PushTasksPanel extends AbstractProvisioningTasksPanel<PushTaskTO> { + + private static final long serialVersionUID = -2492299671757861889L; + + public PushTasksPanel(final String id, final PageReference pageRef) { + super(id, pageRef, PushTaskTO.class); + initTasksTable(); + } + + @Override + protected List<IColumn<AbstractTaskTO, String>> getColumns() { + final List<IColumn<AbstractTaskTO, String>> pushTasksColumns = new ArrayList<IColumn<AbstractTaskTO, String>>(); + + pushTasksColumns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("key", this, null), "key", "key")); + pushTasksColumns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("name", this, null), "name", "name")); + pushTasksColumns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("description", this, null), "description", "description")); + pushTasksColumns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("resourceName", this, null), "resource", "resource")); + pushTasksColumns.add(new DatePropertyColumn<AbstractTaskTO>( + new StringResourceModel("lastExec", this, null), "lastExec", "lastExec")); + pushTasksColumns.add(new DatePropertyColumn<AbstractTaskTO>( + new StringResourceModel("nextExec", this, null), "nextExec", "nextExec")); + pushTasksColumns.add(new PropertyColumn<AbstractTaskTO, String>( + new StringResourceModel("latestExecStatus", this, null), "latestExecStatus", "latestExecStatus")); + + pushTasksColumns.add( + new ActionColumn<AbstractTaskTO, String>(new StringResourceModel("actions", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public ActionLinksPanel getActions(final String componentId, final IModel<AbstractTaskTO> model) { + + final PushTaskTO taskTO = (PushTaskTO) model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + + window.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + return new PushTaskModalPage(window, taskTO, pageRef); + } + }); + + window.show(target); + } + }, ActionLink.ActionType.EDIT, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.startExecution(taskTO.getKey(), false); + getSession().info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.EXECUTE, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.startExecution(taskTO.getKey(), true); + getSession().info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.DRYRUN, TASKS); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + restClient.delete(taskTO.getKey(), SyncTaskTO.class); + info(getString(Constants.OPERATION_SUCCEEDED)); + } catch (SyncopeClientException scce) { + error(scce.getMessage()); + } + target.add(container); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }, ActionLink.ActionType.DELETE, TASKS); + + return panel; + } + + @Override + public Component getHeader(final String componentId) { + final ActionLinksPanel panel = new ActionLinksPanel(componentId, new Model(), pageRef); + + panel.add(new ActionLink() { + + private static final long serialVersionUID = -7978723352517770644L; + + @Override + public void onClick(final AjaxRequestTarget target) { + if (target != null) { + target.add(table); + } + } + }, ActionLink.ActionType.RELOAD, TASKS, "list"); + + return panel; + } + }); + + return pushTasksColumns; + + } +}
