Search in sources :

Example 1 with BasePagingLoadConfig

use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.

the class GwtDeviceServiceImpl method findDeviceEvents.

public PagingLoadResult<GwtDeviceEvent> findDeviceEvents(PagingLoadConfig loadConfig, GwtDevice gwtDevice, Date startDate, Date endDate) throws GwtKapuaException {
    ArrayList<GwtDeviceEvent> gwtDeviceEvents = new ArrayList<GwtDeviceEvent>();
    BasePagingLoadResult<GwtDeviceEvent> gwtResults = null;
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceEventService des = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    try {
        // prepare the query
        BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig;
        DeviceEventQuery query = deviceEventFactory.newQuery(KapuaEid.parseShortId(gwtDevice.getScopeId()));
        KapuaAndPredicate andPredicate = new AndPredicate();
        andPredicate.and(new AttributePredicate<KapuaId>(DeviceEventPredicates.DEVICE_ID, KapuaEid.parseShortId(gwtDevice.getId())));
        // .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.GREATER_THAN));
        // .and(new AttributePredicate<Date>(DeviceEventPredicates.RECEIVED_ON, startDate, Operator.LESS_THAN));
        query.setPredicate(andPredicate);
        query.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, SortOrder.DESCENDING));
        query.setOffset(bplc.getOffset());
        query.setLimit(bplc.getLimit());
        // query execute
        KapuaListResult<DeviceEvent> deviceEvents = des.query(query);
        // prepare results
        for (DeviceEvent deviceEvent : deviceEvents.getItems()) {
            gwtDeviceEvents.add(KapuaGwtConverter.convert(deviceEvent));
        }
        gwtResults = new BasePagingLoadResult<GwtDeviceEvent>(gwtDeviceEvents);
        gwtResults.setOffset(loadConfig.getOffset());
        gwtResults.setTotalLength((int) des.count(query));
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return gwtResults;
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) ArrayList(java.util.ArrayList) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) AndPredicate(org.eclipse.kapua.commons.model.query.predicate.AndPredicate) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventQuery(org.eclipse.kapua.service.device.registry.event.DeviceEventQuery) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) FieldSortCriteria(org.eclipse.kapua.commons.model.query.FieldSortCriteria) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 2 with BasePagingLoadConfig

use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.

the class DeviceTabHistory method initGrid.

private void initGrid() {
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("receivedOnFormatted", MSGS.deviceEventTime(), 75);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    column = new ColumnConfig("eventType", MSGS.deviceEventType(), 50);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    TreeGridCellRenderer<GwtDeviceEvent> eventMessageRenderer = new TreeGridCellRenderer<GwtDeviceEvent>() {

        @Override
        public Object render(GwtDeviceEvent model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDeviceEvent> store, Grid<GwtDeviceEvent> grid) {
            StringBuilder message = new StringBuilder("");
            if (model.getEventMessage() != null) {
                message.append("<label title='").append(model.getUnescapedEventMessage()).append("'>").append(model.getUnescapedEventMessage()).append("</label>");
            }
            return message.toString();
        }
    };
    column = new ColumnConfig("eventMessage", MSGS.deviceEventMessage(), 200);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.LEFT);
    column.setRenderer(eventMessageRenderer);
    columns.add(column);
    // loader and store
    RpcProxy<PagingLoadResult<GwtDeviceEvent>> proxy = new RpcProxy<PagingLoadResult<GwtDeviceEvent>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtDeviceEvent>> callback) {
            if (m_selectedDevice != null) {
                PagingLoadConfig pagingConfig = (BasePagingLoadConfig) loadConfig;
                ((BasePagingLoadConfig) pagingConfig).setLimit(DEVICE_PAGE_SIZE);
                gwtDeviceService.findDeviceEvents(pagingConfig, m_selectedDevice, m_dateRangeSelector.getStartDate(), m_dateRangeSelector.getEndDate(), callback);
            }
        }
    };
    m_loader = new BasePagingLoader<PagingLoadResult<GwtDeviceEvent>>(proxy);
    m_loader.setSortDir(SortDir.DESC);
    m_loader.setSortField("receivedOnFormatted");
    m_loader.setRemoteSort(true);
    m_loader.addLoadListener(new DataLoadListener());
    ListStore<GwtDeviceEvent> store = new ListStore<GwtDeviceEvent>(m_loader);
    m_grid = new Grid<GwtDeviceEvent>(store, new ColumnModel(columns));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setTrackMouseOver(false);
    m_grid.setAutoExpandColumn("eventMessage");
    m_grid.disableTextSelection(false);
    m_grid.getView().setAutoFill(true);
    m_grid.getView().setEmptyText(MSGS.deviceHistoryTableNoHistory());
    m_pagingToolBar = new PagingToolBar(DEVICE_PAGE_SIZE);
    m_pagingToolBar.bind(m_loader);
    GridSelectionModel<GwtDeviceEvent> selectionModel = new GridSelectionModel<GwtDeviceEvent>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
}
Also used : TreeGridCellRenderer(com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) PagingToolBar(com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) PagingLoadConfig(com.extjs.gxt.ui.client.data.PagingLoadConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig)

Example 3 with BasePagingLoadConfig

use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.

the class DevicesMap method refresh.

public void refresh(GwtDeviceQueryPredicates predicates) {
    // clean-up the Marker list
    m_markerLayer.destroyFeatures();
    if (m_popup != null) {
        m_map.removePopup(m_popup);
    }
    // reload the devices for this account
    final DevicesMap theDeviceMap = this;
    theDeviceMap.mask(MSGS.loading());
    BasePagingLoadConfig loadConfig = new BasePagingLoadConfig(0, 500);
    gwtDeviceService.findDevices(loadConfig, m_currentSession.getSelectedAccount().getId(), predicates, new AsyncCallback<PagingLoadResult<GwtDevice>>() {

        public void onFailure(Throwable caught) {
            FailureHandler.handle(caught);
            theDeviceMap.unmask();
        }

        public void onSuccess(PagingLoadResult<GwtDevice> loadResult) {
            placeMarkers(loadResult.getData());
            theDeviceMap.unmask();
        }
    });
}
Also used : GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult)

Example 4 with BasePagingLoadConfig

use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.

the class DevicesTable method initDevicesGrid.

private void initDevicesGrid() {
    // 
    // Column Configuration
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("status", MSGS.deviceTableStatus(), 50);
    column.setAlignment(HorizontalAlignment.CENTER);
    GridCellRenderer<GwtDevice> setStatusIcon = new GridCellRenderer<GwtDevice>() {

        public String render(GwtDevice gwtDevice, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDevice> deviceList, Grid<GwtDevice> grid) {
            if (gwtDevice.getGwtDeviceStatus().compareTo("ENABLED") == 0) {
                if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("CONNECTED") == 0) {
                    return ImageUtils.toHTML(Resources.INSTANCE.greenBullet14(), MSGS.connected(), "10");
                } else if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("MISSING") == 0) {
                    return ImageUtils.toHTML(Resources.INSTANCE.redBullet14(), MSGS.missing(), "10");
                } else if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("DISCONNECTED") == 0) {
                    return ImageUtils.toHTML(Resources.INSTANCE.yellowBullet14(), MSGS.disconnected(), "10");
                }
                return gwtDevice.getGwtDeviceConnectionStatus();
            } else {
                if (gwtDevice.getGwtDeviceConnectionStatus().compareTo("CONNECTED") == 0) {
                    return ImageUtils.toHTML(Resources.INSTANCE.greenAndBlackBullet14(), MSGS.disabledButConnected(), "10");
                }
                return ImageUtils.toHTML(Resources.INSTANCE.blackBullet14(), MSGS.disabled(), "10");
            }
        }
    };
    column.setRenderer(setStatusIcon);
    column.setAlignment(HorizontalAlignment.CENTER);
    column.setSortable(false);
    configs.add(column);
    column = new ColumnConfig("clientId", MSGS.deviceTableClientID(), 175);
    column.setSortable(true);
    configs.add(column);
    column = new ColumnConfig("displayName", MSGS.deviceTableDisplayName(), 150);
    column.setSortable(true);
    configs.add(column);
    column = new ColumnConfig("lastEventOnFormatted", MSGS.deviceTableLastReportedDate(), 130);
    column.setSortable(true);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("lastEventType", MSGS.deviceTableLastEventType(), 130);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("serialNumber", MSGS.deviceTableSerialNumber(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    // 
    // Device Management Certificate
    column = new ColumnConfig("Device Management Certificate Status", "DM", 50);
    column.setAlignment(HorizontalAlignment.CENTER);
    GridCellRenderer<GwtDevice> setDmStatusIcon = new GridCellRenderer<GwtDevice>() {

        public String render(GwtDevice gwtDevice, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDevice> deviceList, Grid<GwtDevice> grid) {
            if (gwtDevice.getSignedCertificateId() == null) {
                // Device Management Communication is not signed
                return ImageUtils.toHTML(Resources.INSTANCE.dmUnlock16(), MSGS.deviceTableCertificateDMTooltipStatusNotSigned(), "14");
            } else {
                // Device Management Communication is signed
                return ImageUtils.toHTML(Resources.INSTANCE.lockGreen16(), MSGS.deviceTableCertificateDMTooltipStatusSigned(), "14");
            }
        }
    };
    column.setRenderer(setDmStatusIcon);
    column.setAlignment(HorizontalAlignment.CENTER);
    column.setSortable(false);
    configs.add(column);
    column = new ColumnConfig("applicationIdentifiers", MSGS.deviceTableApplications(), 100);
    column.setSortable(false);
    column.setHidden(false);
    configs.add(column);
    column = new ColumnConfig("esfKuraVersion", MSGS.deviceTableEsfKuraVersion(), 80);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("customAttribute1", MSGS.deviceTableCustomAttribute1(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("customAttribute2", MSGS.deviceTableCustomAttribute2(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("connectionIp", MSGS.deviceTableIpAddress(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("modelId", MSGS.deviceTableModelId(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("firmwareVersion", MSGS.deviceTableFirmwareVersion(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("biosVersion", MSGS.deviceTableBiosVersion(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("osVersion", MSGS.deviceTableOsVersion(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("jvmVersion", MSGS.deviceTableJvmVersion(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("osgiFrameworkVersion", MSGS.deviceTableOsgiVersion(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("imei", MSGS.deviceTableImei(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("imsi", MSGS.deviceTableImsi(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    column = new ColumnConfig("iccid", MSGS.deviceTableIccid(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    // signedCertificateId
    column = new ColumnConfig("signedCertificateId", MSGS.deviceTableCertificate(), 100);
    column.setSortable(false);
    column.setHidden(true);
    configs.add(column);
    // loader and store
    RpcProxy<PagingLoadResult<GwtDevice>> proxy = new RpcProxy<PagingLoadResult<GwtDevice>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtDevice>> callback) {
            PagingLoadConfig pagingConfig = (BasePagingLoadConfig) loadConfig;
            ((BasePagingLoadConfig) pagingConfig).setLimit(DEVICE_PAGE_SIZE);
            gwtDeviceService.findDevices(pagingConfig, m_currentSession.getSelectedAccount().getId(), m_filterPredicates, callback);
        }
    };
    m_loader = new BasePagingLoader<PagingLoadResult<GwtDevice>>(proxy);
    m_loader.setSortDir(SortDir.ASC);
    m_loader.setSortField("clientId");
    m_loader.setRemoteSort(true);
    SwappableListStore<GwtDevice> store = new SwappableListStore<GwtDevice>(m_loader);
    store.setKeyProvider(new ModelKeyProvider<GwtDevice>() {

        public String getKey(GwtDevice device) {
            return device.getScopeId() + ":" + device.getClientId();
        }
    });
    m_devicesGrid = new Grid<GwtDevice>(store, new ColumnModel(configs));
    m_devicesGrid.setBorders(false);
    m_devicesGrid.setStateful(false);
    m_devicesGrid.setLoadMask(true);
    m_devicesGrid.setStripeRows(true);
    m_devicesGrid.setAutoExpandColumn("displayName");
    m_devicesGrid.getView().setAutoFill(true);
    m_devicesGrid.getView().setEmptyText(MSGS.deviceTableNoDevices());
    m_devicesGrid.disableTextSelection(false);
    m_devicesGrid.addListener(Events.HeaderClick, new Listener<GridEvent<GwtDevice>>() {

        @Override
        public void handleEvent(GridEvent<GwtDevice> be) {
            if (be.getColIndex() == 1) {
                if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name())) {
                    if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
                    } else {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                    }
                } else {
                    m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                }
                m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name());
            } else if (be.getColIndex() == 2) {
                if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name())) {
                    if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
                    } else {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                    }
                } else {
                    m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                }
                m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name());
            } else if (be.getColIndex() == 3) {
                if (m_filterPredicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name())) {
                    if (m_filterPredicates.getSortOrderEnum().equals(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING)) {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.DESCENDING.name());
                    } else {
                        m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                    }
                } else {
                    m_filterPredicates.setSortOrder(GwtDeviceQueryPredicates.GwtSortOrder.ASCENDING.name());
                }
                m_filterPredicates.setSortAttribute(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name());
            } else {
                return;
            }
            refresh(m_filterPredicates);
        }
    });
    m_loader.addLoadListener(new DataLoadListener(m_devicesGrid));
    m_pagingToolBar = new PagingToolBar(DEVICE_PAGE_SIZE);
    m_pagingToolBar.bind(m_loader);
    m_pagingToolBar.enable();
    GridSelectionModel<GwtDevice> selectionModel = new GridSelectionModel<GwtDevice>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_devicesGrid.setSelectionModel(selectionModel);
    m_devicesGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtDevice>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtDevice> se) {
            m_selectedDevice = se.getSelectedItem();
            if (m_selectedDevice != null) {
                m_deleteDeviceButton.setEnabled(true);
                m_devicesView.setDevice(m_selectedDevice);
            } else {
                // m_editDeviceButton.setEnabled(false);
                m_deleteDeviceButton.setEnabled(false);
            }
        }
    });
}
Also used : GridEvent(com.extjs.gxt.ui.client.event.GridEvent) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) SwappableListStore(org.eclipse.kapua.app.console.client.util.SwappableListStore) SwappableListStore(org.eclipse.kapua.app.console.client.util.SwappableListStore) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) PagingToolBar(com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) GridCellRenderer(com.extjs.gxt.ui.client.widget.grid.GridCellRenderer) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) PagingLoadConfig(com.extjs.gxt.ui.client.data.PagingLoadConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig)

Example 5 with BasePagingLoadConfig

use of com.extjs.gxt.ui.client.data.BasePagingLoadConfig in project kapua by eclipse.

the class GwtDeviceServiceImpl method findDevices.

public PagingLoadResult<GwtDevice> findDevices(PagingLoadConfig loadConfig, String scopeIdString, GwtDeviceQueryPredicates predicates) throws GwtKapuaException {
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    DeviceFactory deviceFactory = locator.getFactory(DeviceFactory.class);
    List<GwtDevice> gwtDevices = new ArrayList<GwtDevice>();
    BasePagingLoadResult<GwtDevice> gwtResults;
    int totalResult = 0;
    try {
        BasePagingLoadConfig bplc = (BasePagingLoadConfig) loadConfig;
        DeviceQuery deviceQuery = deviceFactory.newQuery(KapuaEid.parseShortId(scopeIdString));
        deviceQuery.setLimit(bplc.getLimit() + 1);
        deviceQuery.setOffset(bplc.getOffset());
        AndPredicate andPred = new AndPredicate();
        if (predicates.getClientId() != null) {
            andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.CLIENT_ID, predicates.getUnescapedClientId(), Operator.STARTS_WITH));
        }
        if (predicates.getDisplayName() != null) {
            andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.DISPLAY_NAME, predicates.getUnescapedDisplayName(), Operator.STARTS_WITH));
        }
        if (predicates.getSerialNumber() != null) {
            andPred = andPred.and(new AttributePredicate<String>(DevicePredicates.SERIAL_NUMBER, predicates.getUnescapedSerialNumber()));
        }
        if (predicates.getDeviceStatus() != null) {
            andPred = andPred.and(new AttributePredicate<DeviceStatus>(DevicePredicates.STATUS, DeviceStatus.valueOf(predicates.getDeviceStatus())));
        }
        if (predicates.getSortAttribute() != null) {
            SortOrder sortOrder = SortOrder.ASCENDING;
            if (predicates.getSortOrder().equals(SortOrder.DESCENDING.name())) {
                sortOrder = SortOrder.DESCENDING;
            }
            if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.CLIENT_ID.name())) {
                deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.CLIENT_ID, sortOrder));
            } else if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.DISPLAY_NAME.name())) {
                deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.DISPLAY_NAME, sortOrder));
            } else if (predicates.getSortAttribute().equals(GwtDeviceQueryPredicates.GwtSortAttribute.LAST_EVENT_ON.name())) {
                deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.LAST_EVENT_ON, sortOrder));
            }
        } else {
            deviceQuery.setSortCriteria(new FieldSortCriteria(DevicePredicates.CLIENT_ID, SortOrder.ASCENDING));
        }
        deviceQuery.setPredicate(andPred);
        KapuaListResult<Device> devices = deviceRegistryService.query(deviceQuery);
        totalResult = (int) deviceRegistryService.count(deviceQuery);
        DeviceConnectionService deviceConnectionService = locator.getService(DeviceConnectionService.class);
        DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
        DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
        DeviceEventQuery eventQuery = deviceEventFactory.newQuery(deviceQuery.getScopeId());
        eventQuery.setLimit(1);
        eventQuery.setSortCriteria(new FieldSortCriteria(DeviceEventPredicates.RECEIVED_ON, SortOrder.DESCENDING));
        for (Device d : devices.getItems()) {
            DeviceConnection deviceConnection = deviceConnectionService.findByClientId(d.getScopeId(), d.getClientId());
            // Connection info
            GwtDevice gwtDevice = KapuaGwtConverter.convert(d);
            gwtDevice.setConnectionIp(deviceConnection.getClientIp());
            gwtDevice.setGwtDeviceConnectionStatus(deviceConnection.getStatus().name());
            gwtDevice.setLastEventOn(deviceConnection.getModifiedOn());
            // Event infos
            eventQuery.setPredicate(new AttributePredicate<KapuaId>(DeviceEventPredicates.DEVICE_ID, d.getId()));
            KapuaListResult<DeviceEvent> events = deviceEventService.query(eventQuery);
            if (!events.isEmpty()) {
                DeviceEvent lastEvent = events.getItem(0);
                gwtDevice.setLastEventType(lastEvent.getResource());
                gwtDevice.setLastEventOn(lastEvent.getReceivedOn());
            }
            gwtDevices.add(gwtDevice);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    gwtResults = new BasePagingLoadResult<GwtDevice>(gwtDevices);
    gwtResults.setOffset(loadConfig.getOffset());
    gwtResults.setTotalLength(totalResult);
    return gwtResults;
}
Also used : GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) DeviceEvent(org.eclipse.kapua.service.device.registry.event.DeviceEvent) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) ArrayList(java.util.ArrayList) DeviceEventQuery(org.eclipse.kapua.service.device.registry.event.DeviceEventQuery) AttributePredicate(org.eclipse.kapua.commons.model.query.predicate.AttributePredicate) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) FieldSortCriteria(org.eclipse.kapua.commons.model.query.FieldSortCriteria) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceQuery(org.eclipse.kapua.service.device.registry.DeviceQuery) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Device(org.eclipse.kapua.service.device.registry.Device) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) KapuaAndPredicate(org.eclipse.kapua.model.query.predicate.KapuaAndPredicate) AndPredicate(org.eclipse.kapua.commons.model.query.predicate.AndPredicate) SortOrder(org.eclipse.kapua.commons.model.query.FieldSortCriteria.SortOrder) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceFactory(org.eclipse.kapua.service.device.registry.DeviceFactory) DeviceConnection(org.eclipse.kapua.service.device.registry.connection.DeviceConnection) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceConnectionService(org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService)

Aggregations

BasePagingLoadConfig (com.extjs.gxt.ui.client.data.BasePagingLoadConfig)5 ArrayList (java.util.ArrayList)4 PagingLoadResult (com.extjs.gxt.ui.client.data.PagingLoadResult)3 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)3 GwtDeviceEvent (org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent)3 PagingLoadConfig (com.extjs.gxt.ui.client.data.PagingLoadConfig)2 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)2 ListStore (com.extjs.gxt.ui.client.store.ListStore)2 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)2 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)2 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)2 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)2 GridSelectionModel (com.extjs.gxt.ui.client.widget.grid.GridSelectionModel)2 PagingToolBar (com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 FieldSortCriteria (org.eclipse.kapua.commons.model.query.FieldSortCriteria)2 AndPredicate (org.eclipse.kapua.commons.model.query.predicate.AndPredicate)2 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 KapuaAndPredicate (org.eclipse.kapua.model.query.predicate.KapuaAndPredicate)2