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
- 1653 discussions
r1526 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities
by bpoussin@users.nuiton.org 15 Feb '13
by bpoussin@users.nuiton.org 15 Feb '13
15 Feb '13
Author: bpoussin
Date: 2013-02-15 12:17:45 +0100 (Fri, 15 Feb 2013)
New Revision: 1526
Url: http://nuiton.org/projects/wikitty/repository/revisions/1526
Log:
fixes #2527: remove extension in wikitty object
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java 2013-01-26 14:38:37 UTC (rev 1525)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java 2013-02-15 11:17:45 UTC (rev 1526)
@@ -191,6 +191,16 @@
void addExtension(Collection<WikittyExtension> exts);
/**
+ * Remove extension in argument and all dependants extensions.
+ * Fields of extension is removed too.
+ * If extension in argument is not found, nothing is done
+ *
+ * @param ext extension to remove
+ * @since 3.9
+ */
+ void removeExtension(String ext);
+
+ /**
* Check that the wikitty has a metaExtension about a given extension.
*
* @param metaExtensionName the metaExtension to be checked
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java 2013-01-26 14:38:37 UTC (rev 1525)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java 2013-02-15 11:17:45 UTC (rev 1526)
@@ -250,6 +250,13 @@
}
}
+ public void removeExtension(String ext) {
+ if (target.getExtensionNames().contains(ext)) {
+ substituteTargetWithCopy();
+ target.removeExtension(ext);
+ }
+ }
+
@Override
public boolean hasExtension(String extName) {
return target.hasExtension(extName);
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2013-01-26 14:38:37 UTC (rev 1525)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2013-02-15 11:17:45 UTC (rev 1526)
@@ -407,6 +407,16 @@
incrementVersion(ext.name);
}
+ public void removeExtension(String ext) {
+ Collection<WikittyExtension> exts = getExtensionDependencies(ext, true);
+ for (WikittyExtension e : exts) {
+ extensions.remove(e.getName());
+ for (String field : e.getFieldNames()) {
+ fieldValue.remove(field);
+ }
+ }
+ }
+
/**
* @see Wikitty#hasMetaExtension(String, String)
*/
@@ -589,9 +599,10 @@
def += extension.toDefinition() + "\n";
}
throw new WikittyException(String.format(
- "field '%s' is not valid, extensions definition : %s", ext + "." + fieldName, def));
+ "field '%s' is not valid, extensions definition : %s",
+ WikittyUtil.getFQFieldName(ext, fieldName), def));
}
- String key = ext + "." + fieldName;
+ String key = WikittyUtil.getFQFieldName(ext, fieldName);
// take old value if needed
Object oldValue = null;
1
0
r1525 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty/entities test/java/org/nuiton/wikitty
by jcouteau@users.nuiton.org 26 Jan '13
by jcouteau@users.nuiton.org 26 Jan '13
26 Jan '13
Author: jcouteau
Date: 2013-01-26 15:38:37 +0100 (Sat, 26 Jan 2013)
New Revision: 1525
Url: http://nuiton.org/projects/wikitty/repository/revisions/1525
Log:
fixes #2514
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityImpl.java 2012-12-29 13:22:20 UTC (rev 1524)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityImpl.java 2013-01-26 14:38:37 UTC (rev 1525)
@@ -24,12 +24,13 @@
*/
package org.nuiton.wikitty.entities;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Collection;
import java.util.Collections;
-import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyUtil;
/**
*
@@ -96,7 +97,9 @@
public void setWikitty(Wikitty wikitty) {
if(wikitty != null) {
for (WikittyExtension ext : getStaticExtensions()) {
- wikitty.addExtension(ext);
+ if (!wikitty.getExtensions().contains(ext)){
+ wikitty.addExtension(ext);
+ }
}
}
this.wikitty = wikitty;
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2012-12-29 13:22:20 UTC (rev 1524)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2013-01-26 14:38:37 UTC (rev 1525)
@@ -25,6 +25,15 @@
package org.nuiton.wikitty.entities;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ObjectUtil;
+import org.nuiton.util.VersionUtil;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.generator.WikittyTagValue;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.math.BigDecimal;
@@ -43,18 +52,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ObjectUtil;
-import org.nuiton.util.VersionUtil;
-import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.generator.WikittyTagValue;
/**
* Wikitty implementation.
- *
+ *
+ * {@link #getDirty()} contains 2 types of info :
+ * <li>the name of a modified field (extension.field)</li>
+ * <li>an extension added or deleted (extension)</li>
+ *
* @author poussin
* @version $Revision$
*
@@ -247,7 +252,7 @@
} catch (CloneNotSupportedException eee) {
throw new WikittyException(String.format(
"Can't copy field %s.%s",
- ext.getName(), fieldName), eee);
+ extName, fieldName), eee);
}
}
this.setField(extName, fieldName, value);
@@ -367,8 +372,7 @@
protected void setFieldDirty(String ext, String fieldName,
Object oldValue, Object newValue) {
String key = ext + "." + fieldName;
- fieldDirty.add(key);
- version = WikittyUtil.incrementMinorRevision(version);
+ incrementVersion(key);
getPropertyChangeSupport().firePropertyChange(key, oldValue, newValue);
}
@@ -400,6 +404,7 @@
}
extensions.put(ext.name, ext);
+ incrementVersion(ext.name);
}
/**
@@ -428,12 +433,14 @@
* @see Wikitty#addMetaExtension(WikittyExtension, String)
*/
@Override
- public void addMetaExtension(WikittyExtension metaExtension, String extensionName) {
+ public void addMetaExtension(WikittyExtension metaExtension,
+ String extensionName) {
if (hasExtension(extensionName)) {
String metaExtensionFQName = WikittyUtil.getFQMetaExtensionName(
metaExtension.getName(),
extensionName);
extensions.put(metaExtensionFQName, metaExtension);
+ incrementVersion(metaExtensionFQName);
} else {
throw new IllegalArgumentException("this wikitty doesn't have an extension named " + extensionName);
}
@@ -1008,7 +1015,7 @@
}
/**
- * @see org.nuiton.wikitty.Wikitty#addToField(String, Object)
+ * @see org.nuiton.wikitty.entities.Wikitty#addToField(String, Object)
*/
@Override
public void addToField(String fqFieldName, Object value) {
@@ -1292,4 +1299,10 @@
}
}
+ protected void incrementVersion(String cause) {
+ //Indexation solr vérifie si un objet à changé seulement si fieldDirty est non vide
+ fieldDirty.add(cause);
+ version = WikittyUtil.incrementMinorRevision(version);
+ }
+
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java 2012-12-29 13:22:20 UTC (rev 1524)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyUtilTest.java 2013-01-26 14:38:37 UTC (rev 1525)
@@ -24,18 +24,6 @@
*/
package org.nuiton.wikitty;
-import java.beans.PropertyChangeListener;
-import java.math.BigDecimal;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,6 +40,18 @@
import org.nuiton.wikitty.entities.WikittyLabelImpl;
import org.nuiton.wikitty.services.WikittyServiceInMemory;
+import java.beans.PropertyChangeListener;
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* Test on WikittyUtil class.
*
@@ -581,7 +581,7 @@
String wikittyId = label.getWikittyId();
- Wikitty labelWikitty = WikittyUtil.getWikitty(null,null,label);
+ Wikitty labelWikitty = WikittyUtil.getWikitty(label);
Assert.assertEquals(wikittyId, labelWikitty.getWikittyId());
Assert.assertEquals(Collections.singleton("Test"),labelWikitty.getFieldAsObject(WikittyLabel.EXT_WIKITTYLABEL,WikittyLabel.FIELD_WIKITTYLABEL_LABELS));
@@ -652,7 +652,7 @@
source.addLabels("toto");
source.addLabels("titi");
- Wikitty labelWikitty = WikittyUtil.getWikitty(null, null, source);
+ Wikitty labelWikitty = WikittyUtil.getWikitty(source);
Wikitty cloned = WikittyUtil.clone(labelWikitty, false);
WikittyLabelImpl labelCloned = new WikittyLabelImpl(cloned);
@@ -669,7 +669,7 @@
source.addLabels("toto");
source.addLabels("titi");
- Wikitty labelWikitty = WikittyUtil.getWikitty(null, null, source);
+ Wikitty labelWikitty = WikittyUtil.getWikitty(source);
Wikitty cloned = WikittyUtil.clone(labelWikitty, true);
WikittyLabelImpl labelCloned = new WikittyLabelImpl(cloned);
1
0
Author: tchemit
Date: 2012-12-29 14:22:20 +0100 (Sat, 29 Dec 2012)
New Revision: 1524
Url: http://nuiton.org/projects/wikitty/repository/revisions/1524
Log:
Update mavenpom4redmine to 3.4.7.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-11-19 17:19:04 UTC (rev 1523)
+++ trunk/pom.xml 2012-12-29 13:22:20 UTC (rev 1524)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.4.3</version>
+ <version>3.4.7</version>
</parent>
<!-- ************************************************************* -->
1
0
r1523 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty/query test/java/org/nuiton/wikitty/query
by bpoussin@users.nuiton.org 19 Nov '12
by bpoussin@users.nuiton.org 19 Nov '12
19 Nov '12
Author: bpoussin
Date: 2012-11-19 18:19:04 +0100 (Mon, 19 Nov 2012)
New Revision: 1523
Url: http://nuiton.org/repositories/revision/wikitty/1523
Log:
Fixes Anomalie #2447: Wikitty query staring with space pasing throw NullPointerException
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.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-11-19 08:57:20 UTC (rev 1522)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/WikittyQueryParser.java 2012-11-19 17:19:04 UTC (rev 1523)
@@ -236,6 +236,7 @@
* @return
*/
static public WikittyQuery parse(String queryString, Map<String, String> alias) {
+ queryString = StringUtils.strip(queryString);
if (queryString == null) {
queryString = "";
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-11-19 08:57:20 UTC (rev 1522)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-11-19 17:19:04 UTC (rev 1523)
@@ -440,7 +440,6 @@
* @throws Exception
*/
@Test
- @Ignore
public void testParseSpaceStart() {
WikittyQueryMaker cc = new WikittyQueryMaker();
cc.parse(" xxx");
1
0
r1522 - trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query
by echatellier@users.nuiton.org 19 Nov '12
by echatellier@users.nuiton.org 19 Nov '12
19 Nov '12
Author: echatellier
Date: 2012-11-19 09:57:20 +0100 (Mon, 19 Nov 2012)
New Revision: 1522
Url: http://nuiton.org/repositories/revision/wikitty/1522
Log:
refs #2447: add new test for query starting with space
Modified:
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-11-09 13:45:28 UTC (rev 1521)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/query/WikittyQueryTest.java 2012-11-19 08:57:20 UTC (rev 1522)
@@ -28,6 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyImpl;
@@ -432,4 +433,16 @@
// test d'equalite sur les representation string des 2 query
Assert.assertEquals(queryParsed.toString(), queryCopyParsed.toString());
}
+
+ /**
+ * Les requettes qui commencent par un espace provoque une erreur de parsing.
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void testParseSpaceStart() {
+ WikittyQueryMaker cc = new WikittyQueryMaker();
+ cc.parse(" xxx");
+ }
}
1
0
r1521 - in trunk: wikitty-api wikitty-api/src/it/generation wikitty-api/src/it/generation/src/main/models wikitty-generators/src/main/java/org/nuiton/wikitty/generator
by echatellier@users.nuiton.org 09 Nov '12
by echatellier@users.nuiton.org 09 Nov '12
09 Nov '12
Author: echatellier
Date: 2012-11-09 14:45:28 +0100 (Fri, 09 Nov 2012)
New Revision: 1521
Url: http://nuiton.org/repositories/revision/wikitty/1521
Log:
fixes #2405 : Wikitty purifier template generate accessor for non navigable association
Added:
trunk/wikitty-api/src/it/generation/src/main/models/mymodel6.objectmodel
Modified:
trunk/wikitty-api/pom.xml
trunk/wikitty-api/src/it/generation/pom.xml
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2012-10-30 07:45:06 UTC (rev 1520)
+++ trunk/wikitty-api/pom.xml 2012-11-09 13:45:28 UTC (rev 1521)
@@ -283,10 +283,6 @@
</build>
</profile>
- <!-- Commented because some test are in fail :
- http://www.nuiton.org/issues/show/1160
- and http://www.nuiton.org/issues/show/1161-->
-
<profile>
<id>run-its</id>
<activation>
Modified: trunk/wikitty-api/src/it/generation/pom.xml
===================================================================
--- trunk/wikitty-api/src/it/generation/pom.xml 2012-10-30 07:45:06 UTC (rev 1520)
+++ trunk/wikitty-api/src/it/generation/pom.xml 2012-11-09 13:45:28 UTC (rev 1521)
@@ -152,7 +152,21 @@
<goal>smart-generate</goal>
</goals>
</execution>
- </executions>
+
+ <execution>
+ <id>entities6 generator</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <inputs>
+ <input>src/main/models:mymodel6.objectmodel</input>
+ <input>classpath:model:/:wikitty.objectmodel</input>
+ </inputs>
+ </configuration>
+ <goals>
+ <goal>smart-generate</goal>
+ </goals>
+ </execution>
+ </executions>
<dependencies>
<dependency>
Added: trunk/wikitty-api/src/it/generation/src/main/models/mymodel6.objectmodel
===================================================================
(Binary files differ)
Property changes on: trunk/wikitty-api/src/it/generation/src/main/models/mymodel6.objectmodel
___________________________________________________________________
Added: svn:mime-type
+ application/xml
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java 2012-10-30 07:45:06 UTC (rev 1520)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java 2012-11-09 13:45:28 UTC (rev 1521)
@@ -92,24 +92,27 @@
superClass = model.getClass(superClass.getQualifiedName());
for (ObjectModelAttribute attribute : superClass.getAttributes()) {
- String attributeName;
+
+ if (attribute.isNavigable()) {
+ String attributeName;
- // tag value définie par le developpeur
- if (attribute.hasTagValue(TAG_ALTERNATIVE_NAME)) {
- attributeName = attribute.getTagValue(TAG_ALTERNATIVE_NAME);
- } else {
- attributeName = attribute.getName();
- }
+ // tag value définie par le developpeur
+ if (attribute.hasTagValue(TAG_ALTERNATIVE_NAME)) {
+ attributeName = attribute.getTagValue(TAG_ALTERNATIVE_NAME);
+ } else {
+ attributeName = attribute.getName();
+ }
- // check conflics
- if (attributeNames.contains(attributeName)) {
- attributeName += "From" + superClass.getName();
- builder.addTagValue(clazz, TAG_ALTERNATIVE_NAME
- + "." + superClass.getName() + "." + attribute.getName(), attributeName);
+ // check conflics
+ if (attributeNames.contains(attributeName)) {
+ attributeName += "From" + superClass.getName();
+ builder.addTagValue(clazz, TAG_ALTERNATIVE_NAME
+ + "." + superClass.getName() + "." + attribute.getName(), attributeName);
+ }
+
+ // remember new getter name
+ attributeNames.add(attributeName);
}
-
- // remember new getter name
- attributeNames.add(attributeName);
}
}
}
1
0
Author: tchemit
Date: 2012-10-30 08:45:06 +0100 (Tue, 30 Oct 2012)
New Revision: 1520
Url: http://nuiton.org/repositories/revision/wikitty/1520
Log:
Update mavenpom4redmine to 3.4.3.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-10-26 11:44:48 UTC (rev 1519)
+++ trunk/pom.xml 2012-10-30 07:45:06 UTC (rev 1520)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.4.2</version>
+ <version>3.4.3</version>
</parent>
<!-- ************************************************************* -->
1
0
Author: tchemit
Date: 2012-10-26 13:44:48 +0200 (Fri, 26 Oct 2012)
New Revision: 1519
Url: http://nuiton.org/repositories/revision/wikitty/1519
Log:
Update mavenpom4redmine to 3.4.2.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-10-11 02:50:04 UTC (rev 1518)
+++ trunk/pom.xml 2012-10-26 11:44:48 UTC (rev 1519)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.4</version>
+ <version>3.4.2</version>
</parent>
<!-- ************************************************************* -->
1
0
Author: tchemit
Date: 2012-10-11 04:50:04 +0200 (Thu, 11 Oct 2012)
New Revision: 1518
Url: http://nuiton.org/repositories/revision/wikitty/1518
Log:
Update mavenpom4redmine to 3.4.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-15 12:37:32 UTC (rev 1517)
+++ trunk/pom.xml 2012-10-11 02:50:04 UTC (rev 1518)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.3.7</version>
+ <version>3.4</version>
</parent>
<!-- ************************************************************* -->
1
0
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