/** * get the id of a user given his login. * * @param login the login of the user to search for * @return a wikitty id * @deprecated since 3.4 {@link #getUserWikittyId(org.nuiton.wikitty.WikittyClient, java.lang.String) } */ @Deprecated static public String getUserWikittyId(WikittyProxy proxy, String login) { String userWikittyId = null; Wikitty user = proxy.findByCriteria(Search.query().eq( WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria()); if (user != null) { userWikittyId = user.getWikittyId(); } return userWikittyId; }
/** * Create new {@code Search} object with custom kind. * * @param kind kind * @return Search helper */ public static Search query(KIND kind) { Search search = new Search(); search.kind = kind; return search; }
Search treeSearch = Search.query().and().eq(TREENODE_PARENTS, wikittyId); if (depth >= 0) { Integer d = (Integer) doc.getFieldValue(TREENODE_DEPTH); treeSearch = treeSearch.bw(TREENODE_DEPTH, String.valueOf(d), String.valueOf(d + depth)); Criteria treeCriteria = treeSearch.criteria(); Criteria attCriteria = Search.query(filter).eq( TREENODE_ATTACHED_ALL, wikittyId).criteria() .setFirstIndex(0).setEndIndex(0) .addFacetField(TREENODE_ATTACHED_ALL);
/** * Recherche le premier objet qui a ce label * @param proxy * @param label * @return * @deprecated since 3.4 use {@link #findByLabel(org.nuiton.wikitty.WikittyClient, java.lang.String) } */ @Deprecated static public Wikitty findByLabel(WikittyProxy proxy, String label) { WikittyLabelImpl l = new WikittyLabelImpl(); l.addLabels(label); Criteria criteria = Search.query(l.getWikitty()).criteria(); Wikitty result = proxy.findByCriteria(criteria); return result; }
@Test public void testAssociated() throws Exception { /* Following request mean is : * Looking for any product which price is between 15 and 25, * and name starts with 'Paint', * and with an associated category which name is 'Hardware' */ Restriction dto = q() .bw( "Product.price", "15", "25") .sw( "Product.name", "Paint") .associated( "Product.category" ) .eq( "Category.name", "Hardware" ) .criteria().getRestriction(); Assert.assertTrue( "Restriction is " + dto.getClass().getName(), dto instanceof AssociatedRestriction ); AssociatedRestriction ass = (AssociatedRestriction) dto; Restriction embedded = ass.getRestriction(); Assert.assertTrue( "Restriction is " + dto.getClass().getName(), embedded instanceof Equals ); checkRestriction(embedded, RestrictionName.EQUALS, "Category.name", "Hardware"); Assert.assertEquals( "Product.category", ass.getElement().getName() ); }
@Test public void testOr() throws Exception { String[] elementNames = new String[4]; String[] values = new String[4]; for (int i = 0; i < elementNames.length; i++) { elementNames[i] = elementName + i; values[i] = value + i; } Search q = q().eq(elementNames[0], values[0]); Search qor = q.or() .gt(elementNames[1], values[1]) .ew(elementNames[2], values[2]) .lt(elementNames[3], values[3]); Restriction dto = q.criteria().getRestriction(); Assert.assertTrue( "Restriction is " + dto.getClass().getName(), dto instanceof And ); And and = (And) dto; Restriction[] dtos = and.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.EQUALS, elementName + "0", value + "0"); Assert.assertTrue( "Restriction is " + dtos[1].getClass().getName(), dtos[1] instanceof Or ); Or or = (Or) dtos[1]; dtos = or.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.GREATER, elementName + "1", value + "1"); checkRestriction(dtos[1], RestrictionName.ENDS_WITH, elementName + "2", value + "2"); checkRestriction(dtos[2], RestrictionName.LESS, elementName + "3", value + "3"); }
@Test public void testBinaryOperators() throws Exception { checkSearch( q().eq(elementName, value), RestrictionName.EQUALS ); checkSearch( q().neq(elementName, value), RestrictionName.NOT_EQUALS ); checkSearch( q().lt(elementName, value), RestrictionName.LESS ); checkSearch( q().le(elementName, value), RestrictionName.LESS_OR_EQUAL ); checkSearch( q().gt(elementName, value), RestrictionName.GREATER ); checkSearch( q().ge(elementName, value), RestrictionName.GREATER_OR_EQUAL ); checkSearch( q().sw(elementName, value), RestrictionName.STARTS_WITH ); checkSearch( q().ew(elementName, value), RestrictionName.ENDS_WITH ); }
@Test public void testAnd() throws Exception { Restriction dto = q() .eq(elementName + "0", value + "0") .gt(elementName + "1", value + "1") .ew(elementName + "2", value + "2") .criteria().getRestriction(); Assert.assertTrue( dto instanceof And ); And and = (And) dto; Restriction[] dtos = and.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.EQUALS, elementName + "0", value + "0"); checkRestriction(dtos[1], RestrictionName.GREATER, elementName + "1", value + "1"); checkRestriction(dtos[2], RestrictionName.ENDS_WITH, elementName + "2", value + "2"); }
public <E extends BusinessEntity> List<E> findByCriteria( Class<E> clazz, List<Criteria> criterias) { long start = TimeLog.getTime(); List<E> result = null; if (criterias != null) { BusinessEntityImpl sample = (BusinessEntityImpl) WikittyUtil.newInstance(clazz); Wikitty wikitty = sample.getWikitty(); Collection<String> extensions = wikitty.getExtensionNames(); List<Criteria> serviceCriterias = new ArrayList<Criteria>(criterias.size()); for (Criteria criteria : criterias) { Search search = Search.query(criteria); search = search.exteq(extensions); criteria = search.criteria(); serviceCriterias.add(criteria); } List<String> id = findIdByCriteria(serviceCriterias); result = restore(clazz, id); } timeLog.log(start, "multiFindByCriteria<Business>(List>"); return result; }
@Test public void testXML() throws Exception { Criteria criteria = q().bw(elementName, "from", "to").criteria(); // Serialize String xml = Criteria.toXML(criteria); log.debug("[XML] " + xml); Assert.assertNotNull(xml); // Deserialize criteria = Criteria.fromXML(xml); Assert.assertNotNull(criteria); }
/** * Create new {@code Search} object with default kind to {@link KIND#AND}. * * @return Search helper */ public static Search query() { Search search = query(KIND.AND); return search; }
/** * Return unnamed criteria. * * @return new criteria */ public Criteria criteria() { Criteria criteria = criteria(null); return criteria; }
Search treeSearch = Search.query().and().eq(TREENODE_PARENTS, wikittyId); if (depth >= 0) { Integer d = SolrUtil.getIntFieldValue(doc, TREENODE_DEPTH); treeSearch = treeSearch.bw(TREENODE_DEPTH, String.valueOf(d), String.valueOf(d + depth)); Criteria treeCriteria = treeSearch.criteria(); Criteria attCriteria = Search.query(filter).eq( TREENODE_ATTACHED_ALL, wikittyId).criteria() .setFirstIndex(0).setEndIndex(0) .addFacetField(TREENODE_ATTACHED_ALL);
@Override public List<String> findByCriteria(String securityToken, List<Criteria> criteria) { List<String> result = new ArrayList<String>(criteria.size()); List<Criteria> criteriaLimit = new ArrayList<Criteria>(criteria.size()); for (Criteria c : criteria) { Criteria climit = Search.query(c).criteria().setFirstIndex(0).setEndIndex(1); criteriaLimit.add(climit); } List<PagedResult<String>> idsList = findAllByCriteria( securityToken, criteriaLimit); for (PagedResult<String> ids : idsList) { if (ids.size() > 0) { result.add(ids.getFirst()); } else { result.add(null); } } if (criteria.size() != result.size()) { log.error(String.format("Criteria input list (%s) has not same size that result list (%s)", criteria.size(), result.size())); } return result; }
@Test public void testBetween() throws Exception { Criteria criteria = q().bw(elementName, "from", "to").criteria(); Restriction restriction = criteria.getRestriction(); Assert.assertTrue( restriction instanceof Between ); Between between = (Between) restriction; Assert.assertEquals( "from", between.getMin() ); Assert.assertEquals( "to", between.getMax() ); }
/** * Or (sub query). * * @return sub query */ public Search or() { Search search = Search.query(KIND.OR); subSearchs.add(search); return search; }
protected void checkSearch( Search search, RestrictionName name ) throws Exception { Restriction dto = search.criteria().getRestriction(); checkRestriction( dto, name, elementName, value ); }
/** * Null field are not used in search request. * * @param e sample wikitty * @return */ public <E extends BusinessEntityImpl> E findByExample(E e) { long start = TimeLog.getTime(); Criteria criteria = Search.query(e.getWikitty()).criteria(); String id = findIdByCriteria(criteria); E result = null; if (id != null) { Wikitty w = wikittyService.restore(securityToken, id); result = (E) WikittyUtil.newInstance( securityToken, wikittyService, e.getClass(), w); } timeLog.log(start, "findByExample"); return result; }