http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/PlainSchemaModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/PlainSchemaModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/PlainSchemaModalPage.java new file mode 100644 index 0000000..bad0ae7 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/PlainSchemaModalPage.java @@ -0,0 +1,456 @@ +/* + * 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.pages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.JexlHelpUtil; +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.MultiFieldPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.syncope.common.lib.to.PlainSchemaTO; +import org.apache.syncope.common.lib.types.AttrSchemaType; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.CipherAlgorithm; +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.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +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.CompoundPropertyModel; +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.util.string.Strings; + +/** + * Modal window with Schema form. + */ +public class PlainSchemaModalPage extends AbstractSchemaModalPage<PlainSchemaTO> { + + private static final long serialVersionUID = -5991561277287424057L; + + public PlainSchemaModalPage(final AttributableType kind) { + super(kind); + } + + @Override + public void setSchemaModalPage(final PageReference pageRef, final ModalWindow window, + final PlainSchemaTO schemaTO, final boolean createFlag) { + + final PlainSchemaTO schema = schemaTO == null + ? new PlainSchemaTO() + : schemaTO; + + final Form<PlainSchemaTO> schemaForm = new Form<>(FORM); + + schemaForm.setModel(new CompoundPropertyModel<>(schema)); + schemaForm.setOutputMarkupId(true); + + final AjaxTextFieldPanel name = + new AjaxTextFieldPanel("key", getString("key"), new PropertyModel<String>(schema, "key")); + name.addRequiredLabel(); + name.setEnabled(createFlag); + schemaForm.add(name); + + final AjaxDropDownChoicePanel<AttrSchemaType> type = new AjaxDropDownChoicePanel<>( + "type", getString("type"), new PropertyModel<AttrSchemaType>(schema, "type")); + type.setChoices(Arrays.asList(AttrSchemaType.values())); + type.addRequiredLabel(); + schemaForm.add(type); + + // -- long, double, date + final AjaxTextFieldPanel conversionPattern = new AjaxTextFieldPanel("conversionPattern", + getString("conversionPattern"), new PropertyModel<String>(schema, "conversionPattern")); + schemaForm.add(conversionPattern); + + final WebMarkupContainer conversionParams = new WebMarkupContainer("conversionParams"); + conversionParams.setOutputMarkupPlaceholderTag(true); + conversionParams.add(conversionPattern); + schemaForm.add(conversionParams); + + final WebMarkupContainer typeParams = new WebMarkupContainer("typeParams"); + typeParams.setOutputMarkupPlaceholderTag(true); + // -- enum + final AjaxTextFieldPanel enumerationValuesPanel = + new AjaxTextFieldPanel("panel", "enumerationValues", new Model<String>(null)); + @SuppressWarnings({ "unchecked", "rawtypes" }) + final MultiFieldPanel<String> enumerationValues = new MultiFieldPanel<>("enumerationValues", + new Model(), + enumerationValuesPanel); + enumerationValues.setModelObject(getEnumValuesAsList(schema.getEnumerationValues())); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final MultiFieldPanel<String> enumerationKeys = new MultiFieldPanel<>("enumerationKeys", + new Model(), + new AjaxTextFieldPanel("panel", "enumerationKeys", new Model<String>(null))); + enumerationKeys.setModelObject(getEnumValuesAsList(schema.getEnumerationKeys())); + + final WebMarkupContainer enumParams = new WebMarkupContainer("enumParams"); + enumParams.setOutputMarkupPlaceholderTag(true); + enumParams.add(enumerationValues); + enumParams.add(enumerationKeys); + typeParams.add(enumParams); + + // -- encrypted + final AjaxTextFieldPanel secretKey = new AjaxTextFieldPanel("secretKey", + getString("secretKey"), new PropertyModel<String>(schema, "secretKey")); + + final AjaxDropDownChoicePanel<CipherAlgorithm> cipherAlgorithm = new AjaxDropDownChoicePanel<>( + "cipherAlgorithm", getString("cipherAlgorithm"), + new PropertyModel<CipherAlgorithm>(schema, "cipherAlgorithm")); + cipherAlgorithm.setChoices(Arrays.asList(CipherAlgorithm.values())); + + final WebMarkupContainer encryptedParams = new WebMarkupContainer("encryptedParams"); + encryptedParams.setOutputMarkupPlaceholderTag(true); + encryptedParams.add(secretKey); + encryptedParams.add(cipherAlgorithm); + typeParams.add(encryptedParams); + + // -- binary + final AjaxTextFieldPanel mimeType = new AjaxTextFieldPanel("mimeType", + getString("mimeType"), new PropertyModel<String>(schema, "mimeType")); + mimeType.setChoices(mimeTypesInitializer.getMimeTypes()); + + final WebMarkupContainer binaryParams = new WebMarkupContainer("binaryParams"); + binaryParams.setOutputMarkupPlaceholderTag(true); + binaryParams.add(mimeType); + typeParams.add(binaryParams); + + schemaForm.add(typeParams); + + // -- show or hide + showHide(schema, type, + conversionParams, conversionPattern, + enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys, + encryptedParams, secretKey, cipherAlgorithm, + binaryParams, mimeType); + type.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + PlainSchemaModalPage.this.showHide(schema, type, + conversionParams, conversionPattern, + enumParams, enumerationValuesPanel, enumerationValues, enumerationKeys, + encryptedParams, secretKey, cipherAlgorithm, + binaryParams, mimeType); + target.add(typeParams); + } + }); + + final IModel<List<String>> validatorsList = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return schemaRestClient.getAllValidatorClasses(); + } + }; + final AjaxDropDownChoicePanel<String> validatorClass = new AjaxDropDownChoicePanel<>("validatorClass", + getString("validatorClass"), new PropertyModel<String>(schema, "validatorClass")); + ((DropDownChoice) validatorClass.getField()).setNullValid(true); + validatorClass.setChoices(validatorsList.getObject()); + schemaForm.add(validatorClass); + + final AutoCompleteTextField<String> mandatoryCondition = + new AutoCompleteTextField<String>("mandatoryCondition") { + + private static final long serialVersionUID = -2428903969518079100L; + + @Override + protected Iterator<String> getChoices(final String input) { + List<String> choices = new ArrayList<String>(); + + if (Strings.isEmpty(input)) { + choices = Collections.emptyList(); + } else if ("true".startsWith(input.toLowerCase())) { + choices.add("true"); + } else if ("false".startsWith(input.toLowerCase())) { + choices.add("false"); + } + + return choices.iterator(); + } + }; + mandatoryCondition.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + } + }); + schemaForm.add(mandatoryCondition); + + final WebMarkupContainer pwdJexlHelp = JexlHelpUtil.getJexlHelpWebContainer("jexlHelp"); + + final AjaxLink<Void> pwdQuestionMarkJexlHelp = JexlHelpUtil.getAjaxLink(pwdJexlHelp, "questionMarkJexlHelp"); + schemaForm.add(pwdQuestionMarkJexlHelp); + pwdQuestionMarkJexlHelp.add(pwdJexlHelp); + + final AjaxCheckBoxPanel multivalue = new AjaxCheckBoxPanel("multivalue", getString("multivalue"), + new PropertyModel<Boolean>(schema, "multivalue")); + schemaForm.add(multivalue); + + final AjaxCheckBoxPanel readonly = new AjaxCheckBoxPanel("readonly", getString("readonly"), + new PropertyModel<Boolean>(schema, "readonly")); + schemaForm.add(readonly); + + final AjaxCheckBoxPanel uniqueConstraint = new AjaxCheckBoxPanel("uniqueConstraint", + getString("uniqueConstraint"), new PropertyModel<Boolean>(schema, "uniqueConstraint")); + schemaForm.add(uniqueConstraint); + + final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(SUBMIT)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + final PlainSchemaTO schemaTO = (PlainSchemaTO) form.getDefaultModelObject(); + + schemaTO.setEnumerationValues(getEnumValuesAsString(enumerationValues.getView().getModelObject())); + schemaTO.setEnumerationKeys(getEnumValuesAsString(enumerationKeys.getView().getModelObject())); + + if (schemaTO.isMultivalue() && schemaTO.isUniqueConstraint()) { + error(getString("multivalueAndUniqueConstr.validation")); + feedbackPanel.refresh(target); + return; + } + + try { + if (createFlag) { + schemaRestClient.createPlainSchema(kind, schemaTO); + } else { + schemaRestClient.updatePlainSchema(kind, schemaTO); + } + if (pageRef.getPage() instanceof BasePage) { + ((BasePage) pageRef.getPage()).setModalResult(true); + } + + window.close(target); + } catch (SyncopeClientException e) { + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + feedbackPanel.refresh(target); + } + }; + schemaForm.add(submit); + + final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + window.close(target); + } + }; + cancel.setDefaultFormProcessing(false); + schemaForm.add(cancel); + + String allowedRoles = createFlag + ? xmlRolesReader.getEntitlement("Schema", "create") + : xmlRolesReader.getEntitlement("Schema", "update"); + + MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); + + add(schemaForm); + } + + private void showHide(final PlainSchemaTO schema, final AjaxDropDownChoicePanel<AttrSchemaType> type, + final WebMarkupContainer conversionParams, final AjaxTextFieldPanel conversionPattern, + final WebMarkupContainer enumParams, final AjaxTextFieldPanel enumerationValuesPanel, + final MultiFieldPanel<String> enumerationValues, final MultiFieldPanel<String> enumerationKeys, + final WebMarkupContainer encryptedParams, + final AjaxTextFieldPanel secretKey, final AjaxDropDownChoicePanel<CipherAlgorithm> cipherAlgorithm, + final WebMarkupContainer binaryParams, final AjaxTextFieldPanel mimeType) { + + final int typeOrdinal = Integer.parseInt(type.getField().getValue()); + if (AttrSchemaType.Long.ordinal() == typeOrdinal + || AttrSchemaType.Double.ordinal() == typeOrdinal + || AttrSchemaType.Date.ordinal() == typeOrdinal) { + + conversionParams.setVisible(true); + + enumParams.setVisible(false); + if (enumerationValuesPanel.isRequired()) { + enumerationValuesPanel.removeRequiredLabel(); + } + enumerationValues.setModelObject(getEnumValuesAsList(null)); + enumerationKeys.setModelObject(getEnumValuesAsList(null)); + + encryptedParams.setVisible(false); + if (secretKey.isRequired()) { + secretKey.removeRequiredLabel(); + } + secretKey.setModelObject(null); + if (cipherAlgorithm.isRequired()) { + cipherAlgorithm.removeRequiredLabel(); + } + cipherAlgorithm.setModelObject(null); + + binaryParams.setVisible(false); + mimeType.setModelObject(null); + } else if (AttrSchemaType.Enum.ordinal() == typeOrdinal) { + conversionParams.setVisible(false); + conversionPattern.setModelObject(null); + + enumParams.setVisible(true); + if (!enumerationValuesPanel.isRequired()) { + enumerationValuesPanel.addRequiredLabel(); + } + enumerationValues.setModelObject(getEnumValuesAsList(schema.getEnumerationValues())); + enumerationKeys.setModelObject(getEnumValuesAsList(schema.getEnumerationKeys())); + + encryptedParams.setVisible(false); + if (secretKey.isRequired()) { + secretKey.removeRequiredLabel(); + } + secretKey.setModelObject(null); + if (cipherAlgorithm.isRequired()) { + cipherAlgorithm.removeRequiredLabel(); + } + cipherAlgorithm.setModelObject(null); + + binaryParams.setVisible(false); + mimeType.setModelObject(null); + } else if (AttrSchemaType.Encrypted.ordinal() == typeOrdinal) { + conversionParams.setVisible(false); + conversionPattern.setModelObject(null); + + enumParams.setVisible(false); + if (enumerationValuesPanel.isRequired()) { + enumerationValuesPanel.removeRequiredLabel(); + } + enumerationValues.setModelObject(getEnumValuesAsList(null)); + enumerationKeys.setModelObject(getEnumValuesAsList(null)); + + encryptedParams.setVisible(true); + if (!secretKey.isRequired()) { + secretKey.addRequiredLabel(); + } + if (cipherAlgorithm.isRequired()) { + cipherAlgorithm.addRequiredLabel(); + } + + binaryParams.setVisible(false); + mimeType.setModelObject(null); + } else if (AttrSchemaType.Binary.ordinal() == typeOrdinal) { + conversionParams.setVisible(false); + conversionPattern.setModelObject(null); + + enumParams.setVisible(false); + if (enumerationValuesPanel.isRequired()) { + enumerationValuesPanel.removeRequiredLabel(); + } + enumerationValues.setModelObject(getEnumValuesAsList(null)); + enumerationKeys.setModelObject(getEnumValuesAsList(null)); + + encryptedParams.setVisible(false); + if (secretKey.isRequired()) { + secretKey.removeRequiredLabel(); + } + secretKey.setModelObject(null); + if (cipherAlgorithm.isRequired()) { + cipherAlgorithm.removeRequiredLabel(); + } + cipherAlgorithm.setModelObject(null); + + binaryParams.setVisible(true); + } else { + conversionParams.setVisible(false); + conversionPattern.setModelObject(null); + + enumParams.setVisible(false); + if (enumerationValuesPanel.isRequired()) { + enumerationValuesPanel.removeRequiredLabel(); + } + enumerationValues.setModelObject(getEnumValuesAsList(null)); + enumerationKeys.setModelObject(getEnumValuesAsList(null)); + + encryptedParams.setVisible(false); + if (secretKey.isRequired()) { + secretKey.removeRequiredLabel(); + } + secretKey.setModelObject(null); + if (cipherAlgorithm.isRequired()) { + cipherAlgorithm.removeRequiredLabel(); + } + cipherAlgorithm.setModelObject(null); + + binaryParams.setVisible(false); + mimeType.setModelObject(null); + } + } + + private String getEnumValuesAsString(final List<String> enumerationValues) { + final StringBuilder builder = new StringBuilder(); + + for (String str : enumerationValues) { + if (StringUtils.isNotBlank(str)) { + if (builder.length() > 0) { + builder.append(SyncopeConstants.ENUM_VALUES_SEPARATOR); + } + + builder.append(str.trim()); + } + } + + return builder.toString(); + } + + private List<String> getEnumValuesAsList(final String enumerationValues) { + final List<String> values = new ArrayList<String>(); + + if (StringUtils.isNotBlank(enumerationValues)) { + for (String value : enumerationValues.split(SyncopeConstants.ENUM_VALUES_SEPARATOR)) { + values.add(value.trim()); + } + } else { + values.add(StringUtils.EMPTY); + } + + return values; + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java new file mode 100644 index 0000000..efa61c1 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java @@ -0,0 +1,451 @@ +/* + * 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.pages; + +import java.util.ArrayList; +import java.util.Arrays; +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.panels.NotificationPanel; +import org.apache.syncope.client.console.panels.PolicyBeanPanel; +import org.apache.syncope.client.console.rest.PolicyRestClient; +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.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.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.ResourceTO; +import org.apache.syncope.common.lib.to.RoleTO; +import org.apache.syncope.common.lib.to.SyncPolicyTO; +import org.apache.syncope.common.lib.types.AccountPolicySpec; +import org.apache.syncope.common.lib.types.PasswordPolicySpec; +import org.apache.syncope.common.lib.types.PolicySpec; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.syncope.common.lib.types.SyncPolicySpec; +import org.apache.wicket.Page; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +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.table.AbstractColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider; +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.basic.Label; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.model.StringResourceModel; +import org.apache.wicket.model.util.ListModel; +import org.apache.wicket.spring.injection.annot.SpringBean; + +/** + * Modal window with Resource form. + */ +public class PolicyModalPage<T extends AbstractPolicyTO> extends BaseModalPage { + + private static final long serialVersionUID = -7325772767481076679L; + + private static final int WIN_HEIGHT = 600; + + private static final int WIN_WIDTH = 1100; + + @SpringBean + private PolicyRestClient policyRestClient; + + public PolicyModalPage(final PageReference pageRef, final ModalWindow window, final T policyTO) { + super(); + + final Form<?> form = new Form<>(FORM); + form.setOutputMarkupId(true); + add(form); + + final AjaxTextFieldPanel policyid = + new AjaxTextFieldPanel("key", "key", new PropertyModel<String>(policyTO, "key")); + policyid.setEnabled(false); + policyid.setStyleSheet("ui-widget-content ui-corner-all short_fixedsize"); + form.add(policyid); + + final AjaxTextFieldPanel description = new AjaxTextFieldPanel("description", "description", + new PropertyModel<String>(policyTO, "description")); + description.addRequiredLabel(); + description.setStyleSheet("ui-widget-content ui-corner-all medium_dynamicsize"); + form.add(description); + + final AjaxDropDownChoicePanel<PolicyType> type = + new AjaxDropDownChoicePanel<>("type", "type", new PropertyModel<PolicyType>(policyTO, "type")); + switch (policyTO.getType()) { + case GLOBAL_ACCOUNT: + case ACCOUNT: + type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_ACCOUNT, PolicyType.ACCOUNT })); + break; + + case GLOBAL_PASSWORD: + case PASSWORD: + type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_PASSWORD, PolicyType.PASSWORD })); + break; + + case GLOBAL_SYNC: + case SYNC: + type.setChoices(Arrays.asList(new PolicyType[] { PolicyType.GLOBAL_SYNC, PolicyType.SYNC })); + + default: + } + type.setChoiceRenderer(new PolicyTypeRenderer()); + type.addRequiredLabel(); + form.add(type); + + // Authentication resources - only for AccountPolicyTO + Fragment fragment; + if (policyTO instanceof AccountPolicyTO) { + fragment = new Fragment("forAccountOnly", "authResourcesFragment", form); + + final List<String> resourceNames = new ArrayList<>(); + for (ResourceTO resource : resourceRestClient.getAll()) { + resourceNames.add(resource.getKey()); + } + fragment.add(new AjaxPalettePanel<>("authResources", + new PropertyModel<List<String>>(policyTO, "resources"), + new ListModel<>(resourceNames))); + } else { + fragment = new Fragment("forAccountOnly", "emptyFragment", form); + } + form.add(fragment); + // + + final PolicySpec policy = getPolicySpecification(policyTO); + + form.add(new PolicyBeanPanel("panel", policy)); + + final ModalWindow mwindow = new ModalWindow("metaEditModalWin"); + mwindow.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + mwindow.setInitialHeight(WIN_HEIGHT); + mwindow.setInitialWidth(WIN_WIDTH); + mwindow.setCookieName("meta-edit-modal"); + add(mwindow); + + List<IColumn<String, String>> resColumns = new ArrayList<>(); + resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("name", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public void populateItem(final Item<ICellPopulator<String>> cellItem, + final String componentId, final IModel<String> rowModel) { + + cellItem.add(new Label(componentId, rowModel.getObject())); + } + }); + resColumns.add(new AbstractColumn<String, String>(new StringResourceModel("actions", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem(final Item<ICellPopulator<String>> cellItem, final String componentId, + final IModel<String> model) { + + final String resource = model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference()); + 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; + + @Override + public Page createPage() { + return new ResourceModalPage(PolicyModalPage.this.getPageReference(), + mwindow, resourceRestClient.read(resource), false); + } + }); + + mwindow.show(target); + } + }, ActionLink.ActionType.EDIT, "Resources"); + + cellItem.add(panel); + } + }); + ISortableDataProvider<String, String> resDataProvider = new SortableDataProvider<String, String>() { + + private static final long serialVersionUID = 8263758912838836438L; + + @Override + public Iterator<? extends String> iterator(final long first, final long count) { + return policyTO.getKey() == 0 + ? Collections.<String>emptyList().iterator() + : policyRestClient.getPolicy(policyTO.getKey()). + getUsedByResources().subList((int) first, (int) first + (int) count).iterator(); + } + + @Override + public long size() { + return policyTO.getKey() == 0 + ? 0 + : policyRestClient.getPolicy(policyTO.getKey()). + getUsedByResources().size(); + } + + @Override + public IModel<String> model(final String object) { + return new Model<>(object); + } + }; + final AjaxFallbackDefaultDataTable<String, String> resources = + new AjaxFallbackDefaultDataTable<>("resources", resColumns, resDataProvider, 10); + form.add(resources); + + List<IColumn<RoleTO, String>> roleColumns = new ArrayList<>(); + roleColumns.add(new PropertyColumn<RoleTO, String>(new ResourceModel("key", "key"), "key", "key")); + roleColumns.add(new PropertyColumn<RoleTO, String>(new ResourceModel("name", "name"), "name", "name")); + roleColumns.add(new AbstractColumn<RoleTO, String>(new StringResourceModel("actions", this, null, "")) { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem(final Item<ICellPopulator<RoleTO>> cellItem, final String componentId, + final IModel<RoleTO> model) { + + final RoleTO role = model.getObject(); + + final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference()); + 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; + + @Override + public Page createPage() { + return new RoleModalPage(PolicyModalPage.this.getPageReference(), mwindow, role); + } + }); + + mwindow.show(target); + } + }, ActionLink.ActionType.EDIT, "Roles"); + + cellItem.add(panel); + } + }); + ISortableDataProvider<RoleTO, String> roleDataProvider = new SortableDataProvider<RoleTO, String>() { + + private static final long serialVersionUID = 8263758912838836438L; + + @Override + public Iterator<? extends RoleTO> iterator(final long first, final long count) { + List<RoleTO> roles = new ArrayList<>(); + + if (policyTO.getKey() > 0) { + for (Long roleId : policyRestClient.getPolicy(policyTO.getKey()). + getUsedByRoles().subList((int) first, (int) first + (int) count)) { + + roles.add(roleRestClient.read(roleId)); + } + } + + return roles.iterator(); + } + + @Override + public long size() { + return policyTO.getKey() == 0 + ? 0 + : policyRestClient.getPolicy(policyTO.getKey()). + getUsedByRoles().size(); + } + + @Override + public IModel<RoleTO> model(final RoleTO object) { + return new Model<>(object); + } + }; + final AjaxFallbackDefaultDataTable<RoleTO, String> roles = + new AjaxFallbackDefaultDataTable<>("roles", roleColumns, roleDataProvider, 10); + form.add(roles); + + mwindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + target.add(resources); + target.add(roles); + if (isModalResult()) { + info(getString(Constants.OPERATION_SUCCEEDED)); + feedbackPanel.refresh(target); + setModalResult(false); + } + } + }); + + final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + setPolicySpecification(policyTO, policy); + + try { + if (policyTO.getKey() > 0) { + policyRestClient.updatePolicy(policyTO); + } else { + policyRestClient.createPolicy(policyTO); + } + ((BasePage) pageRef.getPage()).setModalResult(true); + + window.close(target); + } catch (Exception e) { + LOG.error("While creating policy", e); + + error(getString(Constants.ERROR) + ": " + e.getMessage()); + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + ((NotificationPanel) getPage().get(Constants.FEEDBACK)).refresh(target); + } + }; + form.add(submit); + + final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + window.close(target); + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + } + }; + cancel.setDefaultFormProcessing(false); + form.add(cancel); + } + + private PolicySpec getPolicySpecification(final AbstractPolicyTO policyTO) { + PolicySpec spec; + + switch (policyTO.getType()) { + case GLOBAL_ACCOUNT: + case ACCOUNT: + spec = ((AccountPolicyTO) policyTO).getSpecification() != null + ? ((AccountPolicyTO) policyTO).getSpecification() + : new AccountPolicySpec(); + break; + + case GLOBAL_PASSWORD: + case PASSWORD: + spec = ((PasswordPolicyTO) policyTO).getSpecification() != null + ? ((PasswordPolicyTO) policyTO).getSpecification() + : new PasswordPolicySpec(); + break; + + case GLOBAL_SYNC: + case SYNC: + default: + spec = ((SyncPolicyTO) policyTO).getSpecification() != null + ? ((SyncPolicyTO) policyTO).getSpecification() + : new SyncPolicySpec(); + } + + return spec; + } + + private void setPolicySpecification(final AbstractPolicyTO policyTO, final PolicySpec specification) { + switch (policyTO.getType()) { + case GLOBAL_ACCOUNT: + case ACCOUNT: + if (!(specification instanceof AccountPolicySpec)) { + throw new ClassCastException("policy is type Account, but spec is not: " + + specification.getClass().getName()); + } + ((AccountPolicyTO) policyTO).setSpecification((AccountPolicySpec) specification); + break; + + case GLOBAL_PASSWORD: + case PASSWORD: + if (!(specification instanceof PasswordPolicySpec)) { + throw new ClassCastException("policy is type Password, but spec is not: " + + specification.getClass().getName()); + } + ((PasswordPolicyTO) policyTO).setSpecification((PasswordPolicySpec) specification); + break; + + case GLOBAL_SYNC: + case SYNC: + if (!(specification instanceof SyncPolicySpec)) { + throw new ClassCastException("policy is type Sync, but spec is not: " + + specification.getClass().getName()); + } + ((SyncPolicyTO) policyTO).setSpecification((SyncPolicySpec) specification); + + default: + } + } + + private class PolicyTypeRenderer extends ChoiceRenderer<PolicyType> { + + private static final long serialVersionUID = -8993265421104002134L; + + @Override + public Object getDisplayValue(final PolicyType object) { + return getString(object.name()); + } + }; +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java new file mode 100644 index 0000000..5a6779f --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java @@ -0,0 +1,45 @@ +/* + * 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.pages; + +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.wicket.model.PropertyModel; + +/** + * Modal window with Task form (to stop and start execution). + */ +public class PropagationTaskModalPage extends TaskModalPage { + + private static final long serialVersionUID = 523379887023786151L; + + public PropagationTaskModalPage(final AbstractTaskTO taskTO) { + super(taskTO); + + final AjaxTextFieldPanel accountId = new AjaxTextFieldPanel("accountId", getString("accountId"), + new PropertyModel<String>(taskTO, "accountId")); + accountId.setEnabled(false); + profile.add(accountId); + + final AjaxTextFieldPanel resource = new AjaxTextFieldPanel("resource", getString("resource"), + new PropertyModel<String>(taskTO, "resource")); + resource.setEnabled(false); + profile.add(resource); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java new file mode 100644 index 0000000..dc3ee88 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java @@ -0,0 +1,250 @@ +/* + * 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.pages; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.status.AbstractStatusBeanProvider; +import org.apache.syncope.client.console.commons.status.ConnObjectWrapper; +import org.apache.syncope.client.console.commons.status.StatusBean; +import org.apache.syncope.client.console.commons.status.StatusUtils; +import org.apache.syncope.client.console.panels.ActionDataTablePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.AbstractSubjectTO; +import org.apache.syncope.common.lib.to.BulkActionResult; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.to.RoleTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.ResourceDeassociationActionType; +import org.apache.syncope.common.lib.wrap.AbstractWrappable; +import org.apache.syncope.common.lib.wrap.SubjectKey; +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.grid.ICellPopulator; +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.ISortableDataProvider; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.StringResourceModel; + +public class ProvisioningModalPage<T extends AbstractAttributableTO> extends AbstractStatusModalPage { + + private static final long serialVersionUID = -4285220460543213901L; + + private static final int ROWS_PER_PAGE = 10; + + private final ResourceTO resourceTO; + + private final Class<? extends AbstractAttributableTO> typeRef; + + private final PageReference pageRef; + + private final ModalWindow window; + + private final StatusUtils statusUtils; + + public ProvisioningModalPage( + final PageReference pageRef, + final ModalWindow window, + final ResourceTO resourceTO, + final Class<T> typeRef) { + + super(); + + this.pageRef = pageRef; + this.window = window; + this.resourceTO = resourceTO; + this.typeRef = typeRef; + + statusUtils = new StatusUtils((UserTO.class.isAssignableFrom(typeRef) ? userRestClient : roleRestClient)); + + add(new Label("displayName", StringUtils.EMPTY)); + + final List<IColumn<StatusBean, String>> columns = new ArrayList<>(); + columns.add(new PropertyColumn<StatusBean, String>( + new StringResourceModel("key", this, null, "Attributable key"), + "attributableKey", "attributableKey")); + columns.add(new PropertyColumn<StatusBean, String>( + new StringResourceModel("name", this, null, "Attributable name"), + "attributableName", "attributableName")); + columns.add(new PropertyColumn<StatusBean, String>( + new StringResourceModel("resourceName", this, null, "Resource name"), + "resourceName", "resourceName")); + columns.add(new PropertyColumn<StatusBean, String>( + new StringResourceModel("accountLink", this, null, "Account link"), + "accountLink", "accountLink")); + columns.add(new AbstractColumn<StatusBean, String>( + new StringResourceModel("status", this, null, "")) { + + private static final long serialVersionUID = -3503023501954863131L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem( + final Item<ICellPopulator<StatusBean>> cellItem, + final String componentId, + final IModel<StatusBean> model) { + cellItem. + add(statusUtils.getStatusImagePanel(componentId, model.getObject().getStatus())); + } + }); + + final ActionDataTablePanel<StatusBean, String> table = new ActionDataTablePanel<>( + "resourceDatatable", + columns, + (ISortableDataProvider<StatusBean, String>) new StatusBeanProvider(), + ROWS_PER_PAGE, + pageRef); + + final String pageId = "Resources"; + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + bulkAssociationAction(target, ResourceDeassociationActionType.UNLINK, table, columns); + } catch (Exception e) { + LOG.error("Error unlinkink resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNLINK, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + bulkAssociationAction(target, ResourceDeassociationActionType.DEPROVISION, table, columns); + } catch (Exception e) { + LOG.error("Error de-provisioning user", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.DEPROVISION, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target) { + try { + bulkAssociationAction(target, ResourceDeassociationActionType.UNASSIGN, table, columns); + } catch (Exception e) { + LOG.error("Error unassigning resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNASSIGN, pageId); + + table.addCancelButton(window); + + add(table); + } + + private class StatusBeanProvider extends AbstractStatusBeanProvider { + + private static final long serialVersionUID = 4287357360778016173L; + + public StatusBeanProvider() { + super("accountLink"); + } + + @SuppressWarnings("unchecked") + @Override + public List<StatusBean> getStatusBeans() { + final String fiql = SyncopeClient.getUserSearchConditionBuilder().hasResources(resourceTO.getKey()).query(); + + final List<T> subjects = new ArrayList<>(); + if (UserTO.class.isAssignableFrom(typeRef)) { + subjects.addAll((List<T>) userRestClient.search(fiql, 1, ROWS_PER_PAGE, new SortParam<>("key", true))); + } else { + subjects.addAll((List<T>) roleRestClient.search(fiql, 1, ROWS_PER_PAGE, new SortParam<>("key", true))); + } + + final List<ConnObjectWrapper> connObjects = statusUtils.getConnectorObjects( + (List<AbstractSubjectTO>) subjects, Collections.<String>singleton(resourceTO.getKey())); + + final List<StatusBean> statusBeans = new ArrayList<>(connObjects.size() + 1); + final LinkedHashMap<String, StatusBean> initialStatusBeanMap = new LinkedHashMap<>(connObjects.size()); + + for (ConnObjectWrapper entry : connObjects) { + final StatusBean statusBean = statusUtils.getStatusBean( + entry.getAttributable(), + entry.getResourceName(), + entry.getConnObjectTO(), + RoleTO.class.isAssignableFrom(typeRef)); + + initialStatusBeanMap.put(entry.getResourceName(), statusBean); + statusBeans.add(statusBean); + } + + return statusBeans; + } + } + + private void bulkAssociationAction( + final AjaxRequestTarget target, + final ResourceDeassociationActionType type, + final ActionDataTablePanel<StatusBean, String> table, + final List<IColumn<StatusBean, String>> columns) { + + final List<StatusBean> beans = new ArrayList<>(table.getModelObject()); + List<SubjectKey> subjectKeys = new ArrayList<>(); + for (StatusBean bean : beans) { + LOG.debug("Selected bean {}", bean); + subjectKeys.add(AbstractWrappable.getInstance(SubjectKey.class, bean.getAttributableId())); + } + + if (beans.isEmpty()) { + window.close(target); + } else { + final BulkActionResult res = resourceRestClient.bulkAssociationAction( + resourceTO.getKey(), typeRef, type, subjectKeys); + + ((BasePage) pageRef.getPage()).setModalResult(true); + + setResponsePage(new BulkActionResultModalPage<>(window, beans, columns, res, "attributableKey")); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java new file mode 100644 index 0000000..a799b15 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java @@ -0,0 +1,135 @@ +/* + * 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.pages; + +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.panels.RoleSearchPanel; +import org.apache.syncope.client.console.panels.UserSearchPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel; +import org.apache.syncope.common.lib.to.PushTaskTO; +import org.apache.syncope.common.lib.to.SchedTaskTO; +import org.apache.syncope.common.lib.types.MatchingRule; +import org.apache.syncope.common.lib.types.UnmatchingRule; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.model.Model; + +/** + * Modal window with Push Task form. + */ +public class PushTaskModalPage extends AbstractSyncTaskModalPage { + + private static final long serialVersionUID = 2148403203517274669L; + + private final UserSearchPanel userFilter; + + private final RoleSearchPanel roleFilter; + + private final AjaxCheckBoxPanel checkUserFilter; + + private final AjaxCheckBoxPanel checkRoleFilter; + + @Override + protected List<String> getSyncActions() { + return taskRestClient.getPushActionsClasses(); + } + + public PushTaskModalPage(final ModalWindow window, final PushTaskTO taskTO, final PageReference pageRef) { + + super(window, taskTO, pageRef); + + // set default Matching rule + ((DropDownChoice) matchingRule.getField()).setDefaultModelObject(taskTO.getMatchingRule() == null + ? MatchingRule.UPDATE + : taskTO.getMatchingRule()); + profile.add(matchingRule); + + // set default Unmatching rule + ((DropDownChoice) unmatchingRule.getField()).setDefaultModelObject(taskTO.getUnmatchingRule() == null + ? UnmatchingRule.ASSIGN + : taskTO.getUnmatchingRule()); + profile.add(unmatchingRule); + + final WebMarkupContainer filterContainer = new WebMarkupContainer("filterContainer"); + filterContainer.setOutputMarkupId(true); + + checkUserFilter = new AjaxCheckBoxPanel("checkUserFilter", "checkUserFilter", + new Model<Boolean>(taskTO.getUserFilter() != null)); + filterContainer.add(checkUserFilter); + + checkRoleFilter = new AjaxCheckBoxPanel("checkRoleFilter", "checkRoleFilter", + new Model<Boolean>(taskTO.getRoleFilter() != null)); + filterContainer.add(checkRoleFilter); + + userFilter = new UserSearchPanel.Builder("userFilter").fiql(taskTO.getUserFilter()).build(); + userFilter.setEnabled(checkUserFilter.getModelObject()); + + filterContainer.add(userFilter); + + roleFilter = new RoleSearchPanel.Builder("roleFilter").fiql(taskTO.getRoleFilter()).build(); + roleFilter.setEnabled(checkRoleFilter.getModelObject()); + filterContainer.add(roleFilter); + + checkUserFilter.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + userFilter.setEnabled(checkUserFilter.getModelObject()); + target.add(filterContainer); + } + }); + + checkRoleFilter.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + roleFilter.setEnabled(checkRoleFilter.getModelObject()); + target.add(filterContainer); + } + }); + + profile.add(filterContainer); + } + + @Override + public void submitAction(final SchedTaskTO taskTO) { + setFilters((PushTaskTO) taskTO); + if (taskTO.getKey() > 0) { + taskRestClient.updateSchedTask((PushTaskTO) taskTO); + } else { + taskRestClient.createSchedTask((PushTaskTO) taskTO); + } + } + + private void setFilters(final PushTaskTO pushTaskTO) { + // set user filter if enabled + pushTaskTO.setUserFilter(checkUserFilter.getModelObject() ? userFilter.buildFIQL() : null); + // set role filter if enabled + pushTaskTO.setRoleFilter(checkRoleFilter.getModelObject() ? roleFilter.buildFIQL() : null); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java new file mode 100644 index 0000000..c6b57d2 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java @@ -0,0 +1,73 @@ +/* + * 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.pages; + +import java.util.Arrays; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; +import org.apache.syncope.common.lib.types.ReportExecExportFormat; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.form.IChoiceRenderer; +import org.apache.wicket.model.Model; + +public class ReportExecResultDownloadModalPage extends BaseModalPage { + + private static final long serialVersionUID = 3163146190501510888L; + + public ReportExecResultDownloadModalPage(final ModalWindow window, final PageReference callerPageRef) { + + final AjaxDropDownChoicePanel<ReportExecExportFormat> format = + new AjaxDropDownChoicePanel<>("format", "format", new Model<ReportExecExportFormat>()); + + format.setChoices(Arrays.asList(ReportExecExportFormat.values())); + + format.setChoiceRenderer(new IChoiceRenderer<ReportExecExportFormat>() { + + private static final long serialVersionUID = -3941271550163141339L; + + @Override + public Object getDisplayValue(final ReportExecExportFormat object) { + return object.name(); + } + + @Override + public String getIdValue(final ReportExecExportFormat object, final int index) { + + return object.name(); + } + }); + + format.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + format.getField(); + + ((ReportModalPage) callerPageRef.getPage()).setExportFormat(format.getField().getModelObject()); + window.close(target); + } + }); + add(format); + } +}
