Search in sources :

Example 6 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class ItextTableRenderer method renderTable.

private void renderTable(Document document, TableData data) throws DocumentException {
    int colDepth = data.getRootColumn().getDepth();
    List<TableColumn> colLeaves = data.getRootColumn().getLeaves();
    int colBreadth = colLeaves.size();
    Table table = new Table(colBreadth, 1);
    table.setUseVariableBorders(true);
    table.setWidth(100.0f);
    table.setBorderWidth(0);
    for (int depth = 1; depth <= colDepth; ++depth) {
        List<TableColumn> columns = data.getRootColumn().getDescendantsAtDepth(depth);
        for (TableColumn column : columns) {
            Cell cell = ThemeHelper.columnHeaderCell(column.getLabel(), column.isLeaf(), computeHAlign(column));
            cell.setColspan(Math.max(1, column.getChildren().size()));
            cell.setRowspan(colDepth - depth - column.getDepth() + 1);
            table.addCell(cell);
        }
    }
    table.endHeaders();
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
    NumberFormat numberFormat = NumberFormat.getIntegerInstance();
    numberFormat.setGroupingUsed(true);
    for (SiteDTO row : data.getRows()) {
        for (TableColumn column : colLeaves) {
            Object value = row.get(column.getSitePropertyName());
            String label = "";
            if (value instanceof Date) {
                label = dateFormat.format(value);
            } else if (value instanceof Number) {
                label = numberFormat.format(value);
            } else if (value != null) {
                label = value.toString();
            }
            table.addCell(ThemeHelper.bodyCell(label, false, 0, true, computeHAlign(column)));
        }
    }
    document.add(table);
}
Also used : DateFormat(java.text.DateFormat) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

Example 7 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class ActivityFormClassBuilderTest method nullLocationTypeIsNotVisible.

@Test
@OnDataSet("/dbunit/chad-form.db.xml")
public void nullLocationTypeIsNotVisible() {
    setUser(9944);
    int databaseId = 1470;
    FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(11218)));
    ResourceId locationFieldId = CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD);
    assertThat(formClass.getFields(), not(hasItem(withId(locationFieldId))));
    // Make sure we can update if location is not specified
    FormInstance instance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClass.getId()), formClass.getId());
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
    instance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1734));
    instance.set(ResourceId.valueOf("Q0000031845"), new EnumValue(CuidAdapter.attributeField(166617)));
    assertResolves(locator.persist(instance));
    // Make sure the null location object is visible to legacy code
    SiteDTO site = execute(GetSites.byId(CuidAdapter.getLegacyIdFromCuid(instance.getId()))).getData().get(0);
    assertThat(site.getLocationName(), equalTo("Chad"));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 8 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class ImportSimpleTest method test.

@Test
public void test() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(HOUSEHOLD_SURVEY_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    source.parseAllRows();
    assertThat(source.getRows().size(), equalTo(63));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    dumpList("COLUMNS", source.getColumns());
    // Step 2: User maps imported columns to FormFields
    dumpList("FIELDS", importer.getImportTargets());
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultMale"));
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultFemale"));
    importModel.setColumnAction(columnIndex("_CREATION_DATE"), target("Start Date"));
    importModel.setColumnAction(columnIndex("_SUBMISSION_DATE"), target("End Date"));
    importModel.setColumnAction(columnIndex("district name"), target("District Name"));
    importModel.setColumnAction(columnIndex("upazila"), target("Upzilla Name"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    // Step 3: Validate for user
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    // VERIFY total count
    SiteResult allResults = execute(new GetSites(Filter.filter().onActivity(1)));
    assertThat(allResults.getData().size(), equalTo(63));
    // AND... verify
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.AdminLevel, MODHUPUR);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getTotalLength(), equalTo(1));
    SiteDTO site = sites.getData().get(0);
    assertThat(site.getDate1(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getDate2(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getAdminEntity(3), not(nullValue()));
}
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) Filter(org.activityinfo.legacy.shared.command.Filter) 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) Test(org.junit.Test)

Example 9 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class SiteDTOs method validateNewSite.

public static void validateNewSite(SiteDTO secondRead) {
    SiteDTO newSite = newSite();
    Assert.assertEquals("site.location.name", LocationDTOs.newLocation().getName(), secondRead.getLocationName());
    Assert.assertEquals("site.location.axe", LocationDTOs.newLocation().getAxe(), secondRead.getLocationAxe());
    Assert.assertEquals("site.attribute[1]", true, secondRead.getAttributeValue(1));
    Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 996.0, (Double) secondRead.getIndicatorValue(1), 0.1);
    Assert.assertEquals("site.comments", newSite.getComments(), secondRead.getComments());
    Assert.assertEquals("site.partner", newSite.getPartner().getId(), secondRead.getPartner().getId());
}
Also used : SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO)

Example 10 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class SiteDTOs method newSite.

public static SiteDTO newSite() {
    SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(1);
    newSite.setLocationId(1);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setReportingPeriodId(new KeyGenerator().generateInt());
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setIndicatorValue(1, 996.0);
    newSite.setIndicatorValue(2, null);
    newSite.setAttributeValue(1, true);
    newSite.setAttributeValue(2, false);
    newSite.setComments("huba huba");
    newSite.setProject(new ProjectDTO(1, "WoeiProject"));
    return newSite;
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator)

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