Search in sources :

Example 6 with PrismReferenceDefinition

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

the class TestOrgStruct method test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment.

// this test should generate a SchemaException (modifying targetRef in assignment should be prohibited)
@Test
public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment() throws Exception {
    final String TEST_NAME = "test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    Long id = findAssignmentIdForTarget(jack, ORG_MINISTRY_OF_OFFENSE_OID);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceDefinition referenceDefinition = getUserDefinition().findItemDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
    ReferenceDelta referenceDelta = new ReferenceDelta(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_TARGET_REF)), referenceDefinition, prismContext);
    PrismReferenceValue oldValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
    PrismReferenceValue newValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
    newValue.setRelation(SchemaConstants.ORG_MANAGER);
    referenceDelta.addValueToDelete(oldValue);
    referenceDelta.addValueToAdd(newValue);
    modifications.add(referenceDelta);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    try {
        modelService.executeChanges(deltas, null, task, result);
        AssertJUnit.fail("executeChanges should fail but it did not.");
    } catch (SchemaException e) {
    // ok!
    } catch (Exception e) {
        AssertJUnit.fail("executeChanges failed in the wrong way (expected SchemaException): " + e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 7 with PrismReferenceDefinition

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

the class RawTypeUtil method getParsedItem.

public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
    Item<IV, ID> subItem = null;
    List<IV> parsedValues = new ArrayList<IV>();
    for (RawType rawValue : values) {
        if (itemDefinition == null && containerDef != null) {
            itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
        }
        IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
        if (parsed != null) {
            parsedValues.add(parsed);
        }
    }
    PrismContext prismContext = null;
    if (containerDef != null) {
        prismContext = containerDef.getPrismContext();
    }
    if (prismContext == null && itemDefinition != null) {
        prismContext = itemDefinition.getPrismContext();
    }
    if (itemDefinition == null) {
        PrismProperty property = new PrismProperty(elementQName, prismContext);
        property.addAll(PrismValue.cloneCollection(parsedValues));
        return property;
    }
    if (itemDefinition instanceof PrismPropertyDefinition<?>) {
        // property
        PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            property.add((PrismPropertyValue) val.clone());
        }
        subItem = (Item<IV, ID>) property;
    } else if (itemDefinition instanceof PrismContainerDefinition<?>) {
        PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            container.add((PrismContainerValue) val.clone());
        }
        subItem = (Item<IV, ID>) container;
    } else if (itemDefinition instanceof PrismReferenceDefinition) {
        // TODO
        PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
        for (IV val : parsedValues) {
            PrismReferenceValue ref;
            if (val instanceof PrismReferenceValue) {
                ref = (PrismReferenceValue) val.clone();
            } else if (val instanceof PrismContainerValue) {
                // this is embedded (full) object
                Containerable c = ((PrismContainerValue) val).asContainerable();
                if (!(c instanceof Objectable)) {
                    throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
                }
                Objectable o = (Objectable) c;
                ref = new PrismReferenceValue();
                ref.setObject(o.asPrismObject());
            } else {
                throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
            }
            reference.merge(ref);
        }
        subItem = (Item<IV, ID>) reference;
    } else {
        throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
    }
    return subItem;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) PrismReference(com.evolveum.midpoint.prism.PrismReference) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 8 with PrismReferenceDefinition

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

the class ModelObjectResolver method resolve.

public <O extends ObjectType> PrismObject<O> resolve(PrismReferenceValue refVal, String string, GetOperationOptions options, Task task, OperationResult result) throws ObjectNotFoundException {
    String oid = refVal.getOid();
    Class<?> typeClass = ObjectType.class;
    QName typeQName = refVal.getTargetType();
    if (typeQName == null && refVal.getParent() != null && refVal.getParent().getDefinition() != null) {
        PrismReferenceDefinition refDef = (PrismReferenceDefinition) refVal.getParent().getDefinition();
        typeQName = refDef.getTargetTypeName();
    }
    if (typeQName != null) {
        typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
    }
    return (PrismObject<O>) (getObjectSimple((Class<O>) typeClass, oid, options, task, result)).asPrismObject();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) QName(javax.xml.namespace.QName) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Example 9 with PrismReferenceDefinition

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

the class ReferenceDelta method createModificationAdd.

public static ReferenceDelta createModificationAdd(ItemPath path, PrismObjectDefinition<?> objectDefinition, Collection<PrismReferenceValue> refValues) {
    PrismReferenceDefinition referenceDefinition = objectDefinition.findItemDefinition(path, PrismReferenceDefinition.class);
    // hoping the prismContext is there
    ReferenceDelta referenceDelta = new ReferenceDelta(path, referenceDefinition, objectDefinition.getPrismContext());
    referenceDelta.addValuesToAdd(refValues);
    return referenceDelta;
}
Also used : PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Example 10 with PrismReferenceDefinition

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

the class ReferenceDelta method createModificationReplace.

public static ReferenceDelta createModificationReplace(QName refName, PrismObjectDefinition<?> objectDefinition, PrismReferenceValue refValue) {
    PrismReferenceDefinition referenceDefinition = objectDefinition.findItemDefinition(refName, PrismReferenceDefinition.class);
    // hoping the prismContext is there
    ReferenceDelta referenceDelta = new ReferenceDelta(refName, referenceDefinition, objectDefinition.getPrismContext());
    if (refValue == null) {
        referenceDelta.setValueToReplace();
    } else {
        referenceDelta.setValueToReplace(refValue);
    }
    return referenceDelta;
}
Also used : PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Aggregations

PrismReferenceDefinition (com.evolveum.midpoint.prism.PrismReferenceDefinition)15 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)3 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ArrayList (java.util.ArrayList)3 QName (javax.xml.namespace.QName)3 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 List (java.util.List)2