Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
September 2012
- 1 participants
- 8 discussions
r1517 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query
by bpoussin@users.nuiton.org 15 Sep '12
by bpoussin@users.nuiton.org 15 Sep '12
15 Sep '12
Author: bpoussin
Date: 2012-09-15 14:37:32 +0200 (Sat, 15 Sep 2012)
New Revision: 1517
Url: http://nuiton.org/repositories/revision/wikitty/1517
Log:
modif du WikittyQueryMaker pour permettre d'en heriter dans les applications
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMakerAbstract.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java 2012-09-15 11:24:28 UTC (rev 1516)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java 2012-09-15 12:37:32 UTC (rev 1517)
@@ -1,1182 +1,35 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
package org.nuiton.wikitty.query;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.entities.BusinessEntityImpl;
-import org.nuiton.wikitty.entities.Element;
-import org.nuiton.wikitty.entities.FieldType;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.query.conditions.Aggregate;
-import org.nuiton.wikitty.query.conditions.And;
-import org.nuiton.wikitty.query.conditions.Between;
-import org.nuiton.wikitty.query.conditions.Condition;
-import org.nuiton.wikitty.query.conditions.ConditionValue;
-import org.nuiton.wikitty.query.conditions.ConditionValueString;
-import org.nuiton.wikitty.query.conditions.ContainsAll;
-import org.nuiton.wikitty.query.conditions.ContainsOne;
-import org.nuiton.wikitty.query.conditions.Equals;
-import org.nuiton.wikitty.query.conditions.False;
-import org.nuiton.wikitty.query.conditions.Greater;
-import org.nuiton.wikitty.query.conditions.GreaterOrEquals;
-import org.nuiton.wikitty.query.conditions.Keyword;
-import org.nuiton.wikitty.query.conditions.Less;
-import org.nuiton.wikitty.query.conditions.LessOrEquals;
-import org.nuiton.wikitty.query.conditions.Like;
-import org.nuiton.wikitty.query.conditions.Not;
-import org.nuiton.wikitty.query.conditions.NotEquals;
-import org.nuiton.wikitty.query.conditions.NotNull;
-import org.nuiton.wikitty.query.conditions.Null;
-import org.nuiton.wikitty.query.conditions.Or;
-import org.nuiton.wikitty.query.conditions.Select;
-import org.nuiton.wikitty.query.conditions.True;
-import org.nuiton.wikitty.query.conditions.Unlike;
/**
- * Cette objet sert a construire une condition a la facon d'un flux.
- * <p>
- * Condition c = new WikittyQueryMaker().and().eq("ext.field", "toto").eq("ext.field2", 10).getCondition();
- * <p>
- * On peut aussi vouloir continuer avec un WikittyQuery pour cela on peut faire.
- * <p>
- * WikittyQuery q = new WikittyQueryMaker().and().[other condition].end();
- * <p>
- * Si un {@link WikittyQuery} est passé en parametre du constructeur et que la
- * method {@link #end()} est appeler alors la condition creee est envoyee dans
- * le WikittyQuery et le constructeur est fermer (on ne peut plus ajouter de
- * condition)
- * <p>
- * Le WikittyQuery lie avec cet objet lorsqu'on le recupere via la method
- * {@link #getQuery()} a en interne comme condition la valuer courante de la
- * condition en cours d'ecriture
+ * Classe concrete de construction de requete pour la documentation voir
+ * {@link WikittyQueryMakerAbstract}
*
* @author poussin
* @version $Revision$
- * @since 3.3
*
* Last update: $Date$
* by : $Author$
*/
-public class WikittyQueryMaker {
+public class WikittyQueryMaker extends WikittyQueryMakerAbstract<WikittyQueryMaker> {
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyQueryMaker.class);
- /** query where to send condition when end() method called */
- protected WikittyQuery query;
-
- /** query condition */
- protected Condition condition;
- /** stack des conditions non terminales ouvertes */
- protected Deque<Condition> openStack = new LinkedList<Condition>();
-
public WikittyQueryMaker() {
+ super();
}
public WikittyQueryMaker(WikittyQuery query) {
- this.query = query;
+ super(query);
}
- public Condition getCondition() {
- return condition;
- }
-
- /**
- * La query passee dans le constructeur ou une nouvelle query si aucune
- * query n'avait ete passee dans le constructeur
- *
- * @return
- */
- public WikittyQuery getQuery() {
- if (query == null) {
- query = new WikittyQuery();
- }
- // la condition de la query doit toujours refleter la valeur courante
- // de la condition en cours de creation
- query.setCondition(getCondition());
- return query;
- }
-
- /**
- * Retourne le stack courant des conditions, si le stack est null cela
- * veut dire que le maker ne permet plus de modification
- * @return
- */
- protected Deque<Condition> getOpenStack() {
- if (openStack == null) {
- throw new WikittyException(
- "You can't create condition if you have used setCondition method"
- + " or close last condition");
- }
- return openStack;
- }
-
- /**
- * Ajout une condition
- *
- */
- protected void addCondition(Condition c) {
- addCondition(c, false);
- }
- /**
- * Ajout une condition. Si terminal est true, alors quelque soit le type de
- * cette condition la stack restera inchange apres l'ajout. Cela permet
- * d'ajouter des conditions non terminale comme des terminales
- */
- protected void addCondition(Condition c, boolean terminal) {
- Condition parent = getOpenStack().peek();
- if (!terminal) {
- // on ne met les conditions toujours dans le stack (meme les terminales)
- // si c'est la premiere cela permet d'indiquer a l'utilisateur
- // qu'il faut commencer par un or, and, not car une exception sera
- // levee car non supprimer par le while dans lequel on ne passe pas
- // car on passe dans le if et non le else (parent == null)
- getOpenStack().push(c);
- }
-
- if (parent == null) {
- // il n'y a rien dans la stack donc rien dans condition, il faut
- // mettre cette condition dedans
- condition = c;
- // et on ne depile pas le stack
- } else {
- // se add peut lever une exception si parent n'accepte pas cet enfant
- parent.addCondition(c);
- // on depile toutes les conditions qui n'ont plus besoin de renseignement
- // sauf si l'ajout a ete force en terminal
- if (!terminal) {
- closeIfNecessary();
- }
- }
- }
-
- protected void closeIfNecessary() {
- // on depile toutes les conditions qui n'ont plus besoin de renseignement
- while (getOpenStack().peek() != null
- && !getOpenStack().peek().waitCondition()) {
- getOpenStack().poll();
- }
- if (getOpenStack().size() == 0) {
- // we just close last open condition, set stack to null, to prevent
- // next condition add that is mistake
- openStack = null;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // Q U E R Y F L O W C R E A T I O N
- //
- ///////////////////////////////////////////////////////////////////////////
-
- // eq(Wikitty|Date|Number|Boolean|String)
-
- static protected ConditionValue convertToConditionValue(Object o) {
- ConditionValue result;
- if (o instanceof ConditionValue) {
- result = (ConditionValue)o;
- } else {
- String s = WikittyUtil.toString(o);
- result = new ConditionValueString(s);
- }
- return result;
- }
-
- public WikittyQueryMaker value(Object value) {
- ConditionValue v = convertToConditionValue(value);
- addCondition(v);
+ @Override
+ protected WikittyQueryMaker asM() {
return this;
}
- /**
- * Ajoute une condition, cette condition est prise comme une condition terminal
- * Si l'on veut continuer a construire la requete, il faut avoir ajouter
- * avant une {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
- * @param c la condition a ajouter
- * @return {@code this} with the {@code c} restriction added.
- */
- public WikittyQueryMaker condition(Condition c) {
- addCondition(c, true);
- return this;
- }
-
- /**
- * Parse et ajoute un bout de requete. Cette requete est prise comme une
- * condition terminal si l'on veut continuer a construire la requete, il
- * faut avoir ajouter avant une
- * {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
- * @param query la requete a ajouter (peut-etre vide ou nul, dans ce cas, la
- * condition utiliser est "true")
- * @return {@code this} with the {@code c} restriction added.
- */
- public WikittyQueryMaker parse(String query) {
- if (StringUtils.isNotBlank(query)) {
- WikittyQuery filter = WikittyQueryParser.parse(query);
- addCondition(filter.getCondition(), true);
- } else {
- addCondition(new True());
- }
- return this;
- }
-
- /**
- * Ajoute une contrainte qui cree les conditions en prenant comme exemple
- * l'objet passer en parametre. Seuls les champs non null sont utilises ainsi
- * que la liste des extensions de l'objet
- *
- * @param w le wikitty a prendre comme exemple
- * @return {@code this} with the {@code w} restriction added.
- */
- public WikittyQueryMaker wikitty(Wikitty w) {
- WikittyQueryMaker result = new WikittyQueryMaker().and();
-
- // result object must have same extension that wikitty example
- result.extContainsAll(w.getExtensionNames());
-
- for (String fqfieldName : w.fieldNames()) {
- Object value = w.getFqField(fqfieldName);
- if (value != null) {
- FieldType type = w.getFieldType(fqfieldName);
- if (type.isCollection()) {
- result.containsAll(fqfieldName, (Collection<?>)value);
- } else {
- result.eq(fqfieldName, value);
- }
- }
- }
- addCondition(result.getCondition());
-
- return this;
- }
-
- /**
- * Ajoute une contrainte qui cree les conditions en prenant comme exemple
- * l'objet passer en parametre. Seuls les champs non null sont utilises ainsi
- * que la liste des extensions de l'objet
- *
- * @param e l'objet a prendre comme exemple
- * @return {@code this} with the {@code e} restriction added.
- */
- public WikittyQueryMaker wikitty(BusinessEntityImpl e) {
- Wikitty w = e.getWikitty();
- return wikitty(w);
- }
-
- /**
- * @see {@link ContainsAll}
- */
- public WikittyQueryMaker containsAll(Element element) {
- addCondition(new ContainsAll(element));
- return this;
- }
-
- /**
- * @see {@link ContainsAll}
- */
- public WikittyQueryMaker containsAll(String element) {
- return containsAll(Element.get(element));
- }
-
- /**
- * Contains.
- *
- * Search on lists (multivalued fields) that a field contains all the values
- * of the list given in parameter.
- *
- * Ex : The field with value [toto,titi,tutu] contains [titi,tutu] but not
- * [titi,tutu,tata]
- *
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @param element the element on which the restriction is put
- * @param values the values to search in the element
- * @return {@code this} with the {@code contains} restriction added.
- * @see {@link ContainsAll}
- */
- public <E> WikittyQueryMaker containsAll(String fqfield, Collection<E> values) {
- return containsAll(Element.get(fqfield), values);
- }
-
- /**
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @see {@link ContainsAll}
- */
- public <E> WikittyQueryMaker containsAll(Element element, Collection<E> values) {
- containsAll(element);
- for (E e : values) {
- value(e);
- }
- close();
- return this;
- }
-
- /**
- * Search on lists (multivalued fields) that a field contains all the values
- * given in parameter.
- *
- * Ex : The field with value [toto,titi,tutu] contains [titi,tutu] but not
- * [titi,tutu,tata]
- *
- * Ps : Use wildcards if you search for substrings.
- *
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @param element the element on which the restriction is put
- * @param value1 first value to search in the field
- * @param values list of values to search in the field
- * @return {@code this} with the {@code contains} restriction added.
- * @see {@link ContainsAll}
- */
- public <E> WikittyQueryMaker containsAll(String fqfield, E value1, E ... values) {
- List<E> l = new LinkedList<E>();
- l.add(value1);
- l.addAll(Arrays.asList(values));
- return containsAll(fqfield, l);
- }
-
- /**
- * @see {@link ContainsOne}
- */
- public WikittyQueryMaker containsOne(Element element) {
- addCondition(new ContainsOne(element));
- return this;
- }
-
- /**
- * @see {@link ContainsOne}
- */
- public WikittyQueryMaker containsOne(String element) {
- return containsOne(Element.get(element));
- }
-
- /**
- * Search if a field is contained in the list of values in parameter
- *
- * Ex : The field with value titi is in [titi,tutu] but not in
- * [tutu,tata]
- *
- * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @param element the element on which the restriction is put
- * @param values list of values the field must be in
- * @return {@code this} with the {@code in} restriction added.
- * @see {@link ContainsOne}
- */
- public <E> WikittyQueryMaker containsOne(String fqfield, Collection<E> values) {
- return containsOne(Element.get(fqfield), values);
- }
-
- /**
- * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @see {@link ContainsOne}
- */
- public <E> WikittyQueryMaker containsOne(Element element, Collection<E> values) {
- containsOne(element);
- for (E e : values) {
- value(e);
- }
- close();
- return this;
- }
-
- /**
- * Search if a field is contained in the list of values in parameter
- *
- * Ex : The field with value titi is in [titi,tutu] but not in
- * [tutu,tata]
- *
- * Ps : Use wildcards in the values if you search for substrings.
- *
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
- * de {@link #close()}
- *
- * @param element the element on which the restriction is put
- * @param value1 first value the field must be in
- * @param values list of values the field must be in
- * @return {@code this} with the {@code in} restriction added.
- * @see {@link ContainsOne}
- */
- public <E> WikittyQueryMaker containsOne(String fqfield, E value1, E ... values) {
- List<E> l = new LinkedList<E>();
- l.add(value1);
- l.addAll(Arrays.asList(values));
- return containsOne(fqfield, l);
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker eq(Element element) {
- addCondition(new Equals(element));
- return this;
- }
-
- /**
- * Equals.
- *
- * Restrict search so that the field value equals the parameter.
- *
- * You might use patterns in your equality.
- *
- * @param element the field on which the search is made
- * @param value the value the element must be equals to
- * @return {@code this}
- * @see {@link Equals}
- */
- public WikittyQueryMaker eq(String fqfield, Object value) {
- return eq(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker eq(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new Equals(element, s));
- return this;
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker eqIgnoreCaseAndAccent(Element element) {
- addCondition(new Equals(element, true));
- return this;
- }
-
- /**
- * Equals.
- *
- * Restrict search so that the field value equals the parameter.
- *
- * You might use patterns in your equality.
- *
- * @param element the field on which the search is made
- * @param value the value the element must be equals to
- * @return {@code this}
- * @see {@link Equals}
- */
- public WikittyQueryMaker eqIgnoreCaseAndAccent(String fqfield, Object value) {
- return eqIgnoreCaseAndAccent(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker eqIgnoreCaseAndAccent(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new Equals(element, s, true));
- return this;
- }
-
- /**
- * Extension equals.
- *
- * Restrict search to wikitties that got the extension in parameter.
- *
- * @param s the extension to restrict the results to
- * @return {@code this} with the {@code exteq} restriction added.
- * @see {@link Equals}
- */
- public WikittyQueryMaker exteq(String extensionName) {
- return eq(Element.EXTENSION, extensionName);
- }
-
- /**
- * Id equals.
- *
- * Restrict search to wikitties that got the id in parameter.
- *
- * @param value the id or wikitty to restrict the results to
- * @return {@code this} with the {@code ideq} restriction added.
- * @see {@link Equals}
- */
- public WikittyQueryMaker ideq(Object idOrWikitty) {
- return eq(Element.ID, idOrWikitty);
- }
-
- /**
- * Extension equals.
- *
- * Restrict search to wikitties that got all the extensions in parameter.
- *
- * @param extensionNames list of the extension to restrict the results to
- * @return {@code this} with the {@code exteq} restriction added.
- * @see {@link ContainsAll}
- */
- public WikittyQueryMaker extContainsAll(Collection<String> extensionNames) {
- return containsAll(Element.EXTENSION, extensionNames);
- }
-
- /**
- * @see {@link ContainsAll}
- */
- public WikittyQueryMaker extContainsAll(String ext1, String ... exts) {
- List<String> l = new LinkedList<String>();
- l.add(ext1);
- l.addAll(Arrays.asList(exts));
- return containsAll(Element.EXTENSION, l);
- }
-
- /**
- * Extension equals.
- *
- * Restrict search to wikitties that got one of the extensions in parameter.
- *
- * @param extensionNames list of the extension to restrict the results to
- * @return {@code this} with the {@code exteq} restriction added.
- * @see {@link ContainsAll}
- */
- public WikittyQueryMaker extContainsOne(Collection<String> extensionNames) {
- return containsOne(Element.EXTENSION, extensionNames);
- }
-
- /**
- * @see {@link ContainsOne}
- */
- public WikittyQueryMaker extContainsOne(String ext1, String ... exts) {
- List<String> l = new LinkedList<String>();
- l.add(ext1);
- l.addAll(Arrays.asList(exts));
- return containsOne(Element.EXTENSION, l);
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker ne(Element element) {
- addCondition(new NotEquals(element));
- return this;
- }
-
- /**
- * Not equals.
- *
- * Restrict search to elements that are not equals to the value given in
- * parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value the element must not be equals to.
- * @return {@code this} with the {@code neq} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker ne(String fqfield, Object value) {
- return ne(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker ne(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new NotEquals(element, s));
- return this;
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker neIgnoreCaseAndAccent(Element element) {
- addCondition(new NotEquals(element, true));
- return this;
- }
-
- /**
- * Not equals.
- *
- * Restrict search to elements that are not equals to the value given in
- * parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value the element must not be equals to.
- * @return {@code this} with the {@code neq} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker neIgnoreCaseAndAccent(String fqfield, Object value) {
- return neIgnoreCaseAndAccent(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker neIgnoreCaseAndAccent(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new NotEquals(element, s, true));
- return this;
- }
-
- /**
- * Extension not equals.
- *
- * Restrict search to wikitties that do not get the extension given in
- * parameter.
- *
- * @param extensionName the extension that the wikitties must not have.
- * @return {@code this} with the {@code extneq} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker extne(String extensionName) {
- return ne(Element.EXTENSION, extensionName);
- }
-
- /**
- * Id not equals.
- *
- * Restrict search to wikitties that do not have the id given in parameter.
- *
- * @param idOrWikitty the id the wikitties must not have.
- * @return {@code this} with the {@code idne} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker idne(Object idOrWikitty) {
- return ne(Element.ID, idOrWikitty);
- }
-
- /**
- * @see {@link Greater}
- */
- public WikittyQueryMaker gt(Element element) {
- addCondition(new Greater(element));
- return this;
- }
-
- /**
- * Greater than.
- *
- * Search if an element value is greater than the parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value to be compared to
- * @return {@code this} with the {@code gt} restriction added.
- * @see {@link Greater}
- */
- public WikittyQueryMaker gt(String fqfield, Object value) {
- return gt(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Greater}
- */
- public WikittyQueryMaker gt(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new Greater(element, s));
- return this;
- }
-
- /**
- * @see {@link GreaterOrEquals}
- */
- public WikittyQueryMaker ge(Element element) {
- addCondition(new GreaterOrEquals(element));
- return this;
- }
-
- /**
- * Greater than or equals.
- *
- * Search if an element value is greater than or equals to the parameter.
- *
- * @param fqfield the field on which the search is made
- * @param value the value to be compared to
- * @return {@code this} with the {@code ge} restriction added.
- * @see {@link GreaterOrEquals}
- */
- public WikittyQueryMaker ge(String fqfield, Object value) {
- return ge(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link GreaterOrEquals}
- */
- public WikittyQueryMaker ge(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new GreaterOrEquals(element, s));
- return this;
- }
-
- /**
- * @see {@link Less}
- */
- public WikittyQueryMaker lt(Element element) {
- addCondition(new Less(element));
- return this;
- }
-
- /**
- * Less than.
- *
- * Search if an element value is less than the parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value to be compared to
- * @return {@code this} with the {@code lt} restriction added.
- * @see {@link Less}
- */
- public WikittyQueryMaker lt(String fqfield, Object value) {
- return lt(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Less}
- */
- public WikittyQueryMaker lt(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new Less(element, s));
- return this;
- }
-
- /**
- * @see {@link LessOrEquals}
- */
- public WikittyQueryMaker le(Element element) {
- addCondition(new LessOrEquals(element));
- return this;
- }
-
- /**
- * Less than or equals.
- *
- * Search if an element value is less than or equals to the parameter.
- *
- * @param fqfield the element on which the restriction is put.
- * @param value the value to be compared to.
- * @return {@code this} with the {@code le} restriction added.
- * @see {@link LessOrEquals}
- */
- public WikittyQueryMaker le(String fqfield, Object value) {
- return le(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link LessOrEquals}
- */
- public WikittyQueryMaker le(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new LessOrEquals(element, s));
- return this;
- }
-
- /**
- * @see {@link Between}
- */
- public WikittyQueryMaker bw(Element element) {
- addCondition(new Between(element));
- return this;
- }
-
- /**
- * Between.
- *
- * Restrict search so that the element value is between the lower and upper
- * values (it can also be equals).
- *
- * @param fqfield the element on which the restriction is put.
- * @param lowerValue the lower bound.
- * @param upperValue the upper bound.
- * @return {@code this} with the {@code le} restriction added.
- * @see {@link Between}
- */
- public WikittyQueryMaker bw(String fqfield, Object lowerValue, Object upperValue) {
- return bw(Element.get(fqfield), lowerValue, upperValue);
- }
-
- /**
- * @see {@link Between}
- */
- public WikittyQueryMaker bw(Element element, Object lowerValue, Object upperValue) {
- ConditionValue min = convertToConditionValue(lowerValue);
- ConditionValue max = convertToConditionValue(upperValue);
- addCondition(new Between(element, min, max));
- return this;
- }
-
- /**
- * Starts with.
- *
- * Search if an element starts with the value in parameter.
- *
- * @param fqfield the element on which the restriction is put.
- * @param value the value the element must start with.
- * @return {@code this} with the {@code sw} restriction added.
- * @see {@link Equals}
- */
- public WikittyQueryMaker sw(String fqfield, String value) {
- return sw(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker sw(Element element, String value) {
- addCondition(new Equals(element, value + "*"));
- return this;
- }
-
- /**
- * Not starts with.
- *
- * Search if an element does not starts with the value in parameter.
- *
- * @param fqfield the element on which the restriction is put.
- * @param value the value the element must not start with.
- * @return {@code this} with the {@code nsw} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker notsw(String fqfield, String value) {
- return notsw(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker notsw(Element element, String value) {
- addCondition(new NotEquals(element, value + "*"));
- return this;
- }
-
- /**
- * Ends with.
- *
- * Search if an element ends with the value in parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value the element must ends with.
- * @return {@code this} with the {@code ew} restriction added.
- * @see {@link Equals}
- */
- public WikittyQueryMaker ew(String fqfield, Object value) {
- return ew(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Equals}
- */
- public WikittyQueryMaker ew(Element element, Object value) {
- addCondition(new Equals(element, "*" + value));
- return this;
- }
-
- /**
- * Not ends with.
- *
- * Search if an element does not ends with the value in parameter.
- *
- * @param fqfield the element on which the restriction is put
- * @param value the value the element must not ends with.
- * @return {@code this} with the {@code notew} restriction added.
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker notew(String fqfield, Object value) {
- return notew(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link NotEquals}
- */
- public WikittyQueryMaker notew(Element element, Object value) {
- addCondition(new NotEquals(element, "*" + value));
- return this;
- }
-
- /**
- * Keyword.
- *
- * Search if the value in parameter is present in any field of any
- * extension.
- *
- * @param value the value to find.
- * @return {@code this} with the {@code keyword} restriction added.
- * @see {@link Keyword}
- */
- public WikittyQueryMaker keyword() {
- addCondition(new Keyword());
- return this;
- }
-
- /**
- * Keyword.
- *
- * Search if the value in parameter is present in any field of any
- * extension.
- *
- * @param value the value to find.
- * @return {@code this} with the {@code keyword} restriction added.
- * @see {@link Keyword}
- */
- public WikittyQueryMaker keyword(Object value) {
- ConditionValue s = convertToConditionValue(value);
- addCondition(new Keyword().addCondition(s));
- return this;
- }
-
- /**
- * Is null.
- *
- * Check that a field is null.
- *
- * @param fqfield the field that must be null.
- * @return {@code this} with the {@code isNull} restriction added.
- * @see {@link Null}
- */
- public WikittyQueryMaker isNull(String fqfield) {
- return isNull(Element.get(fqfield));
- }
-
- /**
- * @see {@link Null}
- */
- public WikittyQueryMaker isNull(Element element) {
- addCondition(new Null(element));
- return this;
- }
-
- /**
- * Is not null.
- *
- * Check that a field is not null.
- *
- * @param fqfield the field that must not be null.
- * @return {@code this} with the {@code isNotNull} restriction added.
- * @see {@link NotNull}
- */
- public WikittyQueryMaker isNotNull(String fqfield) {
- return isNotNull(Element.get(fqfield));
- }
-
- /**
- * @see {@link NotNull}
- */
- public WikittyQueryMaker isNotNull(Element element) {
- addCondition(new NotNull(element));
- return this;
- }
-
- /**
- * False.
- *
- * Add a restriction that always return false.
- *
- * @return {@code this} with the {@code rFalse} restriction added.
- * @see {@link False}
- */
- public WikittyQueryMaker rFalse() {
- addCondition(new False());
- return this;
- }
-
- /**
- * True.
- *
- * Add a restriction that always return true.
- *
- * @return {@code this} with the {@code rTrue} restriction added.
- * @see {@link True}
- */
- public WikittyQueryMaker rTrue() {
- addCondition(new True());
- return this;
- }
-
- /**
- * @see {@link Like}
- */
- public WikittyQueryMaker like(Element element) {
- addCondition(new Like(element));
- return this;
- }
-
- /**
- * Like.
- *
- * Check that a string is present in a field. For example "tric" is present
- * in "Restriction".
- *
- * @param fqfield the element on which the restriction is put
- * @param value
- * @return {@code this}
- * @see {@link Like}
- */
- public WikittyQueryMaker like(String fqfield, Object value) {
- return like(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Like}
- */
- public WikittyQueryMaker like(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- Like c = new Like(element, s);
- addCondition(c);
- return this;
- }
-
- /**
- * @see {@link Unlike}
- */
- public WikittyQueryMaker unlike(Element element) {
- addCondition(new Unlike(element));
- return this;
- }
-
- /**
- * Unlike.
- *
- * @param fqfield the element on which the restriction is put
- * @param value
- * @param searchAs
- * @return {@code this}
- * @see {@link Unlike}
- */
- public WikittyQueryMaker unlike(String fqfield, Object value) {
- return unlike(Element.get(fqfield), value);
- }
-
- /**
- * @see {@link Unlike}
- */
- public WikittyQueryMaker unlike(Element element, Object value) {
- ConditionValue s = convertToConditionValue(value);
- Unlike c = new Unlike(element, s);
- addCondition(c);
- return this;
- }
-
- /**
- * Not (sub query). To close this sub query you must used {@link #close()}
- * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
- *
- * @see {@link Not}
- */
- public WikittyQueryMaker not() {
- Condition child = new Not();
- addCondition(child);
- return this;
- }
-
- /**
- * Or (sub query). To close this sub query you must used {@link #close()}
- * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
- *
- * @see {@link Or}
- */
- public WikittyQueryMaker or() {
- Condition child = new Or();
- addCondition(child);
- return this;
- }
-
- /**
- * And (sub query). To close this sub query you must used {@link #close()}
- * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
- *
- * @see {@link And}
- */
- public WikittyQueryMaker and() {
- Condition child = new And();
- addCondition(child);
-
- return this;
- }
-
- /**
- * Add {@link Select}, this condition must be first or
- * @param element le champs dont il faut extraire les donnees
- * @return {@code this}
- * @see {@link Select}
- */
- public WikittyQueryMaker select(String element) {
- return select(Element.get(element));
- }
-
- /**
- * Add {@link Select}, this condition must be first or
- * @param element le champs dont il faut extraire les donnees
- * @return {@code this}
- * @see {@link Select}
- */
- public WikittyQueryMaker select(String element, Aggregate aggregate) {
- return select(Element.get(element), aggregate);
- }
-
- /*
- * @see {@link Select}
- */
- public WikittyQueryMaker select(Element element) {
- return select(element, null);
- }
-
- /*
- * @see {@link Select}
- */
- public WikittyQueryMaker select(Element element, Aggregate aggregate) {
- Condition child = new Select(element, aggregate);
- addCondition(child);
- return this;
- }
-
- /**
- * Close last non terminal condition (or, and, not, in).
- * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
- * @return
- */
- public WikittyQueryMaker close() {
- getOpenStack().pop(); // on en ferme 1 obligatoirement
- // on cherche a en fermer plus
- closeIfNecessary();
- return this;
- }
-
- /**
- * Ferme la construction de la condition et la met en place dans la
- * WikittyQuery qui sera retournee
- *
- * @return un objet WikittyQuery soit un nouveau soit celui passe dans le
- * constructeur
- */
- public WikittyQuery end() {
- WikittyQuery result = getQuery();
- result.setCondition(getCondition());
- // on interdit les modifications futur
- openStack = null;
-
- return result;
- }
}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMakerAbstract.java (from rev 1512, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMakerAbstract.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMakerAbstract.java 2012-09-15 12:37:32 UTC (rev 1517)
@@ -0,0 +1,1202 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 CodeLutin, Benjamin Poussin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.query;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.BusinessEntityImpl;
+import org.nuiton.wikitty.entities.Element;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.query.conditions.Aggregate;
+import org.nuiton.wikitty.query.conditions.And;
+import org.nuiton.wikitty.query.conditions.Between;
+import org.nuiton.wikitty.query.conditions.Condition;
+import org.nuiton.wikitty.query.conditions.ConditionValue;
+import org.nuiton.wikitty.query.conditions.ConditionValueString;
+import org.nuiton.wikitty.query.conditions.ContainsAll;
+import org.nuiton.wikitty.query.conditions.ContainsOne;
+import org.nuiton.wikitty.query.conditions.Equals;
+import org.nuiton.wikitty.query.conditions.False;
+import org.nuiton.wikitty.query.conditions.Greater;
+import org.nuiton.wikitty.query.conditions.GreaterOrEquals;
+import org.nuiton.wikitty.query.conditions.Keyword;
+import org.nuiton.wikitty.query.conditions.Less;
+import org.nuiton.wikitty.query.conditions.LessOrEquals;
+import org.nuiton.wikitty.query.conditions.Like;
+import org.nuiton.wikitty.query.conditions.Not;
+import org.nuiton.wikitty.query.conditions.NotEquals;
+import org.nuiton.wikitty.query.conditions.NotNull;
+import org.nuiton.wikitty.query.conditions.Null;
+import org.nuiton.wikitty.query.conditions.Or;
+import org.nuiton.wikitty.query.conditions.Select;
+import org.nuiton.wikitty.query.conditions.True;
+import org.nuiton.wikitty.query.conditions.Unlike;
+
+/**
+ * Cette objet sert a construire une condition a la facon d'un flux.
+ * <p>
+ * Condition c = new WikittyQueryMaker().and().eq("ext.field", "toto").eq("ext.field2", 10).getCondition();
+ * <p>
+ * On peut aussi vouloir continuer avec un WikittyQuery pour cela on peut faire.
+ * <p>
+ * WikittyQuery q = new WikittyQueryMaker().and().[other condition].end();
+ * <p>
+ * Si un {@link WikittyQuery} est passé en parametre du constructeur et que la
+ * method {@link #end()} est appeler alors la condition creee est envoyee dans
+ * le WikittyQuery et le constructeur est fermer (on ne peut plus ajouter de
+ * condition)
+ * <p>
+ * Le WikittyQuery lie avec cet objet lorsqu'on le recupere via la method
+ * {@link #getQuery()} a en interne comme condition la valuer courante de la
+ * condition en cours d'ecriture
+ *
+ * Cette classe est abstraite pour facilite l'heritage pour une utilisation dans
+ * des applications qui auraient besoin d'ajouter des methodes de construction
+ * (par exemple des methodes qui ajouteraient un ensemble de contraintes).
+ *
+ * Pour cela il faut heriter de cette classe et implanter la methode {@link #asM}
+ * Par exemple:
+ * <pre>
+ * class MonMaker extends WikittyQueryMakerAbstract<MonMaker> {
+ *
+ * // ... constructeurs et methodes supplementaires ...
+ *
+ * @Override
+ * MonMaker asM() {
+ * return this;
+ * }
+ * }
+ * </pre>
+ *
+ * @author poussin
+ * @version $Revision$
+ * @since 3.3
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public abstract class WikittyQueryMakerAbstract<M extends WikittyQueryMakerAbstract> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyQueryMakerAbstract.class);
+
+ /** query where to send condition when end() method called */
+ protected WikittyQuery query;
+
+ /** query condition */
+ protected Condition condition;
+ /** stack des conditions non terminales ouvertes */
+ protected Deque<Condition> openStack = new LinkedList<Condition>();
+
+ public WikittyQueryMakerAbstract() {
+ }
+
+ public WikittyQueryMakerAbstract(WikittyQuery query) {
+ this.query = query;
+ }
+
+ protected abstract M asM();
+
+ public Condition getCondition() {
+ return condition;
+ }
+
+ /**
+ * La query passee dans le constructeur ou une nouvelle query si aucune
+ * query n'avait ete passee dans le constructeur
+ *
+ * @return
+ */
+ public WikittyQuery getQuery() {
+ if (query == null) {
+ query = new WikittyQuery();
+ }
+ // la condition de la query doit toujours refleter la valeur courante
+ // de la condition en cours de creation
+ query.setCondition(getCondition());
+ return query;
+ }
+
+ /**
+ * Retourne le stack courant des conditions, si le stack est null cela
+ * veut dire que le maker ne permet plus de modification
+ * @return
+ */
+ protected Deque<Condition> getOpenStack() {
+ if (openStack == null) {
+ throw new WikittyException(
+ "You can't create condition if you have used setCondition method"
+ + " or close last condition");
+ }
+ return openStack;
+ }
+
+ /**
+ * Ajout une condition
+ *
+ */
+ protected void addCondition(Condition c) {
+ addCondition(c, false);
+ }
+ /**
+ * Ajout une condition. Si terminal est true, alors quelque soit le type de
+ * cette condition la stack restera inchange apres l'ajout. Cela permet
+ * d'ajouter des conditions non terminale comme des terminales
+ */
+ protected void addCondition(Condition c, boolean terminal) {
+ Condition parent = getOpenStack().peek();
+ if (!terminal) {
+ // on ne met les conditions toujours dans le stack (meme les terminales)
+ // si c'est la premiere cela permet d'indiquer a l'utilisateur
+ // qu'il faut commencer par un or, and, not car une exception sera
+ // levee car non supprimer par le while dans lequel on ne passe pas
+ // car on passe dans le if et non le else (parent == null)
+ getOpenStack().push(c);
+ }
+
+ if (parent == null) {
+ // il n'y a rien dans la stack donc rien dans condition, il faut
+ // mettre cette condition dedans
+ condition = c;
+ // et on ne depile pas le stack
+ } else {
+ // se add peut lever une exception si parent n'accepte pas cet enfant
+ parent.addCondition(c);
+ // on depile toutes les conditions qui n'ont plus besoin de renseignement
+ // sauf si l'ajout a ete force en terminal
+ if (!terminal) {
+ closeIfNecessary();
+ }
+ }
+ }
+
+ protected void closeIfNecessary() {
+ // on depile toutes les conditions qui n'ont plus besoin de renseignement
+ while (getOpenStack().peek() != null
+ && !getOpenStack().peek().waitCondition()) {
+ getOpenStack().poll();
+ }
+ if (getOpenStack().size() == 0) {
+ // we just close last open condition, set stack to null, to prevent
+ // next condition add that is mistake
+ openStack = null;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Q U E R Y F L O W C R E A T I O N
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ // eq(Wikitty|Date|Number|Boolean|String)
+
+ static protected ConditionValue convertToConditionValue(Object o) {
+ ConditionValue result;
+ if (o instanceof ConditionValue) {
+ result = (ConditionValue)o;
+ } else {
+ String s = WikittyUtil.toString(o);
+ result = new ConditionValueString(s);
+ }
+ return result;
+ }
+
+ public M value(Object value) {
+ ConditionValue v = convertToConditionValue(value);
+ addCondition(v);
+ return this.asM();
+ }
+
+ /**
+ * Ajoute une condition, cette condition est prise comme une condition terminal
+ * Si l'on veut continuer a construire la requete, il faut avoir ajouter
+ * avant une {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
+ * @param c la condition a ajouter
+ * @return {@code this} with the {@code c} restriction added.
+ */
+ public M condition(Condition c) {
+ addCondition(c, true);
+ return this.asM();
+ }
+
+ /**
+ * Parse et ajoute un bout de requete. Cette requete est prise comme une
+ * condition terminal si l'on veut continuer a construire la requete, il
+ * faut avoir ajouter avant une
+ * {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
+ * @param query la requete a ajouter (peut-etre vide ou nul, dans ce cas, la
+ * condition utiliser est "true")
+ * @return {@code this} with the {@code c} restriction added.
+ */
+ public M parse(String query) {
+ if (StringUtils.isNotBlank(query)) {
+ WikittyQuery filter = WikittyQueryParser.parse(query);
+ addCondition(filter.getCondition(), true);
+ } else {
+ addCondition(new True());
+ }
+ return this.asM();
+ }
+
+ /**
+ * Ajoute une contrainte qui cree les conditions en prenant comme exemple
+ * l'objet passer en parametre. Seuls les champs non null sont utilises ainsi
+ * que la liste des extensions de l'objet
+ *
+ * @param w le wikitty a prendre comme exemple
+ * @return {@code this} with the {@code w} restriction added.
+ */
+ public M wikitty(Wikitty w) {
+ WikittyQueryMaker result = new WikittyQueryMaker().and();
+
+ // result object must have same extension that wikitty example
+ result.extContainsAll(w.getExtensionNames());
+
+ for (String fqfieldName : w.fieldNames()) {
+ Object value = w.getFqField(fqfieldName);
+ if (value != null) {
+ FieldType type = w.getFieldType(fqfieldName);
+ if (type.isCollection()) {
+ result.containsAll(fqfieldName, (Collection<?>)value);
+ } else {
+ result.eq(fqfieldName, value);
+ }
+ }
+ }
+ addCondition(result.getCondition());
+
+ return this.asM();
+ }
+
+ /**
+ * Ajoute une contrainte qui cree les conditions en prenant comme exemple
+ * l'objet passer en parametre. Seuls les champs non null sont utilises ainsi
+ * que la liste des extensions de l'objet
+ *
+ * @param e l'objet a prendre comme exemple
+ * @return {@code this} with the {@code e} restriction added.
+ */
+ public M wikitty(BusinessEntityImpl e) {
+ Wikitty w = e.getWikitty();
+ return wikitty(w);
+ }
+
+ /**
+ * @see {@link ContainsAll}
+ */
+ public M containsAll(Element element) {
+ addCondition(new ContainsAll(element));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link ContainsAll}
+ */
+ public M containsAll(String element) {
+ return containsAll(Element.get(element));
+ }
+
+ /**
+ * Contains.
+ *
+ * Search on lists (multivalued fields) that a field contains all the values
+ * of the list given in parameter.
+ *
+ * Ex : The field with value [toto,titi,tutu] contains [titi,tutu] but not
+ * [titi,tutu,tata]
+ *
+ * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @param element the element on which the restriction is put
+ * @param values the values to search in the element
+ * @return {@code this} with the {@code contains} restriction added.
+ * @see {@link ContainsAll}
+ */
+ public <E> M containsAll(String fqfield, Collection<E> values) {
+ return containsAll(Element.get(fqfield), values);
+ }
+
+ /**
+ * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @see {@link ContainsAll}
+ */
+ public <E> M containsAll(Element element, Collection<E> values) {
+ containsAll(element);
+ for (E e : values) {
+ value(e);
+ }
+ close();
+ return this.asM();
+ }
+
+ /**
+ * Search on lists (multivalued fields) that a field contains all the values
+ * given in parameter.
+ *
+ * Ex : The field with value [toto,titi,tutu] contains [titi,tutu] but not
+ * [titi,tutu,tata]
+ *
+ * Ps : Use wildcards if you search for substrings.
+ *
+ * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @param element the element on which the restriction is put
+ * @param value1 first value to search in the field
+ * @param values list of values to search in the field
+ * @return {@code this} with the {@code contains} restriction added.
+ * @see {@link ContainsAll}
+ */
+ public <E> M containsAll(String fqfield, E value1, E ... values) {
+ List<E> l = new LinkedList<E>();
+ l.add(value1);
+ l.addAll(Arrays.asList(values));
+ return containsAll(fqfield, l);
+ }
+
+ /**
+ * @see {@link ContainsOne}
+ */
+ public M containsOne(Element element) {
+ addCondition(new ContainsOne(element));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link ContainsOne}
+ */
+ public M containsOne(String element) {
+ return containsOne(Element.get(element));
+ }
+
+ /**
+ * Search if a field is contained in the list of values in parameter
+ *
+ * Ex : The field with value titi is in [titi,tutu] but not in
+ * [tutu,tata]
+ *
+ * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @param element the element on which the restriction is put
+ * @param values list of values the field must be in
+ * @return {@code this} with the {@code in} restriction added.
+ * @see {@link ContainsOne}
+ */
+ public <E> M containsOne(String fqfield, Collection<E> values) {
+ return containsOne(Element.get(fqfield), values);
+ }
+
+ /**
+ * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @see {@link ContainsOne}
+ */
+ public <E> M containsOne(Element element, Collection<E> values) {
+ containsOne(element);
+ for (E e : values) {
+ value(e);
+ }
+ close();
+ return this.asM();
+ }
+
+ /**
+ * Search if a field is contained in the list of values in parameter
+ *
+ * Ex : The field with value titi is in [titi,tutu] but not in
+ * [tutu,tata]
+ *
+ * Ps : Use wildcards in the values if you search for substrings.
+ *
+ * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * de {@link #close()}
+ *
+ * @param element the element on which the restriction is put
+ * @param value1 first value the field must be in
+ * @param values list of values the field must be in
+ * @return {@code this} with the {@code in} restriction added.
+ * @see {@link ContainsOne}
+ */
+ public <E> M containsOne(String fqfield, E value1, E ... values) {
+ List<E> l = new LinkedList<E>();
+ l.add(value1);
+ l.addAll(Arrays.asList(values));
+ return containsOne(fqfield, l);
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M eq(Element element) {
+ addCondition(new Equals(element));
+ return this.asM();
+ }
+
+ /**
+ * Equals.
+ *
+ * Restrict search so that the field value equals the parameter.
+ *
+ * You might use patterns in your equality.
+ *
+ * @param element the field on which the search is made
+ * @param value the value the element must be equals to
+ * @return {@code this}
+ * @see {@link Equals}
+ */
+ public M eq(String fqfield, Object value) {
+ return eq(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M eq(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new Equals(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M eqIgnoreCaseAndAccent(Element element) {
+ addCondition(new Equals(element, true));
+ return this.asM();
+ }
+
+ /**
+ * Equals.
+ *
+ * Restrict search so that the field value equals the parameter.
+ *
+ * You might use patterns in your equality.
+ *
+ * @param element the field on which the search is made
+ * @param value the value the element must be equals to
+ * @return {@code this}
+ * @see {@link Equals}
+ */
+ public M eqIgnoreCaseAndAccent(String fqfield, Object value) {
+ return eqIgnoreCaseAndAccent(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M eqIgnoreCaseAndAccent(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new Equals(element, s, true));
+ return this.asM();
+ }
+
+ /**
+ * Extension equals.
+ *
+ * Restrict search to wikitties that got the extension in parameter.
+ *
+ * @param s the extension to restrict the results to
+ * @return {@code this} with the {@code exteq} restriction added.
+ * @see {@link Equals}
+ */
+ public M exteq(String extensionName) {
+ return eq(Element.EXTENSION, extensionName);
+ }
+
+ /**
+ * Id equals.
+ *
+ * Restrict search to wikitties that got the id in parameter.
+ *
+ * @param value the id or wikitty to restrict the results to
+ * @return {@code this} with the {@code ideq} restriction added.
+ * @see {@link Equals}
+ */
+ public M ideq(Object idOrWikitty) {
+ return eq(Element.ID, idOrWikitty);
+ }
+
+ /**
+ * Extension equals.
+ *
+ * Restrict search to wikitties that got all the extensions in parameter.
+ *
+ * @param extensionNames list of the extension to restrict the results to
+ * @return {@code this} with the {@code exteq} restriction added.
+ * @see {@link ContainsAll}
+ */
+ public M extContainsAll(Collection<String> extensionNames) {
+ return containsAll(Element.EXTENSION, extensionNames);
+ }
+
+ /**
+ * @see {@link ContainsAll}
+ */
+ public M extContainsAll(String ext1, String ... exts) {
+ List<String> l = new LinkedList<String>();
+ l.add(ext1);
+ l.addAll(Arrays.asList(exts));
+ return containsAll(Element.EXTENSION, l);
+ }
+
+ /**
+ * Extension equals.
+ *
+ * Restrict search to wikitties that got one of the extensions in parameter.
+ *
+ * @param extensionNames list of the extension to restrict the results to
+ * @return {@code this} with the {@code exteq} restriction added.
+ * @see {@link ContainsAll}
+ */
+ public M extContainsOne(Collection<String> extensionNames) {
+ return containsOne(Element.EXTENSION, extensionNames);
+ }
+
+ /**
+ * @see {@link ContainsOne}
+ */
+ public M extContainsOne(String ext1, String ... exts) {
+ List<String> l = new LinkedList<String>();
+ l.add(ext1);
+ l.addAll(Arrays.asList(exts));
+ return containsOne(Element.EXTENSION, l);
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M ne(Element element) {
+ addCondition(new NotEquals(element));
+ return this.asM();
+ }
+
+ /**
+ * Not equals.
+ *
+ * Restrict search to elements that are not equals to the value given in
+ * parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value the element must not be equals to.
+ * @return {@code this} with the {@code neq} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M ne(String fqfield, Object value) {
+ return ne(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M ne(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new NotEquals(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M neIgnoreCaseAndAccent(Element element) {
+ addCondition(new NotEquals(element, true));
+ return this.asM();
+ }
+
+ /**
+ * Not equals.
+ *
+ * Restrict search to elements that are not equals to the value given in
+ * parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value the element must not be equals to.
+ * @return {@code this} with the {@code neq} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M neIgnoreCaseAndAccent(String fqfield, Object value) {
+ return neIgnoreCaseAndAccent(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M neIgnoreCaseAndAccent(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new NotEquals(element, s, true));
+ return this.asM();
+ }
+
+ /**
+ * Extension not equals.
+ *
+ * Restrict search to wikitties that do not get the extension given in
+ * parameter.
+ *
+ * @param extensionName the extension that the wikitties must not have.
+ * @return {@code this} with the {@code extneq} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M extne(String extensionName) {
+ return ne(Element.EXTENSION, extensionName);
+ }
+
+ /**
+ * Id not equals.
+ *
+ * Restrict search to wikitties that do not have the id given in parameter.
+ *
+ * @param idOrWikitty the id the wikitties must not have.
+ * @return {@code this} with the {@code idne} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M idne(Object idOrWikitty) {
+ return ne(Element.ID, idOrWikitty);
+ }
+
+ /**
+ * @see {@link Greater}
+ */
+ public M gt(Element element) {
+ addCondition(new Greater(element));
+ return this.asM();
+ }
+
+ /**
+ * Greater than.
+ *
+ * Search if an element value is greater than the parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value to be compared to
+ * @return {@code this} with the {@code gt} restriction added.
+ * @see {@link Greater}
+ */
+ public M gt(String fqfield, Object value) {
+ return gt(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Greater}
+ */
+ public M gt(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new Greater(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link GreaterOrEquals}
+ */
+ public M ge(Element element) {
+ addCondition(new GreaterOrEquals(element));
+ return this.asM();
+ }
+
+ /**
+ * Greater than or equals.
+ *
+ * Search if an element value is greater than or equals to the parameter.
+ *
+ * @param fqfield the field on which the search is made
+ * @param value the value to be compared to
+ * @return {@code this} with the {@code ge} restriction added.
+ * @see {@link GreaterOrEquals}
+ */
+ public M ge(String fqfield, Object value) {
+ return ge(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link GreaterOrEquals}
+ */
+ public M ge(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new GreaterOrEquals(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link Less}
+ */
+ public M lt(Element element) {
+ addCondition(new Less(element));
+ return this.asM();
+ }
+
+ /**
+ * Less than.
+ *
+ * Search if an element value is less than the parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value to be compared to
+ * @return {@code this} with the {@code lt} restriction added.
+ * @see {@link Less}
+ */
+ public M lt(String fqfield, Object value) {
+ return lt(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Less}
+ */
+ public M lt(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new Less(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link LessOrEquals}
+ */
+ public M le(Element element) {
+ addCondition(new LessOrEquals(element));
+ return this.asM();
+ }
+
+ /**
+ * Less than or equals.
+ *
+ * Search if an element value is less than or equals to the parameter.
+ *
+ * @param fqfield the element on which the restriction is put.
+ * @param value the value to be compared to.
+ * @return {@code this} with the {@code le} restriction added.
+ * @see {@link LessOrEquals}
+ */
+ public M le(String fqfield, Object value) {
+ return le(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link LessOrEquals}
+ */
+ public M le(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new LessOrEquals(element, s));
+ return this.asM();
+ }
+
+ /**
+ * @see {@link Between}
+ */
+ public M bw(Element element) {
+ addCondition(new Between(element));
+ return this.asM();
+ }
+
+ /**
+ * Between.
+ *
+ * Restrict search so that the element value is between the lower and upper
+ * values (it can also be equals).
+ *
+ * @param fqfield the element on which the restriction is put.
+ * @param lowerValue the lower bound.
+ * @param upperValue the upper bound.
+ * @return {@code this} with the {@code le} restriction added.
+ * @see {@link Between}
+ */
+ public M bw(String fqfield, Object lowerValue, Object upperValue) {
+ return bw(Element.get(fqfield), lowerValue, upperValue);
+ }
+
+ /**
+ * @see {@link Between}
+ */
+ public M bw(Element element, Object lowerValue, Object upperValue) {
+ ConditionValue min = convertToConditionValue(lowerValue);
+ ConditionValue max = convertToConditionValue(upperValue);
+ addCondition(new Between(element, min, max));
+ return this.asM();
+ }
+
+ /**
+ * Starts with.
+ *
+ * Search if an element starts with the value in parameter.
+ *
+ * @param fqfield the element on which the restriction is put.
+ * @param value the value the element must start with.
+ * @return {@code this} with the {@code sw} restriction added.
+ * @see {@link Equals}
+ */
+ public M sw(String fqfield, String value) {
+ return sw(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M sw(Element element, String value) {
+ addCondition(new Equals(element, value + "*"));
+ return this.asM();
+ }
+
+ /**
+ * Not starts with.
+ *
+ * Search if an element does not starts with the value in parameter.
+ *
+ * @param fqfield the element on which the restriction is put.
+ * @param value the value the element must not start with.
+ * @return {@code this} with the {@code nsw} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M notsw(String fqfield, String value) {
+ return notsw(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M notsw(Element element, String value) {
+ addCondition(new NotEquals(element, value + "*"));
+ return this.asM();
+ }
+
+ /**
+ * Ends with.
+ *
+ * Search if an element ends with the value in parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value the element must ends with.
+ * @return {@code this} with the {@code ew} restriction added.
+ * @see {@link Equals}
+ */
+ public M ew(String fqfield, Object value) {
+ return ew(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Equals}
+ */
+ public M ew(Element element, Object value) {
+ addCondition(new Equals(element, "*" + value));
+ return this.asM();
+ }
+
+ /**
+ * Not ends with.
+ *
+ * Search if an element does not ends with the value in parameter.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value the value the element must not ends with.
+ * @return {@code this} with the {@code notew} restriction added.
+ * @see {@link NotEquals}
+ */
+ public M notew(String fqfield, Object value) {
+ return notew(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link NotEquals}
+ */
+ public M notew(Element element, Object value) {
+ addCondition(new NotEquals(element, "*" + value));
+ return this.asM();
+ }
+
+ /**
+ * Keyword.
+ *
+ * Search if the value in parameter is present in any field of any
+ * extension.
+ *
+ * @param value the value to find.
+ * @return {@code this} with the {@code keyword} restriction added.
+ * @see {@link Keyword}
+ */
+ public M keyword() {
+ addCondition(new Keyword());
+ return this.asM();
+ }
+
+ /**
+ * Keyword.
+ *
+ * Search if the value in parameter is present in any field of any
+ * extension.
+ *
+ * @param value the value to find.
+ * @return {@code this} with the {@code keyword} restriction added.
+ * @see {@link Keyword}
+ */
+ public M keyword(Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ addCondition(new Keyword().addCondition(s));
+ return this.asM();
+ }
+
+ /**
+ * Is null.
+ *
+ * Check that a field is null.
+ *
+ * @param fqfield the field that must be null.
+ * @return {@code this} with the {@code isNull} restriction added.
+ * @see {@link Null}
+ */
+ public M isNull(String fqfield) {
+ return isNull(Element.get(fqfield));
+ }
+
+ /**
+ * @see {@link Null}
+ */
+ public M isNull(Element element) {
+ addCondition(new Null(element));
+ return this.asM();
+ }
+
+ /**
+ * Is not null.
+ *
+ * Check that a field is not null.
+ *
+ * @param fqfield the field that must not be null.
+ * @return {@code this} with the {@code isNotNull} restriction added.
+ * @see {@link NotNull}
+ */
+ public M isNotNull(String fqfield) {
+ return isNotNull(Element.get(fqfield));
+ }
+
+ /**
+ * @see {@link NotNull}
+ */
+ public M isNotNull(Element element) {
+ addCondition(new NotNull(element));
+ return this.asM();
+ }
+
+ /**
+ * False.
+ *
+ * Add a restriction that always return false.
+ *
+ * @return {@code this} with the {@code rFalse} restriction added.
+ * @see {@link False}
+ */
+ public M rFalse() {
+ addCondition(new False());
+ return this.asM();
+ }
+
+ /**
+ * True.
+ *
+ * Add a restriction that always return true.
+ *
+ * @return {@code this} with the {@code rTrue} restriction added.
+ * @see {@link True}
+ */
+ public M rTrue() {
+ addCondition(new True());
+ return this.asM();
+ }
+
+ /**
+ * @see {@link Like}
+ */
+ public M like(Element element) {
+ addCondition(new Like(element));
+ return this.asM();
+ }
+
+ /**
+ * Like.
+ *
+ * Check that a string is present in a field. For example "tric" is present
+ * in "Restriction".
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value
+ * @return {@code this}
+ * @see {@link Like}
+ */
+ public M like(String fqfield, Object value) {
+ return like(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Like}
+ */
+ public M like(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ Like c = new Like(element, s);
+ addCondition(c);
+ return this.asM();
+ }
+
+ /**
+ * @see {@link Unlike}
+ */
+ public M unlike(Element element) {
+ addCondition(new Unlike(element));
+ return this.asM();
+ }
+
+ /**
+ * Unlike.
+ *
+ * @param fqfield the element on which the restriction is put
+ * @param value
+ * @param searchAs
+ * @return {@code this}
+ * @see {@link Unlike}
+ */
+ public M unlike(String fqfield, Object value) {
+ return unlike(Element.get(fqfield), value);
+ }
+
+ /**
+ * @see {@link Unlike}
+ */
+ public M unlike(Element element, Object value) {
+ ConditionValue s = convertToConditionValue(value);
+ Unlike c = new Unlike(element, s);
+ addCondition(c);
+ return this.asM();
+ }
+
+ /**
+ * Not (sub query). To close this sub query you must used {@link #close()}
+ * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
+ *
+ * @see {@link Not}
+ */
+ public M not() {
+ Condition child = new Not();
+ addCondition(child);
+ return this.asM();
+ }
+
+ /**
+ * Or (sub query). To close this sub query you must used {@link #close()}
+ * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
+ *
+ * @see {@link Or}
+ */
+ public M or() {
+ Condition child = new Or();
+ addCondition(child);
+ return this.asM();
+ }
+
+ /**
+ * And (sub query). To close this sub query you must used {@link #close()}
+ * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
+ *
+ * @see {@link And}
+ */
+ public M and() {
+ Condition child = new And();
+ addCondition(child);
+
+ return this.asM();
+ }
+
+ /**
+ * Add {@link Select}, this condition must be first or
+ * @param element le champs dont il faut extraire les donnees
+ * @return {@code this}
+ * @see {@link Select}
+ */
+ public M select(String element) {
+ return select(Element.get(element));
+ }
+
+ /**
+ * Add {@link Select}, this condition must be first or
+ * @param element le champs dont il faut extraire les donnees
+ * @return {@code this}
+ * @see {@link Select}
+ */
+ public M select(String element, Aggregate aggregate) {
+ return select(Element.get(element), aggregate);
+ }
+
+ /*
+ * @see {@link Select}
+ */
+ public M select(Element element) {
+ return select(element, null);
+ }
+
+ /*
+ * @see {@link Select}
+ */
+ public M select(Element element, Aggregate aggregate) {
+ Condition child = new Select(element, aggregate);
+ addCondition(child);
+ return this.asM();
+ }
+
+ /**
+ * Close last non terminal condition (or, and, not, in).
+ * <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
+ * @return
+ */
+ public M close() {
+ getOpenStack().pop(); // on en ferme 1 obligatoirement
+ // on cherche a en fermer plus
+ closeIfNecessary();
+ return this.asM();
+ }
+
+ /**
+ * Ferme la construction de la condition et la met en place dans la
+ * WikittyQuery qui sera retournee
+ *
+ * @return un objet WikittyQuery soit un nouveau soit celui passe dans le
+ * constructeur
+ */
+ public WikittyQuery end() {
+ WikittyQuery result = getQuery();
+ result.setCondition(getCondition());
+ // on interdit les modifications futur
+ openStack = null;
+
+ return result;
+ }
+}
1
0
15 Sep '12
Author: bpoussin
Date: 2012-09-15 13:24:28 +0200 (Sat, 15 Sep 2012)
New Revision: 1516
Url: http://nuiton.org/repositories/revision/wikitty/1516
Log:
modif des tests suite a la modification de l'implantation de format
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java 2012-09-13 23:52:35 UTC (rev 1515)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java 2012-09-15 11:24:28 UTC (rev 1516)
@@ -104,24 +104,25 @@
result = WikittyUtil.format(
"Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"toto$s",
group.getWikitty());
- Assert.assertEquals("Group Name = null", result);
+ Assert.assertEquals("Group Name = WikittyGroup.nametoto", result);
// test un cas ou le champs demande n'existe pas dans le wikitty (sans remplacement)
// avec deux fois le meme champs
result = WikittyUtil.format(
"Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"toto$s(%"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"tata$s)",
group.getWikitty());
- Assert.assertEquals("Group Name = null(null)", result);
+ Assert.assertEquals("Group Name = WikittyGroup.nametoto(WikittyGroup.nametata)", result);
+ group = new WikittyGroupImpl();
// test un cas ou le champs demande n'existe pas dans le wikitty (avec remplacement vide)
result = WikittyUtil.format(
- "Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"toto|$s",
+ "Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"|$s",
group.getWikitty());
Assert.assertEquals("Group Name = ", result);
// test un cas ou le champs demande n'existe pas dans le wikitty (avec remplacement
result = WikittyUtil.format(
- "Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"toto|noname$s",
+ "Group Name = %"+WikittyGroupImpl.FQ_FIELD_WIKITTYGROUP_NAME+"|noname$s",
group.getWikitty());
Assert.assertEquals("Group Name = noname", result);
}
1
0
13 Sep '12
Author: bpoussin
Date: 2012-09-14 01:52:35 +0200 (Fri, 14 Sep 2012)
New Revision: 1515
Url: http://nuiton.org/repositories/revision/wikitty/1515
Log:
support des dates qui sorte de solr
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-09-13 16:55:22 UTC (rev 1514)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-09-13 23:52:35 UTC (rev 1515)
@@ -142,6 +142,7 @@
"yyyyMMdd",
"yyyy-MM-dd",
"yyyy-MM-dd hh:mm",
+ "yyyy-MM-dd'T'hh:mm:ss'Z'"
};
/** no break space, used to parse BigDecimal */
1
0
r1514 - in trunk/wikitty-api/src/main/java/org/nuiton/wikitty: . services
by bpoussin@users.nuiton.org 13 Sep '12
by bpoussin@users.nuiton.org 13 Sep '12
13 Sep '12
Author: bpoussin
Date: 2012-09-13 18:55:22 +0200 (Thu, 13 Sep 2012)
New Revision: 1514
Url: http://nuiton.org/repositories/revision/wikitty/1514
Log:
changement du commentaire, car on efface pas que l'indexe, on
efface aussi les donn?\195?\169es
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyClient.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyClient.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyClient.java 2012-09-13 16:54:57 UTC (rev 1513)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyClient.java 2012-09-13 16:55:22 UTC (rev 1514)
@@ -1479,7 +1479,7 @@
}
/**
- * Use with caution : It will delete ALL indexes from search engine !
+ * Use with caution : It will delete ALL data !
* This operation should be disabled in production environment.
*
* @return clear event
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2012-09-13 16:54:57 UTC (rev 1513)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2012-09-13 16:55:22 UTC (rev 1514)
@@ -132,7 +132,7 @@
*/
/**
- * Use with caution : It will delete ALL indexes from search engine !
+ * Use with caution : It will delete ALL data !
* This operation should be disabled in production environment.
*
* @param securityToken security token
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2012-09-13 16:54:57 UTC (rev 1513)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2012-09-13 16:55:22 UTC (rev 1514)
@@ -818,7 +818,7 @@
}
/**
- * Use with caution : It will delete ALL indexes from search engine !
+ * Use with caution : It will delete ALL data !
* This operation should be disabled in production environment.
*/
@Override
1
0
13 Sep '12
Author: bpoussin
Date: 2012-09-13 18:54:57 +0200 (Thu, 13 Sep 2012)
New Revision: 1513
Url: http://nuiton.org/repositories/revision/wikitty/1513
Log:
Wikitty.format permet maintenant de mettre un autre champs comme
valeur par defaut (utiliser pour les toString)
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-09-10 06:41:03 UTC (rev 1512)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-09-13 16:54:57 UTC (rev 1513)
@@ -454,42 +454,12 @@
for (Pair<String, String> pair : fields) {
String fieldAsked = pair.getKey();
String defaultValue = pair.getValue();
- Wikitty wtmp = w;
- // recherche de l'objet reel sur lequel prendre la valeur du champs
- if (StringUtils.contains(fieldAsked, ",")) {
- String path = StringUtils.substringBeforeLast(fieldAsked, ",");
- fieldAsked = StringUtils.substringAfterLast(fieldAsked, ",");
- for (String field : StringUtils.split(path, ",")) {
- if (wtmp.hasField(field)) {
- String extName = WikittyExtension.extractExtensionName(field);
- String fieldName = WikittyExtension.extractFieldName(field);
- wtmp = wtmp.getFieldAsWikitty(extName, fieldName, false);
- } else {
- wtmp = null;
- }
- if (wtmp == null) {
- break;
- }
- }
- }
- Object value = null;
- if(wtmp != null) {
- // recuperation de la valeur du champs
- if (wtmp.hasField(fieldAsked)) {
- String extName = WikittyExtension.extractExtensionName(fieldAsked);
- String fieldName = WikittyExtension.extractFieldName(fieldAsked);
- // on essai toujours de recuperer l'objet plutot que l'id si
- // possible en 1er
- value = wtmp.getFieldAsWikitty(extName, fieldName, false);
- if (value == null) {
- // pas un wikitty ou pas pre-charge, on demande simplement le champs
- value = wtmp.getFqField(fieldAsked);
- }
- }
- }
+ Object value = getValue(w, fieldAsked);
+ Object defaultValueObject = getValue(w, defaultValue);
+
// on ajoute dans la liste la valeur du champs
- values.add(ObjectUtils.defaultIfNull(value, defaultValue));
+ values.add(ObjectUtils.defaultIfNull(value, defaultValueObject));
}
if (log.isDebugEnabled()) {
@@ -502,6 +472,56 @@
}
/**
+ * Recupere la valeur du champs pointer par fieldAsked. Si fieldAsked contient
+ * des ',' alors on parcours les differents objets pour arrive a satisfaire la demande
+ * Si fieldAsked ne represente pas un champs alors on retourne fieldAsked
+ * @param w
+ * @param fieldAsked
+ * @return
+ */
+ static private Object getValue(Wikitty w, String fieldAsked) {
+ String initialFieldAsked = fieldAsked;
+ Wikitty wtmp = w;
+ // recherche de l'objet reel sur lequel prendre la valeur du champs
+ if (StringUtils.contains(fieldAsked, ",")) {
+ String path = StringUtils.substringBeforeLast(fieldAsked, ",");
+ fieldAsked = StringUtils.substringAfterLast(fieldAsked, ",");
+ for (String field : StringUtils.split(path, ",")) {
+ if (wtmp.hasField(field)) {
+ String extName = WikittyExtension.extractExtensionName(field);
+ String fieldName = WikittyExtension.extractFieldName(field);
+ wtmp = wtmp.getFieldAsWikitty(extName, fieldName, false);
+ } else {
+ wtmp = null;
+ }
+ if (wtmp == null) {
+ break;
+ }
+ }
+ }
+
+ Object value = null;
+ if(wtmp != null) {
+ // recuperation de la valeur du champs
+ if (wtmp.hasField(fieldAsked)) {
+ String extName = WikittyExtension.extractExtensionName(fieldAsked);
+ String fieldName = WikittyExtension.extractFieldName(fieldAsked);
+ // on essai toujours de recuperer l'objet plutot que l'id si
+ // possible en 1er
+ value = wtmp.getFieldAsWikitty(extName, fieldName, false);
+ if (value == null) {
+ // pas un wikitty ou pas pre-charge, on demande simplement le champs
+ value = wtmp.getFqField(fieldAsked);
+ }
+ } else {
+ // on a pas trouver le champs, on retourne la chaine car ce n'etait pas un champs
+ value = initialFieldAsked;
+ }
+ }
+ return value;
+ }
+
+ /**
* Get value as Binary.
*
* @param value null and empty return empty byte[]
1
0
r1512 - in trunk: src/site/rst/user wikitty-api/src/main/java/org/nuiton/wikitty/query
by bpoussin@users.nuiton.org 10 Sep '12
by bpoussin@users.nuiton.org 10 Sep '12
10 Sep '12
Author: bpoussin
Date: 2012-09-10 08:41:03 +0200 (Mon, 10 Sep 2012)
New Revision: 1512
Url: http://nuiton.org/repositories/revision/wikitty/1512
Log:
Mise a jour de la documentation
- suppression des In
- ajout de #offset, #limit, #depth
Modified:
trunk/src/site/rst/user/query.rst
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java
Modified: trunk/src/site/rst/user/query.rst
===================================================================
--- trunk/src/site/rst/user/query.rst 2012-09-10 06:40:20 UTC (rev 1511)
+++ trunk/src/site/rst/user/query.rst 2012-09-10 06:41:03 UTC (rev 1512)
@@ -543,59 +543,111 @@
Quelques exemples
+++++++++++++++++
-.. FIXME wrong doc, in doesn't exists anymore
-
Pour avoir tous les attachments de tous les noeuds de tous les arbres::
WikittyQuery q = new WikittyQueryMaker()
- .in(Element.ID)
+ .containsOne(Element.ID)
.select(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_ATTACHMENT).end();
WikittyQuery q = WikittyQueryParser.parse(
- "id IN (SELECT WikittyTreeNode.attachment)");
+ "id={SELECT WikittyTreeNode.attachment}");
Pour avoir tous les attachments de tous les noeuds d'un arbre ayant le nom 'MyTree'::
WikittyQuery q = new WikittyQueryMaker()
- .in(Element.ID)
+ .containsOne(Element.ID)
.select(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_ATTACHMENT)
- .in(Element.ROOT_NODE)
- .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyTree").end();
+ .containsOne(Element.ROOT_NODE)
+ .select(Element.ID)
+ .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyTree").end();
WikittyQuery q = WikittyQueryParser.parse(
- "id IN (SELECT WikittyTreeNode.attachment WHERE rootNode IN (WikittyTreeNode.name=MyTree))");
+ "id={SELECT WikittyTreeNode.attachment WHERE rootNode={SELECT id WHERE (WikittyTreeNode.name=MyTree)}");
Pour avoir tous les attachments d'un sous arbre commencant à un noeud ayant
le nom "MyBranch" d'un arbre ayant le nom 'MyTree'::
WikittyQuery q = new WikittyQueryMaker()
- .in(Element.ID)
+ .containsOne(Element.ID)
.select(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_ATTACHMENT)
.and()
- .in(Element.ROOT_NODE)
- .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyTree")
+ .containsOne(Element.ROOT_NODE)
+ .select(Element.ID)
+ .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyTree")
.close();
- .in(Element.PATH_NODE)
- .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyBranch").end();
+ .containsOne(Element.PATH_NODE)
+ .select(Element.ID)
+ .eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyBranch").end();
- WikittyQuery q = WikittyQueryParser.parse("id IN (SELECT WikittyTreeNode.attachment WHERE
- + " rootNode IN (WikittyTreeNode.name=MyTree) AND pathNode IN (WikittyTreeNode.name=MyBranch))");
+ WikittyQuery q = WikittyQueryParser.parse("id={SELECT WikittyTreeNode.attachment WHERE
+ + " (rootNode={SELECT id WHERE (WikittyTreeNode.name=MyTree)} AND"
+ + " pathNode={SELECT id WHERE (WikittyTreeNode.name=MyBranch)})}");
Pour avoir tous les attachments d'un arbre ayant le nom 'MyTree' jusqu'à une
profondeur de 3 (root, fils, sous fils)::
WikittyQuery q = new WikittyQueryMaker()
- .in(Element.ID)
+ .containsOne(Element.ID)
.select(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_ATTACHMENT)
.and()
- .in(Element.ROOT_NODE)
+ .containsOne(Element.ROOT_NODE)
.eq(WikittyTreeNode.ELEMENT_FIELD_WIKITTYTREENODE_NAME, "MyTree")
.close();
.le(Element.PATH_NODE, 3).end();
- WikittyQuery q = WikittyQueryParser.parse("id IN (SELECT WikittyTreeNode.attachment WHERE
- + " rootNode IN (WikittyTreeNode.name=MyTree) AND pathNode<=3)");
+ WikittyQuery q = WikittyQueryParser.parse("id={(SELECT WikittyTreeNode.attachment WHERE
+ + " rootNode={SELECT Element.ID WHERE (WikittyTreeNode.name=MyTree)} AND pathNode<=3)}");
+Limiter et étendre les recherches
+---------------------------------
+
+Il est possible de restraindre la plage de résultats retournés. Mais aussi
+de demander à ce que les recherches se fasse aussi sur les relations entres
+objet pour une profondeur donnée.
+
+offset
+++++++
+
+Indique le premier résultat qui doit être retourné.
+
+Si on souhaite seulement les résultats à partir du 10ème::
+
+ WikittyQuery q = new WikittyQueryMaker().rTrue().end();
+ q.setOffset(10);
+
+ WikittyQuery q = WikittyQueryParser.parse("TRUE #offset 10");
+
+limit
++++++
+
+Indique le nombre de résultats qui doit être retournés.
+
+Si on souhaite seulement avoir 20 résultats::
+
+ WikittyQuery q = new WikittyQueryMaker().rTrue().end();
+ q.setLimit(20);
+
+ WikittyQuery q = WikittyQueryParser.parse("TRUE #limit 20");
+
+depth
++++++
+
+Indique la profondeur de recherche, c'est à dire le nombre de fois que l'on suite
+les relations.
+
+Par exemple si on a des 'Person' qui appartiennent à une 'Company'. 'Person' ne
+contient que l'id d'une company. Il faut donc faire des containsOne avec un select
+si on veut faire des contraintes sur les personnes appartenants à une company.
+
+Si on souhaite toutes les personnes s'appelant Jean de la Company 'Code Lutin'::
+
+ WikittyQuery q = WikittyQueryParser.parse("Couteau 'Code lutin' #depth 1");
+
+Il faut faire attention car on ne travail pas sur le nom des champs, les recherches
+se font dans ce cas la toujours en fulltext. Donc vous pouvez avoir beaucoup
+plus de résultat qu'attendu. Mettre une profondeur de plus de 1 peut avoir
+des conséquences non négligeable sur les performances de recherche.
+
Spécificité de WikittyQueryMaker
--------------------------------
@@ -736,7 +788,7 @@
* Nom : name - Nommage de la requête.
-* Premier index : first - Permet de définir le premier index à retourner.
+* Premier index : offset - Permet de définir le premier index à retourner.
Principalement utilisé pour la pagination.
* Nombre : limit - Permet de définir le nombre de résultat à retourner.
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java 2012-09-10 06:40:20 UTC (rev 1511)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryMaker.java 2012-09-10 06:41:03 UTC (rev 1512)
@@ -35,18 +35,17 @@
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.entities.BusinessEntityImpl;
+import org.nuiton.wikitty.entities.Element;
import org.nuiton.wikitty.entities.FieldType;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.query.conditions.Aggregate;
import org.nuiton.wikitty.query.conditions.And;
import org.nuiton.wikitty.query.conditions.Between;
-import org.nuiton.wikitty.query.conditions.ConditionValue;
import org.nuiton.wikitty.query.conditions.Condition;
+import org.nuiton.wikitty.query.conditions.ConditionValue;
import org.nuiton.wikitty.query.conditions.ConditionValueString;
import org.nuiton.wikitty.query.conditions.ContainsAll;
import org.nuiton.wikitty.query.conditions.ContainsOne;
-import org.nuiton.wikitty.entities.Element;
-import org.nuiton.wikitty.entities.ElementField;
import org.nuiton.wikitty.query.conditions.Equals;
import org.nuiton.wikitty.query.conditions.False;
import org.nuiton.wikitty.query.conditions.Greater;
@@ -223,7 +222,7 @@
/**
* Ajoute une condition, cette condition est prise comme une condition terminal
* Si l'on veut continuer a construire la requete, il faut avoir ajouter
- * avant une {@link #and()}, {@link #or()}, {@link #not()}, {@link #in()}
+ * avant une {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
* @param c la condition a ajouter
* @return {@code this} with the {@code c} restriction added.
*/
@@ -236,7 +235,7 @@
* Parse et ajoute un bout de requete. Cette requete est prise comme une
* condition terminal si l'on veut continuer a construire la requete, il
* faut avoir ajouter avant une
- * {@link #and()}, {@link #or()}, {@link #not()}, {@link #in()}
+ * {@link #and()}, {@link #or()}, {@link #not()}, {@link #containsOne()}
* @param query la requete a ajouter (peut-etre vide ou nul, dans ce cas, la
* condition utiliser est "true")
* @return {@code this} with the {@code c} restriction added.
@@ -391,7 +390,7 @@
* Ex : The field with value titi is in [titi,tutu] but not in
* [tutu,tata]
*
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
* de {@link #close()}
*
* @param element the element on which the restriction is put
@@ -404,7 +403,7 @@
}
/**
- * Force l'ajout du containsAll en terminal (il n'y a pas besoin de faire
+ * Force l'ajout du containsOne en terminal (il n'y a pas besoin de faire
* de {@link #close()}
*
* @see {@link ContainsOne}
@@ -1153,26 +1152,6 @@
return this;
}
-// /**
-// * Add {@link In} to allow search on association (like sql join).
-// * To close this sub query you must used {@link #close()}
-// * @param foreignFieldName association fieldName
-// * @return {@code this}
-// * @see {@link In}
-// */
-// public WikittyQueryMaker in(String foreignFieldName) {
-// return in(Element.get(foreignFieldName));
-// }
-//
-// /*
-// * @see {@link In}
-// */
-// public WikittyQueryMaker in(Element element) {
-// Condition child = new In(element);
-// addCondition(child);
-// return this;
-// }
-//
/**
* Close last non terminal condition (or, and, not, in).
* <li>ex: WikittyQueryMaker().not().rTrue().close().and().rTrue().rFalse().close().or().rTrue().rFalse().close();
1
0
r1511 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query
by bpoussin@users.nuiton.org 10 Sep '12
by bpoussin@users.nuiton.org 10 Sep '12
10 Sep '12
Author: bpoussin
Date: 2012-09-10 08:40:20 +0200 (Mon, 10 Sep 2012)
New Revision: 1511
Url: http://nuiton.org/repositories/revision/wikitty/1511
Log:
- On permet de pas avoir de clause Where dans ce cas c'est equivalent
a WHERE TRUE
- gere les requetes null comme les requetes ""
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java 2012-09-10 05:42:27 UTC (rev 1510)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java 2012-09-10 06:40:20 UTC (rev 1511)
@@ -236,6 +236,9 @@
* @return
*/
static public WikittyQuery parse(String queryString, Map<String, String> alias) {
+ if (queryString == null) {
+ queryString = "";
+ }
if (alias != null) {
String queryStringInit = queryString;
// on synchronise l'utilisation de la map, pour etre sur qu'il n'y
@@ -476,7 +479,8 @@
}
Rule select() {
Var<Aggregate> aggregate = new Var<Aggregate>();
- return Sequence(icSELECT, space(), Optional(aggregate(aggregate)), space(), field(), push(match()), space(), icWHERE, space(), term(),
+ return Sequence(icSELECT, space(), Optional(aggregate(aggregate)), space(), field(), push(match()), space(),
+ FirstOf(Sequence(icWHERE, space(), term()), empty()),
push(new Select(toElement(pop(1).toString()), aggregate.get(), (Condition)pop())));
}
Rule aggregate(Var<Aggregate> aggregate) {
1
0
r1510 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query
by bpoussin@users.nuiton.org 10 Sep '12
by bpoussin@users.nuiton.org 10 Sep '12
10 Sep '12
Author: bpoussin
Date: 2012-09-10 07:42:27 +0200 (Mon, 10 Sep 2012)
New Revision: 1510
Url: http://nuiton.org/repositories/revision/wikitty/1510
Log:
Evolution #2307: Enhance parser to support #depth as WikittyFieldSearchDepth
Evolution #2308: enhance parser to support empty query as True
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java 2012-08-30 14:44:42 UTC (rev 1509)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java 2012-09-10 05:42:27 UTC (rev 1510)
@@ -128,9 +128,11 @@
public static final String OFFSET = "#OFFSET";
public static final String LIMIT = "#LIMIT";
+ public static final String DEPTH = "#DEPTH";
public Rule icOFFSET = IgnoreCase(OFFSET);
public Rule icLIMIT = IgnoreCase(LIMIT);
+ public Rule icDEPTH = IgnoreCase(DEPTH);
public Rule icEXTENSION = IgnoreCase(Element.EXTENSION.getValue());
public Rule icID = IgnoreCase(Element.ID.getValue());
@@ -309,10 +311,14 @@
}
Rule start() {
- return Sequence(or(), push(new WikittyQuery((Condition)pop())),
- offset(), limit(), space(), EOI);
+ return Sequence(FirstOf(or(), empty()), push(new WikittyQuery((Condition)pop())),
+ offset(), limit(), depth(), space(), EOI);
}
+ Rule empty() {
+ return Sequence(EMPTY, push(new True()));
+ }
+
Rule offset() {
return Optional(space(), icOFFSET, FirstOf(EQUALS, space()), OneOrMore(AnyOf("1234567890")),
push(((WikittyQuery)pop()).setOffset(toInt(match())))
@@ -325,6 +331,12 @@
);
}
+ Rule depth() {
+ return Optional(space(), icDEPTH, FirstOf(EQUALS, space()), OneOrMore(AnyOf("1234567890")),
+ push(((WikittyQuery)pop()).setWikittyFieldSearchDepth(toInt(match())))
+ );
+ }
+
Rule or() {
return Sequence(and(), ZeroOrMore(space(), icOR, space(), and(),
push(new Or((Condition)pop(1), (Condition)pop()))));
1
0