use of org.jivesoftware.smackx.iot.data.element.TimestampElement 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 XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch(eventType) {
case START_ELEMENT:
switch(name) {
case TimestampElement.ELEMENT:
TimestampElement timestampElement = parseTimestampElement(parser);
timestampElements.add(timestampElement);
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return new NodeElement(nodeInfo, timestampElements);
}
use of org.jivesoftware.smackx.iot.data.element.TimestampElement 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 if an exception occurs.
* @throws TimeoutException if there was a timeout.
*/
@SmackIntegrationTest
public void dataTest() throws 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 {
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
values = iotDataManagerTwo.requestMomentaryValuesReadOut(conOne.getUser());
} finally {
iotDataManagerOne.uninstallThing(dataThing);
IntegrationTestRosterUtil.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());
}
use of org.jivesoftware.smackx.iot.data.element.TimestampElement in project Smack by igniterealtime.
the class IoTFieldsExtensionProvider method parseTimestampElement.
public TimestampElement parseTimestampElement(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
final int initialDepth = parser.getDepth();
final String dateString = parser.getAttributeValue(null, "value");
Date date = XmppDateTime.parseDate(dateString);
List<IoTDataField> fields = new ArrayList<>();
outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
final String name = parser.getName();
IoTDataField field = null;
final String fieldName = parser.getAttributeValue(null, "name");
final String fieldValue = parser.getAttributeValue(null, "value");
switch(name) {
case "int":
{
int value = Integer.parseInt(fieldValue);
field = new IoTDataField.IntField(fieldName, value);
}
break;
case "boolean":
{
boolean value = Boolean.parseBoolean(fieldValue);
field = new IoTDataField.BooleanField(fieldName, value);
}
break;
default:
LOGGER.warning("IoT Data field type '" + name + "' not implement yet. Ignoring.");
break;
}
if (field != null) {
fields.add(field);
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return new TimestampElement(date, fields);
}
Aggregations