/** * Transforms the delta to the simplest (and safest) form. E.g. it will transform add delta for * single-value properties to replace delta. */ public void simplify() { checkMutability(); ItemDefinition itemDefinition = getDefinition(); if (itemDefinition == null) { throw new IllegalStateException("Attempt to simplify delta without a definition"); } if (itemDefinition.isSingleValue() && isAdd()) { valuesToReplace = valuesToAdd; valuesToAdd = null; valuesToDelete = null; } }
public void validate(String contextDescription) throws SchemaException { if (definition == null) { throw new IllegalStateException("Attempt to validate delta without a definition: "+this); } if (definition.isSingleValue()) { if (valuesToAdd != null && valuesToAdd.size() > 1) { throw new SchemaException("Attempt to add "+valuesToAdd.size()+" values to a single-valued item "+getPath() + (contextDescription == null ? "" : " in "+contextDescription) + "; values: "+valuesToAdd); } if (valuesToReplace != null && valuesToReplace.size() > 1) { throw new SchemaException("Attempt to replace "+valuesToReplace.size()+" values to a single-valued item "+getPath() + (contextDescription == null ? "" : " in "+contextDescription) + "; values: "+valuesToReplace); } } if (definition.isMandatory()) { if (valuesToReplace != null && valuesToReplace.isEmpty()) { throw new SchemaException("Attempt to clear all values of a mandatory item "+getPath() + (contextDescription == null ? "" : " in "+contextDescription)); } } }
public boolean add(@NotNull V newValue, boolean checkUniqueness, @NotNull EquivalenceStrategy equivalenceStrategy) throws SchemaException { checkMutability(); if (newValue.getPrismContext() == null) { newValue.setPrismContext(prismContext); } Itemable originalParent = newValue.getParent(); newValue.setParent(this); // needed e.g. because of PrismReferenceValue comparisons if (checkUniqueness && contains(newValue, equivalenceStrategy)) { newValue.setParent(originalParent); return false; } D definition = getDefinition(); if (definition != null) { if (!values.isEmpty() && definition.isSingleValue()) { throw new SchemaException("Attempt to put more than one value to single-valued item " + this + "; newly added value: " + newValue); } newValue.applyDefinition(definition, false); } return values.add(newValue); }
} else { Attribute attr = AttributeBuilder.build(icfName, convertedValues); if (valueFilter.getDefinition().isSingleValue()) { return FilterBuilder.equalTo(attr); } else { if (valueFilter.getDefinition().isSingleValue()) { return FilterBuilder.equalTo(attr); } else {
private static Object variableFromOtherExpression(HashMap<String, Object> resultingVariables, ScriptingVariableDefinitionType definition, VariableResolutionContext ctx, String shortDesc, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException { ItemDefinition<?> outputDefinition = determineOutputDefinition(definition, ctx, shortDesc); Expression<PrismValue, ItemDefinition<?>> expression = ctx.expressionFactory .makeExpression(definition.getExpression(), outputDefinition, shortDesc, ctx.task, result); ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, createVariables(resultingVariables), shortDesc, ctx.task, result); PrismValueDeltaSetTriple<?> triple = ModelExpressionThreadLocalHolder .evaluateAnyExpressionInContext(expression, context, ctx.task, result); Collection<?> resultingValues = triple.getNonNegativeValues(); if (definition.getMaxOccurs() != null && outputDefinition.isSingleValue() // cardinality of outputDefinition is derived solely from definition.maxOccurs (if specified) || definition.getMaxOccurs() == null || resultingValues.size() <= 1) { return MiscUtil.getSingleValue(resultingValues, null, shortDesc); // unwrapping will occur when the value is used } else { return unwrapPrismValues(resultingValues); } }
PrismObjectDefinition<O> objDef = objectTypeClass != null ? prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass) : null; ItemDefinition itemDef = objDef != null ? objDef.findItemDefinition(path) : null; Boolean isSingle = itemDef != null ? itemDef.isSingleValue() : null; if (isSingle == null) { LOGGER.warn("Couldn't find definition for {}:{}", objectTypeClass, path);
if (item.getDefinition().isSingleValue()) {
if (item.getDefinition() != null && item.getDefinition().isSingleValue()) {
@Override public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) throws QueryException { if (!path.isSingleName()) { throw new QueryException("Couldn't resolve paths other than those in the form of single name in extension/attributes container: " + path); } if (itemDefinition == null) { throw new QueryException("Couldn't resolve dynamically defined item path '" + path + "' without proper definition"); } CollectionSpecification collSpec = itemDefinition.isSingleValue() ? null : new CollectionSpecification(); String jpaName; // longs, strings, ... JpaDataNodeDefinition jpaNodeDefinition; if (itemDefinition instanceof PrismPropertyDefinition) { try { jpaName = RAnyConverter.getAnySetType(itemDefinition, prismContext); } catch (SchemaException e) { throw new QueryException(e.getMessage(), e); } jpaNodeDefinition = new JpaAnyPropertyDefinition(Object.class, null); // TODO } else if (itemDefinition instanceof PrismReferenceDefinition) { jpaName = "references"; jpaNodeDefinition = new JpaAnyReferenceDefinition(Object.class, RObject.class); } else { throw new QueryException("Unsupported 'any' item: " + itemDefinition); } JpaLinkDefinition<?> linkDefinition = new JpaAnyItemLinkDefinition(itemDefinition, jpaName, collSpec, getOwnerType(), jpaNodeDefinition); return new DataSearchResult<>(linkDefinition, ItemPath.EMPTY_PATH); }