示例#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;
  }
示例#2
0
  /**
   * Encargado de borrar la informacion de un riego apartir de su identificacion
   *
   * @param idIrr: Identificacion del riego
   * @return Estado del proceso
   */
  public String delete() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "crop/delete")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    Integer idIrr = 0;
    try {
      idIrr = Integer.parseInt(this.getRequest().getParameter("idIrr"));
    } catch (NumberFormatException e) {
      idIrr = -1;
    }

    if (idIrr == -1) {
      state = "failure";
      info = "Fallo al momento de obtener la informacion a borrar";
      return "states";
    }

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

    try {
      tx = session.beginTransaction();
      Irrigation pr = irrDao.objectById(idIrr);
      pr.setStatus(false);
      //            session.delete(pro);
      session.saveOrUpdate(pr);

      LogEntities log = new LogEntities();
      log.setIdLogEnt(null);
      log.setIdEntityLogEnt(idEntSystem);
      log.setIdObjectLogEnt(pr.getIdIrr());
      log.setTableLogEnt("irrigation");
      log.setDateLogEnt(new Date());
      log.setActionTypeLogEnt("D");
      session.saveOrUpdate(log);
      //            logDao.save(log);
      tx.commit();
      state = "success";
      info = "El riego ha sido borrado con exito";
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
      state = "failure";
      info = "Fallo al momento de borrar un riego";
    } finally {
      session.close();
    }

    return "states";
    //        return SUCCESS;
  }