Search in sources :

Example 1 with DeviceCreator

use of org.eclipse.kapua.service.device.registry.DeviceCreator in project kapua by eclipse.

the class DeviceValidationTest method shouldValidateNullClientIdInCreator.

@Test
public void shouldValidateNullClientIdInCreator() throws KapuaException {
    DeviceCreator deviceCreator = new TestDeviceCreator(new KapuaEid(ONE));
    try {
        deviceValidation.validateCreatePreconditions(deviceCreator);
    } catch (KapuaIllegalNullArgumentException e) {
        if (e.getMessage().contains("clientId")) {
            return;
        }
    }
    fail();
}
Also used : DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) KapuaIllegalNullArgumentException(org.eclipse.kapua.KapuaIllegalNullArgumentException) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Test(org.junit.Test)

Example 2 with DeviceCreator

use of org.eclipse.kapua.service.device.registry.DeviceCreator in project kapua by eclipse.

the class GwtDeviceServiceImpl method createDevice.

public GwtDevice createDevice(GwtXSRFToken xsrfToken, GwtDeviceCreator gwtDeviceCreator) throws GwtKapuaException {
    // 
    // Checking validity of the given XSRF Token
    checkXSRFToken(xsrfToken);
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class);
    GwtDevice gwtDevice = null;
    try {
        KapuaId scopeId = KapuaEid.parseShortId(gwtDeviceCreator.getScopeId());
        DeviceCreator deviceCreator = deviceFactory.newCreator(scopeId, gwtDeviceCreator.getClientId());
        deviceCreator.setDisplayName(gwtDeviceCreator.getDisplayName());
        deviceCreator.setCredentialsMode(DeviceCredentialsMode.valueOf(gwtDeviceCreator.getGwtCredentialsTight().name()));
        deviceCreator.setCustomAttribute1(gwtDeviceCreator.getCustomAttribute1());
        deviceCreator.setCustomAttribute2(gwtDeviceCreator.getCustomAttribute2());
        deviceCreator.setCustomAttribute3(gwtDeviceCreator.getCustomAttribute3());
        deviceCreator.setCustomAttribute4(gwtDeviceCreator.getCustomAttribute4());
        deviceCreator.setCustomAttribute5(gwtDeviceCreator.getCustomAttribute5());
        Device device = deviceRegistryService.create(deviceCreator);
        gwtDevice = KapuaGwtConverter.convert(device);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtDevice;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) GwtDeviceCreator(org.eclipse.kapua.app.console.shared.model.GwtDeviceCreator) Device(org.eclipse.kapua.service.device.registry.Device) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceFactory(org.eclipse.kapua.service.device.registry.DeviceFactory) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 3 with DeviceCreator

use of org.eclipse.kapua.service.device.registry.DeviceCreator 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)

Example 4 with DeviceCreator

use of org.eclipse.kapua.service.device.registry.DeviceCreator in project kapua by eclipse.

the class DeviceValidationTest method shouldValidateNullScopeIdInCreator.

@Test
public void shouldValidateNullScopeIdInCreator() throws KapuaException {
    DeviceCreator deviceCreator = new TestDeviceCreator(null);
    try {
        deviceValidation.validateCreatePreconditions(deviceCreator);
    } catch (KapuaIllegalNullArgumentException e) {
        if (e.getMessage().contains("scopeId")) {
            return;
        }
    }
    fail();
}
Also used : DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) KapuaIllegalNullArgumentException(org.eclipse.kapua.KapuaIllegalNullArgumentException) Test(org.junit.Test)

Example 5 with DeviceCreator

use of org.eclipse.kapua.service.device.registry.DeviceCreator in project kapua by eclipse.

the class DeviceValidationTest method shouldCheckCreatorPermissions.

@Test
public void shouldCheckCreatorPermissions() throws KapuaException {
    // Given
    DeviceCreator deviceCreator = new TestDeviceCreator(new KapuaEid(ONE));
    deviceCreator.setClientId("foo");
    // When
    deviceValidation.validateCreatePreconditions(deviceCreator);
    // Then
    Mockito.verify(authorizationService).checkPermission(any(Permission.class));
}
Also used : DeviceCreator(org.eclipse.kapua.service.device.registry.DeviceCreator) Permission(org.eclipse.kapua.service.authorization.permission.Permission) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Test(org.junit.Test)

Aggregations

DeviceCreator (org.eclipse.kapua.service.device.registry.DeviceCreator)7 Test (org.junit.Test)4 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)3 KapuaIllegalNullArgumentException (org.eclipse.kapua.KapuaIllegalNullArgumentException)2 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 Device (org.eclipse.kapua.service.device.registry.Device)2 DeviceFactory (org.eclipse.kapua.service.device.registry.DeviceFactory)2 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)2 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)1 GwtDeviceCreator (org.eclipse.kapua.app.console.shared.model.GwtDeviceCreator)1 KapuaPosition (org.eclipse.kapua.message.KapuaPosition)1 KapuaBirthChannel (org.eclipse.kapua.message.device.lifecycle.KapuaBirthChannel)1 KapuaBirthPayload (org.eclipse.kapua.message.device.lifecycle.KapuaBirthPayload)1 Permission (org.eclipse.kapua.service.authorization.permission.Permission)1 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)1 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)1 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)1