예제 #1
0
  @Override
  public List<Pedido> listaPagPedidos(String username, int paginaActual, int resultadosPorPagina) {

    session = sessionFactory.openSession();
    Usuario usuario = (Usuario) session.get(Usuario.class, username);
    List<Pedido> p =
        session
            .createCriteria(Pedido.class)
            .add(Restrictions.eq("usuario", usuario))
            .add(Restrictions.eq("confirmado", true))
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .addOrder(Order.desc("idpedido"))
            .list();
    session.close();

    int primer_resultado = paginaActual * resultadosPorPagina - resultadosPorPagina;
    int max_resultados =
        paginaActual * resultadosPorPagina - resultadosPorPagina + resultadosPorPagina;

    List<Pedido> pe;

    if (p.subList(primer_resultado, p.size()).size() < resultadosPorPagina)
      pe = p.subList(primer_resultado, p.size());
    else pe = p.subList(primer_resultado, max_resultados);

    return pe;
  }
예제 #2
0
  public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de facturas con params {}", params);
    if (params == null) {
      params = new HashMap<>();
    }

    if (!params.containsKey("max")) {
      params.put("max", 10);
    } else {
      params.put("max", Math.min((Integer) params.get("max"), 100));
    }

    if (params.containsKey("pagina")) {
      Long pagina = (Long) params.get("pagina");
      Long offset = (pagina - 1) * (Integer) params.get("max");
      params.put("offset", offset.intValue());
    }

    if (!params.containsKey("offset")) {
      params.put("offset", 0);
    }
    Criteria criteria = currentSession().createCriteria(FacturaAlmacen.class);
    Criteria countCriteria = currentSession().createCriteria(FacturaAlmacen.class);

    if (params.containsKey("almacen")) {
      criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
      countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
    }

    if (params.containsKey("filtro")) {
      String filtro = (String) params.get("filtro");
      Disjunction propiedades = Restrictions.disjunction();
      propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE));
      criteria.add(propiedades);
      countCriteria.add(propiedades);
    }

    if (params.containsKey("order")) {
      String campo = (String) params.get("order");
      if (params.get("sort").equals("desc")) {
        criteria.addOrder(Order.desc(campo));
      } else {
        criteria.addOrder(Order.asc(campo));
      }
    } else {
      criteria.createCriteria("estatus").addOrder(Order.asc("prioridad"));
    }
    criteria.addOrder(Order.desc("fechaModificacion"));

    if (!params.containsKey("reporte")) {
      criteria.setFirstResult((Integer) params.get("offset"));
      criteria.setMaxResults((Integer) params.get("max"));
    }
    params.put("facturas", criteria.list());

    countCriteria.setProjection(Projections.rowCount());
    params.put("cantidad", (Long) countCriteria.list().get(0));

    return params;
  }
예제 #3
0
 public List<User> checkLogin(String username, String password) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("userName", username));
   criteria.add(Restrictions.eq("password", password));
   List<User> list = criteria.list();
   closeSession();
   return list;
 }
예제 #4
0
 public User getUserByUsernameAndId(String username, Integer id) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("userName", username));
   criteria.add(Restrictions.eq("userId", id));
   List<User> list = criteria.list();
   if (!list.isEmpty()) {
     return list.get(0);
   } else return null;
 }
예제 #5
0
  public List<BlacklistDTO> findByUserType(Integer userId, Integer type) {
    Criteria criteria =
        getSession()
            .createCriteria(BlacklistDTO.class)
            .createAlias("user", "u")
            .add(Restrictions.eq("u.id", userId))
            .add(Restrictions.eq("type", type));

    return criteria.list();
  }
예제 #6
0
  public List<BlacklistDTO> findByEntitySource(Integer entityId, Integer source) {
    Criteria criteria =
        getSession()
            .createCriteria(BlacklistDTO.class)
            .createAlias("company", "c")
            .add(Restrictions.eq("c.id", entityId))
            .add(Restrictions.eq("source", source));

    return criteria.list();
  }
예제 #7
0
  public List<User> getStaffData(
      String fName, String lName, String nickName, String company, String employeeId) {
    Criteria criteria = getSession().createCriteria(User.class);
    if (BeanUtils.isNotEmpty(fName) && BeanUtils.isNotEmpty(lName)) {
      if (BeanUtils.isNotEmpty(fName)) {
        criteria.add(Restrictions.like("thFname", "%" + fName + "%"));
      }
      if (BeanUtils.isNotEmpty(lName)) {
        criteria.add(Restrictions.like("thLname", "%" + lName + "%"));
      }
    } else if (BeanUtils.isEmpty(lName) && BeanUtils.isNotEmpty(fName)) {
      criteria.add(
          Restrictions.or(
              Restrictions.like("thFname", "%" + fName + "%"),
              Restrictions.like("thLname", "%" + fName + "%")));
    }
    if (BeanUtils.isNotEmpty(nickName)) {
      criteria.add(Restrictions.like("nickName", "%" + nickName + "%"));
    }
    if (BeanUtils.isNotEmpty(employeeId)) {
      criteria.add(Restrictions.like("empId", "%" + employeeId + "%"));
    }
    if (BeanUtils.isNotEmpty(company)) {
      criteria.add(Restrictions.eq("compId", Integer.parseInt(company)));
    }

    criteria.add(Restrictions.eq("status", 2));
    List<User> list = (List<User>) criteria.list();
    closeSession();
    return list;
  }
예제 #8
0
 public List<User> getUserValidate(String piority, Integer page) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("validateStu", 0));
   criteria.add(Restrictions.like("piority", "%" + piority + "%"));
   criteria.addOrder(Order.asc("dateCreate"));
   page = (page - 1) * 10;
   criteria.setFirstResult(page);
   criteria.setMaxResults(10);
   List<User> list = (List<User>) criteria.list();
   closeSession();
   return list;
 }
예제 #9
0
  public Integer getCountUserValidate(String staffPiority) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.eq("validateStu", 0));
    criteria.add(Restrictions.like("piority", "%" + staffPiority + "%"));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.count("validateStu"));
    criteria.setProjection(projectionList);

    Integer count = (Integer) criteria.uniqueResult();
    closeSession();
    return count;
  }
예제 #10
0
  public Integer getViewEva(Integer userId) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.eq("viewEav", 0));
    criteria.add(Restrictions.isNotNull("evaGrade"));

    List<User> users = criteria.list();

    Integer count = users.size();
    closeSession();
    return count;
  }
예제 #11
0
  public List<BlacklistDTO> filterByName(Integer entityId, String firstName, String lastName) {
    Criteria criteria =
        getSession()
            .createCriteria(BlacklistDTO.class)
            .createAlias("company", "c")
            .add(Restrictions.eq("c.id", entityId))
            .add(Restrictions.eq("type", BlacklistDTO.TYPE_NAME))
            .createAlias("contact", "ct")
            .add(equals("ct.firstName", firstName))
            .add(equals("ct.lastName", lastName));

    return criteria.list();
  }
예제 #12
0
 public List<User> getStudentUserDataList(Integer userID, String status) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("userId", userID));
   List<User> list = criteria.list();
   closeSession();
   if (status.equals("user")) {
     Criteria criteria1 = getSession().createCriteria(UniversityFacultyMajor.class);
     criteria1.add(Restrictions.eq("uniFacMajId", list.get(0).getUniFacMajId()));
     List<UniversityFacultyMajor> list1 = criteria1.list();
     closeSession();
     list.get(0).setUniversityFacultyMajor(list1.get(0));
   }
   return list;
 }
예제 #13
0
  public List<BlacklistDTO> filterByPhone(
      Integer entityId, Integer phoneCountryCode, Integer phoneAreaCode, String phoneNumber) {
    Criteria criteria =
        getSession()
            .createCriteria(BlacklistDTO.class)
            .createAlias("company", "c")
            .add(Restrictions.eq("c.id", entityId))
            .add(Restrictions.eq("type", BlacklistDTO.TYPE_PHONE_NUMBER))
            .createAlias("contact", "ct")
            .add(equals("ct.phoneCountryCode", phoneCountryCode))
            .add(equals("ct.phoneAreaCode", phoneAreaCode))
            .add(equals("ct.phoneNumber", phoneNumber));

    return criteria.list();
  }
예제 #14
0
  // Create by JOB
  public List<User> getAllUserTrainee() {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.setProjection(
        Projections.projectionList()
            .add(Projections.property("empId"), "empId")
            .add(Projections.property("thFname"), "thFname")
            .add(Projections.property("thLname"), "thLname"));
    Criterion cri = Restrictions.eq("aptId", 1);
    Criterion cri2 = Restrictions.eq("aptId", 2);
    criteria.add(Restrictions.or(cri, cri2));

    criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
    List<User> allUserTrainee = criteria.list();
    return allUserTrainee;
  }
예제 #15
0
  @Override
  public void borrarProductosCarrito(String username, int idproducto) {

    session = sessionFactory.openSession();
    Transaction transaction = null;
    try {

      transaction = session.beginTransaction();

      Producto producto = (Producto) session.get(Producto.class, idproducto);
      Pedido p = getPedidoCarritoSinSession(username);

      if (p != null) {

        List<LineaPedido> lp =
            session
                .createCriteria(LineaPedido.class)
                .add(Restrictions.eq("pedido", p))
                .add(Restrictions.eq("producto", producto))
                .list();

        if (lp.size() != 0) {

          int cantidad_productos = lp.get(0).getCantidad();

          // Si hay mas de 1 producto en el carrito, se borra sólo el producto del carrito
          if (p.getLineasPedido().size() > 1) {
            session.delete(lp.get(0));
            // Si sólo hay 1 producto en el carrito, se borra el producto del carrito y el carrito
          } else {
            session.delete(lp.get(0));
            session.delete(p);
          }

          producto.setCantidad(producto.getCantidad() + cantidad_productos);
          session.save(producto);
        }
      }

      transaction.commit();

    } catch (HibernateException e) {
      transaction.rollback();
      e.printStackTrace();
    } finally {
      session.close();
    }
  }
예제 #16
0
 public List<User> searchUserOneStringColum(String colum, String value) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq(colum, value));
   List<User> list = criteria.list();
   closeSession();
   return list;
 }
예제 #17
0
  public Pedido getPedidoCarritoSinSession(String username) {

    Pedido pedido = null;

    Usuario usuario = (Usuario) session.get(Usuario.class, username);
    List<Pedido> p =
        session
            .createCriteria(Pedido.class)
            .add(Restrictions.eq("usuario", usuario))
            .add(Restrictions.eq("confirmado", false))
            .list();

    if (p.size() > 0) pedido = p.get(0);

    return pedido;
  }
예제 #18
0
  public List findByRoleNameLike(String roleName) {

    Session session = HibernateTrain.getSession();
    Criteria criteria =
        session.createCriteria(StaffRole.class).add(Restrictions.like("roleName", roleName));
    return criteria.list();
  }
예제 #19
0
 public static User getUserDatas(Integer id) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("userId", id));
   User user = (User) criteria.uniqueResult();
   closeSession();
   return user;
 }
예제 #20
0
 public List<User> getStaff() {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("status", 2));
   List list = criteria.list();
   closeSession();
   return list;
 }
예제 #21
0
  @Override
  public List<Pedido> listPedidos(String username) {

    session = sessionFactory.openSession();
    Usuario usuario = (Usuario) session.get(Usuario.class, username);
    List<Pedido> p =
        session
            .createCriteria(Pedido.class)
            .add(Restrictions.eq("usuario", usuario))
            .add(Restrictions.eq("confirmado", true))
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .addOrder(Order.desc("idpedido"))
            .list();
    session.close();

    return p;
  }
예제 #22
0
  public List<User> getUserDataByPiority(String piority) {
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.eq("piority", piority));
    List<User> users = (List<User>) criteria.list();

    closeSession();
    return users;
  }
예제 #23
0
 @SuppressWarnings("unchecked")
 public List<T> findAllByIdInList(List<Integer> ids) {
   if (ids != null && ids.size() > 0) {
     return findByCriteria(Restrictions.in("id", ids));
   } else {
     return new ArrayList<T>();
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public List<Lancamento> listar(Conta conta, Date dataInicio, Date dataFim) {
    Criteria criteria = this.session.createCriteria(Lancamento.class);

    if (dataInicio != null && dataFim != null) {
      criteria.add(Restrictions.between("data", dataInicio, dataFim));
    } else if (dataInicio != null) {
      criteria.add(Restrictions.ge("data", dataInicio));
    } else if (dataFim != null) {
      criteria.add(Restrictions.le("data", dataFim));
    }

    criteria.add(Restrictions.eq("conta", conta));
    criteria.addOrder(Order.asc("data"));
    return criteria.list();
  }
예제 #25
0
  /**
   * Returns true if a persisted record exsits for the given id.
   *
   * @param id primary key of entity
   * @return true if entity exists for id, false if entity does not exist
   */
  public boolean isIdPersisted(Serializable id) {
    Criteria criteria =
        getSession()
            .createCriteria(getPersistentClass())
            .add(Restrictions.idEq(id))
            .setProjection(Projections.rowCount());

    return (criteria.uniqueResult() != null && ((Long) criteria.uniqueResult()) > 0);
  }
예제 #26
0
 public User getUserById(Integer userId) {
   Criteria criteria = getSession().createCriteria(User.class);
   criteria.add(Restrictions.eq("userId", userId));
   List<User> list = criteria.list();
   closeSession();
   if (!list.isEmpty()) {
     return list.get(0);
   } else return null;
 }
예제 #27
0
  @Override
  public void restaProductosCarrito(String username, int idproducto) {

    session = sessionFactory.openSession();
    Transaction transaction = null;
    try {

      transaction = session.beginTransaction();

      Producto producto = (Producto) session.get(Producto.class, idproducto);
      Pedido p = getPedidoCarritoSinSession(username);

      if (p != null) {

        List<LineaPedido> lp =
            session
                .createCriteria(LineaPedido.class)
                .add(Restrictions.eq("pedido", p))
                .add(Restrictions.eq("producto", producto))
                .list();

        if (lp.size() != 0) {
          // si hay mas de una unidad del producto se resta una unidad a la cantidad de producto
          if (lp.get(0).getCantidad() > 1) {
            lp.get(0).setCantidad(lp.get(0).getCantidad() - 1);
            session.save(lp.get(0));
            producto.setCantidad(producto.getCantidad() + 1);
            session.save(producto);
            transaction.commit();
            session.close();
          } else {
            transaction.commit();
            session.close();
            borrarProductosCarrito(username, idproducto);
          }
        }
      }

    } catch (HibernateException e) {
      transaction.rollback();
      e.printStackTrace();
    }
  }
예제 #28
0
  public List<BlacklistDTO> findByEntity(Integer entityId) {
    // I need to access an association, so I can't use the parent helper class
    Criteria criteria =
        getSession()
            .createCriteria(BlacklistDTO.class)
            .createAlias("company", "c")
            .add(Restrictions.eq("c.id", entityId));

    return criteria.list();
  }
예제 #29
0
 public Teacher findByFullName(String name, String firstName) {
   Criteria criteria;
   Transaction tx;
   Teacher teacher;
   Session session = ProductionSessionFactory.getDefault().getCurrentSession();
   tx = session.beginTransaction();
   try {
     criteria =
         session
             .createCriteria(persistentClass)
             .add(
                 Restrictions.and(
                     Restrictions.eq("name", name), Restrictions.eq("vorname", firstName)));
     teacher = (Teacher) criteria.uniqueResult();
   } finally {
     tx.commit();
   }
   return teacher;
 }
예제 #30
0
  public static Integer findPiority(String pior, Integer status) {
    Integer sizePioruty = 0;
    StringBuffer piorityBuffer = new StringBuffer();
    Criteria criteria = getSession().createCriteria(User.class);
    criteria.add(Restrictions.like("piority", pior + "%"));
    criteria.add(Restrictions.eq("status", status));
    criteria.add(new LengthExpression("piority", pior.length() + 3));
    criteria.addOrder(Order.asc("piority"));
    List<User> list = (List<User>) criteria.list();
    sizePioruty = list.size();

    if ((list.size() > 0 && status == 3) || (status == 2 && list.size() > 0)) {
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 3)
              + "");
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 2)
              + "");
      piorityBuffer.append(
          list.get(list.size() - 1)
                  .getPiority()
                  .charAt(list.get(list.size() - 1).getPiority().length() - 1)
              + "");
      sizePioruty = Integer.parseInt(piorityBuffer.toString()) + 1;
    }
    if (list.size() <= 0 && status == 2) {
      sizePioruty++;
    }
    if (list.size() <= 0 && status == 3) {

      sizePioruty++;
    }
    return sizePioruty;
  }