@SuppressWarnings("unchecked")
  private String actionQuery(
      EntityManager em,
      BundleJobBean bundleBean,
      Map<String, Timestamp> times,
      List<BulkResponseImpl> responseList)
      throws ParseException {
    Query q = em.createNamedQuery("BULK_MONITOR_ACTIONS_QUERY");
    StringBuilder getActions = new StringBuilder(q.toString());
    StringBuilder conditionClause = new StringBuilder();
    conditionClause.append(
        coordNamesClause(bulkFilter.get(BulkResponseImpl.BULK_FILTER_COORD_NAME)));
    conditionClause.append(statusClause(bulkFilter.get(BulkResponseImpl.BULK_FILTER_STATUS)));
    int offset = getActions.indexOf("ORDER");
    getActions.insert(offset - 1, conditionClause);
    timesClause(getActions, offset, times);
    q = em.createQuery(getActions.toString());
    Iterator<Entry<String, Timestamp>> iter = times.entrySet().iterator();
    while (iter.hasNext()) {
      Entry<String, Timestamp> time = iter.next();
      q.setParameter(time.getKey(), time.getValue());
    }
    q.setParameter("bundleId", bundleBean.getId());
    // pagination
    q.setFirstResult(start - 1);
    q.setMaxResults(len);

    List<Object[]> response = q.getResultList();
    for (Object[] r : response) {
      BulkResponseImpl br = getResponseFromObject(bundleBean, r);
      responseList.add(br);
    }
    return q.toString();
  }
  @SuppressWarnings("unchecked")
  @Override
  public List<FiseFormato12CC> buscarFormato12CC(
      String codEmpresa,
      long anioDesde,
      long mesDesde,
      long anioHasta,
      long mesHasta,
      String etapa) {
    List<FiseFormato12CC> lista = null;
    try {
      String q = "SELECT t FROM FiseFormato12CC t WHERE 1=1 ";
      if (FormatoUtil.isNotBlank(codEmpresa)) {
        q = q + " AND t.id.codEmpresa = :codEmpresa ";
      }
      q = q + " AND t.id.anoPresentacion*100+t.id.mesPresentacion >= :fechaDesde ";
      q = q + " AND t.id.anoPresentacion*100+t.id.mesPresentacion <= :fechaHasta ";
      if (FormatoUtil.isNotBlank(etapa)) {
        q = q + " AND t.id.etapa = :etapa ";
      }
      Query query = em.createQuery(q);
      if (FormatoUtil.isNotBlank(codEmpresa)) {
        query.setParameter("codEmpresa", codEmpresa);
      }
      long fechaDesde = 0;
      if (anioDesde != 0) {
        fechaDesde = anioDesde * 100;
      }
      if (mesDesde != 0) {
        fechaDesde = fechaDesde + mesDesde;
      }
      long fechaHasta = 0;
      if (anioHasta != 0) {
        fechaHasta = anioHasta * 100;
      }
      if (mesHasta != 0) {
        fechaHasta = fechaHasta + mesHasta;
      }
      query.setParameter("fechaDesde", fechaDesde);
      query.setParameter("fechaHasta", fechaHasta);
      if (FormatoUtil.isNotBlank(etapa)) {
        query.setParameter("etapa", etapa);
      }

      lista = query.getResultList();
      System.out.println("SQL   > " + query.toString());

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      em.close();
    }
    return lista;
  }
 public Category getByid(Long id) {
   Category categoryResult = new Category();
   Query q = em.createQuery("SELECT c FROM Category c WHERE c.id=:id");
   q.setParameter("id", id);
   String query1 = q.toString();
   ArrayList<Category> results = new ArrayList<Category>(q.getResultList());
   if (results.isEmpty() == true) {
     return null;
   }
   categoryResult = results.get(0);
   return categoryResult;
 }
  @Override
  public List<Estudiante> buscarPorApellido(String apellido) {

    EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.getTransaction().begin();
    Query query =
        entityManager.createQuery(
            "Select u from Estudiante u where u.persona.apellido = '" + apellido + "'");
    System.out.println(query.toString());
    List list = query.getResultList();
    entityManager.getTransaction().commit();
    entityManager.close();
    return list;
  }
 @SuppressWarnings("unchecked")
 @Override
 public List<FiseTipDocRef> listarFiseTipDocRef() {
   List<FiseTipDocRef> lst = null;
   try {
     StringBuffer jql = new StringBuffer();
     jql.append(" SELECT f FROM FiseTipDocRef f ");
     Query query = em.createQuery(jql.toString());
     System.out.println(query.toString());
     lst = query.getResultList();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return lst;
 }
 private long countQuery(
     String clause, EntityManager em, BundleJobBean bundleBean, Map<String, Timestamp> times) {
   Query q = em.createNamedQuery("BULK_MONITOR_COUNT_QUERY");
   StringBuilder getTotal = new StringBuilder(q.toString() + " ");
   getTotal.append(clause.substring(clause.indexOf("WHERE"), clause.indexOf("ORDER")));
   q = em.createQuery(getTotal.toString());
   q.setParameter("bundleId", bundleBean.getId());
   Iterator<Entry<String, Timestamp>> iter = times.entrySet().iterator();
   while (iter.hasNext()) {
     Entry<String, Timestamp> time = iter.next();
     q.setParameter(time.getKey(), time.getValue());
   }
   long total = ((Long) q.getSingleResult()).longValue();
   return total;
 }