Пример #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 mostrar en un formulario la informacion de una finca apartir de la identificacion
   *
   * @param idFar: Identificacion de la finca
   * @return Informacion de la finca
   */
  public String show() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/create")
        || !usrDao.getPrivilegeUser(idUsrSystem, "farm/modify")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    actExe = (String) (this.getRequest().getParameter("action"));
    viewInfo = (String) (this.getRequest().getParameter("viewInfo"));
    int pageReq;
    if (this.getRequest().getParameter("page") != null) {
      pageReq = Integer.parseInt(StringUtils.trim(this.getRequest().getParameter("page")));
      this.setPage(pageReq);
    }
    try {
      this.setIdFarm(Integer.parseInt(this.getRequest().getParameter("idFar")));
    } catch (NumberFormatException e) {
      this.setIdFarm(-1);
      //            return;
    }

    this.setDepartment_property(new DepartmentsDao().findAll());
    //        System.out.println("id farm->"+this.getIdFarm());
    if (this.getIdFarm() != -1) {
      FarmsDao eventoDao = new FarmsDao();
      //            System.out.println("id_producer->"+this.getIdProducer());
      HashMap farmInfo = eventoDao.findById(this.getIdFarm());
      //            System.out.println("valores->" + farmInfo);

      // Pasar la conversion a grados, min, seg por defecto ??
      this.setIdProducer(Integer.parseInt(String.valueOf(farmInfo.get("id_producer"))));
      this.setIdFarm(Integer.parseInt(String.valueOf(farmInfo.get("id_farm"))));
      this.setName_producer(String.valueOf(farmInfo.get("name_producer")));
      this.setName_property(String.valueOf(farmInfo.get("name_farm")));
      this.setLatitude_property(String.valueOf(farmInfo.get("latitude_farm")));
      this.setLength_property(String.valueOf(farmInfo.get("length_farm")));
      //            this.setOption_geo(1);

      this.setAltitude_property(String.valueOf(farmInfo.get("altitude_farm")));
      this.setDirection_property(String.valueOf(farmInfo.get("dir_farm")));
      this.setLane_property(String.valueOf(farmInfo.get("lane_farm")));
      this.setDepFar(String.valueOf(farmInfo.get("id_dep")));
      this.setCityFar(String.valueOf(farmInfo.get("id_mun")));
      this.setCity_property(
          new MunicipalitiesDao()
              .findAll(Integer.parseInt(String.valueOf(farmInfo.get("id_dep")))));
    } else {
      List<Municipalities> mun = new ArrayList<Municipalities>();
      mun.add(new Municipalities());
      this.setCity_property(mun);
    }
    return SUCCESS;
  }
Пример #3
0
 @Override
 public void prepare() throws Exception {
   user = (Users) this.getSession().get(APConstants.SESSION_USER);
   idEntSystem = UsersDao.getEntitySystem(user.getIdUsr());
   usrDao = new UsersDao();
   idUsrSystem = user.getIdUsr();
 }
Пример #4
0
  @Override
  public void prepare() throws Exception {
    user = (Users) ActionContext.getContext().getSession().get(APConstants.SESSION_USER);
    //        user = (Users) this.getSession().get(APConstants.SESSION_USER);
    idEntSystem = UsersDao.getEntitySystem(user.getIdUsr());
    EntitiesDao entDao = new EntitiesDao();
    Entities entTemp = entDao.findById(idEntSystem);
    typeEnt = entTemp.getEntitiesTypes().getIdEntTyp();
    if (entTemp.getEntitiesTypes().getIdEntTyp() == 2) {
      ProducersDao proDao = new ProducersDao();
      Producers proTemp = new Producers();
      proTemp = proDao.objectByEntityId(idEntSystem);
      if (proTemp != null) {
        idProducer = proTemp.getIdPro();
        name_producer = entTemp.getNameEnt();
      }
    }
    this.setDepartment_property(new DepartmentsDao().findAll());
    usrDao = new UsersDao();
    idUsrSystem = user.getIdUsr();
    List<Municipalities> mun = new ArrayList<Municipalities>();
    mun.add(new Municipalities());
    this.setCity_property(mun);
    assDao = new AssociationDao();
    //        HashMap route = new HashMap();
    //        route.put("getting", getText("email.from"));
    //        listRoute.add(route);
    //        route = new HashMap();
    ////        String val = getText('text.title.farm');
    //        route.put("listFarm", getText("email.from"));
    //        listRoute.add(route);

  }
Пример #5
0
  /**
   * Encargado de borrar la informacion de las fincas que se han seleccionado
   *
   * @param valSel: Valores que se han seleccionado para borrar
   * @return Estado del proceso
   */
  public String deleteAll() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/delete")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    String valSel = "";
    try {
      valSel = String.valueOf(this.getRequest().getParameter("valSel"));
    } catch (NumberFormatException e) {
      valSel = "-1";
    }

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

    state = farDao.deleteAllFarms(valSel, idEntSystem);
    if (state.equals("success")) {
      info = "La o las finca(s) ha(n) sido borrada(s) con exito";
    } else if (state.equals("failure")) {
      info = "Fallo al momento de borrar una finca";
    }

    return "states";
  }
Пример #6
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;
  }
Пример #7
0
  /**
   * Encargado de buscar las coincidencias de un formulario de busqueda, para cada uno de los riegos
   * registrados a un usuario
   *
   * @param valName: Nombre del valor a buscar
   * @param valId: Identificacion del valor a buscar
   * @param selected: Valor seleccionado
   * @return lista de riegos
   */
  public String search() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "crop/list")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    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 findParams = new HashMap();
    findParams.put("idEntUser", idEntSystem);
    findParams.put("idEvent", this.getIdCrop());
    listIrr = irrDao.findByParams(findParams);
    return SUCCESS;
  }
Пример #8
0
  public String getReport() throws Exception {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/list")) {
      return BaseAction.NOT_AUTHORIZED;
    }

    String selAll = "false";
    if (selectAllname_agronomist != null) {
      selAll = "true";
    }

    HashMap findParams = new HashMap();
    findParams.put("selAll", selAll);
    findParams.put("selItem", selectItemname_agronomist);
    Integer entTypeId = new EntitiesDao().getEntityTypeId(user.getIdUsr());
    findParams.put("entType", entTypeId);
    findParams.put("idEntUser", idEntSystem);
    String fileName = "" + getText("file.docfarm");
    //        String fileName  = "farmsInfo.csv";
    farDao.getFarms(findParams, fileName);

    File f = new File(fileName);
    inputStream = new FileInputStream(f);
    return "OUTPUTCSV";
  }
Пример #9
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";
  }
Пример #10
0
  /**
   * Encargado de guardar la informacion suministrada por el usuario para una siembra
   *
   * @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;
    //        info = "La siembra ha sido modificado con exito";

    try {
      tx = session.beginTransaction();

      String dmy = new SimpleDateFormat("yyyy-MM-dd").format(sowing.getDateSow());
      Date dateSow = new SimpleDateFormat("yyyy-MM-dd").parse(dmy);

      //            event.setFields(event.getFields());
      //            event.setCropsTypes(new CropsTypes(2));
      //            event.setIdProjectProEve(event.getIdProjectProEve());
      //            event.setStatus(event.isStatus());
      session.saveOrUpdate(event);

      if (sowing.getIdSow() == null) {
        Sowing sowTemp = sowDao.objectById(idCrop);
        if (sowTemp != null) {
          sowing.setIdSow(sowTemp.getIdSow());
        }
      }

      sowing.setProductionEvents(new ProductionEvents(idCrop));
      sowing.setDateSow(dateSow);
      if (sowing.getChemicalsSowing().getIdCheSow() == -1) {
        sowing.setChemicalsSowing(null);
      }

      if (sowing.getDoseUnits() != null
          && (sowing.getDoseUnits().getIdDosUni() == -1
              || sowing.getChemicalsSowing().getIdCheSow() == 3)) {
        sowing.setDoseUnits(null);
      }
      //            sowing.setSowingTypes(new SowingTypes(idCrop));
      sowing.setStatus(true);
      session.saveOrUpdate(sowing);

      Maize maizeOld = maizeDao.objectById(this.getIdCrop());
      if (maizeOld != null) session.delete(maizeOld);

      Beans beansOld = beansDao.objectById(this.getIdCrop());
      if (beansOld != null) session.delete(beansOld);

      if (typeCrop == 1) {
        maize.setProductionEvents(new ProductionEvents(idCrop));
        maize.setStatus(true);
        session.saveOrUpdate(maize);
      } else if (typeCrop == 2) {
        beans.setSeedsTypes(null);
        beans.setProductionEvents(new ProductionEvents(idCrop));
        beans.setStatus(true);
        session.saveOrUpdate(beans);
      } else if (typeCrop == 3) {
        //                Cassavas ca = new Cassavas();
        //                ca.setIdCas(null);
        //                ca.setProductionEvents(pro);
      }

      LogEntities log = new LogEntities();
      log.setIdLogEnt(null);
      log.setIdEntityLogEnt(idEntSystem);
      log.setIdObjectLogEnt(sowing.getIdSow());
      log.setTableLogEnt("sowing");
      log.setDateLogEnt(new Date());
      log.setActionTypeLogEnt(action);
      session.saveOrUpdate(log);

      tx.commit();
      state = "success";
      if (action.equals("C")) {
        info = "La siembra ha sido agregada con exito";
        //                return "list";
      } else if (action.equals("M")) {
        info = "La siembra ha sido modificada con exito";
        //                return "list";
      }
      SfGuardUserDao sfDao = new SfGuardUserDao();
      SfGuardUser sfUser = sfDao.getUserByLogin(user.getCreatedBy(), user.getNameUserUsr(), "");
      GlobalFunctions.sendInformationCrop(idCrop, typeCrop, 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 una siembra";
    } catch (ParseException e) {

    } finally {
      session.close();
    }

    //        return ERROR;
    return "states";
  }
Пример #11
0
  /**
   * Encargado de guardar la informacion suministrada por el usuario para una finca
   *
   * @return Estado del proceso
   */
  public String saveData() throws SQLException {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/create")
        || !usrDao.getPrivilegeUser(idUsrSystem, "farm/modify")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    String action = "";
    /*
     * 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";
    }

    ProducersDao proDao = new ProducersDao();
    SessionFactory sessions = HibernateUtil.getSessionFactory();
    Session session = sessions.openSession();
    Transaction tx = null;
    HashMap proData = proDao.findById(idProducer);

    Double altPro = Double.parseDouble(altitude_property.replace(',', '.'));
    Double latPro = Double.parseDouble(latitude_property.replace(',', '.'));
    Double lonPro = Double.parseDouble(length_property.replace(',', '.'));
    //        Double altPro = Double.parseDouble(altitude_property);
    //        Double latPro = Double.parseDouble(latitude_property);
    //        Double lonPro = Double.parseDouble(length_property);

    if (option_geo == 2) {
      latPro = (latitude_minutes_property / 60) + (latitude_seconds_property / 3600);
      latPro =
          (latitude_degrees_property < 0)
              ? ((Math.abs(latitude_degrees_property)) + latPro) * -1
              : (latitude_degrees_property + latPro);

      lonPro = (length_minutes_property / 60) + (length_seconds_property / 3600);
      lonPro =
          (length_degrees_property < 0)
              ? ((Math.abs(length_degrees_property)) + lonPro) * -1
              : (length_degrees_property + lonPro);
    }

    try {
      tx = session.beginTransaction();
      SfGuardUserDao sfDao = new SfGuardUserDao();
      SfGuardUser sfUser = sfDao.getUserByLogin(user.getCreatedBy(), user.getNameUserUsr(), "");
      Farms far = null;
      int idProOld = 0;
      if (idFarm <= 0) {
        far = new Farms();
        far.setIdFar(null);
        far.setGeorefFar(true);
        far.setIdProjectFar("1");
        far.setStatus(true);
      } else {
        HashMap fieldInfo = farDao.findById(idFarm);
        idProOld = Integer.parseInt(String.valueOf(fieldInfo.get("id_producer")));
        far = farDao.objectById(idFarm);
      }
      far.setNameFar(name_property);
      far.setAddressFar(direction_property);
      far.setLatitudeFar(latPro);
      far.setLongitudeFar(lonPro);
      far.setAltitudeFar(altPro);
      far.setNameCommuneFar(lane_property);
      far.setMunicipalities(new Municipalities(Integer.parseInt(cityFar)));
      Integer idUserMobile = null;
      if (sfUser != null) {
        idUserMobile = sfUser.getId().intValue();
      }
      far.setCreatedBy(idUserMobile);
      session.saveOrUpdate(far);
      depFar = String.valueOf(MunicipalitiesDao.getDepartmentId(Integer.parseInt(cityFar)));

      //            farDao.save(far);
      //            System.out.println("valId->"+far.getIdFar());

      if (far.getIdFar() > 0 && action.equals("M")) {
        if (idProOld != idProducer) {
          FarmsProducers farTemp = farDao.checkFarmProducer(far.getIdFar(), idProOld);
          session.delete(farTemp);
        }
        //                System.out.println("id field->"+fiePro.getFields().getIdFie());
        //                fiePro = new FieldsProducers();
        //                fiePro.setId(new FieldsProducersId(lot.getIdFie(), idProducer));
        //                fiePro.setFields(lot);
        //                fiePro.setProducers(proDao.objectById(idProducer));
        //                fiePro.setFieldTypes(new FieldTypes(typeLot));
        //                session.saveOrUpdate(fiePro);
      }

      if (idProOld != idProducer) {
        FarmsProducers farPro = new FarmsProducers();
        farPro.setId(new FarmsProducersId(far.getIdFar(), idProducer));
        farPro.setFarms(far);
        farPro.setProducers(proDao.objectById(idProducer));
        session.saveOrUpdate(farPro);
      }

      /*LogEntities log = new LogEntities();
      log.setIdLogEnt(null);
      log.setIdEntityLogEnt(idEntSystem); //Colocar el usuario registrado en el sistema
      log.setIdObjectLogEnt(far.getIdFar());
      log.setTableLogEnt("farms");
      log.setDateLogEnt(new Date());
      log.setActionTypeLogEnt(action);
      session.saveOrUpdate(log);*/
      //            logDao.save(log);

      /*
      "102": "Nombre de la finca" => nameFarm
      "103": "-30.98664622,-64.10017675,601" Capturar posicion => lat, lng, alt
      "105": "Vereda" => district
      "108": "Indicación (como llegar)" => address
      "241": "Seleccione el productor asociado" => Seleccion (solo dato seleccionado) => prodId
      "336": "Departamento" => department
      "338": "Municipio (Amazonas)" => municipality
      */

      // Manejo para ingresar datos en MongoDB

      HashMap valInfo = new HashMap();
      valInfo.put("farmId", far.getIdFar());
      valInfo.put("nameFarm", far.getNameFar());
      valInfo.put("prodId", idProducer);
      valInfo.put("nameProd", proData.get("name"));
      valInfo.put("district", far.getNameCommuneFar());
      valInfo.put("address", far.getAddressFar());
      valInfo.put("lat", latPro);
      valInfo.put("lng", lonPro);
      valInfo.put("alt", altPro);
      valInfo.put("department", depFar);
      valInfo.put("municipality", cityFar);
      valInfo.put("userMobileId", idUserMobile);
      //            System.out.println("valInfo=>"+valInfo);

      BasicDBObject query = new BasicDBObject();
      query.put("InsertedId", "" + far.getIdFar());
      query.put("form_id", "3");

      MongoClient mongo = null;
      try {
        mongo = new MongoClient("localhost", 27017);
      } catch (UnknownHostException ex) {
        Logger.getLogger(ActionField.class.getName()).log(Level.SEVERE, null, ex);
      }
      DB db = mongo.getDB("ciat");
      DBCollection col = db.getCollection("log_form_records");

      DBCursor cursor = col.find(query);
      WriteResult result = null;
      BasicDBObject jsonField = GlobalFunctions.generateJSONFarm(valInfo);

      if (cursor.count() > 0) {
        System.out.println("actualizo mongo");
        result = col.update(query, jsonField);
      } else {
        System.out.println("inserto mongo");
        result = col.insert(jsonField);
      }

      if (result.getError() != null) {
        throw new HibernateException("");
      }

      mongo.close();
      tx.commit();
      state = "success";
      if (action.equals("C")) {
        info = "La finca ha sido agregada con exito";
        //                return "list";
      } else if (action.equals("M")) {
        info = "La finca ha sido modificada con exito";
      }
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
      state = "failure";
      info = "Fallo al momento de agregar una finca";
    } finally {
      session.close();
    }

    return "states";
    //        return ERROR;
  }
Пример #12
0
  /**
   * Encargado de buscar las coincidencias de un formulario de busqueda, para cada una de las fincas
   * registradas a un usuario
   *
   * @param valName: Nombre del valor a buscar
   * @param valId: Identificacion del valor a buscar
   * @param selected: Valor seleccionado
   * @return lista de fincas
   */
  public String search() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/list")) {
      //        if (!false) {
      return BaseAction.NOT_AUTHORIZED;
    }
    valName = (String) (this.getRequest().getParameter("valName"));
    valId = (String) (this.getRequest().getParameter("valId"));
    selected = (String) (this.getRequest().getParameter("selected"));
    viewInfo = (String) (this.getRequest().getParameter("viewInfo"));
    String selAll = "false";
    if (selected == null) {
      selected = "property";
      selAll = "true";
    }

    if (selectAllname_agronomist != null) {
      selAll = "true";
    }
    additionals = new HashMap();
    additionals.put("selected", selected);
    HashMap findParams = new HashMap();
    findParams.put("selAll", selAll);
    findParams.put("selItem", selectItemname_agronomist);
    Integer entTypeId = new EntitiesDao().getEntityTypeId(user.getIdUsr());
    findParams.put("entType", entTypeId);
    list_agronomist = assDao.gelAllAgronomist(idEntSystem);
    if (searchFromFarm != null && searchFromFarm == 2) {
      search_farm = "";
    }

    //        fardParams.put("nameProperty", this.getName_property());
    //        System.out.println("this.getAltitude_property()->"+this.getAltitude_property());
    findParams.put("idEntUser", idEntSystem);
    findParams.put("search_farm", search_farm);
    findParams.put("name_producer", name_producer);
    findParams.put("name_property", name_property);
    findParams.put("depFar", depFar);
    findParams.put("cityFar", cityFar);
    findParams.put("lane_property", lane_property);
    findParams.put("altitude_property", altitude_property);
    findParams.put("latitude_property", latitude_property);
    findParams.put("length_property", length_property);
    int pageReq;
    if (this.getRequest().getParameter("page") == null) {
      pageReq = this.getPage();
    } else {
      pageReq = Integer.parseInt(StringUtils.trim(this.getRequest().getParameter("page")));
    }
    findParams.put("pageNow", pageReq);
    findParams.put("maxResults", this.getMaxResults());
    FarmsDao farmDao = new FarmsDao();
    //        System.out.println("entreeee");
    listProperties = farmDao.findByParams(findParams);
    //        this.setCountTotal(100);
    //        System.out.println("entreeee->"+listProperties.get(0).get("countTotal"));
    this.setCountTotal(Integer.parseInt(String.valueOf(listProperties.get(0).get("countTotal"))));
    this.setPage(page);
    listProperties.remove(0);
    //        System.out.println("countTotal->"+this.getCountTotal());
    return SUCCESS;
  }
Пример #13
0
  /**
   * Encargado de borrar la informacion de una finca apartir de su identificacion
   *
   * @param idFar: Identificacion de la finca
   * @return Estado del proceso
   */
  public String delete() {
    if (!usrDao.getPrivilegeUser(idUsrSystem, "farm/delete")) {
      return BaseAction.NOT_AUTHORIZED;
    }
    Integer idFar = 0;
    try {
      idFar = Integer.parseInt(this.getRequest().getParameter("idFar"));
    } catch (NumberFormatException e) {
      idFar = -1;
    }

    if (idFar == -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();
      Farms far = farDao.objectById(idFar);
      far.setStatus(false);
      session.saveOrUpdate(far);
      //            session.delete(far);
      //            farDao.delete(far);

      LogEntities log = new LogEntities();
      log.setIdLogEnt(null);
      log.setIdEntityLogEnt(idEntSystem); // Colocar el usuario registrado en el sistema
      log.setIdObjectLogEnt(far.getIdFar());
      log.setTableLogEnt("farms");
      log.setDateLogEnt(new Date());
      log.setActionTypeLogEnt("D");
      session.saveOrUpdate(log);
      //            logDao.save(log);

      BasicDBObject query = new BasicDBObject();
      query.put("InsertedId", "" + far.getIdFar());
      query.put("form_id", "3");

      MongoClient mongo = null;
      try {
        mongo = new MongoClient("localhost", 27017);
      } catch (UnknownHostException ex) {
        Logger.getLogger(ActionField.class.getName()).log(Level.SEVERE, null, ex);
      }
      DB db = mongo.getDB("ciat");
      DBCollection col = db.getCollection("log_form_records");
      WriteResult result = null;

      System.out.println("borro mongo");
      result = col.remove(query);

      if (result.getError() != null) {
        throw new HibernateException("");
      }
      mongo.close();

      FieldsDao fieDao = new FieldsDao();
      fieDao.deleteFieldsMongo(far.getIdFar());

      tx.commit();
      state = "success";
      info = "La finca ha sido borrada con exito";
    } catch (HibernateException e) {
      if (tx != null) {
        tx.rollback();
      }
      e.printStackTrace();
      state = "failure";
      info = "Fallo al momento de borrar una finca";
    } finally {
      session.close();
    }

    return "states";
    //        return SUCCESS;
  }