Search in sources :

Example 6 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class ProxyLoader method get.

/**
 * retrieve object by path
 */
@Override
public C2KLocalObject get(ItemPath thisItem, String path) throws PersistencyException {
    try {
        Item thisEntity = getIOR(thisItem);
        ClusterType type = getClusterType(path);
        // fetch the xml from the item
        String queryData = thisEntity.queryData(path);
        if (Logger.doLog(8))
            Logger.msg("ProxyLoader.get() - " + thisItem + " : " + path + " = " + queryData);
        if (queryData != null) {
            if (type == ClusterType.OUTCOME)
                return new Outcome(path, queryData);
            else
                return (C2KLocalObject) Gateway.getMarshaller().unmarshall(queryData);
        }
    } catch (ObjectNotFoundException e) {
        return null;
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
    return null;
}
Also used : Item(org.cristalise.kernel.entity.Item) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ClusterType(org.cristalise.kernel.persistency.ClusterType) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 7 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class DefaultResourceImportHandler method getResourceOutcomes.

@Override
public Set<Outcome> getResourceOutcomes(String name, String ns, String location, Integer version) throws Exception {
    HashSet<Outcome> retArr = new HashSet<Outcome>();
    String data = Gateway.getResource().getTextResource(ns, location);
    if (data == null)
        throw new Exception("No data found for " + type.getSchemaName() + " " + name);
    Outcome resOutcome = new Outcome(0, data, LocalObjectLoader.getSchema(type.getSchemaName(), 0));
    retArr.add(resOutcome);
    return retArr;
}
Also used : Outcome(org.cristalise.kernel.persistency.outcome.Outcome) HashSet(java.util.HashSet)

Example 8 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class OutcomeTest method testGetRecord.

@Test
public void testGetRecord() throws Exception {
    Outcome patient1 = getOutcome("patient1", "PatientDetails");
    compareRecord(patient1.getRecord());
    compareRecord(patient1.getRecord("/PatientDetails"));
    String[] names = { "InsuranceNumber", "DateOfBirth", "Gender", "Weight" };
    compareRecord(patient1.getRecord(Arrays.asList(names)));
    compareRecord(patient1.getRecord("/PatientDetails", Arrays.asList(names)));
}
Also used : Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Test(org.junit.Test) MainTest(org.cristalise.kernel.test.process.MainTest)

Example 9 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class OutcomeTest method testSetRecord.

@Test
public void testSetRecord() throws Exception {
    Outcome patient2 = getOutcome("patient2", "PatientDetails");
    Map<String, String> record = new HashMap<>();
    record.put("InsuranceNumber", "123456789ABC");
    record.put("DateOfBirth", "1999-12-12");
    record.put("Gender", "male");
    record.put("Weight", "85");
    record.put("Note", "no comment");
    patient2.setRecord(record);
    Logger.msg(patient2.getData());
    patient2.getDOM().normalize();
    patient2.validateAndCheck();
    compareRecord(patient2.getRecord());
}
Also used : HashMap(java.util.HashMap) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Test(org.junit.Test) MainTest(org.cristalise.kernel.test.process.MainTest)

Example 10 with Outcome

use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.

the class OutcomeTest method testComplexXpath.

@Test
public void testComplexXpath() throws Exception {
    Outcome complexTestOc = getOutcome("complexOutcomeTest.xml");
    String slotID = complexTestOc.getNodeByXPath("/Fields/@slotID").getNodeValue();
    assertEquals("1", slotID);
    NodeList fields = complexTestOc.getNodesByXPath("//Field");
    for (int i = 0; i < fields.getLength(); i++) {
        NodeList children = fields.item(i).getChildNodes();
        // There are actually 5 nodes, becuase of the text nodes
        assertEquals(5, children.getLength());
        String fieldName = "";
        String fieldValue = "";
        for (int j = 0; j < children.getLength(); j++) {
            if (children.item(j).getNodeType() == Node.ELEMENT_NODE) {
                if (children.item(j).getNodeName().equals("FieldName"))
                    fieldName = children.item(j).getTextContent().trim();
                else if (children.item(j).getNodeName().equals("FieldValue"))
                    fieldValue = children.item(j).getTextContent().trim();
            } else {
                Logger.msg("testComplexXpath() - SKIPPING nodeName:" + children.item(j).getNodeName() + " nodeType:" + children.item(j).getNodeType());
            }
        }
        assertNotNull("fieldName shall not be null", fieldName);
        assertNotNull("fieldValue shall not be null", fieldValue);
        Logger.msg("testComplexXpath() - slotID:" + slotID + " fieldName:" + fieldName + " fieldValue:" + fieldValue);
    }
}
Also used : Outcome(org.cristalise.kernel.persistency.outcome.Outcome) NodeList(org.w3c.dom.NodeList) Test(org.junit.Test) MainTest(org.cristalise.kernel.test.process.MainTest)

Aggregations

Outcome (org.cristalise.kernel.persistency.outcome.Outcome)19 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)6 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)6 MainTest (org.cristalise.kernel.test.process.MainTest)6 Test (org.junit.Test)6 Schema (org.cristalise.kernel.persistency.outcome.Schema)5 History (org.cristalise.kernel.events.History)4 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 Event (org.cristalise.kernel.events.Event)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 HashMap (java.util.HashMap)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 ClusterType (org.cristalise.kernel.persistency.ClusterType)2 Property (org.cristalise.kernel.property.Property)2