Search in sources :

Example 51 with ObjectType

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

the class ObjectSelectionPanel method initColumns.

private List<IColumn<SelectableBean<ObjectType>, String>> initColumns() {
    List<IColumn<SelectableBean<ObjectType>, String>> columns = new ArrayList<>();
    IColumn column = new LinkColumn<SelectableBean<ObjectType>>(createStringResource("chooseTypeDialog.column.name"), context.getSortableProperty(), "value.name") {

        @Override
        public void onClick(AjaxRequestTarget target, IModel<SelectableBean<ObjectType>> rowModel) {
            ObjectType object = rowModel.getObject().getValue();
            context.chooseOperationPerformed(target, object);
        }
    };
    columns.add(column);
    return columns;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) IModel(org.apache.wicket.model.IModel) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) ArrayList(java.util.ArrayList) LinkColumn(com.evolveum.midpoint.web.component.data.column.LinkColumn)

Example 52 with ObjectType

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

the class GenerateExpressionEvaluator method evaluate.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java
	 * .util.Collection, java.util.Map, boolean, java.lang.String,
	 * com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    StringPolicyType stringPolicyType = null;
    ObjectReferenceType generateEvaluatorValuePolicyRef = generateEvaluatorType.getValuePolicyRef();
    if (generateEvaluatorValuePolicyRef != null) {
        if (generateEvaluatorType.getValuePolicyRef() != null) {
            ValuePolicyType valuePolicyType = objectResolver.resolve(generateEvaluatorValuePolicyRef, ValuePolicyType.class, null, "resolving value policy reference in generateExpressionEvaluator", context.getTask(), context.getResult());
            stringPolicyType = valuePolicyType.getStringPolicy();
        }
    }
    // would be generated
    if (stringPolicyType == null) {
        StringPolicyResolver stringPolicyResolver = context.getStringPolicyResolver();
        if (stringPolicyResolver != null) {
            stringPolicyType = stringPolicyResolver.resolve();
        }
    }
    elementStringPolicy = stringPolicyType;
    // } else {
    // stringPolicyType = elementStringPolicy;
    // }
    //
    String stringValue = null;
    GenerateExpressionEvaluatorModeType mode = generateEvaluatorType.getMode();
    Item<V, D> output = outputDefinition.instantiate();
    if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {
        PrismObject<? extends ObjectType> object = getObject(context);
        // TODO: generate value based on stringPolicyType (if not null)
        if (stringPolicyType != null) {
            if (isNotEmptyMinLength(stringPolicyType)) {
                stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, true, object, context.getContextDescription(), context.getTask(), context.getResult());
            } else {
                stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, false, object, context.getContextDescription(), context.getTask(), context.getResult());
            }
            context.getResult().computeStatus();
            if (context.getResult().isError()) {
                throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() + ". " + context.getResult().getMessage());
            }
        }
        if (stringValue == null) {
            int length = DEFAULT_LENGTH;
            RandomString randomString = new RandomString(length);
            stringValue = randomString.nextString();
        }
    } else if (mode == GenerateExpressionEvaluatorModeType.UUID) {
        UUID randomUUID = UUID.randomUUID();
        stringValue = randomUUID.toString();
    } else {
        throw new ExpressionEvaluationException("Unknown mode for generate expression: " + mode);
    }
    Object value = ExpressionUtil.convertToOutputValue(stringValue, outputDefinition, protector);
    if (output instanceof PrismProperty) {
        PrismPropertyValue<Object> pValue = new PrismPropertyValue<Object>(value);
        ((PrismProperty<Object>) output).add(pValue);
    } else {
        throw new UnsupportedOperationException("Can only generate values of property, not " + output.getClass());
    }
    return ItemDelta.toDeltaSetTriple(output, null);
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) UUID(java.util.UUID) RandomString(com.evolveum.midpoint.util.RandomString) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) RandomString(com.evolveum.midpoint.util.RandomString) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismObject(com.evolveum.midpoint.prism.PrismObject) UUID(java.util.UUID) GenerateExpressionEvaluatorModeType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorModeType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 53 with ObjectType

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

the class AbstractSearchExpressionEvaluator method executeSearchUsingCache.

private <O extends ObjectType> List<V> executeSearchUsingCache(Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    ObjectSearchStrategyType searchStrategy = getSearchStrategy();
    AbstractSearchExpressionEvaluatorCache cache = getCache();
    if (cache == null) {
        return executeSearch(null, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
    }
    List<V> list = cache.getQueryResult(targetTypeClass, query, searchStrategy, params, prismContext);
    if (list != null) {
        LOGGER.trace("Cache: HIT {} ({})", query, targetTypeClass.getSimpleName());
        return CloneUtil.clone(list);
    }
    LOGGER.trace("Cache: MISS {} ({})", query, targetTypeClass.getSimpleName());
    List<PrismObject> rawResult = new ArrayList<>();
    list = executeSearch(rawResult, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
    if (list != null && !list.isEmpty()) {
        // we don't want to cache negative results (e.g. if used with focal objects it might mean that they would be attempted to create multiple times)
        cache.putQueryResult(targetTypeClass, query, searchStrategy, params, list, rawResult, prismContext);
    }
    return list;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) AbstractSearchExpressionEvaluatorCache(com.evolveum.midpoint.model.common.expression.evaluator.caching.AbstractSearchExpressionEvaluatorCache) ObjectSearchStrategyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSearchStrategyType) ArrayList(java.util.ArrayList)

Example 54 with ObjectType

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

the class AbstractSearchExpressionEvaluator method transformSingleValue.

@Override
protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZero valueDestination, boolean useNew, ExpressionEvaluationContext context, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    //		if (LOGGER.isTraceEnabled()) {
    //			LOGGER.trace("transformSingleValue in {}\nvariables:\n{}\nvalueDestination: {}\nuseNew: {}",
    //					new Object[]{contextDescription, variables.debugDump(1), valueDestination, useNew});
    //		}
    QName targetTypeQName = getExpressionEvaluatorType().getTargetType();
    if (targetTypeQName == null) {
        targetTypeQName = getDefaultTargetType();
    }
    if (targetTypeQName != null && QNameUtil.isUnqualified(targetTypeQName)) {
        targetTypeQName = getPrismContext().getSchemaRegistry().resolveUnqualifiedTypeName(targetTypeQName);
    }
    ObjectTypes targetType = ObjectTypes.getObjectTypeFromTypeQName(targetTypeQName);
    if (targetType == null) {
        throw new SchemaException("Unknown target type " + targetTypeQName + " in " + shortDebugDump());
    }
    Class<? extends ObjectType> targetTypeClass = targetType.getClassDefinition();
    List<V> resultValues = null;
    ObjectQuery query = null;
    List<ItemDelta<V, D>> additionalAttributeDeltas = null;
    PopulateType populateAssignmentType = getExpressionEvaluatorType().getPopulate();
    if (populateAssignmentType != null) {
        additionalAttributeDeltas = collectAdditionalAttributes(populateAssignmentType, outputDefinition, variables, context, contextDescription, task, result);
    }
    if (getExpressionEvaluatorType().getOid() != null) {
        resultValues = new ArrayList<>(1);
        resultValues.add(createPrismValue(getExpressionEvaluatorType().getOid(), targetTypeQName, additionalAttributeDeltas, context));
    } else {
        SearchFilterType filterType = getExpressionEvaluatorType().getFilter();
        if (filterType == null) {
            throw new SchemaException("No filter in " + shortDebugDump());
        }
        query = QueryJaxbConvertor.createObjectQuery(targetTypeClass, filterType, prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("XML query converted to: {}", query.debugDump());
        }
        query = ExpressionUtil.evaluateQueryExpressions(query, variables, context.getExpressionFactory(), prismContext, context.getContextDescription(), task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Expression in query evaluated to: {}", query.debugDump());
        }
        query = extendQuery(query, context);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query after extension: {}", query.debugDump());
        }
        resultValues = executeSearchUsingCache(targetTypeClass, targetTypeQName, query, additionalAttributeDeltas, context, contextDescription, task, context.getResult());
        if (resultValues.isEmpty()) {
            ObjectReferenceType defaultTargetRef = getExpressionEvaluatorType().getDefaultTargetRef();
            if (defaultTargetRef != null) {
                resultValues.add(createPrismValue(defaultTargetRef.getOid(), targetTypeQName, additionalAttributeDeltas, context));
            }
        }
    }
    if (resultValues.isEmpty() && getExpressionEvaluatorType().isCreateOnDemand() == Boolean.TRUE && (valueDestination == PlusMinusZero.PLUS || valueDestination == PlusMinusZero.ZERO || useNew)) {
        String createdObjectOid = createOnDemand(targetTypeClass, variables, context, context.getContextDescription(), task, context.getResult());
        resultValues.add(createPrismValue(createdObjectOid, targetTypeQName, additionalAttributeDeltas, context));
    }
    LOGGER.trace("Search expression got {} results for query {}", resultValues == null ? "null" : resultValues.size(), query);
    return (List<V>) resultValues;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) List(java.util.List) ArrayList(java.util.ArrayList) PopulateType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)

Example 55 with ObjectType

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

the class ValuePolicyProcessor method validateValue.

public <O extends ObjectType> boolean validateValue(String newValue, ValuePolicyType pp, PrismObject<O> object, StringBuilder message, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    Validate.notNull(pp, "Value policy must not be null.");
    OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION);
    result.addParam("policyName", pp.getName());
    normalize(pp);
    if (newValue == null && (pp.getMinOccurs() == null || XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()) == 0)) {
        // No password is allowed
        result.recordSuccess();
        return true;
    }
    if (newValue == null) {
        newValue = "";
    }
    LimitationsType lims = pp.getStringPolicy().getLimitations();
    testMinimalLength(newValue, lims, result, message);
    testMaximalLength(newValue, lims, result, message);
    testMinimalUniqueCharacters(newValue, lims, result, message);
    if (lims.getLimit() == null || lims.getLimit().isEmpty()) {
        if (message.toString() == null || message.toString().isEmpty()) {
            result.computeStatus();
        } else {
            result.computeStatus(message.toString());
        }
        return result.isAcceptable();
    }
    // check limitation
    HashSet<String> validChars = null;
    HashSet<String> allValidChars = new HashSet<>();
    List<String> passwd = StringPolicyUtils.stringTokenizer(newValue);
    for (StringLimitType stringLimitationType : lims.getLimit()) {
        OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());
        validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
        int count = countValidCharacters(validChars, passwd);
        allValidChars.addAll(validChars);
        testMinimalOccurence(stringLimitationType, count, limitResult, message);
        testMaximalOccurence(stringLimitationType, count, limitResult, message);
        testMustBeFirst(stringLimitationType, count, limitResult, message, newValue, validChars);
        limitResult.computeStatus();
        result.addSubresult(limitResult);
    }
    testInvalidCharacters(passwd, allValidChars, result, message);
    testCheckExpression(newValue, lims, object, shortDesc, task, result, message);
    if (message.toString() == null || message.toString().isEmpty()) {
        result.computeStatus();
    } else {
        result.computeStatus(message.toString());
    }
    return result.isAcceptable();
}
Also used : StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) HashSet(java.util.HashSet)

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