Search in sources :

Example 11 with PrimitiveXNode

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);
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) Visitable(com.evolveum.midpoint.prism.Visitable)

Example 12 with PrimitiveXNode

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;
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with PrimitiveXNode

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());
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) DeltaConvertor.toObjectDeltaType(com.evolveum.midpoint.schema.DeltaConvertor.toObjectDeltaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with PrimitiveXNode

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);
        }
    }
}
Also used : ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 15 with PrimitiveXNode

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;
}
Also used : XNodeProcessorEvaluationMode(com.evolveum.midpoint.prism.marshaller.XNodeProcessorEvaluationMode) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ValueParser(com.evolveum.midpoint.prism.xnode.ValueParser) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Aggregations

PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)19 QName (javax.xml.namespace.QName)13 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)10 XNode (com.evolveum.midpoint.prism.xnode.XNode)9 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)8 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)5 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)5 Test (org.testng.annotations.Test)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 JAXBElement (javax.xml.bind.JAXBElement)3 Element (org.w3c.dom.Element)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 DomLexicalProcessor (com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor)2 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)2 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)1 ParsingContext (com.evolveum.midpoint.prism.ParsingContext)1