Example usage for org.hibernate.criterion Restrictions disjunction

List of usage examples for org.hibernate.criterion Restrictions disjunction

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions disjunction.

Prototype

public static Disjunction disjunction() 

Source Link

Document

Group expressions together in a single disjunction (A or B or C...).

Usage

From source file:edu.monash.merc.dao.TrafficLightDAO.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w w. j a  v  a  2  s  .c  om*/
 */
public TrafficLight getTLByChromEnsemblAcVersionToken(ChromType chromType, String ensgAc, long versionId,
        int trackToken) {
    Criteria qCriteria = this.session().createCriteria(this.persistClass);

    Criteria tlGeneCriteria = qCriteria.createCriteria("tlGene");
    tlGeneCriteria.add(Restrictions.eq("chromosome", chromType.chm()));

    Disjunction orConds = Restrictions.disjunction();
    orConds.add(Restrictions.eq("ensgAccession", ensgAc));
    tlGeneCriteria.add(orConds);
    Criteria tpbVCriteria = qCriteria.createCriteria("tpbVersion");
    tpbVCriteria.add(Restrictions.eq("id", versionId));
    tpbVCriteria.add(Restrictions.eq("trackToken", trackToken));
    return (TrafficLight) qCriteria.uniqueResult();
}

From source file:edu.monash.merc.dao.TrafficLightDAO.java

License:Open Source License

private void addSpecificTPBTypeColorLevelConditions(Criteria criteria, String dataType,
        List<Integer> colorLevels) {
    //convert the dataType into DataType
    DataType tpbDataType = DataType.fromType(dataType);
    //PE//from   w w w .  j a  va  2  s.co  m
    if (DataType.PE.equals(tpbDataType)) {
        Criteria peColorCriteria = criteria.createCriteria("tlPEColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            peColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE MS
    if (DataType.PE_MS.equals(tpbDataType)) {
        Criteria peMsColorCriteria = criteria.createCriteria("tlPEMSColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peMsColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peMsColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE MS Ann
    if (DataType.PE_MS_ANN.equals(tpbDataType)) {
        Criteria peMsAnnColorCriteria = criteria.createCriteria("tlPEMSANNColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peMsAnnColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peMsAnnColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE MS Prob
    if (DataType.PE_MS_PROB.equals(tpbDataType)) {
        Criteria peMsProbColorCriteria = criteria.createCriteria("tlPEMSPROBColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peMsProbColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peMsProbColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE MS Sam
    if (DataType.PE_MS_SAM.equals(tpbDataType)) {
        Criteria peMsSamColorCriteria = criteria.createCriteria("tlPEMSSAMColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peMsSamColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peMsSamColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE ANTI
    if (DataType.PE_ANTI.equals(tpbDataType)) {
        Criteria peAntiColorCriteria = criteria.createCriteria("tlPEANTIColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peAntiColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peAntiColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE ANTI ANN
    if (DataType.PE_ANTI_ANN.equals(tpbDataType)) {
        Criteria peAntiAnnColorCriteria = criteria.createCriteria("tlPEANTIANNColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peAntiAnnColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peAntiAnnColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE ANTI IHC
    if (DataType.PE_ANTI_IHC.equals(tpbDataType)) {
        Criteria peAntiIhcColorCriteria = criteria.createCriteria("tlPEANTIIHCColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peAntiIhcColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peAntiIhcColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE ANTI IHC Norm
    if (DataType.PE_ANTI_IHC_NORM.equals(tpbDataType)) {
        Criteria peAntiIhcNormColorCriteria = criteria.createCriteria("tlPEANTIIHCNORMColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peAntiIhcNormColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peAntiIhcNormColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE OTH
    if (DataType.PE_OTH.equals(tpbDataType)) {
        Criteria peOthColorCriteria = criteria.createCriteria("tlPEOTHColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peOthColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peOthColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PE OTH Cur
    if (DataType.PE_OTH_CUR.equals(tpbDataType)) {
        Criteria peOthCurColorCriteria = criteria.createCriteria("tlPEOTHCURColor");
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            peOthCurColorCriteria.add(colorLevelOr);
        }
        if (colorLevels != null && colorLevels.size() == 1) {
            peOthCurColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM
    if (DataType.PTM.equals(tpbDataType)) {
        Criteria ptmColorCriteria = criteria.createCriteria("tlPTMColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM PHS
    if (DataType.PTM_PHS.equals(tpbDataType)) {
        Criteria ptmPhsColorCriteria = criteria.createCriteria("tlPTMPHSColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmPhsColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmPhsColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM PHS SER
    if (DataType.PTM_PHS_SER.equals(tpbDataType)) {
        Criteria ptmPhsSerColorCriteria = criteria.createCriteria("tlPTMPHSSERColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmPhsSerColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmPhsSerColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM PHS THR
    if (DataType.PTM_PHS_THR.equals(tpbDataType)) {
        Criteria ptmPhsThrColorCriteria = criteria.createCriteria("tlPTMPHSTHRColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmPhsThrColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmPhsThrColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM PHS TYR
    if (DataType.PTM_PHS_TYR.equals(tpbDataType)) {
        Criteria ptmPhsTyrColorCriteria = criteria.createCriteria("tlPTMPHSTYRColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmPhsTyrColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmPhsTyrColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM ACE
    if (DataType.PTM_ACE.equals(tpbDataType)) {
        Criteria ptmAceColorCriteria = criteria.createCriteria("tlPTMACEColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmAceColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmAceColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM ACE LYS
    if (DataType.PTM_ACE_LYS.equals(tpbDataType)) {
        Criteria ptmAceLysColorCriteria = criteria.createCriteria("tlPTMACELYSColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmAceLysColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmAceLysColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //PTM ACE NTA
    if (DataType.PTM_ACE_NTA.equals(tpbDataType)) {
        Criteria ptmAceNtaColorCriteria = criteria.createCriteria("tlPTMACENTAColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            ptmAceNtaColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            ptmAceNtaColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //TE
    if (DataType.TE.equals(tpbDataType)) {
        Criteria teColorCriteria = criteria.createCriteria("tlTEColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            teColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            teColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //TE MA
    if (DataType.TE_MA.equals(tpbDataType)) {
        Criteria teMaColorCriteria = criteria.createCriteria("tlTEMAColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            teMaColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            teMaColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //TE MA PROP
    if (DataType.TE_MA_PROP.equals(tpbDataType)) {
        Criteria teMaPropColorCriteria = criteria.createCriteria("tlTEMAPROPColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            teMaPropColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            teMaPropColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //TE OTH
    if (DataType.TE_OTH.equals(tpbDataType)) {
        Criteria teOthColorCriteria = criteria.createCriteria("tlTEOTHColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            teOthColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            teOthColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

    //TE OTH CUR
    if (DataType.TE_OTH_CUR.equals(tpbDataType)) {
        Criteria teOthCurColorCriteria = criteria.createCriteria("tlTEOTHCURColor");
        //color level size is great than one. we use or condition
        if (colorLevels != null && colorLevels.size() > 1) {
            Disjunction colorLevelOr = Restrictions.disjunction();
            for (Integer level : colorLevels) {
                colorLevelOr.add(Restrictions.eq("colorLevel", level.intValue()));
            }
            teOthCurColorCriteria.add(colorLevelOr);
        }
        //if only on color level, we just use eq condition
        if (colorLevels != null && colorLevels.size() == 1) {
            teOthCurColorCriteria.add(Restrictions.eq("colorLevel", colorLevels.get(0).intValue()));
        }
    }

}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.delta.AmendmentDao.java

License:BSD License

@SuppressWarnings({ "unchecked" })
public Amendment getByNaturalKey(String key, Study study) {
    final Amendment.Key keyParts = Amendment.decomposeNaturalKey(key);
    List<Amendment> results = getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            //need to have both "lt & ge" or "eq" criterias to work on Oracle and Postgres dbs for date with timestamp.
            Criteria crit = session.createCriteria(Amendment.class)
                    .add(Restrictions.disjunction()
                            .add(Restrictions.and(Restrictions.lt("date", keyParts.getDateNext()),
                                    Restrictions.ge("date", keyParts.getDate())))
                            .add(Restrictions.eq("date", keyParts.getDate())));
            if (keyParts.getName() != null)
                crit.add(Restrictions.eq("name", keyParts.getName()));
            crit.addOrder(Order.asc("name"));
            return crit.list();
        }//from w w  w  .jav a 2s .c  o m
    });
    // filter out amendments for other studies
    for (Iterator<Amendment> it = results.iterator(); it.hasNext();) {
        Amendment result = it.next();
        if (!study.hasAmendment(result))
            it.remove();
    }
    if (results.size() == 0) {
        return null;
    } else if (results.size() > 1) {
        // if there's one with this date and no name, it matches
        for (Amendment result : results)
            if (result.getName() == null)
                return result;

        List<String> resultKeys = new ArrayList<String>(results.size());
        for (Amendment result : results)
            resultKeys.add(result.getNaturalKey());
        throw new StudyCalendarValidationException(
                "More than one amendment could match %s: %s.  Please be more specific.", key,
                StringUtils.join(resultKeys.iterator(), ", "));
    } else {
        return results.get(0);
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.StudyDao.java

License:BSD License

@SuppressWarnings({ "unchecked" })
private Collection<Integer> searchForVisibleIds(VisibleStudyParameters parameters, String search,
        boolean includeManaging, boolean includeParticipating, boolean includeSpecific) {
    if (log.isDebugEnabled()) {
        log.debug("Searching visible studies for {} with {}", parameters,
                search == null ? "no term" : "term \"" + search + '"');
        if (!includeManaging)
            log.debug("- Excluding managing");
        if (!includeParticipating)
            log.debug("- Excluding participating");
        if (!includeSpecific)
            log.debug("- Excluding specific studies");
    }/*from  w  ww .  j a va2  s . c o m*/
    List<DetachedCriteria> separateCriteria = new LinkedList<DetachedCriteria>();
    if (parameters.isAllManagingSites() && includeManaging) {
        if (search == null) {
            return null; // shortcut for all
        } else {
            separateCriteria.add(criteria().add(searchRestriction(search)));
        }
    } else {
        // These are implemented as separate queries and then merged because
        // the criteria are too complex to reliably express in a single statement.

        if (includeSpecific && !parameters.getSpecificStudyIdentifiers().isEmpty()) {
            separateCriteria.add(criteria()
                    .add(MoreRestrictions.in("assignedIdentifier", parameters.getSpecificStudyIdentifiers())));
        }
        if (includeManaging && !parameters.getManagingSiteIdentifiers().isEmpty()) {
            separateCriteria.add(criteria().createAlias("managingSites", "ms", Criteria.LEFT_JOIN)
                    .add(Restrictions.disjunction()
                            .add(MoreRestrictions.in("ms.assignedIdentifier",
                                    parameters.getManagingSiteIdentifiers()))
                            .add(Restrictions.isNull("ms.assignedIdentifier")) // <- unmanaged studies
            ));
        }
        if (includeParticipating) {
            if (parameters.isAllParticipatingSites()) {
                separateCriteria
                        .add(criteria().createAlias("studySites", "ss").add(Restrictions.isNotNull("ss.id")));
            } else if (!parameters.getParticipatingSiteIdentifiers().isEmpty()) {
                separateCriteria.add(criteria().createAlias("studySites", "ss").createAlias("ss.site", "s")
                        .add(MoreRestrictions.in("s.assignedIdentifier",
                                parameters.getParticipatingSiteIdentifiers())));
            }
        }

        for (DetachedCriteria criteria : separateCriteria) {
            if (search != null) {
                criteria.add(searchRestriction(search));
            }
        }
    }

    Set<Integer> ids = new LinkedHashSet<Integer>();
    for (DetachedCriteria criteria : separateCriteria) {
        ids.addAll(getHibernateTemplate().findByCriteria(criteria.setProjection(Projections.id())));
    }
    log.debug("Found IDs {}", ids);
    return ids;
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.ActionDashboardTabMyPlans.java

License:Open Source License

private List<Criterion> _idInSet(Set<ActionPlan> set) {
    List<Criterion> lis = new ArrayList<Criterion>(1);
    if (set.size() <= 0) {
        lis.add(Restrictions.eq("id", -1L)); // nothing matches, inefficient way to show nothing in table
    } else {/*from ww w  . j a  v  a 2 s .  c  om*/
        Disjunction disj = Restrictions.disjunction(); // remember, an empty disjunction ("or") finds everything
        for (ActionPlan ap : set) {
            disj.add(Restrictions.eq("id", ap.getId()));
        }
        lis.add(disj);
    }
    return lis;
}

From source file:edu.uiowa.icts.bluebutton.controller.ClinicalDocumentController.java

License:Apache License

@ResponseBody
@RequestMapping(value = "datatable", produces = "application/json")
public String datatable(HttpServletRequest request,
        @RequestParam(value = "personId", required = false) Integer personId,
        @RequestParam(value = "length", required = false) Integer limit,
        @RequestParam(value = "start", required = false) Integer start,
        @RequestParam(value = "draw", required = false) String draw,
        @RequestParam(value = "search[regex]", required = false, defaultValue = "false") Boolean searchRegularExpression,
        @RequestParam(value = "search[value]", required = false) String search,
        @RequestParam(value = "columnCount", required = false, defaultValue = "0") Integer columnCount,
        @RequestParam(value = "individualSearch", required = false, defaultValue = "false") Boolean individualSearch,
        @RequestParam(value = "display", required = false, defaultValue = "list") String display) {

    List<DataTableHeader> headers = new ArrayList<DataTableHeader>();
    for (int i = 0; i < columnCount; i++) {
        DataTableHeader dth = new DataTableHeader();
        dth.setData(Integer.valueOf(request.getParameter("columns[" + i + "][data]")));
        dth.setName(request.getParameter("columns[" + i + "][name]"));
        dth.setOrderable(Boolean.valueOf(request.getParameter("columns[" + i + "][orderable]")));
        dth.setSearchable(Boolean.valueOf(request.getParameter("columns[" + i + "][searchable]")));
        dth.setSearchValue(request.getParameter("columns[" + i + "][search][value]"));
        dth.setSearchRegex(Boolean.valueOf(request.getParameter("columns[" + i + "][search][regex]")));
        headers.add(dth);//  w  w w.  j  ava 2  s  . com
    }

    ArrayList<SortColumn> sorts = new ArrayList<SortColumn>();

    JSONObject ob = new JSONObject();

    try {

        for (int i = 0; i < columnCount; i++) {
            Integer columnIndex = null;
            String columnIndexString = request.getParameter("order[" + i + "][column]");
            if (columnIndexString != null) {
                try {
                    columnIndex = Integer.parseInt(columnIndexString);
                } catch (NumberFormatException e) {
                    continue;
                }
                if (columnIndex != null) {
                    if (StringUtils.equalsIgnoreCase("person", headers.get(columnIndex).getName())) {
                        sorts.add(new SortColumn("person.lastName",
                                request.getParameter("order[" + i + "][dir]")));
                        sorts.add(new SortColumn("person.firstName",
                                request.getParameter("order[" + i + "][dir]")));
                    } else {
                        sorts.add(new SortColumn(headers.get(columnIndex).getName(),
                                request.getParameter("order[" + i + "][dir]")));
                    }
                }
            }
        }

        GenericDaoListOptions options = new GenericDaoListOptions();

        List<Alias> aliases = new ArrayList<Alias>();
        aliases.add(new Alias("person", "person"));
        options.setAliases(aliases);

        Map<String, Object> individualEquals = new HashMap<String, Object>();
        if (personId != null) {
            individualEquals.put("person.personId", personId);
        }
        options.setIndividualEquals(individualEquals);

        if (!individualSearch) {
            ArrayList<String> searchColumns = new ArrayList<String>();
            for (int i = 0; i < columnCount; i++) {
                if (headers.get(i).getSearchable()) {
                    if (StringUtils.equalsIgnoreCase("person", headers.get(i).getName())) {
                        searchColumns.add("person.lastName");
                        searchColumns.add("person.firstName");
                    } else {
                        searchColumns.add(headers.get(i).getName());
                    }
                }
            }
            options.setSearch(search);
            options.setSearchColumns(searchColumns);
        } else {

            List<Junction> disjunctions = new ArrayList<Junction>();

            for (DataTableHeader header : headers) {
                if (header.getSearchable() && header.getSearchValue() != null
                        && !StringUtils.equals("", header.getSearchValue().trim())) {
                    for (String splitColumnValue : StringUtils.split(header.getSearchValue().trim(), ' ')) {
                        Disjunction disjunction = Restrictions.disjunction();
                        if (StringUtils.equalsIgnoreCase("person", header.getName())) {
                            disjunction
                                    .add(Restrictions.ilike("person.lastName", "%" + splitColumnValue + "%"));
                            disjunction
                                    .add(Restrictions.ilike("person.firstName", "%" + splitColumnValue + "%"));
                        } else {
                            disjunction.add(Restrictions.ilike(header.getName(), "%" + splitColumnValue + "%"));
                        }
                        disjunctions.add(disjunction);
                    }
                }
            }
            options.setJunctions(disjunctions);
        }

        Integer count = bluebuttonDaoService.getClinicalDocumentService().count(options);

        options.setLimit(limit);
        options.setStart(start);
        options.setSorts(sorts);

        List<ClinicalDocument> clinicalDocumentList = bluebuttonDaoService.getClinicalDocumentService()
                .list(options);

        ob.put("draw", draw);
        ob.put("recordsFiltered", count);
        ob.put("recordsTotal", count);
        JSONArray jsonArray = new JSONArray();
        for (ClinicalDocument clinicalDocument : clinicalDocumentList) {
            JSONArray tableRow = new JSONArray();
            for (DataTableHeader header : headers) {
                String headerName = header.getName();
                if (StringUtils.equals("clinicalDocumentId", headerName)) {
                    tableRow.put(clinicalDocument.getClinicalDocumentId());
                } else if (StringUtils.equals("document", headerName)) {
                    tableRow.put(clinicalDocument.getDocument());
                } else if (StringUtils.equals("name", headerName)) {
                    tableRow.put(clinicalDocument.getName());
                } else if (StringUtils.equals("source", headerName)) {
                    tableRow.put(clinicalDocument.getSource());
                } else if (StringUtils.equals("description", headerName)) {
                    tableRow.put(clinicalDocument.getDescription());
                } else if (StringUtils.equals("dateUploaded", headerName)) {
                    tableRow.put(clinicalDocument.getDateUploaded());
                } else if (StringUtils.equals("jsonParserVersion", headerName)) {
                    tableRow.put(clinicalDocument.getJsonParserVersion());
                } else if (StringUtils.equals("person", headerName)) {
                    String toPut = "";
                    if (clinicalDocument.getPerson() != null) {
                        toPut = clinicalDocument.getPerson().getLastName() + ", "
                                + clinicalDocument.getPerson().getFirstName();
                    }
                    tableRow.put(toPut);
                } else if (StringUtils.equals("urls", headerName)) {
                    String urls = "";
                    if (StringUtils.equals("list", display)) {
                        urls += "<a href=\"show?" + "clinicalDocumentId="
                                + clinicalDocument.getClinicalDocumentId()
                                + "\"><span class=\"glyphicon glyphicon-eye-open\"></a> ";
                        urls += "<a href=\"edit?" + "clinicalDocumentId="
                                + clinicalDocument.getClinicalDocumentId()
                                + "\"><span class=\"glyphicon glyphicon-pencil\"></a> ";
                        urls += "<a href=\"delete?" + "clinicalDocumentId="
                                + clinicalDocument.getClinicalDocumentId()
                                + "\"><span class=\"glyphicon glyphicon-trash\"></a>";
                    } else if (StringUtils.equals("person", display)) {
                        urls += "<a href=\"" + request.getContextPath()
                                + "/clinicaldocument/show.html?clinicalDocumentId="
                                + clinicalDocument.getClinicalDocumentId() + "\">[view]</a>";
                    } else {

                    }
                    tableRow.put(urls);
                } else {
                    tableRow.put("[error: column " + headerName + " not supported]");
                }
            }
            jsonArray.put(tableRow);
        }
        ob.put("data", jsonArray);

    } catch (Exception e) {
        log.error("error builing datatable json object for ClinicalDocument", e);
        try {
            String stackTrace = e.getMessage() + String.valueOf('\n');
            for (StackTraceElement ste : e.getStackTrace()) {
                stackTrace += ste.toString() + String.valueOf('\n');
            }
            ob = new JSONObject();
            ob.put("draw", draw);
            ob.put("recordsFiltered", 0);
            ob.put("recordsTotal", 0);
            ob.put("error", stackTrace);
        } catch (JSONException je) {
            log.error("error building json error object for ClinicalDocument", je);
        }
    }

    return ob.toString();
}

From source file:edu.uiowa.icts.bluebutton.dao.LabResultSynonymHome.java

License:Apache License

public List<LabResultSynonym> getSynonym(Set<String> set) {
    if (set.size() > 0) {
        Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(LabResultSynonym.class);
        Disjunction d = Restrictions.disjunction();
        for (String unofficialName : set) {
            d.add(Restrictions.eq("unofficialName", unofficialName.trim()).ignoreCase());
        }/*from ww  w.  ja  v a  2 s.c om*/
        List<LabResultSynonym> lrsList = (List<LabResultSynonym>) criteria.list();
        return (List<LabResultSynonym>) criteria.list();
    }
    return null;
}

From source file:edu.utah.further.core.data.hibernate.query.CriterionBuilderHibernateImpl.java

License:Apache License

/**
 * @param criterion/*from ww  w  .j  ava  2 s.c o m*/
 * @see #visit(edu.utah.further.core.data.search.JunctionCriterionImpl)
 */
public void visitJunction() {
    final SearchType searchType = criterion.getSearchType();
    switch (searchType) {
    case CONJUNCTION: {
        result = Restrictions.conjunction();
        break;
    }

    case DISJUNCTION: {
        result = Restrictions.disjunction();
        break;
    }

    default: {
        throw new BusinessRuleException(unsupportedMessage(searchType));
    }
    }

    // Add junction arguments
    for (final Criterion c : convertedCriteria) {
        ((Junction) result).add(c);
    }
}

From source file:edu.utah.further.ds.impl.executor.db.hibernate.criteria.HibernateLoadByIdExecutor.java

License:Apache License

/**
 * @param request/*from w  w w  . j av a 2s.  c om*/
 * @return
 * @see edu.utah.further.core.chain.AbstractRequestHandler#process(edu.utah.further.core.api.chain.ChainRequest)
 */
@Override
public boolean process(final ChainRequest request) {
    // Read input arguments
    final HibernateExecReq executionReq = new HibernateExecReq(request);
    final SessionFactory sessionFactory = executionReq.getSessionFactory();
    notNull(sessionFactory, "Expected SessionFactory");

    final Class<? extends PersistentEntity<?>> rootEntity = executionReq.getRootEntity();
    notNull(rootEntity, "Expected root entity class");

    // Read the search criteria's root entity meta data
    final List<Object> list = executionReq.getResult();
    final Object[] listArray = CollectionUtil.toArrayNullSafe(list);
    final ClassMetadata classMetadata = sessionFactory.getClassMetadata(rootEntity);
    final String identifierName = classMetadata.getIdentifierPropertyName();
    final Type identifierType = classMetadata.getIdentifierType();
    final int numTypes = listArray.length;
    final Type[] types = new Type[numTypes];
    for (int i = 0; i < numTypes; i++) {
        types[i] = identifierType;
    }

    // Build Hibernate criteria
    final GenericCriteria criteria = GenericCriteriaFactory.criteria(CriteriaType.CRITERIA, rootEntity,
            sessionFactory.getCurrentSession());
    if (identifierType.isComponentType()) {
        final String sqlInClause = HibernateUtil.sqlRestrictionCompositeIn(rootEntity, sessionFactory,
                numTypes);
        criteria.add(Restrictions.sqlRestriction(sqlInClause, listArray, types));
    } else {
        final int size = list.size();
        if (size > MAX_IN) {
            // Create a disjunction of IN clauses. Add MAX_IN elements at a time to
            // each IN clause (except the last IN, whose size is size % MAX_IN).
            final Junction junction = Restrictions.disjunction();
            for (int i = 0; i < size; i += MAX_IN) {
                junction.add(
                        Restrictions.in(THIS + identifierName, list.subList(i, Math.max(size, MAX_IN + i))));
            }
            criteria.add(junction);
        } else {
            // Single chunk, add directly as a criterion without the junction trick
            criteria.add(Restrictions.in(THIS + identifierName, list));
        }

    }

    executionReq.setResult(criteria);
    return false;
}

From source file:es.sm2.openppm.core.dao.CategoryDAO.java

License:Open Source License

/**
 * Find categories by company and enabled, include actual category
 *
 * @param company//from ww  w .  j a v  a  2  s.  c o  m
 * @param category
 * @return
 */
public List<Category> findByCompanyAndEnabled(Company company, Category category) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            // Filter by company
            .add(Restrictions.eq(Category.COMPANY, company));

    if (category != null && category.getIdCategory() != null) {

        // Filter by enable or this category
        crit.add(Restrictions.disjunction().add(Restrictions.eq(Category.ENABLE, true))
                .add(Restrictions.eq(Category.IDCATEGORY, category.getIdCategory())));
    } else {
        // Filter by enable
        crit.add(Restrictions.eq(Category.ENABLE, true));
    }

    // Order
    crit.addOrder(Order.asc(Category.NAME));

    return crit.list();
}