public Item<V,D> getEmptyItem() throws SchemaException { ItemDefinition definition = getDefinition(); if (definition == null) { throw new IllegalStateException("No definition in source "+this); } return definition.instantiate(getElementName()); }
public <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> getParsedItem(ID itemDefinition, QName itemName) throws SchemaException { Validate.notNull(itemDefinition); Validate.notNull(itemName); Item<IV,ID> item = itemDefinition.instantiate(); IV newValue = getParsedValue(itemDefinition, itemName); if (newValue != null) { item.add((IV) newValue.clone()); } return item; }
public Item<V,D> getOutput() throws SchemaException { if (outputTriple == null) { return null; } //noinspection unchecked Item<V,D> output = outputDefinition.instantiate(); output.addAll(PrismValueCollectionsUtil.cloneCollection(outputTriple.getNonNegativeValues())); return output; }
newItem = (I) itemDefinition.instantiate(name); } else { QName computed = new QName(itemDefinition.getNamespace(), name.getLocalPart()); newItem = (I) itemDefinition.instantiate(computed);
public static <V extends PrismContainerValue> void createParentIfNeeded(V value, ItemDefinition definition) throws SchemaException { if (value.getParent() != null) { return; } if (!(definition instanceof PrismContainerDefinition)) { throw new SchemaException("Missing or invalid definition for a PrismContainer: " + definition); } PrismContainerImpl<?> rv = (PrismContainerImpl) definition.instantiate(); rv.add(value); }
static <V extends PrismContainerValue> void createParentIfNeeded(V value, ItemDefinition definition) throws SchemaException { if (value.getParent() != null) { return; } if (!(definition instanceof PrismContainerDefinition)) { throw new SchemaException("Missing or invalid definition for a PrismContainer: " + definition); } PrismContainer<?> rv = (PrismContainer) definition.instantiate(); rv.add(value); }
@NotNull public static List<Item<?, ?>> mapToExtensionItems(Map<QName, Object> values, PrismContainerDefinition<?> extensionDefinition, PrismContext prismContext) throws SchemaException { List<Item<?, ?>> extensionItems = new ArrayList<>(); for (Map.Entry<QName, Object> entry : values.entrySet()) { ItemDefinition<Item<PrismValue, ItemDefinition>> def = extensionDefinition != null ? extensionDefinition.findItemDefinition(ItemName.fromQName(entry.getKey())) : null; if (def == null) { //noinspection unchecked def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(entry.getKey()); // a bit of hack here if (def == null) { throw new SchemaException("No definition of " + entry.getKey() + " in task extension"); } } Item<PrismValue, ItemDefinition> extensionItem = def.instantiate(); if (entry.getValue() != null) { if (entry.getValue() instanceof Collection) { for (Object value : (Collection) entry.getValue()) { addRealValue(extensionItem, value, prismContext); } } else { addRealValue(extensionItem, entry.getValue(), prismContext); } } extensionItems.add(extensionItem); } return extensionItems; }
@Override public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException { String constName = constEvaluatorType.getValue(); String stringValue = constantsManager.getConstantValue(constName); Item<V, D> output = outputDefinition.instantiate(); Object value = ExpressionUtil.convertToOutputValue(stringValue, outputDefinition, protector); if (output instanceof PrismProperty) { ((PrismProperty<Object>) output).addRealValue(value); } else { throw new UnsupportedOperationException( "Can only generate values of property, not " + output.getClass()); } return ItemDeltaUtil.toDeltaSetTriple(output, null, prismContext); }
public Item<V,D> getItemNewMatchingPath(Item<V,D> itemOld) throws SchemaException { if (definition == null) { throw new IllegalStateException("No definition in "+this); } Item<V,D> itemNew; if (itemOld == null) { if (isEmpty()) { return null; } itemNew = definition.instantiate(getElementName()); } else { itemNew = itemOld.clone(); } applyToMatchingPath(itemNew, ParameterizedEquivalenceStrategy.DEFAULT_FOR_DELTA_APPLICATION); return itemNew; }
private ItemDelta createNewDelta(FactorOutResultMulti<O> rv, ItemDelta<?, ?> modification) throws SchemaException { ObjectDeltaImpl<O> offspring = createOffspring(); ItemDelta delta = modification.getDefinition().instantiate().createDelta(modification.getPath()); offspring.addModification(delta); rv.offsprings.add(offspring); return delta; }
/** * Returns the "new" state of the property - the state that would be after * the delta is applied. */ public Item<V,D> getItemNew(Item<V,D> itemOld) throws SchemaException { if (definition == null) { throw new IllegalStateException("No definition in "+this); } Item<V,D> itemNew; if (itemOld == null) { if (isEmpty()) { return null; } itemNew = definition.instantiate(getElementName()); } else { itemNew = itemOld.clone(); } applyTo(itemNew); return itemNew; }
@Override public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException { long counter = getSequenceCounter(sequentialValueEvaluatorType.getSequenceRef().getOid(), repositoryService, context.getResult()); Object value = ExpressionUtil.convertToOutputValue(counter, outputDefinition, protector); Item<V,D> output = outputDefinition.instantiate(); if (output instanceof PrismProperty) { ((PrismProperty<Object>)output).addRealValue(value); } else { throw new UnsupportedOperationException("Can only generate values of property, not "+output.getClass()); } return ItemDeltaUtil.toDeltaSetTriple(output, null, prismContext); }
@NotNull Item getFilterItem() throws SchemaException { if (getDefinition() == null){ throw new SchemaException("Could not find definition for item " + getPath()); } Item filterItem = getDefinition().instantiate(); if (getValues() != null && !getValues().isEmpty()) { try { for (PrismValue v : getValues()){ filterItem.add(v.clone()); } } catch (SchemaException e) { throw new IllegalArgumentException(e.getMessage(), e); } } return filterItem; }
@Test public void testExtensionEnum() throws Exception { Session session = getFactory().openSession(); QName valueName = new QName(NS_P, "enumType"); ItemDefinition def = getDefinition(GenericObjectType.class, ItemPath.create(ObjectType.F_EXTENSION, valueName)); AssertJUnit.assertNotNull(def); PrismProperty item = (PrismProperty) def.instantiate(); item.setRealValue(BeforeAfterType.AFTER); def.toMutable().setName(valueName); RAnyConverter converter = new RAnyConverter(prismContext, extItemDictionary); Set<RAnyValue<?>> values; try { values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION); AssertJUnit.fail("Should have throw serialization related exception after creating ext item"); } catch (DtoTranslationException ex) { AssertJUnit.assertTrue(SerializationRelatedException.class.equals(ex.getCause().getClass())); } values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION); AssertJUnit.assertEquals("Expected only one enum value, but was " + values.size(), 1, values.size()); RAnyValue value = values.iterator().next(); AssertJUnit.assertEquals("after", value.getValue()); session.close(); }
if (entry.getValue() == null) { if (itemDef != null) { item = itemDef.instantiate(); // TODO or skip the creation altogether? } else { item = null;
Item<V, D> output = outputDefinition.instantiate(); if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {
@SuppressWarnings("unchecked") private <V extends PrismValue, D extends ItemDefinition> SceneDeltaItemImpl createSceneDeltaItemCommon(ItemDelta<V, D> itemDelta, SceneImpl owningScene) throws SchemaException { String simpleName = itemDelta.getElementName() != null ? itemDelta.getElementName().getLocalPart() : ""; NameImpl name = new NameImpl(simpleName); if (itemDelta.getDefinition() != null) { name.setDisplayName(itemDelta.getDefinition().getDisplayName()); } name.setId(simpleName); name.setNamesAreResourceKeys(true); SceneDeltaItemImpl si = new SceneDeltaItemImpl(name); si.setSourceDelta(itemDelta); D def = itemDelta.getDefinition(); if (def != null) { Item<V,D> item = def.instantiate(); if (itemDelta.getEstimatedOldValues() != null) { item.addAll(CloneUtil.cloneCollectionMembers(itemDelta.getEstimatedOldValues())); } si.setSourceItem(item); si.setOperational(def.isOperational()); } ItemPath remainder = itemDelta.getPath().remainder(owningScene.getSourceRelPath()); if (remainder.startsWithNullId()) { remainder = remainder.rest(); } si.setSourceRelPath(remainder); return si; }
Item shouldBeItem = outputDefinition.instantiate(); if (consolidatedTriples != null) {