@Override
  public List<Visiting> getVisitngsToBeCreatedForAnotherThreeMonths() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -3);
    Date date = calendar.getTime();
    System.out.println("BEFORE THREE MONTHS :" + date);

    String queryString =
        "SELECT visiting_id as visiting_id"
            + " FROM visiting"
            + " WHERE start_date IN (SELECT Max(start_date)"
            + " FROM visiting"
            + " WHERE visiting_status='ACTIVE'"
            + " GROUP BY avg_time_per_appointment, created_user, no_of_patients, hospital_doctor_id, day_of_week)";

    SQLQuery sqlQuery = sessionFactory.getCurrentSession().createSQLQuery(queryString);
    sqlQuery.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List<Map> result = sqlQuery.list();
    List<String> results = new ArrayList<String>();
    for (Map map : result) {
      results.add((String) map.get("visiting_id"));
    }

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Visiting.class);
    criteria.add(
        Restrictions.conjunction()
            .add(Restrictions.in("visitingId", results))
            .add(Restrictions.le("startDate", date)));

    return criteria.list();
  }
Example #2
0
  /**
   * Perform a search over all child and sub orgs within the given organisation
   *
   * <p>If a search query is given it will be split by space and the key words searched in the
   * title, orgid, address, addressLine2 and postcode fields.
   *
   * @param q - search query, which is a space seperated list of key words. Optional
   * @param organisation - search is for orgs inside this
   * @param orgType - optional, if given results are limited to organisations of this type
   * @param session
   * @return
   */
  public static List<Organisation> search(
      String q, Organisation organisation, OrgType orgType, Session session) {
    Criteria crit = session.createCriteria(Organisation.class);
    crit.setCacheable(true);
    Disjunction notDeleted = Restrictions.disjunction();
    notDeleted.add(Restrictions.isNull("deleted"));
    notDeleted.add(Restrictions.eq("deleted", Boolean.FALSE));
    crit.add(notDeleted);

    if (q != null) {
      String[] arr = q.split(" ");
      Conjunction con = Restrictions.conjunction();
      for (String queryPart : arr) {
        Disjunction dis = Restrictions.disjunction();
        String s = "%" + queryPart + "%";
        dis.add(Restrictions.ilike("title", s));
        dis.add(Restrictions.ilike("orgId", s));
        dis.add(Restrictions.ilike("address", s));
        dis.add(Restrictions.ilike("addressLine2", s));
        dis.add(Restrictions.ilike("postcode", s));
        con.add(dis);
      }
      crit.add(con);
    }

    if (orgType != null) {
      crit.add(Restrictions.eq("orgType", orgType));
    }
    // TODO: add other properties like address
    Criteria critParentLink = crit.createCriteria("parentOrgLinks");
    critParentLink.add(Restrictions.eq("owner", organisation));
    crit.addOrder(Order.asc("title"));
    return DbUtils.toList(crit, Organisation.class);
  }
  @Override
  public List<PurchaseOrderDetail> findAllByPurchaseOrderId(Long purchaseOrderId) {
    final Junction conjunction = Restrictions.conjunction();
    conjunction.add(Restrictions.eq("isValid", Boolean.TRUE));
    conjunction.add(Restrictions.eq("purchaseOrder.id", purchaseOrderId));

    return findAllByCriterionList(null, null, null, null, conjunction);
  }
  @Override
  public ObjectList<PurchaseOrderDetail> findAllWithPaging(
      int pageNumber, int resultsPerPage, long purchaseOrderId) {
    final Junction conjunction = Restrictions.conjunction();
    conjunction.add(Restrictions.eq("isValid", Boolean.TRUE));
    conjunction.add(Restrictions.eq("purchaseOrder.id", purchaseOrderId));

    return findAllByCriterion(pageNumber, resultsPerPage, null, null, null, null, conjunction);
  }
 @Override
 @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
 public List<VisitingSolts> getAllActiveVisitingSlotsExpired() throws Exception {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(VisitingSolts.class);
   criteria.add(
       Restrictions.conjunction()
           .add(Restrictions.lt("endTime", Calendar.getInstance().getTime()))
           .add(Restrictions.lt("activeStatus", ActiveStatus.ACTIVE)));
   return criteria.list();
 }
  public List<DmAccount> getListOwnerByPermittedAccount(
      String accountId, Integer permissionLevelStart) {
    DmAccount permittedAccount = null;
    if (accountId != null) {
      permittedAccount = new DmAccount();
      permittedAccount.setId(accountId);
    }

    List<DmAccount> ownerList = null;
    if (permittedAccount != null) {
      Criteria crit = getSession().createCriteria(DmFolder.class);
      crit.setProjection(Projections.distinct(Projections.property("owner")));
      crit.add(Restrictions.ne("owner", permittedAccount));
      //            crit.setProjection(Projections.property("owner"));

      //            crit.add(Restrictions.eq("owner", accountOwner));
      //            crit.add(Restrictions.isNull("parent"));
      //            crit.addOrder(Order.asc("name"));
      //            if (permissionLevelStart != null) {
      //                crit.createCriteria("permissionList").add(Restrictions.ge("permissionType",
      // permissionLevelStart));
      //            }
      //            Criterion permissionCrit = null;

      Conjunction conjunction = Restrictions.conjunction();
      if (permissionLevelStart != null) {
        conjunction.add(Restrictions.ge("permissionType", permissionLevelStart));
      }
      conjunction.add(Restrictions.eq("account", permittedAccount));

      crit.createCriteria("permissionList").add(conjunction);

      ownerList = crit.list();

      //            if (ownerList != null) {
      //                for (DmAccount owner : ownerList) {
      //                    System.out.println("name = " + owner.getName());
      //                }
      //            }
      // start - get children for each child (trigger lazy fetch)
      //            for (DmFolder folderTmp : folderList) {
      //                if (folderTmp.getChildList() != null) {
      //                    folderTmp.getChildList().size();
      //                }
      //            }
      // end - get children for each child (trigger lazy fetch)
    }

    return ownerList;
    //        return null;
  }
Example #7
0
  protected Criterion getByExampleCriterion(T entity, SearchTemplate searchTemplate) {
    Criterion example = HibernateUtil.constructExample(entity, searchTemplate);
    List<Criterion> extras = getByExampleExtraCriterions(entity, searchTemplate);

    if (extras != null && extras.size() > 0) {
      Junction conjunction = Restrictions.conjunction();
      for (Criterion extra : extras) {
        conjunction.add(extra);
      }
      conjunction.add(example);
      return conjunction;
    } else {
      return example;
    }
  }
Example #8
0
  /**
   * 解析一个条件成为符合Hibernate的Junction的实例条件
   *
   * @param condition
   * @param junction
   */
  public static void parseConditionToJunction(
      Condition condition, Junction junction, Class<?> persistentClass) {
    // 子条件
    List<Condition> subConditions = condition.getSubConditions();

    // 有子条件则进行遍历获取最终的条件
    if (null != subConditions && !subConditions.isEmpty()) {
      // 子条件当中的and条件集合
      List<Condition> andConditions = condition.getAndConditions();
      if (null != andConditions && !andConditions.isEmpty()) {
        // 创建一个and条件集合
        Conjunction conj = Restrictions.conjunction();
        // 添加到父条件中
        junction.add(conj);
        for (Condition andCondition : andConditions) {
          /*
           * 把每个条件看做是一个大的条件(包含 and 和 or 2个部分),
           * 然后使用disjunction连接条件集合来组合这个大条件的(and项 和 or项);
           * 因为and项和or项都已经被分为2个部分
           * ,而且又是用disjunction来组合,所以可以保证一个大条件只会被or连接符分隔成2个部分
           */
          Disjunction dj = Restrictions.disjunction();
          conj.add(dj);
          parseConditionToJunction(andCondition, dj, persistentClass);
        }
      }

      // 子条件当中的or条件集合
      List<Condition> orConditions = condition.getOrConditions();
      if (null != orConditions && !orConditions.isEmpty()) {
        // 创建一个or条件集合
        Disjunction disj = Restrictions.disjunction();
        // 添加到父条件中
        junction.add(disj);
        for (Condition orCondition : orConditions) {
          // 这里的实现原理与上面的andCondition的处理相同
          Disjunction dj = Restrictions.disjunction();
          disj.add(dj);
          parseConditionToJunction(orCondition, dj, persistentClass);
        }
      }
    } else {
      // 条件为最终条件,转换为符合Hibernate的条件,然后条件到条件集合中
      junction.add(condition.getCriterion(persistentClass));
    }
  }
  @Override
  public void markMissingInstancesUnhealthy(
      final AutoScalingGroupMetadata group, final Collection<String> instanceIds)
      throws AutoScalingMetadataException {
    final AutoScalingInstance example = exampleForGroup(group);
    example.setHealthStatus(HealthStatus.Healthy);

    final List<AutoScalingInstance> instancesToMark =
        persistenceSupport.listByExample(
            example,
            LifecycleState.InService,
            instanceIds.isEmpty()
                ? Restrictions.conjunction()
                : Restrictions.not(Property.forName("displayName").in(instanceIds)),
            Collections.<String, String>emptyMap(),
            Functions.<AutoScalingInstance>identity());

    for (final AutoScalingInstance instance : instancesToMark) {
      try {
        persistenceSupport.updateByExample(
            AutoScalingInstance.withUuid(instance.getNaturalId()),
            group.getOwner(),
            instance.getInstanceId(),
            new Callback<AutoScalingInstance>() {
              @Override
              public void fire(final AutoScalingInstance instance) {
                if (instance.healthStatusGracePeriodExpired()) {
                  logger.info("Marking instance unhealthy: " + instance.getInstanceId());
                  instance.setHealthStatus(HealthStatus.Unhealthy);
                } else {
                  logger.debug(
                      "Instance not healthy but within grace period: " + instance.getInstanceId());
                }
              }
            });
      } catch (final AutoScalingMetadataNotFoundException e) {
        // removed, no need to mark unhealthy
      }
    }
  }
  @Override
  public void botaoBuscarActionPerformed(ActionEvent evt) {
    try {
      String busca = getCampoBusca().getText();

      Disjunction or = Restrictions.disjunction();
      or.add(Restrictions.ilike("nome", busca, MatchMode.ANYWHERE));
      // or.add(Restrictions.ilike("ativo", busca, MatchMode.ANYWHERE));

      try {
        or.add(Restrictions.eq("id", Integer.parseInt(busca)));
      } catch (Exception err) {
      }

      List<Object> grupos =
          ProfissionalDAO.getInstance()
              .findByCriteria(new Profissional(), Restrictions.conjunction(), or);
      this.atualizarGrid(-1, grupos);
    } catch (Exception err) {
      SOptionPane.showMessageDialog(this, err, "Erro!", JOptionPane.ERROR_MESSAGE);
    }
  }
Example #11
0
 /**
  * Count the matching entities for the given example.
  *
  * @param example The example entity
  * @return The number of matching entities
  */
 public static long count(final Object example) {
   return count(example, Restrictions.conjunction(), Collections.<String, String>emptyMap());
 }
Example #12
0
 @Override
 public Criterion getEqualityCriteria() {
   return Restrictions.conjunction()
       .add(DaoBase.associationEq("massSpecSample", getMassSpecSample()))
       .add(DaoBase.associationEq("proteinGroups", getProteinGroups()));
 }
Example #13
0
  public List<DmFolder> getSharedFirstLevelList(String accountSharedId, String accountOwnerId) {
    DmAccount permittedAccount = null;
    if (accountSharedId != null) {
      permittedAccount = new DmAccount();
      permittedAccount.setId(accountSharedId);
    }

    DmAccount ownerAccount = null;
    if (accountOwnerId != null) {
      ownerAccount = new DmAccount();
      ownerAccount.setId(accountOwnerId);
    }

    List<DmFolder> folderList = null;
    if (permittedAccount != null) {
      Criteria crit = getSession().createCriteria(DmFolderPermission.class);
      crit.setProjection(Projections.property("folder"));

      Conjunction conjunction = Restrictions.conjunction();
      //            conjunction.add(Restrictions.ge("permissionType",
      // ApplicationConstants.FOLDER_PERMISSION_MANAGER));
      conjunction.add(Restrictions.eq("account", permittedAccount));
      conjunction.add(Restrictions.ne("account", ownerAccount));
      crit.add(conjunction);

      crit.createAlias("folder", "folderShared", CriteriaSpecification.LEFT_JOIN);
      crit.add(Restrictions.eq("folderShared.owner", ownerAccount));

      crit.createAlias("folderShared.parent", "parentFolder", CriteriaSpecification.LEFT_JOIN);
      //            crit.createAlias("parentFolder.permissionList", "parentPermission");
      crit.createAlias(
          "parentFolder.permissionList", "parentPermission", CriteriaSpecification.LEFT_JOIN);

      //            DetachedCriteria subquery = DetachedCriteria.forClass(DmFolder.class,
      // "last_pos");
      DetachedCriteria subquery = DetachedCriteria.forClass(DmFolderPermission.class);
      subquery.setProjection(Projections.property("folder"));
      subquery.add(conjunction);

      Disjunction disjunction = Restrictions.disjunction();
      disjunction.add(Restrictions.isNull("folderShared.parent"));
      //            disjunction.add(Restrictions.isNull("parentFolder.permissionList"));
      //            disjunction.add(Restrictions.isNull("parentPermission.id"));
      //            disjunction.add(conjunction2);
      disjunction.add(Subqueries.propertyNotIn("folderShared.parent", subquery));

      //            crit.add(Subqueries.propertyNotIn("folderShared.parent", subquery));

      //            Conjunction conjunction2 = Restrictions.conjunction();
      //            conjunction2.add(Restrictions.eq("parentPermission.permissionType",
      // ApplicationConstants.FOLDER_PERMISSION_MANAGER));
      //            conjunction2.add(Restrictions.eq("parentPermission.account", permittedAccount));
      //
      //            Conjunction conjunction3 = Restrictions.conjunction();
      //            conjunction3.add(Restrictions.eq("parentPermission.permissionType",
      // ApplicationConstants.FOLDER_PERMISSION_MANAGER));
      //            conjunction3.add(Restrictions.eq("parentPermission.account", permittedAccount));

      //            disjunction.add(conjunction3);
      //            disjunction.add(Restrictions.ne("parentPermission.account", permittedAccount));
      //            disjunction.add(Restrictions.eq("parentPermission.permissionType",
      // ApplicationConstants.FOLDER_PERMISSION_MANAGER));

      //            disjunction.add(Restrictions.isNull("parentFolder.permissionList"));

      //            disjunction.add(Restrictions.eq("parentPermission.permissionType",
      // ApplicationConstants.FOLDER_PERMISSION_MANAGER));
      //            disjunction.add(Restrictions.ne("parentPermission.account", permittedAccount));

      crit.add(disjunction);

      folderList = crit.list();

      // start - get children for each child (trigger lazy fetch)
      for (DmFolder folderTmp : folderList) {
        if (folderTmp.getChildList() != null) {
          folderTmp.getChildList().size();
        }
      }
      // end - get children for each child (trigger lazy fetch)
    }

    return folderList;
  }
  protected Criteria buildTaskInstanceExtensionSearchCriteria(
      String taskName,
      String assetType,
      Long[] assetPrimaryKeys,
      Date dueDateGT,
      Date dueDateLT,
      Boolean completed,
      Boolean searchByUserRoles,
      boolean andOperator,
      ServiceContext serviceContext)
      throws SystemException {

    Criteria criteria = _session.createCriteria(TaskInstanceExtensionImpl.class);

    criteria.createAlias("taskInstance", "taskInstance");

    criteria.add(Restrictions.eq("companyId", serviceContext.getCompanyId()));

    if (Validator.isNotNull(taskName)
        || Validator.isNotNull(assetType)
        || (dueDateGT != null)
        || (dueDateLT != null)) {

      Junction junction = null;

      if (andOperator) {
        junction = Restrictions.conjunction();
      } else {
        junction = Restrictions.disjunction();
      }

      if (Validator.isNotNull(taskName)) {
        String[] taskNameKeywords = StringUtil.split(taskName, StringPool.SPACE);

        for (String taskNameKeyword : taskNameKeywords) {
          junction.add(Restrictions.like("taskInstance.name", "%" + taskNameKeyword + "%"));
        }
      }

      if (Validator.isNotNull(assetType)) {
        String[] assetTypeKeywords = StringUtil.split(assetType, StringPool.SPACE);

        for (String assetTypeKeyword : assetTypeKeywords) {
          junction.add(
              Restrictions.like(
                  "workflowContext", "%\"entryType\":\"%" + assetTypeKeyword + "%\"%"));
        }
      }

      if (Validator.isNotNull(assetPrimaryKeys)) {
        for (Long assetPrimaryKey : assetPrimaryKeys) {
          junction.add(
              Restrictions.like(
                  "workflowContext", "%\"entryClassPK\":\"%" + assetPrimaryKey + "%\"%"));
        }
      }

      if (dueDateGT != null) {
        junction.add(Restrictions.ge("taskInstance.dueDate", dueDateGT));
      }

      if (dueDateLT != null) {
        junction.add(Restrictions.lt("taskInstance.dueDate", dueDateGT));
      }

      criteria.add(junction);
    }

    addSearchByUserRolesCriterion(criteria, searchByUserRoles, serviceContext);

    if (completed != null) {
      if (completed.booleanValue()) {
        criteria.add(Restrictions.isNotNull("taskInstance.end"));
      } else {
        criteria.add(Restrictions.isNull("taskInstance.end"));
      }
    }

    return criteria;
  }