use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ACAttributeDto method getConstruction.
public ResourceAttributeDefinitionType getConstruction(PrismContext prismContext) throws SchemaException {
if (isEmpty()) {
return null;
}
ResourceAttributeDefinitionType attrConstruction = new ResourceAttributeDefinitionType();
if (construction != null && construction.getRef() != null) {
// preserves original ref (including xmlns prefix!) - in order to avoid false deltas when comparing old and new values
attrConstruction.setRef(construction.getRef());
} else {
attrConstruction.setRef(new ItemPathType(definition.getItemName()));
}
MappingType outbound;
if (construction != null && construction.getOutbound() != null) {
outbound = construction.getOutbound().clone();
} else {
outbound = new MappingType();
outbound.setStrength(MappingStrengthType.STRONG);
}
attrConstruction.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
List<ACValueConstructionDto> values = getValues();
PrismProperty property = definition.instantiate();
// needed in serializeValueElements below
property.revive(prismContext);
for (ACValueConstructionDto dto : values) {
if (dto.getValue() == null) {
continue;
}
property.addRealValue(dto.getValue());
}
List evaluators = expression.getExpressionEvaluator();
List<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> evaluator : collection) {
evaluators.add(evaluator);
}
if (evaluators.isEmpty()) {
return null;
}
return attrConstruction;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ExpressionUtil method serialize.
public static String serialize(JAXBElement<?> element, PrismContext prismContext) throws SchemaException {
String xml;
if (element.getValue() instanceof RawType) {
RawType raw = (RawType) element.getValue();
RootXNode rootNode = prismContext.xnodeFactory().root(element.getName(), raw.serializeToXNode());
xml = prismContext.xmlSerializer().serialize(rootNode);
} else {
xml = prismContext.xmlSerializer().serialize(element);
}
return WebXmlUtil.stripNamespaceDeclarations(xml);
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ExpressionUtil method getLiteralExpressionValues.
@NotNull
public static List<String> getLiteralExpressionValues(ExpressionType expression) throws SchemaException {
List<String> values = new ArrayList<>();
List<JAXBElement<?>> elements = ExpressionUtil.findAllEvaluatorsByName(expression, SchemaConstantsGenerated.C_VALUE);
for (JAXBElement<?> element : elements) {
if (element.getValue() instanceof RawType) {
RawType raw = (RawType) element.getValue();
if (raw != null) {
if (raw.getXnode() != null && raw.getXnode() instanceof PrimitiveXNode) {
PrimitiveXNode<?> valueNode = (PrimitiveXNode<?>) raw.getXnode();
if (valueNode != null && valueNode.getValue() != null) {
values.add(valueNode.getValue().toString());
} else if (valueNode.getValueParser() != null) {
values.add(valueNode.getValueParser().getStringValue());
}
} else if (raw.getParsedRealValue(String.class) != null) {
values.add(raw.getParsedRealValue(String.class));
}
}
}
}
return values;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ExpressionUtil method removeShadowRefEvaluatorValue.
public static void removeShadowRefEvaluatorValue(ExpressionType expression, String shadowRefOid, PrismContext prismContext) {
if (expression == null || StringUtils.isEmpty(shadowRefOid)) {
return;
}
List<JAXBElement<?>> elementList = findAllEvaluatorsByName(expression, SchemaConstants.C_VALUE);
if (CollectionUtils.isEmpty(elementList)) {
return;
}
boolean removePerformed = false;
Iterator<JAXBElement<?>> elementIterator = elementList.iterator();
while (elementIterator.hasNext()) {
JAXBElement element = elementIterator.next();
if (element != null && element.getValue() instanceof RawType) {
RawType raw = (RawType) element.getValue();
if (raw.isParsed()) {
try {
if (raw.getParsedRealValue(ShadowAssociationType.class) != null) {
ShadowAssociationType assoc = raw.getParsedRealValue(ShadowAssociationType.class);
if (assoc.getShadowRef() != null && shadowRefOid.equals(assoc.getShadowRef().getOid())) {
elementIterator.remove();
break;
}
}
} catch (SchemaException e) {
LoggingUtils.logExceptionAsWarning(LOGGER, "Could not remove association value", e);
}
} else {
XNode node = raw.getXnode();
if (node instanceof MapXNode && ((MapXNode) node).containsKey(SHADOW_REF_KEY)) {
XNode shadowRefNodes = ((MapXNode) node).get(SHADOW_REF_KEY);
if (shadowRefNodes instanceof MapXNode && shadowRefOid.equals(getShadowRefNodeOid((MapXNode) shadowRefNodes))) {
prismContext.xnodeMutator().putToMapXNode((MapXNode) node, SHADOW_REF_KEY, null);
removePerformed = true;
// todo don't get why while using removeEvaluatorByName no changes are saved
// removeEvaluatorByName(expression, SchemaConstantsGenerated.C_VALUE);
} else if (shadowRefNodes instanceof ListXNode) {
Iterator<? extends XNode> it = ((ListXNode) shadowRefNodes).asList().iterator();
while (it.hasNext()) {
XNode shadowRefNode = it.next();
if (shadowRefNode instanceof MapXNode && shadowRefOid.equals(getShadowRefNodeOid((MapXNode) shadowRefNode))) {
it.remove();
removePerformed = true;
break;
}
}
}
}
}
}
if (removePerformed) {
break;
}
}
expression.getExpressionEvaluator().clear();
expression.getExpressionEvaluator().addAll(elementList);
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class TestParseObjectTemplate method assertObjectTemplateInternals.
// checks raw values of mappings
// should be called only on reparsed values in order to catch some raw-data-related serialization issues (MID-2196)
private void assertObjectTemplateInternals(PrismObject<ObjectTemplateType> object) throws SchemaException {
int assignmentValuesFound = 0;
for (ObjectTemplateMappingType mappingType : object.asObjectable().getMapping()) {
if (mappingType.getExpression() != null) {
if (mappingType.getTarget() != null && mappingType.getTarget().getPath() != null && UserType.F_ASSIGNMENT.equivalent(mappingType.getTarget().getPath().getItemPath())) {
ItemDefinition assignmentDef = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findItemDefinition(UserType.F_ASSIGNMENT);
for (JAXBElement evaluator : mappingType.getExpression().getExpressionEvaluator()) {
if (evaluator.getValue() instanceof RawType) {
RawType rawType = (RawType) evaluator.getValue();
System.out.println("\nraw assignment:\n" + rawType);
Item assignment = rawType.getParsedItem(assignmentDef);
System.out.println("\nassignment:\n" + assignment.debugDump());
assignmentValuesFound++;
}
}
}
}
}
assertEquals("wrong # of assignment values found in mapping", 2, assignmentValuesFound);
}
Aggregations