use of org.activityinfo.server.database.hibernate.entity.TargetValueId 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