Search in sources :

Example 26 with PrismReference

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

the class RepositoryObjectDataProvider method createItem.

private DebugObjectItem createItem(PrismObject<? extends ObjectType> object, OperationResult result) {
    DebugObjectItem item = DebugObjectItem.createDebugObjectItem(object);
    if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
        PrismReference ref = object.findReference(new ItemPath(ShadowType.F_RESOURCE_REF));
        if (ref == null || ref.getValue() == null) {
            return item;
        }
        PrismReferenceValue refValue = ref.getValue();
        String resourceOid = refValue.getOid();
        ResourceDescription desc = resourceCache.get(resourceOid);
        if (desc == null) {
            desc = loadDescription(resourceOid, result);
            resourceCache.put(resourceOid, desc);
        }
        item.setResourceName(desc.getName());
        item.setResourceType(desc.getType());
    }
    return item;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) DebugObjectItem(com.evolveum.midpoint.web.page.admin.configuration.dto.DebugObjectItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 27 with PrismReference

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

the class RepositoryObjectDataProvider method loadDescription.

private ResourceDescription loadDescription(String oid, OperationResult result) {
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ResourceType.F_CONNECTOR, GetOperationOptions.createResolve());
    OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
    subResult.addParam("oid", oid);
    PrismObject<ResourceType> resource = null;
    String type = null;
    try {
        resource = getModel().getObject(ResourceType.class, oid, options, getPage().createSimpleTask(OPERATION_LOAD_RESOURCE), subResult);
        PrismReference ref = resource.findReference(ResourceType.F_CONNECTOR_REF);
        if (ref != null && ref.getValue() != null) {
            PrismReferenceValue refValue = ref.getValue();
            if (refValue.getObject() != null) {
                PrismObject connector = refValue.getObject();
                PrismProperty<String> pType = connector.findProperty(ConnectorType.F_CONNECTOR_TYPE);
                if (pType != null && pType.getRealValue() != null) {
                    type = pType.getRealValue(String.class);
                }
            }
        }
        subResult.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource for account", ex);
        subResult.recordFatalError("Couldn't load resource for account.");
    } finally {
        subResult.recomputeStatus();
    }
    return new ResourceDescription(oid, WebComponentUtil.getName(resource), type);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismReference(com.evolveum.midpoint.prism.PrismReference) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Example 28 with PrismReference

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

the class NameStep method isConnectorOnHost.

private boolean isConnectorOnHost(PrismObject<ConnectorType> connector, @Nullable PrismObject<ConnectorHostType> host) {
    PrismReference connHostRef = connector.findReference(ConnectorType.F_CONNECTOR_HOST_REF);
    String connHostOid = connHostRef != null ? connHostRef.getOid() : null;
    String hostOid = host != null ? host.getOid() : null;
    return ObjectUtils.equals(connHostOid, hostOid);
}
Also used : PrismReference(com.evolveum.midpoint.prism.PrismReference) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 29 with PrismReference

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

use of com.evolveum.midpoint.prism.PrismReference 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)

Aggregations

PrismReference (com.evolveum.midpoint.prism.PrismReference)41 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)15 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)8 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 QName (javax.xml.namespace.QName)7 Test (org.testng.annotations.Test)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)5 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4