use of org.activityinfo.legacy.shared.model.TargetDTO 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.model.TargetDTO 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.model.TargetDTO in project activityinfo by bedatadriven.
the class TargetTest method deleteTargetTest.
@Test
public void deleteTargetTest() {
TargetDTO target = createTarget();
CreateResult cresult = execute(new AddTarget(db.getId(), target));
int newId = cresult.getNewId();
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
assertEquals("name", "Target0071", dto.getName());
execute(new Delete(dto));
targets = execute(new GetTargets()).getData();
TargetDTO deleted = getTargetById(targets, newId);
assertNull(deleted);
}
use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.
the class TargetTest method testTarget.
@Test
public void testTarget() throws CommandException {
TargetDTO target = createTarget();
CreateResult cresult = execute(new AddTarget(db.getId(), target));
int newId = cresult.getNewId();
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
assertNotNull(dto);
assertEquals("name", "Target0071", dto.getName());
}
use of org.activityinfo.legacy.shared.model.TargetDTO in project activityinfo by bedatadriven.
the class DbTargetGrid method createGridAndAddToContainer.
@Override
protected Grid<TargetDTO> createGridAndAddToContainer(Store store) {
this.store = (ListStore<TargetDTO>) store;
grid = new Grid<TargetDTO>((ListStore) store, createColumnModel());
grid.setAutoExpandColumn("name");
grid.setLoadMask(true);
setLayout(new BorderLayout());
add(grid, new BorderLayoutData(Style.LayoutRegion.CENTER));
return grid;
}
Aggregations