use of org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus in project kapua by eclipse.
the class GwtDeviceServiceImpl method findDeviceProfile.
public ListLoadResult<GwtGroupedNVPair> findDeviceProfile(String scopeIdString, String clientId) throws GwtKapuaException {
List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
KapuaLocator locator = KapuaLocator.getInstance();
DeviceRegistryService drs = locator.getService(DeviceRegistryService.class);
DeviceConnectionService dcs = locator.getService(DeviceConnectionService.class);
try {
KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
Device device = drs.findByClientId(scopeId, clientId);
if (device != null) {
pairs.add(new GwtGroupedNVPair("devInfo", "devStatus", device.getStatus().toString()));
DeviceConnection deviceConnection = dcs.findByClientId(scopeId, device.getClientId());
DeviceConnectionStatus connectionStatus = null;
if (deviceConnection != null) {
connectionStatus = deviceConnection.getStatus();
} else {
connectionStatus = DeviceConnectionStatus.DISCONNECTED;
}
pairs.add(new GwtGroupedNVPair("devInfo", "devConnectionStatus", connectionStatus.toString()));
pairs.add(new GwtGroupedNVPair("devInfo", "devClientId", device.getClientId()));
pairs.add(new GwtGroupedNVPair("devInfo", "devDisplayName", device.getDisplayName()));
String lastEventType = device.getLastEventType() != null ? device.getLastEventType().toString() : "";
pairs.add(new GwtGroupedNVPair("devInfo", "devLastEventType", lastEventType));
if (device.getLastEventOn() != null) {
pairs.add(new GwtGroupedNVPair("devInfo", "devLastEventOn", String.valueOf(device.getLastEventOn().getTime())));
} else {
pairs.add(new GwtGroupedNVPair("devInfo", "devLastEventOn", null));
}
if (device.getPreferredUserId() != null) {
pairs.add(new GwtGroupedNVPair("devInfo", "devLastUserUsed", device.getPreferredUserId().getShortId()));
}
pairs.add(new GwtGroupedNVPair("devInfo", "devApps", device.getApplicationIdentifiers()));
pairs.add(new GwtGroupedNVPair("devInfo", "devAccEnc", device.getAcceptEncoding()));
pairs.add(new GwtGroupedNVPair("devAttributesInfo", "devCustomAttribute1", device.getCustomAttribute1()));
pairs.add(new GwtGroupedNVPair("devAttributesInfo", "devCustomAttribute2", device.getCustomAttribute2()));
pairs.add(new GwtGroupedNVPair("devAttributesInfo", "devCustomAttribute3", device.getCustomAttribute3()));
pairs.add(new GwtGroupedNVPair("devAttributesInfo", "devCustomAttribute4", device.getCustomAttribute4()));
pairs.add(new GwtGroupedNVPair("devAttributesInfo", "devCustomAttribute5", device.getCustomAttribute5()));
// Credentials tight
pairs.add(new GwtGroupedNVPair("devSecurity", "devSecurityCredentialsTight", GwtDeviceCredentialsTight.valueOf(device.getCredentialsMode().name()).getLabel()));
pairs.add(new GwtGroupedNVPair("devSecurity", "devSecurityAllowCredentialsChange", device.getPreferredUserId() == null ? "Yes" : "No"));
pairs.add(new GwtGroupedNVPair("devHw", "devModelName", device.getModelId()));
pairs.add(new GwtGroupedNVPair("devHw", "devModelId", device.getModelId()));
pairs.add(new GwtGroupedNVPair("devHw", "devSerialNumber", device.getSerialNumber()));
pairs.add(new GwtGroupedNVPair("devSw", "devFirmwareVersion", device.getFirmwareVersion()));
pairs.add(new GwtGroupedNVPair("devSw", "devBiosVersion", device.getBiosVersion()));
pairs.add(new GwtGroupedNVPair("devSw", "devOsVersion", device.getOsVersion()));
pairs.add(new GwtGroupedNVPair("devJava", "devJvmVersion", device.getJvmVersion()));
pairs.add(new GwtGroupedNVPair("netInfo", "netConnIp", deviceConnection.getClientIp()));
pairs.add(new GwtGroupedNVPair("gpsInfo", "gpsLat", String.valueOf(device.getGpsLatitude())));
pairs.add(new GwtGroupedNVPair("gpsInfo", "gpsLong", String.valueOf(device.getGpsLongitude())));
pairs.add(new GwtGroupedNVPair("modemInfo", "modemImei", device.getImei()));
pairs.add(new GwtGroupedNVPair("modemInfo", "modemImsi", device.getImsi()));
pairs.add(new GwtGroupedNVPair("modemInfo", "modemIccid", device.getIccid()));
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}
return new BaseListLoadResult<GwtGroupedNVPair>(pairs);
}
use of org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus in project kapua by eclipse.
the class GwtDeviceServiceImpl method getNumOfDevicesConnected.
public Map<String, Integer> getNumOfDevicesConnected(String scopeIdString) throws GwtKapuaException {
KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
Map<String, Integer> devicesStatus = new HashMap<String, Integer>();
KapuaLocator locator = KapuaLocator.getInstance();
DeviceConnectionService dcs = locator.getService(DeviceConnectionService.class);
DeviceConnectionFactory deviceConnectionFactory = locator.getFactory(DeviceConnectionFactory.class);
try {
DeviceConnectionQuery query = deviceConnectionFactory.newQuery(scopeId);
query.setPredicate(new AttributePredicate<DeviceConnectionStatus>(DeviceConnectionPredicates.CONNECTION_STATUS, DeviceConnectionStatus.CONNECTED));
int count = new Long(dcs.count(query)).intValue();
if (count > 0) {
devicesStatus.put("connected", count);
}
query.setPredicate(new AttributePredicate<DeviceConnectionStatus>(DeviceConnectionPredicates.CONNECTION_STATUS, DeviceConnectionStatus.DISCONNECTED));
count = new Long(dcs.count(query)).intValue();
if (count > 0) {
devicesStatus.put("disconnected", count);
}
query.setPredicate(new AttributePredicate<DeviceConnectionStatus>(DeviceConnectionPredicates.CONNECTION_STATUS, DeviceConnectionStatus.MISSING));
count = new Long(dcs.count(query)).intValue();
if (count > 0) {
devicesStatus.put("missing", count);
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
return null;
}
return devicesStatus;
}
Aggregations