Search in sources :

Example 1 with Attr

use of org.apache.syncope.common.lib.Attr in project syncope by apache.

the class LinkedAccountPlainAttrsPanel method setAttrs.

@Override
protected void setAttrs() {
    List<Attr> attrs = new ArrayList<>();
    List<PlainSchemaTO> notReadonlyValues = schemas.values().stream().filter(schema -> checkIsReadonlyAttr(schema.getKey())).collect(Collectors.toList());
    setFixedAttr(notReadonlyValues);
    Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(fixedAttrs);
    attrs.addAll(notReadonlyValues.stream().map(schema -> {
        Attr attrTO = new Attr();
        attrTO.setSchema(schema.getKey());
        if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) {
            attrTO.getValues().add("");
        } else {
            attrTO = attrMap.get(schema.getKey());
        }
        return attrTO;
    }).collect(Collectors.toList()));
    fixedAttrs.clear();
    fixedAttrs.addAll(attrs);
}
Also used : AbstractFieldPanel(org.apache.syncope.client.ui.commons.markup.html.form.AbstractFieldPanel) Accordion(org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion) Attr(org.apache.syncope.common.lib.Attr) LinkedAccountPlainAttrProperty(org.apache.syncope.client.console.commons.LinkedAccountPlainAttrProperty) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) AnyTO(org.apache.syncope.common.lib.to.AnyTO) CheckBox(org.apache.wicket.markup.html.form.CheckBox) FormComponent(org.apache.wicket.markup.html.form.FormComponent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) Map(java.util.Map) Constants(org.apache.syncope.client.ui.commons.Constants) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) BootstrapToggle(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle) ComponentTag(org.apache.wicket.markup.ComponentTag) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) EntityWrapper(org.apache.syncope.client.ui.commons.wizards.any.EntityWrapper) ListItem(org.apache.wicket.markup.html.list.ListItem) Collection(java.util.Collection) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) Model(org.apache.wicket.model.Model) Set(java.util.Set) IndicatorAjaxFormComponentUpdatingBehavior(org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior) SchemaType(org.apache.syncope.common.lib.types.SchemaType) FieldPanel(org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel) Collectors(java.util.stream.Collectors) List(java.util.List) LinkedAccountTO(org.apache.syncope.common.lib.to.LinkedAccountTO) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PropertyModel(org.apache.wicket.model.PropertyModel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) BootstrapToggleConfig(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig) UserTO(org.apache.syncope.common.lib.to.UserTO) AjaxWizard(org.apache.syncope.client.ui.commons.wizards.AjaxWizard) ResourceModel(org.apache.wicket.model.ResourceModel) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) ArrayList(java.util.ArrayList) Attr(org.apache.syncope.common.lib.Attr)

Example 2 with Attr

use of org.apache.syncope.common.lib.Attr in project syncope by apache.

the class AnyWizardBuilder method fixPlainAndVirAttrs.

@Override
protected void fixPlainAndVirAttrs(final AnyTO updated, final AnyTO original) {
    // form layout, which might have not included some plain or virtual attributes
    for (Attr plainAttr : original.getPlainAttrs()) {
        if (updated.getPlainAttr(plainAttr.getSchema()).isEmpty()) {
            updated.getPlainAttrs().add(plainAttr);
        }
    }
    for (Attr virAttr : original.getVirAttrs()) {
        if (updated.getVirAttr(virAttr.getSchema()).isEmpty()) {
            updated.getVirAttrs().add(virAttr);
        }
    }
    if (updated instanceof GroupableRelatableTO && original instanceof GroupableRelatableTO) {
        GroupableRelatableTO.class.cast(original).getMemberships().forEach(oMemb -> GroupableRelatableTO.class.cast(updated).getMembership(oMemb.getGroupKey()).ifPresent(uMemb -> {
            oMemb.getPlainAttrs().stream().filter(attr -> uMemb.getPlainAttr(attr.getSchema()).isEmpty()).forEach(attr -> uMemb.getPlainAttrs().add(attr));
            oMemb.getVirAttrs().stream().filter(attr -> uMemb.getVirAttr(attr.getSchema()).isEmpty()).forEach(attr -> uMemb.getVirAttrs().add(attr));
        }));
    }
    // remove from the updated object any plain or virtual attribute without values, thus triggering for removal in
    // the generated patch
    updated.getPlainAttrs().removeIf(attr -> attr.getValues().isEmpty());
    updated.getVirAttrs().removeIf(attr -> attr.getValues().isEmpty());
    if (updated instanceof GroupableRelatableTO) {
        GroupableRelatableTO.class.cast(updated).getMemberships().forEach(memb -> {
            memb.getPlainAttrs().removeIf(attr -> attr.getValues().isEmpty());
            memb.getVirAttrs().removeIf(attr -> attr.getValues().isEmpty());
        });
    }
}
Also used : AnyForm(org.apache.syncope.client.ui.commons.wizards.any.AnyForm) UserWrapper(org.apache.syncope.client.ui.commons.wizards.any.UserWrapper) Attr(org.apache.syncope.common.lib.Attr) AnyObjectFormLayoutInfo(org.apache.syncope.client.console.layout.AnyObjectFormLayoutInfo) AbstractAnyWizardBuilder(org.apache.syncope.client.ui.commons.wizards.any.AbstractAnyWizardBuilder) AnyWrapper(org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper) GroupFormLayoutInfo(org.apache.syncope.client.console.layout.GroupFormLayoutInfo) AnyTO(org.apache.syncope.common.lib.to.AnyTO) Callable(java.util.concurrent.Callable) SyncopeConsoleSession(org.apache.syncope.client.console.SyncopeConsoleSession) PageReference(org.apache.wicket.PageReference) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Serializable(java.io.Serializable) AbstractAnyFormLayout(org.apache.syncope.client.ui.commons.layout.AbstractAnyFormLayout) List(java.util.List) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) UserFormLayoutInfo(org.apache.syncope.client.console.layout.UserFormLayoutInfo) WizardModel(org.apache.wicket.extensions.wizard.WizardModel) SyncopeWebApplication(org.apache.syncope.client.console.SyncopeWebApplication) Optional(java.util.Optional) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) AjaxWizard(org.apache.syncope.client.ui.commons.wizards.AjaxWizard) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) Attr(org.apache.syncope.common.lib.Attr)

Example 3 with Attr

use of org.apache.syncope.common.lib.Attr in project syncope by apache.

the class PlainAttrs method setAttrs.

@Override
protected void setAttrs() {
    Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());
    List<Attr> attrs = schemas.values().stream().map(schema -> {
        Attr attr = new Attr();
        attr.setSchema(schema.getKey());
        if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) {
            attr.getValues().add("");
        } else {
            attr = attrMap.get(schema.getKey());
        }
        return attr;
    }).collect(Collectors.toList());
    anyTO.getPlainAttrs().clear();
    anyTO.getPlainAttrs().addAll(attrs);
}
Also used : Accordion(org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion) UserWrapper(org.apache.syncope.client.ui.commons.wizards.any.UserWrapper) Attr(org.apache.syncope.common.lib.Attr) StringResourceModel(org.apache.wicket.model.StringResourceModel) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) Attributable(org.apache.syncope.common.lib.Attributable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) Map(java.util.Map) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) IModel(org.apache.wicket.model.IModel) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ListView(org.apache.wicket.markup.html.list.ListView) ListModel(org.apache.wicket.model.util.ListModel) ListItem(org.apache.wicket.markup.html.list.ListItem) AnyWrapper(org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) Model(org.apache.wicket.model.Model) SchemaType(org.apache.syncope.common.lib.types.SchemaType) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) List(java.util.List) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxWizard(org.apache.syncope.client.ui.commons.wizards.AjaxWizard) UserTO(org.apache.syncope.common.lib.to.UserTO) ResourceModel(org.apache.wicket.model.ResourceModel) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) Attr(org.apache.syncope.common.lib.Attr)

Example 4 with Attr

use of org.apache.syncope.common.lib.Attr in project syncope by apache.

the class PlainAttrs method setAttrs.

@Override
protected void setAttrs(final MembershipTO membershipTO) {
    Map<String, Attr> attrMap = GroupableRelatableTO.class.cast(anyTO).getMembership(membershipTO.getGroupKey()).isPresent() ? EntityTOUtils.buildAttrMap(GroupableRelatableTO.class.cast(anyTO).getMembership(membershipTO.getGroupKey()).get().getPlainAttrs()) : new HashMap<>();
    List<Attr> attrs = membershipSchemas.get(membershipTO.getGroupKey()).values().stream().map(schema -> {
        Attr attr = new Attr();
        attr.setSchema(schema.getKey());
        if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) {
            attr.getValues().add(StringUtils.EMPTY);
        } else {
            attr.getValues().addAll(attrMap.get(schema.getKey()).getValues());
        }
        return attr;
    }).collect(Collectors.toList());
    membershipTO.getPlainAttrs().clear();
    membershipTO.getPlainAttrs().addAll(attrs);
}
Also used : Accordion(org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion) UserWrapper(org.apache.syncope.client.ui.commons.wizards.any.UserWrapper) Attr(org.apache.syncope.common.lib.Attr) StringResourceModel(org.apache.wicket.model.StringResourceModel) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) Attributable(org.apache.syncope.common.lib.Attributable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) Map(java.util.Map) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) IModel(org.apache.wicket.model.IModel) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ListView(org.apache.wicket.markup.html.list.ListView) ListModel(org.apache.wicket.model.util.ListModel) ListItem(org.apache.wicket.markup.html.list.ListItem) AnyWrapper(org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) Model(org.apache.wicket.model.Model) SchemaType(org.apache.syncope.common.lib.types.SchemaType) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) List(java.util.List) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxWizard(org.apache.syncope.client.ui.commons.wizards.AjaxWizard) UserTO(org.apache.syncope.common.lib.to.UserTO) ResourceModel(org.apache.wicket.model.ResourceModel) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) Attr(org.apache.syncope.common.lib.Attr)

Example 5 with Attr

use of org.apache.syncope.common.lib.Attr in project syncope by apache.

the class DerAttrs method setAttrs.

@Override
protected void setAttrs(final MembershipTO membershipTO) {
    List<Attr> attrs = new ArrayList<>();
    final Map<String, Attr> attrMap;
    if (GroupableRelatableTO.class.cast(anyTO).getMembership(membershipTO.getGroupKey()).isPresent()) {
        attrMap = EntityTOUtils.buildAttrMap(GroupableRelatableTO.class.cast(anyTO).getMembership(membershipTO.getGroupKey()).get().getDerAttrs());
    } else {
        attrMap = new HashMap<>();
    }
    membershipSchemas.get(membershipTO.getGroupKey()).values().forEach(schema -> {
        Attr attrTO = new Attr();
        attrTO.setSchema(schema.getKey());
        if (attrMap.containsKey(schema.getKey())) {
            attrTO.getValues().addAll(attrMap.get(schema.getKey()).getValues());
        }
        attrs.add(attrTO);
    });
    membershipTO.getDerAttrs().clear();
    membershipTO.getDerAttrs().addAll(attrs);
}
Also used : GroupableRelatableTO(org.apache.syncope.common.lib.to.GroupableRelatableTO) ArrayList(java.util.ArrayList) Attr(org.apache.syncope.common.lib.Attr)

Aggregations

Attr (org.apache.syncope.common.lib.Attr)66 UserTO (org.apache.syncope.common.lib.to.UserTO)30 ArrayList (java.util.ArrayList)25 Test (org.junit.jupiter.api.Test)24 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)20 UserCR (org.apache.syncope.common.lib.request.UserCR)20 List (java.util.List)19 Optional (java.util.Optional)18 Map (java.util.Map)17 UserUR (org.apache.syncope.common.lib.request.UserUR)16 Set (java.util.Set)15 Pair (org.apache.commons.lang3.tuple.Pair)15 StringUtils (org.apache.commons.lang3.StringUtils)14 AnyTO (org.apache.syncope.common.lib.to.AnyTO)14 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)14 Collectors (java.util.stream.Collectors)13 GroupTO (org.apache.syncope.common.lib.to.GroupTO)13 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)12 ResourceOperation (org.apache.syncope.common.lib.types.ResourceOperation)11