private <T> T convertScalarResult(Class<T> expectedType, Function<Object, Object> additionalConvertor, Object rawValue, String contextDescription) throws ExpressionEvaluationException { try { T convertedValue = ExpressionUtil.convertValue(expectedType, additionalConvertor, rawValue, protector, prismContext); return convertedValue; } catch (IllegalArgumentException e) { throw new ExpressionEvaluationException(e.getMessage() + " in " + contextDescription, e); } }
public static <V extends PrismValue> V getExpressionOutputValue(PrismValueDeltaSetTriple<V> outputTriple, String shortDesc) throws ExpressionEvaluationException { if (outputTriple == null) { return null; } Collection<V> nonNegativeValues = outputTriple.getNonNegativeValues(); if (nonNegativeValues == null || nonNegativeValues.isEmpty()) { return null; } if (nonNegativeValues.size() > 1) { throw new ExpressionEvaluationException("Expression returned more than one value (" + nonNegativeValues.size() + ") in " + shortDesc); } return nonNegativeValues.iterator().next(); }
private CompiledScript createCompiledScript(String codeString, String contextDescription) throws ExpressionEvaluationException { CompiledScript compiledScript = scriptCache.get(codeString); if (compiledScript != null) { return compiledScript; } try { InternalMonitor.recordCount(InternalCounters.SCRIPT_COMPILE_COUNT); compiledScript = ((Compilable)scriptEngine).compile(codeString); } catch (ScriptException e) { throw new ExpressionEvaluationException(e.getMessage() + " in " + contextDescription, e); } scriptCache.put(codeString, compiledScript); return compiledScript; }
throw new ExpressionEvaluationException("No script code in " + contextDescription); evalRawResult = compiledScript.eval(bindings); } catch (Throwable e) { throw new ExpressionEvaluationException(e.getMessage() + " in " + contextDescription, e);
Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues(); if (nonNegativeValues == null || nonNegativeValues.isEmpty()) { throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned more than one value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc);
Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues(); if (nonNegativeValues == null || nonNegativeValues.isEmpty()) { throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned more than one value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc); throw new ExpressionEvaluationException("Expression returned no value ("+nonNegativeValues.size()+") in "+shortDesc);
private ResourceType resolveResource(ShadowType shadow, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException { if (shadow.getResource() != null) { return shadow.getResource(); } ObjectReferenceType ref = shadow.getResourceRef(); if (ref == null) { throw new ExpressionEvaluationException("Resource shadow object " + shadow + " doesn't have defined resource."); } if (ref.getOid() == null) { throw new ExpressionEvaluationException("Resource shadow object " + shadow + " defines null resource OID."); } return modelObjectResolver.getObjectSimple(ResourceType.class, ref.getOid(), null, null, result); }
public String evaluateExpression(ShadowType shadow, ExpressionType expressionType, String shortDesc, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException { Validate.notNull(shadow, "Resource object shadow must not be null."); Validate.notNull(expressionType, "Expression must not be null."); Validate.notNull(result, "Operation result must not be null."); ResourceType resource = resolveResource(shadow, result); ExpressionVariables variables = getDefaultXPathVariables(null, shadow, resource); PrismPropertyDefinition<String> outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_STRING); Expression<PrismPropertyValue<String>,PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result); ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result); PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result); if (outputTriple == null) { return null; } Collection<PrismPropertyValue<String>> nonNegativeValues = outputTriple.getNonNegativeValues(); if (nonNegativeValues == null || nonNegativeValues.isEmpty()) { return null; } if (nonNegativeValues.size() > 1) { throw new ExpressionEvaluationException("Expression returned more than one value ("+nonNegativeValues.size()+") in "+shortDesc); } return nonNegativeValues.iterator().next().getValue(); }
((Containerable) value).asPrismContainerValue().applyDefinition(definition); } catch (SchemaException e) { throw new ExpressionEvaluationException(e.getMessage() + " " + contextDescription, e); ((PrismContainerValue) value).applyDefinition(definition); } catch (SchemaException e) { throw new ExpressionEvaluationException(e.getMessage() + " " + contextDescription, e); throw new ExpressionEvaluationException("Expected Containerable or PrismContainerValue as expression output, got "+value.getClass());
@Override public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException { Source<V,D> source; if (context.getSources().isEmpty()) { throw new ExpressionEvaluationException("asIs evaluator cannot work without a source in "+ context.getContextDescription()); } if (context.getSources().size() > 1) { Source<V,D> defaultSource = (Source<V,D>) context.getDefaultSource(); if (defaultSource != null) { source = defaultSource; } else { throw new ExpressionEvaluationException("asIs evaluator cannot work with more than one source ("+ context.getSources().size() +" sources specified) without specification of a default source, in "+ context.getContextDescription()); } } else { source = (Source<V,D>) context.getSources().iterator().next(); } PrismValueDeltaSetTriple<V> sourceTriple = ItemDeltaUtil.toDeltaSetTriple(source.getItemOld(), source.getDelta(), prismContext); if (sourceTriple == null) { return null; } return ExpressionUtil.toOutputTriple(sourceTriple, outputDefinition, context.getAdditionalConvertor(), source.getResidualPath(), protector, prismContext); }
public static <D extends ItemDefinition> Object convertToOutputValue(String stringValue, D outputDefinition, Protector protector) throws ExpressionEvaluationException, SchemaException { if (stringValue == null) { return null; } QName outputType = outputDefinition.getTypeName(); if (outputType.equals(DOMUtil.XSD_STRING)) { return stringValue; } else if (outputType.equals(ProtectedStringType.COMPLEX_TYPE)) { try { return protector.encryptString(stringValue); } catch (EncryptionException e) { throw new ExpressionEvaluationException("Crypto error: " + e.getMessage(), e); } } else if (XmlTypeConverter.canConvert(outputType)) { Class<?> outputJavaType = XsdTypeMapper.toJavaType(outputType); try { return XmlTypeConverter.toJavaValue(stringValue, outputJavaType, true); } catch (NumberFormatException e) { throw new SchemaException("Cannot convert string '" + stringValue + "' to data type " + outputType + ": invalid number format", e); } catch (IllegalArgumentException e) { throw new SchemaException("Cannot convert string '" + stringValue + "' to data type " + outputType + ": " + e.getMessage(), e); } } else { throw new IllegalArgumentException( "Expression cannot generate values for properties of type " + outputType); } }
throw new ExpressionEvaluationException("Expression returned more than one value (" + nonNegativeValues.size() + ") in " + shortDesc); throw new ExpressionEvaluationException(e.getMessage(), e);
throw new ExpressionEvaluationException("Expression "+valueExpression+" evaluated to no value");
throw new ExpressionEvaluationException(desc+" returned more than one value ("+outputValues.size()+" values)");
throw new ExpressionEvaluationException("Iteration token expression in "+accountContext.getHumanReadableName()+" returned more than one value ("+outputValues.size()+" values)");
ExpressionEvaluationException e = new ExpressionEvaluationException("Illegal number of maximum value generation attempts: "+maxAttempts); result.recordFatalError(e); throw e; generatedValue = generateAttempt(policy, defaultLength, generateMinimalSize, ctx, result); if (result.isError()) { throw new ExpressionEvaluationException(result.getMessage()); ExpressionEvaluationException e = new ExpressionEvaluationException("Unable to generate value, maximum number of attempts ("+maxAttempts+") exceeded"); result.recordFatalError(e); throw e;
@Override protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params) throws SchemaException, ExpressionEvaluationException { RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION); if (rAssocTargetDef == null) { throw new ExpressionEvaluationException("No association target object class definition variable in "+ params.getContextDescription()+"; the expression may be used in a wrong place. It is only supposed to create an association."); } ObjectFilter resourceFilter = ObjectQueryUtil.createResourceFilter(rAssocTargetDef.getResourceOid(), getPrismContext()); ObjectFilter objectClassFilter = ObjectQueryUtil.createObjectClassFilter(rAssocTargetDef.getObjectClassDefinition().getTypeName(), getPrismContext()); ObjectFilter extendedFilter = getPrismContext().queryFactory().createAnd(resourceFilter, objectClassFilter, query.getFilter()); query.setFilter(extendedFilter); return query; }
+ " resolution in " + contextDescription + ": " + e.getMessage(), e); } catch (ExpressionEvaluationException e) { throw new ExpressionEvaluationException("Expression evaluation error during variable " + varDesc + " resolution in " + contextDescription + ": " + e.getMessage(), e);
} catch (ExpressionEvaluationException ex) { LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName()); throw new ExpressionEvaluationException("Couldn't confirm user " + user.getElementName(), ex); } catch (ObjectNotFoundException ex) { LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName());
} catch (ObjectAlreadyExistsException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) { throw new ExpressionEvaluationException(e.getMessage(), e);