Search in sources :

Example 16 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.

the class SiteExporter method createDataRows.

private void createDataRows(ActivityFormDTO activity, Filter filter, Sheet sheet) {
    int rowIndex = 2;
    // query in batches in order to avoid sinking MySQL
    int offset = 0;
    while (true) {
        LOGGER.log(Level.INFO, "Fetching batching at offset " + offset);
        SiteResult batch = querySites(activity, filter, offset);
        if (batch.getData().isEmpty()) {
            // break if no data
            break;
        }
        for (SiteDTO site : batch.getData()) {
            addDataRow(sheet, rowIndex++, site);
        }
        offset += SITE_BATCH_SIZE;
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult)

Example 17 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.

the class GeoDigestRenderer method renderSites.

private void renderSites(StringBuilder html, DatabaseModel databaseModel, Collection<Integer> siteIds) {
    if (!siteIds.isEmpty()) {
        for (Integer siteId : siteIds) {
            SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
            SiteDTO siteDTO = siteResult.getData().get(0);
            ActivityDTO activityDTO = databaseModel.getModel().getSchemaDTO().getActivityById(siteDTO.getActivityId());
            // Check to see if this activity is visible to the user...
            if (activityDTO != null) {
                List<SiteHistory> histories = findSiteHistory(siteId, databaseModel.getModel().getUserDigest().getFrom());
                for (SiteHistory history : histories) {
                    html.append("<span class='geo-site' style='margin-left:10px;'>&bull; ");
                    html.append(I18N.MESSAGES.geoDigestSiteMsg(history.getUser().getEmail(), history.getUser().getName(), activityDTO.getName(), siteDTO.getLocationName()));
                    Date targetDate = databaseModel.getModel().getUserDigest().getDate();
                    Date creationDate = new Date(history.getTimeCreated());
                    if (DateCalc.isOnToday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateToday(creationDate));
                    } else if (DateCalc.isOnYesterday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateYesterday(creationDate));
                    } else {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateOther(creationDate));
                    }
                    html.append("</span><br>");
                }
            }
        }
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 18 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.

the class UpdateSiteTest method testUpdatePreservesAdminMemberships.

@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("comments", "new comments");
    execute(new UpdateSite(1, changes));
    // retrieve the old one
    SiteResult result = execute(GetSites.byId(1));
    SiteDTO secondRead = result.getData().get(0);
    assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
    assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) Test(org.junit.Test)

Example 19 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.

the class TableGeneratorTest method createDispatcher.

private DispatcherSync createDispatcher() {
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    replay(dispatcher);
    return dispatcher;
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) DispatcherSync(org.activityinfo.server.command.DispatcherSync)

Example 20 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.

the class TableGeneratorTest method testMap.

// 
// @Test
// public void tableWithMap() {
// 
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
// 
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
// 
// TableElement table = new TableElement();
// table.setMap(map);
// 
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
// 
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
// 
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
// 
// Assert.assertNotNull("content is set", table.getContent());
// 
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
// 
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
    TableElement table = new TableElement();
    table.addColumn(new TableColumn("Index", "map"));
    table.addColumn(new TableColumn("Site", "location.name"));
    MapReportElement map = new MapReportElement();
    map.setBaseMapId("map1");
    CircledMapLayer layer = new BubbleMapLayer();
    layer.setLabelSequence(new ArabicNumberSequence());
    map.addLayer(layer);
    table.setMap(map);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    TileBaseMap baseMap1 = new TileBaseMap();
    baseMap1.setId("map1");
    baseMap1.setMinZoom(0);
    baseMap1.setMaxZoom(12);
    baseMap1.setCopyright("(C)");
    baseMap1.setName("Grand Canyon");
    baseMap1.setTileUrlPattern("http://s/test.png");
    expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
    replay(dispatcher);
    TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
    gtor.generate(user, table, null, null);
    MapContent mapContent = map.getContent();
    Assert.assertNotNull("map content", mapContent);
    Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
    Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
    Map<Integer, String> siteLabels = mapContent.siteLabelMap();
    Assert.assertEquals("site id in map", "1", siteLabels.get(1));
    SiteDTO row = table.getContent().getData().getRows().get(0);
    Assert.assertEquals("label on row", "1", row.get("map"));
}
Also used : ArabicNumberSequence(org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) CircledMapLayer(org.activityinfo.legacy.shared.reports.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Aggregations

SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)24 Test (org.junit.Test)14 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)12 GetSites (org.activityinfo.legacy.shared.command.GetSites)9 OnDataSet (org.activityinfo.server.database.OnDataSet)6 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)5 Date (java.util.Date)4 Filter (org.activityinfo.legacy.shared.command.Filter)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)2 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)2 FormTree (org.activityinfo.model.formTree.FormTree)2 SiteHistory (org.activityinfo.server.database.hibernate.entity.SiteHistory)2 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1