/** Returns the list of enterprises that can't be co-located with an enterprise. */
  @Override
  public List<EnterpriseHB> findExcludedEnterprises(final EnterpriseHB enterprise) {
    assert enterprise != null;

    /*
     * Find all rules of which the enterprise is part first.
     */
    final List<EnterpriseExclusionRuleHB> rules =
        SessionUtils.list(
            getSession(),
            EnterpriseExclusionRuleHB.class,
            "SELECT obj FROM EnterpriseExclusionRuleHB obj "
                + "WHERE "
                + "  obj.enterprise1 = ? OR "
                + "  obj.enterprise2 = ?",
            enterprise,
            enterprise);
    final List<EnterpriseHB> result = new ArrayList<EnterpriseHB>();
    for (final EnterpriseExclusionRuleHB rule : rules) {
      // If the enterprise is enterprise1, then enterprise2 is the enterprise that can't be
      // co-located
      if (rule.getEnterprise1() == enterprise) {
        result.add(rule.getEnterprise2());
      }
      // ...else, then enterprise1 is the enterprise that can't be co-located
      else {
        result.add(rule.getEnterprise1());
      }
    }
    return result;
  }
Ejemplo n.º 2
0
 /**
  * This method transform the current EnterpriseExclusionRule pojo object to a
  * EnterpriseExclusionRule hibernate pojo object
  */
 public EnterpriseExclusionRuleHB toPojoHB() {
   EnterpriseExclusionRuleHB ruleHB = new EnterpriseExclusionRuleHB();
   ruleHB.setEnterprise1(enterprise1.toPojoHB());
   ruleHB.setEnterprise2(enterprise2.toPojoHB());
   return ruleHB;
 }