/** * Search staff list for instructors with matching names * @param fname First Name * @param lname Last Name * @return */ public static List findMatchingName(String fname, String lname) { List list = null; if ( (fname==null || fname.trim().length()==0) && (lname==null || lname.trim().length()==0) ) return list; Conjunction and = Restrictions.conjunction(); if (fname!=null && fname.trim().length()>0) and.add(Restrictions.ilike("firstName", fname, MatchMode.START)); if (lname!=null && lname.trim().length()>0) and.add(Restrictions.ilike("lastName", lname, MatchMode.START)); StaffDAO sdao = new StaffDAO(); list = sdao.getSession() .createCriteria(Staff.class) .add(and) .list(); Collections.sort(list); return list; }
@Override @SuppressWarnings( "unchecked" ) public List<T> getAllLikeName( Set<String> nameWords, int first, int max ) { Conjunction conjunction = Restrictions.conjunction(); for ( String word : nameWords ) { conjunction.add( Restrictions.like( "name", "%" + word + "%" ).ignoreCase() ); } return getSharingCriteria() .add( conjunction ) .addOrder( Order.asc( "name" ) ) .setFirstResult( first ) .setMaxResults( max ) .list(); }
private Criterion handleCondtion(Condition first) { if (first == null) { return null; } Map<String, Object> map = first.getEqs(); if (map.isEmpty()) { return null; } Conjunction conJoin = Restrictions.conjunction(); for (Map.Entry<String, Object> item : map.entrySet()) { Object value = item.getValue(); if(value==null){ conJoin.add(Restrictions.isNull(item.getKey())); }else{ conJoin.add(Restrictions.eq(item.getKey(), value)); } } return conJoin; }
private Junction getDatumJunction(AdvancedSampleSearchBean searchBean) { // if AND and more than one type of datum, don't use junction if (searchBean.getCharacterizationLogicalOperator().equals("and") && searchBean.getDatumTypeCount() > 1) { return null; } Disjunction datumDisjunction = Restrictions.disjunction(); Conjunction datumConjunction = Restrictions.conjunction(); for (CharacterizationQueryBean charQuery : searchBean .getCharacterizationQueries()) { Criterion datumCrit = getDatumCriterion(charQuery); if (datumCrit != null) { datumDisjunction.add(datumCrit); if (searchBean.getDatumTypeCount() == 1) { datumConjunction.add(datumCrit); } } } // default to or if only one query Junction junction = (searchBean.getCharacterizationLogicalOperator() .equals("or") || searchBean.getCharacterizationQueries().size() == 1) ? datumDisjunction : datumConjunction; return junction; }
/** * Get the sample name junction used in sample queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getSampleNameJunction(AdvancedSampleSearchBean searchBean) throws Exception { Disjunction sampleDisjunction = Restrictions.disjunction(); Conjunction sampleConjunction = Restrictions.conjunction(); for (SampleQueryBean query : searchBean.getSampleQueries()) { if (query.getNameType().equals("sample name")) { Criterion sampleNameCrit = getSampleNameCriterion(query); if (sampleNameCrit != null) { sampleDisjunction.add(sampleNameCrit); sampleConjunction.add(sampleNameCrit); } } } Junction junction = (searchBean.getSampleLogicalOperator().equals("or") || searchBean .getSampleQueries().size() == 1) ? sampleDisjunction : sampleConjunction; return junction; }
private static void setSeriesSecurityGroups(DetachedCriteria criteria, List<String> securityGroups) { Conjunction con = new Conjunction(); if (securityGroups != null && securityGroups.size() != 0) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.isNull("securityGroup")); disjunction.add(Restrictions.in("securityGroup", securityGroups)); con.add(disjunction); criteria.add(con); } else { criteria.add(Restrictions.isNull("securityGroup")); } }
@SuppressWarnings("unchecked") public List <Saida> saidaTodosEquipamentos(List<Equipamento> equipamentos) { Criteria criteria = session.createCriteria(Saida.class, "s"); Conjunction c = Restrictions.conjunction(); for (Equipamento e : equipamentos) { c.add(Subqueries.exists( DetachedCriteria.forClass(SaidaEquipamento.class, "se") .setProjection(Projections.id()) .add(Restrictions.eqProperty("s.id", "se.saida.id")) .add(Restrictions.eq("se.equipamento",e)))); } criteria.add(c); return criteria.list(); }
private Criteria parseFilter( Criteria criteria, List<String> filters ) { Conjunction conjunction = Restrictions.conjunction(); Schema schema = schemaService.getDynamicSchema( MinMaxDataElement.class ); if ( !filters.isEmpty() ) { for ( String filter : filters ) { String[] split = filter.split( ":" ); if ( split.length != 3 ) { throw new QueryParserException( "Invalid filter: " + filter ); } QueryPath queryPath = queryPlanner.getQueryPath( schema, split[0] ); Property property = queryParser.getProperty( schema, split[0] ); Criterion restriction = getRestriction( property, queryPath.getPath(), split[1], split[2] ); if ( restriction != null ) { conjunction.add( restriction ); if ( queryPath.haveAlias() ) { for ( String alias : queryPath.getAlias() ) { criteria.createAlias( alias, alias ); } } } } } criteria.add( conjunction ); return criteria; }
/** * Builds a conjunction by the properties of accounts. * * @param banned null for not query * @param twitchToken null for not query, empty for no token * @return conjunction */ private Conjunction buildAccountsPropertiesConjunction(Boolean banned, String twitchToken) { Conjunction conjunction = conjunction(); if (banned != null) { conjunction.add(eq("banned", banned)); } if (twitchToken != null) { conjunction.add(eqOrIsNull("twitchToken", emptyToNull(twitchToken))); } return conjunction; }
/** {@inheritDoc} */ @Override public Criterion getCriterion() { Conjunction conjunction = Restrictions.conjunction(); for(Filter filter : getFilters()) { conjunction.add(filter.getCriterion()); } return conjunction; }
/** * Get the junction used in function queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getFunctionJunction(AdvancedSampleSearchBean searchBean, DetachedCriteria crit) throws Exception { // if AND and more than one query per type, don't use junction if (searchBean.getCompositionLogicalOperator().equals("and") && searchBean.getFuncCount() > 1) { return null; } Disjunction compDisjunction = Restrictions.disjunction(); Conjunction compConjunction = Restrictions.conjunction(); for (CompositionQueryBean compQuery : searchBean .getCompositionQueries()) { // function if (compQuery.getCompositionType().equals("function")) { Criterion funcCrit = this.getFunctionCriterion(compQuery, "", ""); if (funcCrit != null) { compDisjunction.add(funcCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getFuncCount() == 1) { compConjunction.add(funcCrit); } } } } // default to or if only one query Junction junction = (searchBean.getCompositionLogicalOperator().equals( "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction : compConjunction; return junction; }
/** * Get the junction used in nanomaterial entity queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getNanomaterialEntityJunction( AdvancedSampleSearchBean searchBean, DetachedCriteria crit) throws Exception { // if AND and more than one query per type, don't use junction if (searchBean.getCompositionLogicalOperator().equals("and") && searchBean.getNanoEntityCount() > 1) { return null; } Disjunction compDisjunction = Restrictions.disjunction(); Conjunction compConjunction = Restrictions.conjunction(); for (CompositionQueryBean compQuery : searchBean .getCompositionQueries()) { // nanomaterial entity if (compQuery.getCompositionType().equals("nanomaterial entity")) { Criterion nanoEntityCrit = getNanomaterialEntityCriterion( compQuery, ""); if (nanoEntityCrit != null) { compDisjunction.add(nanoEntityCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getNanoEntityCount() == 1) { compConjunction.add(nanoEntityCrit); } } } } // default to or if only one query Junction junction = (searchBean.getCompositionLogicalOperator().equals( "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction : compConjunction; return junction; }
/** * Get the junction used in functionalizing entity queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getFunctionalizingEntityJunction( AdvancedSampleSearchBean searchBean, DetachedCriteria crit) throws Exception { // if AND and more than one query per type, don't use junction if (searchBean.getCompositionLogicalOperator().equals("and") && searchBean.getFuncEntityCount() > 1) { return null; } Disjunction compDisjunction = Restrictions.disjunction(); Conjunction compConjunction = Restrictions.conjunction(); for (CompositionQueryBean compQuery : searchBean .getCompositionQueries()) { // functionalizing entity if (compQuery.getCompositionType().equals("functionalizing entity")) { Criterion funcEntityCrit = getFunctionalizingEntityCriterion( compQuery, ""); if (funcEntityCrit != null) { compDisjunction.add(funcEntityCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getFuncEntityCount() == 1) { compConjunction.add(funcEntityCrit); } } } } // default to or if only one query Junction junction = (searchBean.getCompositionLogicalOperator().equals( "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction : compConjunction; return junction; }
/** * Get the sample disjunction used in sample queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getSampleJunction(AdvancedSampleSearchBean searchBean) throws Exception { // if there are more than one POC query in AND, don't use junction. if (searchBean.getSampleLogicalOperator().equals("and") && searchBean.getPocCount() > 1) { return null; } Disjunction sampleDisjunction = Restrictions.disjunction(); Conjunction sampleConjunction = Restrictions.conjunction(); for (SampleQueryBean query : searchBean.getSampleQueries()) { if (query.getNameType().equals("sample name")) { Criterion sampleNameCrit = getSampleNameCriterion(query); if (sampleNameCrit != null) { sampleDisjunction.add(sampleNameCrit); sampleConjunction.add(sampleNameCrit); } } if (query.getNameType().equals("point of contact name")) { Disjunction pocDisjunction = getPointOfContactDisjunction( searchBean, "poc.", "otherPOC."); if (pocDisjunction != null) { sampleDisjunction.add(pocDisjunction); if (searchBean.getPocCount() == 1) { sampleConjunction.add(pocDisjunction); } } } } Junction junction = (searchBean.getSampleLogicalOperator().equals("or") || searchBean .getSampleQueries().size() == 1) ? sampleDisjunction : sampleConjunction; return junction; }
@Override public Criterion and(Criterion... subqueries) { Conjunction conjunction = Restrictions.conjunction(); for (Criterion criterion : subqueries) { conjunction.add(criterion); } return conjunction; }
/** * Criterion defining active web form. * * @param type web form type * @return criterion */ private Conjunction activeWebFormCriterionForType(WebFormType type) { Conjunction criterion = and(eq("fileType", ProjectFileType.WEBFORM), eq("active", true), isNotNull("xmlSchema")); if (type == WebFormType.LOCAL) { criterion.add(eq("localForm", true)); } if (type == WebFormType.REMOTE) { criterion.add(eq("remoteForm", true)); } return criterion; }
private static void setAuthorizedSiteData(DetachedCriteria criteria, List<SiteData> sites) { Disjunction disjunction = Restrictions.disjunction(); for (SiteData sd : sites) { Conjunction con = new Conjunction(); con.add(Restrictions.eq("dpSiteName",sd.getSiteName())); con.add(Restrictions.eq("project", sd.getCollection())); disjunction.add(con); } criteria.add(disjunction); }
private static void setAuthorizedSiteData(DetachedCriteria criteria, List<SiteData> sites){ Disjunction disjunction = Restrictions.disjunction(); for (SiteData sd : sites){ Conjunction con = new Conjunction(); con.add(Restrictions.eq("dpSiteName",sd.getSiteName())); con.add(Restrictions.eq("project", sd.getCollection())); disjunction.add(con); } criteria.add(disjunction); }
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) @Override public Collection<String> getProfiles(String name, String owner, Boolean banned, String skin, String cape, String elytra, TextureModel model, String serverId) { if (name != null && name.isEmpty()) { throw new BadRequestException("name is empty"); } if (owner != null && owner.isEmpty()) { throw new BadRequestException("owner is empty"); } Session session = sessionFactory.getCurrentSession(); if (serverId == null) { Conjunction conjunction = conjunction(); if (name != null) { conjunction.add(eq("name", name)); } if (owner != null) { conjunction.add(eq("owner.id", owner)); } if (banned != null) { conjunction.add(eq("banned", banned)); } if (skin != null) { conjunction.add(eqOrIsNull("skin", emptyToNull(skin))); } if (cape != null) { conjunction.add(eqOrIsNull("cape", emptyToNull(cape))); } if (elytra != null) { conjunction.add(eqOrIsNull("elytra", emptyToNull(elytra))); } if (model != null) { conjunction.add(eq("textureModel", model)); } @SuppressWarnings("unchecked") List<String> uuids = session.createCriteria(GameProfile.class).add(conjunction).setProjection(property("uuid")).list(); return uuids; } else if (serverId.isEmpty()) { throw new BadRequestException("serverId is empty"); } else { UUID profileUUID = serveridRepo.getOwner(serverId); if (profileUUID != null) { GameProfile profile = session.get(GameProfile.class, profileUUID.toString()); if ((name == null || name.equals(profile.getName())) && (owner == null || owner.equals(profile.getOwner().getId())) && (banned == null || banned.equals(profile.isBanned())) && (skin == null || Objects.equals(emptyToNull(skin), profile.getSkin())) && (cape == null || Objects.equals(emptyToNull(cape), profile.getCape())) && (elytra == null || Objects.equals(emptyToNull(elytra), profile.getElytra())) && (model == null || model.equals(profile.getTextureModel()))) { return Collections.singleton(profile.getUuid()); } } return Collections.emptyList(); } }
/** * Get the junction used in composition queries * * @param searchBean * @param crit * @return * @throws Exception */ private Junction getCompositionJunction( AdvancedSampleSearchBean searchBean, DetachedCriteria crit) throws Exception { // if AND and more than one query per type, don't use junction if (searchBean.getCompositionLogicalOperator().equals("and") && searchBean.getFuncCount() > 1 && searchBean.getNanoEntityCount() > 1 && searchBean.getFuncEntityCount() > 1) { return null; } Disjunction compDisjunction = Restrictions.disjunction(); Conjunction compConjunction = Restrictions.conjunction(); for (CompositionQueryBean compQuery : searchBean .getCompositionQueries()) { // function if (compQuery.getCompositionType().equals("function")) { Criterion funcCrit = this.getFunctionCriterion(compQuery, "inherentFunction.", "function."); if (funcCrit != null) { compDisjunction.add(funcCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getFuncCount() == 1) { compConjunction.add(funcCrit); } } } // nanomaterial entity else if (compQuery.getCompositionType().equals( "nanomaterial entity")) { Criterion nanoEntityCrit = getNanomaterialEntityCriterion( compQuery, "nanoEntity."); if (nanoEntityCrit != null) { compDisjunction.add(nanoEntityCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getNanoEntityCount() == 1) { compConjunction.add(nanoEntityCrit); } } } // functionalizing entity else if (compQuery.getCompositionType().equals( "functionalizing entity")) { Criterion funcEntityCrit = getFunctionalizingEntityCriterion( compQuery, "funcEntity."); if (funcEntityCrit != null) { compDisjunction.add(funcEntityCrit); // only add to conjunction if there is only one query for // the type if (searchBean.getFuncEntityCount() == 1) { compConjunction.add(funcEntityCrit); } } } } // default to or if only one query Junction junction = (searchBean.getCompositionLogicalOperator().equals( "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction : compConjunction; return junction; }
/** * Queries accounts by the properties of themselves in the given range. * * @param banned null for not query * @param twitchToken null for not query, empty for no token * @param range the account range * @return a set of id */ private Collection<String> queryAccountsByPropertiesInRange(Boolean banned, String twitchToken, Set<String> range) { Conjunction propertiesConjunction = buildAccountsPropertiesConjunction(banned, twitchToken); Disjunction accountsDisjunction = disjunction(); range.forEach(id -> accountsDisjunction.add(eq("id", id))); return queryAccountsByCriterion(conjunction(propertiesConjunction, accountsDisjunction)); }