Search in sources :

Example 1 with UpdateTargetValue

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);
    }
}
Also used : EntityDTO(org.activityinfo.shared.dto.EntityDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) UpdateTargetValue(org.activityinfo.shared.command.UpdateTargetValue) Record(com.extjs.gxt.ui.client.store.Record)

Example 2 with UpdateTargetValue

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();
}
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

UpdateTargetValue (org.activityinfo.shared.command.UpdateTargetValue)2 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 Record (com.extjs.gxt.ui.client.store.Record)1 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 VoidResult (org.activityinfo.shared.command.result.VoidResult)1 EntityDTO (org.activityinfo.shared.dto.EntityDTO)1 CommandException (org.activityinfo.shared.exception.CommandException)1