Search in sources :

Example 16 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class ProvisionAuxClassesPanel method onBeforeRender.

@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    IModel<List<String>> model;
    List<String> choices;
    if (provision == null) {
        model = new ListModel<>(Collections.<String>emptyList());
        choices = Collections.emptyList();
    } else {
        model = new PropertyModel<>(provision, "auxClasses");
        choices = new ArrayList<>();
        AnyTypeTO anyType = null;
        try {
            anyType = new AnyTypeRestClient().read(provision.getAnyType());
        } catch (Exception e) {
            LOG.error("Could not read AnyType {}", provision.getAnyType(), e);
        }
        if (anyType != null) {
            for (AnyTypeClassTO aux : new AnyTypeClassRestClient().list()) {
                if (!anyType.getClasses().contains(aux.getKey())) {
                    choices.add(aux.getKey());
                }
            }
        }
    }
    addOrReplace(new AjaxPalettePanel.Builder<String>().build("auxClasses", model, new ListModel<>(choices)).hideLabel().setOutputMarkupId(true).setEnabled(provision != null));
}
Also used : AjaxPalettePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxPalettePanel) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) ArrayList(java.util.ArrayList) List(java.util.List) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) AnyTypeClassRestClient(org.apache.syncope.client.console.rest.AnyTypeClassRestClient)

Example 17 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class RoleDirectoryPanel method getActions.

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

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RoleTO ignore) {
            send(RoleDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new RoleWrapper(new RoleRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionLink.ActionType.EDIT, StandardEntitlement.ROLE_READ);
    panel.add(new ActionLink<RoleTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RoleTO ignore) {
            final RoleTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            send(RoleDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new RoleWrapper(clone), target));
        }
    }, ActionLink.ActionType.CLONE, StandardEntitlement.ROLE_CREATE);
    panel.add(new ActionLink<RoleTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RoleTO ignore) {
            final String query = SyncopeClient.getUserSearchConditionBuilder().and(SyncopeClient.getUserSearchConditionBuilder().inRoles(model.getObject().getKey()), SyncopeClient.getUserSearchConditionBuilder().is("key").notNullValue()).query();
            final AnyTypeRestClient typeRestClient = new AnyTypeRestClient();
            final AnyTypeClassRestClient classRestClient = new AnyTypeClassRestClient();
            final AnyTypeTO anyTypeTO = typeRestClient.read(AnyTypeKind.USER.name());
            ModalPanel panel = new AnyPanel(BaseModal.CONTENT_ID, anyTypeTO, null, null, false, pageRef) {

                private static final long serialVersionUID = -7514498203393023415L;

                @Override
                protected Panel getDirectoryPanel(final String id) {
                    final Panel panel = new UserDirectoryPanel.Builder(classRestClient.list(anyTypeTO.getClasses()), anyTypeTO.getKey(), pageRef).setRealm("/").setFiltered(true).setFiql(query).disableCheckBoxes().addNewItemPanelBuilder(FormLayoutInfoUtils.instantiate(new UserTO(), anyTypeTO.getClasses(), FormLayoutInfoUtils.fetch(typeRestClient.list()).getLeft(), pageRef), false).setWizardInModal(false).build(id);
                    MetaDataRoleAuthorizationStrategy.authorize(panel, WebPage.RENDER, StandardEntitlement.USER_SEARCH);
                    return panel;
                }
            };
            membersModal.header(new StringResourceModel("role.members", RoleDirectoryPanel.this, model));
            membersModal.setContent(panel);
            membersModal.show(true);
            target.add(membersModal);
        }
    }, ActionLink.ActionType.MEMBERS, StandardEntitlement.USER_SEARCH);
    panel.add(new ActionLink<RoleTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RoleTO ignore) {
            final ConsoleLayoutInfo info = new ConsoleLayoutInfo(model.getObject().getKey());
            info.setContent(restClient.readConsoleLayoutInfo(model.getObject().getKey()));
            utilityModal.header(new ResourceModel("console.layout.info", "JSON Content"));
            utilityModal.setContent(new JsonEditorPanel(utilityModal, new PropertyModel<String>(info, "content"), false, pageRef) {

                private static final long serialVersionUID = -8927036362466990179L;

                @Override
                public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                    try {
                        restClient.setConsoleLayoutInfo(info.getKey(), info.getContent());
                        SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                        modal.show(false);
                        modal.close(target);
                    } catch (Exception e) {
                        LOG.error("While updating console layout info for role {}", info.getKey(), e);
                        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            });
            utilityModal.show(true);
            target.add(utilityModal);
        }
    }, ActionLink.ActionType.LAYOUT_EDIT, StandardEntitlement.ROLE_UPDATE);
    panel.add(new ActionLink<RoleTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final RoleTO ignore) {
            try {
                restClient.delete(model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException 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);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.ROLE_DELETE, true);
    return panel;
}
Also used : Form(org.apache.wicket.markup.html.form.Form) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) RoleRestClient(org.apache.syncope.client.console.rest.RoleRestClient) ConsoleLayoutInfo(org.apache.syncope.client.console.layout.ConsoleLayoutInfo) StringResourceModel(org.apache.wicket.model.StringResourceModel) ResourceModel(org.apache.wicket.model.ResourceModel) AnyTypeClassRestClient(org.apache.syncope.client.console.rest.AnyTypeClassRestClient) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RoleTO(org.apache.syncope.common.lib.to.RoleTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) JsonEditorPanel(org.apache.syncope.client.console.wicket.markup.html.form.JsonEditorPanel) Panel(org.apache.wicket.markup.html.panel.Panel) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) UserTO(org.apache.syncope.common.lib.to.UserTO) RoleWrapper(org.apache.syncope.client.console.wizards.role.RoleWrapper) JsonEditorPanel(org.apache.syncope.client.console.wicket.markup.html.form.JsonEditorPanel)

Example 18 with AnyTypeTO

use of org.apache.syncope.common.lib.to.AnyTypeTO in project syncope by apache.

the class ResourceMappingPanel method setAttrNames.

@Override
protected void setAttrNames(final AjaxTextFieldPanel toBeUpdated) {
    toBeUpdated.setRequired(true);
    toBeUpdated.setEnabled(true);
    Set<String> choices = new HashSet<>();
    if (SyncopeConstants.REALM_ANYTYPE.equals(provision.getAnyType())) {
        choices.add("key");
        choices.add("name");
        choices.add("fullpath");
    } else {
        AnyTypeTO anyType = null;
        try {
            anyType = anyTypeRestClient.read(provision.getAnyType());
        } catch (Exception e) {
            LOG.error("Could not read AnyType {}", provision.getAnyType(), e);
        }
        List<AnyTypeClassTO> anyTypeClassTOs = new ArrayList<>();
        if (anyType != null) {
            try {
                anyTypeClassTOs.addAll(anyTypeClassRestClient.list(anyType.getClasses()));
            } catch (Exception e) {
                LOG.error("Could not read AnyType classes for {}", anyType.getClasses(), e);
            }
        }
        for (String auxClass : provision.getAuxClasses()) {
            try {
                anyTypeClassTOs.add(anyTypeClassRestClient.read(auxClass));
            } catch (Exception e) {
                LOG.error("Could not read AnyTypeClass for {}", auxClass, e);
            }
        }
        switch(provision.getAnyType()) {
            case "USER":
                choices.addAll(USER_FIELD_NAMES);
                break;
            case "GROUP":
                choices.addAll(GROUP_FIELD_NAMES);
                break;
            default:
                choices.addAll(ANY_OBJECT_FIELD_NAMES);
        }
        for (AnyTypeClassTO anyTypeClassTO : anyTypeClassTOs) {
            choices.addAll(anyTypeClassTO.getPlainSchemas());
            choices.addAll(anyTypeClassTO.getDerSchemas());
            choices.addAll(anyTypeClassTO.getVirSchemas());
        }
    }
    final List<String> names = new ArrayList<>(choices);
    Collections.sort(names);
    toBeUpdated.setChoices(names);
}
Also used : ArrayList(java.util.ArrayList) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) HashSet(java.util.HashSet)

Aggregations

AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)18 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 Test (org.junit.jupiter.api.Test)9 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)6 ArrayList (java.util.ArrayList)5 Response (javax.ws.rs.core.Response)4 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)4 EntityTO (org.apache.syncope.common.lib.to.EntityTO)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 AnyTypeClassRestClient (org.apache.syncope.client.console.rest.AnyTypeClassRestClient)2 AnyTypeRestClient (org.apache.syncope.client.console.rest.AnyTypeRestClient)2 ActionsPanel (org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel)2 WizardMgtPanel (org.apache.syncope.client.console.wizards.WizardMgtPanel)2 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)2 RoleTO (org.apache.syncope.common.lib.to.RoleTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)2