private V getSingleValue(Item<V, D> item) { if (item == null || item.isEmpty()) { return null; } else if (item.size() == 1) { return item.getAnyValue(); } else { throw new IllegalStateException("Multiple values where single one was expected: " + item); } }
@Override public Long getAssignmentId() { Item<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> any = assignmentIdi.getAnyItem(); return any != null && !any.getValues().isEmpty() ? any.getAnyValue().getId() : null; }
/** * Marshals everything from the item except for the root node. * Separated from marshalItemAsRoot in order to be reusable. */ @NotNull private XNodeImpl marshalItemContent(@NotNull Item<?, ?> item, ItemDefinition itemDefinition, SerializationContext context) throws SchemaException { if (item.size() == 1) { return marshalItemValue(item.getAnyValue(), itemDefinition, null, context); } else { ListXNodeImpl xlist = new ListXNodeImpl(); for (PrismValue val : item.getValues()) { xlist.add(marshalItemValue(val, itemDefinition, null, context)); } return xlist; } }
public static Object getItemRealValue(PrismContainerValue containerValue, String itemName) { Item item = containerValue.findItem(new ItemName(itemName)); if (item == null || item.size() == 0) { return null; } if (item.size() > 1) { throw new IllegalStateException("More than one value in item " + item); } PrismValue value = item.getAnyValue(); if (value == null) { return null; } if (value instanceof PrismPropertyValue) { return ((PrismPropertyValue) value).getValue(); } else if (value instanceof PrismReferenceValue) { ObjectReferenceType ort = new ObjectReferenceType(); ort.setupReferenceValue((PrismReferenceValue) value); return ort; } else if (value instanceof PrismContainerValue) { return ((PrismContainerValue) value).asContainerable(); // questionable } else { throw new IllegalStateException("Unknown PrismValue: " + value); } }
Item<IV,ID> subItem = prismContext.parserFor(getRootXNode(itemName)).name(itemName).definition(itemDefinition).parseItem(); if (!subItem.isEmpty()) { value = subItem.getAnyValue(); } else { value = null;
@Test public void testInboundMapping() throws Exception{ final String TEST_NAME = "testInboundMapping"; TestUtil.displayTestTitle(TEST_NAME); PrismContext prismContext = evaluator.getPrismContext(); PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(MappingTestEvaluator.TEST_DIR + "/account-inbound-mapping.xml")); Item oldItem = account.findItem(ItemPath.create(ShadowType.F_ATTRIBUTES, SchemaTestConstants.ICFS_NAME)); ItemDelta delta = prismContext.deltaFactory().property().createModificationAddProperty(SchemaTestConstants.ICFS_NAME_PATH_PARTS, (PrismPropertyDefinition) oldItem.getDefinition(), ((PrismPropertyValue) oldItem.getAnyValue()).getValue()); PrismObject<UserType> user = evaluator.getUserDefinition().instantiate(); MappingImpl<PrismPropertyValue<PolyString>,PrismPropertyDefinition<PolyString>> mapping = evaluator.createInboudMapping("mapping-inbound.xml", TEST_NAME, delta, user.asObjectable(), account.asObjectable(), null, null); OperationResult opResult = new OperationResult(TEST_NAME); mapping.evaluate(null, opResult); PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple(); outputTriple.checkConsistence(); assertTripleZero(outputTriple, PrismTestUtil.createPolyString("pavolr")); PrismAsserts.assertTripleNoPlus(outputTriple); assertTripleNoMinus(outputTriple); }
PrismPropertyValue<T> propertyValue = (PrismPropertyValue<T>) item.getAnyValue(); propertyValue.clearParent(); if (isGt || isGtEq) {
assertFalse(intAttributeReparsed.getAnyValue().isRaw()); Item<?, ?> stringAttributeReparsed = shadowReparsed.findItem(ItemPath.create(ShadowType.F_ATTRIBUTES, STRING_ATTRIBUTE_NAME)); assertNotNull(stringAttributeReparsed); assertFalse(stringAttributeReparsed.getAnyValue().isRaw()); Item<?, ?> longExtensionReparsed = shadowReparsed.findItem(ItemPath.create(ShadowType.F_EXTENSION, SchemaTestConstants.EXTENSION_LONG_TYPE_ELEMENT)); assertNotNull(longExtensionReparsed); assertFalse(longExtensionReparsed.getAnyValue().isRaw()); Item<?, ?> doubleExtensionReparsed = shadowReparsed.findItem(ItemPath.create(ShadowType.F_EXTENSION, SchemaTestConstants.EXTENSION_DOUBLE_TYPE_ELEMENT)); assertNotNull(doubleExtensionReparsed); assertFalse(doubleExtensionReparsed.getAnyValue().isRaw());
Item<PrismValue, ItemDefinition> attr1Reparsed = shadowReparsed.findItem(ItemPath.create(ShadowType.F_ATTRIBUTES, ATTR1_QNAME)); assertNotNull(attr1Reparsed); assertFalse("Reparsed attribute is raw", attr1Reparsed.getAnyValue().isRaw());