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