Search in sources :

Example 6 with ActionLink

use of org.apache.syncope.client.console.wicket.markup.html.form.ActionLink in project syncope by apache.

the class UserDirectoryPanel method getActions.

@Override
public ActionsPanel<UserTO> getActions(final IModel<UserTO> model) {
    final ActionsPanel<UserTO> panel = super.getActions(model);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new UserWrapper(new UserRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionType.EDIT, StringUtils.join(new String[] { StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE }, ",")).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            UserTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            clone.setUsername(model.getObject().getUsername() + "_clone");
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new UserWrapper(clone), target));
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.CLONE, StandardEntitlement.USER_CREATE).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                UserRestClient.class.cast(restClient).mustChangePassword(model.getObject().getETagValue(), !model.getObject().isMustChangePassword(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While actioning object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionType.MUSTCHANGEPASSWORD, StandardEntitlement.USER_UPDATE).setRealm(realm);
    if (wizardInModal) {
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -4875218360625971340L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                displayAttributeModal.setFormModel(formModel);
                target.add(displayAttributeModal.setContent(new ChangePasswordModal(displayAttributeModal, pageRef, new UserWrapper(model.getObject()))));
                displayAttributeModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                displayAttributeModal.show(true);
            }
        }, ActionType.PASSWORD_MANAGEMENT, StandardEntitlement.USER_UPDATE).setRealm(realm);
        if (SyncopeConsoleSession.get().getPlatformInfo().isPwdResetAllowed() && !SyncopeConsoleSession.get().getPlatformInfo().isPwdResetRequiringSecurityQuestions()) {
            panel.add(new ActionLink<UserTO>() {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                    try {
                        SyncopeConsoleSession.get().getAnonymousClient().getService(UserSelfService.class).requestPasswordReset(model.getObject().getUsername(), null);
                        SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                        target.add(container);
                    } catch (Exception e) {
                        LOG.error("While actioning object {}", model.getObject().getKey(), e);
                        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }, ActionType.REQUEST_PASSWORD_RESET, StandardEntitlement.USER_UPDATE).setRealm(realm);
        }
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", true)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.ENABLE, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
                utilityModal.show(true);
            }
        }, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.notification.tasks", model));
                utilityModal.show(true);
                target.add(utilityModal);
            }
        }, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
    }
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While deleting object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.DELETE, StandardEntitlement.USER_DELETE, true).setRealm(realm);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) AnyWrapper(org.apache.syncope.client.console.wizards.any.AnyWrapper) NotificationTasks(org.apache.syncope.client.console.notifications.NotificationTasks) UserWrapper(org.apache.syncope.client.console.wizards.any.UserWrapper) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyStatusModal(org.apache.syncope.client.console.status.AnyStatusModal) AnyPropagationTasks(org.apache.syncope.client.console.tasks.AnyPropagationTasks) UserTO(org.apache.syncope.common.lib.to.UserTO) ChangePasswordModal(org.apache.syncope.client.console.status.ChangePasswordModal) StringResourceModel(org.apache.wicket.model.StringResourceModel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 7 with ActionLink

use of org.apache.syncope.client.console.wicket.markup.html.form.ActionLink in project syncope by apache.

the class Relationships method getViewFragment.

private Fragment getViewFragment() {
    final Map<String, List<RelationshipTO>> relationships = new HashMap<>();
    addRelationship(relationships, getCurrentRelationships().toArray(new RelationshipTO[] {}));
    final Fragment viewFragment = new Fragment("relationships", "viewFragment", this);
    viewFragment.setOutputMarkupId(true);
    viewFragment.add(new Accordion("relationships", relationships.keySet().stream().map(relationship -> {
        return new AbstractTab(new ResourceModel("relationship", relationship)) {

            private static final long serialVersionUID = 1037272333056449378L;

            @Override
            public Panel getPanel(final String panelId) {
                return new ListViewPanel.Builder<>(RelationshipTO.class, pageRef).setItems(relationships.get(relationship)).includes("otherEndType", "otherEndKey").addAction(new ActionLink<RelationshipTO>() {

                    private static final long serialVersionUID = -6847033126124401556L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RelationshipTO modelObject) {
                        removeRelationships(relationships, modelObject);
                        send(Relationships.this, Broadcast.DEPTH, new ListViewReload<>(target));
                    }
                }, ActionType.DELETE, AnyEntitlement.UPDATE.getFor(anyTO.getType()), true).build(panelId);
            }
        };
    }).collect(Collectors.toList())) {

        private static final long serialVersionUID = 1037272333056449379L;

        @Override
        public void renderHead(final IHeaderResponse response) {
            super.renderHead(response);
            if (relationships.isEmpty()) {
                response.render(OnDomReadyHeaderItem.forScript(String.format("$('#emptyPlaceholder').append(\"%s\")", getString("relationships.empty.list"))));
            }
        }
    });
    final ActionsPanel<RelationshipTO> panel = new ActionsPanel<>("actions", null);
    viewFragment.add(panel);
    panel.add(new ActionLink<RelationshipTO>() {

        private static final long serialVersionUID = 3257738274365467945L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RelationshipTO ignore) {
            Fragment addFragment = new Fragment("relationships", "addFragment", Relationships.this);
            addOrReplace(addFragment);
            addFragment.add(new Specification().setRenderBodyOnly(true));
            target.add(Relationships.this);
        }
    }, ActionType.CREATE, AnyEntitlement.UPDATE.getFor(anyTO.getType())).hideLabel();
    return viewFragment;
}
Also used : Arrays(java.util.Arrays) SearchClausePanel(org.apache.syncope.client.console.panels.search.SearchClausePanel) StringUtils(org.apache.commons.lang3.StringUtils) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) EntityTO(org.apache.syncope.common.lib.to.EntityTO) ICondition(org.apache.wicket.extensions.wizard.WizardModel.ICondition) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) IndicatorAjaxFormComponentUpdatingBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ListModel(org.apache.wicket.model.util.ListModel) Component(org.apache.wicket.Component) ListViewReload(org.apache.syncope.client.console.panels.ListViewPanel.ListViewReload) PageReference(org.apache.wicket.PageReference) SearchUtils(org.apache.syncope.client.console.panels.search.SearchUtils) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) Collectors(java.util.stream.Collectors) LabelInfo(org.apache.syncope.client.console.wicket.ajax.markup.html.LabelInfo) List(java.util.List) AnyDirectoryPanel(org.apache.syncope.client.console.panels.AnyDirectoryPanel) PropertyModel(org.apache.wicket.model.PropertyModel) AnySelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) AnyObjectSelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnyObjectSelectionDirectoryPanel) ResourceModel(org.apache.wicket.model.ResourceModel) Broadcast(org.apache.wicket.event.Broadcast) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink) WizardStep(org.apache.wicket.extensions.wizard.WizardStep) Constants(org.apache.syncope.client.console.commons.Constants) ActionType(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink.ActionType) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) AnyObjectSearchPanel(org.apache.syncope.client.console.panels.search.AnyObjectSearchPanel) ArrayList(java.util.ArrayList) AnyTypeClassRestClient(org.apache.syncope.client.console.rest.AnyTypeClassRestClient) IWizard(org.apache.wicket.extensions.wizard.IWizard) Fragment(org.apache.wicket.markup.html.panel.Fragment) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) Accordion(org.apache.syncope.client.console.wicket.markup.html.bootstrap.tabs.Accordion) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) RelationshipTypeRestClient(org.apache.syncope.client.console.rest.RelationshipTypeRestClient) Panel(org.apache.wicket.markup.html.panel.Panel) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) OnDomReadyHeaderItem(org.apache.wicket.markup.head.OnDomReadyHeaderItem) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Collections(java.util.Collections) IEvent(org.apache.wicket.event.IEvent) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) HashMap(java.util.HashMap) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SearchClausePanel(org.apache.syncope.client.console.panels.search.SearchClausePanel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) AnyDirectoryPanel(org.apache.syncope.client.console.panels.AnyDirectoryPanel) AnySelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) AnyObjectSelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnyObjectSelectionDirectoryPanel) AnyObjectSearchPanel(org.apache.syncope.client.console.panels.search.AnyObjectSearchPanel) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) Panel(org.apache.wicket.markup.html.panel.Panel) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) ListViewReload(org.apache.syncope.client.console.panels.ListViewPanel.ListViewReload) Accordion(org.apache.syncope.client.console.wicket.markup.html.bootstrap.tabs.Accordion) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) ResourceModel(org.apache.wicket.model.ResourceModel) List(java.util.List) ArrayList(java.util.ArrayList) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 8 with ActionLink

use of org.apache.syncope.client.console.wicket.markup.html.form.ActionLink in project syncope by apache.

the class StatusPanel method init.

private void init(final AnyTO any, final IModel<List<StatusBean>> model, final List<Pair<ConnObjectTO, ConnObjectWrapper>> connObjects, final PageReference pageRef, final boolean enableConnObjectLink) {
    final List<StatusBean> statusBeans = new ArrayList<>(connObjects.size() + 1);
    initialStatusBeanMap = new LinkedHashMap<>(connObjects.size() + 1);
    final StatusBean syncope = new StatusBean(any, Constants.SYNCOPE);
    if (any instanceof UserTO) {
        syncope.setConnObjectLink(((UserTO) any).getUsername());
        Status syncopeStatus = Status.UNDEFINED;
        if (((UserTO) any).getStatus() != null) {
            try {
                syncopeStatus = Status.valueOf(((UserTO) any).getStatus().toUpperCase());
            } catch (IllegalArgumentException e) {
                LOG.warn("Unexpected status found: {}", ((UserTO) any).getStatus(), e);
            }
        }
        syncope.setStatus(syncopeStatus);
    } else if (any instanceof GroupTO) {
        syncope.setConnObjectLink(((GroupTO) any).getName());
        syncope.setStatus(Status.ACTIVE);
    }
    statusBeans.add(syncope);
    initialStatusBeanMap.put(syncope.getResource(), syncope);
    connObjects.forEach(pair -> {
        ConnObjectWrapper entry = pair.getRight();
        final StatusBean statusBean = statusUtils.getStatusBean(entry.getAny(), entry.getResourceName(), entry.getConnObjectTO(), any instanceof GroupTO);
        initialStatusBeanMap.put(entry.getResourceName(), statusBean);
        statusBeans.add(statusBean);
    });
    final MultilevelPanel mlp = new MultilevelPanel("resources");
    add(mlp);
    ListViewPanel.Builder<StatusBean> builder = new ListViewPanel.Builder<StatusBean>(StatusBean.class, pageRef) {

        private static final long serialVersionUID = -6809736686861678498L;

        @Override
        protected Component getValueComponent(final String key, final StatusBean bean) {
            if ("status".equalsIgnoreCase(key)) {
                return StatusUtils.getStatusImagePanel("field", bean.getStatus());
            } else {
                return super.getValueComponent(key, bean);
            }
        }
    };
    builder.setModel(model);
    builder.setItems(statusBeans);
    builder.includes("resource", "connObjectLink", "status");
    builder.withChecks(ListViewPanel.CheckAvailability.NONE);
    builder.setReuseItem(false);
    final ActionLink<StatusBean> connObjectLink = new ActionLink<StatusBean>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        protected boolean statusCondition(final StatusBean bean) {
            final Pair<ConnObjectTO, ConnObjectTO> pair = getConnObjectTO(bean.getKey(), bean.getResource(), connObjects);
            return pair != null && pair.getRight() != null;
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final StatusBean bean) {
            mlp.next(bean.getResource(), new RemoteAnyPanel(bean, connObjects), target);
        }
    };
    if (!enableConnObjectLink) {
        connObjectLink.disable();
    }
    builder.addAction(connObjectLink, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
    listViewPanel = ListViewPanel.class.cast(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
    mlp.setFirstLevel(listViewPanel);
}
Also used : Status(org.apache.syncope.client.console.commons.status.Status) ArrayList(java.util.ArrayList) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) MultilevelPanel(org.apache.syncope.client.console.panels.MultilevelPanel) StatusBean(org.apache.syncope.client.console.commons.status.StatusBean) UserTO(org.apache.syncope.common.lib.to.UserTO) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ConnObjectWrapper(org.apache.syncope.client.console.commons.status.ConnObjectWrapper) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Aggregations

ActionLink (org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)8 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)8 StringResourceModel (org.apache.wicket.model.StringResourceModel)6 ResourceModel (org.apache.wicket.model.ResourceModel)4 Serializable (java.io.Serializable)3 NotificationTasks (org.apache.syncope.client.console.notifications.NotificationTasks)3 AnyStatusModal (org.apache.syncope.client.console.status.AnyStatusModal)3 AnyPropagationTasks (org.apache.syncope.client.console.tasks.AnyPropagationTasks)3 ArrayList (java.util.ArrayList)2 ListViewPanel (org.apache.syncope.client.console.panels.ListViewPanel)2 AjaxWizard (org.apache.syncope.client.console.wizards.AjaxWizard)2 AnyWrapper (org.apache.syncope.client.console.wizards.any.AnyWrapper)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1