Search in sources :

Example 6 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class WorkflowManagerImpl method searchContainers.

@SuppressWarnings("unchecked")
@Override
public <T extends Containerable> SearchResultList<T> searchContainers(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(DOT_INTERFACE + ".searchContainers");
    result.addParams(new String[] { "type", "query" }, type, query);
    result.addCollectionOfSerializablesAsParam("options", options);
    try {
        if (!WorkItemType.class.equals(type)) {
            throw new UnsupportedOperationException("searchContainers is available only for work items");
        }
        return (SearchResultList<T>) workItemProvider.searchWorkItems(query, options, result);
    } catch (SchemaException | RuntimeException e) {
        result.recordFatalError("Couldn't count items: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 7 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class TaskManagerQuartzImpl method searchNodes.

/*
     * Gets nodes from repository and adds runtime information to them (taken from ClusterStatusInformation).
     */
//    @Override
//    public int countNodes(ObjectQuery query, OperationResult result) throws SchemaException {
//        return repositoryService.countObjects(NodeType.class, query, result);
//    }
private SearchResultList<PrismObject<NodeType>> searchNodes(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    ClusterStatusInformation clusterStatusInformation = getClusterStatusInformation(options, NodeType.class, true, result);
    List<PrismObject<NodeType>> nodesInRepository;
    try {
        nodesInRepository = repositoryService.searchObjects(NodeType.class, query, options, result);
    } catch (SchemaException e) {
        result.recordFatalError("Couldn't get nodes from repository: " + e.getMessage());
        throw e;
    }
    List<PrismObject<NodeType>> list = new ArrayList<PrismObject<NodeType>>();
    if (clusterStatusInformation != null) {
        for (PrismObject<NodeType> nodeInRepositoryPrism : nodesInRepository) {
            NodeType returnedNode = nodeInRepositoryPrism.asObjectable();
            NodeType nodeRuntimeInfo = clusterStatusInformation.findNodeById(returnedNode.getNodeIdentifier());
            if (nodeRuntimeInfo != null) {
                returnedNode.setExecutionStatus(nodeRuntimeInfo.getExecutionStatus());
                returnedNode.setErrorStatus(nodeRuntimeInfo.getErrorStatus());
                returnedNode.setConnectionResult(nodeRuntimeInfo.getConnectionResult());
            } else {
                // node is in repo, but no information on it is present in CSI
                // (should not occur except for some temporary conditions, because CSI contains info on all nodes from repo)
                returnedNode.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR);
                OperationResult r = new OperationResult("connect");
                r.recordFatalError("Node not known at this moment");
                returnedNode.setConnectionResult(r.createOperationResultType());
            }
            list.add(returnedNode.asPrismObject());
        }
    } else {
        list = nodesInRepository;
    }
    LOGGER.trace("searchNodes returning {}", list);
    result.computeStatus();
    return new SearchResultList(list);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation)

Example 8 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class TestAdHocCertification method test020ModifyIndigo.

@Test
public void test020ModifyIndigo() throws Exception {
    final String TEST_NAME = "test020ModifyIndigo";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAdHocCertification.class.getName() + "." + TEST_NAME);
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    @SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<UserType> delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace("new description").item(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asObjectDelta(USER_INDIGO_OID);
    executeChanges(delta, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    SearchResultList<PrismObject<AccessCertificationCampaignType>> campaigns = repositoryService.searchObjects(AccessCertificationCampaignType.class, null, null, result);
    assertEquals("Wrong # of campaigns", 2, campaigns.size());
    AccessCertificationCampaignType campaign = campaigns.stream().filter(c -> MODIFICATION_CERT_DEF_OID.equals(c.asObjectable().getDefinitionRef().getOid())).findFirst().orElseThrow(() -> new AssertionError("No modification-triggered campaign")).asObjectable();
    campaign = getCampaignWithCases(campaign.getOid());
    display("campaign", campaign);
    // beware, maybe not all details would match (in the future) - then adapt this test
    assertAfterCampaignStart(campaign, modificationCertificationDefinition, 1);
    // no cases, no problems
    assertPercentComplete(campaign, 0, 0, 0);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) DeltaBuilder(com.evolveum.midpoint.prism.delta.builder.DeltaBuilder) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) PrismObject(com.evolveum.midpoint.prism.PrismObject) DebugUtil(com.evolveum.midpoint.util.DebugUtil) Task(com.evolveum.midpoint.task.api.Task) File(java.io.File) IntegrationTestTools.display(com.evolveum.midpoint.test.IntegrationTestTools.display) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrismContext(com.evolveum.midpoint.prism.PrismContext) ContextConfiguration(org.springframework.test.context.ContextConfiguration) TestUtil(com.evolveum.midpoint.test.util.TestUtil) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 9 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class ProvisioningServiceImpl method searchObjects.

@Override
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".searchObjects");
    result.addParam("objectType", type);
    result.addParam("query", query);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    final SearchResultList<PrismObject<T>> objListType = new SearchResultList<>(new ArrayList<PrismObject<T>>());
    SearchResultMetadata metadata;
    try {
        if (!ShadowType.class.isAssignableFrom(type)) {
            SearchResultList<PrismObject<T>> objects = searchRepoObjects(type, query, options, task, result);
            result.computeStatus();
            result.recordSuccessIfUnknown();
            result.cleanupResult();
            //				validateObjects(objects);
            return objects;
        }
        final ResultHandler<T> handler = (object, parentResult1) -> objListType.add(object);
        metadata = searchObjectsIterative(type, query, options, handler, task, result);
    } catch (ConfigurationException | SecurityViolationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Could not search objects: " + e.getMessage(), e);
        throw e;
    }
    result.computeStatus();
    result.cleanupResult();
    //		validateObjects(objListType);
    objListType.setMetadata(metadata);
    return objListType;
}
Also used : Primary(org.springframework.context.annotation.Primary) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ConnectorTestOperation(com.evolveum.midpoint.schema.constants.ConnectorTestOperation) PreDestroy(javax.annotation.PreDestroy) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) Objectable(com.evolveum.midpoint.prism.Objectable) Set(java.util.Set) ProvisioningDiag(com.evolveum.midpoint.schema.ProvisioningDiag) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) NoneFilter(com.evolveum.midpoint.prism.query.NoneFilter) Task(com.evolveum.midpoint.task.api.Task) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) QName(javax.xml.namespace.QName) Validate(org.apache.commons.lang.Validate) LabeledString(com.evolveum.midpoint.schema.LabeledString) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) CryptoUtil(com.evolveum.midpoint.common.crypto.CryptoUtil) Mode(com.evolveum.midpoint.provisioning.impl.ShadowCacheFactory.Mode) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ArrayList(java.util.ArrayList) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) Service(org.springframework.stereotype.Service) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConnectorOperationalStatus(com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus) FailedOperationTypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType) ConstraintsCheckingResult(com.evolveum.midpoint.provisioning.api.ConstraintsCheckingResult) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) OperationProvisioningScriptsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType) PrismObject(com.evolveum.midpoint.prism.PrismObject) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) RepoAddOptions(com.evolveum.midpoint.repo.api.RepoAddOptions) ProvisioningUtil(com.evolveum.midpoint.provisioning.util.ProvisioningUtil) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ProvisioningScriptType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 10 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class ProvisioningServiceImpl method searchRepoObjects.

@SuppressWarnings("unchecked")
private <T extends ObjectType> SearchResultList<PrismObject<T>> searchRepoObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws SchemaException {
    List<PrismObject<T>> repoObjects = null;
    // TODO: should searching connectors trigger rediscovery?
    Collection<SelectorOptions<GetOperationOptions>> repoOptions = null;
    if (GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options))) {
        repoOptions = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
    }
    repoObjects = getCacheRepositoryService().searchObjects(type, query, repoOptions, result);
    SearchResultList<PrismObject<T>> newObjListType = new SearchResultList(new ArrayList<PrismObject<T>>());
    for (PrismObject<T> repoObject : repoObjects) {
        OperationResult objResult = new OperationResult(ProvisioningService.class.getName() + ".searchObjects.object");
        try {
            PrismObject<T> completeResource = completeObject(type, repoObject, options, task, objResult);
            validateObject(completeResource);
            objResult.computeStatusIfUnknown();
            if (!objResult.isSuccess()) {
                // necessary e.g. to skip validation for resources that had issues when checked
                completeResource.asObjectable().setFetchResult(objResult.createOperationResultType());
                result.addSubresult(objResult);
            }
            newObjListType.add((PrismObject<T>) completeResource);
        // TODO: what else do to with objResult??
        } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
            LOGGER.error("Error while completing {}: {}. Using non-complete object.", new Object[] { repoObject, e.getMessage(), e });
            objResult.recordFatalError(e);
            repoObject.asObjectable().setFetchResult(objResult.createOperationResultType());
            newObjListType.add(repoObject);
            result.addSubresult(objResult);
            result.recordPartialError(e);
        } catch (RuntimeException e) {
            // FIXME: Strictly speaking, the runtime exception should
            // not be handled here.
            // The runtime exceptions should be considered fatal anyway
            // ... but some of the
            // ICF exceptions are still translated to system exceptions.
            // So this provides
            // a better robustness now.
            LOGGER.error("System error while completing {}: {}. Using non-complete object.", new Object[] { repoObject, e.getMessage(), e });
            objResult.recordFatalError(e);
            repoObject.asObjectable().setFetchResult(objResult.createOperationResultType());
            newObjListType.add(repoObject);
            result.addSubresult(objResult);
            result.recordPartialError(e);
        }
    }
    return newObjListType;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

SearchResultList (com.evolveum.midpoint.schema.SearchResultList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 Task (com.evolveum.midpoint.task.api.Task)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 DebugUtil (com.evolveum.midpoint.util.DebugUtil)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 ArrayList (java.util.ArrayList)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1