Search in sources :

Example 41 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class XPathTest method testCanonicalizationMulti.

@Test
public void testCanonicalizationMulti() throws Exception {
    ItemPath path = new ItemPath(UserType.F_ASSIGNMENT, 1234, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS);
    assertCanonical(path, null, "\\" + COMMON + "#assignment", "\\" + COMMON + "#assignment\\" + ZERO + "#activation", "\\" + COMMON + "#assignment\\" + ZERO + "#activation\\" + ZERO + "#administrativeStatus");
}
Also used : CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 42 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class XPathTest method xpathTest.

/**
     * This is now a proper test yet.
     * It does some operations with XPath. If it does not die, then the
     * code some somehow consistent.
     *
     * It should be improved later.
     */
@Test
public void xpathTest() throws JAXBException, FileNotFoundException, IOException, ParserConfigurationException, SchemaException {
    ObjectModificationType objectModification = PrismTestUtil.parseAtomicValue(new File(FILENAME_CHANGETYPE), ObjectModificationType.COMPLEX_TYPE);
    for (ItemDeltaType change : objectModification.getItemDelta()) {
        ItemPathType pathType = change.getPath();
        System.out.println("  path=" + pathType + " (" + pathType.getClass().getName() + ") " + pathType.toString());
        //            NamedNodeMap attributes = path.getAttributes();
        //            for (int i = 0; i < attributes.getLength(); i++) {
        //                Node n = attributes.item(i);
        //                System.out.println("   A: " + n.getClass().getName() + " " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
        //            }
        //            List<Object> any = change.getValue().getAny();
        //            for (Object e : any) {
        //                if (e instanceof Element) {
        //                    System.out.println("  E: " + ((Element) e).getLocalName());
        //                }
        //            }
        ItemPath path = pathType.getItemPath();
        XPathHolder xpath = new XPathHolder(path);
        AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpath.getXPathWithoutDeclarations());
        System.out.println("XPATH: " + xpath);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder loader = factory.newDocumentBuilder();
        Document doc = loader.newDocument();
        Element xpathElement = xpath.toElement("http://elelel/", "path", doc);
        Attr nsC = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "c");
        Attr nsPiracy = xpathElement.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "piracy");
        System.out.println("c: " + nsC);
        System.out.println("piracy: " + nsPiracy);
        //            AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/public/common/common-3", nsC.getValue());
        //            AssertJUnit.assertEquals("http://midpoint.evolveum.com/xml/ns/samples/piracy", nsPiracy.getValue());
        System.out.println("XPATH Element: " + xpathElement);
        XPathHolder xpathFromElement = new XPathHolder(xpathElement);
        AssertJUnit.assertEquals(xpath, xpathFromElement);
        //            attributes = xpathElement.getAttributes();
        //            for (int i = 0; i < attributes.getLength(); i++) {
        //                Node n = attributes.item(i);
        //                System.out.println(" A: " + n.getNodeName() + "(" + n.getPrefix() + " : " + n.getLocalName() + ") = " + n.getNodeValue());
        //            }
        List<XPathSegment> segments = xpath.toSegments();
        System.out.println("XPATH segments: " + segments);
        XPathHolder xpathFromSegments = new XPathHolder(segments);
        System.out.println("XPath from segments: " + xpathFromSegments);
        AssertJUnit.assertEquals("c:extension/piracy:ship[2]/c:name", xpathFromSegments.getXPathWithoutDeclarations());
    }
}
Also used : XPathSegment(com.evolveum.midpoint.prism.marshaller.XPathSegment) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Attr(org.w3c.dom.Attr) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 43 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class XPathTest method testCanonicalizationSimpleNoNs.

@Test
public void testCanonicalizationSimpleNoNs() throws Exception {
    ItemPath path = new ItemPath(UserType.F_NAME.getLocalPart());
    assertCanonical(path, null, "\\#name");
    assertCanonical(path, UserType.class, "\\" + COMMON + "#name");
}
Also used : CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 44 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class XPathTest method testCanonicalizationLong.

@Test
public void testCanonicalizationLong() throws Exception {
    ItemPath path = new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION, SchemaConstants.ICF_CONFIGURATION_PROPERTIES, RESOURCE_DUMMY_CONFIGURATION_USELESS_STRING_ELEMENT_NAME);
    assertCanonical(path, null, "\\" + COMMON + "#connectorConfiguration", "\\" + COMMON + "#connectorConfiguration\\" + ICFS + "#configurationProperties", "\\" + COMMON + "#connectorConfiguration\\" + ICFS + "#configurationProperties\\" + ICF + "/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector#uselessString");
}
Also used : CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 45 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class OperationalDataManager method applyMetadataModify.

public <T extends ObjectType, F extends ObjectType> void applyMetadataModify(ObjectDelta<T> objectDelta, LensElementContext<T> objectContext, Class objectTypeClass, XMLGregorianCalendar now, Task task, LensContext<F> context, OperationResult result) throws SchemaException {
    String channel = LensUtil.getChannel(context, task);
    PrismObjectDefinition<T> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass);
    ItemDelta.mergeAll(objectDelta.getModifications(), createModifyMetadataDeltas(context, new ItemPath(ObjectType.F_METADATA), def, now, task));
    List<PrismReferenceValue> approverReferenceValues = new ArrayList<PrismReferenceValue>();
    if (workflowManager != null) {
        for (ObjectReferenceType approverRef : workflowManager.getApprovedBy(task, result)) {
            approverReferenceValues.add(new PrismReferenceValue(approverRef.getOid()));
        }
    }
    if (!approverReferenceValues.isEmpty()) {
        ReferenceDelta refDelta = ReferenceDelta.createModificationReplace((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, approverReferenceValues);
        ((Collection) objectDelta.getModifications()).add(refDelta);
    } else {
        if (objectContext != null && objectContext.getObjectOld() != null) {
            if (objectContext.getObjectOld().asObjectable().getMetadata() != null) {
                List<ObjectReferenceType> existingModifyApproverRefs = objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef();
                LOGGER.trace("Original values of MODIFY_APPROVER_REF: {}", existingModifyApproverRefs);
                if (!existingModifyApproverRefs.isEmpty()) {
                    List<PrismReferenceValue> valuesToDelete = new ArrayList<PrismReferenceValue>();
                    for (ObjectReferenceType approverRef : objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef()) {
                        valuesToDelete.add(approverRef.asReferenceValue().clone());
                    }
                    ReferenceDelta refDelta = ReferenceDelta.createModificationDelete((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, valuesToDelete);
                    ((Collection) objectDelta.getModifications()).add(refDelta);
                }
            }
        }
    }
    if (FocusType.class.isAssignableFrom(objectTypeClass)) {
        applyAssignmentMetadataDelta((LensContext) context, (ObjectDelta) objectDelta, now, task, result);
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Collection(java.util.Collection) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)693 Test (org.testng.annotations.Test)184 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)143 QName (javax.xml.namespace.QName)137 Task (com.evolveum.midpoint.task.api.Task)104 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)84 ArrayList (java.util.ArrayList)79 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)71 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)68 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)61 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)48 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)46 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)41 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)38 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)38 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)33 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)31 NotNull (org.jetbrains.annotations.NotNull)30