Search in sources :

Example 41 with PrismReferenceValue

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

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 42 with PrismReferenceValue

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

the class AbstractIntegrationTest method assertNotLinked.

protected void assertNotLinked(PrismObject<UserType> user, String accountOid) throws ObjectNotFoundException, SchemaException {
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    if (linkRef == null) {
        return;
    }
    boolean found = false;
    for (PrismReferenceValue val : linkRef.getValues()) {
        if (val.getOid().equals(accountOid)) {
            found = true;
        }
    }
    assertFalse("User " + user + " IS linked to account " + accountOid + " but not expecting it", found);
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 43 with PrismReferenceValue

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

the class TestOrgSync method assertResponsibility.

private String assertResponsibility(PrismObject<UserType> user, String respName) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, DirectoryException, ExpressionEvaluationException {
    String respRoleName = "R_" + respName;
    PrismObject<RoleType> respRole = searchObjectByName(RoleType.class, respRoleName);
    assertNotNull("No role for responsibility " + respName);
    display("Responsibility role for " + respName, respRole);
    assertAssignedRole(user, respRole.getOid());
    PrismReferenceValue linkRef = getSingleLinkRef(respRole);
    PrismObject<ShadowType> shadow = getShadowModel(linkRef.getOid());
    display("Role " + respRoleName + " shadow", shadow);
    // TODO assert shadow content
    String groupDn = "cn=" + respRoleName + ",ou=groups," + openDJController.getSuffix();
    Entry groupEntry = openDJController.fetchAndAssertEntry(groupDn, "groupOfUniqueNames");
    display("Group entry", groupEntry);
    PrismReferenceValue accountLinkRef = getLinkRef(user, RESOURCE_OPENDJ_OID);
    PrismObject<ShadowType> accountShadow = getShadowModel(accountLinkRef.getOid());
    String accountDn = IntegrationTestTools.getSecondaryIdentifier(accountShadow);
    openDJController.assertUniqueMember(groupEntry, accountDn);
    IntegrationTestTools.assertAssociation(accountShadow, OPENDJ_ASSOCIATION_GROUP_NAME, shadow.getOid());
    return respRole.getOid();
}
Also used : Entry(org.opends.server.types.Entry) SearchResultEntry(org.opends.server.types.SearchResultEntry) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 44 with PrismReferenceValue

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

the class TestOrgSync method assertBasicRoleAndResources.

private void assertBasicRoleAndResources(PrismObject<UserType> user) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    assertAssignedRole(user, ROLE_BASIC_OID);
    PrismReferenceValue linkRef = getLinkRef(user, RESOURCE_OPENDJ_OID);
    PrismObject<ShadowType> shadow = getShadowModel(linkRef.getOid());
    display("OpenDJ shadow linked to " + user, shadow);
// TODO assert shadow content
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 45 with PrismReferenceValue

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

the class RAuditEventRecord method toRepo.

public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
    Validate.notNull(record, "Audit event record must not be null.");
    Validate.notNull(prismContext, "Prism context must not be null.");
    RAuditEventRecord repo = new RAuditEventRecord();
    if (record.getRepoId() != null) {
        repo.setId(record.getRepoId());
    }
    repo.setChannel(record.getChannel());
    if (record.getTimestamp() != null) {
        repo.setTimestamp(new Timestamp(record.getTimestamp()));
    }
    repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
    repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
    repo.setSessionIdentifier(record.getSessionIdentifier());
    repo.setEventIdentifier(record.getEventIdentifier());
    repo.setHostIdentifier(record.getHostIdentifier());
    repo.setRemoteHostAddress(record.getRemoteHostAddress());
    repo.setNodeIdentifier(record.getNodeIdentifier());
    repo.setParameter(record.getParameter());
    repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
    if (record.getOutcome() != null) {
        repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
    }
    repo.setTaskIdentifier(record.getTaskIdentifier());
    repo.setTaskOID(record.getTaskOID());
    repo.setResult(record.getResult());
    try {
        if (record.getTarget() != null) {
            PrismReferenceValue target = record.getTarget();
            repo.setTargetName(getOrigName(target));
            repo.setTargetOid(target.getOid());
            repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
        }
        if (record.getTargetOwner() != null) {
            PrismObject targetOwner = record.getTargetOwner();
            repo.setTargetOwnerName(getOrigName(targetOwner));
            repo.setTargetOwnerOid(targetOwner.getOid());
        }
        if (record.getInitiator() != null) {
            PrismObject<UserType> initiator = record.getInitiator();
            repo.setInitiatorName(getOrigName(initiator));
            repo.setInitiatorOid(initiator.getOid());
        }
        for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
            if (delta == null) {
                continue;
            }
            ObjectDelta<?> objectDelta = delta.getObjectDelta();
            for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
                ItemPath path = itemDelta.getPath();
                if (path != null) {
                    // TODO what if empty?
                    CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
                    for (int i = 0; i < canonical.size(); i++) {
                        RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
                        repo.getChangedItems().add(changedItem);
                    }
                }
            }
            RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
            rDelta.setTransient(true);
            rDelta.setRecord(repo);
            repo.getDeltas().add(rDelta);
        }
        for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
            for (String propertyValue : propertyEntry.getValue()) {
                repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
            }
        }
        for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
            for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
                repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
            }
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    return repo;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) Timestamp(java.sql.Timestamp) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

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