Struggling with Xpath development

I am developing the Xpath functions for my patch but I cannot seem to get the expected returns

Taking the following test:

public void testGetImporter() throws Exception {
    Act doc = (Act) create("act.exportDocumentAttachment");
    Act export = (Act) create(ExportArchetypes.EXPORT);
    ActBean bean = new ActBean(export);
    bean.addRelationship("actRelationship.exportItem", doc);
    Party importer = TestHelper.createImporter(true);
    JXPathContext ctx = createContext(doc);
    assertEquals(export, ctx.getValue("openvpms:get(.,\"export.source\")"));
    //assertNull(ctx.getValue("export:getImporter(openvpms:get(.,\"export.source\"))"));
    assertNull(ctx.getValue("export:getImporter(.)"));
    bean.addParticipation("participation.importer", importer);

    assertEquals(importer, ctx.getValue("export:getImporter(openvpms:get(.,\"export.source\"))"));
    assertEquals(importer, ctx.getValue("export:getImporter(.)"));
}

you can see I am attempting to sue the core functions to check the association between document and export.

<node name="export" path="/targetActRelationships" type="java.util.HashSet"
      baseName="TargetActRelationship" minCardinality="0" maxCardinality="1" hidden="false" readOnly="true"
      filter="actRelationship.exportItem">
    <assertion name="archetypeRange">
        <propertyList name="archetypes">
            <propertyMap name="archetype">
                <property name="shortName" value="actRelationship.exportItem"/>
            </propertyMap>
        </propertyList>
    </assertion>
</node>

 

act.exportDocument* has a node the source is the act.Export and the target is the act.exportDocument ..

I have confirmed via the debug consule that the above script creates these accurately but the following function fails. returning a null. 

assertEquals(export, ctx.getValue("openvpms:get(.,\"export.source\")"));

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Struggling with Xpath development

You need to save both doc and export before you can retrieve them via the openvpms:get(...) functions.

Also, you can use single quotes to avoid the need to escape double quotes.

Re: Struggling with Xpath development

Thanks my tests are now passing 

Does save only apply when you are testing past the primary object saved into the context...ie if you try and retrieve a patient from a customer record...you would need to call save(). but if you where retrieving the customers full name you wouldnt assuming the customer was the object passed to the createContext function?

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au

Re: Struggling with Xpath development

If the underlying function needs to retrieve an object from the archetype service, the object must first be saved. So accessing the customer's name won't require the customer to be saved.

If you want to access the customer's patients, then the patients will need to be saved.

Similarly, if you have an invoice, and want to access the patients and products associated with the invoice items, then the items, patients and products will all need to be saved.

 

 

Syndicate content