use of org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot in project kapua by eclipse.
the class GwtDeviceManagementServiceImpl method findDeviceSnapshots.
//
// Snapshots
//
@Override
public ListLoadResult<GwtSnapshot> findDeviceSnapshots(GwtDevice gwtDevice) throws GwtKapuaException {
List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
try {
// execute the command
KapuaLocator locator = KapuaLocator.getInstance();
DeviceSnapshotManagementService deviceSnapshotManagementService = locator.getService(DeviceSnapshotManagementService.class);
KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
DeviceSnapshots snapshotIds = deviceSnapshotManagementService.get(scopeId, deviceId, null);
// sort them by most recent first
// sort the list alphabetically by service name
Collections.sort(snapshotIds.getSnapshots(), new Comparator<DeviceSnapshot>() {
@Override
public int compare(DeviceSnapshot arg0, DeviceSnapshot arg1) {
DeviceSnapshot snapshotId0 = arg0;
DeviceSnapshot snapshotId1 = arg1;
// Descending order
return -1 * snapshotId0.getTimestamp().compareTo(snapshotId1.getTimestamp());
}
});
for (DeviceSnapshot snapshot : snapshotIds.getSnapshots()) {
Long timestamp = snapshot.getTimestamp();
GwtSnapshot gwtSnapshot = new GwtSnapshot();
gwtSnapshot.setCreatedOn(new Date(timestamp));
snapshots.add(gwtSnapshot);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return new BaseListLoadResult<GwtSnapshot>(snapshots);
}
use of org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot 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