Search in sources :

Example 1 with GwtDeviceEvent

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

the class KapuaGwtConverter method convert.

public static GwtDeviceEvent convert(DeviceEvent deviceEvent) {
    GwtDeviceEvent gwtDeviceEvent = new GwtDeviceEvent();
    gwtDeviceEvent.setDeviceId(deviceEvent.getDeviceId().getShortId());
    gwtDeviceEvent.setSentOn(deviceEvent.getSentOn());
    gwtDeviceEvent.setReceivedOn(deviceEvent.getReceivedOn());
    gwtDeviceEvent.setEventType(deviceEvent.getResource());
    String escapedMessage = KapuaSafeHtmlUtils.htmlEscape(deviceEvent.getEventMessage());
    gwtDeviceEvent.setEventMessage(escapedMessage);
    return gwtDeviceEvent;
}
Also used : GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent)

Example 2 with GwtDeviceEvent

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

use of org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent 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)

Aggregations

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