use of com.evolveum.midpoint.schema.cache.CacheConfigurationManager in project midpoint by Evolveum.
the class ResourceObjectConverter method searchResourceObjects.
public SearchResultMetadata searchResourceObjects(@NotNull ProvisioningContext ctx, @NotNull ResourceObjectHandler resultHandler, @Nullable ObjectQuery query, boolean fetchAssociations, @Nullable FetchErrorReportingMethodType errorReportingMethod, @NotNull OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
LOGGER.trace("Searching resource objects, query: {}, OC: {}", query, objectDefinition);
AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(ctx);
SearchHierarchyConstraints searchHierarchyConstraints = entitlementConverter.determineSearchHierarchyConstraints(ctx, parentResult);
if (InternalsConfig.consistencyChecks && query != null && query.getFilter() != null) {
query.getFilter().checkConsistence(true);
}
ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
AtomicInteger objectCounter = new AtomicInteger(0);
UcfFetchErrorReportingMethod ucfErrorReportingMethod;
if (errorReportingMethod == FetchErrorReportingMethodType.FETCH_RESULT) {
ucfErrorReportingMethod = UcfFetchErrorReportingMethod.UCF_OBJECT;
} else {
ucfErrorReportingMethod = UcfFetchErrorReportingMethod.EXCEPTION;
}
SearchResultMetadata metadata;
try {
metadata = connector.search(objectDefinition, query, (ucfObject, result) -> {
ResourceObjectFound objectFound = new ResourceObjectFound(ucfObject, ResourceObjectConverter.this, ctx, fetchAssociations);
// in order to utilize the cache right from the beginning...
RepositoryCache.enterLocalCaches(cacheConfigurationManager);
try {
int objectNumber = objectCounter.getAndIncrement();
Task task = ctx.getTask();
try {
OperationResult objResult = result.subresult(OperationConstants.OPERATION_SEARCH_RESULT).setMinor().addParam("number", objectNumber).addArbitraryObjectAsParam("primaryIdentifierValue", ucfObject.getPrimaryIdentifierValue()).addArbitraryObjectAsParam("errorState", ucfObject.getErrorState()).build();
try {
objectFound.initialize(task, objResult);
return resultHandler.handle(objectFound, objResult);
} catch (Throwable t) {
objResult.recordFatalError(t);
throw t;
} finally {
objResult.computeStatusIfUnknown();
// AbstractSummarizingResultHandler [lazyman]
if (objResult.isSuccess() && objResult.canBeCleanedUp()) {
objResult.getSubresults().clear();
}
// TODO Reconsider this. It is quite dubious to touch the global result from the inside.
result.summarize();
}
} finally {
RepositoryCache.exitLocalCaches();
}
} catch (RuntimeException e) {
throw e;
} catch (Throwable t) {
throw new TunnelException(t);
}
}, attributesToReturn, objectDefinition.getPagedSearches(ctx.getResource()), searchHierarchyConstraints, ucfErrorReportingMethod, ctx.getUcfExecutionContext(), parentResult);
} catch (GenericFrameworkException e) {
parentResult.recordFatalError("Generic error in the connector: " + e.getMessage(), e);
throw new SystemException("Generic error in the connector: " + e.getMessage(), e);
} catch (CommunicationException ex) {
parentResult.recordFatalError("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
throw new CommunicationException("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
} catch (SecurityViolationException ex) {
parentResult.recordFatalError("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
throw new SecurityViolationException("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
} catch (TunnelException e) {
Throwable cause = e.getCause();
parentResult.recordFatalError("Problem while communicating with the connector " + connector + ": " + cause.getMessage(), cause);
if (cause instanceof SchemaException) {
throw (SchemaException) cause;
} else if (cause instanceof CommunicationException) {
throw (CommunicationException) cause;
} else if (cause instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) cause;
} else if (cause instanceof ConfigurationException) {
throw (ConfigurationException) cause;
} else if (cause instanceof SecurityViolationException) {
throw (SecurityViolationException) cause;
} else if (cause instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) cause;
} else if (cause instanceof GenericFrameworkException) {
throw new GenericConnectorException(cause.getMessage(), cause);
} else {
throw new SystemException(cause.getMessage(), cause);
}
}
computeResultStatus(parentResult);
LOGGER.trace("Searching resource objects done: {}", parentResult.getStatus());
return metadata;
}
Aggregations