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);
}
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"));
}
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()));
}
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());
}
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;
}
Aggregations