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);
}
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();
}
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;
}
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);
}
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);
}
Aggregations