Search in sources :

Example 1 with PlainAttrUniqueValue

use of org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue in project syncope by apache.

the class AbstractPlainAttr method add.

@Override
public void add(final String value, final AnyUtils anyUtils) {
    checkNonNullSchema();
    PlainAttrValue attrValue;
    if (getSchema().isUniqueConstraint()) {
        attrValue = anyUtils.newPlainAttrUniqueValue();
        ((PlainAttrUniqueValue) attrValue).setSchema(getSchema());
    } else {
        attrValue = anyUtils.newPlainAttrValue();
    }
    add(value, attrValue);
}
Also used : PlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue)

Example 2 with PlainAttrUniqueValue

use of org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue in project syncope by apache.

the class ConfigurationDataBinderImpl method fillAttr.

private void fillAttr(final List<String> values, final PlainSchema schema, final CPlainAttr attr, final SyncopeClientException invalidValues) {
    // if schema is multivalue, all values are considered for addition;
    // otherwise only the fist one - if provided - is considered
    List<String> valuesProvided = schema.isMultivalue() ? values : (values.isEmpty() ? Collections.<String>emptyList() : Collections.singletonList(values.iterator().next()));
    if (valuesProvided.isEmpty()) {
        JexlContext jexlContext = new MapContext();
        JexlUtils.addPlainAttrsToContext(confDAO.get().getPlainAttrs(), jexlContext);
        if (!schema.isReadonly() && Boolean.parseBoolean(JexlUtils.evaluate(schema.getMandatoryCondition(), jexlContext))) {
            LOG.error("Mandatory schema " + schema.getKey() + " not provided with values");
            SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
            reqValMissing.getElements().add(schema.getKey());
            throw reqValMissing;
        }
    }
    for (String value : valuesProvided) {
        if (value == null || value.isEmpty()) {
            LOG.debug("Null value for {}, ignoring", schema.getKey());
        } else {
            try {
                PlainAttrValue attrValue;
                if (schema.isUniqueConstraint()) {
                    attrValue = entityFactory.newEntity(CPlainAttrUniqueValue.class);
                    ((PlainAttrUniqueValue) attrValue).setSchema(schema);
                } else {
                    attrValue = entityFactory.newEntity(CPlainAttrValue.class);
                }
                attr.add(value, attrValue);
            } catch (InvalidPlainAttrValueException e) {
                LOG.warn("Invalid value for attribute " + schema.getKey() + ": " + value, e);
                invalidValues.getElements().add(schema.getKey() + ": " + value + " - " + e.getMessage());
            }
        }
    }
}
Also used : CPlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue) PlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue) CPlainAttrValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue) CPlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue) JexlContext(org.apache.commons.jexl3.JexlContext) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) CPlainAttrValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue) MapContext(org.apache.commons.jexl3.MapContext) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)

Example 3 with PlainAttrUniqueValue

use of org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue in project syncope by apache.

the class ConfTest method add.

private void add(final CPlainAttr newAttr, final String value) {
    JPACPlainAttrValue attrValue;
    if (newAttr.getSchema().isUniqueConstraint()) {
        attrValue = new JPACPlainAttrValue();
        ((PlainAttrUniqueValue) attrValue).setSchema(newAttr.getSchema());
    } else {
        attrValue = new JPACPlainAttrValue();
    }
    newAttr.add(value, attrValue);
}
Also used : PlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue) JPACPlainAttrValue(org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue)

Example 4 with PlainAttrUniqueValue

use of org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue in project syncope by apache.

the class ConfTest method add.

private void add(final CPlainAttr newAttr, final String value) {
    JPACPlainAttrValue attrValue;
    if (newAttr.getSchema().isUniqueConstraint()) {
        attrValue = new JPACPlainAttrValue();
        ((PlainAttrUniqueValue) attrValue).setSchema(newAttr.getSchema());
    } else {
        attrValue = new JPACPlainAttrValue();
    }
    newAttr.add(value, attrValue);
}
Also used : PlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue) JPACPlainAttrValue(org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue)

Aggregations

PlainAttrUniqueValue (org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue)4 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)2 JPACPlainAttrValue (org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue)2 JexlContext (org.apache.commons.jexl3.JexlContext)1 MapContext (org.apache.commons.jexl3.MapContext)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 InvalidPlainAttrValueException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)1 CPlainAttrUniqueValue (org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue)1 CPlainAttrValue (org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue)1