Search in sources :

Example 1 with PrismReferenceDefinition

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

the class ReferenceDelta method createModificationReplace.

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

Example 2 with PrismReferenceDefinition

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

the class ReferenceDelta method createModificationReplace.

public static ReferenceDelta createModificationReplace(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.setValuesToReplace(refValues);
    return referenceDelta;
}
Also used : PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Example 3 with PrismReferenceDefinition

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

the class AssignmentProcessor method setReferences.

private <F extends ObjectType> void setReferences(LensFocusContext<F> focusContext, QName itemName, Collection<PrismReferenceValue> targetState) throws SchemaException {
    PrismObject<F> focusOld = focusContext.getObjectOld();
    if (focusOld == null) {
        if (targetState.isEmpty()) {
            return;
        }
    } else {
        PrismReference existingState = focusOld.findReference(itemName);
        if (existingState == null || existingState.isEmpty()) {
            if (targetState.isEmpty()) {
                return;
            }
        } else {
            // we don't use QNameUtil.match here, because we want to ensure we store qualified values there
            // (and newValues are all qualified)
            Comparator<PrismReferenceValue> comparator = (a, b) -> 2 * a.getOid().compareTo(b.getOid()) + (Objects.equals(a.getRelation(), b.getRelation()) ? 0 : 1);
            if (MiscUtil.unorderedCollectionCompare(targetState, existingState.getValues(), comparator)) {
                return;
            }
        }
    }
    PrismReferenceDefinition itemDef = focusContext.getObjectDefinition().findItemDefinition(itemName, PrismReferenceDefinition.class);
    ReferenceDelta itemDelta = new ReferenceDelta(itemName, itemDef, focusContext.getObjectDefinition().getPrismContext());
    itemDelta.setValuesToReplace(targetState);
    focusContext.swallowToSecondaryDelta(itemDelta);
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Construction(com.evolveum.midpoint.model.impl.lens.Construction) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectResolver(com.evolveum.midpoint.schema.util.ObjectResolver) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ConstructionPack(com.evolveum.midpoint.model.impl.lens.ConstructionPack) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) QNameUtil(com.evolveum.midpoint.util.QNameUtil) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ModelUtils(com.evolveum.midpoint.model.impl.controller.ModelUtils) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ActivationComputer(com.evolveum.midpoint.common.ActivationComputer) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Objects(java.util.Objects) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) Entry(java.util.Map.Entry) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) java.util(java.util) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) DeltaMapTriple(com.evolveum.midpoint.prism.delta.DeltaMapTriple) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.AssignmentEvaluator) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Component(org.springframework.stereotype.Component) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) PrismReference(com.evolveum.midpoint.prism.PrismReference) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Example 4 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 {
    Task task = getTestTask();
    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(ItemPath.create(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
    ReferenceDelta referenceDelta = prismContext.deltaFactory().reference().create(ItemPath.create(UserType.F_ASSIGNMENT, id, AssignmentType.F_TARGET_REF), referenceDefinition);
    PrismReferenceValue oldValue = itemFactory().createReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
    PrismReferenceValue newValue = itemFactory().createReferenceValue(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 = prismContext.deltaFactory().object().createModifyDelta(USER_JACK_OID, modifications, UserType.class);
    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 : 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) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 5 with PrismReferenceDefinition

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

the class AbstractRepositorySearchAction method createResourceRefFilter.

private RefFilter createResourceRefFilter(String oid) throws SchemaException {
    PrismContext prismContext = context.getPrismContext();
    List<PrismReferenceValue> values = new ArrayList<>();
    if (oid != null) {
        values.add(prismContext.itemFactory().createReferenceValue(oid, ResourceType.COMPLEX_TYPE));
    }
    SchemaRegistry registry = prismContext.getSchemaRegistry();
    PrismReferenceDefinition def = registry.findItemDefinitionByFullPath(ShadowType.class, PrismReferenceDefinition.class, ShadowType.F_RESOURCE_REF);
    return prismContext.queryFactory().createReferenceEqual(ShadowType.F_RESOURCE_REF, def, values);
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition)

Aggregations

PrismReferenceDefinition (com.evolveum.midpoint.prism.PrismReferenceDefinition)19 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)4 QName (javax.xml.namespace.QName)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 ArrayList (java.util.ArrayList)3 PrismReference (com.evolveum.midpoint.prism.PrismReference)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 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)2 ConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)2 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)2 IModel (org.apache.wicket.model.IModel)2 PropertyModel (org.apache.wicket.model.PropertyModel)2 ActivationComputer (com.evolveum.midpoint.common.ActivationComputer)1 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)1