Search in sources :

Example 26 with SiteDTO

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();
        }
    });
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) CreateSite(org.activityinfo.legacy.shared.command.CreateSite)

Example 27 with SiteDTO

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));
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 28 with SiteDTO

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);
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Date(java.util.Date)

Example 29 with SiteDTO

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);
                }
            }
        }
    }
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO)

Example 30 with SiteDTO

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()));
                    }
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) Date(java.util.Date) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Row(org.apache.poi.ss.usermodel.Row) TableData(org.activityinfo.legacy.shared.reports.content.TableData) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)48 Test (org.junit.Test)31 GetSites (org.activityinfo.legacy.shared.command.GetSites)16 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)12 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)9 OnDataSet (org.activityinfo.server.database.OnDataSet)8 Date (java.util.Date)6 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)6 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)5 ArrayList (java.util.ArrayList)4 UpdateSite (org.activityinfo.legacy.shared.command.UpdateSite)4 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)3 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)3 TableData (org.activityinfo.legacy.shared.reports.content.TableData)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 Filter (org.activityinfo.legacy.shared.command.Filter)2 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)2