use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class SiteDialog method saveNewSite.
private void saveNewSite() {
final SiteDTO newSite = new SiteDTO();
keyGenerator = new KeyGenerator();
newSite.setId(keyGenerator.generateInt());
newSite.setActivityId(activity.getId());
if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
}
updateModel(newSite);
dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(CreateResult result) {
hide();
callback.onSaved();
}
});
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteSite.
@Test
public void testDeleteSite() throws CommandException {
PagingResult<SiteDTO> sites = execute(GetSites.byId(3));
execute(new Delete(sites.getData().get(0)));
sites = execute(GetSites.byId(3));
Assert.assertEquals(0, sites.getData().size());
sites = execute(new GetSites());
assertNull(getById(sites.getData(), 3));
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class SiteUpdate method ensureInitialHistoryEntry.
public void ensureInitialHistoryEntry(Site site, User user) {
long count = entityManager.createQuery("select count(h.id) from " + "SiteHistory h where h.site = :site", Long.class).setParameter("site", site).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(site.getId()));
SiteDTO siteDTO = siteResult.getData().get(0);
String completeProperties = JsonUtil.encodeMap(siteDTO.getProperties()).toString();
SiteHistory baseline = new SiteHistory();
baseline.setSite(site);
baseline.setUser(user);
baseline.setJson(completeProperties);
baseline.setTimeCreated(new Date().getTime());
baseline.setInitial(false);
entityManager.persist(baseline);
}
}
use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.
the class BubbleLayerGenerator method generatePoints.
public void generatePoints(List<SiteDTO> sites, TiledMap map, BubbleMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
for (SiteDTO site : sites) {
if (hasValue(site, layer.getIndicatorIds())) {
Point px = null;
AiLatLng geoPoint = getPoint(site);
if (geoPoint != null) {
px = map.fromLatLngToPixel(geoPoint);
}
Double value = getValue(site, layer.getIndicatorIds());
if (value != null && value != 0) {
PointValue pv = new PointValue(site, createSymbol(site, layer.getColorDimensions()), value, px);
if (geoPoint != null || 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 ExcelTableRenderer method render.
@Override
public void render(Workbook book, TableElement element) {
final TableData tableData = element.getContent().getData();
new BaseExcelTableRenderer<TableElement, TableColumn>(book, element) {
@Override
public List<FilterDescription> generateFilterDescriptions() {
return element.getContent().getFilterDescriptions();
}
@Override
public void generate() {
/* Generate the column headers for the table */
initColHeaderStyles(element.getRootColumn());
generateColumnHeaders(0, element.getRootColumn());
int headerHeight = rowIndex;
sheet.createFreezePane(element.getFrozenColumns(), headerHeight);
/* Prepare the generators and indexes */
List<TableColumn> leaves = element.getRootColumn().getLeaves();
String[] colIndexes = new String[leaves.size()];
for (int i = 0; i != leaves.size(); ++i) {
colIndexes[i] = leaves.get(i).getSitePropertyName();
}
for (SiteDTO rowData : tableData.getRows()) {
Row row = sheet.createRow(rowIndex++);
for (int i = 0; i != colIndexes.length; ++i) {
Object value = null;
if (colIndexes[i] != null) {
value = rowData.get(colIndexes[i]);
}
Cell cell = row.createCell(i);
if (value instanceof Number) {
cell.setCellValue(((Number) value).doubleValue());
} else if (value instanceof Date) {
cell.setCellValue((Date) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value != null) {
cell.setCellValue(factory.createRichTextString(value.toString()));
}
}
}
}
};
}
Aggregations