use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class FlatSiteGridPanel method initGrid.
public void initGrid(Filter filter, ColumnModel columnModel) {
PagingLoader<PagingLoadResult<SiteDTO>> loader = new BasePagingLoader<PagingLoadResult<SiteDTO>>(new SiteProxy());
loader.addLoadListener(new LoadListener() {
@Override
public void loaderLoadException(LoadEvent le) {
Log.debug("Exception thrown during load of FlatSiteGrid: ", le.exception);
}
});
loader.setRemoteSort(true);
loader.setSortField("date2");
loader.setSortDir(SortDir.DESC);
pagingToolBar.bind(loader);
listStore = new ListStore<>(loader);
if (editorGrid == null) {
editorGrid = new EditorGrid<SiteDTO>(listStore, columnModel);
editorGrid.setLoadMask(true);
// editorGrid.setStateful(true);
editorGrid.setClicksToEdit(ClicksToEdit.TWO);
editorGrid.setStripeRows(true);
final GridSelectionModel<SiteDTO> sm = new GridSelectionModel<SiteDTO>();
sm.setSelectionMode(SelectionMode.SINGLE);
sm.addSelectionChangedListener(new SelectionChangedListener<SiteDTO>() {
@Override
public void selectionChanged(SelectionChangedEvent<SiteDTO> se) {
fireEvent(Events.SelectionChange, se);
}
});
editorGrid.setSelectionModel(sm);
new QuickTip(editorGrid);
editorGrid.addListener(Events.RowDoubleClick, new Listener<GridEvent>() {
@Override
public void handleEvent(GridEvent be) {
SiteDTO site = listStore.getAt(be.getRowIndex());
SelectionChangedEvent<SiteDTO> event = new SelectionChangedEvent<>(sm, site);
fireEvent(Events.RowDoubleClick, event);
}
});
add(editorGrid, new BorderLayoutData(Style.LayoutRegion.CENTER));
layout();
} else {
editorGrid.reconfigure(listStore, columnModel);
}
this.currentFilter = filter;
loader.load();
new QuickTip(editorGrid);
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class SiteHistoryProcessor method process.
@Timed(name = "updates.site_history")
public void process(Command<?> cmd, final int userId, final int siteId) {
assert (cmd instanceof SiteCommand);
LOGGER.fine("persisting site history (site: " + siteId + ", user: " + userId + ")");
EntityManager em = entityManager.get();
// It's important to use getOnlyReference() here rather
// than find() becuase the site might not actually have
// been sent to the database at this point
Site site = em.getReference(Site.class, siteId);
User user = em.getReference(User.class, userId);
ChangeType type = ChangeType.getType(cmd);
if (!type.isNew()) {
Query q = em.createQuery("select count(*) from SiteHistory where site = :site");
q.setParameter("site", site);
Long count = (Long) q.getSingleResult();
if (count == 0) {
// update, but first entry -> repair history by adding baseline
// record with complete site json
LOGGER.fine("site is not new, but history was empty. Adding baseline record..");
SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
SiteDTO siteDTO = siteResult.getData().get(0);
String fulljson = JsonUtil.encodeMap(siteDTO.getProperties()).toString();
SiteHistory baseline = new SiteHistory();
baseline.setSite(site);
baseline.setUser(user);
baseline.setJson(fulljson);
baseline.setTimeCreated(new Date().getTime());
baseline.setInitial(false);
persist(baseline);
}
}
String json = null;
if (type.isNewOrUpdate()) {
Map<String, Object> changeMap = ((SiteCommand) cmd).getProperties().getTransientMap();
if (!changeMap.isEmpty()) {
json = JsonUtil.encodeMap(changeMap).toString();
}
} else if (type.isDelete()) {
json = JSON_DELETE;
}
if (!Strings.isNullOrEmpty(json)) {
persistHistory(site, user, type, json);
}
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class TableGenerator method generate.
@Override
public void generate(User user, TableElement element, Filter inheritedFilter, DateRange dateRange) {
Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
TableContent content = new TableContent();
content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
TableData data = generateData(element, effectiveFilter);
content.setData(data);
if (element.getMap() != null) {
mapGenerator.generate(user, element.getMap(), effectiveFilter, dateRange);
Map<Integer, String> siteLabels = element.getMap().getContent().siteLabelMap();
for (SiteDTO row : data.getRows()) {
row.set("map", siteLabels.get(row.getId()));
}
}
element.setContent(content);
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class PiechartLayerGenerator method generatePoints.
public void generatePoints(TiledMap map, PiechartMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
for (SiteDTO site : sites) {
if (hasValue(site, layer.getIndicatorIds())) {
Point px = null;
if (site.hasLatLong()) {
px = map.fromLatLngToPixel(new AiLatLng(site.getLatitude(), site.getLongitude()));
}
Double value = getValue(site, layer.getIndicatorIds());
if (value != null && value != 0) {
PointValue pv = new PointValue(site, new MapSymbol(), value, px);
calulateSlices(pv, site);
if (clusterer.isMapped(site)) {
mapped.add(pv);
} else {
unmapped.add(pv);
}
}
}
}
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteIndicator.
@Test
public void testDeleteIndicator() throws CommandException {
int activityId = 1;
int indicatorId = 1;
execute(new Delete("Indicator", indicatorId));
ActivityFormDTO form = execute(new GetActivityForm(activityId));
assertNull(form.getIndicatorById(indicatorId));
PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
assertNull(sites.getData().get(0).getIndicatorValue(1));
}
Aggregations