You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/02/05 17:01:10 UTC
[39/52] syncope git commit: [SYNCOPE-620] Console (JAR) in,
now time for console-reference
http://git-wip-us.apache.org/repos/asf/syncope/blob/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PolicyModalPage.java
new file mode 100644
index 0000000..70b646c
--- /dev/null
+++ b/syncope620/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<Void>(FORM);
+ form.setOutputMarkupId(true);
+ add(form);
+
+ final AjaxTextFieldPanel policyid = new AjaxTextFieldPanel("id", "id",
+ new PropertyModel<String>(policyTO, "id"));
+ 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<PolicyType>("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<IColumn<String, String>>();
+ 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<String>(object);
+ }
+ };
+ final AjaxFallbackDefaultDataTable<String, String> resources =
+ new AjaxFallbackDefaultDataTable<String, String>("resources", resColumns, resDataProvider, 10);
+ form.add(resources);
+
+ List<IColumn<RoleTO, String>> roleColumns = new ArrayList<IColumn<RoleTO, String>>();
+ roleColumns.add(new PropertyColumn<RoleTO, String>(new ResourceModel("id", "id"), "id", "id"));
+ 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<RoleTO>(object);
+ }
+ };
+ final AjaxFallbackDefaultDataTable<RoleTO, String> roles =
+ new AjaxFallbackDefaultDataTable<RoleTO, String>("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/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PropagationTaskModalPage.java
new file mode 100644
index 0000000..5a6779f
--- /dev/null
+++ b/syncope620/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/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java
new file mode 100644
index 0000000..c7e192f
--- /dev/null
+++ b/syncope620/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.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.SubjectId;
+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.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));
+
+ final List<IColumn<StatusBean, String>> columns = new ArrayList<IColumn<StatusBean, String>>();
+ columns.add(new PropertyColumn<StatusBean, String>(
+ new StringResourceModel("id", this, null, "Attributable id"),
+ "attributableId", "attributableId"));
+ 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<StatusBean, String>(
+ "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<T>();
+ if (UserTO.class.isAssignableFrom(typeRef)) {
+ subjects.addAll((List<T>) userRestClient.search(fiql, 1, ROWS_PER_PAGE,
+ new SortParam<String>("id", true)));
+ } else {
+ subjects.addAll((List<T>) roleRestClient.search(fiql, 1, ROWS_PER_PAGE,
+ new SortParam<String>("id", true)));
+ }
+
+ final List<ConnObjectWrapper> connObjects = statusUtils.getConnectorObjects(
+ (List<AbstractSubjectTO>) subjects, Collections.<String>singleton(resourceTO.getKey()));
+
+ final List<StatusBean> statusBeans = new ArrayList<StatusBean>(connObjects.size() + 1);
+ final LinkedHashMap<String, StatusBean> initialStatusBeanMap = new LinkedHashMap<String, StatusBean>(
+ 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<StatusBean>(table.getModelObject());
+ List<SubjectId> subjectIds = new ArrayList<SubjectId>();
+ for (StatusBean bean : beans) {
+ LOG.debug("Selected bean {}", bean);
+ subjectIds.add(AbstractWrappable.getInstance(SubjectId.class, bean.getAttributableId()));
+ }
+
+ if (beans.isEmpty()) {
+ window.close(target);
+ } else {
+ final BulkActionResult res = resourceRestClient.bulkAssociationAction(
+ resourceTO.getKey(), typeRef, type, subjectIds);
+
+ ((BasePage) pageRef.getPage()).setModalResult(true);
+
+ setResponsePage(new BulkActionResultModalPage<StatusBean, String>(
+ window, beans, columns, res, "attributableId"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/PushTaskModalPage.java
new file mode 100644
index 0000000..a799b15
--- /dev/null
+++ b/syncope620/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/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportExecResultDownloadModalPage.java
new file mode 100644
index 0000000..c6b57d2
--- /dev/null
+++ b/syncope620/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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/32707b3b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportModalPage.java
----------------------------------------------------------------------
diff --git a/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportModalPage.java b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportModalPage.java
new file mode 100644
index 0000000..ebf91bd
--- /dev/null
+++ b/syncope620/client/console/src/main/java/org/apache/syncope/client/console/pages/ReportModalPage.java
@@ -0,0 +1,640 @@
+/*
+ * 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.Iterator;
+import java.util.List;
+import org.apache.syncope.client.console.commons.Constants;
+import org.apache.syncope.client.console.commons.DateFormatROModel;
+import org.apache.syncope.client.console.commons.HttpResourceStream;
+import org.apache.syncope.client.console.commons.SortableDataProviderComparator;
+import org.apache.syncope.client.console.wicket.ajax.form.AbstractAjaxDownloadBehavior;
+import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxButton;
+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.CrontabContainer;
+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.AjaxTextFieldPanel;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.report.AbstractReportletConf;
+import org.apache.syncope.common.lib.report.ReportletConf;
+import org.apache.syncope.common.lib.to.ReportExecTO;
+import org.apache.syncope.common.lib.to.ReportTO;
+import org.apache.syncope.common.lib.types.ReportExecExportFormat;
+import org.apache.syncope.common.lib.types.ReportExecStatus;
+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.attributes.AjaxCallListener;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+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.modal.ModalWindow;
+import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable;
+import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
+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.Form;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.markup.html.form.ListChoice;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.CompoundPropertyModel;
+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.util.resource.IResourceStream;
+import org.springframework.util.StringUtils;
+
+public class ReportModalPage extends BaseModalPage {
+
+ private static final long serialVersionUID = -5747628615211127644L;
+
+ private static final String ADD_BUTTON_ID = "addButton";
+
+ private static final String EDIT_BUTTON_ID = "editButton";
+
+ private static final String REMOVE_BUTTON_ID = "removeButton";
+
+ private static final String UP_BUTTON_ID = "upButton";
+
+ private static final String DOWN_BUTTON_ID = "downButton";
+
+ private static final int EXEC_EXPORT_WIN_HEIGHT = 100;
+
+ private static final int EXEC_EXPORT_WIN_WIDTH = 400;
+
+ private static final int REPORTLET_CONF_WIN_HEIGHT = 500;
+
+ private static final int REPORTLET_CONF_WIN_WIDTH = 800;
+
+ private final ReportTO reportTO;
+
+ private final Form<ReportTO> form;
+
+ private ReportExecExportFormat exportFormat;
+
+ private long exportExecId;
+
+ private AbstractReportletConf modalReportletConf;
+
+ private String modalReportletConfOldName;
+
+ private ListChoice<AbstractReportletConf> reportlets;
+
+ public ReportModalPage(final ModalWindow window, final ReportTO reportTO, final PageReference callerPageRef) {
+ super();
+ this.reportTO = reportTO;
+
+ form = new Form<ReportTO>(FORM);
+ form.setModel(new CompoundPropertyModel<ReportTO>(reportTO));
+ add(form);
+
+ setupProfile();
+ setupExecutions();
+
+ final CrontabContainer crontab = new CrontabContainer("crontab", new PropertyModel<String>(reportTO,
+ "cronExpression"), reportTO.getCronExpression());
+ form.add(crontab);
+
+ final AjaxButton submit =
+ new ClearIndicatingAjaxButton(APPLY, new ResourceModel(APPLY), getPageReference()) {
+
+ private static final long serialVersionUID = -958724007591692537L;
+
+ @Override
+ protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) {
+ ReportTO toSubmit = (ReportTO) form.getModelObject();
+ toSubmit.setCronExpression(StringUtils.hasText(toSubmit.getCronExpression())
+ ? crontab.getCronExpression()
+ : null);
+
+ try {
+ if (toSubmit.getKey() > 0) {
+ reportRestClient.update(toSubmit);
+ } else {
+ reportRestClient.create(toSubmit);
+ }
+
+ ((BasePage) callerPageRef.getPage()).setModalResult(true);
+
+ window.close(target);
+ } catch (SyncopeClientException e) {
+ LOG.error("While creating or updating report", e);
+ error(getString(Constants.ERROR) + ": " + e.getMessage());
+ feedbackPanel.refresh(target);
+ }
+ }
+
+ @Override
+ protected void onError(final AjaxRequestTarget target, final Form<?> form) {
+ feedbackPanel.refresh(target);
+ }
+ };
+
+ if (reportTO.getKey() > 0) {
+ MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER,
+ xmlRolesReader.getEntitlement("Reports", "update"));
+ } else {
+ MetaDataRoleAuthorizationStrategy.authorize(submit, RENDER,
+ xmlRolesReader.getEntitlement("Reports", "create"));
+ }
+
+ form.add(submit);
+
+ final AjaxButton cancel =
+ new ClearIndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL), getPageReference()) {
+
+ private static final long serialVersionUID = -958724007591692537L;
+
+ @Override
+ protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) {
+ window.close(target);
+ }
+ };
+
+ cancel.setDefaultFormProcessing(false);
+ form.add(cancel);
+ }
+
+ private void setupProfile() {
+ final WebMarkupContainer profile = new WebMarkupContainer("profile");
+ profile.setOutputMarkupId(true);
+ form.add(profile);
+
+ final ModalWindow reportletConfWin = new ModalWindow("reportletConfWin");
+ reportletConfWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
+ reportletConfWin.setCookieName("reportlet-conf-win-modal");
+ reportletConfWin.setInitialHeight(REPORTLET_CONF_WIN_HEIGHT);
+ reportletConfWin.setInitialWidth(REPORTLET_CONF_WIN_WIDTH);
+ reportletConfWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
+
+ private static final long serialVersionUID = 8804221891699487139L;
+
+ @Override
+ public void onClose(final AjaxRequestTarget target) {
+ int foundIdx = -1;
+ if (modalReportletConfOldName != null) {
+ for (int i = 0; i < reportTO.getReportletConfs().size() && foundIdx == -1; i++) {
+ if (reportTO.getReportletConfs().get(i).getName().equals(modalReportletConfOldName)) {
+ foundIdx = i;
+ }
+ }
+ }
+ if (modalReportletConf != null) {
+ if (foundIdx == -1) {
+ reportTO.getReportletConfs().add(modalReportletConf);
+ } else {
+ reportTO.getReportletConfs().set(foundIdx, modalReportletConf);
+ }
+ }
+
+ target.add(reportlets);
+ }
+ });
+ add(reportletConfWin);
+
+ final Label idLabel = new Label("idLabel", new ResourceModel("id"));
+ profile.add(idLabel);
+
+ final AjaxTextFieldPanel id = new AjaxTextFieldPanel("id", getString("id"), new PropertyModel<String>(reportTO,
+ "id"));
+ id.setEnabled(false);
+ profile.add(id);
+
+ final Label nameLabel = new Label("nameLabel", new ResourceModel("name"));
+ profile.add(nameLabel);
+
+ final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(
+ reportTO, "name"));
+ profile.add(name);
+
+ final AjaxTextFieldPanel lastExec = new AjaxTextFieldPanel("lastExec", getString("lastExec"),
+ new DateFormatROModel(new PropertyModel<String>(reportTO, "lastExec")));
+ lastExec.setEnabled(false);
+ profile.add(lastExec);
+
+ final AjaxTextFieldPanel nextExec = new AjaxTextFieldPanel("nextExec", getString("nextExec"),
+ new DateFormatROModel(new PropertyModel<String>(reportTO, "nextExec")));
+ nextExec.setEnabled(false);
+ profile.add(nextExec);
+
+ reportlets = new ListChoice<AbstractReportletConf>("reportletConfs", new Model<AbstractReportletConf>(),
+ reportTO.getReportletConfs(), new IChoiceRenderer<ReportletConf>() {
+
+ private static final long serialVersionUID = 1048000918946220007L;
+
+ @Override
+ public Object getDisplayValue(final ReportletConf object) {
+ return object.getName();
+ }
+
+ @Override
+ public String getIdValue(final ReportletConf object, final int index) {
+ return object.getName();
+ }
+ }) {
+
+ private static final long serialVersionUID = 4022366881854379834L;
+
+ @Override
+ protected CharSequence getDefaultChoice(final String selectedValue) {
+ return null;
+ }
+ };
+
+ reportlets.setNullValid(true);
+ profile.add(reportlets);
+ reportlets.add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
+
+ private static final long serialVersionUID = -1107858522700306810L;
+
+ @Override
+ protected void onUpdate(final AjaxRequestTarget target) {
+ target.add(reportlets);
+ }
+ });
+
+ profile.add(new AjaxLink<Void>(ADD_BUTTON_ID) {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ reportletConfWin.setPageCreator(new ModalWindow.PageCreator() {
+
+ private static final long serialVersionUID = -7834632442532690940L;
+
+ @Override
+ public Page createPage() {
+ modalReportletConfOldName = null;
+ modalReportletConf = null;
+ return new ReportletConfModalPage(null, reportletConfWin,
+ ReportModalPage.this.getPageReference());
+ }
+ });
+ reportletConfWin.show(target);
+ }
+ });
+
+ profile.add(new AjaxLink<Void>(EDIT_BUTTON_ID) {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ if (reportlets.getModelObject() != null) {
+ reportletConfWin.setPageCreator(new ModalWindow.PageCreator() {
+
+ private static final long serialVersionUID = -7834632442532690940L;
+
+ @Override
+ public Page createPage() {
+ modalReportletConfOldName = reportlets.getModelObject().getName();
+ modalReportletConf = null;
+ return new ReportletConfModalPage(reportlets.getModelObject(), reportletConfWin,
+ ReportModalPage.this.getPageReference());
+ }
+ });
+ reportletConfWin.show(target);
+ }
+ }
+ });
+
+ profile.add(new AjaxLink<Void>(REMOVE_BUTTON_ID) {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ reportTO.getReportletConfs().remove(reportlets.getModelObject());
+ reportlets.setModelObject(null);
+ target.add(reportlets);
+ }
+
+ @Override
+ protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
+ if (reportlets.getModelObject() != null) {
+
+ super.updateAjaxAttributes(attributes);
+
+ final AjaxCallListener ajaxCallListener = new AjaxCallListener() {
+
+ private static final long serialVersionUID = 7160235486520935153L;
+
+ @Override
+ public CharSequence getPrecondition(final Component component) {
+ return "if (!confirm('" + getString("confirmDelete") + "')) {return false;}";
+ }
+ };
+ attributes.getAjaxCallListeners().add(ajaxCallListener);
+ }
+ }
+ });
+
+ profile.add(new AjaxLink<Void>(UP_BUTTON_ID) {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ if (reportlets.getModelObject() != null) {
+ moveUp(reportlets.getModelObject());
+ target.add(reportlets);
+ }
+ }
+ });
+
+ profile.add(new AjaxLink<Void>(DOWN_BUTTON_ID) {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ if (reportlets.getModelObject() != null) {
+ moveDown(reportlets.getModelObject());
+ target.add(reportlets);
+ }
+ }
+ });
+ }
+
+ private void moveUp(final AbstractReportletConf item) {
+ final List<AbstractReportletConf> list = reportTO.getReportletConfs();
+ int newPosition = list.indexOf(item) - 1;
+ if (newPosition > -1) {
+ list.remove(item);
+ list.add(newPosition, item);
+ }
+ }
+
+ private void moveDown(final AbstractReportletConf item) {
+ final List<AbstractReportletConf> list = reportTO.getReportletConfs();
+ int newPosition = list.indexOf(item) + 1;
+ if (newPosition < list.size()) {
+ list.remove(item);
+ list.add(newPosition, item);
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setupExecutions() {
+ final WebMarkupContainer executions = new WebMarkupContainer("executionContainer");
+ executions.setOutputMarkupId(true);
+ form.add(executions);
+
+ final ModalWindow reportExecMessageWin = new ModalWindow("reportExecMessageWin");
+ reportExecMessageWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
+ reportExecMessageWin.setCookieName("report-exec-message-win-modal");
+ add(reportExecMessageWin);
+
+ final ModalWindow reportExecExportWin = new ModalWindow("reportExecExportWin");
+ reportExecExportWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
+ reportExecExportWin.setCookieName("report-exec-export-win-modal");
+ reportExecExportWin.setInitialHeight(EXEC_EXPORT_WIN_HEIGHT);
+ reportExecExportWin.setInitialWidth(EXEC_EXPORT_WIN_WIDTH);
+ reportExecExportWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
+
+ private static final long serialVersionUID = 8804221891699487139L;
+
+ @Override
+ public void onClose(final AjaxRequestTarget target) {
+ AjaxExportDownloadBehavior behavior = new AjaxExportDownloadBehavior(ReportModalPage.this.exportFormat,
+ ReportModalPage.this.exportExecId);
+ executions.add(behavior);
+ behavior.initiate(target);
+ }
+ });
+ add(reportExecExportWin);
+
+ final List<IColumn> columns = new ArrayList<IColumn>();
+ columns.add(new PropertyColumn(new ResourceModel("id"), "id", "id"));
+ columns.add(new DatePropertyColumn(new ResourceModel("startDate"), "startDate", "startDate"));
+ columns.add(new DatePropertyColumn(new ResourceModel("endDate"), "endDate", "endDate"));
+ columns.add(new PropertyColumn(new ResourceModel("status"), "status", "status"));
+ columns.add(new ActionColumn<ReportExecTO, String>(new ResourceModel("actions", "")) {
+
+ private static final long serialVersionUID = 2054811145491901166L;
+
+ @Override
+ public ActionLinksPanel getActions(final String componentId, final IModel<ReportExecTO> model) {
+
+ final ReportExecTO taskExecutionTO = 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) {
+ reportExecMessageWin.setPageCreator(new ModalWindow.PageCreator() {
+
+ private static final long serialVersionUID = -7834632442532690940L;
+
+ @Override
+ public Page createPage() {
+ return new ExecMessageModalPage(model.getObject().getMessage());
+ }
+ });
+ reportExecMessageWin.show(target);
+ }
+ }, ActionLink.ActionType.EDIT, "Reports", StringUtils.hasText(model.getObject().getMessage()));
+
+ panel.add(new ActionLink() {
+
+ private static final long serialVersionUID = -3722207913631435501L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ reportExecExportWin.setPageCreator(new ModalWindow.PageCreator() {
+
+ private static final long serialVersionUID = -7834632442532690940L;
+
+ @Override
+ public Page createPage() {
+ ReportModalPage.this.exportExecId = model.getObject().getKey();
+ return new ReportExecResultDownloadModalPage(reportExecExportWin,
+ ReportModalPage.this.getPageReference());
+ }
+ });
+ reportExecExportWin.show(target);
+ }
+ }, ActionLink.ActionType.EXPORT, "Reports", ReportExecStatus.SUCCESS.name().equals(
+ model.getObject().getStatus()));
+
+ panel.add(new ActionLink() {
+
+ private static final long serialVersionUID = -3722207913631435501L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ try {
+ reportRestClient.deleteExecution(taskExecutionTO.getKey());
+
+ reportTO.getExecutions().remove(taskExecutionTO);
+
+ info(getString(Constants.OPERATION_SUCCEEDED));
+ } catch (SyncopeClientException scce) {
+ error(scce.getMessage());
+ }
+
+ feedbackPanel.refresh(target);
+ target.add(executions);
+ }
+ }, ActionLink.ActionType.DELETE, "Reports");
+
+ return panel;
+ }
+
+ @Override
+ public Component getHeader(final String componentId) {
+ final ActionLinksPanel panel = new ActionLinksPanel(componentId, new Model(), getPageReference());
+
+ panel.add(new ActionLink() {
+
+ private static final long serialVersionUID = -7978723352517770644L;
+
+ @Override
+ public void onClick(final AjaxRequestTarget target) {
+ if (target != null) {
+ final ReportTO currentReportTO = reportTO.getKey() == 0
+ ? reportTO
+ : reportRestClient.read(reportTO.getKey());
+ reportTO.getExecutions().clear();
+ reportTO.getExecutions().addAll(currentReportTO.getExecutions());
+ final AjaxFallbackDefaultDataTable currentTable =
+ new AjaxFallbackDefaultDataTable("executionsTable", columns,
+ new ReportExecutionsProvider(reportTO), 10);
+ currentTable.setOutputMarkupId(true);
+ target.add(currentTable);
+ executions.addOrReplace(currentTable);
+ }
+ }
+ }, ActionLink.ActionType.RELOAD, TASKS, "list");
+
+ return panel;
+ }
+ });
+
+ final AjaxFallbackDefaultDataTable table = new AjaxFallbackDefaultDataTable("executionsTable", columns,
+ new ReportExecutionsProvider(reportTO), 10);
+ executions.add(table);
+ }
+
+ public void setExportFormat(final ReportExecExportFormat exportFormat) {
+ this.exportFormat = exportFormat;
+ }
+
+ public void setModalReportletConf(final AbstractReportletConf modalReportletConf) {
+ this.modalReportletConf = modalReportletConf;
+ }
+
+ private static class ReportExecutionsProvider extends SortableDataProvider<ReportExecTO, String> {
+
+ private static final long serialVersionUID = 2118096121691420539L;
+
+ private final SortableDataProviderComparator<ReportExecTO> comparator;
+
+ private final ReportTO reportTO;
+
+ public ReportExecutionsProvider(final ReportTO reportTO) {
+ super();
+ this.reportTO = reportTO;
+ setSort("startDate", SortOrder.DESCENDING);
+ comparator = new SortableDataProviderComparator<ReportExecTO>(this);
+ }
+
+ @Override
+ public Iterator<ReportExecTO> iterator(final long first, final long count) {
+
+ List<ReportExecTO> list = reportTO.getExecutions();
+
+ Collections.sort(list, comparator);
+
+ return list.subList((int) first, (int) first + (int) count).iterator();
+ }
+
+ @Override
+ public long size() {
+ return reportTO.getExecutions().size();
+ }
+
+ @Override
+ public IModel<ReportExecTO> model(final ReportExecTO taskExecution) {
+
+ return new AbstractReadOnlyModel<ReportExecTO>() {
+
+ private static final long serialVersionUID = 7485475149862342421L;
+
+ @Override
+ public ReportExecTO getObject() {
+ return taskExecution;
+ }
+ };
+ }
+ }
+
+ private class AjaxExportDownloadBehavior extends AbstractAjaxDownloadBehavior {
+
+ private static final long serialVersionUID = 3109256773218160485L;
+
+ private final ReportExecExportFormat exportFormat;
+
+ private final long exportExecId;
+
+ private HttpResourceStream stream;
+
+ public AjaxExportDownloadBehavior(final ReportExecExportFormat exportFormat, final long exportExecId) {
+ super();
+ this.exportFormat = exportFormat;
+ this.exportExecId = exportExecId;
+ }
+
+ private void createResourceStream() {
+ if (stream == null) {
+ stream = new HttpResourceStream(reportRestClient.exportExecutionResult(exportExecId, exportFormat));
+ }
+ }
+
+ @Override
+ protected String getFileName() {
+ createResourceStream();
+ return stream == null
+ ? null
+ : stream.getFilename();
+ }
+
+ @Override
+ protected IResourceStream getResourceStream() {
+ createResourceStream();
+ return stream;
+ }
+ }
+}