Search in sources :

Example 1 with UpdateTargetValue

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();
}
Also used : UpdateTargetValue(org.activityinfo.legacy.shared.command.UpdateTargetValue) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult)

Aggregations

UpdateTargetValue (org.activityinfo.legacy.shared.command.UpdateTargetValue)1 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)1