Exemple #1
0
 @SuppressWarnings({"unchecked"})
 private List<Site> getByIds(Collection<Integer> ids) {
   if (ids == null) {
     return getAll();
   } else if (ids.isEmpty()) {
     return Collections.emptyList();
   } else {
     return getHibernateTemplate()
         .findByCriteria(
             criteria()
                 .add(MoreRestrictions.in("id", ids))
                 .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY));
   }
 }
Exemple #2
0
 /**
  * Returns the IDs for all the sites visible according to the given parameters. If the parameters
  * indicate that all sites should be visible, it may return null.
  */
 @SuppressWarnings({"unchecked"})
 public Collection<Integer> getVisibleSiteIds(VisibleSiteParameters parameters) {
   if (parameters.isAllManagingSites() || parameters.isAllParticipatingSites()) {
     return null; // shortcut for all
   } else {
     Set<String> idents = new HashSet<String>();
     idents.addAll(parameters.getParticipatingSiteIdentifiers());
     idents.addAll(parameters.getManagingSiteIdentifiers());
     if (idents.isEmpty()) {
       return Collections.emptySet();
     } else {
       return getHibernateTemplate()
           .findByCriteria(
               criteria()
                   .add(MoreRestrictions.in("assignedIdentifier", idents))
                   .setProjection(Projections.id()));
     }
   }
 }
Exemple #3
0
  @SuppressWarnings({"unchecked"})
  public List<Site> getByAssignedIdentifiers(List<String> assignedIdentifiers) {
    if (assignedIdentifiers.isEmpty()) {
      return Collections.emptyList();
    }
    List fromDatabase =
        getHibernateTemplate()
            .findByCriteria(
                criteria().add(MoreRestrictions.in("assignedIdentifier", assignedIdentifiers)));

    List<Site> inOrder = new ArrayList<Site>();
    for (String assignedIdentifier : assignedIdentifiers) {
      for (Iterator<Site> foundIt = fromDatabase.iterator(); foundIt.hasNext(); ) {
        Site found = foundIt.next();
        if (found.getAssignedIdentifier().equals(assignedIdentifier)) {
          inOrder.add(found);
          foundIt.remove();
          break;
        }
      }
    }
    return inOrder;
  }