Search in sources :

Example 56 with GetOperationOptions

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

the class TestResources method test055GetResourceNoFetchReadOnly.

/**
 * MID-3424
 */
@Test
public void test055GetResourceNoFetchReadOnly() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    // precondition
    assertCounterIncrement(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT, 0);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 0);
    rememberCounter(InternalCounters.PRISM_OBJECT_CLONE_COUNT);
    GetOperationOptions option = GetOperationOptions.createNoFetch();
    option.setReadOnly(true);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(option);
    when();
    PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, options, task, result);
    then();
    assertSuccess(result);
    display("Resource", resource);
    assertCounterIncrement(InternalCounters.PRISM_OBJECT_CLONE_COUNT, 1);
    assertResourceDummy(resource, false);
    assertNull("Schema sneaked in", ResourceTypeUtil.getResourceXsdSchema(resource));
    // Previous noFetch read did NOT place resource in the cache. Because the resource
    // may not be complete.
    assertCounterIncrement(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT, 1);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 0);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 57 with GetOperationOptions

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

the class TestResources method test105SearchResourcesIterativeNoFetch.

/**
 * MID-3424
 */
@Test
public void test105SearchResourcesIterativeNoFetch() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    // precondition
    assertSteadyResources();
    rememberCounter(InternalCounters.PRISM_OBJECT_CLONE_COUNT);
    final List<PrismObject<ResourceType>> resources = new ArrayList<>();
    ResultHandler<ResourceType> handler = (resource, parentResult) -> {
        assertResource(resource, false);
        resources.add(resource);
        return true;
    };
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
    when();
    modelService.searchObjectsIterative(ResourceType.class, null, handler, options, task, result);
    then();
    assertSuccess(result);
    assertFalse("Empty search return", resources.isEmpty());
    assertEquals("Unexpected number of resources found", 2, resources.size());
    // temporary (MID-5465)
    assertCounterIncrement(InternalCounters.PRISM_OBJECT_CLONE_COUNT, 2);
    // No explicit get. Search is doing all the work.
    assertCounterIncrement(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT, 0);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
    assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 0);
    assertSteadyResources();
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) EventResult(com.evolveum.midpoint.common.validator.EventResult) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Test(org.testng.annotations.Test) FailableFunction(com.evolveum.midpoint.util.FailableFunction) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) DOMUtil(com.evolveum.midpoint.util.DOMUtil) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Holder(com.evolveum.midpoint.util.Holder) InternalOperationClasses(com.evolveum.midpoint.schema.internals.InternalOperationClasses) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) Collection(java.util.Collection) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) Task(com.evolveum.midpoint.task.api.Task) List(java.util.List) CarefulAnt(com.evolveum.midpoint.repo.sql.testing.CarefulAnt) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) LegacyValidator(com.evolveum.midpoint.common.validator.LegacyValidator) Node(org.w3c.dom.Node) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) InternalCounters(com.evolveum.midpoint.schema.internals.InternalCounters) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) DummyResource(com.evolveum.icf.dummy.resource.DummyResource) ResourceCarefulAntUtil(com.evolveum.midpoint.repo.sql.testing.ResourceCarefulAntUtil) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Element(org.w3c.dom.Element) ItemName(com.evolveum.midpoint.prism.path.ItemName) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 58 with GetOperationOptions

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

the class ModelRestController method compare.

@PostMapping("/rpc/compare")
public <// @Consumes({ "application/xml" }) TODO do we need to limit it to XML?
T extends ObjectType> ResponseEntity<?> compare(@RequestParam(value = "readOptions", required = false) List<String> restReadOptions, @RequestParam(value = "compareOptions", required = false) List<String> restCompareOptions, @RequestParam(value = "ignoreItems", required = false) List<String> restIgnoreItems, @RequestBody PrismObject<T> clientObject) {
    Task task = initRequest();
    OperationResult result = task.getResult().createSubresult("compare");
    ResponseEntity<?> response;
    try {
        List<ItemPath> ignoreItemPaths = ItemPathCollectionsUtil.pathListFromStrings(restIgnoreItems, prismContext);
        final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions, DefinitionProcessingOption.ONLY_IF_EXISTS);
        Collection<SelectorOptions<GetOperationOptions>> readOptions = getOpOptions != null ? SelectorOptions.createCollection(getOpOptions) : null;
        ModelCompareOptions compareOptions = ModelCompareOptions.fromRestOptions(restCompareOptions);
        CompareResultType compareResult = modelService.compareObject(clientObject, readOptions, compareOptions, ignoreItemPaths, task, result);
        response = createResponse(HttpStatus.OK, compareResult, result);
    } catch (Exception ex) {
        response = handleException(result, ex);
    }
    result.computeStatus();
    finishRequest(task, result);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 59 with GetOperationOptions

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

the class DeleteRepositoryAction method deleteByFilter.

private void deleteByFilter(ObjectTypes type, ObjectQuery query, OperationStatus operation, OperationResult result) throws SchemaException {
    ResultHandler<?> handler = (prismObject, operationResult) -> {
        try {
            State state = options.isAsk() ? askForState(prismObject) : State.DELETE;
            switch(state) {
                case SKIP:
                    operation.incrementSkipped();
                    return true;
                case STOP:
                    return false;
                case DELETE:
                default:
            }
            RepositoryService repository = context.getRepository();
            repository.deleteObject(prismObject.getCompileTimeClass(), prismObject.getOid(), operationResult);
            operation.incrementTotal();
        } catch (ObjectNotFoundException ex) {
        // object was already gone
        } catch (IOException ex) {
            context.getLog().error("Couldn't delete object {}, reason: {}", ex, prismObject, ex.getMessage());
            operation.incrementError();
        }
        return true;
    };
    Collection<SelectorOptions<GetOperationOptions>> opts = new ArrayList<>();
    if (options.isRaw()) {
        opts.add(new SelectorOptions<>(GetOperationOptions.createRaw()));
    }
    RepositoryService repository = context.getRepository();
    repository.searchObjectsIterative(type.getClassDefinition(), query, handler, opts, true, result);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DeleteOptions(com.evolveum.midpoint.ninja.opts.DeleteOptions) InputStreamReader(java.io.InputStreamReader) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Modifier(java.lang.reflect.Modifier) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) BufferedReader(java.io.BufferedReader) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 60 with GetOperationOptions

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

the class ProjectionsLoadOperation method getOrCreateContextForValueToDelete.

private void getOrCreateContextForValueToDelete(@NotNull PrismReferenceValue refVal, @NotNull OperationResult result) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException {
    String oid = refVal.getOid();
    schemaCheck(oid != null, "Cannot delete account ref without an oid in %s", focusContext.getObjectCurrent());
    LensProjectionContext projectionContext;
    PrismObject<ShadowType> shadow;
    try {
        // Using NO_FETCH so we avoid reading in a full account. This is more efficient as we don't need full account here.
        // We need to fetch from provisioning and not repository so the correct definition will be set.
        Collection<SelectorOptions<GetOperationOptions>> options = SchemaService.get().getOperationOptionsBuilder().noFetch().build();
        shadow = beans.provisioningService.getObject(ShadowType.class, oid, options, task, result);
        // Create account context from retrieved object
        // TODO what about shadowSet etc?
        projectionContext = getOrCreateProjectionContext(shadow.asObjectable(), result).context;
        projectionContext.setLoadedObject(shadow);
        projectionContext.setExists(ShadowUtil.isExists(shadow.asObjectable()));
        LOGGER.trace("Loaded projection context: {}", projectionContext);
    } catch (ObjectNotFoundException e) {
        try {
            LOGGER.trace("Broken linkRef? We need to try again with raw options, because the error could be " + "thrown because of non-existent resource", e);
            Collection<SelectorOptions<GetOperationOptions>> options = SchemaService.get().getOperationOptionsBuilder().raw().build();
            shadow = beans.provisioningService.getObject(ShadowType.class, oid, options, task, result);
            projectionContext = getOrCreateEmptyGoneProjectionContext(oid);
            projectionContext.setFresh(true);
            projectionContext.setExists(false);
            projectionContext.setShadowExistsInRepo(false);
            LOGGER.trace("Loaded projection context: {}", projectionContext);
            OperationResult getObjectSubresult = result.getLastSubresult();
            getObjectSubresult.setErrorsHandled();
        } catch (ObjectNotFoundException ex) {
            // This is still OK. It means deleting an accountRef that points to non-existing object just log a warning
            LOGGER.warn("Deleting accountRef of " + focusContext.getObjectCurrent() + " that points to non-existing OID " + oid);
            return;
        }
    }
    if (refVal.getObject() == null) {
        projectionContext.setSynchronizationIntent(SynchronizationIntent.UNLINK);
    } else {
        // I.e. this is when we request to delete link containing full object.
        projectionContext.setSynchronizationIntent(SynchronizationIntent.DELETE);
        projectionContext.setPrimaryDeltaAfterStart(shadow.createDeleteDelta());
    }
    projectionContext.setFresh(true);
}
Also used : GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)62 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)32 Task (com.evolveum.midpoint.task.api.Task)23 Collection (java.util.Collection)16 Test (org.testng.annotations.Test)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 NotNull (org.jetbrains.annotations.NotNull)11 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)10 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 QName (javax.xml.namespace.QName)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 com.evolveum.midpoint.util.exception (com.evolveum.midpoint.util.exception)7 List (java.util.List)7 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)6 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 UniformItemPath (com.evolveum.midpoint.prism.path.UniformItemPath)5 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)5