use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class DbTargetEditor method onAdd.
@Override
protected void onAdd() {
final TargetDTO newTarget = new TargetDTO();
this.view.showAddDialog(newTarget, db, false, 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());
if (newTarget.get("partnerId") != null) {
PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
newTarget.setPartner(partner);
}
if (newTarget.get("projectId") != null) {
ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
newTarget.setProject(project);
}
store.add(newTarget);
store.commitChanges();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
dlg.hide();
}
});
}
});
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateSiteHandlerAsync method createNewSite.
private void createNewSite(CreateSite cmd, ExecutionContext context, AsyncCallback<CreateResult> callback) {
insertSite(context.getTransaction(), cmd);
// we only create a reporting period if this is a one-off activity
Integer reportingPeriodId = cmd.getReportingPeriodId();
if (reportingPeriodId != null) {
insertReportingPeriod(context.getTransaction(), cmd);
}
callback.onSuccess(new CreateResult(cmd.getSiteId()));
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class AddProjectHandler method execute.
@Override
public CommandResult execute(AddProject cmd, User user) {
Database db = em.find(Database.class, cmd.getDatabaseId());
ProjectDTO from = cmd.getProjectDTO();
Project project = new Project();
project.setName(from.getName());
project.setDescription(from.getDescription());
project.setDatabase(db);
db.setLastSchemaUpdate(new Date());
em.persist(project);
em.persist(db);
db.getProjects().add(project);
return new CreateResult(project.getId());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class AddTargetHandler method execute.
@Override
public CommandResult execute(AddTarget cmd, User user) {
TargetDTO form = cmd.getTarget();
Database db = em.find(Database.class, cmd.getDatabaseId());
permissionOracle.assertDesignPrivileges(db, user);
Partner partner = null;
if (form.get("partnerId") != null) {
partner = em.find(Partner.class, form.get("partnerId"));
} else if (form.getPartner() != null) {
partner = em.find(Partner.class, form.getPartner().getId());
}
Project project = null;
if (form.get("projectId") != null) {
project = em.find(Project.class, form.get("projectId"));
} else if (form.getProject() != null) {
project = em.find(Project.class, form.getProject().getId());
}
Target target = new Target();
target.setName(form.getName());
target.setDatabase(db);
target.setPartner(partner);
target.setProject(project);
target.setDate1(form.getFromDate().atMidnightInMyTimezone());
target.setDate2(form.getToDate().atMidnightInMyTimezone());
db.setLastSchemaUpdate(new Date());
em.persist(target);
em.persist(db);
db.getTargets().add(target);
if (project != null) {
project.getTargets().add(target);
}
if (partner != null) {
partner.getTargets().add(target);
}
return new CreateResult(target.getId());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateEntityHandler method createAttribute.
private CommandResult createAttribute(Map<String, Object> properties) {
Attribute attribute = new Attribute();
attribute.setId(generator.generateInt());
AttributeGroup ag = entityManager().getReference(AttributeGroup.class, properties.get("attributeGroupId"));
attribute.setGroup(ag);
updateAttributeProperties(properties, attribute);
if (attribute.getSortOrder() == 0) {
attribute.setSortOrder(queryNextAttributeOrdinal(ag));
}
// Assume group has only one activity
Activity activity = ag.getActivities().iterator().next();
entityManager().persist(attribute);
activity.incrementSchemaVersion();
activity.getDatabase().setLastSchemaUpdate(new Date());
return new CreateResult(attribute.getId());
}
Aggregations