Search in sources :

Example 1 with NodeElement

use of org.jivesoftware.smackx.iot.data.element.NodeElement in project Smack by igniterealtime.

the class IoTFieldsExtensionProvider method parseNode.

public NodeElement parseNode(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
    final int initialDepth = parser.getDepth();
    final NodeInfo nodeInfo = NodeInfoParser.parse(parser);
    List<TimestampElement> timestampElements = new ArrayList<>();
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case TimestampElement.ELEMENT:
                        TimestampElement timestampElement = parseTimestampElement(parser);
                        timestampElements.add(timestampElement);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new NodeElement(nodeInfo, timestampElements);
}
Also used : NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) TimestampElement(org.jivesoftware.smackx.iot.data.element.TimestampElement) ArrayList(java.util.ArrayList) NodeElement(org.jivesoftware.smackx.iot.data.element.NodeElement)

Example 2 with NodeElement

use of org.jivesoftware.smackx.iot.data.element.NodeElement in project Smack by igniterealtime.

the class IoTDataIntegrationTest method dataTest.

/**
     * Connection one provides a thing, which momentary value is read out by connection two.
     *
     * @throws Exception 
     * @throws TimeoutException 
     */
@SmackIntegrationTest
public void dataTest() throws TimeoutException, Exception {
    final String key = StringUtils.randomString(12);
    final String sn = StringUtils.randomString(12);
    final int value = INSECURE_RANDOM.nextInt();
    Thing dataThing = Thing.builder().setKey(key).setSerialNumber(sn).setMomentaryReadOutRequestHandler(new ThingMomentaryReadOutRequest() {

        @Override
        public void momentaryReadOutRequest(ThingMomentaryReadOutResult callback) {
            IoTDataField.IntField field = new IntField(testRunId, value);
            callback.momentaryReadOut(Collections.singletonList(field));
        }
    }).build();
    iotDataManagerOne.installThing(dataThing);
    List<IoTFieldsExtension> values;
    try {
        RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
        values = iotDataManagerTwo.requestMomentaryValuesReadOut(conOne.getUser());
    } finally {
        iotDataManagerOne.uninstallThing(dataThing);
        RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    }
    assertEquals(1, values.size());
    IoTFieldsExtension iotFieldsExtension = values.get(0);
    List<NodeElement> nodes = iotFieldsExtension.getNodes();
    assertEquals(1, nodes.size());
    NodeElement node = nodes.get(0);
    List<TimestampElement> timestamps = node.getTimestampElements();
    assertEquals(1, timestamps.size());
    TimestampElement timestamp = timestamps.get(0);
    List<? extends IoTDataField> fields = timestamp.getDataFields();
    assertEquals(1, fields.size());
    IoTDataField dataField = fields.get(0);
    assertTrue(dataField instanceof IoTDataField.IntField);
    IoTDataField.IntField intDataField = (IoTDataField.IntField) dataField;
    assertEquals(testRunId, intDataField.getName());
    assertEquals(value, intDataField.getValue());
}
Also used : IoTFieldsExtension(org.jivesoftware.smackx.iot.data.element.IoTFieldsExtension) TimestampElement(org.jivesoftware.smackx.iot.data.element.TimestampElement) IntField(org.jivesoftware.smackx.iot.data.element.IoTDataField.IntField) IntField(org.jivesoftware.smackx.iot.data.element.IoTDataField.IntField) IoTDataField(org.jivesoftware.smackx.iot.data.element.IoTDataField) NodeElement(org.jivesoftware.smackx.iot.data.element.NodeElement) ThingMomentaryReadOutResult(org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutResult) ThingMomentaryReadOutRequest(org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutRequest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Aggregations

NodeElement (org.jivesoftware.smackx.iot.data.element.NodeElement)2 TimestampElement (org.jivesoftware.smackx.iot.data.element.TimestampElement)2 ArrayList (java.util.ArrayList)1 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 ThingMomentaryReadOutRequest (org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutRequest)1 ThingMomentaryReadOutResult (org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutResult)1 IoTDataField (org.jivesoftware.smackx.iot.data.element.IoTDataField)1 IntField (org.jivesoftware.smackx.iot.data.element.IoTDataField.IntField)1 IoTFieldsExtension (org.jivesoftware.smackx.iot.data.element.IoTFieldsExtension)1 NodeInfo (org.jivesoftware.smackx.iot.element.NodeInfo)1