@NotNull private <T> T extractValue(PrismPropertyValue value, Class<T> returnType) throws SchemaException { ItemDefinition definition = value.getParent().getDefinition(); //todo raw types Object object = value.getValue(); if (object instanceof Element) { object = getRealRepoValue(definition, (Element) object, prismContext); } else if (object instanceof RawType) { RawType raw = (RawType) object; object = raw.getParsedRealValue(returnType); // todo this can return null! } else { object = getAggregatedRepoObject(object); } if (returnType.isAssignableFrom(object.getClass())) { return (T) object; } throw new IllegalStateException("Can't extract value for saving from prism property value " + value + " expected return type " + returnType + ", actual type " + (object == null ? null : object.getClass())); }
private static void addToPrismValues(List<PrismPropertyValue<?>> pVals, PrismContext prismContext, Object value) { if (value == null) { return; } if (value instanceof Collection) { for (Object o : (Collection) value) { addToPrismValues(pVals, prismContext, o); } return; } if (value.getClass().isArray()) { throw new IllegalStateException("Array within array in filter creation: " + value); } PrismPropertyValue<?> pVal; if (value instanceof PrismPropertyValue) { pVal = (PrismPropertyValue<?>) value; if (pVal.getParent() != null) { pVal = pVal.clone(); } } else { pVal = new PrismPropertyValueImpl<>(value); } PrismUtil.recomputePrismPropertyValue(pVal, prismContext); pVals.add(pVal); }
/** * Takes the definition from the definitionSource parameter and uses it to parse raw elements in origValue. * It returns a new parsed value without touching the original value. */ private PrismPropertyValue<T> parseRawElementToNewValue( PrismPropertyValue<T> origValue, PrismPropertyValue<T> definitionSource) throws SchemaException { if (definitionSource.getParent() != null && definitionSource.getParent().getDefinition() != null) { T parsedRealValue = (T) parseRawElementToNewRealValue(origValue, (PrismPropertyDefinition) definitionSource.getParent().getDefinition()); PrismPropertyValue<T> newPVal = new PrismPropertyValueImpl<>(parsedRealValue); return newPVal; } else if (definitionSource.getRealClass() != null && definitionSource.getPrismContext() != null) { T parsedRealValue = parseRawElementToNewRealValue(origValue, (Class<T>) definitionSource.getRealClass(), definitionSource.getPrismContext()); PrismPropertyValue<T> newPVal = new PrismPropertyValueImpl<>(parsedRealValue); return newPVal; } else { throw new IllegalArgumentException("Attempt to use property " + origValue.getParent() + " values in a raw parsing state (raw elements) with parsed value that has no definition nor class with prism context"); } }
private static String determinePropName(PrismPropertyValue<?> value) { Itemable item = value.getParent(); return item != null && item.getElementName() != null ? item.getElementName().getLocalPart() : ""; }
return ConnIdUtil.toGuardedString(ps, pval.getParent().getElementName().getLocalPart(), protector); } else { throw new ConfigurationException( "Expected protected string as value of configuration property " + pval.getParent().getElementName().getLocalPart() + " but got " + midPointRealValue.getClass());
private static void encryptValue(Protector protector, PrismPropertyValue<?> pval) throws EncryptionException{ Itemable item = pval.getParent(); if (item == null) { return; ProtectedStringType ps = psPval.getValue(); encryptProtectedStringType(protector, ps, propName.getLocalPart()); if (pval.getParent() == null) {
private <T> List<PrismPropertyValue<T>> evaluateExpression(ScriptExpressionEvaluatorType scriptType, ItemDefinition outputDefinition, ExpressionVariables variables, String shortDesc, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException { ScriptExpression scriptExpression = createScriptExpression(scriptType, outputDefinition, shortDesc); List<PrismPropertyValue<T>> resultValues = scriptExpression.evaluate(variables, null, false, shortDesc, null, result); if (resultValues != null) { for (PrismPropertyValue<T> resultVal: resultValues) { if (resultVal.getParent() != null) { AssertJUnit.fail("Result value "+resultVal+" from expression "+scriptExpression+" has parent"); } } } return resultValues; }
private static void checkEncrypted(PrismPropertyValue<?> pval) { Itemable item = pval.getParent(); if (item == null) { return;