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