Search in sources :

Example 86 with PrismReferenceValue

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

the class ROExtReference method createReference.

public static PrismReferenceValue createReference(ROExtReference repo) {
    PrismReferenceValue value = new PrismReferenceValue();
    value.setOid(repo.getValue());
    value.setRelation(RUtil.stringToQName(repo.getRelation()));
    value.setTargetType(ClassMapper.getQNameForHQLType(repo.getTargetType()));
    return value;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue)

Example 87 with PrismReferenceValue

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

the class RAExtReference method createReference.

public static PrismReferenceValue createReference(RAExtReference repo) {
    PrismReferenceValue value = new PrismReferenceValue();
    value.setOid(repo.getValue());
    value.setRelation(RUtil.stringToQName(repo.getRelation()));
    value.setTargetType(ClassMapper.getQNameForHQLType(repo.getTargetType()));
    return value;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue)

Example 88 with PrismReferenceValue

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

the class AbstractIntegrationTest method assertLinked.

protected <F extends FocusType> void assertLinked(PrismObject<F> focus, String projectionOid) throws ObjectNotFoundException, SchemaException {
    PrismReference linkRef = focus.findReference(FocusType.F_LINK_REF);
    assertNotNull("No linkRefs in " + focus, linkRef);
    boolean found = false;
    for (PrismReferenceValue val : linkRef.getValues()) {
        if (val.getOid().equals(projectionOid)) {
            found = true;
        }
    }
    assertTrue("Focus " + focus + " is not linked to shadow " + projectionOid, found);
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 89 with PrismReferenceValue

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

the class AuditServiceProxy method completeRecord.

/**
	 * Complete the record with data that can be computed or discovered from the
	 * environment
	 */
private void completeRecord(AuditEventRecord record, Task task) {
    LightweightIdentifier id = null;
    if (record.getEventIdentifier() == null) {
        id = lightweightIdentifierGenerator.generate();
        record.setEventIdentifier(id.toString());
    }
    if (record.getTimestamp() == null) {
        if (id == null) {
            record.setTimestamp(System.currentTimeMillis());
        } else {
            // To be consistent with the ID
            record.setTimestamp(id.getTimestamp());
        }
    }
    if (record.getTaskIdentifier() == null && task != null) {
        record.setTaskIdentifier(task.getTaskIdentifier());
    }
    if (record.getTaskOID() == null && task != null) {
        record.setTaskOID(task.getOid());
    }
    if (record.getChannel() == null && task != null) {
        record.setChannel(task.getChannel());
    }
    if (record.getInitiator() == null && task != null) {
        record.setInitiator(task.getOwner());
    }
    if (record.getNodeIdentifier() == null && taskManager != null) {
        record.setNodeIdentifier(taskManager.getNodeId());
    }
    HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    if (connInfo == null && securityEnforcer != null) {
        connInfo = securityEnforcer.getStoredConnectionInformation();
    }
    if (connInfo != null) {
        if (record.getSessionIdentifier() == null) {
            record.setSessionIdentifier(connInfo.getSessionId());
        }
        if (record.getRemoteHostAddress() == null) {
            record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
        }
        if (record.getHostIdentifier() == null) {
            record.setHostIdentifier(connInfo.getLocalHostName());
        }
    }
    if (record.getSessionIdentifier() == null && task != null) {
        record.setSessionIdentifier(task.getTaskIdentifier());
    }
    if (record.getDeltas() != null) {
        for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
            ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
            final Map<String, PolyString> resolvedOids = new HashMap<>();
            Visitor namesResolver = new Visitor() {

                @Override
                public void visit(Visitable visitable) {
                    if (visitable instanceof PrismReferenceValue) {
                        PrismReferenceValue refVal = ((PrismReferenceValue) visitable);
                        String oid = refVal.getOid();
                        if (oid == null) {
                            // happen
                            return;
                        }
                        if (refVal.getTargetName() != null) {
                            resolvedOids.put(oid, refVal.getTargetName());
                            return;
                        }
                        if (resolvedOids.containsKey(oid)) {
                            // may
                            PolyString resolvedName = resolvedOids.get(oid);
                            // be
                            // null
                            refVal.setTargetName(resolvedName);
                            return;
                        }
                        if (refVal.getObject() != null) {
                            PolyString name = refVal.getObject().getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            return;
                        }
                        if (repositoryService == null) {
                            LOGGER.warn("No repository, no OID resolution (for {})", oid);
                            return;
                        }
                        PrismObjectDefinition<? extends ObjectType> objectDefinition = null;
                        if (refVal.getTargetType() != null) {
                            objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByType(refVal.getTargetType());
                        }
                        Class<? extends ObjectType> objectClass = null;
                        if (objectDefinition != null) {
                            objectClass = objectDefinition.getCompileTimeClass();
                        }
                        if (objectClass == null) {
                            // the default
                            objectClass = ObjectType.class;
                        // (shouldn't be
                        // needed)
                        }
                        SelectorOptions<GetOperationOptions> getNameOnly = SelectorOptions.create(new ItemPath(ObjectType.F_NAME), GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
                        try {
                            PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, Arrays.asList(getNameOnly), new OperationResult("dummy"));
                            PolyString name = object.getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            LOGGER.trace("Resolved {}: {} to {}", objectClass, oid, name);
                        } catch (ObjectNotFoundException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} as it does not exist", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        } catch (SchemaException | RuntimeException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} because of unexpected exception", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        }
                    }
                }
            };
            delta.accept(namesResolver);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Visitor(com.evolveum.midpoint.prism.Visitor) HashMap(java.util.HashMap) Visitable(com.evolveum.midpoint.prism.Visitable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 90 with PrismReferenceValue

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

the class ConsistencyTest method test510UnlinkAndUnassignAccountMorgan.

/**
	 *  Unlink account morgan, delete shadow and remove assignmnet from user morgan - preparation for the next test
	 */
@Test
public void test510UnlinkAndUnassignAccountMorgan() throws Exception {
    final String TEST_NAME = "test510UnlinkAndUnassignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    List<PrismReferenceValue> linkRefs = user.findReference(UserType.F_LINK_REF).getValues();
    assertEquals("Unexpected number of link refs", 1, linkRefs.size());
    PrismReferenceValue linkRef = linkRefs.iterator().next();
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationDeleteReference(UserType.class, USER_MORGAN_OID, UserType.F_LINK_REF, prismContext, linkRef.clone());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    ///----user's link is removed, now, remove assignment
    userDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, user.findContainer(UserType.F_ASSIGNMENT).getValue().clone());
    deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    repositoryService.deleteObject(ShadowType.class, linkRef.getOid(), result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    //		assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 0, userMorganType.getLinkRef().size());
    // Check shadow
    String accountOid = linkRef.getOid();
    try {
        PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
        assertAccountShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo);
        fail("Unexpected shadow in repo. Shadow mut not exist");
    } catch (ObjectNotFoundException ex) {
    //this is expected..shadow must not exist in repo
    }
    // Check account
    try {
        PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
        assertAccountShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo);
        fail("Unexpected shadow in repo. Shadow mut not exist");
    } catch (ObjectNotFoundException ex) {
    //this is expected..shadow must not exist in repo
    }
// TODO: check OpenDJ Account        
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)126 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)64 Test (org.testng.annotations.Test)47 Task (com.evolveum.midpoint.task.api.Task)45 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)32 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)27 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)25 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 ArrayList (java.util.ArrayList)22 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)20 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)16 PrismReference (com.evolveum.midpoint.prism.PrismReference)15 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)12 Collection (java.util.Collection)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)11