Search in sources :

Example 1 with GwtGroupedNVPair

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

the class GwtDeviceManagementServiceImpl method findBundles.

// 
// Bundles
// 
@Override
public ListLoadResult<GwtGroupedNVPair> findBundles(GwtDevice device) throws GwtKapuaException {
    List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
    try {
        // get the configuration
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(device.getScopeId());
        KapuaId id = KapuaEid.parseShortId(device.getId());
        DeviceBundles bundles = deviceBundleManagementService.get(scopeId, id, null);
        for (DeviceBundle bundle : bundles.getBundles()) {
            GwtGroupedNVPair pair = new GwtGroupedNVPair();
            pair.setId(String.valueOf(bundle.getId()));
            pair.setName(bundle.getName());
            pair.setStatus(toStateString(bundle));
            pair.setVersion(bundle.getVersion());
            pairs.add(pair);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtGroupedNVPair>(pairs);
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DeviceBundles(org.eclipse.kapua.service.device.management.bundle.DeviceBundles) ArrayList(java.util.ArrayList) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceBundle(org.eclipse.kapua.service.device.management.bundle.DeviceBundle) DeviceBundleManagementService(org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair)

Example 2 with GwtGroupedNVPair

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

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

the class AccountDetailsView method createGrid.

private void createGrid(Element parent) {
    RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {

        @Override
        protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
            gwtAccountService.getAccountInfo(selectedAccount.getId(), callback);
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
    m_loader.addLoadListener(new DataLoadListener());
    m_store = new GroupingStore<GwtGroupedNVPair>(m_loader);
    m_store.groupBy("groupLoc");
    ColumnConfig name = new ColumnConfig("nameLoc", MSGS.devicePropName(), 50);
    ColumnConfig value = new ColumnConfig("value", MSGS.devicePropValue(), 50);
    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    config.add(name);
    config.add(value);
    ColumnModel cm = new ColumnModel(config);
    GroupingView view = new GroupingView();
    view.setShowGroupedColumn(false);
    view.setForceFit(true);
    view.setEmptyText(MSGS.accountNoSelectedAccount());
    m_grid = new Grid<GwtGroupedNVPair>(m_store, cm);
    m_grid.setView(view);
    m_grid.setBorders(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.disableTextSelection(false);
    add(m_grid);
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) GroupingView(com.extjs.gxt.ui.client.widget.grid.GroupingView)

Example 4 with GwtGroupedNVPair

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

the class DeviceTabBundles method initToolBar.

private void initToolBar() {
    m_toolBar = new ToolBar();
    // 
    // Refresh Button
    m_refreshButton = new Button(MSGS.refreshButton(), AbstractImagePrototype.create(Resources.INSTANCE.refresh()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (!refreshProcess) {
                refreshProcess = true;
                if (m_selectedDevice.isOnline()) {
                    m_toolBar.disable();
                    m_dirty = true;
                    refresh();
                    refreshProcess = false;
                } else {
                    MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                        @Override
                        public void handleEvent(MessageBoxEvent be) {
                            m_grid.unmask();
                            refreshProcess = false;
                        }
                    });
                }
            }
        }
    });
    m_refreshButton.setEnabled(true);
    m_toolBar.add(m_refreshButton);
    m_toolBar.add(new SeparatorToolItem());
    final AsyncCallback<Void> callback = new AsyncCallback<Void>() {

        public void onFailure(Throwable caught) {
            FailureHandler.handle(caught);
            m_dirty = true;
        }

        public void onSuccess(Void arg0) {
            // mark this panel dirty and also all the other pier panels
            m_deviceTabs.setDevice(m_selectedDevice);
            m_dirty = true;
            refresh();
        }
    };
    // 
    // Start Button
    m_startButton = new Button(MSGS.deviceBndStart(), AbstractImagePrototype.create(Resources.INSTANCE.bundleStart()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_selectedDevice.isOnline()) {
                m_toolBar.disable();
                m_grid.mask(MSGS.loading());
                // 
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtDeviceManagementService.startBundle(token, m_selectedDevice, m_grid.getSelectionModel().getSelectedItem(), callback);
                    }
                });
            } else {
                MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        m_grid.unmask();
                    }
                });
            }
        }
    });
    m_startButton.setEnabled(true);
    m_toolBar.add(m_startButton);
    m_toolBar.add(new SeparatorToolItem());
    // 
    // Stop Button
    m_stopButton = new Button(MSGS.deviceBndStop(), AbstractImagePrototype.create(Resources.INSTANCE.bundleStop()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_selectedDevice.isOnline()) {
                final GwtGroupedNVPair pair = m_grid.getSelectionModel().getSelectedItem();
                String bundleName = pair.getName();
                MessageBox.confirm(MSGS.confirm(), MSGS.deviceStopBundle(bundleName), new Listener<MessageBoxEvent>() {

                    public void handleEvent(MessageBoxEvent ce) {
                        // if confirmed, stop
                        Dialog dialog = ce.getDialog();
                        if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
                            m_toolBar.disable();
                            m_grid.mask(MSGS.loading());
                            // 
                            // Getting XSRF token
                            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                                @Override
                                public void onFailure(Throwable ex) {
                                    FailureHandler.handle(ex);
                                }

                                @Override
                                public void onSuccess(GwtXSRFToken token) {
                                    gwtDeviceManagementService.stopBundle(token, m_selectedDevice, pair, callback);
                                }
                            });
                        }
                    }
                });
            } else {
                MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        m_grid.unmask();
                    }
                });
            }
        }
    });
    m_stopButton.setEnabled(true);
    m_toolBar.add(m_stopButton);
    m_toolBar.add(new SeparatorToolItem());
    m_toolBar.disable();
}
Also used : SeparatorToolItem(com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) ToolBar(com.extjs.gxt.ui.client.widget.toolbar.ToolBar) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Example 5 with GwtGroupedNVPair

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

the class DeviceTabBundles method initGrid.

private void initGrid() {
    RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {

        @Override
        protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
            if (m_selectedDevice != null) {
                if (m_selectedDevice.isOnline()) {
                    gwtDeviceManagementService.findBundles(m_selectedDevice, callback);
                } else {
                    m_grid.getStore().removeAll();
                    m_grid.unmask();
                }
            }
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
    m_loader.addLoadListener(new DataLoadListener());
    m_store = new ListStore<GwtGroupedNVPair>(m_loader);
    ColumnConfig id = new ColumnConfig("id", MSGS.deviceBndId(), 10);
    ColumnConfig name = new ColumnConfig("name", MSGS.deviceBndName(), 50);
    ColumnConfig status = new ColumnConfig("statusLoc", MSGS.deviceBndState(), 20);
    ColumnConfig version = new ColumnConfig("version", MSGS.deviceBndVersion(), 20);
    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    config.add(id);
    config.add(name);
    config.add(status);
    config.add(version);
    ColumnModel cm = new ColumnModel(config);
    GridView view = new GridView();
    view.setForceFit(true);
    view.setEmptyText(MSGS.deviceNoDeviceSelectedOrOffline());
    m_grid = new Grid<GwtGroupedNVPair>(m_store, cm);
    m_grid.setView(view);
    m_grid.setBorders(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    GridSelectionModel<GwtGroupedNVPair> selectionModel = new GridSelectionModel<GwtGroupedNVPair>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
    m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtGroupedNVPair>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtGroupedNVPair> se) {
            if (m_grid.getSelectionModel().getSelectedItem() != null) {
                GwtGroupedNVPair selectedBundle = m_grid.getSelectionModel().getSelectedItem();
                if ("bndActive".equals(selectedBundle.getStatus())) {
                    m_startButton.disable();
                    m_stopButton.enable();
                } else {
                    m_stopButton.disable();
                    m_startButton.enable();
                }
            }
        }
    });
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) GridView(com.extjs.gxt.ui.client.widget.grid.GridView)

Aggregations

GwtGroupedNVPair (org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair)7 ArrayList (java.util.ArrayList)6 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)3 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)3 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)3 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)3 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)3 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)3 KapuaId (org.eclipse.kapua.model.id.KapuaId)3 GroupingView (com.extjs.gxt.ui.client.widget.grid.GroupingView)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)1 Dialog (com.extjs.gxt.ui.client.widget.Dialog)1 Button (com.extjs.gxt.ui.client.widget.button.Button)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)1