use of com.evolveum.midpoint.prism.xnode.PrimitiveXNode in project midpoint by Evolveum.
the class PrismAsserts method assertAllParsedNodes.
public static void assertAllParsedNodes(XNode xnode) {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if ((visitable instanceof PrimitiveXNode<?>)) {
assert ((PrimitiveXNode<?>) visitable).isParsed() : "Xnode " + visitable + " is not parsed";
}
}
};
xnode.accept(visitor);
}
use of com.evolveum.midpoint.prism.xnode.PrimitiveXNode in project midpoint by Evolveum.
the class TestJaxbConstruction method createFilter.
private MapXNode createFilter() {
MapXNode filter = new MapXNode();
MapXNode equalsElement = new MapXNode();
filter.put(new QName(SchemaConstantsGenerated.NS_QUERY, "equal"), equalsElement);
PrimitiveXNode<ItemPathType> pathElement = new PrimitiveXNode<>(new ItemPathType(new ItemPath(new QName("name"))));
equalsElement.put(new QName(SchemaConstantsGenerated.NS_QUERY, "path"), pathElement);
PrimitiveXNode<String> valueElement = new PrimitiveXNode<>("čučoriedka");
equalsElement.put(new QName(SchemaConstantsGenerated.NS_QUERY, "value"), valueElement);
return filter;
}
use of com.evolveum.midpoint.prism.xnode.PrimitiveXNode in project midpoint by Evolveum.
the class TestDeltaConverter method testProtectedStringObjectDelta.
@Test
public void testProtectedStringObjectDelta() throws Exception {
System.out.println("===[ testProtectedStringObjectDelta ]====");
// GIVEN
ItemPath path = CREDENTIALS_PASSWORD_VALUE_PATH;
ProtectedStringType protectedString = new ProtectedStringType();
protectedString.setClearValue("abrakadabra");
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, "12345", path, getPrismContext(), protectedString);
System.out.println("ObjectDelta");
System.out.println(objectDelta.debugDump());
// WHEN
ObjectDeltaType objectDeltaType = toObjectDeltaType(objectDelta);
// THEN
System.out.println("ObjectDeltaType (XML)");
System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectDeltaType));
assertEquals("Wrong changetype", ChangeTypeType.MODIFY, objectDeltaType.getChangeType());
assertEquals("Wrong OID", "12345", objectDeltaType.getOid());
List<ItemDeltaType> modifications = objectDeltaType.getItemDelta();
assertNotNull("null modifications", modifications);
assertEquals("Wrong number of modifications", 1, modifications.size());
ItemDeltaType mod1 = modifications.iterator().next();
assertEquals("Wrong mod type", ModificationTypeType.REPLACE, mod1.getModificationType());
// XPathHolder xpath = new XPathHolder(mod1.getPath());
ItemPathType itemPathType = mod1.getPath();
assertNotNull("Wrong path (must not be null)", itemPathType);
assertEquals("Wrong path", path, itemPathType.getItemPath());
List<RawType> valueElements = mod1.getValue();
assertEquals("Wrong number of value elements", 1, valueElements.size());
RawType val = valueElements.get(0);
MapXNode valXNode = (MapXNode) val.serializeToXNode();
PrimitiveXNode clearValueNode = (PrimitiveXNode) valXNode.get(ProtectedStringType.F_CLEAR_VALUE);
val.getParsedValue(null, null);
// System.out.println("clear value " + clearValueNode);
assertEquals("Wrong element value", protectedString.getClearValue(), clearValueNode.getParsedValue(DOMUtil.XSD_STRING, String.class));
// List<Object> values = val.getContent();
// assertEquals("Wrong number of values", 1, values.size());
// JAXBElement<ProtectedStringType> valueElement = (JAXBElement<ProtectedStringType>)values.iterator().next();
//// assertEquals("Wrong element name", PasswordType.F_VALUE, valueElement.getName());
// assertEquals("Wrong element value", protectedString, valueElement.getValue());
}
use of com.evolveum.midpoint.prism.xnode.PrimitiveXNode in project midpoint by Evolveum.
the class ChangeExecutor method evaluateScriptArgument.
private void evaluateScriptArgument(ProvisioningScriptArgumentType argument, ExpressionVariables variables, LensContext<?> context, LensElementContext<?> objectContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
QName FAKE_SCRIPT_ARGUMENT_NAME = new QName(SchemaConstants.NS_C, "arg");
PrismPropertyDefinition<String> scriptArgumentDefinition = new PrismPropertyDefinitionImpl<>(FAKE_SCRIPT_ARGUMENT_NAME, DOMUtil.XSD_STRING, prismContext);
String shortDesc = "Provisioning script argument expression";
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(argument, scriptArgumentDefinition, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, context, objectContext instanceof LensProjectionContext ? (LensProjectionContext) objectContext : null, task, result);
Collection<PrismPropertyValue<String>> nonNegativeValues = null;
if (outputTriple != null) {
nonNegativeValues = outputTriple.getNonNegativeValues();
}
// replace dynamic script with static value..
argument.getExpressionEvaluator().clear();
if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
// We need to create at least one evaluator. Otherwise the
// expression code will complain
// Element value = DOMUtil.createElement(SchemaConstants.C_VALUE);
// DOMUtil.setNill(value);
JAXBElement<RawType> el = new JAXBElement(SchemaConstants.C_VALUE, RawType.class, new RawType(prismContext));
argument.getExpressionEvaluator().add(el);
} else {
for (PrismPropertyValue<String> val : nonNegativeValues) {
// Element value =
// DOMUtil.createElement(SchemaConstants.C_VALUE);
// value.setTextContent(val.getValue());
PrimitiveXNode<String> prim = new PrimitiveXNode<>();
prim.setValue(val.getValue(), DOMUtil.XSD_STRING);
JAXBElement<RawType> el = new JAXBElement(SchemaConstants.C_VALUE, RawType.class, new RawType(prim, prismContext));
argument.getExpressionEvaluator().add(el);
}
}
}
use of com.evolveum.midpoint.prism.xnode.PrimitiveXNode in project midpoint by Evolveum.
the class TestModelWebServiceNegative method createShadowReplaceChange.
// TODO: more negative tests
private ObjectDeltaType createShadowReplaceChange(String oid, String path, final String value, QName type) {
ObjectDeltaType objectChange = new ObjectDeltaType();
objectChange.setOid(oid);
objectChange.setChangeType(ChangeTypeType.MODIFY);
objectChange.setObjectType(ObjectTypes.SHADOW.getTypeQName());
ItemDeltaType itemDeltaType = new ItemDeltaType();
itemDeltaType.setModificationType(ModificationTypeType.REPLACE);
ItemPathType itemPath = new ItemPathType(path);
itemDeltaType.setPath(itemPath);
PrimitiveXNode<String> xnode = new PrimitiveXNode<>();
ValueParser<String> valueParser = new ValueParser<String>() {
@Override
public String parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
return value;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public String getStringValue() {
return value;
}
@Override
public Map<String, String> getPotentiallyRelevantNamespaces() {
throw new UnsupportedOperationException();
}
};
xnode.setValueParser(valueParser);
if (type != null) {
xnode.setExplicitTypeDeclaration(true);
xnode.setTypeQName(type);
}
RawType rawValue = new RawType(xnode, prismContext);
itemDeltaType.getValue().add(rawValue);
objectChange.getItemDelta().add(itemDeltaType);
return objectChange;
}
Aggregations