Search in sources :

Example 11 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO in project activityinfo by bedatadriven.

the class DbTargetEditor method onEdit.

@Override
protected void onEdit(final TargetDTO dto) {
    this.view.showAddDialog(dto, db, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            final Record record = store.getRecord(dto);
            service.execute(new UpdateEntity(dto, getChangedProperties(record)), dlg, new AsyncCallback<VoidResult>() {

                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(VoidResult result) {
                    PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
                    dto.setPartner(partner);
                    ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
                    dto.setProject(project);
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) VoidResult(org.activityinfo.shared.command.result.VoidResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) Record(com.extjs.gxt.ui.client.store.Record)

Example 12 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO in project activityinfo by bedatadriven.

the class DbTargetEditor method onAdd.

@Override
protected void onAdd() {
    final TargetDTO newTarget = new TargetDTO();
    this.view.showAddDialog(newTarget, db, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            service.execute(new AddTarget(db.getId(), newTarget), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    newTarget.setId(result.getNewId());
                    PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
                    newTarget.setPartner(partner);
                    ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
                    newTarget.setProject(project);
                    store.add(newTarget);
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) AddTarget(org.activityinfo.shared.command.AddTarget) TargetDTO(org.activityinfo.shared.dto.TargetDTO)

Example 13 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO in project activityinfo by bedatadriven.

the class GetSitesHandler method toSite.

private SiteDTO toSite(SqlResultSetRow row) {
    SiteDTO model = new SiteDTO();
    model.setId(row.getInt("SiteId"));
    model.setLinked(row.getBoolean("Linked"));
    model.setActivityId(row.getInt("ActivityId"));
    model.setDate1(row.getDate("Date1"));
    model.setDate2(row.getDate("Date2"));
    model.setDateCreated(row.getDate("DateCreated"));
    model.setTimeEdited(row.getDouble("TimeEdited"));
    model.setLocationId(row.getInt("LocationId"));
    model.setLocationName(row.getString("LocationName"));
    model.setLocationAxe(row.getString("LocationAxe"));
    if (!row.isNull("x") && !row.isNull("y")) {
        model.setX(row.getDouble("x"));
        model.setY(row.getDouble("y"));
    }
    model.setComments(row.getString("Comments"));
    PartnerDTO partner = new PartnerDTO();
    partner.setId(row.getInt("PartnerId"));
    partner.setName(row.getString("PartnerName"));
    if (!row.isNull("ProjectId") && row.isNull("ProjectDateDeleted")) {
        ProjectDTO project = new ProjectDTO();
        project.setId(row.getInt("ProjectId"));
        project.setName(row.getString("ProjectName"));
        model.setProject(project);
    }
    model.setPartner(partner);
    return model;
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO)

Example 14 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO in project activityinfo by bedatadriven.

the class CreateSiteTest method testAdminBoundCreate.

@Test
@Ignore("WIP")
public void testAdminBoundCreate() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = new SiteDTO();
    newSite.setActivityId(4);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setAdminEntity(1, new AdminEntityDTO(1, 2, "Sud Kivu"));
    newSite.setAdminEntity(2, new AdminEntityDTO(2, 11, "Walungu"));
    newSite.setAdminEntity(3, null);
    newSite.setX(27.432);
    newSite.setY(1.23);
    newSite.setComments("huba huba");
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    setUser(1);
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    CreateResult result = execute(cmd);
    newSite.setId(result.getNewId());
    // try to retrieve what we've created
    PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
    Assert.assertEquals(1, loadResult.getData().size());
    SiteDTO secondRead = loadResult.getData().get(0);
    // confirm that the changes are there
    Assert.assertEquals("site.location.name", "Walungu", secondRead.getLocationName());
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.shared.dto.SiteDTO) CreateSite(org.activityinfo.shared.command.CreateSite) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO in project activityinfo by bedatadriven.

the class ProjectTest method updateProject.

@Test
public void updateProject() {
    setUser(1);
    SchemaDTO schema = execute(new GetSchema());
    ProjectDTO project = schema.getProjectById(2);
    project.setName("RRMP II");
    project.setDescription("RRMP The Next Generation");
    execute(RequestChange.update(project, "name", "description"));
    schema = execute(new GetSchema());
    assertThat(schema.getProjectById(2).getName(), equalTo("RRMP II"));
    assertThat(schema.getProjectById(2).getDescription(), equalTo("RRMP The Next Generation"));
    project.setName("RRMP III");
    project.setDescription(null);
    execute(RequestChange.update(project, "name", "description"));
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)16 CreateResult (org.activityinfo.shared.command.result.CreateResult)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)5 SiteDTO (org.activityinfo.shared.dto.SiteDTO)4 Test (org.junit.Test)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)3 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)3 LockedPeriodDTO (org.activityinfo.shared.dto.LockedPeriodDTO)3 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 AddProject (org.activityinfo.shared.command.AddProject)2 CreateSite (org.activityinfo.shared.command.CreateSite)2 GetSchema (org.activityinfo.shared.command.GetSchema)2 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)2 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)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