use of org.activityinfo.legacy.shared.command.UpdateTargetValue in project activityinfo by bedatadriven.
the class UpdateTargetValueHandler method execute.
@Override
public CommandResult execute(UpdateTargetValue cmd, User user) throws CommandException {
Double newValue = cmd.getChanges().get("value");
TargetValue targetValue = entityManager().find(TargetValue.class, new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
if (targetValue == null) {
if (newValue != null) {
// Need a new record
Target target = entityManager().find(Target.class, cmd.getTargetId());
Indicator indicator = entityManager().find(Indicator.class, cmd.getIndicatorId());
targetValue = new TargetValue();
targetValue.setId(new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
targetValue.setValue(cmd.getChanges().get("value"));
targetValue.setTarget(target);
targetValue.setIndicator(indicator);
entityManager().persist(targetValue);
}
} else {
targetValue.setValue(newValue);
}
return new VoidResult();
}
Aggregations