use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class ResourceManager method completeResource.
/**
* Make sure that the resource is complete.
*
* It will check if the resource has a sufficiently fresh schema, etc.
*
* Returned resource may be the same or may be a different instance, but it
* is guaranteed that it will be "fresher" and will correspond to the
* repository state (assuming that the provided resource also corresponded
* to the repository state).
*
* The connector schema that was fetched before can be supplied to this
* method. This is just an optimization. It comes handy e.g. in test
* connection case.
*
* Note: This is not really the best place for this method. Need to figure
* out correct place later.
*
* @param repoResource
* Resource to check
* @param resourceSchema
* schema that was freshly pre-fetched (or null)
* @param parentResult
*
* @return completed resource
*/
private PrismObject<ResourceType> completeResource(PrismObject<ResourceType> repoResource, ResourceSchema resourceSchema, boolean fetchedSchema, Map<String, Collection<Object>> capabilityMap, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
// do not add as a subresult..it will be added later, if the completing
// of resource will be successfull.if not, it will be only set as a
// fetch result in the resource..
OperationResult result = parentResult.createMinorSubresult(OPERATION_COMPLETE_RESOURCE);
try {
applyConnectorSchemaToResource(repoResource, task, result);
} catch (SchemaException e) {
String message = "Schema error while applying connector schema to connectorConfiguration section of " + repoResource + ": " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
} catch (ObjectNotFoundException e) {
String message = "Object not found error while processing connector configuration of " + repoResource + ": " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
} catch (RuntimeException e) {
String message = "Unexpected error while processing connector configuration of " + repoResource + ": " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
}
PrismObject<ResourceType> newResource;
if (isComplete(repoResource)) {
// The resource is complete.
newResource = repoResource;
} else {
if (GetOperationOptions.isNoFetch(options)) {
// We need to fetch schema, but the noFetch option is specified. Therefore return whatever we have.
result.recordSuccessIfUnknown();
return repoResource;
}
try {
completeSchemaAndCapabilities(repoResource, resourceSchema, fetchedSchema, capabilityMap, task, result);
} catch (Exception ex) {
// Catch the exceptions. There are not critical. We need to catch them all because the connector may
// throw even undocumented runtime exceptions.
// Even non-complete resource may still be usable. The fetchResult indicates that there was an error
result.recordPartialError("Cannot complete resource schema and capabilities: " + ex.getMessage(), ex);
return repoResource;
}
try {
// Now we need to re-read the resource from the repository and re-aply the schemas. This ensures that we will
// cache the correct version and that we avoid race conditions, etc.
newResource = repositoryService.getObject(ResourceType.class, repoResource.getOid(), null, result);
applyConnectorSchemaToResource(newResource, task, result);
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
} catch (ObjectNotFoundException e) {
result.recordFatalError(e);
throw e;
} catch (RuntimeException e) {
result.recordFatalError(e);
throw e;
}
}
try {
// make sure it has parsed resource and refined schema. We are going to cache
// it, so we want to cache it with the parsed schemas
RefinedResourceSchemaImpl.getResourceSchema(newResource, prismContext);
RefinedResourceSchemaImpl.getRefinedSchema(newResource);
} catch (SchemaException e) {
String message = "Schema error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return newResource;
} catch (RuntimeException e) {
String message = "Unexpected error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return newResource;
}
result.recordSuccessIfUnknown();
return newResource;
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method applyDefinition.
@Override
@SuppressWarnings("unchecked")
public <T extends ObjectType> void applyDefinition(PrismObject<T> object, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".applyDefinition");
result.addParam(OperationResult.PARAM_OBJECT, object);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
try {
if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
getShadowCache(Mode.STANDARD).applyDefinition((PrismObject<ShadowType>) object, result);
} else if (ResourceType.class.isAssignableFrom(object.getCompileTimeClass())) {
resourceManager.applyDefinition((PrismObject<ResourceType>) object, task, result);
} else {
throw new IllegalArgumentException("Could not apply definition to object type: " + object.getCompileTimeClass());
}
result.computeStatus();
result.recordSuccessIfUnknown();
} catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class TestUnix method test300AddUserCapsizeUnixFail.
/* *************************************************************************** */
@Test
public void test300AddUserCapsizeUnixFail() throws Exception {
final String TEST_NAME = "test300AddUserCapsizeUnixFail";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestUnix.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<SequenceType> sequenceBefore = getObject(SequenceType.class, SEQUENCE_UIDNUMBER_OID);
display("Sequence before", sequenceBefore);
assertEquals("Wrong sequence counter (precondition)", USER_CAPSIZE_UID_NUMBER, sequenceBefore.asObjectable().getCounter().intValue());
assertTrue("Unexpected unused values in the sequence (precondition)", sequenceBefore.asObjectable().getUnusedValues().isEmpty());
PrismObject<UserType> user = createUser(USER_CAPSIZE_USERNAME, USER_CAPSIZE_FIST_NAME, USER_CAPSIZE_LAST_NAME, ROLE_UNIX_OID);
user.asObjectable().getEmployeeType().add("troublemaker");
try {
// WHEN
TestUtil.displayWhen(TEST_NAME);
addObject(user, task, result);
AssertJUnit.fail("Unexpected success");
} catch (ExpressionEvaluationException e) {
display("Expected exception", e);
// this is expected
}
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertFailure(result);
PrismObject<UserType> userAfter = findUserByUsername(USER_CAPSIZE_USERNAME);
display("User after", userAfter);
assertNull("User capsize sneaked in", userAfter);
PrismObject<SequenceType> sequenceAfter = getObject(SequenceType.class, SEQUENCE_UIDNUMBER_OID);
display("Sequence after", sequenceAfter);
assertEquals("Sequence haven't moved", USER_CAPSIZE_UID_NUMBER + 1, sequenceAfter.asObjectable().getCounter().intValue());
assertFalse("No unused values in the sequence", sequenceAfter.asObjectable().getUnusedValues().isEmpty());
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class MidPointQueryExecutor method parseQuery.
@Override
protected void parseQuery() {
try {
String s = dataset.getQuery().getText();
LOGGER.trace("query: " + s);
if (StringUtils.isEmpty(s)) {
query = null;
} else {
if (s.startsWith("<filter")) {
query = getParsedQuery(s, getParameters());
// getParsedQuery(s, expressionParameters);
} else if (s.startsWith("<code")) {
script = getParsedScript(s);
}
}
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw new SystemException(e.getMessage(), e);
}
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class ReportWebService method evaluateAuditScript.
@Override
public AuditEventRecordListType evaluateAuditScript(String script, RemoteReportParametersType parameters) {
try {
Map<QName, Object> params = getParamsMap(parameters);
Collection<AuditEventRecord> resultList = reportService.evaluateAuditScript(script, params);
return createAuditEventRecordListType(resultList);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
// TODO Auto-generated catch block
throw new Fault(e);
}
}
Aggregations