Search in sources :

Example 91 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TaskQuartzImpl method setExtensionPropertyValue.

// use this method to avoid cloning the value
@Override
public <T> void setExtensionPropertyValue(QName propertyName, T value) throws SchemaException {
    PrismPropertyDefinition propertyDef = getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(propertyName);
    if (propertyDef == null) {
        throw new SchemaException("Unknown property " + propertyName);
    }
    ArrayList<PrismPropertyValue<T>> values = new ArrayList(1);
    if (value != null) {
        values.add(new PrismPropertyValue<T>(value));
    }
    processModificationBatched(setExtensionPropertyAndPrepareDelta(propertyName, propertyDef, values));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) F_WORKFLOW_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT) F_MODEL_OPERATION_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_MODEL_OPERATION_CONTEXT) ArrayList(java.util.ArrayList) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 92 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class MidPointQueryExecutor method getParameters.

protected Map<QName, Object> getParameters() {
    JRParameter[] params = dataset.getParameters();
    Map<QName, Object> expressionParameters = new HashMap<QName, Object>();
    for (JRParameter param : params) {
        if (param.isSystemDefined()) {
            continue;
        }
        //LOGGER.trace(((JRBaseParameter)param).getName());
        Object v = getParameterValue(param.getName());
        try {
            expressionParameters.put(new QName(param.getName()), new PrismPropertyValue(v));
        } catch (Exception e) {
        //just skip properties that are not important for midpoint
        }
        LOGGER.trace("p.val: {}", v);
    }
    return expressionParameters;
}
Also used : JRParameter(net.sf.jasperreports.engine.JRParameter) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) JRException(net.sf.jasperreports.engine.JRException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 93 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class ReportUtils method getItemRealValue.

public static Object getItemRealValue(PrismContainerValue containerValue, String itemName) {
    Item item = containerValue.findItem(new QName(itemName));
    if (item == null || item.size() == 0) {
        return null;
    }
    if (item.size() > 1) {
        throw new IllegalStateException("More than one value in item " + item);
    }
    PrismValue value = item.getValue(0);
    if (value == null) {
        return null;
    }
    if (value instanceof PrismPropertyValue) {
        return ((PrismPropertyValue) value).getValue();
    } else if (value instanceof PrismReferenceValue) {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setupReferenceValue((PrismReferenceValue) value);
        return ort;
    } else if (value instanceof PrismContainerValue) {
        // questionable
        return ((PrismContainerValue) value).asContainerable();
    } else {
        throw new IllegalStateException("Unknown PrismValue: " + value);
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) QName(javax.xml.namespace.QName) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 94 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class WebComponentUtil method encryptCredentials.

public static void encryptCredentials(ObjectDelta delta, boolean encrypt, MidPointApplication app) {
    if (delta == null || delta.isEmpty()) {
        return;
    }
    PropertyDelta propertyDelta = delta.findPropertyDelta(new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE));
    if (propertyDelta == null) {
        return;
    }
    Collection<PrismPropertyValue<ProtectedStringType>> values = propertyDelta.getValues(ProtectedStringType.class);
    for (PrismPropertyValue<ProtectedStringType> value : values) {
        ProtectedStringType string = value.getValue();
        encryptProtectedString(string, encrypt, app);
    }
}
Also used : PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 95 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class ValueOperation method interpret.

@Override
public <T> Filter interpret(ObjectFilter objectFilter, ConnIdNameMapper icfNameMapper) throws SchemaException {
    OperationResult parentResult = new OperationResult("interpret");
    ValueFilter valueFilter = (ValueFilter) objectFilter;
    if (valueFilter.getParentPath().isEmpty()) {
        throw new UnsupportedOperationException("Empty path is not supported (filter: " + objectFilter + ")");
    }
    if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ATTRIBUTES))) {
        try {
            QName propName = valueFilter.getDefinition().getName();
            String icfName = icfNameMapper.convertAttributeNameToIcf(propName, getInterpreter().getObjectClassDefinition(), "(attribute in the filter)");
            if (objectFilter instanceof EqualFilter) {
                EqualFilter<T> eq = (EqualFilter<T>) objectFilter;
                Collection<Object> convertedValues = convertValues(propName, eq.getValues());
                if (convertedValues == null || convertedValues.isEmpty()) {
                    // See MID-1460
                    throw new UnsupportedOperationException("Equals filter with a null value is NOT supported by ICF");
                } else {
                    Attribute attr = AttributeBuilder.build(icfName, convertedValues);
                    if (valueFilter.getDefinition().isSingleValue()) {
                        return FilterBuilder.equalTo(attr);
                    } else {
                        return FilterBuilder.containsAllValues(attr);
                    }
                }
            } else if (objectFilter instanceof SubstringFilter) {
                SubstringFilter substring = (SubstringFilter) objectFilter;
                Collection<Object> convertedValues = convertValues(propName, substring.getValues());
                if (convertedValues.isEmpty()) {
                    throw new IllegalArgumentException("Substring filter with null value makes no sense");
                } else {
                    if (convertedValues.size() != 1) {
                        throw new IllegalArgumentException("Substring filter with multiple values makes no sense");
                    //maybe it does, through OR clauses
                    }
                    return FilterBuilder.contains(AttributeBuilder.build(icfName, convertedValues.iterator().next()));
                }
            } else {
                throw new UnsupportedOperationException("Unsupported filter type: " + objectFilter);
            }
        } catch (SchemaException ex) {
            throw ex;
        }
    } else if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ACTIVATION))) {
        if (objectFilter instanceof EqualFilter) {
            QName propName = valueFilter.getDefinition().getName();
            EqualFilter<T> eq = (EqualFilter<T>) objectFilter;
            List<PrismPropertyValue<T>> values = eq.getValues();
            if (values.size() != 1) {
                throw new SchemaException("Unexpected number of values in filter " + objectFilter);
            }
            PrismPropertyValue<T> pval = values.get(0);
            String icfName;
            Object convertedValue;
            if (propName.equals(ActivationType.F_ADMINISTRATIVE_STATUS)) {
                icfName = OperationalAttributes.ENABLE_NAME;
                convertedValue = pval.getValue() == ActivationStatusType.ENABLED;
            } else if (propName.equals(ActivationType.F_LOCKOUT_STATUS)) {
                icfName = OperationalAttributes.LOCK_OUT_NAME;
                convertedValue = pval.getValue() == LockoutStatusType.LOCKED;
            } else {
                throw new UnsupportedOperationException("Unsupported activation property " + propName + " in filter: " + objectFilter);
            }
            Attribute attr = AttributeBuilder.build(icfName, convertedValue);
            if (valueFilter.getDefinition().isSingleValue()) {
                return FilterBuilder.equalTo(attr);
            } else {
                return FilterBuilder.containsAllValues(attr);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported filter type in filter: " + objectFilter);
        }
    } else {
        throw new UnsupportedOperationException("Unsupported parent path " + valueFilter.getParentPath() + " in filter: " + objectFilter);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Attribute(org.identityconnectors.framework.common.objects.Attribute) QName(javax.xml.namespace.QName) SubstringFilter(com.evolveum.midpoint.prism.query.SubstringFilter) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Collection(java.util.Collection) ValueFilter(com.evolveum.midpoint.prism.query.ValueFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ArrayList(java.util.ArrayList) List(java.util.List) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8