Search in sources :

Example 1 with GwtDevice

use of org.eclipse.kapua.app.console.shared.model.GwtDevice 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 2 with GwtDevice

use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.

the class GwtDeviceServiceImpl method findDevice.

public GwtDevice findDevice(String scopeIdString, String clientId) throws GwtKapuaException {
    GwtDevice gwtDevice = null;
    try {
        KapuaId scopeId = KapuaEid.parseShortId(scopeIdString);
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
        Device device = deviceRegistryService.findByClientId(scopeId, clientId);
        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) 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) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 3 with GwtDevice

use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.

the class GwtDeviceServiceImpl method updateAttributes.

public GwtDevice updateAttributes(GwtXSRFToken xsrfToken, GwtDevice gwtDevice) throws GwtKapuaException {
    // 
    // Checking validity of the given XSRF Token
    checkXSRFToken(xsrfToken);
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = null;
    GwtDevice gwtDeviceUpdated = null;
    try {
        // 
        // Find original device
        KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
        device = deviceRegistryService.find(scopeId, deviceId);
        // 
        // Updated values
        // Gerenal info
        device.setDisplayName(gwtDevice.getUnescapedDisplayName());
        device.setStatus(DeviceStatus.valueOf(gwtDevice.getGwtDeviceStatus()));
        // Security Stuff
        device.setCredentialsMode(DeviceCredentialsMode.valueOf(gwtDevice.getCredentialsTight()));
        KapuaId deviceUserId = KapuaEid.parseShortId(gwtDevice.getDeviceUserId());
        device.setPreferredUserId(deviceUserId);
        // Custom attributes
        device.setCustomAttribute1(gwtDevice.getUnescapedCustomAttribute1());
        device.setCustomAttribute2(gwtDevice.getUnescapedCustomAttribute2());
        device.setCustomAttribute3(gwtDevice.getUnescapedCustomAttribute3());
        device.setCustomAttribute4(gwtDevice.getUnescapedCustomAttribute4());
        device.setCustomAttribute5(gwtDevice.getUnescapedCustomAttribute5());
        device.setOptlock(gwtDevice.getOptlock());
        // Do the update
        device = deviceRegistryService.update(device);
        // Convert to gwt object
        gwtDeviceUpdated = KapuaGwtConverter.convert(device);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtDeviceUpdated;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) 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) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 4 with GwtDevice

use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.

the class DeviceConfigComponents method refreshWhenOnline.

// --------------------------------------------------------------------------------------
// 
// Device Configuration Management
// 
// --------------------------------------------------------------------------------------
public void refreshWhenOnline() {
    final int PERIOD_MILLIS = 1000;
    Timer timer = new Timer() {

        private int TIMEOUT_MILLIS = 30000;

        private int countdownMillis = TIMEOUT_MILLIS;

        public void run() {
            if (m_selectedDevice != null) {
                countdownMillis -= PERIOD_MILLIS;
                // 
                // Poll the current status of the device until is online again or timeout.
                gwtDeviceService.findDevice(m_selectedDevice.getScopeId(), m_selectedDevice.getUnescapedClientId(), new AsyncCallback<GwtDevice>() {

                    @Override
                    public void onFailure(Throwable t) {
                        done();
                    }

                    @Override
                    public void onSuccess(GwtDevice gwtDevice) {
                        if (countdownMillis <= 0 || // Allow the device to disconnect before checking if it's online again.
                        ((TIMEOUT_MILLIS - countdownMillis) > 5000 && gwtDevice.isOnline())) {
                            done();
                        }
                    }

                    private void done() {
                        cancel();
                        refresh();
                        if (m_devConfPanel != null) {
                            m_devConfPanel.unmask();
                        }
                    }
                });
            }
        }
    };
    m_devConfPanel.mask(MSGS.waiting());
    timer.scheduleRepeating(PERIOD_MILLIS);
}
Also used : GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) Timer(com.google.gwt.user.client.Timer)

Example 5 with GwtDevice

use of org.eclipse.kapua.app.console.shared.model.GwtDevice in project kapua by eclipse.

the class DeviceConfigSnapshots method refreshWhenOnline.

// --------------------------------------------------------------------------------------
// 
// Device Event List Management
// 
// --------------------------------------------------------------------------------------
public void refreshWhenOnline() {
    final int PERIOD_MILLIS = 1000;
    Timer timer = new Timer() {

        private int TIMEOUT_MILLIS = 30000;

        private int countdownMillis = TIMEOUT_MILLIS;

        public void run() {
            if (m_selectedDevice != null) {
                countdownMillis -= PERIOD_MILLIS;
                // 
                // Poll the current status of the device until is online again or timeout.
                gwtDeviceService.findDevice(m_selectedDevice.getScopeId(), m_selectedDevice.getClientId(), new AsyncCallback<GwtDevice>() {

                    @Override
                    public void onFailure(Throwable t) {
                        done();
                    }

                    @Override
                    public void onSuccess(GwtDevice gwtDevice) {
                        if (countdownMillis <= 0 || // Allow the device to disconnect before checking if it's online again.
                        ((TIMEOUT_MILLIS - countdownMillis) > 5000 && gwtDevice.isOnline())) {
                            done();
                        }
                    }

                    private void done() {
                        cancel();
                        // force a dirty on both tabs
                        m_tabConfig.setDevice(m_selectedDevice);
                        refresh();
                    }
                });
            }
        }
    };
    m_grid.mask(MSGS.waiting());
    timer.scheduleRepeating(PERIOD_MILLIS);
}
Also used : GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) Timer(com.google.gwt.user.client.Timer)

Aggregations

GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)15 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)5 BasePagingLoadConfig (com.extjs.gxt.ui.client.data.BasePagingLoadConfig)3 Button (com.extjs.gxt.ui.client.widget.button.Button)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 KapuaId (org.eclipse.kapua.model.id.KapuaId)3 Device (org.eclipse.kapua.service.device.registry.Device)3 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)3 PagingLoadResult (com.extjs.gxt.ui.client.data.PagingLoadResult)2 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)2 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)2 PagingToolBar (com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar)2 ToolBar (com.extjs.gxt.ui.client.widget.toolbar.ToolBar)2 Timer (com.google.gwt.user.client.Timer)2 ArrayList (java.util.ArrayList)2 AndPredicate (org.eclipse.kapua.commons.model.query.predicate.AndPredicate)2 AttributePredicate (org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)2