use of org.activityinfo.shared.command.UpdateTargetValue in project activityinfo by bedatadriven.
the class TargetIndicatorPresenter method prepareBatch.
protected void prepareBatch(BatchCommand batch, ModelData model) {
if (model instanceof EntityDTO) {
Record record = treeStore.getRecord(model);
if (record.isDirty()) {
UpdateTargetValue cmd = new UpdateTargetValue((Integer) model.get("targetId"), (Integer) model.get("indicatorId"), this.getChangedProperties(record));
batch.add(cmd);
}
}
for (ModelData child : treeStore.getChildren(model)) {
prepareBatch(batch, child);
}
}
use of org.activityinfo.shared.command.UpdateTargetValue 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