Search in sources :

Example 11 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class PolicyRuleProcessor method getNumberOfAssigneesExceptMyself.

/**
	 * Returns numbers of assignees with the given relation name.
	 */
private int getNumberOfAssigneesExceptMyself(AbstractRoleType target, String selfOid, QName relation, OperationResult result) throws SchemaException {
    S_AtomicFilterExit q = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(target.getOid());
    if (selfOid != null) {
        q = q.and().not().id(selfOid);
    }
    ObjectQuery query = q.build();
    List<PrismObject<FocusType>> assignees = repositoryService.searchObjects(FocusType.class, query, null, result);
    int count = 0;
    assignee: for (PrismObject<FocusType> assignee : assignees) {
        for (AssignmentType assignment : assignee.asObjectable().getAssignment()) {
            if (assignment.getTargetRef() != null && ObjectTypeUtil.relationsEquivalent(relation, assignment.getTargetRef().getRelation())) {
                count++;
                continue assignee;
            }
        }
    }
    return count;
}
Also used : S_AtomicFilterExit(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 12 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class FocusConstraintsChecker method checkPropertyUniqueness.

private <T> boolean checkPropertyUniqueness(PrismObject<F> objectNew, ItemPath propPath, LensContext<F> context, OperationResult result) throws SchemaException {
    PrismProperty<T> property = objectNew.findProperty(propPath);
    if (property == null || property.isEmpty()) {
        throw new SchemaException("No property " + propPath + " in new object " + objectNew + ", cannot check uniqueness");
    }
    String oid = objectNew.getOid();
    ObjectQuery query = QueryBuilder.queryFor(objectNew.getCompileTimeClass(), prismContext).itemAs(property).build();
    List<PrismObject<F>> foundObjects = repositoryService.searchObjects(objectNew.getCompileTimeClass(), query, null, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Uniqueness check of {}, property {} resulted in {} results, using query:\n{}", new Object[] { objectNew, propPath, foundObjects.size(), query.debugDump() });
    }
    if (foundObjects.isEmpty()) {
        return true;
    }
    if (foundObjects.size() > 1) {
        LOGGER.trace("Found more than one object with property " + propPath + " = " + property);
        message("Found more than one object with property " + propPath + " = " + property);
        return false;
    }
    LOGGER.trace("Comparing {} and {}", foundObjects.get(0).getOid(), oid);
    boolean match = foundObjects.get(0).getOid().equals(oid);
    if (!match) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Found conflicting existing object with property " + propPath + " = " + property + ":\n" + foundObjects.get(0).debugDump());
        }
        message("Found conflicting existing object with property " + propPath + " = " + property + ": " + foundObjects.get(0));
        conflictingObject = foundObjects.get(0);
    }
    return match;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 13 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class SearchPanel method searchPerformed.

void searchPerformed(AjaxRequestTarget target) {
    PageBase page = (PageBase) getPage();
    PrismContext ctx = page.getPrismContext();
    Search search = getModelObject();
    ObjectQuery query = search.createObjectQuery(ctx);
    LOG.debug("Created query: {}", query);
    searchPerformed(query, target);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 14 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class SearchFormPanel method initLayout.

protected void initLayout() {
    final Form searchForm = new Form(ID_SEARCH_FORM);
    add(searchForm);
    searchForm.setOutputMarkupId(true);
    SearchPanel search = new SearchPanel(ID_SEARCH, getModel()) {

        @Override
        public void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
            SearchFormPanel.this.searchPerformed(query, target);
        }
    };
    searchForm.add(search);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Form(org.apache.wicket.markup.html.form.Form) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 15 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class PageTaskAdd method createResourceList.

private List<TaskAddResourcesDto> createResourceList() {
    OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
    Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
    List<PrismObject<ResourceType>> resources = null;
    List<TaskAddResourcesDto> resourceList = new ArrayList<TaskAddResourcesDto>();
    try {
        resources = getModelService().searchObjects(ResourceType.class, new ObjectQuery(), null, task, result);
        result.recomputeStatus();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get resource list.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resource list", ex);
    }
    // }
    if (resources != null) {
        ResourceType item = null;
        for (PrismObject<ResourceType> resource : resources) {
            item = resource.asObjectable();
            resourceList.add(new TaskAddResourcesDto(item.getOid(), WebComponentUtil.getOrigStringFromPoly(item.getName())));
        }
    }
    return resourceList;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TaskAddResourcesDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)355 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)241 PrismObject (com.evolveum.midpoint.prism.PrismObject)217 Test (org.testng.annotations.Test)159 Task (com.evolveum.midpoint.task.api.Task)150 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)67 QName (javax.xml.namespace.QName)58 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)50 ArrayList (java.util.ArrayList)50 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)38 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)35 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)33 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)30 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)21 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)17 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)16