Search in sources :

Example 66 with PrismObject

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

the class ShadowIntegrityCheckResultHandler method deleteShadows.

// shadowsToDelete do not contain 'already deleted shadows'
private void deleteShadows(DuplicateShadowsTreatmentInstruction instruction, StringBuilder sb, Task task, OperationResult result) {
    LOGGER.trace("Going to delete shadows:\n{}", instruction);
    if (instruction == null || instruction.getShadowsToDelete() == null) {
        return;
    }
    Collection<PrismObject<ShadowType>> shadowsToDelete = instruction.getShadowsToDelete();
    String shadowOidToReplaceDeleted = instruction.getShadowOidToReplaceDeletedOnes();
    for (PrismObject<ShadowType> shadowToDelete : shadowsToDelete) {
        LOGGER.info("Deleting redundant shadow{} {}", skippedForDryRun(), ObjectTypeUtil.toShortString(shadowToDelete));
        sb.append("   --> deleted redundant shadow").append(skippedForDryRun()).append(" ").append(ObjectTypeUtil.toShortString(shadowToDelete)).append("\n");
        String oid = shadowToDelete.getOid();
        List<PrismObject<FocusType>> owners;
        if (checkOwners) {
            owners = (List) shadowToDelete.getUserData(KEY_OWNERS);
        } else {
            owners = searchOwners(shadowToDelete, result);
        }
        if (!dryRun) {
            try {
                repositoryService.deleteObject(ShadowType.class, oid, result);
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, null);
                duplicateShadowsDeleted.add(oid);
            } catch (ObjectNotFoundException e) {
                // suspicious, but not a big deal
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logExceptionAsWarning(LOGGER, "Shadow {} couldn't be deleted, because it does not exist anymore", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            } catch (RuntimeException e) {
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logUnexpectedException(LOGGER, "Shadow {} couldn't be deleted because of an unexpected exception", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            }
        }
        if (owners == null || owners.isEmpty()) {
            continue;
        }
        for (PrismObject owner : owners) {
            List<ItemDelta> modifications = new ArrayList<>(2);
            ReferenceDelta deleteDelta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(oid, ShadowType.COMPLEX_TYPE));
            modifications.add(deleteDelta);
            if (shadowOidToReplaceDeleted != null) {
                ReferenceDelta addDelta = ReferenceDelta.createModificationAdd(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(shadowOidToReplaceDeleted, ShadowType.COMPLEX_TYPE));
                modifications.add(addDelta);
            }
            LOGGER.info("Executing modify delta{} for owner {}:\n{}", skippedForDryRun(), ObjectTypeUtil.toShortString(owner), DebugUtil.debugDump(modifications));
            if (!dryRun) {
                try {
                    repositoryService.modifyObject((Class) owner.getClass(), owner.getOid(), modifications, result);
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, null);
                } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, e);
                    LoggingUtils.logUnexpectedException(LOGGER, "Focal object {} (owner of {}) couldn't be updated", e, ObjectTypeUtil.toShortString(owner), ObjectTypeUtil.toShortString(shadowToDelete));
                }
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 67 with PrismObject

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

the class ShadowIntegrityCheckResultHandler method searchOwners.

private List<PrismObject<FocusType>> searchOwners(PrismObject<ShadowType> shadow, OperationResult result) {
    try {
        ObjectQuery ownerQuery = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_LINK_REF).ref(shadow.getOid()).build();
        List<PrismObject<FocusType>> owners = repositoryService.searchObjects(FocusType.class, ownerQuery, null, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Owners for {}: {}", ObjectTypeUtil.toShortString(shadow), owners);
        }
        return owners;
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create/execute owners query for shadow {}", e, ObjectTypeUtil.toShortString(shadow));
        return null;
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 68 with PrismObject

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

the class ShadowIntegrityCheckResultHandler method addIdentifierValue.

private void addIdentifierValue(ShadowCheckResult checkResult, ObjectTypeContext context, QName identifierName, String identifierValue, PrismObject<ShadowType> shadow) {
    Map<String, List<PrismObject<ShadowType>>> valueMap = context.getIdentifierValueMap().get(identifierName);
    if (valueMap == null) {
        valueMap = new HashMap<>();
        context.getIdentifierValueMap().put(identifierName, valueMap);
    }
    List<PrismObject<ShadowType>> existingShadows = valueMap.get(identifierValue);
    if (existingShadows == null) {
        // all is well
        existingShadows = new ArrayList();
        existingShadows.add(shadow);
        valueMap.put(identifierValue, existingShadows);
    } else {
        // duplicate shadows statistics are collected in a special way
        duplicateShadowsDetected.add(shadow.getOid());
        LOGGER.error("Multiple shadows with the value of identifier attribute {} = {}: existing one(s): {}, duplicate: {}", identifierName, identifierValue, shortDumpList(existingShadows), ObjectTypeUtil.toShortString(shadow.asObjectable()));
        existingShadows.add(shadow);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 69 with PrismObject

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

the class ModelDiagController method repositorySelfTestUser.

private void repositorySelfTestUser(Task task, OperationResult testResult) {
    OperationResult result = testResult.createSubresult(REPOSITORY_SELF_TEST_USER);
    PrismObject<UserType> user;
    try {
        user = getObjectDefinition(UserType.class).instantiate();
    } catch (SchemaException e) {
        result.recordFatalError(e);
        return;
    }
    UserType userType = user.asObjectable();
    String name = generateRandomName();
    PolyStringType namePolyStringType = toPolyStringType(name);
    userType.setName(namePolyStringType);
    result.addContext("name", name);
    userType.setDescription(SelfTestData.POLICIJA);
    userType.setFullName(toPolyStringType(USER_FULL_NAME));
    userType.setGivenName(toPolyStringType(USER_GIVEN_NAME));
    userType.setFamilyName(toPolyStringType(USER_FAMILY_NAME));
    userType.setTitle(toPolyStringType(INSANE_NATIONAL_STRING));
    userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[0]);
    userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[1]);
    userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[0]));
    userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[1]));
    String oid;
    try {
        oid = repositoryService.addObject(user, null, result);
    } catch (ObjectAlreadyExistsException | SchemaException | RuntimeException e) {
        result.recordFatalError(e);
        return;
    }
    try {
        {
            OperationResult subresult = result.createSubresult(result.getOperation() + ".getObject");
            PrismObject<UserType> userRetrieved;
            try {
                userRetrieved = repositoryService.getObject(UserType.class, oid, null, subresult);
            } catch (ObjectNotFoundException | SchemaException | RuntimeException e) {
                result.recordFatalError(e);
                return;
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Self-test:user getObject:\n{}", userRetrieved.debugDump());
            }
            checkUser(userRetrieved, name, subresult);
            subresult.recordSuccessIfUnknown();
        }
        {
            OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.fullName");
            try {
                ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_FULL_NAME).eq(toPolyString(USER_FULL_NAME)).build();
                subresult.addParam("query", query);
                List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
                }
                assertSingleSearchResult("user", foundObjects, subresult);
                PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
                checkUser(userRetrieved, name, subresult);
                subresult.recordSuccessIfUnknown();
            } catch (SchemaException | RuntimeException e) {
                subresult.recordFatalError(e);
                return;
            }
        }
        // MID-1116
        {
            OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.employeeType");
            try {
                ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_EMPLOYEE_TYPE).eq(USER_EMPLOYEE_TYPE[0]).build();
                subresult.addParam("query", query);
                List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
                }
                assertSingleSearchResult("user", foundObjects, subresult);
                PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
                checkUser(userRetrieved, name, subresult);
                subresult.recordSuccessIfUnknown();
            } catch (SchemaException | RuntimeException e) {
                subresult.recordFatalError(e);
                return;
            }
        }
        // MID-1116
        {
            OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.organization");
            try {
                ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_ORGANIZATION).eq(toPolyString(USER_ORGANIZATION[1])).build();
                subresult.addParam("query", query);
                List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
                }
                assertSingleSearchResult("user", foundObjects, subresult);
                PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
                checkUser(userRetrieved, name, subresult);
                subresult.recordSuccessIfUnknown();
            } catch (SchemaException | RuntimeException e) {
                subresult.recordFatalError(e);
                return;
            }
        }
    } finally {
        try {
            repositoryService.deleteObject(UserType.class, oid, testResult);
        } catch (ObjectNotFoundException | RuntimeException e) {
            result.recordFatalError(e);
            return;
        }
        result.computeStatus();
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RandomString(com.evolveum.midpoint.util.RandomString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) List(java.util.List)

Example 70 with PrismObject

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

the class OrgStructFunctionsImpl method getManagersOfOrg.

@Override
public Collection<UserType> getManagersOfOrg(String orgOid, boolean preAuthorized) throws SchemaException, SecurityViolationException {
    Set<UserType> retval = new HashSet<UserType>();
    OperationResult result = new OperationResult("getManagerOfOrg");
    PrismReferenceValue parentOrgRefVal = new PrismReferenceValue(orgOid, OrgType.COMPLEX_TYPE);
    parentOrgRefVal.setRelation(SchemaConstants.ORG_MANAGER);
    ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext).item(ObjectType.F_PARENT_ORG_REF).ref(parentOrgRefVal).build();
    List<PrismObject<ObjectType>> members = searchObjects(ObjectType.class, objectQuery, result, preAuthorized);
    for (PrismObject<ObjectType> member : members) {
        if (member.asObjectable() instanceof UserType) {
            UserType user = (UserType) member.asObjectable();
            retval.add(user);
        }
    }
    return retval;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)488 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)358 Test (org.testng.annotations.Test)227 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)219 Task (com.evolveum.midpoint.task.api.Task)205 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)97 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)95 ArrayList (java.util.ArrayList)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)79 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)64 QName (javax.xml.namespace.QName)59 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)50 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)40 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)37 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)37 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)37 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)37 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)37 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)34