Search in sources :

Example 61 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TestRetirement method reconcileAllOrgs.

private void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = createTask("reconcileAllOrgs");
    OperationResult result = task.getResult();
    ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {

        @Override
        public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
            try {
                display("reconciling " + object);
                reconcileOrg(object.getOid(), task, parentResult);
            } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                throw new SystemException(e.getMessage(), e);
            }
            return true;
        }
    };
    display("Reconciling all orgs");
    modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 62 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class SingleItemSerializationSafeContainerImpl method getValue.

@Override
public T getValue() {
    if (actualValue != null) {
        return actualValue;
    }
    if (valueForStorageWhenNotEncoded != null) {
        actualValue = valueForStorageWhenNotEncoded;
        return actualValue;
    }
    if (valueForStorageWhenEncoded != null) {
        if (prismContext == null) {
            throw new IllegalStateException("PrismContext not set for SerializationSafeContainer holding " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH));
        }
        if (encodingScheme == EncodingScheme.PRISM) {
            try {
                PrismValue prismValue = prismContext.parserFor(valueForStorageWhenEncoded).xml().parseItemValue();
                actualValue = prismValue != null ? prismValue.getRealValue() : null;
            } catch (SchemaException e) {
                throw new SystemException("Couldn't deserialize value from JAXB: " + StringUtils.abbreviate(valueForStorageWhenEncoded, MAX_WIDTH), e);
            }
            return actualValue;
        } else {
            throw new IllegalStateException("Unexpected encoding scheme " + encodingScheme);
        }
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 63 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class SingleItemSerializationSafeContainerImpl method setValue.

@Override
public void setValue(T value) {
    this.actualValue = value;
    checkPrismContext();
    if (value != null && prismContext.canSerialize(value)) {
        try {
            this.valueForStorageWhenEncoded = prismContext.xmlSerializer().serializeAnyData(value, new QName("value"));
        } catch (SchemaException e) {
            throw new SystemException("Couldn't serialize value of type " + value.getClass() + ": " + e.getMessage(), e);
        }
        this.valueForStorageWhenNotEncoded = null;
        encodingScheme = EncodingScheme.PRISM;
    } else if (value == null || value instanceof Serializable) {
        this.valueForStorageWhenNotEncoded = value;
        this.valueForStorageWhenEncoded = null;
        encodingScheme = EncodingScheme.NONE;
        if (value instanceof Itemable) {
            throw new IllegalStateException("Itemable value is used as not-encoded serializable item; value = " + value);
        }
    } else {
        throw new IllegalStateException("Attempt to put non-serializable item " + value.getClass() + " into " + this.getClass().getSimpleName());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Serializable(java.io.Serializable) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName)

Example 64 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ObjectRetriever method isAnySubordinateAttempt.

public boolean isAnySubordinateAttempt(String upperOrgOid, Collection<String> lowerObjectOids) {
    Session session = null;
    try {
        session = baseHelper.beginReadOnlyTransaction();
        Query query;
        if (lowerObjectOids.size() == 1) {
            query = session.getNamedQuery("isAnySubordinateAttempt.oneLowerOid");
            query.setString("dOid", lowerObjectOids.iterator().next());
        } else {
            query = session.getNamedQuery("isAnySubordinateAttempt.moreLowerOids");
            query.setParameterList("dOids", lowerObjectOids);
        }
        query.setString("aOid", upperOrgOid);
        Number number = (Number) query.uniqueResult();
        session.getTransaction().commit();
        return number != null && number.longValue() != 0L;
    } catch (RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, null);
    } finally {
        baseHelper.cleanupSessionAndResult(session, null);
    }
    throw new SystemException("isAnySubordinateAttempt failed somehow, this really should not happen.");
}
Also used : ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 65 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class PrimaryChangeAspectHelper method evaluateApplicabilityCondition.

//endregion
//region ========================================================================== Expression evaluation
public boolean evaluateApplicabilityCondition(PcpAspectConfigurationType config, ModelContext modelContext, Serializable itemToApprove, ExpressionVariables additionalVariables, PrimaryChangeAspect aspect, Task task, OperationResult result) {
    if (config == null || config.getApplicabilityCondition() == null) {
        return true;
    }
    ExpressionType expressionType = config.getApplicabilityCondition();
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
    ExpressionVariables expressionVariables = new ExpressionVariables();
    expressionVariables.addVariableDefinition(SchemaConstants.C_MODEL_CONTEXT, modelContext);
    expressionVariables.addVariableDefinition(SchemaConstants.C_ITEM_TO_APPROVE, itemToApprove);
    if (additionalVariables != null) {
        expressionVariables.addVariableDefinitions(additionalVariables);
    }
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple;
    try {
        Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, "applicability condition expression", task, result);
        ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, "applicability condition expression", task, result);
        exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | RuntimeException e) {
        // TODO report as a specific exception?
        throw new SystemException("Couldn't evaluate applicability condition in aspect " + aspect.getClass().getSimpleName() + ": " + e.getMessage(), e);
    }
    Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
    if (exprResult.size() == 0) {
        return false;
    } else if (exprResult.size() > 1) {
        throw new IllegalStateException("Applicability condition expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
    }
    Boolean boolResult = exprResult.iterator().next().getValue();
    return boolResult != null ? boolResult : false;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12