Search in sources :

Example 1 with KapuaPosition

use of org.eclipse.kapua.message.KapuaPosition in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method death.

@Override
public void death(KapuaId connectionId, KapuaDisconnectMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, message.getReceivedOn(), "DEATH");
    deviceEventCreator.setReceivedOn(message.getReceivedOn());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getSentOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 2 with KapuaPosition

use of org.eclipse.kapua.message.KapuaPosition in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method missing.

@Override
public void missing(KapuaId connectionId, KapuaMissingMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, device.getId(), message.getReceivedOn(), "MISSING");
    deviceEventCreator.setEventMessage(payload.toDisplayString());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getReceivedOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 3 with KapuaPosition

use of org.eclipse.kapua.message.KapuaPosition in project kapua by eclipse.

the class TranslatorKuraKapuaUtils method translate.

/**
 * Translate {@link DevicePosition} to {@link KapuaPosition}
 *
 * @param kuraPosition
 * @return
 */
public static KapuaPosition translate(DevicePosition kuraPosition) {
    KapuaPosition kapuaPosition = null;
    if (kuraPosition != null) {
        KapuaLocator locator = KapuaLocator.getInstance();
        KapuaMessageFactory kapuaMessageFactory = locator.getFactory(KapuaMessageFactory.class);
        kapuaPosition = kapuaMessageFactory.newPosition();
        kapuaPosition.setAltitude(kuraPosition.getAltitude());
        kapuaPosition.setHeading(kuraPosition.getHeading());
        kapuaPosition.setLatitude(kuraPosition.getLatitude());
        kapuaPosition.setLongitude(kuraPosition.getLongitude());
        kapuaPosition.setPrecision(kuraPosition.getPrecision());
        kapuaPosition.setSatellites(kuraPosition.getSatellites());
        kapuaPosition.setSpeed(kuraPosition.getSpeed());
        kapuaPosition.setStatus(kuraPosition.getStatus());
        kapuaPosition.setTimestamp(kuraPosition.getTimestamp());
    }
    return kapuaPosition;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) KapuaMessageFactory(org.eclipse.kapua.message.KapuaMessageFactory)

Example 4 with KapuaPosition

use of org.eclipse.kapua.message.KapuaPosition in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method applications.

@Override
public void applications(KapuaId connectionId, KapuaAppsMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, device.getId(), message.getReceivedOn(), "APPLICATION");
    deviceEventCreator.setEventMessage(payload.toDisplayString());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getReceivedOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 5 with KapuaPosition

use of org.eclipse.kapua.message.KapuaPosition in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method birth.

@Override
public void birth(KapuaId connectionId, KapuaBirthMessage message) throws KapuaException {
    KapuaBirthPayload payload = message.getPayload();
    KapuaBirthChannel channel = message.getChannel();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = null;
    if (deviceId == null) {
        String clientId = channel.getClientId();
        DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class);
        DeviceCreator deviceCreator = deviceFactory.newCreator(scopeId, clientId);
        deviceCreator.setDisplayName(payload.getDisplayName());
        deviceCreator.setSerialNumber(payload.getSerialNumber());
        deviceCreator.setModelId(payload.getModelId());
        deviceCreator.setImei(payload.getModemImei());
        deviceCreator.setImsi(payload.getModemImsi());
        deviceCreator.setIccid(payload.getModemIccid());
        deviceCreator.setBiosVersion(payload.getBiosVersion());
        deviceCreator.setFirmwareVersion(payload.getFirmwareVersion());
        deviceCreator.setOsVersion(payload.getOsVersion());
        deviceCreator.setJvmVersion(payload.getJvmVersion());
        deviceCreator.setOsgiFrameworkVersion(payload.getContainerFrameworkVersion());
        deviceCreator.setApplicationIdentifiers(payload.getApplicationIdentifiers());
        deviceCreator.setAcceptEncoding(payload.getAcceptEncoding());
        deviceCreator.setCredentialsMode(DeviceCredentialsMode.LOOSE);
        device = deviceRegistryService.create(deviceCreator);
    } else {
        device = deviceRegistryService.find(scopeId, deviceId);
        device.setDisplayName(payload.getDisplayName());
        device.setSerialNumber(payload.getSerialNumber());
        device.setModelId(payload.getModelId());
        device.setImei(payload.getModemImei());
        device.setImsi(payload.getModemImsi());
        device.setIccid(payload.getModemIccid());
        device.setBiosVersion(payload.getBiosVersion());
        device.setFirmwareVersion(payload.getFirmwareVersion());
        device.setOsVersion(payload.getOsVersion());
        device.setJvmVersion(payload.getJvmVersion());
        device.setOsgiFrameworkVersion(payload.getContainerFrameworkVersion());
        device.setApplicationIdentifiers(payload.getApplicationIdentifiers());
        device.setAcceptEncoding(payload.getAcceptEncoding());
        deviceRegistryService.update(device);
    }
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, device.getId(), message.getReceivedOn(), "BIRTH");
    deviceEventCreator.setEventMessage(payload.toDisplayString());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getSentOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceFactory(org.eclipse.kapua.service.device.registry.DeviceFactory) KapuaBirthChannel(org.eclipse.kapua.message.device.lifecycle.KapuaBirthChannel) DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaBirthPayload(org.eclipse.kapua.message.device.lifecycle.KapuaBirthPayload)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)5 KapuaPosition (org.eclipse.kapua.message.KapuaPosition)5 KapuaId (org.eclipse.kapua.model.id.KapuaId)4 Device (org.eclipse.kapua.service.device.registry.Device)4 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)4 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)4 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)4 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)4 KapuaPayload (org.eclipse.kapua.message.KapuaPayload)3 KapuaMessageFactory (org.eclipse.kapua.message.KapuaMessageFactory)1 KapuaBirthChannel (org.eclipse.kapua.message.device.lifecycle.KapuaBirthChannel)1 KapuaBirthPayload (org.eclipse.kapua.message.device.lifecycle.KapuaBirthPayload)1 DeviceCreator (org.eclipse.kapua.service.device.registry.DeviceCreator)1 DeviceFactory (org.eclipse.kapua.service.device.registry.DeviceFactory)1