use of com.bedatadriven.rebar.time.calendar.LocalDate 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 com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class LockedPeriodTest method createForFolder.
@Test
public void createForFolder() {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("NFI ");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setFolderId(1);
execute(create);
// Now verify that they appear
SchemaDTO schema = execute(new GetSchema());
assertThat(schema.getDatabaseById(1).getFolderById(1).getLockedPeriods(), Matchers.hasSize(1));
LockedPeriodSet locks = new LockedPeriodSet(schema);
assertTrue(locks.isActivityLocked(1, new LocalDate(2011, 1, 1)));
// Verify that the new code works too...
DatabaseProviderImpl provider = new DatabaseProviderImpl(Providers.of(em));
UserDatabaseMeta metadata = provider.getDatabaseMetadata(CuidAdapter.databaseId(1), 1);
ArrayList<RecordLock> folderLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.folderId(1)));
ArrayList<RecordLock> formLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.activityFormClass(1)));
assertThat(folderLocks, Matchers.hasSize(2));
assertThat(formLocks, Matchers.hasSize(3));
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class LockedPeriodTest method createTest.
@Test
public void createTest() throws CommandException {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("my name");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setDatabaseId(1);
CreateResult result = execute(create);
Map<String, Object> changes = Maps.newHashMap();
changes.put("toDate", new LocalDate(2011, 2, 28));
execute(new UpdateEntity("LockedPeriod", result.getNewId(), changes));
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class GeoDigestModelBuilderTest method testEmptyDigestsAreNotSent.
@Test
public void testEmptyDigestsAreNotSent() throws Exception {
// only notification
User user = em.find(User.class, 1);
LocalDate today = new LocalDate(2041, 1, 1);
UserDigest userDigest = new UserDigest(user, today.atMidnightInMyTimezone(), 1, "testToken");
GeoDigestModel model = geoDigestModelBuilder.createModel(userDigest);
assertThat(model.hasData(), equalTo(false));
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class OldGetSitesHandler method primaryQuery.
private SqlQuery primaryQuery(ExecutionContext context, GetSites command) {
SqlQuery query = SqlQuery.select().appendColumn("site.SiteId").appendColumn("(0)", "Linked").appendColumn("activity.ActivityId").appendColumn("activity.name", "ActivityName").appendColumn("db.DatabaseId", "DatabaseId").appendColumn("site.DateCreated", "DateCreated").appendColumn("site.projectId", "ProjectId").appendColumn("project.name", "ProjectName").appendColumn("project.dateDeleted", "ProjectDateDeleted").appendColumn("site.comments", "Comments").appendColumn("site.DateEdited").appendColumn("site.timeEdited", "TimeEdited");
if (command.isFetchAllReportingPeriods()) {
query.appendColumn("period.Date1", "Date1").appendColumn("period.Date2", "Date2").appendColumn("period.ReportingPeriodId", "PeriodId");
query.from(Tables.REPORTING_PERIOD, "period").leftJoin(Tables.SITE, "site").on("site.SiteId=period.SiteId");
LocalDate filterMinDate = command.getFilter().getEndDateRange().getMinLocalDate();
LocalDate filterMaxDate = command.getFilter().getEndDateRange().getMaxLocalDate();
if (filterMinDate != null) {
query.where("period.Date1").greaterThanOrEqualTo(filterMinDate);
}
if (filterMaxDate != null) {
query.where("period.Date2").lessThanOrEqualTo(filterMaxDate);
}
} else {
query.from(Tables.SITE);
query.appendColumn("site.Date1", "Date1").appendColumn("site.Date2", "Date2");
}
query.whereTrue("site.dateDeleted is null").leftJoin(Tables.ACTIVITY).on("site.ActivityId = activity.ActivityId").leftJoin(Tables.USER_DATABASE, "db").on("activity.DatabaseId = db.DatabaseId").leftJoin(Tables.PARTNER).on("site.PartnerId = partner.PartnerId").leftJoin(Tables.PROJECT).on("site.ProjectId = project.ProjectId");
if (command.isFetchPartner()) {
query.appendColumn("partner.PartnerId", "PartnerId").appendColumn("partner.name", "PartnerName");
}
if (command.isFetchLocation()) {
query.appendColumn("location.locationId", "LocationId").appendColumn("location.name", "LocationName").appendColumn("location.axe", "LocationAxe").appendColumn("locationType.name", "LocationTypeName").appendColumn("location.x", "x").appendColumn("location.y", "y").appendColumn("location.workflowStatusId", "workflowStatusId");
}
if (locationJoinRequired(command)) {
query.leftJoin(Tables.LOCATION).on("site.LocationId = location.LocationId").leftJoin(Tables.LOCATION_TYPE, "locationType").on("location.LocationTypeId = locationType.LocationTypeId");
}
applyPermissions(query, context);
applyFilter(query, command);
Optional<Integer> adminLevelId = adminLevelId(command.getSortInfo().getSortField());
if (command.isFetchAdminEntities() && adminLevelId.isPresent()) {
query.appendColumn("derived.name", "adminName");
query.leftJoin(locationToAdminTable(adminLevelId.get()), "derived").on("derived.locationId = location.LocationId");
}
if (command.getFilter().isRestricted(DimensionType.Indicator)) {
applyPrimaryIndicatorFilter(query, command.getFilter());
}
System.out.println(query.sql());
return query;
}
Aggregations