use of org.activityinfo.server.database.hibernate.entity.Target 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.server.database.hibernate.entity.Target in project activityinfo by bedatadriven.
the class UpdateEntityHandler method updateTarget.
private void updateTarget(User user, UpdateEntity cmd, Map<String, Object> changes) {
// TODO: check permissions when updating the Target
Target target = entityManager().find(Target.class, cmd.getId());
updateTargetProperties(target, changes);
target.getUserDatabase().setLastSchemaUpdate(new Date());
}
use of org.activityinfo.server.database.hibernate.entity.Target in project activityinfo by bedatadriven.
the class UpdateTargetValueHandler method execute.
@Override
public CommandResult execute(UpdateTargetValue cmd, User user) throws CommandException {
LOG.fine("[execute] Update command for entity: TargetValue");
Map<String, Object> changes = cmd.getChanges().getTransientMap();
new PropertyMap(changes);
try {
TargetValue targetValue = entityManager().find(TargetValue.class, new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
if (cmd.getChanges().get("value") != null) {
targetValue.setValue((Double.valueOf((String) cmd.getChanges().get("value"))));
entityManager().persist(targetValue);
return new VoidResult();
}
entityManager().remove(targetValue);
return new VoidResult();
} catch (Exception e) {
// ignore
}
Target target = entityManager().find(Target.class, cmd.getTargetId());
Indicator indicator = entityManager().find(Indicator.class, cmd.getIndicatorId());
TargetValue targetValue = new TargetValue();
targetValue.setId(new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
targetValue.setValue((Double.valueOf((String) cmd.getChanges().get("value"))));
targetValue.setTarget(target);
targetValue.setIndicator(indicator);
entityManager().persist(targetValue);
return new VoidResult();
}
Aggregations