Example #1
0
  /**
   * Encargado de mostrar en un formulario la informacion de un riego de la identificacion
   *
   * @param idIrr: Identificacion del riego
   * @return Informacion del riego
   */
  public String show() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "crop/create")
        || !usrDao.getPrivilegeUser(idUsrSystem, "crop/modify")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    actExe = (String) (this.getRequest().getParameter("action"));
    try {
      this.setIdCrop(Integer.parseInt(this.getRequest().getParameter("idCrop")));
    } catch (NumberFormatException e) {
      //            LOG.error("There was an error trying to parse the activityId parameter");
      this.setIdCrop(-1);
    }

    HashMap prod = cropDao.findById(idCrop);
    Integer tyCro = Integer.parseInt(String.valueOf(prod.get("typeCrop")));
    //        System.out.println("tyCro=>"+tyCro);

    try {
      this.setIdIrr(Integer.parseInt(this.getRequest().getParameter("idIrr")));
    } catch (NumberFormatException e) {
      //            LOG.error("There was an error trying to parse the activityId parameter");
      this.setIdIrr(-1);
    }

    this.setType_irr_typ(new IrrigationsTypesDao().findAllByTypeCrop(tyCro));
    if (this.getIdIrr() != -1) {
      irr = irrDao.objectById(this.getIdIrr());
    }
    return SUCCESS;
  }
Example #2
0
  /**
   * Encargado de guardar la informacion suministrada por el usuario para un riego
   *
   * @return Estado del proceso
   */
  public String saveData() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "crop/create")
        || !usrDao.getPrivilegeUser(idUsrSystem, "crop/modify")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    String action = "";
    //        System.out.println("Entre a guardar la info");
    /*
     * Se evalua dependiendo a la accion realizada:
     * 1) create: Al momento de guardar un registro por primera ves
     * 2) modify: Al momento de modificar un registro
     * 3) delete: Al momento de borrar un registro
     */
    if (actExe.equals("create")) {
      action = "C";
    } else if (actExe.equals("modify")) {
      action = "M";
    }

    SessionFactory sessions = HibernateUtil.getSessionFactory();
    Session session = sessions.openSession();
    Transaction tx = null;

    try {
      tx = session.beginTransaction();

      String dmy = new SimpleDateFormat("yyyy-MM-dd").format(irr.getDateIrr());
      Date dateIrr = new SimpleDateFormat("yyyy-MM-dd").parse(dmy);

      irr.setUseIrrigationIrr(true);
      irr.setProductionEvents(new ProductionEvents(idCrop));
      irr.setDateIrr(dateIrr);
      //            if (sowing.getChemicalsSowing().getIdCheSow()==-1) {
      //                sowing.setChemicalsSowing(null);
      //            }
      //
      //            if (sowing.getDoseUnits().getIdDosUni()==-1) {
      //                sowing.setDoseUnits(null);
      //            }
      irr.setStatus(true);
      session.saveOrUpdate(irr);

      LogEntities log = new LogEntities();
      log.setIdLogEnt(null);
      log.setIdEntityLogEnt(idEntSystem);
      log.setIdObjectLogEnt(irr.getIdIrr());
      log.setTableLogEnt("irrigation");
      log.setDateLogEnt(new Date());
      log.setActionTypeLogEnt(action);
      session.saveOrUpdate(log);
      tx.commit();
      state = "success";
      if (action.equals("C")) {
        info = "El riego ha sido agregado con exito";
        //                return "list";
      } else if (action.equals("M")) {
        info = "El riego ha sido modificado con exito";
        //                return "list";
      }
      HashMap prod = cropDao.findById(idCrop);
      Integer tyCro = Integer.parseInt(String.valueOf(prod.get("typeCrop")));
      SfGuardUserDao sfDao = new SfGuardUserDao();
      SfGuardUser sfUser = sfDao.getUserByLogin(user.getCreatedBy(), user.getNameUserUsr(), "");
      GlobalFunctions.sendInformationCrop(idCrop, tyCro, sfUser.getId());
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
      //            System.out.println("error->"+e.getMessage());
      state = "failure";
      info = "Fallo al momento de agregar un riego";
    } catch (ParseException e) {

    } finally {
      session.close();
    }

    //        return ERROR;
    return "states";
  }