Search in sources :

Example 11 with SiteResult

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

the class CalculatedIndicatorsQuery method querySites.

private void querySites() {
    GetSites sitesQuery = new GetSites(composeSiteFilter());
    sitesQuery.setFetchAdminEntities(query.isPivotedBy(DimensionType.AdminLevel));
    sitesQuery.setFetchAttributes(query.isPivotedBy(DimensionType.AttributeGroup));
    sitesQuery.setFetchAllIndicators(true);
    sitesQuery.setFetchLocation(query.isPivotedBy(DimensionType.Location) || query.isPivotedBy(DimensionType.Site));
    sitesQuery.setFetchPartner(query.isPivotedBy(DimensionType.Partner));
    sitesQuery.setFetchComments(false);
    sitesQuery.setFetchDates(query.isPivotedBy(DimensionType.Date));
    sitesQuery.setFetchLinks(false);
    sitesQuery.setFetchAllReportingPeriods(true);
    sitesQuery.setLimit(-1);
    for (Dimension dim : query.getDimensions()) {
        if (dim.getType() != DimensionType.Indicator) {
            dimAccessors.add(createAccessor(dim));
        }
    }
    queryContext.getExecutionContext().execute(sitesQuery, new AsyncCallback<SiteResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(SiteResult result) {
            try {
                aggregateSites(result);
                callback.onSuccess(null);
            } catch (Throwable caught) {
                callback.onFailure(caught);
            }
        }
    });
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 12 with SiteResult

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

the class ImportWithMultiClassRangeTest method testSimple.

@Test
public void testSimple() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(NFI_DISTRIBUTION_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "nfi.csv"), Charsets.UTF_8));
    source.parseAllRows();
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("Date1"), target("Start Date"));
    importModel.setColumnAction(columnIndex("Date2"), target("End Date"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    importModel.setColumnAction(columnIndex("Localité"), target("Localité Name"));
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
    importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
    importModel.setColumnAction(columnIndex("Groupement"), target("Groupement Name"));
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    importModel.setColumnAction(columnIndex("Nombre de ménages ayant reçu une assistance en NFI"), target("Nombre de ménages ayant reçu une assistance en NFI"));
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    GetSites query = new GetSites(Filter.filter().onActivity(33));
    query.setSortInfo(new SortInfo("date2", Style.SortDir.DESC));
    SiteResult result = execute(query);
    // 651 - 8 = 643 (8 records where start date is before end date)
    assertThat(result.getTotalLength(), equalTo(643));
    // assertThat(result.getTotalLength(), equalTo(313));
    SiteDTO lastSite = result.getData().get(0);
    // assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013,4,26)));
    assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013, 4, 30)));
    assertThat(lastSite.getLocationName(), equalTo("Kilimani Camp"));
    assertThat(lastSite.getAdminEntity(PROVINCE_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(DISTRICT_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(TERRITOIRE_LEVEL).getName(), equalTo("Masisi"));
    assertThat(lastSite.getAdminEntity(SECTEUR_LEVEL).getName(), equalTo("Masisi"));
    assertThat((Double) lastSite.getIndicatorValue(NUMBER_MENAGES), equalTo(348.0));
    assertThat(lastSite.getAttributeValue(ECHO), equalTo(false));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 13 with SiteResult

use of org.activityinfo.legacy.shared.command.result.SiteResult 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 14 with SiteResult

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

the class TableGenerator method generateData.

public TableData generateData(TableElement element, Filter filter) {
    GetSites query = new GetSites(filter);
    if (!element.getSortBy().isEmpty()) {
        TableColumn sortBy = element.getSortBy().get(0);
        query.setSortInfo(new SortInfo(sortBy.getSitePropertyName(), sortBy.isOrderAscending() ? SortDir.ASC : SortDir.DESC));
    }
    SiteResult sites = getDispatcher().execute(query);
    return new TableData(element.getRootColumn(), sites.getData());
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) TableData(org.activityinfo.legacy.shared.reports.content.TableData) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

Example 15 with SiteResult

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

the class GetSitesHandler method execute.

@Override
public SiteResult execute(GetSites cmd, User user) {
    if (useLegacyMethod(cmd, user)) {
        return dispatcher.execute(new OldGetSites(cmd));
    }
    LOGGER.info("Entering execute()");
    aggregateTime.start();
    try {
        initialiseHandler(cmd, user);
        fetchActivityMetadata(cmd.getFilter());
        queryFormTrees();
        constructActivityLinks();
        buildQueries();
        batchQueries();
        executeBatch();
        mergeMonthlyRootSites();
        setSitesLinkedStatus();
        sort();
    } catch (CommandException excp) {
        // old method at any point of execution and elongate the return time
        return dispatcher.execute(new OldGetSites(cmd));
    }
    aggregateTime.stop();
    printTimes();
    SiteResult result = new SiteResult(siteList);
    result.setOffset(cmd.getOffset());
    result.setTotalLength(totalResultLength);
    LOGGER.info("Exiting execute()");
    return result;
}
Also used : OldGetSites(org.activityinfo.legacy.shared.command.OldGetSites) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

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