Search in sources :

Example 6 with ProjectDTO

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

the class AddProjectHandler method execute.

@Override
public CommandResult execute(AddProject cmd, User user) throws CommandException {
    UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
    ProjectDTO from = cmd.getProjectDTO();
    Project project = new Project();
    project.setName(from.getName());
    project.setDescription(from.getDescription());
    project.setUserDatabase(db);
    db.setLastSchemaUpdate(new Date());
    em.persist(project);
    em.persist(db);
    db.getProjects().add(project);
    return new CreateResult(project.getId());
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) Project(org.activityinfo.server.database.hibernate.entity.Project) AddProject(org.activityinfo.shared.command.AddProject) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Date(java.util.Date)

Example 7 with ProjectDTO

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

the class GetLockedPeriodsHandler method execute.

@Override
public void execute(GetLockedPeriods command, ExecutionContext context, final AsyncCallback<LockedPeriodsResult> callback) {
    final List<Integer> projectIds = Lists.newArrayList();
    final List<Integer> activityIds = Lists.newArrayList();
    final List<LockedPeriodDTO> lockedPeriods = Lists.newArrayList();
    SqlQuery.select("ProjectId").from("project").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {

        @Override
        public void handleRow(SqlResultSetRow row) {
            projectIds.add(row.getInt("ProjectId"));
        }
    });
    SqlQuery.select("ActivityId").from("activity").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {

        @Override
        public void handleRow(SqlResultSetRow row) {
            activityIds.add(row.getInt("ActivityId"));
        }
    });
    // TODO(ruud): load only what is visible to user
    SqlQuery.select("fromDate", "toDate", "enabled", "name", "lockedPeriodId", "userDatabaseId", "activityId", "projectId").from("lockedperiod").where("ActivityId").in(activityIds).or().where("ProjectId").in(projectIds).or().where("UserDatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            UserDatabaseDTO db = new UserDatabaseDTO();
            ActivityDTO activity = new ActivityDTO();
            ProjectDTO project = new ProjectDTO();
            for (SqlResultSetRow row : results.getRows()) {
                LockedPeriodDTO lockedPeriod = new LockedPeriodDTO();
                lockedPeriod.setFromDate(row.getDate("fromDate"));
                lockedPeriod.setToDate(row.getDate("toDate"));
                lockedPeriod.setEnabled(row.getBoolean("enabled"));
                lockedPeriod.setName(row.getString("name"));
                lockedPeriod.setId(row.getInt("lockedPeriodId"));
                boolean parentFound = false;
                if (!row.isNull("activityId")) {
                    Integer activityId = row.getInt("activityId");
                    lockedPeriod.setParentId(activityId);
                    lockedPeriod.setParentType(activity.getEntityName());
                    parentFound = true;
                }
                if (!row.isNull("userDatabaseId")) {
                    Integer databaseId = row.getInt("userDatabaseId");
                    lockedPeriod.setParentId(databaseId);
                    lockedPeriod.setParentType(db.getEntityName());
                    parentFound = true;
                }
                if (!row.isNull("projectID")) {
                    Integer projectId = row.getInt("projectId");
                    lockedPeriod.setParentId(projectId);
                    lockedPeriod.setParentType(project.getEntityName());
                    parentFound = true;
                }
                if (!parentFound) {
                    Log.debug("Orphan lockedPeriod: No parent (UserDatabase/Activity/Project) found for LockedPeriod with Id=" + lockedPeriod.getId());
                }
                lockedPeriods.add(lockedPeriod);
            }
            callback.onSuccess(new LockedPeriodsResult(lockedPeriods));
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO) RowHandler(com.bedatadriven.rebar.sql.client.util.RowHandler) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) LockedPeriodsResult(org.activityinfo.shared.command.GetLockedPeriods.LockedPeriodsResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback)

Example 8 with ProjectDTO

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

the class CreateSiteTest method testAllAttribsFalse.

@Test
public void testAllAttribsFalse() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(1);
    newSite.setLocationId(1);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setLocationName("Virunga");
    newSite.setAttributeValue(1, false);
    newSite.setAttributeValue(2, false);
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
    // execute the command
    setUser(1);
    CreateResult result = execute(cmd);
    // let the client know the command has succeeded
    newSite.setId(result.getNewId());
    // cmd.onCompleted(result);
    // 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.attribute[2]", false, secondRead.getAttributeValue(1));
    Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite) Test(org.junit.Test)

Example 9 with ProjectDTO

use of org.activityinfo.shared.dto.ProjectDTO 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.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator)

Example 10 with ProjectDTO

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

the class DbProjectEditor method onAdd.

@Override
protected void onAdd() {
    final ProjectDTO newProject = new ProjectDTO();
    this.view.showAddDialog(newProject, new FormDialogCallback() {

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

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

                @Override
                public void onSuccess(CreateResult result) {
                    newProject.setId(result.getNewId());
                    store.add(newProject);
                    db.getProjects().add(newProject);
                    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) AddProject(org.activityinfo.shared.command.AddProject) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) DuplicatePartnerException(org.activityinfo.shared.exception.DuplicatePartnerException) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether)

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