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;
}
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;
}
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);
}
Aggregations