Search in sources :

Example 36 with PrismContainerValue

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

the class JaxbTestUtil method determineElementQName.

private QName determineElementQName(Containerable containerable) {
    PrismContainerValue prismContainerValue = containerable.asPrismContainerValue();
    PrismContainerDefinition<?> definition = prismContainerValue.getParent() != null ? prismContainerValue.getParent().getDefinition() : null;
    if (definition != null) {
        if (definition.getName() != null) {
            return definition.getName();
        }
    }
    throw new IllegalStateException("Cannot determine element name of " + containerable + " (parent = " + prismContainerValue.getParent() + ", definition = " + definition + ")");
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue)

Example 37 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue 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 38 with PrismContainerValue

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

the class Construction method evaluateAssociation.

private Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluateAssociation(ResourceObjectAssociationType associationDefinitionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    QName assocName = ItemPathUtil.getOnlySegmentQName(associationDefinitionType.getRef());
    if (assocName == null) {
        throw new SchemaException("Missing 'ref' in association in construction in " + getSource());
    }
    MappingType outboundMappingType = associationDefinitionType.getOutbound();
    if (outboundMappingType == null) {
        throw new SchemaException("No outbound section in definition of association " + assocName + " in construction in " + getSource());
    }
    PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
    Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>createMappingBuilder().mappingType(outboundMappingType).contextDescription("for association " + PrettyPrinter.prettyPrint(assocName) + " in " + getSource()).originType(OriginType.ASSIGNMENTS).originObject(getSource());
    RefinedAssociationDefinition rAssocDef = refinedObjectClassDefinition.findAssociationDefinition(assocName);
    if (rAssocDef == null) {
        throw new SchemaException("No association " + assocName + " in object class " + refinedObjectClassDefinition.getHumanReadableName() + " in construction in " + getSource());
    }
    Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = evaluateMapping(mappingBuilder, assocName, outputDefinition, rAssocDef.getAssociationTarget(), task, result);
    LOGGER.trace("Evaluated mapping for association " + assocName + ": " + evaluatedMapping);
    return evaluatedMapping;
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)

Example 39 with PrismContainerValue

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

the class TestMultiResource method test440DavidAndGoliathAssignRoleAndCreateUserInOneStep.

@Test
public void test440DavidAndGoliathAssignRoleAndCreateUserInOneStep() throws Exception {
    final String TEST_NAME = "test440DavidAndGoliathAssignRoleAndCreateUserInOneStep";
    TestUtil.displayTestTile(TEST_NAME);
    dummyResourceGoliath.setBreakMode(BreakMode.NONE);
    dummyResourceDavid.setBreakMode(BreakMode.NONE);
    try {
        Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
        OperationResult result = task.getResult();
        // delete user and his roles which were added before
        PrismObject<UserType> userWorld = findUserByUsername(USER_FIELD_NAME);
        AssertJUnit.assertNotNull("User must not be null.", userWorld);
        ObjectDelta<UserType> delta = ObjectDelta.createDeleteDelta(UserType.class, userWorld.getOid(), prismContext);
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        deltas.add(delta);
        modelService.executeChanges(deltas, null, task, result);
        OperationResult deleteResult = new OperationResult("Check if user was deleted properly.");
        try {
            repositoryService.getObject(UserType.class, userWorld.getOid(), null, deleteResult);
        } catch (ObjectNotFoundException ex) {
        //this is OK, we deleted user before
        }
        // GIVEN
        assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
        PrismObject<UserType> userBefore = createUser(USER_WORLD_NAME, USER_WORLD_FULL_NAME, true);
        userBefore.asObjectable().getOrganizationalUnit().add(PrismTestUtil.createPolyStringType("stone"));
        PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
        PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
        targetRef.getValue().setOid(ROLE_FIGHT_OID);
        targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
        userBefore.findOrCreateContainer(UserType.F_ASSIGNMENT).add((PrismContainerValue) cval);
        //		userBefore.asObjectable().getAssignment().add(cval.asContainerable());
        // this should add user and at the sate time assign the role fight..->
        // the result of the operation have to be the same as in test 400
        addObject(userBefore);
        dummyAuditService.clear();
        // WHEN
        TestUtil.displayWhen(TEST_NAME);
        //        assignRole(userBefore.getOid(), ROLE_FIGHT_OID, task, result);
        // THEN
        TestUtil.displayThen(TEST_NAME);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        assertDavidGoliath(userBefore.getOid(), "stone", USER_WORLD_NAME, true, true, true);
        // Check audit
        display("Audit", dummyAuditService);
    //        dummyAuditService.assertRecords(4);
    //        dummyAuditService.assertSimpleRecordSanity();
    //        dummyAuditService.assertAnyRequestDeltas();
    //        dummyAuditService.assertExecutionDeltas(0,3);
    //        dummyAuditService.asserHasDelta(0,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(0,ChangeType.ADD, ShadowType.class);
    //        dummyAuditService.assertExecutionDeltas(1,3);
    //        dummyAuditService.asserHasDelta(1,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(1,ChangeType.ADD, ShadowType.class);
    //        dummyAuditService.assertExecutionDeltas(2,2);
    //        dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, UserType.class);
    //        dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, ShadowType.class);
    //        dummyAuditService.assertExecutionSuccess();
    //        
    //        // Have a closer look at the last shadow modify delta. Make sure there are no phantom changes.
    //        ObjectDeltaOperation<?> executionDeltaOp = dummyAuditService.getExecutionDelta(2, ChangeType.MODIFY, ShadowType.class);
    //        ObjectDelta<?> executionDelta = executionDeltaOp.getObjectDelta();
    //        display("Last execution delta", executionDelta);
    //        PrismAsserts.assertModifications("Phantom changes in last delta:", executionDelta, 2);
    } catch (Exception ex) {
        LOGGER.info("ex: {}", ex);
        throw ex;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) 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) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractPasswordTest(com.evolveum.midpoint.model.intest.password.AbstractPasswordTest)

Example 40 with PrismContainerValue

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

the class PolicyRuleBasedAspect method assignmentToDelta.

// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(Class<? extends Objectable> focusClass, AssignmentType assignmentType, boolean assignmentRemoved, String objectOid) throws SchemaException {
    PrismContainerValue value = assignmentType.clone().asPrismContainerValue();
    S_ValuesEntry item = DeltaBuilder.deltaFor(focusClass, prismContext).item(FocusType.F_ASSIGNMENT);
    S_ItemEntry op = assignmentRemoved ? item.delete(value) : item.add(value);
    return (ObjectDelta<? extends FocusType>) op.asObjectDelta(objectOid);
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) S_ValuesEntry(com.evolveum.midpoint.prism.delta.builder.S_ValuesEntry)

Aggregations

PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 Task (com.evolveum.midpoint.task.api.Task)22 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)22 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)21 Test (org.testng.annotations.Test)18 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 ArrayList (java.util.ArrayList)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 QName (javax.xml.namespace.QName)10 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)9 PrismReference (com.evolveum.midpoint.prism.PrismReference)9 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)6 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6