use of org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotFactory in project kapua by eclipse.
the class TranslatorAppSnapshotKuraKapua method translateBody.
private void translateBody(SnapshotResponsePayload snapshotResponsePayload, String charEncoding, KuraSnapshotIds kuraSnapshotIdResult) throws TranslatorException {
try {
if (kuraSnapshotIdResult != null) {
KapuaLocator locator = KapuaLocator.getInstance();
DeviceSnapshotFactory deviceSnapshotFactory = locator.getFactory(DeviceSnapshotFactory.class);
DeviceSnapshots deviceSnapshots = deviceSnapshotFactory.newDeviceSnapshots();
List<Long> snapshotIds = kuraSnapshotIdResult.getSnapshotIds();
for (Long snapshotId : snapshotIds) {
DeviceSnapshot snapshot = deviceSnapshotFactory.newDeviceSnapshot();
snapshot.setId(Long.toString(snapshotId));
snapshot.setTimestamp(snapshotId);
deviceSnapshots.getSnapshots().add(snapshot);
}
StringWriter sw = new StringWriter();
XmlUtil.marshal(deviceSnapshots, sw);
byte[] requestBody = sw.toString().getBytes(charEncoding);
snapshotResponsePayload.setBody(requestBody);
}
} catch (Exception e) {
throw new TranslatorException(TranslatorErrorCodes.INVALID_BODY, e, // null for now
kuraSnapshotIdResult);
}
}
Aggregations