Search in sources :

Example 56 with ExpressionEvaluationException

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) TunnelException(com.evolveum.midpoint.util.exception.TunnelException)

Example 57 with ExpressionEvaluationException

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();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 58 with ExpressionEvaluationException

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 59 with ExpressionEvaluationException

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 60 with ExpressionEvaluationException

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Fault(org.apache.cxf.interceptor.Fault) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Aggregations

ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)120 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)93 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)92 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)71 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)71 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)69 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)59 Task (com.evolveum.midpoint.task.api.Task)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)32 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)28 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)26 QName (javax.xml.namespace.QName)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 ArrayList (java.util.ArrayList)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13 Collection (java.util.Collection)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12