Search in sources :

Example 1 with TargetValueId

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();
}
Also used : TargetValue(org.activityinfo.server.database.hibernate.entity.TargetValue) UpdateTargetValue(org.activityinfo.shared.command.UpdateTargetValue) Target(org.activityinfo.server.database.hibernate.entity.Target) PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) VoidResult(org.activityinfo.shared.command.result.VoidResult) TargetValueId(org.activityinfo.server.database.hibernate.entity.TargetValueId) CommandException(org.activityinfo.shared.exception.CommandException) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator)

Aggregations

PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 Target (org.activityinfo.server.database.hibernate.entity.Target)1 TargetValue (org.activityinfo.server.database.hibernate.entity.TargetValue)1 TargetValueId (org.activityinfo.server.database.hibernate.entity.TargetValueId)1 UpdateTargetValue (org.activityinfo.shared.command.UpdateTargetValue)1 VoidResult (org.activityinfo.shared.command.result.VoidResult)1 CommandException (org.activityinfo.shared.exception.CommandException)1