Search in sources :

Example 1 with DeviceConnectionStatus

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);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Device(org.eclipse.kapua.service.device.registry.Device) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) DeviceConnectionStatus(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus) DeviceConnection(org.eclipse.kapua.service.device.registry.connection.DeviceConnection) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceConnectionService(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 2 with DeviceConnectionStatus

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;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) HashMap(java.util.HashMap) DeviceConnectionStatus(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus) DeviceConnectionFactory(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionFactory) DeviceConnectionQuery(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceConnectionService(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 DeviceConnectionService (org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService)2 DeviceConnectionStatus (org.eclipse.kapua.service.device.registry.connection.DeviceConnectionStatus)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)1 GwtGroupedNVPair (org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair)1 Device (org.eclipse.kapua.service.device.registry.Device)1 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)1 DeviceConnection (org.eclipse.kapua.service.device.registry.connection.DeviceConnection)1 DeviceConnectionFactory (org.eclipse.kapua.service.device.registry.connection.DeviceConnectionFactory)1 DeviceConnectionQuery (org.eclipse.kapua.service.device.registry.connection.DeviceConnectionQuery)1