public static boolean getBooleanConditionOutput(PrismPropertyValue<Boolean> conditionOutput) { if (conditionOutput == null) { return false; } Boolean value = conditionOutput.getValue(); if (value == null) { return false; } return value; }
private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException { RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName()); QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName(); MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName()); List<PrismPropertyValue<T>> normalized = new ArrayList<>(); for (PrismPropertyValue<T> origPValue : attr.getValues()){ T normalizedValue = matchingRule.normalize(origPValue.getValue()); PrismPropertyValue<T> normalizedPValue = origPValue.clone(); normalizedPValue.setValue(normalizedValue); normalized.add(normalizedPValue); } return normalized; }
@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())); }
/** * 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 <T> PrismPropertyValue<T> filterValue(PrismPropertyValue<T> propertyValue, List<ValueFilterType> filters) { PrismPropertyValue<T> filteredValue = propertyValue.clone(); filteredValue.setOriginType(OriginType.INBOUND); if (filters == null || filters.isEmpty()) { return filteredValue; } for (ValueFilterType filter : filters) { Filter filterInstance = filterManager.getFilterInstance(filter.getType(), filter.getAny()); filterInstance.apply(filteredValue); } return filteredValue; }
if (firstVal != null && !firstVal.isRaw() && firstVal.getValue() != null) { if (DebugUtil.isDetailedDebugDump() && firstVal.getValue() instanceof DebugDumpable) { multiline = true; } else if ((firstVal.getValue() instanceof ShortDumpable)) { multiline = false; } else if (firstVal.getValue() instanceof DebugDumpable) { dump = PrettyPrinter.debugDump(firstVal.getValue(), indent + 1); if (dump.length() > MAX_SINGLELINE_LEN || dump.contains("\n")) { multiline = true; for (PrismPropertyValue<T> value: getValues()) { sb.append("\n"); if (value.isRaw()) { sb.append(formatRawValueForDump(value.getRawElement())); sb.append(" (raw)"); } else if (value.getExpression() != null) { sb.append(" (expression)"); } else { dump = null; } else { T realValue = value.getValue(); if (realValue instanceof ShortDumpable) { ((ShortDumpable)realValue).shortDump(sb); while (iterator.hasNext()) { PrismPropertyValue<T> value = iterator.next(); if (value.isRaw()) { sb.append(formatRawValueForDump(value.getRawElement()));
List<PrismPropertyValue<T>> extraValues = new ArrayList<>(); for (PrismPropertyValue<T> configurationPropertyValue: configurationProperty.getValues()) { ExpressionWrapper expressionWrapper = configurationPropertyValue.getExpression(); if (expressionWrapper == null) { return; Iterator<PrismPropertyValue<T>> iterator = expressionOutputValues.iterator(); PrismPropertyValue<T> firstValue = iterator.next(); configurationPropertyValue.setValue(firstValue.getValue()); while (iterator.hasNext()) { extraValues.add(iterator.next());
private static void encryptValue(Protector protector, PrismPropertyValue<?> pval) throws EncryptionException{ Itemable item = pval.getParent(); if (item == null) { return; @SuppressWarnings("unchecked") PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval; ProtectedStringType ps = psPval.getValue(); encryptProtectedStringType(protector, ps, propName.getLocalPart()); if (pval.getParent() == null) { pval.setParent(item); // todo ??? if the parent is null we wouldn't get here MailConfigurationType mailCfg = ((PrismPropertyValue<MailConfigurationType>) pval).getValue(); if (mailCfg != null) { for (MailServerConfigurationType serverCfg : mailCfg.getServer()) { SmsConfigurationType smsCfg = ((PrismPropertyValue<SmsConfigurationType>) pval).getValue(); if (smsCfg != null) { for (SmsGatewayConfigurationType gwCfg : smsCfg.getGateway()) {
throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues); taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue()); throw new SchemaException("'createdTimestamp' filter contains a null value: " + filter); Object realValue = value.getRealValue(); if (!(realValue instanceof XMLGregorianCalendar)) { throw new SchemaException("'createdTimestamp' filter contains a value other than XMLGregorianCalendar: " + realValue + " in " + filter);
private boolean matches(PrismPropertyValue<?> value1, PrismPropertyValue<?> value2, MatchingRule<?> matchingRule) { try { if (matchingRule.match(value1.getRealValue(), value2.getRealValue())) { return true; } } catch (SchemaException e) { // At least one of the values is invalid. But we do not want to throw exception from // a comparison operation. That will make the system very fragile. Let's fall back to // ordinary equality mechanism instead. if (Objects.equals(value1.getRealValue(), value2.getRealValue())) { return true; } } return false; }
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); }
public static boolean containsRealValue(Collection<PrismPropertyValue<?>> collection, PrismPropertyValue<?> value) { for (PrismPropertyValue<?> colVal: collection) { if (value.equals(colVal, EquivalenceStrategy.REAL_VALUE)) { return true; } } return false; }
@Override protected ItemDelta fixupDelta(ItemDelta delta, Item otherItem) { PrismPropertyDefinition def = getDefinition(); if (def != null && def.isSingleValue() && !delta.isEmpty()) { // Drop the current delta (it was used only to detect that something has changed // Generate replace delta instead of add/delete delta PrismProperty<T> other = (PrismProperty<T>)otherItem; PropertyDelta<T> propertyDelta = (PropertyDelta<T>)delta; delta.clear(); Collection<PrismPropertyValue<T>> replaceValues = new ArrayList<>(other.getValues().size()); for (PrismPropertyValue<T> value : other.getValues()) { replaceValues.add(value.clone()); } propertyDelta.setValuesToReplace(replaceValues); return propertyDelta; } else { return super.fixupDelta(delta, otherItem); } }
private ObjectDelta<? extends ObjectType> createDelta(ObjectType objectType, PipelineData deltaData) throws ScriptExecutionException { if (deltaData.getData().size() != 1) { throw new ScriptExecutionException("Expected exactly one delta to apply, found " + deltaData.getData().size() + " instead."); } @SuppressWarnings({"unchecked", "raw"}) ObjectDeltaType deltaType = ((PrismPropertyValue<ObjectDeltaType>) deltaData.getData().get(0).getValue()).clone().getRealValue(); if (deltaType.getChangeType() == null) { deltaType.setChangeType(ChangeTypeType.MODIFY); } if (deltaType.getOid() == null && deltaType.getChangeType() != ChangeTypeType.ADD) { deltaType.setOid(objectType.getOid()); } if (deltaType.getObjectType() == null) { if (objectType.asPrismObject().getDefinition() == null) { throw new ScriptExecutionException("No definition for prism object " + objectType); } deltaType.setObjectType(objectType.asPrismObject().getDefinition().getTypeName()); } try { return DeltaConvertor.createObjectDelta(deltaType, prismContext); } catch (SchemaException e) { throw new ScriptExecutionException("Couldn't process delta due to schema exception", e); } } }
if (currentProperty != null) { for (PrismPropertyValue currentValue : currentProperty.getValues()) { currentValues.add(currentValue.clone()); if (o1.equals(o2, EquivalenceStrategy.IGNORE_METADATA, matchingRule)) { return 0; } else { for (PrismPropertyValue valueToAdd : propertyDelta.getValuesToAdd()) { if (!PrismValueCollectionsUtil.containsValue(currentValues, valueToAdd, comparator)) { currentValues.add(valueToAdd.clone()); } else { LOGGER.warn("Attempting to add a value of {} that is already present in {}: {}",
public void addValue(PrismPropertyValue<T> pValueToAdd) { checkMutability(); ((PrismPropertyValueImpl<T>) pValueToAdd).checkValue(); Iterator<PrismPropertyValue<T>> iterator = getValues().iterator(); while (iterator.hasNext()) { PrismPropertyValue<T> pValue = iterator.next(); if (pValue.equals(pValueToAdd, EquivalenceStrategy.REAL_VALUE)) { LOGGER.warn("Adding value to property "+ getElementName()+" that already exists (overwriting), value: "+pValueToAdd); iterator.remove(); } } pValueToAdd.setParent(this); pValueToAdd.recompute(); getValues().add(pValueToAdd); }
public boolean deleteValue(PrismPropertyValue<T> pValueToDelete) { checkMutability(); Iterator<PrismPropertyValue<T>> iterator = getValues().iterator(); boolean found = false; while (iterator.hasNext()) { PrismPropertyValue<T> pValue = iterator.next(); if (pValue.equals(pValueToDelete, EquivalenceStrategy.REAL_VALUE)) { iterator.remove(); pValue.setParent(null); found = true; } } if (!found) { LOGGER.warn("Deleting value of property "+ getElementName()+" that does not exist (skipping), value: "+pValueToDelete); } return found; }
private static String determinePropName(PrismPropertyValue<?> value) { Itemable item = value.getParent(); return item != null && item.getElementName() != null ? item.getElementName().getLocalPart() : ""; }