Search in sources :

Example 41 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method generateValue.

@Override
public <O extends ObjectType> void generateValue(PrismObject<O> object, PolicyItemsDefinitionType policyItemsDefinition, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
    String oid = object.getOid();
    OperationResult result = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
    Class<O> clazz = (Class<O>) object.asObjectable().getClass();
    ValuePolicyType valuePolicy = null;
    try {
        valuePolicy = getValuePolicy(object, task, result);
    } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
        LOGGER.error("Failed to get value policy for generating value. ", e);
        result.recordFatalError("Error while getting value policy. Reason: " + e.getMessage(), e);
        throw e;
    }
    Collection<PropertyDelta<?>> deltasToExecute = new ArrayList<>();
    for (PolicyItemDefinitionType policyItemDefinition : policyItemsDefinition.getPolicyItemDefinition()) {
        OperationResult generateValueResult = parentResult.createSubresult(OPERATION_GENERATE_VALUE);
        ItemPath path = getPath(policyItemDefinition);
        if (path == null) {
            LOGGER.error("No item path defined in the target for policy item definition. Cannot generate value");
            generateValueResult.recordFatalError("No item path defined in the target for policy item definition. Cannot generate value");
            continue;
        }
        result.addParam("policyItemPath", path);
        PrismPropertyDefinition<?> propertyDef = getItemDefinition(object, path);
        if (propertyDef == null) {
            LOGGER.error("No definition for property {} in object. Is the path referencing prism property?" + path, object);
            generateValueResult.recordFatalError("No definition for property " + path + " in object " + object + ". Is the path referencing prism property?");
            continue;
        }
        LOGGER.trace("Default value policy: {}", valuePolicy);
        try {
            generateValue(object, valuePolicy, policyItemDefinition, task, generateValueResult);
        } catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
            LOGGER.error("Failed to generate value for {} " + policyItemDefinition, e);
            generateValueResult.recordFatalError("Failed to generate value for " + policyItemDefinition + ". Reason: " + e.getMessage(), e);
            policyItemDefinition.setResult(generateValueResult.createOperationResultType());
            continue;
        }
        collectDeltasForGeneratedValuesIfNeeded(object, policyItemDefinition, deltasToExecute, path, propertyDef);
        generateValueResult.computeStatusIfUnknown();
    }
    result.computeStatus();
    if (!result.isAcceptable()) {
        return;
    }
    try {
        if (!deltasToExecute.isEmpty()) {
            modelCrudService.modifyObject(clazz, oid, deltasToExecute, null, task, result);
        }
    } catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | ObjectAlreadyExistsException | PolicyViolationException | SecurityViolationException e) {
        LOGGER.error("Could not execute deltas for generated values. Reason: " + e.getMessage(), e);
        result.recordFatalError("Could not execute deltas for gegenerated values. Reason: " + e.getMessage(), e);
        throw e;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PolicyItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 42 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method generateValue.

private <O extends ObjectType> void generateValue(PrismObject<O> object, ValuePolicyType defaultPolicy, PolicyItemDefinitionType policyItemDefinition, Task task, OperationResult result) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    PolicyItemTargetType target = policyItemDefinition.getTarget();
    if (target == null || ItemPath.isNullOrEmpty(target.getPath())) {
        LOGGER.error("Target item path must be defined");
        throw new SchemaException("Target item path must be defined");
    }
    ItemPath targetPath = target.getPath().getItemPath();
    ValuePolicyType valuePolicy = resolveValuePolicy(policyItemDefinition, defaultPolicy, task, result);
    LOGGER.trace("Value policy used for generating new value : {}", valuePolicy);
    StringPolicyType stringPolicy = valuePolicy != null ? valuePolicy.getStringPolicy() : null;
    if (stringPolicy == null) {
        LOGGER.trace("No sting policy defined. Cannot generate value.");
        result.recordFatalError("No string policy defined. Cannot generate value");
        return;
    //			throw new SchemaException("No value policy for " + targetPath);
    }
    String newValue = policyProcessor.generate(targetPath, stringPolicy, 10, object, "generating value for" + targetPath, task, result);
    policyItemDefinition.setValue(newValue);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolicyItemTargetType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 43 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method validateValue.

private <T, O extends ObjectType> boolean validateValue(PrismObject<O> object, ValuePolicyType policy, PolicyItemDefinitionType policyItemDefinition, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
    ValuePolicyType stringPolicy = resolveValuePolicy(policyItemDefinition, policy, task, parentResult);
    RawType rawValue = (RawType) policyItemDefinition.getValue();
    String valueToValidate = null;
    List<String> valuesToValidate = new ArrayList<>();
    PolicyItemTargetType target = policyItemDefinition.getTarget();
    ItemPath path = null;
    if (target != null) {
        path = target.getPath().getItemPath();
    }
    if (rawValue != null) {
        valueToValidate = rawValue.getParsedRealValue(String.class);
        valuesToValidate.add(valueToValidate);
    } else {
        if (target == null || target.getPath() == null) {
            LOGGER.error("Target item path must be defined");
            parentResult.recordFatalError("Target item path must be defined");
            throw new SchemaException("Target item path must be defined");
        }
        path = target.getPath().getItemPath();
        PrismProperty<T> property = object.findProperty(path);
        if (property == null || property.isEmpty()) {
            LOGGER.error("Attribute {} has no value. Nothing to validate.", property);
            parentResult.recordFatalError("Attribute " + property + " has no value. Nothing to validate");
            throw new SchemaException("Attribute " + property + " has no value. Nothing to validate");
        }
        PrismPropertyDefinition<T> itemToValidateDefinition = property.getDefinition();
        QName definitionName = itemToValidateDefinition.getTypeName();
        if (!isSupportedType(definitionName)) {
            LOGGER.error("Trying to validate string policy on the property of type {} failed. Unsupported type.", itemToValidateDefinition);
            parentResult.recordFatalError("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
            throw new SchemaException("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
        }
        if (itemToValidateDefinition.isSingleValue()) {
            if (definitionName.equals(PolyStringType.COMPLEX_TYPE)) {
                valueToValidate = ((PolyString) property.getRealValue()).getOrig();
            } else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
                ProtectedStringType protectedString = ((ProtectedStringType) property.getRealValue());
                valueToValidate = getClearValue(protectedString);
            } else {
                valueToValidate = (String) property.getRealValue();
            }
            valuesToValidate.add(valueToValidate);
        } else {
            if (definitionName.equals(DOMUtil.XSD_STRING)) {
                valuesToValidate.addAll(property.getRealValues(String.class));
            } else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
                for (ProtectedStringType protectedString : property.getRealValues(ProtectedStringType.class)) {
                    valuesToValidate.add(getClearValue(protectedString));
                }
            } else {
                for (PolyString val : property.getRealValues(PolyString.class)) {
                    valuesToValidate.add(val.getOrig());
                }
            }
        }
    }
    for (String newValue : valuesToValidate) {
        OperationResult result = parentResult.createSubresult(OPERATION_VALIDATE_VALUE + ".value");
        if (path != null)
            result.addParam("path", path);
        result.addParam("valueToValidate", newValue);
        if (!policyProcessor.validateValue(newValue, stringPolicy, object, "validate value " + (path != null ? "for " + path : "") + " for " + object + " value " + valueToValidate, task, result)) {
            result.recordFatalError("Validation for value " + newValue + " against policy " + stringPolicy + " failed");
            LOGGER.error("Validation for value {} against policy {} failed", newValue, stringPolicy);
        }
        result.computeStatusIfUnknown();
    }
    parentResult.computeStatus();
    policyItemDefinition.setResult(parentResult.createOperationResultType());
    return parentResult.isAcceptable();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PolicyItemTargetType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class OrgStructFunctionsImpl method getManagersOfOrg.

@Override
public Collection<UserType> getManagersOfOrg(String orgOid, boolean preAuthorized) throws SchemaException, SecurityViolationException {
    Set<UserType> retval = new HashSet<UserType>();
    OperationResult result = new OperationResult("getManagerOfOrg");
    PrismReferenceValue parentOrgRefVal = new PrismReferenceValue(orgOid, OrgType.COMPLEX_TYPE);
    parentOrgRefVal.setRelation(SchemaConstants.ORG_MANAGER);
    ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext).item(ObjectType.F_PARENT_ORG_REF).ref(parentOrgRefVal).build();
    List<PrismObject<ObjectType>> members = searchObjects(ObjectType.class, objectQuery, result, preAuthorized);
    for (PrismObject<ObjectType> member : members) {
        if (member.asObjectable() instanceof UserType) {
            UserType user = (UserType) member.asObjectable();
            retval.add(user);
        }
    }
    return retval;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 45 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.

the class SchemaTransformer method applyObjectTemplateToDefinition.

public <O extends ObjectType> void applyObjectTemplateToDefinition(PrismObjectDefinition<O> objectDefinition, ObjectTemplateType objectTemplateType, OperationResult result) throws ObjectNotFoundException, SchemaException {
    if (objectTemplateType == null) {
        return;
    }
    for (ObjectReferenceType includeRef : objectTemplateType.getIncludeRef()) {
        PrismObject<ObjectTemplateType> subTemplate = cacheRepositoryService.getObject(ObjectTemplateType.class, includeRef.getOid(), null, result);
        applyObjectTemplateToDefinition(objectDefinition, subTemplate.asObjectable(), result);
    }
    for (ObjectTemplateItemDefinitionType templateItemDefType : objectTemplateType.getItem()) {
        ItemPathType ref = templateItemDefType.getRef();
        if (ref == null) {
            throw new SchemaException("No 'ref' in item definition in " + objectTemplateType);
        }
        ItemPath itemPath = ref.getItemPath();
        ItemDefinition itemDef = objectDefinition.findItemDefinition(itemPath);
        if (itemDef != null) {
            applyObjectTemplateItem(itemDef, templateItemDefType, "item " + itemPath + " in object type " + objectDefinition.getTypeName() + " as specified in item definition in " + objectTemplateType);
        } else {
            OperationResult subResult = result.createMinorSubresult(SchemaTransformer.class.getName() + ".applyObjectTemplateToDefinition");
            subResult.recordPartialError("No definition for item " + itemPath + " in object type " + objectDefinition.getTypeName() + " as specified in item definition in " + objectTemplateType);
            continue;
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)321 Test (org.testng.annotations.Test)267 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)252 Task (com.evolveum.midpoint.task.api.Task)251 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)230 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)170 ArrayList (java.util.ArrayList)136 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)65 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)61 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)53 Holder (javax.xml.ws.Holder)51 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)50 QName (javax.xml.namespace.QName)46 PrismObject (com.evolveum.midpoint.prism.PrismObject)42 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)36 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)36 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)34