Search in sources :

Example 11 with LocalDate

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()));
}
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 12 with LocalDate

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));
}
Also used : DatabaseProviderImpl(org.activityinfo.server.endpoint.rest.DatabaseProviderImpl) RecordLock(org.activityinfo.model.database.RecordLock) LockedPeriodSet(org.activityinfo.legacy.shared.model.LockedPeriodSet) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 13 with LocalDate

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));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) Test(org.junit.Test)

Example 14 with LocalDate

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));
}
Also used : UserDigest(org.activityinfo.server.digest.UserDigest) User(org.activityinfo.server.database.hibernate.entity.User) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Test(org.junit.Test)

Example 15 with LocalDate

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;
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Aggregations

LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)19 Test (org.junit.Test)9 Date (java.util.Date)6 HashMap (java.util.HashMap)3 LockedPeriodDTO (org.activityinfo.legacy.shared.model.LockedPeriodDTO)3 SqlInsert (com.bedatadriven.rebar.sql.client.query.SqlInsert)2 JsonObject (com.google.gson.JsonObject)2 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)2 GetSites (org.activityinfo.legacy.shared.command.GetSites)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 FormTree (org.activityinfo.model.formTree.FormTree)2 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)2 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 Converter (com.extjs.gxt.ui.client.binding.Converter)1 FieldBinding (com.extjs.gxt.ui.client.binding.FieldBinding)1