Example usage for org.apache.commons.collections4 Transformer Transformer

List of usage examples for org.apache.commons.collections4 Transformer Transformer

Introduction

In this page you can find the example usage for org.apache.commons.collections4 Transformer Transformer.

Prototype

Transformer

Source Link

Usage

From source file:org.apache.syncope.client.console.panels.ConnectorDetailsPanel.java

private List<String> getVersions(final ConnInstanceTO connInstanceTO, final List<ConnBundleTO> bundles) {
    return new ArrayList<>(
            CollectionUtils.collect(CollectionUtils.select(bundles, new Predicate<ConnBundleTO>() {

                @Override//w  w w .  j av a2s . c o  m
                public boolean evaluate(final ConnBundleTO object) {
                    return object.getLocation().equals(connInstanceTO.getLocation())
                            && object.getBundleName().equals(connInstanceTO.getBundleName());
                }
            }), new Transformer<ConnBundleTO, String>() {

                @Override
                public String transform(final ConnBundleTO input) {
                    return input.getVersion();
                }
            }, new HashSet<String>()));
}

From source file:org.apache.syncope.client.console.panels.ConnObjects.java

public ConnObjects(final BaseModal<?> baseModal, final String resource, final PageReference pageReference) {

    super(BaseModal.CONTENT_ID);

    List<String> availableAnyTypes = CollectionUtils.collect(
            new ResourceRestClient().read(resource).getProvisions(), new Transformer<ProvisionTO, String>() {

                @Override//from   ww w  . j  a  va2  s.  c o m
                public String transform(final ProvisionTO provision) {
                    return provision.getAnyType();
                }
            }, new ArrayList<String>());

    anyTypes = new AjaxDropDownChoicePanel<>("anyTypes", "anyTypes", new Model<String>(), true);
    anyTypes.setChoices(availableAnyTypes);
    anyTypes.hideLabel();
    anyTypes.setNullValid(false);
    if (availableAnyTypes.contains(AnyTypeKind.USER.name())) {
        anyTypes.setDefaultModelObject(AnyTypeKind.USER.name());
    } else if (availableAnyTypes.contains(AnyTypeKind.GROUP.name())) {
        anyTypes.setDefaultModelObject(AnyTypeKind.GROUP.name());
    } else if (!availableAnyTypes.isEmpty()) {
        anyTypes.setDefaultModelObject(availableAnyTypes.get(0));
    }
    add(anyTypes);

    connObjects = new MultilevelPanel("connObjects") {

        private static final long serialVersionUID = 1473786800290434002L;

        @Override
        protected void prev(final AjaxRequestTarget target) {
            anyTypes.setEnabled(true);
            target.add(anyTypes);

            super.prev(target);
        }

    };
    connObjects.setFirstLevel(new NextableConnObjectDirectoryPanel(baseModal, connObjects, resource,
            anyTypes.getField().getModelObject(), pageReference));
    connObjects.setOutputMarkupId(true);
    add(connObjects);

    anyTypes.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            connObjects.setFirstLevel(new NextableConnObjectDirectoryPanel(baseModal, connObjects, resource,
                    anyTypes.getField().getModelObject(), pageReference));
            target.add(connObjects);
        }
    });
}

From source file:org.apache.syncope.client.console.panels.search.SearchClausePanel.java

@Override
public FieldPanel<SearchClause> settingsDependingComponents() {
    final SearchClause searchClause = this.clause.getObject();

    final WebMarkupContainer operatorContainer = new WebMarkupContainer("operatorContainer");
    operatorContainer.setOutputMarkupId(true);
    field.add(operatorContainer);//w ww  .  j av a 2 s  .  c  o  m

    final BootstrapToggleConfig config = new BootstrapToggleConfig()
            .withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning)
            .withSize(BootstrapToggleConfig.Size.mini);

    operatorFragment.add(new BootstrapToggle("operator", new Model<Boolean>() {

        private static final long serialVersionUID = -7157802546272668001L;

        @Override
        public Boolean getObject() {
            return searchClause.getOperator() == Operator.AND;
        }

        @Override
        public void setObject(final Boolean object) {
            searchClause.setOperator(object ? Operator.AND : Operator.OR);
        }
    }, config) {

        private static final long serialVersionUID = 2969634208049189343L;

        @Override
        protected IModel<String> getOffLabel() {
            return Model.of("OR");
        }

        @Override
        protected IModel<String> getOnLabel() {
            return Model.of("AND");
        }

        @Override
        protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
            final CheckBox checkBox = super.newCheckBox(id, model);
            checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                }
            });
            return checkBox;
        }
    }.setOutputMarkupPlaceholderTag(true));

    if (getIndex() > 0) {
        operatorContainer.add(operatorFragment);
    } else {
        operatorContainer.add(searchButtonFragment);
    }

    final AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property",
            new PropertyModel<String>(searchClause, "property"), false);
    property.hideLabel().setOutputMarkupId(true).setEnabled(true);
    property.setChoices(properties.getObject());
    field.add(property);

    property.getField().add(AttributeModifier.replace("onkeydown",
            Model.of("if(event.keyCode == 13) { event.preventDefault(); }")));

    property.getField().add(new IndicatorAjaxEventBehavior("onkeyup") {

        private static final long serialVersionUID = -7866120562087857309L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
                return;
            }

            if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
                String[] inputAsArray = property.getField().getInputAsArray();

                if (StringUtils.isBlank(property.getField().getInput()) || inputAsArray.length == 0) {
                    property.setChoices(properties.getObject());
                } else {
                    String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null) ? inputAsArray[1]
                            : property.getField().getInput();
                    inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*")) ? inputValue + "*"
                            : (!inputValue.startsWith("*") && inputValue.endsWith("*")) ? "*" + inputValue
                                    : (inputValue.startsWith("*") && inputValue.endsWith("*") ? inputValue
                                            : "*" + inputValue + "*");

                    if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
                        List<GroupTO> filteredGroups = groupRestClient.search("/",
                                SyncopeClient.getGroupSearchConditionBuilder().is("name")
                                        .equalToIgnoreCase(inputValue).query(),
                                1, AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY,
                                new SortParam<>("name", true), null);
                        Collection<String> newList = CollectionUtils.collect(filteredGroups,
                                new Transformer<GroupTO, String>() {

                                    @Override
                                    public String transform(final GroupTO input) {
                                        return input.getName();
                                    }
                                });

                        final List<String> names = new ArrayList<>(newList);
                        Collections.sort(names);
                        property.setChoices(names);
                    }
                }
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().clear();
        }
    }, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {

        }
    });

    final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>(
            "comparator", "comparator", new PropertyModel<>(searchClause, "comparator"));
    comparator.setChoices(comparators);
    comparator.setNullValid(false).hideLabel().setOutputMarkupId(true);
    comparator.setRequired(required);
    comparator.setChoiceRenderer(getComparatorRender(field.getModel()));
    field.add(comparator);

    final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value",
            new PropertyModel<>(searchClause, "value"), false);
    value.hideLabel().setOutputMarkupId(true);
    field.add(value);

    value.getField().add(AttributeModifier.replace("onkeydown",
            Model.of("if(event.keyCode == 13) {event.preventDefault();}")));

    value.getField().add(new IndicatorAjaxEventBehavior("onkeydown") {

        private static final long serialVersionUID = -7133385027739964990L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            target.focusComponent(null);
            value.getField().inputChanged();
            value.getField().validate();
            if (value.getField().isValid()) {
                value.getField().valid();
                value.getField().updateModel();
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);

            attributes.getAjaxCallListeners().add(new AjaxCallListener() {

                private static final long serialVersionUID = 7160235486520935153L;

                @Override
                public CharSequence getPrecondition(final Component component) {
                    return "if (Wicket.Event.keyCode(attrs.event)  == 13) { return true; } else { return false; }";
                }
            });
        }
    });

    final AjaxDropDownChoicePanel<SearchClause.Type> type = new AjaxDropDownChoicePanel<>("type", "type",
            new PropertyModel<>(searchClause, "type"));
    type.setChoices(types).hideLabel().setRequired(required).setOutputMarkupId(true);
    type.setNullValid(false);
    type.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            final SearchClause searchClause = new SearchClause();
            if (StringUtils.isNotEmpty(type.getDefaultModelObjectAsString())) {
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
            }
            SearchClausePanel.this.clause.setObject(searchClause);

            setFieldAccess(searchClause.getType(), property, comparator, value);

            // reset property value in case and just in case of change of type
            property.setModelObject(StringUtils.EMPTY);
            target.add(property);

            target.add(comparator);
            target.add(value);
        }
    });
    field.add(type);

    comparator.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (type.getModelObject() == SearchClause.Type.ATTRIBUTE
                    || type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                if (comparator.getModelObject() == SearchClause.Comparator.IS_NULL
                        || comparator.getModelObject() == SearchClause.Comparator.IS_NOT_NULL) {
                    value.setModelObject(StringUtils.EMPTY);
                    value.setEnabled(false);
                } else {
                    value.setEnabled(true);
                }
                target.add(value);
            }

            if (type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                property.setEnabled(true);

                final SearchClause searchClause = new SearchClause();
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
                searchClause.setComparator(comparator.getModelObject());
                SearchClausePanel.this.clause.setObject(searchClause);

                target.add(property);
            }
        }
    });

    setFieldAccess(searchClause.getType(), property, comparator, value);

    return this;
}

From source file:org.apache.syncope.client.console.panels.search.UserSearchPanel.java

@Override
protected void populate() {
    super.populate();

    this.roleNames = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override//from w  ww.j  a v  a2s  .  co  m
        protected List<String> load() {
            return CollectionUtils.collect(roleRestClient.list(), new Transformer<RoleTO, String>() {

                @Override
                public String transform(final RoleTO input) {
                    return input.getKey();
                }
            }, new ArrayList<String>());
        }
    };
}

From source file:org.apache.syncope.client.console.policies.PolicySpecModalPanel.java

public PolicySpecModalPanel(final PullPolicyTO policyTO, final BaseModal<PullPolicyTO> modal,
        final PageReference pageRef) {

    super(modal, pageRef);
    modal.setFormModel(policyTO);/*from  w w w.j  a va  2s. co  m*/

    add(new AjaxDropDownChoicePanel<>("conflictResolutionAction", "conflictResolutionAction",
            new PropertyModel<ConflictResolutionAction>(policyTO.getSpecification(),
                    "conflictResolutionAction")).setChoices(Arrays.asList(ConflictResolutionAction.values())));

    model = new PropertyModel<List<CorrelationRule>>(policyTO.getSpecification(), "correlationRules") {

        private static final long serialVersionUID = -8168676563540297301L;

        private List<CorrelationRule> rules = CollectionUtils.collect(
                policyTO.getSpecification().getCorrelationRules() == null ? Collections.<String>emptySet()
                        : policyTO.getSpecification().getCorrelationRules().keySet(),
                new Transformer<String, CorrelationRule>() {

                    @Override
                    public CorrelationRule transform(final String input) {
                        return new CorrelationRule(input,
                                policyTO.getSpecification().getCorrelationRules().get(input));
                    }
                }, new ArrayList<CorrelationRule>());

        @Override
        public List<CorrelationRule> getObject() {
            return rules;
        }

        @Override
        public void setObject(final List<CorrelationRule> object) {
            policyTO.getSpecification().getCorrelationRules().clear();
            for (CorrelationRule rule : rules) {
                policyTO.getSpecification().getCorrelationRules().put(rule.getAny(), rule.getRule());
            }
        }

    };

    add(new MultiPanel<CorrelationRule>("correlationRules", "correlationRules", model, false) {

        private static final long serialVersionUID = -2481579077338205547L;

        @Override
        protected CorrelationRule newModelObject() {
            return new CorrelationRule();
        }

        @Override
        protected CorrelationRulePanel getItemPanel(final ListItem<CorrelationRule> item) {
            return new CorrelationRulePanel("panel", Model.of(item.getModelObject()));
        }
    });
}

From source file:org.apache.syncope.client.console.widgets.CamelMetricsWidget.java

private Bar build(final List<CamelMetrics.MeanRate> meanRates) {
    Bar bar = new Bar();
    bar.getOptions().setScaleBeginAtZero(true);
    bar.getOptions().setScaleShowGridLines(true);
    bar.getOptions().setScaleGridLineWidth(1);
    bar.getOptions().setBarShowStroke(true);
    bar.getOptions().setBarStrokeWidth(2);
    bar.getOptions().setBarValueSpacing(5);
    bar.getOptions().setBarDatasetSpacing(1);
    bar.getOptions().setResponsive(true);
    bar.getOptions().setMaintainAspectRatio(true);

    bar.getData()/*from   ww w .  j  a  va  2 s. co m*/
            .setLabels(CollectionUtils.collect(meanRates, new Transformer<CamelMetrics.MeanRate, String>() {

                @Override
                public String transform(final CamelMetrics.MeanRate input) {
                    return input.getRouteId();
                }
            }, new ArrayList<String>()));

    BarDataSet dataset = new BarDataSet(
            CollectionUtils.collect(meanRates, new Transformer<CamelMetrics.MeanRate, Double>() {

                @Override
                public Double transform(final CamelMetrics.MeanRate input) {
                    return input.getValue();
                }
            }, new ArrayList<Double>()));
    dataset.setFillColor("blue");
    bar.getData().setDatasets(Collections.singletonList(dataset));

    return bar;
}

From source file:org.apache.syncope.client.console.wizards.any.Details.java

public Details(final AnyWrapper<T> wrapper, final IModel<List<StatusBean>> statusModel,
        final boolean templateMode, final boolean includeStatusPanel, final PageReference pageRef) {

    this.pageRef = pageRef;

    final T inner = wrapper.getInnerObject();

    if (templateMode) {
        realm = new AjaxTextFieldPanel("destinationRealm", "destinationRealm",
                new PropertyModel<String>(inner, "realm"), false);
        AjaxTextFieldPanel.class.cast(realm).enableJexlHelp();
    } else {/* ww w  .j a  v a 2 s  .  c om*/
        realm = new AjaxDropDownChoicePanel<>("destinationRealm", "destinationRealm",
                new PropertyModel<String>(inner, "realm"), false);

        ((AjaxDropDownChoicePanel<String>) realm).setChoices(
                CollectionUtils.collect(new RealmRestClient().list(), new Transformer<RealmTO, String>() {

                    @Override
                    public String transform(final RealmTO input) {
                        return input.getFullPath();
                    }
                }, new ArrayList<String>()));
    }
    add(realm);

    statusPanel = new StatusPanel("status", inner, statusModel, pageRef);

    add(statusPanel.setEnabled(includeStatusPanel).setVisible(includeStatusPanel).setRenderBodyOnly(true));

    add(getGeneralStatusInformation("generalStatusInformation", inner).setEnabled(includeStatusPanel)
            .setVisible(includeStatusPanel).setRenderBodyOnly(true));
}

From source file:org.apache.syncope.client.console.wizards.resources.ConnectorConfPanel.java

/**
 * Get available configuration properties.
 *
 * @param instance connector instance./*from ww w . j  a v  a  2  s.  co m*/
 * @return configuration properties.
 */
@Override
protected final List<ConnConfProperty> getConnProperties(final ConnInstanceTO instance) {
    return CollectionUtils.collect(ConnectorWizardBuilder.getBundle(instance, bundles).getProperties(),
            new Transformer<ConnConfPropSchema, ConnConfProperty>() {

                @Override
                public ConnConfProperty transform(final ConnConfPropSchema key) {
                    final ConnConfProperty property = new ConnConfProperty();
                    property.setSchema(key);

                    if (instance.getConfMap().containsKey(key.getName())
                            && instance.getConfMap().get(key.getName()).getValues() != null) {

                        property.getValues().addAll(instance.getConfMap().get(key.getName()).getValues());
                        property.setOverridable(instance.getConfMap().get(key.getName()).isOverridable());
                    }

                    if (property.getValues().isEmpty() && !key.getDefaultValues().isEmpty()) {
                        property.getValues().addAll(key.getDefaultValues());
                    }
                    return property;
                }
            }, new ArrayList<ConnConfProperty>());
}

From source file:org.apache.syncope.client.console.wizards.resources.ConnectorDetailsPanel.java

public ConnectorDetailsPanel(final ConnInstanceTO connInstanceTO, final List<ConnBundleTO> bundles) {
    super();/*w  w w  . j a  v a 2  s .  c  o  m*/
    setOutputMarkupId(true);

    AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "displayName",
            new PropertyModel<String>(connInstanceTO, "displayName"), false);
    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();
    add(displayName);

    AjaxTextFieldPanel location = new AjaxTextFieldPanel("location", "location",
            new PropertyModel<String>(connInstanceTO, "location"), false);
    location.addRequiredLabel();
    location.setOutputMarkupId(true);
    location.setEnabled(false);
    add(location);

    final AjaxDropDownChoicePanel<String> bundleName = new AjaxDropDownChoicePanel<>("bundleName", "bundleName",
            new PropertyModel<String>(connInstanceTO, "bundleName"), false);
    ((DropDownChoice<String>) bundleName.getField()).setNullValid(true);
    bundleName.setChoices(CollectionUtils.collect(bundles, new Transformer<ConnBundleTO, String>() {

        @Override
        public String transform(final ConnBundleTO input) {
            return input.getBundleName();
        }
    }, new ArrayList<String>()));
    bundleName.addRequiredLabel();
    bundleName.setOutputMarkupId(true);
    bundleName.setEnabled(connInstanceTO.getKey() == null);
    bundleName.getField().setOutputMarkupId(true);
    add(bundleName);

    final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version",
            new PropertyModel<String>(connInstanceTO, "version"), false);
    version.setChoices(getVersions(connInstanceTO, bundles));
    version.addRequiredLabel();
    version.setEnabled(connInstanceTO.getBundleName() != null);
    version.setOutputMarkupId(true);
    version.getField().setOutputMarkupId(true);
    add(version);

    bundleName.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) bundleName.getField()).setNullValid(false);
            version.setEnabled(true);

            List<String> versions = getVersions(connInstanceTO, bundles);
            if (versions.size() == 1) {
                connInstanceTO.setVersion(versions.get(0));
                version.getField().setModelObject(versions.get(0));
            }
            version.setChoices(versions);

            target.add(version);
        }
    });

    if (connInstanceTO.getPoolConf() == null) {
        connInstanceTO.setPoolConf(new ConnPoolConfTO());
    }

    add(new AjaxSpinnerFieldPanel.Builder<Integer>().min(0).max(Integer.MAX_VALUE).build("connRequestTimeout",
            "connRequestTimeout", Integer.class,
            new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout")));

    add(new AjaxSpinnerFieldPanel.Builder<Integer>().min(0).max(Integer.MAX_VALUE).build("poolMaxObjects",
            "poolMaxObjects", Integer.class,
            new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects")));

    add(new AjaxSpinnerFieldPanel.Builder<Integer>().min(0).max(Integer.MAX_VALUE).build("poolMinIdle",
            "poolMinIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle")));

    add(new AjaxSpinnerFieldPanel.Builder<Integer>().min(0).max(Integer.MAX_VALUE).build("poolMaxIdle",
            "poolMaxIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle")));

    add(new AjaxSpinnerFieldPanel.Builder<Long>().min(0L).max(Long.MAX_VALUE).build("poolMaxWait",
            "poolMaxWait", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait")));

    add(new AjaxSpinnerFieldPanel.Builder<Long>().min(0L).max(Long.MAX_VALUE).build("poolMinEvictableIdleTime",
            "poolMinEvictableIdleTime", Long.class,
            new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis")));
}

From source file:org.apache.syncope.core.logic.LoggerLogic.java

private List<LoggerTO> list(final LoggerType type) {
    return CollectionUtils.collect(loggerDAO.findAll(type), new Transformer<Logger, LoggerTO>() {

        @Override// www . j a v  a2s . c  o  m
        public LoggerTO transform(final Logger logger) {
            LoggerTO loggerTO = new LoggerTO();
            BeanUtils.copyProperties(logger, loggerTO);
            return loggerTO;
        }
    }, new ArrayList<LoggerTO>());
}