use of org.activityinfo.shared.command.AddTarget in project activityinfo by bedatadriven.
the class AddTargetHandler method execute.
@Override
public CommandResult execute(AddTarget cmd, User user) throws CommandException {
TargetDTO form = cmd.getTargetDTO();
UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
Partner partner = null;
if (form.get("partnerId") != null) {
partner = em.find(Partner.class, form.get("partnerId"));
}
Project project = null;
if (form.get("projectId") != null) {
project = em.find(Project.class, form.get("projectId"));
}
AdminEntity adminEntity = null;
// if(form.getAdminEntity() != null){
// adminEntity = em.find(AdminEntity.class,
// form.getAdminEntity().getId());
// }
Target target = new Target();
target.setName(form.getName());
target.setUserDatabase(db);
target.setAdminEntity(adminEntity);
target.setPartner(partner);
target.setProject(project);
target.setDate1(form.getDate1());
target.setDate2(form.getDate2());
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.shared.command.AddTarget 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();
/*
* Load Targets to verify the changes have stuck
*/
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
Assert.assertEquals("name", "Target0071", dto.getName());
/*
* Delete new target now
*/
execute(new Delete(dto));
/*
* Verify if target is deleted.
*/
targets = execute(new GetTargets()).getData();
TargetDTO deleted = getTargetById(targets, newId);
Assert.assertNull(deleted);
}
use of org.activityinfo.shared.command.AddTarget in project activityinfo by bedatadriven.
the class TargetTest method testTarget.
@Test
public void testTarget() throws CommandException {
/*
* Create a new Target
*/
TargetDTO target = createTarget();
CreateResult cresult = execute(new AddTarget(db.getId(), target));
int newId = cresult.getNewId();
/*
* Load Targets to verify the changes have stuck
*/
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
Assert.assertNotNull(dto);
Assert.assertEquals("name", "Target0071", dto.getName());
}
use of org.activityinfo.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, 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());
PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
newTarget.setPartner(partner);
ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
newTarget.setProject(project);
store.add(newTarget);
store.commitChanges();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
dlg.hide();
}
});
}
});
}
Aggregations