Search in sources :

Example 1 with Target

use of org.activityinfo.server.database.hibernate.entity.Target in project activityinfo by bedatadriven.

the class AddTargetHandler method execute.

@Override
public CommandResult execute(AddTarget cmd, User user) throws CommandException {
    TargetDTO form = cmd.getTargetDTO();
    UserDatabase db = em.find(UserDatabase.class, cmd.getDatabaseId());
    Partner partner = null;
    if (form.get("partnerId") != null) {
        partner = em.find(Partner.class, form.get("partnerId"));
    }
    Project project = null;
    if (form.get("projectId") != null) {
        project = em.find(Project.class, form.get("projectId"));
    }
    AdminEntity adminEntity = null;
    // if(form.getAdminEntity() != null){
    // adminEntity = em.find(AdminEntity.class,
    // form.getAdminEntity().getId());
    // }
    Target target = new Target();
    target.setName(form.getName());
    target.setUserDatabase(db);
    target.setAdminEntity(adminEntity);
    target.setPartner(partner);
    target.setProject(project);
    target.setDate1(form.getDate1());
    target.setDate2(form.getDate2());
    db.setLastSchemaUpdate(new Date());
    em.persist(target);
    em.persist(db);
    db.getTargets().add(target);
    // }
    if (project != null) {
        project.getTargets().add(target);
    }
    if (partner != null) {
        partner.getTargets().add(target);
    }
    return new CreateResult(target.getId());
}
Also used : Project(org.activityinfo.server.database.hibernate.entity.Project) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Target(org.activityinfo.server.database.hibernate.entity.Target) AddTarget(org.activityinfo.shared.command.AddTarget) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) TargetDTO(org.activityinfo.shared.dto.TargetDTO) Partner(org.activityinfo.server.database.hibernate.entity.Partner) Date(java.util.Date)

Example 2 with Target

use of org.activityinfo.server.database.hibernate.entity.Target in project activityinfo by bedatadriven.

the class UpdateEntityHandler method updateTarget.

private void updateTarget(User user, UpdateEntity cmd, Map<String, Object> changes) {
    // TODO: check permissions when updating the Target
    Target target = entityManager().find(Target.class, cmd.getId());
    updateTargetProperties(target, changes);
    target.getUserDatabase().setLastSchemaUpdate(new Date());
}
Also used : Target(org.activityinfo.server.database.hibernate.entity.Target) Date(java.util.Date)

Example 3 with Target

use of org.activityinfo.server.database.hibernate.entity.Target 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

Target (org.activityinfo.server.database.hibernate.entity.Target)3 Date (java.util.Date)2 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)1 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 Partner (org.activityinfo.server.database.hibernate.entity.Partner)1 Project (org.activityinfo.server.database.hibernate.entity.Project)1 TargetValue (org.activityinfo.server.database.hibernate.entity.TargetValue)1 TargetValueId (org.activityinfo.server.database.hibernate.entity.TargetValueId)1 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)1 AddTarget (org.activityinfo.shared.command.AddTarget)1 UpdateTargetValue (org.activityinfo.shared.command.UpdateTargetValue)1 CreateResult (org.activityinfo.shared.command.result.CreateResult)1 VoidResult (org.activityinfo.shared.command.result.VoidResult)1 TargetDTO (org.activityinfo.shared.dto.TargetDTO)1 CommandException (org.activityinfo.shared.exception.CommandException)1