use of org.activityinfo.legacy.shared.command.AddTarget 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.AddTarget 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.AddTarget in project activityinfo by bedatadriven.
the class CommandValidatorTest method nameTooLong.
@Test
public void nameTooLong() {
TargetDTO target = new TargetDTO();
target.setName(Strings.repeat("xoxoxo", 2000));
AddTarget command = new AddTarget();
command.setTarget(target);
assertThat(validator.validate(command), hasItems(forProperty("target.name")));
}
use of org.activityinfo.legacy.shared.command.AddTarget in project activityinfo by bedatadriven.
the class CommandValidatorTest method missingRootProperty.
@Test
public void missingRootProperty() {
AddTarget command = new AddTarget();
assertThat(validator.validate(command), hasItems(forProperty("databaseId"), forProperty("target")));
}
use of org.activityinfo.legacy.shared.command.AddTarget in project activityinfo by bedatadriven.
the class CommandValidatorTest method missingDates.
@Test
public void missingDates() {
TargetDTO target = new TargetDTO();
AddTarget command = new AddTarget();
command.setTarget(target);
assertThat(validator.validate(command), hasItems(forProperty("target.name"), forProperty("target.fromDate"), forProperty("target.toDate")));
}
Aggregations