Search in sources :

Example 36 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 37 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 38 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 39 with PrismObject

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

the class ObjectPolicyPanel method createObjectTemplateList.

protected IModel<List<ObjectTemplateConfigTypeReferenceDto>> createObjectTemplateList() {
    return new AbstractReadOnlyModel<List<ObjectTemplateConfigTypeReferenceDto>>() {

        @Override
        public List<ObjectTemplateConfigTypeReferenceDto> getObject() {
            List<PrismObject<ObjectTemplateType>> templateList = null;
            List<ObjectTemplateConfigTypeReferenceDto> list = new ArrayList<>();
            OperationResult result = new OperationResult(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
            Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
            try {
                templateList = getPageBase().getModelService().searchObjects(ObjectTemplateType.class, new ObjectQuery(), null, task, result);
                result.recomputeStatus();
            } catch (Exception e) {
                result.recordFatalError("Could not get list of object templates", e);
                LoggingUtils.logUnexpectedException(LOGGER, "Could not get list of object templates", e);
            // TODO - show this error in GUI
            }
            if (templateList != null) {
                ObjectTemplateType template;
                for (PrismObject<ObjectTemplateType> obj : templateList) {
                    template = obj.asObjectable();
                    list.add(new ObjectTemplateConfigTypeReferenceDto(template.getOid(), WebComponentUtil.getName(template)));
                }
            }
            return list;
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectTemplateConfigTypeReferenceDto(com.evolveum.midpoint.web.page.admin.configuration.dto.ObjectTemplateConfigTypeReferenceDto) Task(com.evolveum.midpoint.task.api.Task) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 40 with PrismObject

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

the class PageDebugList method loadResources.

private List<ObjectViewDto> loadResources() {
    List<ObjectViewDto> objects = new ArrayList<>();
    try {
        OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
        List<PrismObject<ResourceType>> list = WebModelServiceUtils.searchObjects(ResourceType.class, null, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result, this, null);
        for (PrismObject obj : list) {
            ObjectViewDto dto = new ObjectViewDto(obj.getOid(), WebComponentUtil.getName(obj));
            objects.add(dto);
        }
    } catch (Exception ex) {
    // todo implement error handling
    }
    Collections.sort(objects, (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()));
    return objects;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectViewDto(com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)696 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)484 Test (org.testng.annotations.Test)317 Task (com.evolveum.midpoint.task.api.Task)307 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)288 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)147 ArrayList (java.util.ArrayList)113 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)92 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)72 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)68 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 List (java.util.List)61 QName (javax.xml.namespace.QName)60 SystemException (com.evolveum.midpoint.util.exception.SystemException)46 File (java.io.File)46 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)44 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)42 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38