Search in sources :

Example 1 with DeviceSnapshotFactory

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);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) StringWriter(java.io.StringWriter) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) DeviceSnapshot(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot) DeviceSnapshots(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException) DeviceSnapshotFactory(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotFactory)

Aggregations

StringWriter (java.io.StringWriter)1 KapuaException (org.eclipse.kapua.KapuaException)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 DeviceSnapshot (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot)1 DeviceSnapshotFactory (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotFactory)1 DeviceSnapshots (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1