Search in sources :

Example 1 with SiteDTO

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);
}
Also used : QuickTip(com.extjs.gxt.ui.client.widget.tips.QuickTip) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO)

Example 2 with SiteDTO

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);
    }
}
Also used : Site(org.activityinfo.server.database.hibernate.entity.Site) User(org.activityinfo.server.database.hibernate.entity.User) Query(javax.persistence.Query) Date(java.util.Date) EntityManager(javax.persistence.EntityManager) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteCommand(org.activityinfo.legacy.shared.command.SiteCommand) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 3 with SiteDTO

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);
}
Also used : DimensionType(org.activityinfo.legacy.shared.command.DimensionType) Filter(org.activityinfo.legacy.shared.command.Filter) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) TableData(org.activityinfo.legacy.shared.reports.content.TableData) TableContent(org.activityinfo.legacy.shared.reports.content.TableContent)

Example 4 with SiteDTO

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

Example 5 with SiteDTO

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

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