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
October 2010
- 7 participants
- 86 discussions
r464 - in trunk: . wikitty-api wikitty-generators wikitty-hbase-impl wikitty-hessian-client wikitty-hessian-server wikitty-jdbc-impl wikitty-jms-impl wikitty-jpa-impl wikitty-multistorage-impl wikitty-solr-impl wikitty-ui-zk
by bpoussin@users.nuiton.org 29 Oct '10
by bpoussin@users.nuiton.org 29 Oct '10
29 Oct '10
Author: bpoussin
Date: 2010-10-29 19:03:00 +0200 (Fri, 29 Oct 2010)
New Revision: 464
Url: http://nuiton.org/repositories/revision/wikitty/464
Log:
change version to 3.0-SNAPSHOT
check all dependency with
mvn -Panalyze-dependencies
Modified:
trunk/pom.xml
trunk/wikitty-api/pom.xml
trunk/wikitty-generators/pom.xml
trunk/wikitty-hbase-impl/pom.xml
trunk/wikitty-hessian-client/pom.xml
trunk/wikitty-hessian-server/pom.xml
trunk/wikitty-jdbc-impl/pom.xml
trunk/wikitty-jms-impl/pom.xml
trunk/wikitty-jpa-impl/pom.xml
trunk/wikitty-multistorage-impl/pom.xml
trunk/wikitty-solr-impl/pom.xml
trunk/wikitty-ui-zk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -15,7 +15,7 @@
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
<modules>
@@ -137,6 +137,20 @@
</dependency>
<dependency>
+ <groupId>org.apache.solr</groupId>
+ <artifactId>solr-solrj</artifactId>
+ <version>1.4.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>2.9.3</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
@@ -201,6 +215,13 @@
<dependency>
<groupId>jivesoftware</groupId>
+ <artifactId>smack</artifactId>
+ <version>3.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>jivesoftware</groupId>
<artifactId>smackx</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-api/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
@@ -40,12 +40,6 @@
<scope>test</scope>
</dependency>
- <!-- TEST -->
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
-
<!-- COMPILE -->
<dependency>
<groupId>org.picocontainer</groupId>
@@ -110,11 +104,16 @@
<artifactId>jgroups</artifactId>
</dependency>
- <dependency>
- <groupId>jivesoftware</groupId>
- <artifactId>smackx</artifactId>
- </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smack</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
Modified: trunk/wikitty-generators/pom.xml
===================================================================
--- trunk/wikitty-generators/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-generators/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
@@ -22,6 +22,10 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
Modified: trunk/wikitty-hbase-impl/pom.xml
===================================================================
--- trunk/wikitty-hbase-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-hbase-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -8,7 +8,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.2.0-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
Modified: trunk/wikitty-hessian-client/pom.xml
===================================================================
--- trunk/wikitty-hessian-client/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-hessian-client/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
@@ -38,5 +38,4 @@
<description>Wikitty hessian client</description>
<inceptionYear>2010</inceptionYear>
-
</project>
Modified: trunk/wikitty-hessian-server/pom.xml
===================================================================
--- trunk/wikitty-hessian-server/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-hessian-server/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -39,6 +39,10 @@
</dependency>
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
</dependency>
@@ -69,8 +73,7 @@
<inceptionYear>2010</inceptionYear>
<packaging>war</packaging>
-
- <properties>
+ <properties>
<!-- extra files to include in release -->
<redmine.releaseFiles>target/${project.build.finalName}.${project.packaging}</redmine.releaseFiles>
</properties>
Modified: trunk/wikitty-jdbc-impl/pom.xml
===================================================================
--- trunk/wikitty-jdbc-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-jdbc-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.wikitty</groupId>
@@ -63,10 +63,6 @@
</dependency>
<dependency>
- <groupId>xpp3</groupId>
- <artifactId>xpp3</artifactId>
- </dependency>
- <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
@@ -78,12 +74,27 @@
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
</dependency>
+
<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjta</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
@@ -95,6 +106,5 @@
<name>Wikitty :: wikitty-jdbc-impl</name>
<description>Wikitty jdbc storage</description>
<inceptionYear>2009</inceptionYear>
-
</project>
Modified: trunk/wikitty-jms-impl/pom.xml
===================================================================
--- trunk/wikitty-jms-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-jms-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -7,7 +7,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.2.0-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.wikitty</groupId>
Modified: trunk/wikitty-jpa-impl/pom.xml
===================================================================
--- trunk/wikitty-jpa-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-jpa-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -8,7 +8,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.2.0-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
Modified: trunk/wikitty-multistorage-impl/pom.xml
===================================================================
--- trunk/wikitty-multistorage-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-multistorage-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -7,7 +7,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.2.0-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.wikitty</groupId>
Modified: trunk/wikitty-solr-impl/pom.xml
===================================================================
--- trunk/wikitty-solr-impl/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-solr-impl/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
@@ -32,15 +32,38 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjta</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ </dependency>
+
<!-- SOLR -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
</dependency>
+
<dependency>
+ <groupId>org.apache.solr</groupId>
+ <artifactId>solr-solrj</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
+ <scope>runtime</scope>
</dependency>
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
@@ -50,10 +73,6 @@
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
<!-- TEST -->
<dependency>
@@ -71,6 +90,5 @@
<description>Wikiity solr search engine</description>
<inceptionYear>2009</inceptionYear>
-
</project>
Modified: trunk/wikitty-ui-zk/pom.xml
===================================================================
--- trunk/wikitty-ui-zk/pom.xml 2010-10-29 15:41:32 UTC (rev 463)
+++ trunk/wikitty-ui-zk/pom.xml 2010-10-29 17:03:00 UTC (rev 464)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>wikitty</artifactId>
- <version>2.3-SNAPSHOT</version>
+ <version>3.0-SNAPSHOT</version>
</parent>
<!-- ************************************************************* -->
@@ -52,16 +52,16 @@
</dependency>
<dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
</dependency>
<dependency>
- <groupId>org.nuiton</groupId>
- <artifactId>nuiton-utils</artifactId>
- <scope>compile</scope>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
</dependency>
+
<!-- <dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
@@ -116,8 +116,7 @@
<!-- ************************************************************* -->
<packaging>war</packaging>
-
- <properties>
+ <properties>
<!-- extra files to include in release -->
<redmine.releaseFiles>target/${project.build.finalName}.${project.packaging}</redmine.releaseFiles>
</properties>
1
0
r463 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services
by bpoussin@users.nuiton.org 29 Oct '10
by bpoussin@users.nuiton.org 29 Oct '10
29 Oct '10
Author: bpoussin
Date: 2010-10-29 17:41:32 +0200 (Fri, 29 Oct 2010)
New Revision: 463
Url: http://nuiton.org/repositories/revision/wikitty/463
Log:
small mistake to merge result in findAllCriteria
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java 2010-10-29 15:29:23 UTC (rev 462)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java 2010-10-29 15:41:32 UTC (rev 463)
@@ -256,7 +256,7 @@
new LinkedHashSet<String>(resultTx.size() + resultWs.size());
ids.addAll(resultTx.getAll());
for (String id : resultWs.getAll()) {
- if (tx.exists(securityToken, id) && ! tx.isDeleted(securityToken, id)) {
+ if (!tx.exists(securityToken, id) || ! tx.isDeleted(securityToken, id)) {
ids.add(id);
}
}
1
0
Author: bpoussin
Date: 2010-10-29 17:29:23 +0200 (Fri, 29 Oct 2010)
New Revision: 462
Url: http://nuiton.org/repositories/revision/wikitty/462
Log:
change business entity package in model, we need to change generation plugin configuration
http://www.nuiton.org/issues/show/1003
Modified:
trunk/wikitty-api/pom.xml
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-29 15:19:55 UTC (rev 461)
+++ trunk/wikitty-api/pom.xml 2010-10-29 15:29:23 UTC (rev 462)
@@ -187,9 +187,9 @@
<inputs>
<input>zargo:src/main/xmi:*.zargo</input>
</inputs>
- <fullPackagePath>org.nuiton.wikitty</fullPackagePath>
- <defaultPackage>org.nuiton.wikitty</defaultPackage>
- <extractedPackages>org.nuiton.wikitty</extractedPackages>
+ <fullPackagePath>org.nuiton.wikitty.entities</fullPackagePath>
+ <defaultPackage>org.nuiton.wikitty.entities</defaultPackage>
+ <extractedPackages>org.nuiton.wikitty.entities</extractedPackages>
<templates>org.nuiton.wikitty.generator.WikittyMetaGenerator</templates>
</configuration>
<goals>
1
0
Author: bpoussin
Date: 2010-10-29 17:19:55 +0200 (Fri, 29 Oct 2010)
New Revision: 461
Url: http://nuiton.org/repositories/revision/wikitty/461
Log:
Repackage all classe in wikitty-api module
http://www.nuiton.org/issues/show/1003
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyImportExportService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyLabelUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ExportTask.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportCSV.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportMethod.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportXML.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportTask.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/JobState.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityWikitty.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/ExtensionFactory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldFactory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java
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/WikittyExtension.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyMetaExtensionUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Criteria.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopic.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/And.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/AssociatedRestriction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Between.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/BinaryOperator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Contains.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Element.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/EndsWith.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Equals.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Greater.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/GreaterOrEqual.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/In.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Keyword.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Less.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/LessOrEqual.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Like.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Not.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/NotEquals.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Null.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Or.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Restriction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/RestrictionName.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SearchOperand.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/StartsWith.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SubSearch.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Unlike.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/JGroupsNotifierTransporter.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyCache.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigration.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigrationRename.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittySecurityHelper.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceCached.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceDelegator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEnhanced.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceListener.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceNotifier.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/XMPPNotifierTransporter.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorage.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorageInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngin.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEnginInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorage.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorageInMemory.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/WikittyI18nTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/importexport/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/importexport/ImportExportCSVTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceHelperTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceTransactionTest.java
Removed:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntityWikitty.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Criteria.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/ExtensionFactory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FacetTopic.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldFactory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldType.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Wikitty.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCopyOnWrite.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtension.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionStorage.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyLabelUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySearchEngin.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyStorage.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/And.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/AssociatedRestriction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Between.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/BinaryOperator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Contains.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Element.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/EndsWith.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Equals.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Greater.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/GreaterOrEqual.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/In.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Keyword.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Less.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/LessOrEqual.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Like.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Not.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/NotEquals.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Null.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Or.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Restriction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionName.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SearchOperand.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/StartsWith.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SubSearch.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Unlike.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTree.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionHelper.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Search.java
trunk/wikitty-api/src/main/xmi/wikitty.properties
trunk/wikitty-api/src/main/xmi/wikitty.zargo
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/CommonTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/ExtensionFactoryTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/SearchCriteriaTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/WikittyUtilTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/AbstractWikittyServiceTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java
trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/Restriction2Solr.java
trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/SolrSearchTest.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/TreeTest.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/FieldExtension.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Model.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyForm.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyModel.java
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntity.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntity.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,147 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.io.Serializable;
-import java.util.Collection;
-
-/**
- * Used as parent interface to all Business class
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-// FIXME poussin 20100528 voir si cette interface est reellement necessaire. On pourra renommer BusinessEntityWikitty en BusinessEntity
-public interface BusinessEntity extends Serializable, Cloneable {
-
- /**
- * Return wikitty id (uuid).
- *
- * @return wikitty id
- */
- public String getWikittyId();
-
- /**
- * Return wikitty version (x.y).
- *
- * @return wikitty version
- */
- public String getWikittyVersion();
-
- /**
- * Return wikitty
- *
- * @return the wikitty actually storing the entity's data
- * @since 2.2.1
- */
- public Wikitty getWikitty();
-
- /**
- * Only framework can use this method.
- *
- * @param version version to set
- */
- public void setWikittyVersion(String version);
-
- /**
- * Return list of all extension for this object.
- *
- * @return extension names
- */
- public Collection<String> getExtensionNames();
-
- /**
- * Return list of all field for this object.
- *
- * @param ext extension to get fields
- * @return fields collections
- */
- public Collection<String> getExtensionFields(String ext);
-
- /**
- * Return field value for the specific extension and field.
- *
- * @param ext extension
- * @param fieldName field name
- * @return field value
- */
- public Object getField(String ext, String fieldName);
-
- /**
- * Set field value for the specific extension and field.
- *
- * This method don't check the type of value for this field.
- *
- * @param ext extension
- * @param fieldName field name
- * @param value value to set
- */
- public void setField(String ext, String fieldName, Object value);
-
- /**
- * Return the field type.
- *
- * @param ext extension
- * @param fieldName field name
- * @return feild type
- */
- public FieldType getFieldType(String ext, String fieldName);
-
- /**
- * Add {@link PropertyChangeListener}.
- *
- * @param listener listener to add
- */
- void addPropertyChangeListener(PropertyChangeListener listener);
-
- /**
- * Remove {@link PropertyChangeListener}.
- *
- * @param listener listener to remove
- */
- void removePropertyChangeListener(PropertyChangeListener listener);
-
- /**
- * Add {@link PropertyChangeListener} on {@code propertyName}.
- *
- * @param propertyName property name
- * @param listener listener to add
- */
- void addPropertyChangeListener(String propertyName, PropertyChangeListener listener);
-
- /**
- * Remove {@link PropertyChangeListener} on {@code propertyName}
- *
- * @param propertyName property name
- * @param listener listener listener to remove
- */
- void removePropertyChangeListener(String propertyName, PropertyChangeListener listener);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntityWikitty.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntityWikitty.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntityWikitty.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,179 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Each business object will inherit of this class.
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class BusinessEntityWikitty implements BusinessEntity {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = -4399752739887114180L;
-
- /**
- * Property change support.
- *
- * Warning, this transient field is null after deserialization.
- */
- protected transient PropertyChangeSupport propertyChangeSupport;
-
- protected Wikitty wikitty;
-
- public BusinessEntityWikitty(Wikitty wi) {
- setWikitty(wi);
- }
-
- public BusinessEntityWikitty() {
- this(new WikittyImpl());
- }
-
- protected PropertyChangeSupport getPropertyChangeSupport() {
- if (propertyChangeSupport == null) {
- propertyChangeSupport = new PropertyChangeSupport(this);
- }
- return propertyChangeSupport;
- }
-
- public String getWikittyId() {
- String result = getWikitty().getId();
- return result;
- }
-
- public String getWikittyVersion() {
- String result = getWikitty().getVersion();
- return result;
- }
-
- public void setWikittyVersion(String version) {
- getWikitty().setVersion(version);
- }
-
- public void setWikitty(Wikitty wikitty) {
- if(wikitty != null) {
- for (WikittyExtension ext : getStaticExtensions()) {
- wikitty.addExtension(ext);
- }
- }
- this.wikitty = wikitty;
- }
-
- /**
- * @see BusinessEntity#getWikitty()
- */
- public Wikitty getWikitty() {
- return wikitty;
- }
-
- public Collection<String> getExtensionNames() {
- Collection<String> result = getWikitty().getExtensionNames();
- return result;
- }
-
- public Collection<String> getExtensionFields(String ext) {
- Collection<String> result = getWikitty().getExtension(ext).getFieldNames();
- return result;
- }
-
- public FieldType getFieldType(String ext, String fieldName) {
- FieldType result = getWikitty().getExtension(ext).getFieldType(fieldName);
- return result;
- }
-
- public Object getField(String ext, String fieldName) {
- Object result = getWikitty().getFieldAsObject(ext, fieldName);
- return result;
- }
-
- public void setField(String ext, String fieldName, Object value) {
- getWikitty().setField(ext, fieldName, value);
- }
-
- public Collection<WikittyExtension> getStaticExtensions() {
- return Collections.emptyList();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (!BusinessEntityWikitty.class.isAssignableFrom(obj.getClass())) {
- return false;
- }
- BusinessEntityWikitty wikitty = (BusinessEntityWikitty) obj;
- return getWikittyId().equals(wikitty.getWikittyId());
- }
-
- @Override
- public int hashCode() {
- return getWikittyId().hashCode();
- }
-
- /*
- * @see org.nuiton.wikitty.BusinessEntity#addPropertyChangeListener(java.beans.PropertyChangeListener)
- */
- @Override
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(listener);
- }
-
- /*
- * @see org.nuiton.wikitty.BusinessEntity#removePropertyChangeListener(java.beans.PropertyChangeListener)
- */
- @Override
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(listener);
- }
-
- /*
- * @see org.nuiton.wikitty.BusinessEntity#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
- */
- @Override
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
- }
-
- /*
- * @see org.nuiton.wikitty.BusinessEntity#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
- */
- @Override
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Criteria.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Criteria.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Criteria.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,246 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.XMLDecoder;
-import java.beans.XMLEncoder;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.nuiton.wikitty.search.Restriction;
-
-/**
- * Criteria represent the search on the wikitty with restriction on field and
- * informations on facet, pagination and sorting.
- *<p>
- * For search multiple extension use ALL_EXTENSIONS as extension name and
- * specify field type.
- * <p>
- * Example : Criteria.ALL_EXTENSIONS + Criteria.SEPARATOR + <fieldName> + Criteria.SEPARATOR + FieldType.TYPE.<fieldType>
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class Criteria implements Serializable {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 2590223960861630283L;
-
- /** Use to not limit result. */
- static final public int ALL_ELEMENTS = -1;
-
- /** Search on all extension. */
- static final public String ALL_EXTENSIONS = "*";
-
- /** Search on all values. */
- static final public String ALL_VALUES = "*";
-
- /** Separator between extension name, field name and type. */
- static final public String SEPARATOR = ".";
-
- /**
- * Criteria can have name this help for presentation and is very
- * useful for facet created by criteria.
- */
- protected String name;
-
- /** All restriction on fields. */
- protected Restriction restriction;
-
- /** First index to get result. */
- protected int firstIndex = 0;
- /** Last index to get result. */
- protected int endIndex = ALL_ELEMENTS;
-
- /** Facet on criteria. */
- protected List<Criteria> facetCriteria;
- /** Facet on field. */
- protected List<String> facetField;
-
- /** Sort ascending on fields. */
- protected List<String> sortAscending;
- /** Sort descending on fields. */
- protected List<String> sortDescending;
-
- /**
- * Default constructor.
- */
- public Criteria() {
- }
-
- /**
- * Create named criteria.
- *
- * @param name criteria name
- */
- public Criteria(String name) {
- this();
- this.name = name;
- }
-
- /**
- * Deserialize xml to criteria.
- *
- * @param xml xml to deserialize
- * @return criteria criteria
- */
- public static Criteria fromXML(String xml) {
- InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
- XMLDecoder decoder = new XMLDecoder(inputStream);
- Criteria criteria = (Criteria) decoder.readObject();
- return criteria;
- }
-
- /**
- * Serialize criteria to xml.
- *
- * @param criteria criteria to serialize
- * @return xml string
- */
- public static String toXML(Criteria criteria) {
- OutputStream outputStream = new ByteArrayOutputStream();
- XMLEncoder encoder = new XMLEncoder(outputStream);
- encoder.writeObject(criteria);
- encoder.close();
- String result = outputStream.toString();
- return result;
- }
-
- public Restriction getRestriction() {
- return restriction;
- }
-
- public void setRestriction(Restriction restriction) {
- this.restriction = restriction;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getFirstIndex() {
- return firstIndex;
- }
-
- public Criteria setFirstIndex(int firstIndex) {
- this.firstIndex = firstIndex;
- return this;
- }
-
- public int getEndIndex() {
- return endIndex;
- }
-
- public Criteria setEndIndex(int endIndex) {
- this.endIndex = endIndex;
- return this;
- }
-
- public List<Criteria> getFacetCriteria() {
- return facetCriteria;
- }
-
- public Criteria addFacetCriteria(Criteria criteria) {
- if (facetCriteria == null) {
- facetCriteria = new ArrayList<Criteria>();
- }
- facetCriteria.add(criteria);
- return this;
- }
-
- public Criteria setFacetCriteria(Criteria[] facetCriteria) {
- this.facetCriteria = Arrays.asList(facetCriteria);
- return this;
- }
-
- public List<String> getFacetField() {
- return facetField;
- }
-
- public Criteria addFacetField(String field) {
- if (facetField == null) {
- facetField = new ArrayList<String>();
- }
- facetField.add(field);
- return this;
- }
-
- public Criteria setFacetField(String[] facetField) {
- this.facetField = Arrays.asList(facetField);
- return this;
- }
-
- public List<String> getSortAscending() {
- return sortAscending;
- }
-
- public Criteria addSortAscending(String field) {
- if(sortAscending == null) {
- sortAscending = new ArrayList<String>();
- }
- sortAscending.add(field);
- return this;
- }
-
- public Criteria setSortAscending(String[] sortAscending) {
- this.sortAscending = Arrays.asList(sortAscending);
- return this;
- }
-
- public List<String> getSortDescending() {
- return sortDescending;
- }
-
- public Criteria addSortDescending(String field) {
- if(sortDescending == null) {
- sortDescending = new ArrayList<String>();
- }
- sortDescending.add(field);
- return this;
- }
-
- public Criteria setSortDescending(String[] sortDescending) {
- this.sortDescending = Arrays.asList(sortDescending);
- return this;
- }
-
- @Override
- public String toString() {
- return toXML(this);
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/ExtensionFactory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/ExtensionFactory.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/ExtensionFactory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,62 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.LinkedHashMap;
-
-import org.nuiton.wikitty.FieldType.TYPE;
-
-public class ExtensionFactory {
-
- protected String name;
- protected String version;
- protected String requiredExtension;
-
- protected LinkedHashMap<String, FieldType> fields;
-
- protected ExtensionFactory(String name, String version) {
- this.name = name;
- this.version = version;
- this.fields = new LinkedHashMap<String, FieldType>();
- }
-
- public static ExtensionFactory create(String name, String version) {
- return new ExtensionFactory(name, version);
- }
-
- public FieldFactory addField(String name, TYPE fieldType) {
- return new FieldFactory(this, name, fieldType);
- }
-
- public WikittyExtension extension() {
- WikittyExtension ext = new WikittyExtension(name, version, requiredExtension, fields);
- return ext;
- }
-
- protected void add(String fieldName, FieldType fieldType) {
- fields.put(fieldName, fieldType);
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FacetTopic.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FacetTopic.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FacetTopic.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,66 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.io.Serializable;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class FacetTopic implements Serializable {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 1408493244549775810L;
-
- protected String facetName;
-
- protected String topicName;
-
- protected int count;
-
- public FacetTopic(String facetName, String topicName, int count) {
- this.facetName = facetName;
- this.topicName = topicName;
- this.count = count;
- }
-
- public String getFacetName() {
- return facetName;
- }
-
- public String getTopicName() {
- return topicName;
- }
-
- public int getCount() {
- return count;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldFactory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldFactory.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldFactory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,91 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.nuiton.wikitty.FieldType.TYPE;
-
-public class FieldFactory {
-
- protected ExtensionFactory parentFactory;
- protected String fieldName;
- protected TYPE type;
- protected int minOccur = 0, maxOccur = 1;
- protected boolean unique = false;
- protected Map<String, String> tagValues = new HashMap<String, String>();
-
- public FieldFactory(ExtensionFactory parentFactory, String fieldName, TYPE type) {
- this.parentFactory = parentFactory;
- this.fieldName = fieldName;
- this.type = type;
- }
-
- public FieldFactory addField(String name, TYPE type) {
- append();
- return parentFactory.addField(name, type);
- }
-
- public WikittyExtension extension() {
- append();
- return parentFactory.extension();
- }
-
- protected void append() {
- FieldType fieldType = new FieldType(type, minOccur, maxOccur);
- for (Map.Entry<String, String> entry : tagValues.entrySet()) {
- String tag = entry.getKey();
- String value = entry.getValue();
- fieldType.addTagValue(tag, value);
- }
- parentFactory.add(fieldName, fieldType);
- }
-
- public FieldFactory maxOccur(int max) {
- maxOccur = max;
- return this;
- }
-
- public FieldFactory minOccur(int min) {
- minOccur = min;
- return this;
- }
-
- public FieldFactory unique() {
- addTagValue(FieldType.UNIQUE, "true");
- return this;
- }
-
- public FieldFactory notNull() {
- addTagValue(FieldType.NOT_NULL, "true");
- return this;
- }
-
- public FieldFactory addTagValue(String tag, String value) {
- tagValues.put(tag, value);
- return this;
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldType.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldType.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldType.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,229 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class FieldType implements Serializable {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = -4375308750387837026L;
-
- /** tag/value use for unique */
- static public String UNIQUE = "unique";
- /** tag/value use for not null */
- static public String NOT_NULL = "notNull";
-
- static public enum TYPE {
- BOOLEAN, DATE, NUMERIC, STRING, WIKITTY;
-
- /**
- * convert string to TYPE, this method accept not trimed and not well
- * cased string (difference with valueOf)
- * @param name
- * @return TYPE else exception is throw
- */
- public static TYPE parse(String name) {
- TYPE result = valueOf(name.trim().toUpperCase());
- return result;
- }
- }
-
- public static final int NOLIMIT = Integer.MAX_VALUE;
-
- protected TYPE type;
- protected int lowerBound;
- protected int upperBound;
-
- /** used to store tag/value used by client side ex: editor=xhtml */
- Map<String, String> tagValues = new HashMap<String, String>();
-
- public FieldType() {
- }
-
- public FieldType(TYPE type, int lowerBound, int upperBound) {
- this.type = type;
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
- }
-
- public void addTagValue(String tag, String value) {
- tagValues.put(tag, value);
- }
-
- public String getTagValue(String tag) {
- String result = tagValues.get(tag);
- return result;
- }
-
- public Set<String> getTagNames() {
- return tagValues.keySet();
- }
-
- public Map<String, String> getTagValues() {
- return tagValues;
- }
-
- public void setTagValues(Map<String, String> tagValues) {
- this.tagValues = tagValues;
- }
-
- /**
- * Return true if this field have upperBound > 1.
- *
- * @return {@code true} is field is collection
- */
- public boolean isCollection() {
- return upperBound > 1;
- }
-
- /**
- * Return string definition for this field.
- *
- * @param name field name used for definition
- * @return field definition
- */
- public String toDefinition(String name) {
- String result = type + " " + name;
- if (lowerBound != 0 || upperBound != 0) {
- if (upperBound != NOLIMIT) {
- result += "[" + lowerBound + "-" + upperBound + "]";
- } else {
- result += "[" + lowerBound + "-*]";
- }
- }
- result += WikittyUtil.tagValuesToString(tagValues);
- return result;
- }
-
- /**
- * Convert value in argument in right type for this FieldType. Don't support
- * collection.
- *
- * @param value value to convert
- * @return object in type of this FieldType
- */
- protected Object getContainedValidObject( Object value ) {
- Object result = null;
- switch (type) {
- case DATE:
- result = WikittyUtil.toDate(value); break;
- case NUMERIC:
- result = WikittyUtil.toBigDecimal(value); break;
- case BOOLEAN:
- result = WikittyUtil.toBoolean(value); break;
- case STRING:
- result = WikittyUtil.toString(value); break;
- default:
- // if type is not found then type is business type
- // and is wikitty object
- result = WikittyUtil.toWikitty(value); break;
- }
- return result;
- }
-
- /**
- * Return a valid value for this field.
- *
- * @param value is casted if possible to an actual correct value.
- * @return value validity
- * @throws WikittyException if value can't be obtained
- */
- public Object getValidValue(Object value) throws WikittyException {
- if (value == null && isNotNull()) {
- throw new WikittyException("Value can't be null for this field");
- }
-
- Object result;
- if (value == null) {
- result = null;
- } else if (isCollection()) {
- if ( !(value instanceof Collection) ) {
- throw new WikittyException( "A collection is expected for type "
- + type.name() + "[" + lowerBound + " - " + upperBound + "]" );
- }
- Collection<Object> col;
- if (isUnique()) {
- col = new LinkedHashSet<Object>();
- } else {
- col = new ArrayList<Object>();
- }
-
- // copy all value in new collections
- for ( Object o : (Collection<?>) value ) {
- col.add( getContainedValidObject(o) );
- }
- result = col;
- } else {
- result = getContainedValidObject(value);
- }
- return result;
- }
-
- /**
- * Test if value in argument is valid for this field type.
- *
- * @param value to test
- * @return true if value is valid
- */
- public boolean isValidValue(Object value) {
- return getValidValue(value) != null;
- }
-
- public TYPE getType() {
- return type;
- }
-
- public int getLowerBound() {
- return lowerBound;
- }
-
- public int getUpperBound() {
- return upperBound;
- }
-
- public boolean isUnique() {
- return "true".equalsIgnoreCase(getTagValue(UNIQUE));
- }
-
- public boolean isNotNull() {
- return "true".equalsIgnoreCase(getTagValue(NOT_NULL));
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,135 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import org.apache.commons.lang.StringUtils;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jgroups.Channel;
-import org.jgroups.ChannelException;
-import org.jgroups.JChannel;
-import org.jgroups.Message;
-import org.jgroups.ReceiverAdapter;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- * JGroups notifier.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class JGroupsNotifierTransporter extends ReceiverAdapter
- implements WikittyServiceNotifier.RemoteNotifierTransporter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class);
-
- /** Notifier service reference reference. */
- protected WikittyServiceNotifier ws;
-
-
- /** JGroup channel. */
- protected JChannel channel;
-
- public JGroupsNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
- this.ws = ws;
-
- // can be null according to default constructor
- if (config != null) {
- // add notifier as listener
- String jgroupChannel = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_JGROUP_CHANNELNAME.getKey());
- if (!StringUtils.isBlank(jgroupChannel)) {
- initChannel(jgroupChannel);
- } else {
- throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!");
- }
- }
- }
-
- /**
- * Init jgroup channel.
- *
- * @param channelName channel name
- */
- protected void initChannel(String channelName) {
- if (log.isDebugEnabled()) {
- log.debug("Init jgroup communication channel...");
- }
-
- try {
- // use default udp.xml in classpath
- channel = new JChannel();
- channel.setReceiver(this);
-
- // don't receive messages sent by myself
- channel.setOpt(Channel.LOCAL, false);
-
- channel.connect(channelName);
-
- if (log.isInfoEnabled()) {
- log.info("JGroup communication channel initialized to "
- + channel.getAddressAsString() + " ("
- + channel.getClusterName() + ")");
- log.info("Channel view: " + channel.getView());
- }
- } catch (ChannelException eee) {
- throw new WikittyException("Can't initialize jgroup channel", eee);
- }
- }
-
- /**
- * Send a jgroup message to all other channel member.
- *
- * @param event message to send
- */
- @Override
- public void sendMessage(WikittyServiceEvent event) throws Exception {
- Message msg = new Message(null, null, event);
- channel.send(msg);
- }
-
- /*
- * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message)
- */
- @Override
- public void receive(Message msg) {
-
- Object message = msg.getObject();
-
- if (log.isInfoEnabled()) {
- log.info("Receive message : " + message);
- }
-
- if (message instanceof WikittyServiceEvent) {
- WikittyServiceEvent event = (WikittyServiceEvent)message;
- ws.processRemoteEvent(event);
- }
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,286 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import static org.nuiton.i18n.I18n._;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Paged result containing result collection and facet topics.
- *
- * @param <T> paged result value type
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class PagedResult<T> implements Serializable {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(PagedResult.class);
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 8518774558223121855L;
-
- /** indice element in global search result */
- protected int firstIndice;
- /** total number of result if we call the query for all possible result */
- protected int numFound;
- /** query really executed */
- protected String queryString;
- /** list of result in the wanted interval */
- protected List<T> results;
- /** facet asked or null if no facet */
- protected Map<String, List<FacetTopic>> facets;
-
- /**
- * we don't initialize securityToken
- *
- * @param firstIndice
- * @param numFound
- * @param queryString
- * @param facets
- * @param results
- */
- public PagedResult(int firstIndice, int numFound, String queryString,
- Map<String, List<FacetTopic>> facets, List<T> results) {
- this.firstIndice = firstIndice;
- this.numFound = numFound;
- this.queryString = queryString;
- this.facets = facets;
- this.results = Collections.unmodifiableList(results);
- }
-
- /**
- * Call {@link #cast(WikittyProxy, Class, boolean)} with
- * autoconvert = true
- *
- * @param proxy used to retrieve securityToken and WikittyService
- * @param clazz target PagedResult type
- * @return new PagedResult, this result can have less elements that original
- * for some reason (security, ...)
- */
- public <E extends BusinessEntityWikitty> PagedResult<E> cast(
- WikittyProxy proxy, Class<E> clazz) {
- return cast(proxy, clazz, true);
- }
-
- /**
- * Convert all result to the wikitty type and return new PagedResult with
- * this new result list.
- *
- * @param securityToken security token
- * @param ws wikitty service
- *
- * @return new PagedResult, this result can have less elements that original
- * for some reason (security, ...)
- */
- public PagedResult<Wikitty> cast(String securityToken, WikittyService ws) {
- List<Wikitty> castedResult;
-
- if (results.size() == 0) {
- castedResult = new ArrayList<Wikitty>();
- } else {
- if (results.get(0) instanceof String) {
- // le pagedresult courant contient des Ids
- // Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
- // ce PagedResult ne sait pas ce qu'il fait :)
- List<String> ids = (List<String>) results;
- castedResult = ws.restore(securityToken, ids);
- } else {
- throw new ClassCastException("PagedResult don't contains" +
- " wikitty String id but " + results.get(0).getClass());
- }
- }
- PagedResult<Wikitty> result = new PagedResult<Wikitty>(
- firstIndice, numFound, queryString, facets, castedResult);
- return result;
- }
-
- /**
- * Convert all result to the wanted type and return new PagedResult with
- * this new result list. If some result don't have the right extension (clazz)
- * this extension is automatically added if autoconvert is true. Else
- * an exception is thrown when result without extension is found.
- *
- * When you used autoconvert = false, you have a potentially problem when
- * you have modified a BusinessEntity to have new extension and all your
- * wikitty object are not uptodate in database.
- *
- * @param <E> class to cast into
- * @param proxy used to retrieve securityToken and WikittyService
- * @param autoconvert if autoconvert is false and object don't all needed
- * extension, object is not put in the result
- * @return new PagedResult, this result can have less elements that original
- * for some reason (security, ...)
- */
- public <E extends BusinessEntityWikitty> PagedResult<E> cast(
- WikittyProxy proxy, Class<E> clazz, boolean autoconvert) {
- List<E> castedResult;
-
- if (results.size() > 0 && results.get(0) instanceof String) {
- // le pagedresult courant contient des Ids
- // Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
- // ce PagedResult ne sait pas ce qu'il fait :)
- List<String> ids = (List<String>)results;
- castedResult = proxy.restore(clazz, ids, !autoconvert);
- } else {
- castedResult = new ArrayList<E>(results.size());
- E sample = WikittyUtil.newInstance(clazz);
- Collection<WikittyExtension> wantedExtension = sample.getStaticExtensions();
- for (T t : results) {
- if (t == null) {
- castedResult.add(null);
- } else {
- Wikitty w = null;
- if (t instanceof Wikitty) {
- w = (Wikitty) t;
- } else if (t instanceof BusinessEntityWikitty) {
- w = ((BusinessEntityWikitty) t).getWikitty();
- } else {
- throw new WikittyException(String.format(
- "Illegal object result class '%s' can't convert it to wikitty",
- t.getClass().getName(), clazz.getName()));
- }
-
- Collection<WikittyExtension> wikittyExtension = w.getExtensions();
- if (autoconvert || wikittyExtension.containsAll(wantedExtension)) {
- E e = WikittyUtil.newInstance(proxy.getSecurityToken(),
- proxy.getWikittyService(), clazz, (Wikitty) t);
- castedResult.add(e);
- } else {
- // silently pass current object, this object is not put
- // in result
- if (log.isDebugEnabled()) {
- log.debug(_(
- "Illegal object result class '%s' can't convert it to '%s'" +
- "there is no same extension %s != %s",
- t.getClass().getName(), clazz.getName(),
- wikittyExtension, wantedExtension));
- }
- }
- }
- }
- }
- PagedResult<E> result = new PagedResult<E>(
- firstIndice, numFound, queryString, facets, castedResult);
- return result;
- }
-
- public int getFirstIndice() {
- return firstIndice;
- }
-
- public int getNumFound() {
- return numFound;
- }
-
- public String getQueryString() {
- return queryString;
- }
-
- /**
- * Return name of all facet used in query.
- *
- * @return result's facets names
- */
- public Collection<String> getFacetNames() {
- Collection<String> result = facets.keySet();
- return result;
- }
-
- /**
- * Return all topic for the specified facet.
- *
- * @param facetName name of the wanted facet
- * @return facet's topics
- */
- public List<FacetTopic> getTopic(String facetName) {
- List<FacetTopic> result = facets.get(facetName);
- return result;
- }
-
- /**
- * Get map represent facets.
- *
- * @return all facets
- */
- public Map<String, List<FacetTopic>> getFacets() {
- return facets;
- }
-
- /**
- * Return the first element in result
- *
- * Can throw an exception if no element available
- * @return first element
- */
- public T getFirst() {
- T result = get(0);
- return result;
- }
-
- /**
- * Return element at index.
- *
- * @param i index
- * @return element at index
- */
- public T get(int i) {
- T result = results.get(i);
- return result;
- }
-
- /**
- * Return unmodifiable list of all result.
- *
- * @return all results
- */
- public List<T> getAll() {
- return results;
- }
-
- /**
- * Return the number of result in this object.
- *
- * @return result number
- */
- public int size() {
- int result = results.size();
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Wikitty.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Wikitty.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Wikitty.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,228 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-public interface Wikitty extends Cloneable, Serializable {
-
- void addPropertyChangeListener(PropertyChangeListener listener);
-
- void removePropertyChangeListener(PropertyChangeListener listener);
-
- void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
-
- void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener);
-
- /**
- * Replace all field of current wikitty with field found in w.
- * This two wikitty must have same id
- * @param w wikitty where we take information
- */
- void replace(Wikitty w);
-
- String getId();
-
- boolean isDeleted();
-
- Date getDeleteDate();
-
- /**
- * Server only used
- * @param delete
- */
- void setDeleteDate(Date delete);
-
- void addExtension(WikittyExtension ext);
-
- void addExtension(List<WikittyExtension> exts);
-
- /** check that the wikitty has a metaExtension about a given extension.
- * @param metaExtensionName the metaExtension to be checked
- * @param extensionName an extension already added to the wikitty
- * @since 2.2.0
- */
- boolean hasMetaExtension(String metaExtensionName,
- String extensionName);
-
- /** add a meta-extension about the given extension to this wikitty.
- * @param metaExtension the metaExtension to add
- * @param extension an extension already added to the wikitty
- * @since 2.1
- */
- void addMetaExtension(WikittyExtension metaExtension,
- WikittyExtension extension);
-
-
- /** add a meta-extension on the given extension to this wikitty.
- * @param metaExtension the metaExtension to add
- * @param extensionFqn the name of the extension already added to the wikitty
- * @since 2.1
- */
- void addMetaExtension(WikittyExtension metaExtension, String extensionFqn);
-
- boolean hasExtension(String extName);
-
- boolean hasField(String extName, String fieldName);
-
- WikittyExtension getExtension(String ext);
-
- Collection<String> getExtensionNames();
-
- Collection<WikittyExtension> getExtensions();
-
- Collection<WikittyExtension> getExtensionDependencies(String ext,
- boolean recursively);
-
- /**
- * return field type for the given fieldName.
- * @param fqfieldName fully qualified fieldName extension.fieldname
- * @return field type
- */
- FieldType getFieldType(String fqfieldName);
-
- void setField(String ext, String fieldName, Object value);
-
- Object getFieldAsObject(String ext, String fieldName);
-
- boolean getFieldAsBoolean(String ext, String fieldName);
-
- BigDecimal getFieldAsBigDecimal(String ext, String fieldName);
-
- int getFieldAsInt(String ext, String fieldName);
-
- long getFieldAsLong(String ext, String fieldName);
-
- float getFieldAsFloat(String ext, String fieldName);
-
- double getFieldAsDouble(String ext, String fieldName);
-
- String getFieldAsString(String ext, String fieldName);
-
- Date getFieldAsDate(String ext, String fieldName);
-
- /**
- * return wikitty id and not wikitty objet because this method can be call
- * on server or client side and it's better to keep conversion between id
- * and objet to the caller
- * @param ext extension name where this field must to be
- * @param fieldName the field name
- * @return id of wikitty object or null
- * @throws org.nuiton.wikitty.WikittyException
- */
- String getFieldAsWikitty(String ext, String fieldName);
-
- /**
- * If object is a set, it is automatically transform to list.
- * @param <E>
- * @param clazz
- * @return unmodifiable list
- */
- <E> List<E> getFieldAsList(String ext, String fieldName,
- final Class<E> clazz);
-
- /**
- *
- * @param <E>
- * @param clazz
- * @return unmodifiable list
- */
- <E> Set<E> getFieldAsSet(String ext, String fieldName, final Class<E> clazz);
-
- void addToField(String ext, String fieldName, Object value);
-
- void removeFromField(String ext, String fieldName, Object value);
-
- void clearField(String ext, String fieldName);
-
- /**
- * Add an element in a field
- * @param fqFieldName the fully qualified name of a collection field
- * @param value the value to be added to the collection
- * @since 2.2.0
- */
- void addToField(String fqFieldName, Object value);
-
- /**
- * Remove an element from a field
- * @param fqFieldName the fully qualified name of a collection field
- * @param value the value to be removed to the collection
- * @since 2.2.0
- */
- void removeFromField(String fqFieldName, Object value);
-
- /**
- * Clear a field
- * @param fqFieldName the fully qualified name of a collection field
- * @since 2.2.0
- */
- void clearField(String fqFieldName);
-
- Set<String> fieldNames();
-
- /** get the value of and field given its fqn */
- Object getFqField(String fqFieldName);
-
- String getVersion();
-
- /**
- * Server only used
- * @param version
- */
- void setVersion(String version);
-
- /**
- * get the field modified after wikitty was restored
- * @return a set of fully qualified field names
- * @since 2.2.0
- */
- Set<String> getDirty();
-
- /** clear the lists of modified field since last restore. */
- void clearDirty();
-
-
- /** set the value of a field given is fqn.
- * @param fieldName fqn (ex: extensionName.fieldName)
- * @param value new value
- */
- void setFqField(String fieldName, Object value);
-
- boolean isEmpty();
-
- /**
- * @see Cloneable#clone()
- */
- Wikitty clone() throws CloneNotSupportedException;
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,199 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- * Cette classe sert a introduire du cache dans wikitty. Elle sert a centraliser
- * tous les appels au cache pour pouvoir simplement changer de librairie de
- * cache si necessaire, meme si pour l'instant on s'appuie le JDK
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyCache implements WikittyServiceListener {
-
- static private Log log = LogFactory.getLog(WikittyCache.class);
-
- /** keys are wikitty ids */
- protected Map<String, Wikitty> wikittyCache;
-
- /**
- *
- * @param config not used currently but necessary in futur to configure the cache
- * Create a soft cache.
- */
- public WikittyCache(ApplicationConfig config) {
- this(true);
- }
-
- /**
- * Init cache with specific reference type.
- *
- * @param soft si vrai utilise un cache avec des reference Soft, sinon
- * utilise des references static (utile pour les transactions)
- */
- public WikittyCache(boolean soft) {
- if (soft) {
- wikittyCache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
- } else {
- wikittyCache = new HashMap<String, Wikitty>();
- }
- }
-
- public boolean existsWikitty(String id) {
- Object o = wikittyCache.get(id);
- boolean result = (o != null);
- return result;
- }
-
- /**
- * Return wikitty object if is in the cache, null otherwize.
- *
- * @param id
- * @return wikitty object or null
- */
- public Wikitty getWikitty(String id) {
- Wikitty result = wikittyCache.get(id);
- return result;
- }
-
- /**
- * Only realy put wikitty in cache, if not in cache or version is newer than
- * one in cache
- * @param e
- */
- public void putWikitty(Wikitty e) {
- if (e == null) {
- return;
- }
- Wikitty old = getWikitty(e.getId());
- if (old == null
- || WikittyUtil.versionGreaterThan(e.getVersion(), old.getVersion())) {
- wikittyCache.put(e.getId(), e);
-
- if (log.isTraceEnabled()) {
- log.trace("Replace cached wikitty : new version " + e.getVersion() +
- " > old version " + (old == null ? null : old.getVersion()));
- }
- }
- else {
- if (log.isTraceEnabled()) {
- log.trace("Ignoring putWikittyEvent : new version " + e.getVersion() + " < old version " + old.getVersion());
- }
- }
- }
-
- /**
- * batched put
- * @param all
- */
- public void putAllWikitty(Collection<Wikitty> all) {
- for (Wikitty w : all) {
- putWikitty(w);
- }
- }
-
- /**
- * Remove wikitty from cache.
- *
- * @param id wikitty id to remove
- */
- public void removeWikitty(String id) {
- wikittyCache.remove(id);
- }
-
- /**
- * batched remove
- * @param ids
- */
- public void removeAllWikitty(Collection<String> ids) {
- for (String id : ids) {
- removeWikitty(id);
- }
- }
-
- /**
- * Clear all cache.
- */
- public void clearWikitty() {
- wikittyCache.clear();
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
- */
- @Override
- public void clearWikitty(WikittyServiceEvent event) {
- clearWikitty();
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
- */
- @Override
- public void putWikitty(WikittyServiceEvent event) {
- Collection<Wikitty> wikitties = event.getWikitties().values();
- putAllWikitty(wikitties);
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
- */
- @Override
- public void removeWikitty(WikittyServiceEvent event) {
- for (String id : event.getRemoveDate().keySet()) {
- removeWikitty(id);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
- */
- @Override
- public void putExtension(WikittyServiceEvent event) {
-
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
- */
- @Override
- public void clearExtension(WikittyServiceEvent event) {
-
- }
-}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,5 +1,7 @@
package org.nuiton.wikitty;
+import org.nuiton.wikitty.services.XMPPNotifierTransporter;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
import java.io.File;
import java.util.Properties;
import static org.nuiton.i18n.I18n._;
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCopyOnWrite.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCopyOnWrite.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCopyOnWrite.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,368 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/** this class wrap a wikitty in a proxy that copy the wikitty before applying any change
- *
- * It is used for caching purpose. This class own a reference to an actual
- * wikitty, multiple instance of this class can own some references to a same
- * actual wikitty. To prevent the target to be modified, a copy is created
- * to prevent side-effect.
- *
- * So, when a wikitty restored from cache is modified, a copy is modified, so
- * if change are cancelled, next restore will restore the original and not
- * the modified version (until the modified version is stored).
- *
- * used in {@link WikittyServiceCached}
- */
-public class WikittyCopyOnWrite implements Wikitty {
-
- private static final long serialVersionUID = 1L;
-
- private static final Log log = LogFactory.getLog(WikittyCopyOnWrite.class);
-
- protected Wikitty target;
-
- protected boolean targetIsACopy = false;
-
- /** only WikittyService with cache should create instances */
- protected WikittyCopyOnWrite(Wikitty target) {
- this.target = target;
- }
-
- @Override
- public void replace(Wikitty w) {
- // test make a the copy once
- if (targetIsACopy) {
- target.replace(w);
- } else {
- try {
- target = w.clone();
- if (log.isTraceEnabled()) {
- log.trace(this + " now has for target " + target);
- }
- } catch (CloneNotSupportedException eee) {
- throw new WikittyException(String.format(
- "unable to clone wikitty %s", target), eee);
- }
- targetIsACopy = true;
- }
- }
-
- /** replace {@link #target} with a clone
- *
- * this method must be called to prevent any modification on target
- */
- protected void substituteTargetWithCopy() {
- // test make a the copy once
- if (! targetIsACopy) {
- try {
- target = target.clone();
- if (log.isTraceEnabled()) {
- log.trace(this + " now has for target " + target);
- }
- } catch (CloneNotSupportedException eee) {
- throw new WikittyException(String.format(
- "unable to clone wikitty %s", target), eee);
- }
- targetIsACopy = true;
- }
- }
-
- public boolean equals(Object obj) {
- // FIXME 20100804 bleny side-effect ?
- return target.equals(obj);
- }
-
- public int hashCode() {
- // FIXME 20100804 bleny side-effect ?
- return target.hashCode();
- }
-
- public String toString() {
- return "[" + WikittyCopyOnWrite.class.getName() + "]" + target.toString();
- }
-
- @Override
- public Wikitty clone() throws CloneNotSupportedException {
- // return a clone of the target
- return target.clone();
- }
-
- /* ** below are only delegation code with copy-on-write */
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- target.addPropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- target.removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- target.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- target.removePropertyChangeListener(propertyName, listener);
- }
-
- public String getId() {
- return target.getId();
- }
-
- public boolean isDeleted() {
- return target.isDeleted();
- }
-
- public Date getDeleteDate() {
- return target.getDeleteDate();
- }
-
- public void setDeleteDate(Date delete) {
- target.setDeleteDate(delete);
- }
-
- public void addExtension(WikittyExtension ext) {
- substituteTargetWithCopy();
- target.addExtension(ext);
- }
-
- public void addExtension(List<WikittyExtension> exts) {
- substituteTargetWithCopy();
- target.addExtension(exts);
- }
-
- public boolean hasExtension(String extName) {
- return target.hasExtension(extName);
- }
-
- public boolean hasField(String extName, String fieldName) {
- return target.hasField(extName, fieldName);
- }
-
- public WikittyExtension getExtension(String ext) {
- return target.getExtension(ext);
- }
-
- public Collection<String> getExtensionNames() {
- return target.getExtensionNames();
- }
-
- public Collection<WikittyExtension> getExtensions() {
- return target.getExtensions();
- }
-
- public Collection<WikittyExtension> getExtensionDependencies(String ext,
- boolean recursively) {
- return target.getExtensionDependencies(ext, recursively);
- }
-
- public FieldType getFieldType(String fqfieldName) {
- return target.getFieldType(fqfieldName);
- }
-
- public void setField(String ext, String fieldName, Object value) {
- substituteTargetWithCopy();
- target.setField(ext, fieldName, value);
- }
-
- public Object getFieldAsObject(String ext, String fieldName) {
- return target.getFieldAsObject(ext, fieldName);
- }
-
- public boolean getFieldAsBoolean(String ext, String fieldName) {
- return target.getFieldAsBoolean(ext, fieldName);
- }
-
- public BigDecimal getFieldAsBigDecimal(String ext, String fieldName) {
- return target.getFieldAsBigDecimal(ext, fieldName);
- }
-
- public int getFieldAsInt(String ext, String fieldName) {
- return target.getFieldAsInt(ext, fieldName);
- }
-
- public long getFieldAsLong(String ext, String fieldName) {
- return target.getFieldAsLong(ext, fieldName);
- }
-
- public float getFieldAsFloat(String ext, String fieldName) {
- return target.getFieldAsFloat(ext, fieldName);
- }
-
- public double getFieldAsDouble(String ext, String fieldName) {
- return target.getFieldAsDouble(ext, fieldName);
- }
-
- public String getFieldAsString(String ext, String fieldName) {
- return target.getFieldAsString(ext, fieldName);
- }
-
- public Date getFieldAsDate(String ext, String fieldName) {
- return target.getFieldAsDate(ext, fieldName);
- }
-
- public String getFieldAsWikitty(String ext, String fieldName) {
- return target.getFieldAsWikitty(ext, fieldName);
- }
-
- public <E> List<E> getFieldAsList(String ext, String fieldName,
- Class<E> clazz) {
- return target.getFieldAsList(ext, fieldName, clazz);
- }
-
- public <E> Set<E> getFieldAsSet(String ext, String fieldName, Class<E> clazz) {
- return target.getFieldAsSet(ext, fieldName, clazz);
- }
-
- public void addToField(String ext, String fieldName, Object value) {
- substituteTargetWithCopy();
- target.addToField(ext, fieldName, value);
- }
-
- public void removeFromField(String ext, String fieldName, Object value) {
- substituteTargetWithCopy();
- target.removeFromField(ext, fieldName, value);
- }
-
- public void clearField(String ext, String fieldName) {
- substituteTargetWithCopy();
- target.clearField(ext, fieldName);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addToField(String, Object)
- */
- @Override
- public void addToField(String fqFieldName, Object value) {
- substituteTargetWithCopy();
- target.addToField(fqFieldName, value);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#removeFromField(String, Object)
- */
- @Override
- public void removeFromField(String fqFieldName, Object value) {
- substituteTargetWithCopy();
- target.removeFromField(fqFieldName, value);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#clearField(String)
- */
- @Override
- public void clearField(String fqFieldName) {
- substituteTargetWithCopy();
- target.clearField(fqFieldName);
- }
-
- public Set<String> fieldNames() {
- return target.fieldNames();
- }
-
- public Object getFqField(String fqFieldName) {
- return target.getFqField(fqFieldName);
- }
-
- public String getVersion() {
- return target.getVersion();
- }
-
- public void setVersion(String version) {
- substituteTargetWithCopy();
- target.setVersion(version);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#getDirty()
- */
- public Set<String> getDirty() {
- return target.getDirty();
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#clearDirty()
- */
- public void clearDirty() {
- substituteTargetWithCopy();
- target.clearDirty();
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#setFqField(String, Object)
- */
- public void setFqField(String fieldName, Object value) {
- substituteTargetWithCopy();
- target.setFqField(fieldName, value);
- }
-
- public boolean isEmpty() {
- return target.isEmpty();
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#hasMetaExtension(String, String)
- */
- @Override
- public boolean hasMetaExtension(String metaExtensionName,
- String extensionName) {
- return target.hasMetaExtension(metaExtensionName, extensionName);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, WikittyExtension)
- */
- @Override
- public void addMetaExtension(WikittyExtension metaExtension,
- WikittyExtension extension) {
- substituteTargetWithCopy();
- target.addMetaExtension(metaExtension, extension);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, String)
- */
- @Override
- public void addMetaExtension(WikittyExtension metaExtension,
- String extensionFqn) {
- substituteTargetWithCopy();
- target.addMetaExtension(metaExtension, extensionFqn);
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtension.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtension.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtension.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,321 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyExtension implements Serializable {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = -3598621577607442972L;
-
- /** Field name pattern only word character [a-zA-Z_0-9] is accepted */
- static protected Pattern fieldNamePattern = Pattern.compile("^\\w+$");
-
- /**
- * Property change support.
- *
- * Warning, this transient field is null after deserialization.
- */
- protected transient PropertyChangeSupport propertyChangeSupport;
-
- /** Name of this extension. */
- protected String name;
-
- /**
- * Name of other extension needed to put this extension to object.
- *
- * Warning : Multiples extensions are not supported yet.
- *
- * FIXME EC-20100420 multiples extensions need to work
- */
- protected String requires;
-
- /**
- * use to know version objet, when you change field number, type or other
- * you must change version number.
- */
- protected String version = WikittyUtil.DEFAULT_VERSION;
-
- /** used to store tag/value used by client side ex: updatedDate=101212 */
- protected Map<String, String> tagValues = new HashMap<String, String>();
-
- /**
- * fields use ordered map, to keep order insertion of field
- * key: field name
- * value: field type
- */
- protected LinkedHashMap<String, FieldType> fields = new LinkedHashMap<String, FieldType>();
-
- /**
- * Default constructor.
- *
- * Used by hibernate.
- */
- public WikittyExtension() {
-
- }
-
- public WikittyExtension(String name) {
- setName(name);
- }
-
- public WikittyExtension(String name, String version,
- String requires, LinkedHashMap<String, FieldType> fields) {
- if (version == null) {
- throw new IllegalArgumentException("Version must not be null");
- }
- setName(name);
- this.version = WikittyUtil.normalizeVersion(version);
- this.requires = requires;
- if (fields != null) {
- for (Map.Entry<String, FieldType> entry : fields.entrySet()) {
- String fieldName = entry.getKey();
- FieldType fieldType = entry.getValue();
- addField(fieldName, fieldType);
- }
- }
- }
-
- protected PropertyChangeSupport getPropertyChangeSupport() {
- if (propertyChangeSupport == null) {
- propertyChangeSupport = new PropertyChangeSupport(this);
- }
- return propertyChangeSupport;
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
- }
-
- public WikittyExtension cloneForUpgrade() {
- String nextRevision = WikittyUtil.incrementMajorRevision(getVersion());
-
- LinkedHashMap<String, FieldType> nextFields = null;
- if (fields != null) {
- nextFields = new LinkedHashMap<String, FieldType>();
- for (Map.Entry<String, FieldType> entry : fields.entrySet()) {
- FieldType type = entry.getValue();
- FieldType nextType = new FieldType(
- type.getType(), type.getLowerBound(), type.getUpperBound());
- Set<String> tagNames = type.getTagNames();
- if (tagNames != null) {
- for (String tagName : tagNames) {
- String tagValue = type.getTagValue(tagName);
- nextType.addTagValue(tagName, tagValue);
- }
- }
- nextFields.put(entry.getKey(), nextType);
- }
- }
-
- WikittyExtension result = new WikittyExtension(name, nextRevision, requires, nextFields);
- return result;
- }
-
- /**
- * Compute id for extension name and version in argument.
- *
- * @param name extension name
- * @param version extension version
- * @return extension string id
- */
- static public String computeId(String name, String version) {
- String result = name + "[" + version + "]";
- return result;
- }
-
- static public String computeName(String id) {
- int i = id.lastIndexOf("[");
- String result = id;
- if (i != -1) {
- result = id.substring(0, i);
- }
- return result;
- }
-
- static public String computeVersion(String id) {
- int b = id.lastIndexOf("[");
- int e = id.lastIndexOf("]");
- String result = null;
- if (b != -1 && e != -1) {
- result = id.substring(b+1, e);
- }
- result = WikittyUtil.normalizeVersion(result);
- return result;
- }
-
- public String getId() {
- String result = computeId(getName(), getVersion());
- return result;
- }
-
- public String getName() {
- return name;
- }
-
- /**
- * Set extension name.
- *
- * Check for invalid extension name (non alphanumeric characters).
- *
- * @param name name
- */
- public void setName(String name) {
-
- // check alphanumeric characters
- if (name == null) {
- throw new IllegalArgumentException("Name must not be null");
- }
- if (!name.matches("\\w+")) {
- throw new IllegalArgumentException("Name contains non alphanumeric characters");
- }
-
- this.name = name;
- }
-
- public String getVersion() {
- return version;
- }
-
- public String getRequires() {
- return requires;
- }
-
- public FieldType getFieldType(String fieldName) {
- return fields.get(fieldName);
- }
-
- public Collection<String> getFieldNames() {
- Collection<String> result = fields.keySet();
- return result;
- }
-
- public void addField(String fieldName, FieldType type) {
- Matcher matcher = fieldNamePattern.matcher(fieldName);
- if(matcher.find()) {
- fields.put(fieldName, type);
- // TODO EC20100610 null for old value
- getPropertyChangeSupport().firePropertyChange("fields", null, fields);
- } else {
- throw new IllegalArgumentException("For field name [" + fieldName +"], only word character [a-zA-Z_0-9] is accepted");
- }
- }
-
- public void removeField(String fieldName) {
- fields.remove(fieldName);
- // TODO EC20100610 null for old value
- getPropertyChangeSupport().firePropertyChange("fields", null, fields);
- }
-
- @Override
- public int hashCode() {
- return getId().hashCode();
- }
-
- public void addTagValue(String tag, String value) {
- tagValues.put(tag, value);
- // TODO EC20100610 null for old value
- getPropertyChangeSupport().firePropertyChange("tagValues", null, tagValues);
- }
-
- public String getTagValue(String tag) {
- String result = tagValues.get(tag);
- return result;
- }
-
- public Set<String> getTagNames() {
- return tagValues.keySet();
- }
-
- public Map<String, String> getTagValues() {
- return tagValues;
- }
-
- public void setTagValues(Map<String, String> tagValues) {
- Map<String, String> oldValue = this.tagValues;
- this.tagValues = tagValues;
- getPropertyChangeSupport().firePropertyChange("tagValues", oldValue, tagValues);
- }
-
- @Override
- public boolean equals(Object obj) {
- boolean result = false;
- if (obj instanceof WikittyExtension) {
- WikittyExtension other = (WikittyExtension)obj;
- result = this.getId().equals(other.getId());
- }
- return result;
- }
-
- @Override
- public String toString() {
- return getId();
- }
-
- public String toDefinition() {
- String result = "Extension " + getId();
- result += WikittyUtil.tagValuesToString(tagValues);
- result += " {\n";
- for (String fieldName : fields.keySet()) {
- result += fields.get(fieldName).toDefinition(fieldName) + "\n";
- }
- result += "}";
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,64 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Interface used to migrate Wikitty data from one WikittyExtension version
- * to another version
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public interface WikittyExtensionMigration {
-
- // TODO poussin 20090902 permit configuration of migrationRegistry by spring
- /**
- * use to put migration class for extension.
- * key: extensionName, value: migration class
- */
- static public Map<String, WikittyExtensionMigration> migrationRegistry =
- new HashMap<String, WikittyExtensionMigration>();
-
- /**
- * Migrate wikitty data from oldExt version to newExt.
- *
- * @param service Wikitty service that do migration
- * @param wikitty Wikitty object that contains data in old version
- * extension format
- * @param oldExt old extension definition
- * @param newExt new extension definition
- * @return same wikitty as argument if nothing to do, or new wikitty
- * if some modification is done
- */
- public Wikitty migrate(WikittyService service, Wikitty wikitty,
- WikittyExtension oldExt, WikittyExtension newExt);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,137 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Basic extension migration use to manage rename field name. Order to detect a
- * rename, not creation a new field, you should use tag value "renameFrom" with
- * name of use in before extension.
- *
- * Since 1.5, this class also take care about extension order.
- *
- * @author ruchaud
- */
-public class WikittyExtensionMigrationRename implements WikittyExtensionMigration {
-
- static private Log log = LogFactory.getLog(WikittyExtensionMigrationRename.class);
-
- public static final String TAG_RENAME = "renameFrom";
-
- /**
- * Recursively add extension with requires ones (orderer).
- * WikittyService used in this method must not have WikittyServiceSecurity
- * in stack because we pass null as secuirtyToken to method. (TODO poussin
- * 2010 verify this assertion, when we use Migration, we don't need
- * Security)
- *
- * @param service service
- * @param transaction current transaction to use
- * @param wikitty wikitty to add extension to
- * @param newExt extension to add
- */
- protected void addExtension(
- WikittyService service, Wikitty wikitty, WikittyExtension newExt) {
-
- // manage requires before current
- String requires = newExt.getRequires();
- if (StringUtils.isNotEmpty(requires)) {
- for (String require : requires.split(",")) {
- WikittyExtension newRequireExt =
- service.restoreExtensionLastVersion(null, require);
- addExtension(service, wikitty, newRequireExt);
- }
- }
-
- // add current extension
- wikitty.addExtension(newExt);
- }
-
- @Override
- public Wikitty migrate(WikittyService service, Wikitty wikitty,
- WikittyExtension oldExt, WikittyExtension newExt) {
-
- String wikittyId = wikitty.getId();
- String wikittyVersion = wikitty.getVersion();
-
- Wikitty result = new WikittyImpl(wikittyId);
- result.setVersion(wikittyVersion);
-
- // Add all extension and replace old by the new
- for (WikittyExtension extension : wikitty.getExtensions()) {
- // add one by one to manage require
-
- // during loop add new when old one is found
- if (extension.equals(oldExt)) {
- addExtension(service, result, newExt);
- }
- else {
- addExtension(service, result, extension);
- }
- }
-
- // Copy other values
- Set<String> fqFieldNames = wikitty.fieldNames();
- String extName = newExt.getName();
- for (String fieldName : fqFieldNames) {
- if(!fieldName.startsWith(extName + ".")) {
- Object value = wikitty.getFqField(fieldName);
- log.debug("Value " + fieldName + "=" + value);
- result.setFqField(fieldName, value);
- }
- }
-
- // Migrate field name
- Collection<String> oldFieldNames = oldExt.getFieldNames();
- Collection<String> newFieldNames = newExt.getFieldNames();
- for (String fieldName : newFieldNames) {
- FieldType fieldType = newExt.getFieldType(fieldName);
-
- String renameFrom = fieldType.getTagValue(TAG_RENAME);
- log.debug("Scan rename migration on " + extName + "." + fieldName + ":" + TAG_RENAME + "=" + renameFrom);
-
- if(renameFrom != null && !renameFrom.isEmpty()) {
- Object value = wikitty.getFieldAsObject(extName, renameFrom);
- log.debug("Rename " + extName + "." + fieldName + "=" + value);
- result.setField(extName, fieldName, value);
- } else {
- if(oldFieldNames.contains(fieldName)) {
- Object value = wikitty.getFieldAsObject(extName, fieldName);
- log.debug("Copy " + extName + "." + fieldName + "=" + value);
- result.setField(extName, fieldName, value);
- }
- }
- }
-
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionStorage.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionStorage.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionStorage.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,107 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public interface WikittyExtensionStorage {
-
- /**
- * Store extension in storage.
- *
- * @param transaction the current transaction
- * @param extensions the extensions to store
- * @return information usefull for client side update data
- */
- WikittyServiceEvent store(WikittyTransaction transaction,
- Collection<WikittyExtension> extensions);
-
- /**
- * Return true if id exists in storage.
- *
- * @param transaction the current transaction
- * @param id an extension id
- * @return true if the extension exists
- */
- boolean exists(WikittyTransaction transaction, String id);
-
- /**
- * Return all extension ids.
- *
- * @param transaction the current transaction
- * @return a list of extension ids
- */
- List<String> getAllExtensionIds(WikittyTransaction transaction);
-
- /**
- * Return all extension ids where the specified extensionName is required.
- *
- * @param transaction the current transaction
- * @param extensionName the extension required
- * @return a list of extension ids
- */
- List<String> getAllExtensionsRequires(WikittyTransaction transaction,
- String extensionName);
-
- /**
- * return last version available for specified extension name.
- *
- * @param transaction the current transaction
- * @param extName name of extension
- * @return last version availble for this version, or null if extension
- * doesn't exist
- */
- String getLastVersion(WikittyTransaction transaction, String extName);
-
- /**
- * Restore one extension from storage, if not found an exception is thrown.
- *
- * @param transaction the current transaction
- * @param name extension name to restore
- * @param version extension version to restore
- * @return an extension
- * @throws WikittyException if exception during restore
- */
- WikittyExtension restore(WikittyTransaction transaction, String name, String version)
- throws WikittyException;
-
- /**
- * Remove all extensions.
- *
- * @param transaction transaction
- */
- public WikittyServiceEvent clear(WikittyTransaction transaction);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nImpl.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,217 +0,0 @@
-package org.nuiton.wikitty;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.StringUtil;
-
-/**
- * WikittyI18n permet de gerer les traductions des champs des extensions.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyI18nImpl extends WikittyI18nAbstract
- implements PropertyChangeListener {
-
- private static final long serialVersionUID = 3824481585361443459L;
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyI18nImpl.class);
-
- /** contient les translations sous une forme plus simple a utiliser */
- transient protected Map<String, Map<String, String>> translationsCache = null;
-
- /**
- * WikittyI18nImpl :
- */
- public WikittyI18nImpl() {
- super();
- }
-
- /**
- * WikittyI18nImpl :
- * @param wikitty
- */
- public WikittyI18nImpl(Wikitty wikitty) {
- super(wikitty);
- }
-
- /**
- * WikittyI18nImpl :
- * @param businessEntityWikitty
- */
- public WikittyI18nImpl(BusinessEntityWikitty businessEntityWikitty) {
- super(businessEntityWikitty.getWikitty());
- }
-
- /**
- * WikittyAuthorisationImpl :
- * @param extension
- * @param wikitty
- */
-
- public WikittyI18nImpl(WikittyExtension extension, Wikitty wikitty) {
- this(wikitty);
- setExtensionForMetaExtension(extension);
- }
-
- /**
- * On surcharge la methode pour se mettre listener des modifications de
- * translation pour pouvoir vider le cache de translation
- * @param wikitty
- */
- @Override
- public void setWikitty(Wikitty wikitty) {
- if (this.wikitty != null) {
- this.wikitty.removePropertyChangeListener(
- FQ_FIELD_WIKITTYI18N_TRANSLATIONS, this);
- }
- super.setWikitty(wikitty);
- if (this.wikitty != null) {
- this.wikitty.addPropertyChangeListener(
- FQ_FIELD_WIKITTYI18N_TRANSLATIONS, this);
- }
- }
-
- /**
- * Retourne la translation pour un champs donne pour une lang donnee
- * @param lang la langue souhaitee (ex: fr)
- * @param field le champs souhaite (ex: name)
- * @return la traduction
- */
- public String getTranslation(String lang, String field) {
- parseAndCacheTranslations();
-
- String result = null;
- Map<String, String> l = translationsCache.get(lang);
- if (l != null) {
- result = l.get(field);
- }
-
- if (result == null) {
- // no translation for this field, default return field in parameter
- result = field;
- }
- return result;
- }
-
- /**
- * Modifie la traduction d'un champs
- * @param lang
- * @param field
- * @param trad
- */
- public void setTranslation(String lang, String field, String trad) {
- parseAndCacheTranslations();
- putInTranslationCache(lang, field, trad);
- // on sauve temporairement le cache, car il va etre supprime
- // suite au setTranslations, vu qu'il est a jour se serait dommage de
- // devoir le reconstruire
- Map<String, Map<String, String>> tmp = translationsCache;
- String trans = convertToString(tmp);
- setTranslations(trans);
- // remet le cache sauvegarde en place
- translationsCache = tmp;
-
- // on indique que la lang a des traductions si besoin
- if (getLang() == null || !getLang().contains(lang)) {
- addLang(lang);
- }
- }
-
- /**
- * Parse les traductions et le met en cache
- *
- * Translations est de la forme:
- * [fr:"name"="nom","firstname"="prenom"],[en:"name="name","firstname"="firstname"]
- */
- protected void parseAndCacheTranslations() {
- if (translationsCache == null) {
- String trans = getTranslations();
- String[] langsFields = StringUtil.split(trans, ",");
- for (String langFields : langsFields) {
- // suppression des [ ]
- langFields = langFields.substring(1, langFields.length() - 1);
- int colonPos = langFields.indexOf(":");
- // recuperation de la langue
- String lang = langFields.substring(0, colonPos);
- langFields = langFields.substring(colonPos + 1);
- String[] fields = StringUtil.split(langFields, ",");
- for (String field : fields) {
- String[] fieldNameAndTrad = StringUtil.split(field, "=");
- String fieldName = fieldNameAndTrad[0];
- String fieldTrad = fieldNameAndTrad[1];
-
- // suppression des "
- fieldName = fieldName.substring(1, fieldName.length() - 1);
- fieldTrad = fieldTrad.substring(1, fieldTrad.length() - 1);
- putInTranslationCache(lang, fieldName, fieldTrad);
- }
- }
- }
- }
-
- /**
- * met un traduction en plus dans le cache
- * @param lang
- * @param field
- * @param trans
- */
- protected void putInTranslationCache(String lang, String field, String trans) {
- if (translationsCache == null) {
- translationsCache = new HashMap<String, Map<String, String>>();
- }
- Map<String, String> l = translationsCache.get(lang);
- if (l == null) {
- l = new HashMap<String, String>();
- translationsCache.put(lang, l);
- }
- l.put(field, trans);
- }
-
- /**
- * converti le cache dans une representation string
- * @param trans
- * @return
- */
- protected String convertToString(Map<String, Map<String, String>> trans) {
- StringBuilder result = new StringBuilder();
- for (Map.Entry<String, Map<String, String>> l : trans.entrySet()) {
- String lang = l.getKey();
- result.append("[" + lang + ":");
- for(Map.Entry<String, String> t : l.getValue().entrySet()) {
- result.append("\"" + t.getKey() + "\"=\"" + t.getValue() + "\",");
- }
- // suppression de la derniere ,
- if (result.charAt(result.length() - 1) == ',') {
- result.deleteCharAt(result.length() - 1);
- }
- result.append("],");
- }
- if (result.charAt(result.length() - 1) == ',') {
- result.deleteCharAt(result.length() - 1);
- }
- return result.toString();
- }
-
- /**
- * Ecoute les events pour devalider le cache
- * @param evt
- */
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- String propName = evt.getPropertyName();
- if (FQ_FIELD_WIKITTYI18N_TRANSLATIONS.equals(propName)) {
- // la valeur a change on vide le cache
- translationsCache = null;
- }
- }
-
-} //WikittyI18nImpl
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nUtil.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,44 +0,0 @@
-package org.nuiton.wikitty;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * Cette classe sert a aider a la gestion multi-langue des extensions
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyI18nUtil {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyI18nUtil.class);
-
- /**
- * Create or load WikittyExtensionTranslation for given extension.
- * If created you must call store if you want keep it in storage
- * @param proxy
- * @param extension
- * @return
- */
- static public WikittyI18n getI18n(WikittyProxy proxy, WikittyExtension extension) {
- String id = WikittyMetaExtensionUtil.generateId(
- WikittyI18n.EXT_WIKITTYI18N,
- extension.getName());
-
- WikittyI18n result;
- Wikitty w = proxy.restore(id);
- if (w == null) {
- w = new WikittyImpl(id);
- }
- result = new WikittyI18nImpl(w);
-
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImpl.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,919 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.math.BigDecimal;
-import java.util.AbstractList;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.commons.lang.ObjectUtils;
-import org.nuiton.util.ObjectUtil;
-
-/**
- * Wikitty implementation.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyImpl implements Wikitty {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 4910886672760691052L;
-
- /** Technical id for this wikitty object. id must be never null. */
- protected String id;
-
- /** Current version of this wikitty object. */
- protected String version = WikittyUtil.DEFAULT_VERSION;
-
- /** If not null, date of deletion, if date this object is marked as deleted. */
- protected Date deleteDate = null;
-
- /**
- * Used to add property change support to wikitty object.
- *
- * Warning, this field can be null after deserialization.
- */
- private transient PropertyChangeSupport propertyChange;
-
- /**
- * key: field name prefixed by extension name (dot separator)
- * value: value of field
- */
- protected HashMap<String, Object> fieldValue = new HashMap<String, Object>();
-
- /**
- * all field name currently modified (field name = extension . fieldname)
- */
- protected Set<String> fieldDirty = new HashSet<String>();
-
- /**
- * Map is LinkedHashMap to maintains order like user want
- * key: extension name
- * value: extension definition
- */
- protected Map<String, WikittyExtension> extensions =
- new LinkedHashMap<String, WikittyExtension>();
-
-
- public WikittyImpl() {
- this(null);
- }
-
- public WikittyImpl(String id) {
- if (id == null) {
- this.id = WikittyUtil.genUID();
- } else {
- this.id = id;
- }
- }
-
- /**
- * Replace all field of current wikitty with field found in w.
- * This two wikitty must have same id.
- *
- * This method is used to clone Wikitty too
- *
- * @param w wikitty where we take information
- */
- @Override
- public void replace(Wikitty w) {
- // il faut que ce soit le meme objet mais pas la meme instance
- // car ca ne sert a rien de copier un objet sur lui meme
- if (this == w) {
- return;
- }
- if (this.getId().equals(w.getId())) {
- this.extensions.clear();
- this.fieldValue.clear();
- for (WikittyExtension ext : w.getExtensions()) {
- String extName = ext.getName();
- this.extensions.put(extName, ext);
- for(String fieldName : ext.getFieldNames()) {
- Object value = w.getFieldAsObject(extName, fieldName);
- if (value != null) {
- // seul les collections sont a cloner, sinon ce ne sont
- // que des types primitifs immutable
- if (value instanceof Collection && value instanceof Cloneable) {
- try {
- value = ObjectUtil.clone((Cloneable) value);
- } catch (CloneNotSupportedException eee) {
- throw new WikittyException(String.format(
- "Can't copy field %s.%s",
- ext.getName(), fieldName), eee);
- }
- }
- this.setField(extName, fieldName, value);
- }
- }
- }
-
- // we must change version after field value copy, because
- // copy increment version because it use setField method
- this.version = w.getVersion();
- this.deleteDate = w.getDeleteDate();
-
- clearDirty();
- } else {
- throw new IllegalArgumentException("Wikitty in argument don't have same id");
- }
- }
-
- /**
- * Always call this method because field is transient.
- *
- * @return
- */
- protected PropertyChangeSupport getPropertyChangeSupport() {
- if (propertyChange == null) {
- propertyChange = new PropertyChangeSupport(this);
- }
- return propertyChange;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#addPropertyChangeListener(java.beans.PropertyChangeListener)
- */
- @Override
- public synchronized void addPropertyChangeListener(
- PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(listener);
- }
-
-
- /*
- * @see org.nuiton.wikitty.Wikitty#removePropertyChangeListener(java.beans.PropertyChangeListener)
- */
- @Override
- public synchronized void removePropertyChangeListener(
- PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(listener);
- }
-
-
- /*
- * @see org.nuiton.wikitty.Wikitty#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
- */
- @Override
- public synchronized void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
- }
-
-
- /*
- * @see org.nuiton.wikitty.Wikitty#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
- */
- @Override
- public synchronized void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getId()
- */
- @Override
- public String getId() {
- return id;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#isDeleted()
- */
- @Override
- public boolean isDeleted() {
- boolean result = deleteDate != null;
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getDeleteDate()
- */
- @Override
- public Date getDeleteDate() {
- return deleteDate;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#setDeleteDate(java.util.Date)
- */
- @Override
- public void setDeleteDate(Date delete) {
- this.deleteDate = delete;
- }
-
- /**
- * Mark field as dirty.
- *
- * @param ext
- * @param fieldName
- */
- protected void setFieldDirty(String ext, String fieldName,
- Object oldValue, Object newValue) {
- String key = ext + "." + fieldName;
- fieldDirty.add(key);
- version = WikittyUtil.incrementMinorRevision(version);
- getPropertyChangeSupport().firePropertyChange(key, oldValue, newValue);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#addExtension(org.nuiton.wikitty.WikittyExtension)
- */
- @Override
- public void addExtension(WikittyExtension ext) {
- String required = ext.getRequires();
- if (required != null && !required.isEmpty() &&
- !extensions.containsKey(required)) {
- throw new WikittyException(String.format(
- "You try to add extension '%s' that" +
- " required not available extension '%s' in this wikitty",
- ext.getName(), required));
- }
- extensions.put(ext.name, ext);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#hasMetaExtension(String, String)
- */
- @Override
- public boolean hasMetaExtension(String metaExtensionName,
- String extensionName) {
- String metaExtensionFQName = WikittyUtil.getFQMetaExtensionName(
- metaExtensionName,
- extensionName);
- boolean hasMetaExtension = extensions.containsKey(metaExtensionFQName);
- return hasMetaExtension;
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, WikittyExtension)
- */
- @Override
- public void addMetaExtension(WikittyExtension metaExtension,
- WikittyExtension extension) {
- addMetaExtension(metaExtension, extension.getName());
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, String)
- */
- @Override
- public void addMetaExtension(WikittyExtension metaExtension, String extensionName) {
- if (hasExtension(extensionName)) {
- String metaExtensionFQName = WikittyUtil.getFQMetaExtensionName(
- metaExtension.getName(),
- extensionName);
- extensions.put(metaExtensionFQName, metaExtension);
- } else {
- throw new IllegalArgumentException("this wikitty doesn't have an extension named " + extensionName);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#addExtension(java.util.List)
- */
- @Override
- public void addExtension(List<WikittyExtension> exts) {
- for (WikittyExtension ext : exts) {
- addExtension(ext);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#hasExtension(java.lang.String)
- */
- @Override
- public boolean hasExtension(String extName) {
- return extensions.containsKey(extName);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#hasField(java.lang.String, java.lang.String)
- */
- @Override
- public boolean hasField(String extName, String fieldName) {
- boolean result = false;
- WikittyExtension ext = extensions.get(extName);
- if (ext != null) {
- result = ext.getFieldType(fieldName) != null;
- }
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getExtension(java.lang.String)
- */
- @Override
- public WikittyExtension getExtension(String ext) {
- WikittyExtension result = extensions.get(ext);
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getExtensionNames()
- */
- @Override
- public Collection<String> getExtensionNames() {
- Collection<String> result = extensions.keySet();
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getExtensions()
- */
- @Override
- public Collection<WikittyExtension> getExtensions() {
- Collection<WikittyExtension> result = extensions.values();
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getExtensionDependencies(java.lang.String, boolean)
- */
- @Override
- public Collection<WikittyExtension> getExtensionDependencies(String ext, boolean recursively) {
- Collection<WikittyExtension> result = new HashSet<WikittyExtension>();
- Collection<WikittyExtension> all = extensions.values();
- for (WikittyExtension dependency : all) {
- String requires = dependency.getRequires();
- if(requires != null && !requires.isEmpty() && requires.equals(ext)) {
- result.add(dependency);
- if(recursively) {
- String dependencyName = dependency.getName();
- Collection<WikittyExtension> dependencies = getExtensionDependencies(dependencyName, recursively);
- result.addAll(dependencies);
- }
- }
- }
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldType(java.lang.String)
- */
- @Override
- public FieldType getFieldType(String fqfieldName) {
- try {
- String[] field = fqfieldName.split("\\.");
- WikittyExtension ext = getExtension(field[0]);
- if (ext == null) {
- throw new WikittyException(String.format(
- "Extension '%s' doesn't exists on wikitty '%s'", field[0], id));
- } else {
- String fieldName = field[1];
- int crochet = fieldName.indexOf("[");
- if (crochet != -1) {
- fieldName = fieldName.substring(0, crochet);
- }
- FieldType result = ext.getFieldType(fieldName);
- if (result == null) {
- throw new WikittyException(String.format(
- "field '%s' doesn't exists on extension '%s'", fieldName, field[0]));
-
- }
- return result;
- }
- } catch (Exception eee) {
- throw new WikittyException(
- String.format("Field %s is not a fully qualified field name", fqfieldName),
- eee
- );
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#setField(java.lang.String, java.lang.String, java.lang.Object)
- */
- @Override
- public void setField(String ext, String fieldName, Object value) {
- if (! hasField(ext, fieldName)) {
- String def = "";
- for ( WikittyExtension extension : extensions.values() ) {
- def += extension.toDefinition() + "\n";
- }
- throw new WikittyException(String.format(
- "field '%s' is not valid, extensions definition : %s", ext + "." + fieldName, def));
- }
- String key = ext + "." + fieldName;
-
- // take old value if needed
- Object oldValue = null;
- if (getPropertyChangeSupport().hasListeners(key)) {
- oldValue = fieldValue.get(key);
- }
-
- // put new value
- FieldType fieldType = getExtension(ext).getFieldType(fieldName);
- Object validValue = fieldType.getValidValue(value);
- fieldValue.put(key, validValue);
-
- // mark field dirty and call listener
- setFieldDirty(ext, fieldName, oldValue, validValue);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsObject(java.lang.String, java.lang.String)
- */
- @Override
- public Object getFieldAsObject(String ext, String fieldName) {
- if (!hasField(ext, fieldName)) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid field",
- ext + "." + fieldName));
- }
- String key = ext + "." + fieldName;
- Object result = fieldValue.get(key);
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsBoolean(java.lang.String, java.lang.String)
- */
- @Override
- public boolean getFieldAsBoolean(String ext, String fieldName) {
- Object value = getFieldAsObject(ext, fieldName);
- try {
- boolean result = WikittyUtil.toBoolean(value);
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid boolean",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsBigDecimal(java.lang.String, java.lang.String)
- */
- @Override
- public BigDecimal getFieldAsBigDecimal(String ext, String fieldName) {
- Object value = getFieldAsObject(ext, fieldName);
- try {
- BigDecimal result = WikittyUtil.toBigDecimal(value);
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid numeric",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsInt(java.lang.String, java.lang.String)
- */
- @Override
- public int getFieldAsInt(String ext, String fieldName) {
- try {
- BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
- int result = value.intValue();
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid int",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsLong(java.lang.String, java.lang.String)
- */
- @Override
- public long getFieldAsLong(String ext, String fieldName) {
- try {
- BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
- long result = value.longValue();
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid int",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsFloat(java.lang.String, java.lang.String)
- */
- @Override
- public float getFieldAsFloat(String ext, String fieldName) {
- try {
- BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
- float result = value.floatValue();
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid float",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsDouble(java.lang.String, java.lang.String)
- */
- @Override
- public double getFieldAsDouble(String ext, String fieldName) {
- try {
- BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
- double result = value.doubleValue();
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid float",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsString(java.lang.String, java.lang.String)
- */
- @Override
- public String getFieldAsString(String ext, String fieldName) {
- Object value = getFieldAsObject(ext, fieldName);
- try {
- String result = WikittyUtil.toString(value);
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid String",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsDate(java.lang.String, java.lang.String)
- */
- @Override
- public Date getFieldAsDate(String ext, String fieldName) {
- Object value = getFieldAsObject(ext, fieldName);
- try {
- Date result = WikittyUtil.toDate(value);
- return result;
- } catch (WikittyException eee) {
- throw new WikittyException(String.format(
- "field '%s' is not a valid Date",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsWikitty(java.lang.String, java.lang.String)
- */
- @Override
- public String getFieldAsWikitty(String ext, String fieldName) {
- Object value = getFieldAsObject(ext, fieldName);
- String result = WikittyUtil.toWikitty(value);
- return result;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsList(java.lang.String, java.lang.String, java.lang.Class)
- */
- @Override
- public <E> List<E> getFieldAsList(String ext, String fieldName, final Class<E> clazz) {
- try {
- final Collection<E> collection = (Collection<E>) getFieldAsObject(ext, fieldName);
- if (collection != null) {
- // return unmodiable collection that check type of element
- return new AbstractList<E>() {
- List<E> contained = new ArrayList<E>(collection);
- @Override public E get(int index) {
- return WikittyUtil.cast( contained.get(index), clazz );
- }
- @Override public int size() {
- return contained.size();
- }
- };
- }
- return null;
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't get value to field '%s'",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFieldAsSet(java.lang.String, java.lang.String, java.lang.Class)
- */
- @Override
- public <E> Set<E> getFieldAsSet(String ext, String fieldName, final Class<E> clazz) {
- try {
- final Set<E> result = (Set<E>) getFieldAsObject(ext, fieldName);
- if (result != null) {
- // return unmodifable Set
- return new AbstractSet<E>() {
- Set<E> contained = result;
- @Override public int size() {
- return contained.size();
- }
- @Override
- public Iterator<E> iterator() {
- return new Iterator<E>() {
- Iterator containedIterator = contained.iterator();
- public boolean hasNext() {
- return containedIterator.hasNext();
- }
-
- public E next() {
- Object o = containedIterator.next();
- return WikittyUtil.cast(o, clazz);
- }
-
- public void remove() {
- throw new UnsupportedOperationException("Not supported operation");
- }
- };
-
- }
- };
- }
- return result;
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't get value to field '%s'",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#addToField(java.lang.String, java.lang.String, java.lang.Object)
- */
- @Override
- public void addToField(String ext, String fieldName, Object value) {
- try {
- FieldType fieldType = getExtension(ext).getFieldType(fieldName);
- Collection col = (Collection) getFieldAsObject(ext, fieldName);
- if (col == null) {
- if (fieldType.isUnique()) {
- col = new HashSet();
- } else {
- col = new ArrayList();
- }
- col.add(value);
- setField(ext, fieldName, col);
- // no call dirty, because already done in setField
- } else {
- // check upper bound only if col exists,
- // because ask upper bound == 0 is ridiculous
-
- if (fieldType.isUnique()) {
- if (!col.contains(value)) {
- // only add if not already in collection (unique)
- if (col.size() + 1 > fieldType.getUpperBound()) {
- // if upper bound reached, throw an exception
- throw new WikittyException(String.format(
- "Can't add value for field '%s', upper bound is reached",
- ext + "." + fieldName));
- }
- col.add(value);
- setFieldDirty(ext, fieldName, null, col);
- }
- } else {
- if (col.size() + 1 > fieldType.getUpperBound()) {
- throw new WikittyException(String.format(
- "Can't add value for field '%s', upper bound is reached",
- ext + "." + fieldName));
- }
- col.add(value);
- setFieldDirty(ext, fieldName, null, col);
- }
- }
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't add value to field '%s'",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#removeFromField(java.lang.String, java.lang.String, java.lang.Object)
- */
- @Override
- public void removeFromField(String ext, String fieldName, Object value) {
- try {
- Collection col = (Collection) getFieldAsObject(ext, fieldName);
- if (col != null) {
- FieldType type = getExtension(ext).getFieldType(fieldName);
- if (col.contains(value)) {
- if (col.size() - 1 < type.getLowerBound()) {
- throw new WikittyException(String.format(
- "Can't remove value for field '%s', lower bound is reached",
- ext + "." + fieldName));
- } else {
- if (col.remove(value)) {
- // field is dirty only if remove is done
- setFieldDirty(ext, fieldName, null, col);
- }
- }
- }
- }
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't remove value for field '%s'",
- ext + "." + fieldName), eee);
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#clearField(java.lang.String, java.lang.String)
- */
- @Override
- public void clearField(String ext, String fieldName) {
- FieldType type = getExtension(ext).getFieldType(fieldName);
- if (type.getLowerBound() > 0) {
- throw new WikittyException(String.format(
- "Can't clear values for field '%s', lower bound is > 0",
- ext + "." + fieldName));
- }
- try {
- Collection col = (Collection) getFieldAsObject(ext, fieldName);
- if (col != null) {
- col.clear();
- setFieldDirty(ext, fieldName, null, col);
- }
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't clear value for field '%s'",
- ext + "." + fieldName), eee);
- }
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#addToField(String, Object)
- */
- @Override
- public void addToField(String fqFieldName, Object value) {
- String[] extAndField = fqFieldName.split("\\.");
- addToField(extAndField[0], extAndField[1], value);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#removeFromField(String, Object)
- */
- @Override
- public void removeFromField(String fqFieldName, Object value) {
- String[] extAndField = fqFieldName.split("\\.");
- removeFromField(extAndField[0], extAndField[1], value);
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#clearField(String)
- */
- @Override
- public void clearField(String fqFieldName) {
- String[] extAndField = fqFieldName.split("\\.");
- clearField(extAndField[0], extAndField[1]);
- }
-
- @Override
- public boolean equals(Object obj) {
- boolean result = false;
- if (obj instanceof Wikitty) {
- Wikitty other = (Wikitty) obj;
- result = id.equals(other.getId());
- }
- return result;
- }
-
- @Override
- public int hashCode() {
- if (id == null) {
- return super.hashCode();
- } else {
- return id.hashCode();
- }
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#fieldNames()
- */
- @Override
- public Set<String> fieldNames() {
- return fieldValue.keySet();
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getFqField(java.lang.String)
- */
- @Override
- public Object getFqField(String fqFieldName) {
- return fieldValue.get(fqFieldName);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#getVersion()
- */
- @Override
- public String getVersion() {
- return version;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#setVersion(java.lang.String)
- */
- @Override
- public void setVersion(String version) {
- this.version = version;
- }
-
- /**
- * @see org.nuiton.wikitty.Wikitty#getDirty()
- */
- public Set<String> getDirty() {
- return fieldDirty;
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#clearDirty()
- */
- @Override
- public void clearDirty() {
- fieldDirty.clear();
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#setFqField(java.lang.String, java.lang.Object)
- */
- @Override
- public void setFqField(String fieldName, Object value) {
- FieldType fieldType = getFieldType(fieldName);
- Object validValue = fieldType.getValidValue(value);
- fieldValue.put(fieldName, validValue);
- }
-
- /*
- * @see org.nuiton.wikitty.Wikitty#isEmpty()
- */
- @Override
- public boolean isEmpty() {
- return fieldValue.isEmpty();
- }
-
- @Override
- public String toString() {
- boolean cr = true;
- String str = "[" + getId() + ":" + getVersion() + "] {";
- for ( String extName : getExtensionNames() ) {
- WikittyExtension ext = getExtension(extName);
- str += (cr ? "\n" : "") + "\t<" + extName + ">\n";
- cr = false;
- for ( String fieldName : ext.getFieldNames() ) {
- str += "\t\t" + fieldName + " = " + getFieldAsString(extName, fieldName) + "\n";
- }
- }
- str += "}";
- return str;
- }
-
- /**
- * Clone is deep for extension and values
- * @return
- * @throws CloneNotSupportedException
- */
- @Override
- public WikittyImpl clone() throws CloneNotSupportedException {
- WikittyImpl result = new WikittyImpl(this.id);
- result.replace(this);
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,262 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
-import org.nuiton.util.ApplicationConfig;
-
-import org.nuiton.wikitty.importexport.ExportTask;
-import org.nuiton.wikitty.importexport.ImportExportCSV;
-import org.nuiton.wikitty.importexport.ImportExportMethod;
-import org.nuiton.wikitty.importexport.ImportExportXML;
-import org.nuiton.wikitty.importexport.ImportTask;
-import org.nuiton.wikitty.importexport.JobState;
-import org.nuiton.wikitty.search.Search;
-
-/**
- * Import/export service.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyImportExportService {
-
- static public enum FORMAT {
- XML(new ImportExportXML()),
- CSV(new ImportExportCSV());
-
- /** ieport == Importer/Exporter */
- protected ImportExportMethod ieporter;
- FORMAT(ImportExportMethod ieporter) {
- this.ieporter = ieporter;
- }
-
- public ImportExportMethod ieporter() {
- return ieporter;
- }
- };
-
- /** directory path where export asynchronous file are stored */
- protected String exportDirectory = "/tmp/";
- /** url used by client to retrieve export file when job is ended */
- protected String exportPublicURL = "file:///tmp/";
-
- /** Executor that do import export task */
- protected ExecutorService importExportExecutor;
-
- /** contains all import or export task, key is job id send to client */
- protected Map<String, Future<String>> importExportTask =
- new HashMap<String, Future<String>>();
-
- protected WikittyService ws;
- protected String securityToken;
-
- public WikittyImportExportService(
- ApplicationConfig config, String securityToken, WikittyService ws) {
- this.securityToken = securityToken;
- this.ws = ws;
-
- exportDirectory = config.getOption(
- WikittyConfig.Option.WIKITTY_EXPORT_DIRECTORY.getKey());
- exportPublicURL = config.getOption(
- WikittyConfig.Option.WIKITTY_EXPORT_PUBLICURL.getKey());
-
- int maxThread = config.getOptionAsInt(
- WikittyConfig.Option.WIKITTY_EXPORT_THREADNUMBER.getKey());
- this.importExportExecutor =
- Executors.newFixedThreadPool(maxThread);
- }
-
- public WikittyService getWikittyService() {
- return ws;
- }
-
- public String getExportDirectory() {
- return exportDirectory;
- }
-
- public String getExportPublicURL() {
- return exportPublicURL;
- }
-
- public void syncImport(FORMAT format, String s) {
- Reader reader = new StringReader(s);
- ImportTask task = new ImportTask(securityToken, ws, format, reader);
- task.run();
- }
-
- public void syncImportFromUri(FORMAT format, String uri) {
- try {
- URL url = new URL(uri);
- Reader reader = new InputStreamReader(url.openStream());
- ImportTask task = new ImportTask(securityToken, ws, format, reader);
- task.run();
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't import in format %s uri %s", format, uri), eee);
- }
- }
-
- public String asyncImportFromUri(FORMAT format, String uri) {
- try {
- URL url = new URL(uri);
- Reader reader = new InputStreamReader(url.openStream());
- ImportTask task = new ImportTask(securityToken, ws, format, reader);
- FutureTask<String> future = new FutureTask<String>(task, null);
- importExportExecutor.submit(future);
-
- String jobId = UUID.randomUUID().toString();
- importExportTask.put(jobId, future);
- return jobId;
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't import in format %s uri %s", format, uri), eee);
- }
- }
-
- /**
- * Asynchronous export by example.
- *
- * @param format export format
- * @param e sample
- * @return job id
- */
- public String asyncExportAllByExample(FORMAT format, BusinessEntityWikitty e) {
- Criteria criteria = Search.query(e.getWikitty()).criteria();
- String result = asyncExportAllByCriteria(format, criteria);
- return result;
- }
-
- /**
- * Synchronous export by example.
- *
- * @param format export format
- * @param e sample
- * @return export string
- */
- public String syncExportAllByExample(FORMAT format, BusinessEntityWikitty e) {
- Criteria criteria = Search.query(e.getWikitty()).criteria();
- String result = syncExportAllByCriteria(format, criteria);
- return result;
- }
-
- /**
- * Asynchronous export by criteria.
- *
- * @param format export format
- * @param criteria criteria
- * @return export as string
- */
- public String asyncExportAllByCriteria(FORMAT format, Criteria criteria) {
- try {
- String jobId = UUID.randomUUID().toString();
-
- File file = new File(exportDirectory, jobId);
- String url = exportPublicURL + jobId;
- Writer result = new FileWriter(file);
- ExportTask task = new ExportTask(
- securityToken, ws, format, criteria, result);
- FutureTask<String> future = new FutureTask<String>(task, url);
- importExportExecutor.submit(future);
-
- importExportTask.put(jobId, future);
- return jobId;
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't export in format %s", format), eee);
- }
- }
-
- /**
- * Synchronous export by criteria.
- *
- * @param format export format
- * @param criteria criteria
- * @return export as string
- */
- public String syncExportAllByCriteria(FORMAT format, Criteria criteria) {
- StringWriter result = new StringWriter();
- ExportTask task = new ExportTask(
- securityToken, ws, format, criteria, result);
- task.run();
- return result.toString();
- }
-
- /**
- * Return job information.
- *
- * @param jobId job id
- * @return job state
- */
- public JobState infoJob(String jobId) {
- try {
- Future<String> future = importExportTask.get(jobId);
- JobState result = new JobState();
- if (future.isDone()) {
- result.status = "done";
- result.resourceUri = future.get();
- } else if (future.isCancelled()) {
- result.status = "cancelled";
- } else {
- result.status = "inProgress";
- }
- return result;
- } catch (Exception eee) {
- throw new WikittyException(String.format(
- "Can't retrieve job info for job %s", jobId), eee);
- }
- }
-
- public void cancelJob(String jobId) {
- Future<String> future = importExportTask.get(jobId);
- future.cancel(true); // true to kill process, perhaps to strong ?
- }
-
- public void freeJobResource(String jobId) {
- Future<String> future = importExportTask.remove(jobId);
- if (future != null) {
- File file = new File(exportDirectory, jobId);
- file.delete();
- }
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyLabelUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyLabelUtil.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyLabelUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,111 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin
- * %%
- * 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;
-
-
-import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.search.Search;
-
-/**
- * Util method to manage Label (add and find)
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyLabelUtil {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyLabelUtil.class);
-
- /**
- * Add new lable to the wikitty object.
- *
- * @param proxy
- * @param wikittyId object'id
- * @param label label to add
- */
- static public void addLabel(WikittyProxy proxy, String wikittyId, String label) {
- Wikitty w = proxy.restore(wikittyId);
- WikittyLabelImpl l = new WikittyLabelImpl(w);
- l.addLabels(label);
- proxy.store(l);
- }
-
- /**
- * Recherche tous les objets qui ont ce label
- *
- * @param proxy
- * @param label
- * @param firstIndex
- * @param endIndex
- * @return
- */
- static public PagedResult<Wikitty> findAllByLabel(WikittyProxy proxy,
- String label, int firstIndex, int endIndex) {
- WikittyLabelImpl l = new WikittyLabelImpl();
- l.addLabels(label);
-
- Criteria criteria = Search.query(l.getWikitty()).criteria()
- .setFirstIndex(firstIndex).setEndIndex(endIndex);
- PagedResult<Wikitty> result = proxy.findAllByCriteria(criteria);
-
- return result;
- }
-
- /**
- * Recherche le premier objet qui a ce label
- * @param proxy
- * @param label
- * @return
- */
- static public Wikitty findByLabel(WikittyProxy proxy, String label) {
- WikittyLabelImpl l = new WikittyLabelImpl();
- l.addLabels(label);
- Criteria criteria = Search.query(l.getWikitty()).criteria();
- Wikitty result = proxy.findByCriteria(criteria);
-
- return result;
- }
-
- /**
- * Retrieve all labels applied on a wikitty object.
- *
- * @param proxy
- * @param wikittyId
- * @return set of label
- */
- static public Set<String> findAllAppliedLabels(WikittyProxy proxy, String wikittyId) {
- Wikitty w = proxy.restore(wikittyId);
- Set<String> result = WikittyLabelHelper.getLabels(w);
-
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,82 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyMetaExtensionUtil {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyMetaExtensionUtil.class);
-
- private static String SEPARATOR = ":";
-
- /**
- * generate id for meta extension and extension
- * @return a wikitty id
- */
- static public String generateId(
- String metaExtensionName, String extensionName) {
- return String.format("%s%s%s", metaExtensionName, SEPARATOR, extensionName);
- }
-
- /**
- * Extract meta extension name from wikittyId. If Id is not meta extension
- * id, return null
- */
- static public String extractMetaName(String id) {
- String[] ids = id.split(SEPARATOR);
- if (ids.length == 2) {
- return ids[0];
- } else {
- return null;
- }
- }
-
- /**
- * Extract extension name from wikittyId. If Id is not meta extension
- * id, return null
- */
- static public String extractExtName(String id) {
- String[] ids = id.split(SEPARATOR);
- if (ids.length == 2) {
- return ids[1];
- } else {
- return null;
- }
- }
-
-}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -25,6 +25,14 @@
package org.nuiton.wikitty;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.BusinessEntity;
+import org.nuiton.wikitty.entities.BusinessEntityWikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -35,8 +43,9 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
-import org.nuiton.wikitty.search.Element;
+import org.nuiton.wikitty.search.operators.Element;
import org.nuiton.wikitty.search.Search;
/**
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySearchEngin.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySearchEngin.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySearchEngin.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,91 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * WikittySearchEngin is used to abstract search engine used in WikittyService.
- *
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public interface WikittySearchEngin {
-
- /**
- * Remove all data in index
- */
- public void clear(WikittyTransaction transaction);
-
- /**
- * Store wikitty in storage
- * @return information usefull for client side update data
- */
- public void store(WikittyTransaction transaction,
- Collection<Wikitty> wikitties);
-
- /**
- * Delete all object with idList argument. If id is not valid or don't exist.
- *
- * @param idList list of ids to delete
- * @return <code>UpdateResponse</code>>
- * @throws WikittyException
- */
- public void delete(WikittyTransaction transaction,
- Collection<String> idList) throws WikittyException;
-
- /**
- * Delete all object with idList argument. idList is directly passed to search engine
- * and is processed without any other kind of treatment.
- *
- * @param idList list of ids to delete
- * @return <code>UpdateResponse</code>
- * @throws WikittyException
- */
- public void delete(Collection<String> idList) throws WikittyException;
-
- public PagedResult<String> findAllByCriteria(WikittyTransaction transaction, Criteria criteria);
-
- /**
- * Find count of child for a node
- * @param w
- * @return
- */
- public Integer findNodeCount(WikittyTransaction transaction, Wikitty w, Criteria filter);
-
- /**
- * Find all children ids with count for a node wikitty.
- * @param w
- * @return
- */
- public Map<String, Integer> findAllChildrenCount(WikittyTransaction transaction, Wikitty w, Criteria filter);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,142 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.search.Search;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittySecurityHelper {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittySecurityHelper.class);
-
- /** nom du groupe des administrateurs de l'application */
- static final public String WIKITTY_APPADMIN_GROUP_NAME = "WikittyAppAdmin";
-
- /**
- * get the id of a user given his login.
- *
- * @param securityToken a token
- * @param login the login of the user to search for
- * @return a wikitty id
- */
- static public String getUserWikittyId(WikittyProxy proxy, String login) {
- String userWikittyId = null;
- Wikitty user = proxy.findByCriteria(Search.query().eq(
- WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
- if (user != null) {
- userWikittyId = user.getId();
- }
- return userWikittyId;
- }
-
- /**
- * create appAdminGroup and add current user as first member
- */
- static public WikittyGroup createAppAdminGroup(WikittyUser user) {
- WikittyGroup result = new WikittyGroupImpl();
- result.setName(WIKITTY_APPADMIN_GROUP_NAME);
-
- String firstUserId = user.getWikittyId();
- result.addMembers(firstUserId);
-
- return result;
- }
-
- /**
- * create wikitty that represent a <strong>level 2</strong> security policy
- * on the given extension.
- *
- * Store must check if this security policy doesn't already exist
- *
- */
- static public Wikitty createExtensionAuthorisation(WikittyUser owner,
- WikittyExtension extension) {
-
- String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
- Wikitty result = new WikittyImpl(wikittyAuthorisationId);
- WikittyAuthorisationHelper.addExtension(result);
- WikittyAuthorisationHelper.setOwner(result, owner.getWikittyId());
- return result;
- }
-
- static public Wikitty restoreExtensionAuthorisation(
- WikittyProxy proxy, WikittyExtension extension) {
- String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
- Wikitty result = proxy.restore(wikittyAuthorisationId);
- return result;
- }
-
-// /**
-// * @param securityToken token with rights to modify extension
-// * @param extensionRights a wikitty that has extension WikittyAuthorisation
-// */
-// static public void storeExtensionAuthorisation(String securityToken,
-// Wikitty extensionRights) {
-//
-// String userId = getUserId(securityToken);
-//
-// Wikitty oldVersion = ws.restore(securityToken, extensionRights.getId());
-//
-// // check that the extensionRights does not have
-// if (WikittyAuthorisationHelper.hasExtension(extensionRights)) {
-//
-// if (oldVersion == null) {
-// // if this exception is raised, you should use addExtensionAuthorisation()
-// throw new IllegalArgumentException("you can't store an authorisation for the fist time");
-//
-// } else {
-//
-// if ( userIsAnonymousOrAppAdmin(securityToken, userId) ||
-// canAdmin(securityToken, userId, null, oldVersion) ) {
-//
-// ws.store(securityToken, extensionRights);
-//
-// } else {
-// throw new SecurityException(String.format(
-// "user %s can't admin rights for this extension", userId));
-// }
-// }
-// } else {
-// throw new IllegalArgumentException(String.format(
-// "extensionRights %s is not a wikittyAuthorisation. It misses the extension",
-// extensionRights));
-// }
-// }
-//
-}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -25,9 +25,16 @@
package org.nuiton.wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyServiceListener;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
/**
* Wikitty service.
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,420 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- * Override some method of WikittyService to use cache
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceCached implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceCached.class);
-
- /** Cache. */
- protected WikittyCache cache = null;
-
- /** Delegated wikitty service implementation. */
- protected WikittyService ws;
-
- /** cache policy (configuration)
- *
- * if true the cache will always restore copies of the wikitty
- * if false the cache will restore wikitties that do a lazy copy when the
- * wikitty is modified ({@link WikittyCopyOnWrite} instances)
- *
- * default set to false. To change this value, use
- * {@link WikittyServiceCached#WikittyServiceCached(WikittyService, Properties)}
- * and set the good property.
- */
- protected boolean allwaysRestoreCopies = false;
-
- // FIXME 20101027 REMOVE IT when WikittyConfig is used everywhere
-// /**
-// * Default constructor.
-// *
-// * @param ws delegate service
-// */
-// public WikittyServiceCached(WikittyService ws) {
-// this(null, ws);
-// }
-
- /**
- * Constructor with configuration.
- *
- * @param ws delegate service
- * @param props properties (can be null)
- */
- public WikittyServiceCached(ApplicationConfig config, WikittyService ws) {
- this.ws = ws;
- cache = new WikittyCache(config);
- registerWikittyServiceListener(config);
-
- if (config != null) {
- // reading configuration and set allwaysRestoreCopies accordingly
- allwaysRestoreCopies =
- config.getOptionAsBoolean(WikittyConfig.Option.WIKITTY_CACHE_RESTORE_COPIES.getKey());
- }
- }
-
- /** wrap the wikitty or copy it according to allwaysRestoreCopies value */
- protected Wikitty wrapWikitty(Wikitty wikitty) {
-
- // Restored wikitty can be null
- if (wikitty == null) {
- return null;
- }
-
- Wikitty result = null;
- if (allwaysRestoreCopies) {
- try {
- result = wikitty.clone();
- } catch (CloneNotSupportedException e) {
- log.error("unable to clone " + wikitty, e);
- }
- }
-
- // if allwaysRestoreCopies is false and above clone failed
- if (result == null) {
- result = new WikittyCopyOnWrite(wikitty);
- }
- return result;
- }
-
- /**
- * Add cache as service listener if configuration request it.
- *
- * @param props properties (can be null)
- */
- protected void registerWikittyServiceListener(ApplicationConfig config) {
- if (config != null) {
- // add notifier as listener
- boolean listenEvents = config.getOptionAsBoolean(
- WikittyConfig.Option.WIKITTY_CACHE_LISTEN_REMOTEEVENTS.getKey());
- if (listenEvents) {
- // add service listener for synchronisation
- // listener des remote event
- addWikittyServiceListener(cache, ServiceListenerType.REMOTE);
-
- if (log.isDebugEnabled()) {
- log.debug("Listen remote event on service");
- }
- }
- }
- }
-
- @Override
- public String login(String login, String password) {
- return ws.login(login, password);
- }
-
- @Override
- public void logout(String securityToken) {
- ws.logout(securityToken);
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- return ws.canWrite(securityToken, wikitty);
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- return ws.canDelete(securityToken, wikittyId);
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- return ws.canRead(securityToken, wikittyId);
- }
-
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- WikittyServiceEvent result = ws.clear(securityToken);
- cache.clearWikitty();
- return result;
- }
-
- /**
- * delete objets in cache
- * @param ids
- */
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
- WikittyServiceEvent result = ws.delete(securityToken, ids);
- cache.removeAllWikitty(ids);
- return result;
- }
-
- /**
- * just wrap service method
- *
- * @param criteria
- * @return
- */
- @Override
- public PagedResult<String> findAllByCriteria(
- String securityToken, Criteria criteria) {
- // if we want to add cache for this method, we must clear cache when
- // addLabel, store, storeExtension are called
- return ws.findAllByCriteria(securityToken, criteria);
- }
-
- /**
- * just wrap service method
- *
- * @param securityToken
- * @param criteria
- * @param transaction
- *
- * @return
- */
- @Override
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- // if we want to add cache for this method, we must clear cache when
- // addLabel, store, storeExtension are called
- return ws.findByCriteria(securityToken, criteria);
- }
-
- /**
- * just wrap service method
- *
- * @return
- */
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- // TODO poussin 20100412: perhaps use cache for extension ?
- return ws.getAllExtensionIds(securityToken);
- }
-
- /**
- * just wrap service method
- *
- * @param extensionName
- * @return
- */
- @Override
- public List<String> getAllExtensionsRequires(
- String securityToken, String extensionName) {
- // TODO poussin 20100412: perhaps use cache for extension ?
- return ws.getAllExtensionsRequires(securityToken, extensionName);
- }
-
- /**
- * Overriden to put all restored object from server in cache
- *
- * @param securityToken security token
- * @param ids wikitty ids to restore
- * @return wikitty list
- */
- @Override
- public List<Wikitty> restore(String securityToken, List<String> ids) {
- ArrayList<String> notInCache = new ArrayList<String>();
- // linked to maintains the ordre
- LinkedHashMap<String, Wikitty> fromCache =
- new LinkedHashMap<String, Wikitty>();
- for (String id : ids) {
- Wikitty w = cache.getWikitty(id);
- fromCache.put(id, w); // put all to maintains order
- if (w == null) { // if not found on cache, ask the server
- notInCache.add(id);
- }
- }
-
- // retrieve missing object
- List<Wikitty> missingInCache = ws.restore(securityToken, notInCache);
-
- cache.putAllWikitty(missingInCache);
-
- for (Wikitty w : missingInCache) {
- // add missing object
- fromCache.put(w.getId(), w);
- }
-
- Collection<Wikitty> tmp = fromCache.values();
-
- // wrap the resulting wikitties to prevent cache conflicts
- ArrayList<Wikitty> result = new ArrayList<Wikitty>();
- for (Wikitty w : tmp) {
- result.add(wrapWikitty(w));
- }
-
- return result;
- }
-
- /**
- * just wrap service method
- *
- * @param wikittyId
- * @param filter
- * @return
- */
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(
- String securityToken, String wikittyId, Criteria filter) {
- // FIXME lookup in cache, and put in cache
- return ws.restoreChildren(securityToken, wikittyId, filter);
- }
-
- /**
- * just wrap service method
- *
- * @param name
- * @return
- */
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- // TODO poussin 20100412: perhaps use cache for extension ?
- return ws.restoreExtensionLastVersion(securityToken, name);
- }
-
- /**
- * just wrap service method
- *
- * @param wikittyId
- * @param filter
- * @return
- */
- @Override
- public Entry<WikittyTreeNode, Integer> restoreNode(
- String securityToken, String wikittyId, Criteria filter) {
- // FIXME lookup in cache, and put in cache
- return ws.restoreNode(securityToken, wikittyId, filter);
- }
-
- /**
- * just wrap service method
- *
- * @param wikittyId
- * @return
- */
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- // FIXME lookup in cache, and put in cache
- return ws.restoreTree(securityToken, wikittyId);
- }
-
- /**
- * just wrap service method
- *
- * @param wikittyId
- * @return
- */
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
- return ws.deleteTree(securityToken, wikittyId);
- }
-
- /**
- * Overriden to put wikitty in cache
- *
- * @param wikitties
- * @param force boolean force non version version increment on saved wikitty
- * or force version on wikitty creation (version 0.0)
- * @return
- */
- @Override
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
-
- cache.putAllWikitty(result.getWikitties().values());
-
- return result;
- }
-
- @Override
- public WikittyServiceEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- // TODO poussin 20101029: perhaps use cache for extension ?
- return ws.storeExtension(securityToken, exts);
- }
-
- @Override
- public WikittyExtension restoreExtension(String securityToken, String id) {
- // TODO poussin 20101029: perhaps use cache for extension ?
- return ws.restoreExtension(securityToken, id);
- }
-
- @Override
- public Wikitty restoreVersion(
- String securityToken, String wikittyId, String version) {
- // not put it in cache
- return ws.restoreVersion(securityToken, wikittyId, version);
- }
-
- //
- // Just delegate method
- //
-
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- ws.addWikittyServiceListener(listener, type);
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- ws.removeWikittyServiceListener(listener, type);
- }
-
- @Override
- public void syncEngin(String securityToken) {
- ws.syncEngin(securityToken);
- }
-
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- return ws.replay(securityToken, events);
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- return ws.exists(securityToken, wikittyId);
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- return ws.isDeleted(securityToken, wikittyId);
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,215 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Wikitty service delegator.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class WikittyServiceDelegator implements WikittyService {
-
- /** Delegated wikitty service. */
- protected WikittyService delegate;
-
- public WikittyServiceDelegator() {
- }
-
- public WikittyServiceDelegator(WikittyService delegate) {
- setDelegate(delegate);
- }
-
- /**
- * Get delegated service.
- *
- * @return delegate service
- */
- public WikittyService getDelegate() {
- return delegate;
- }
-
- /**
- * Set delegated service.
- *
- * @param delegate delegate
- */
- public void setDelegate(WikittyService delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener,
- ServiceListenerType type) {
- delegate.addWikittyServiceListener(listener, type);
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener,
- ServiceListenerType type) {
- delegate.removeWikittyServiceListener(listener, type);
- }
-
- @Override
- public String login(String login, String password) {
- return delegate.login(login, password);
- }
-
- @Override
- public void logout(String securityToken) {
- delegate.logout(securityToken);
- }
-
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- return delegate.clear(securityToken);
- }
-
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- return delegate.replay(securityToken, events);
- }
-
- @Override
- public WikittyServiceEvent store(
- String securityToken, Collection<Wikitty> wikitties, boolean force) {
- return delegate.store(securityToken, wikitties, force);
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- return delegate.getAllExtensionIds(securityToken);
- }
-
- @Override
- public List<String> getAllExtensionsRequires(String securityToken,
- String extensionName) {
- return delegate.getAllExtensionsRequires(securityToken, extensionName);
- }
-
- @Override
- public WikittyServiceEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- return delegate.storeExtension(securityToken, exts);
- }
-
- @Override
- public WikittyExtension restoreExtension(String securityToken, String id) {
- return delegate.restoreExtension(securityToken, id);
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- return delegate.restoreExtensionLastVersion(securityToken, name);
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> id) {
- return delegate.restore(securityToken, id);
- }
-
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
- return delegate.delete(securityToken, ids);
- }
-
- @Override
- public PagedResult<String> findAllByCriteria(
- String securityToken, Criteria criteria) {
- return delegate.findAllByCriteria(securityToken, criteria);
- }
-
- @Override
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- return delegate.findByCriteria(securityToken, criteria);
- }
-
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- return delegate.restoreTree(securityToken, wikittyId);
- }
-
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
- return delegate.deleteTree(securityToken, wikittyId);
- }
-
- @Override
- public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken,
- String wikittyId, Criteria filter) {
- return delegate.restoreNode(securityToken, wikittyId, filter);
- }
-
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
- String wikittyId, Criteria filter) {
- return delegate.restoreChildren(securityToken, wikittyId, filter);
- }
-
- @Override
- public Wikitty restoreVersion(String securityToken, String wikittyId,
- String version) {
- return delegate.restoreVersion(securityToken, wikittyId, version);
- }
-
- @Override
- public void syncEngin(String securityToken) {
- delegate.syncEngin(securityToken);
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- return delegate.canWrite(securityToken, wikitty);
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- return delegate.canDelete(securityToken, wikittyId);
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- return delegate.canRead(securityToken, wikittyId);
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- return delegate.exists(securityToken, wikittyId);
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- return delegate.isDeleted(securityToken, wikittyId);
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,79 +0,0 @@
-package org.nuiton.wikitty;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Same as delegator but with some helpfull method for developer. This new
- * methods are methods with less arguments or simple argument and not collection
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceEnhanced extends WikittyServiceDelegator {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceEnhanced.class);
-
- public WikittyServiceEnhanced(WikittyService service) {
- super(service);
- }
-
- public WikittyServiceEvent store(String securityToken, Wikitty wikitty) {
- return store(securityToken, Collections.singleton(wikitty), false);
- }
-
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties) {
- return store(securityToken, wikitties, false);
- }
-
- public WikittyServiceEvent storeExtension(String securityToken,
- WikittyExtension ext) {
- return storeExtension(securityToken, Collections.singleton(ext));
- }
-
- /**
- *
- * @param securityToken security token
- * @param id object id to restore
- * @return the corresponding object, or null if object doesn't exist, is
- * deleted or you don't have authorisation (you can check authorisation
- * before call restore with {@link #canRead(java.lang.String, java.lang.String)}
- */
- public Wikitty restore(String securityToken, String id) {
- Wikitty result = restore(this, securityToken, id);
- return result;
- }
-
- public WikittyServiceEvent delete(String securityToken, String id) {
- return delete(securityToken, Collections.singleton(id));
- }
-
- /**
- * Conveniant static method usefull in other WikittyService implementation
- * where we don't wan't instanciate WikittyServiceEnhanced
- *
- * @param securityToken security token
- * @param id object id to restore
- * @return the corresponding object, or null if object doesn't exist, is
- * deleted or you don't have authorisation (you can check authorisation
- * before call restore with {@link #canRead(java.lang.String, java.lang.String)}
- */
- static public Wikitty restore(WikittyService ws, String securityToken, String id) {
- Wikitty result = null;
- List<Wikitty> resultList =
- ws.restore(securityToken, Collections.singletonList(id));
- if (resultList != null && resultList.size() > 0) {
- result = resultList.get(0);
- }
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,306 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import com.thoughtworks.xstream.XStream;
-import java.util.Date;
-import java.util.EnumSet;
-import java.util.EventObject;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Wikitty service event.
- *
- * Contains :
- * <ul>
- * <li>Wikitty service as source
- * <li>wikitties : wikitty added if type contains PUT_WIKITTY
- * <li>ids & remove date : if type contains REMOVE_WIKITTY
- * <li>extensions : extension added if type contains PUT_EXTENSION
- * </ul>
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class WikittyServiceEvent extends EventObject {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 9017732163643700599L;
-
- /** Message type (put, remove, clear...). */
- static public enum WikittyEventType {
- PUT_WIKITTY(WikittyServiceListener.PUT_WIKITTY_METHOD),
- REMOVE_WIKITTY(WikittyServiceListener.REMOVE_WIKITTY_METHOD),
- CLEAR_WIKITTY(WikittyServiceListener.CLEAR_WIKITTY_METHOD),
- PUT_EXTENSION(WikittyServiceListener.PUT_EXTENSION_METHOD),
- // il est impossible actuellement de supprimer des extensions
-// REMOVE_EXTENSION(WikittyServiceListener.REMOVE_EXTENSION_METHOD),
- CLEAR_EXTENSION(WikittyServiceListener.CLEAR_EXTENSION_METHOD);
-
- /** le nom de la methode du listener a appeler pour ce type d'event */
- public String listenerMethodName;
- WikittyEventType(String listenerMethodName) {
- this.listenerMethodName = listenerMethodName;
- }
- }
-
-
- /** unique event id, each event must have eventId, and event is sequence
- * without hole. (ex: 0,1,2,3,4,5,6,...) */
- protected long eventId;
-
- /** Remote event (received from server). */
- protected boolean remote;
-
- /** event type, one event can have multiple type
- * (ex: PUT_WIKITTY + PUT_EXTENSION */
- protected EnumSet<WikittyEventType> type;
-
- /** heure de creation de l'event */
- protected long time;
-
- /** Use by PUT_WIKITTY, all wikitties added */
- protected Map<String, Wikitty> wikitties;
-
- /** Use by REMOVE_WIKITTY. key: wikittyId, value: removed date */
- protected Map<String, Date> removeDate;
-
- /** Use by PUT_EXTENSION, all extensions added */
- protected Map<String, WikittyExtension> extensions;
-
- /**
- * Constructor with source {@link WikittyService}.
- *
- * @param source wikitty service
- * @param eventId unique event id
- */
- public WikittyServiceEvent(Object source) {
- super(source);
- this.time = System.currentTimeMillis();
- this.type = EnumSet.noneOf(WikittyEventType.class);
- }
-
- /**
- * Return time of event creation
- * @return
- */
- public long getTime() {
- return time;
- }
-
- /**
- * To allow set transient source after deserialisation.
- *
- * @param source source
- */
- public void setSource(Object source) {
- this.source = source;
- }
-
- public EnumSet<WikittyEventType> getType() {
- return type;
- }
-
- /**
- * @param type
- */
- public void addType(WikittyEventType type) {
- this.type.add(type);
- }
-
- /**
- * Is event remote.
- *
- * @return remote event
- */
- public boolean isRemote() {
- return remote;
- }
-
- /**
- * Change remote event property.
- *
- * @param remote remote
- */
- public void setRemote(boolean remote) {
- this.remote = remote;
- }
-
- public long getEventId() {
- return eventId;
- }
-
- /**
- * This method must be call with right id, just before send message
- * notification
- * @param eventId
- */
- public void setEventId(long eventId) {
- this.eventId = eventId;
- }
-
- public Map<String, Wikitty> getWikitties() {
- return wikitties;
- }
-
- public void addWikitty(Wikitty wikitty) {
- if (wikitties == null) {
- wikitties = new LinkedHashMap<String, Wikitty>();
- addType(WikittyEventType.PUT_WIKITTY);
- }
- this.wikitties.put(wikitty.getId(), wikitty);
- }
-
- public Map<String, Date> getRemoveDate() {
- return removeDate;
- }
-
- public void addRemoveDate(String wikittyId, Date date) {
- if (removeDate == null) {
- removeDate = new HashMap<String, Date>();
- addType(WikittyEventType.REMOVE_WIKITTY);
- }
- removeDate.put(wikittyId, date);
- }
-
- public Map<String, WikittyExtension> getExtensions() {
- return extensions;
- }
-
- public void addExtension(WikittyExtension extension) {
- if (extensions == null) {
- extensions = new LinkedHashMap<String, WikittyExtension>();
- addType(WikittyEventType.PUT_EXTENSION);
- }
- extensions.put(extension.getId(), extension);
- }
-
- /**
- * Merge this event with event passed in arguement. Merged datas are:
- * <li> type
- * <li> wikitties
- * <li> extensions
- * <li> removeDate
- *
- * @param e
- */
- public void add(WikittyServiceEvent e) {
- getType().addAll(e.getType());
- if (e.getWikitties() != null) {
- for (Map.Entry<String, Wikitty> i : e.getWikitties().entrySet()) {
- addWikitty(i.getValue());
- }
- }
- if (e.getExtensions() != null) {
- for (Map.Entry<String, WikittyExtension> i : e.getExtensions().entrySet()) {
- addExtension(i.getValue());
- }
- }
- if (e.getRemoveDate() != null) {
- for (Map.Entry<String, Date> i : e.getRemoveDate().entrySet()) {
- addRemoveDate(i.getKey(), i.getValue());
- }
- }
- }
-
- /**
- * Update data directly in object passed in argument.
- * Actualy only version and deletion date are updated.
- * <p>
- * rem: during store action, no migration has done. Migration is only
- * done during restore process. This implies that extension don't change
- * after store. But another client, may can load wikitty with migration
- * and store it, or add manualy some extension. In that case, stored wikitty
- * has new/more extension that another client.
- * <p>
- * And internaly wikitty object is marked clean (not dirty)
- * @param e
- * @return wikitty passed in arguement or null, if event is CLEAR_WIKITTY
- */
- public Wikitty update(Wikitty e) {
- // update version
- String id = e.getId();
- if (type.contains(WikittyEventType.CLEAR_WIKITTY)) {
- e = null;
- } else {
- if (type.contains(WikittyEventType.PUT_WIKITTY)) {
- Wikitty newWikitty = getWikitties().get(id);
- e.replace(newWikitty);
- }
- if (type.contains(WikittyEventType.REMOVE_WIKITTY)) {
- Date date = getRemoveDate().get(id);
- e.setDeleteDate(date);
- }
- e.clearDirty();
- }
- return e;
- }
-
- @Override
- public String toString() {
- String toString = getClass().getName()
- + "[source=" + source
- + ", eventId=" + eventId
- + ", time=" + time
- + ", type=" + type
- + ", remote=" + remote
- + ", wikitties=" + wikitties
- + ", removeDate=" + removeDate
- + ", extensions=" + extensions
- + "]";
- return toString;
- }
-
- /**
- * Permet de serializer en XML l'event. Pourrait etre utilise pour l'envoi
- * sur un transporteur qui ne peremt pas la serialisation java
- * @return
- */
- public String toXML() {
- XStream xstream = new XStream();
- xstream.setMode(XStream.NO_REFERENCES);
- xstream.alias("event", WikittyServiceEvent.class);
- String result = xstream.toXML(this);
- return result;
- }
-
- /**
- * Inverse de la methode toXML
- * @param xml
- * @return
- */
- static public WikittyServiceEvent fromXML(String xml) {
- XStream xstream = new XStream();
- xstream.alias("event", WikittyServiceEvent.class);
- WikittyServiceEvent result = (WikittyServiceEvent)xstream.fromXML(xml);
- return result;
- }
-}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,6 +1,7 @@
package org.nuiton.wikitty;
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,1086 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.AbstractMap.SimpleEntry;
-import java.util.LinkedHashSet;
-import java.util.Map.Entry;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.search.Search;
-
-/**
- * WikittyService is main service
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceImpl implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceImpl.class);
-
- /** Default migration use to migrate a wikitty in last extension version */
- protected WikittyExtensionMigration defaultExtensionMigration =
- new WikittyExtensionMigrationRename();
-
- protected WikittySearchEngin searchEngin;
- protected WikittyExtensionStorage extensionStorage;
- protected WikittyStorage wikittyStorage;
-
- /**
- * FIXME poussin 20101027 remove it when all used WikittyServiceHelper.build
- *
- * Used by specific child
- * {@link org.nuiton.wikitty.jdbc.WikittyServiceJDBC}
- * {@link org.nuiton.wikitty.jdbc.WikittyServiceJPA}
- * {@link org.nuiton.wikitty.jdbc.WikittyServiceHbase}
- */
- protected WikittyServiceImpl() {
- }
-
- public WikittyServiceImpl(WikittyExtensionStorage extensionStorage,
- WikittyStorage wikittyStorage,
- WikittySearchEngin searchEngin) {
- this.extensionStorage = extensionStorage;
- this.wikittyStorage = wikittyStorage;
- this.searchEngin = searchEngin;
- }
-
- protected WikittySearchEngin getSearchEngin() {
- return searchEngin;
- }
-
- protected WikittyExtensionStorage getExtensionStorage() {
- return extensionStorage;
- }
-
- protected WikittyStorage getWikittyStorage() {
- return wikittyStorage;
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyService#addWikittyServiceListener(org.nuiton.wikitty.WikittyServiceListener, org.nuiton.wikitty.WikittyService.ServiceListenerType)
- */
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- throw new UnsupportedOperationException("Can't add listener on " + WikittyServiceImpl.class.getName());
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyService#removeWikittyServiceListener(org.nuiton.wikitty.WikittyServiceListener, org.nuiton.wikitty.WikittyService.ServiceListenerType)
- */
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- throw new UnsupportedOperationException("Can't remove listener on " + WikittyServiceImpl.class.getName());
- }
-
- @Override
- public String login(String login, String password) {
- log.warn("login asked, but there is no security service");
- return null;
- }
-
- @Override
- public void logout(String securityToken) {
- log.warn("logout asked, but there is no security service");
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- return true;
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- return true;
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- return true;
- }
-
- protected void checkConstraint(Collection<Wikitty> wikitties) {
- for(Wikitty w : wikitties) {
- for(WikittyExtension ext : w.getExtensions()) {
- for (String fieldName : ext.getFieldNames()) {
- FieldType type = ext.getFieldType(fieldName);
- if (type.isNotNull()) {
- if (null == w.getFieldAsObject(ext.getName(), fieldName)) {
- throw new WikittyException(String.format(
- "Field %s must not be null", fieldName));
- }
- }
- }
- }
- }
- }
-
-// @Override
-// public UpdateResponse store(String securityToken, WikittyTransaction transaction,
-// Collection<Wikitty> wikitties, boolean force) {
-// if (!(wikitties instanceof Set)) {
-// // use all time Set to prevent duplicated wikitty in collection
-// wikitties = new LinkedHashSet<Wikitty>(wikitties);
-// }
-// checkConstraint(wikitties);
-//
-// // update/store extension if necessary
-// Set<WikittyExtension> allExtensions = new LinkedHashSet<WikittyExtension>();
-// for (Wikitty w : wikitties) {
-// // collect all extensions used by all wikitties
-// allExtensions.addAll(w.getExtensions());
-// }
-//
-// // try to commit command
-// UpdateResponse extUpdate = getExtensionStorage().store(transaction, allExtensions);
-// UpdateResponse wikUpdate = getWikittyStorage().store(transaction, wikitties, force);
-// UpdateResponse indexUpdate = getSearchEngin().store(transaction, wikitties);
-//
-// UpdateResponse result = new UpdateResponse();
-// // prepare update client response
-// result.add(extUpdate);
-// result.add(wikUpdate);
-// result.add(indexUpdate);
-//
-// return result;
-// }
- @Override
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = store(securityToken, null, wikitties, force);
- return result;
- }
-
- protected WikittyServiceEvent store(String securityToken,
- WikittyTransaction transaction,
- Collection<Wikitty> wikitties, boolean force) {
- if (!(wikitties instanceof Set)) {
- // use all time Set to prevent duplicated wikitty in collection
- wikitties = new LinkedHashSet<Wikitty>(wikitties);
- }
- checkConstraint(wikitties);
-
- // update/store extension if necessary
- Set<WikittyExtension> allExtensions = new LinkedHashSet<WikittyExtension>();
- for (Wikitty w : wikitties) {
- // collect all extensions used by all wikitties
- allExtensions.addAll(w.getExtensions());
- }
-
- boolean txCreated = false;
- try {
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- // try to commit command
- WikittyServiceEvent extUpdate =
- getExtensionStorage().store(transaction, allExtensions);
- WikittyServiceEvent wikUpdate =
- getWikittyStorage().store(transaction, wikitties, force);
- getSearchEngin().store(transaction, wikitties);
-
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- // prepare update client response
- result.add(extUpdate);
- result.add(wikUpdate);
-
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Can't store wikitty", eee);
- }
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- List<String> result = getExtensionStorage().getAllExtensionIds(transaction);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't retrieve all extension's ids", eee);
- }
- }
-
- @Override
- public List<String> getAllExtensionsRequires(
- String securityToken, String extensionName) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- List<String> result = getExtensionStorage()
- .getAllExtensionsRequires(transaction, extensionName);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException(String.format(
- "Can't retrieve all required extension for %s", extensionName), eee);
- }
- }
-
- @Override
- public WikittyServiceEvent storeExtension(
- String securityToken, Collection<WikittyExtension> exts) {
- WikittyServiceEvent result = storeExtension(securityToken, null, exts);
- return result;
- }
-
- protected WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts) {
- boolean txCreated = false;
- try {
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- WikittyServiceEvent result =
- getExtensionStorage().store(transaction, exts);
-
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Can't store extensions", eee);
- }
- }
-
- @Override
- public WikittyExtension restoreExtension(
- String securityToken, String extensionId) {
- WikittyExtension result = restoreExtension(securityToken, null, extensionId);
- return result;
- }
-
- protected WikittyExtension restoreExtension(
- String securityToken, WikittyTransaction transaction, String extensionId) {
- boolean txCreated = false;
- try {
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- //split the id to ensure that version is normalized
- String name = WikittyExtension.computeName(extensionId);
- String version = WikittyExtension.computeVersion(extensionId);
-
- WikittyExtension result = getExtensionStorage().restore(transaction, name, version);
-
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Can't restore extensions", eee);
- }
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- WikittyExtension result = restoreExtensionLastVersion(securityToken, null, name);
- return result;
- }
-
- protected WikittyExtension restoreExtensionLastVersion(String securityToken,
- WikittyTransaction transaction, String name) {
- String version = getExtensionStorage().getLastVersion(transaction, name);
- if(version == null) {
- return null;
- }
-
- boolean txCreated = false;
- try {
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- WikittyExtension result = getExtensionStorage().restore(transaction, name, version);
-
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Can't store extensions", eee);
- }
- }
-
- protected Wikitty restore(String securityToken,
- WikittyTransaction transaction, String id) {
- if (id == null) {
- return null;
- }
- if (!getWikittyStorage().exists(transaction, id)) {
- // object doesn't exist, we return null
- return null;
- }
-
- if (getWikittyStorage().isDeleted(transaction, id)) {
- // object deleted, we return null
- return null;
- }
- Wikitty result = getWikittyStorage().restore(transaction, id);
- if(result != null) {
- result = upgradeData(securityToken, transaction, result);
- }
- return result;
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> ids) {
- List<Wikitty> result = restore(securityToken, null, ids);
- return result;
- }
-
- protected List<Wikitty> restore(String securityToken,
- WikittyTransaction transaction, List<String> ids) {
-
- List<Wikitty> result = new ArrayList<Wikitty>();
- boolean txCreated = false;
- try {
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- for (String id : ids) {
- Wikitty w = restore(securityToken, transaction, id);
- // on l'ajoutde tout le temps, meme si w est nul lorsqu'il y a
- // une demande et qu'elle echoue on ajout
- // bien null, pour qu'il y ait une correspondance 1 pour 1
- // avec la demande
- result.add(w);
- }
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Can't restore wikitty", eee);
- }
- }
-
-// @Override
-// public Wikitty restore(String securityToken, String id) {
-// WikittyTransaction transaction = new WikittyTransaction();
-// try {
-// transaction.begin();
-//
-// Wikitty result = restore(securityToken, transaction, id);
-//
-// transaction.commit();
-// return result;
-// } catch (Exception eee) {
-// transaction.rollback();
-// throw new WikittyException("Can't restore wikitty", eee);
-// }
-// }
-
- // FIXME poussin 20101029 use WikittyServiceTransaction and remove other transaction
- protected Wikitty upgradeData(String securityToken,
- WikittyTransaction transaction, Wikitty wikitty) {
- Wikitty result = wikitty;
-
- Collection<WikittyExtension> extensions = wikitty.getExtensions();
- for (WikittyExtension extension : extensions) {
- String extensionName = extension.getName();
-
- if (log.isDebugEnabled()) {
- log.debug("extensionName=" + extensionName);
- }
-
- WikittyExtension currentExtension = extension;
- String currentExtensionVersion = currentExtension.getVersion();
-
- WikittyExtension lastExtension = restoreExtensionLastVersion(
- securityToken, transaction, extensionName);
- String lastExtensionVersion = lastExtension.getVersion();
-
- if (log.isDebugEnabled()) {
- log.debug("lastExtensionVersion=" + lastExtensionVersion);
- }
-
- WikittyExtensionMigration migration =
- WikittyExtensionMigration.migrationRegistry.get(extensionName);
- if (migration == null) {
- migration = defaultExtensionMigration;
- }
-
- // Loop on between extension in wikitty and last version
- while(WikittyUtil.versionGreaterThan(lastExtensionVersion, currentExtensionVersion)) {
-
- // Get extension after the current version
- String nextExtensionVersion =
- WikittyUtil.incrementMajorRevision(currentExtensionVersion);
- String nextExtensionId =
- WikittyExtension.computeId(extensionName, nextExtensionVersion);
- WikittyExtension nextExtension = restoreExtension(
- securityToken, transaction, nextExtensionId);
-
- if (log.isDebugEnabled()) {
- log.debug("currentExtensionVersion=" + currentExtensionVersion);
- log.debug("nextExtensionVersion=" + nextExtensionVersion);
- }
-
- // Test if extension is never use in this version
- if(nextExtension != null) {
- result = migration.migrate(this, result,
- currentExtension, nextExtension);
- currentExtension = nextExtension;
- }
-
- // Follow
- currentExtensionVersion = nextExtensionVersion;
- }
- }
-
- return result;
- }
-
- protected WikittyServiceEvent delete(String securityToken, WikittyTransaction transaction,
- Collection<String> ids) throws WikittyException {
- // work only on valid id
- Collection<Wikitty> storedWikitties = new LinkedHashSet<Wikitty>();
- // copy ids because we can remove some element, and modify it
- // use set to prevent id duplication and preformance (contains method call)
- Set<String> idSet = new LinkedHashSet<String>(ids);
- for (Iterator<String> i = idSet.iterator(); i.hasNext();) {
- String id = i.next();
- // test if wikitty exists
- if (!getWikittyStorage().exists(transaction, id)) {
- // don't exist, remove this id in id list
- i.remove();
- // go to the next id, because this id doesn't exist and can't
- // be used in tree
- continue;
- }
- if (getWikittyStorage().isDeleted(transaction, id)) {
- // already deleted, remove this id in id list
- i.remove();
- // go to the next id, because this id already deleted and can't
- // be used in tree
- continue;
- }
-
- // Store node with have deleted node as parent
- Criteria criteria =
- Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT, id).criteria();
- List<String> wikittyNodesId = findAllByCriteria(
- securityToken, transaction, criteria).getAll();
- for (String wikittyNodeId : wikittyNodesId) {
- if(!idSet.contains(wikittyNodeId)) {
- Wikitty treeNode = restore(
- securityToken, transaction, wikittyNodeId);
- WikittyTreeNodeHelper.setParent(treeNode, null);
- storedWikitties.add(treeNode);
- }
- }
-
- // Store node with have deleted child
- criteria = Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_ATTACHMENT, id).criteria();
- wikittyNodesId = findAllByCriteria(
- securityToken, transaction, criteria).getAll();
- for (String wikittyNodeId : wikittyNodesId) {
- if(!idSet.contains(wikittyNodeId)) {
- Wikitty treeNode = restore(
- securityToken, transaction, wikittyNodeId);
- WikittyTreeNodeHelper.removeAttachment(treeNode, id);
- storedWikitties.add(treeNode);
- }
- }
- }
-
- WikittyServiceEvent eventDelete =
- getWikittyStorage().delete(transaction, idSet);
- getSearchEngin().delete(transaction, idSet);
-
- WikittyServiceEvent eventStore =
- store(securityToken, transaction, storedWikitties, false);
-
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- result.add(eventDelete);
- result.add(eventStore);
-
- return result;
- }
-
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids){
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- WikittyServiceEvent result = delete(securityToken, transaction, ids);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't delete wikitty", eee);
- }
- }
-
- /**
- * Use with caution : It will delete ALL indexes from search engine !
- * This operation should be disabled in production environment.
- */
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
-
- WikittyServiceEvent result = clear(securityToken, transaction);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't clear all data", eee);
- }
- }
-
- /**
- * Use with caution : It will delete ALL indexes from search engine !
- * This operation should be disabled in production environment.
- */
- protected WikittyServiceEvent clear(String securityToken, WikittyTransaction tx) {
- getSearchEngin().clear(tx);
- WikittyServiceEvent eventWik = getWikittyStorage().clear(tx);
- WikittyServiceEvent eventExt = getExtensionStorage().clear(tx);
-
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- result.add(eventWik);
- result.add(eventExt);
- return result;
- }
-
- /**
- * Assume that this PagedResult contains wikitty id as result and
- * return new PagedResult with Wikitty instance
- */
- @Override
- public PagedResult<String> findAllByCriteria(
- String securityToken, Criteria criteria) {
- PagedResult<String> result = findAllByCriteria(securityToken, null, criteria);
- return result;
- }
-
- protected PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- try {
- boolean txCreated = false;
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- PagedResult<String> result =
- getSearchEngin().findAllByCriteria(transaction, criteria);
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Error during find", eee);
- }
- }
-
- @Override
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- Wikitty result = findByCriteria(securityToken, null, criteria);
- return result;
- }
-
- protected Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- try {
- boolean txCreated = false;
- if (transaction == null) {
- transaction = new WikittyTransaction();
- txCreated = true;
- transaction.begin();
- }
-
- criteria.setFirstIndex(0).setEndIndex(1);
- PagedResult<String> pages = findAllByCriteria(
- securityToken, transaction, criteria);
-
- Wikitty result = null;
- if (pages.size() > 0) {
- String id = pages.getFirst();
- result = restore(securityToken, transaction, id);
- }
-
- if (txCreated) {
- transaction.commit();
- }
- return result;
- } catch (WikittyException ex) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw ex;
- } catch (Exception eee) {
- if (transaction != null) {
- transaction.rollback();
- }
- throw new WikittyException("Error during find", eee);
- }
- }
-
- protected WikittyTree restoreTree(String securityToken,
- WikittyTransaction transaction, String wikittyId) {
- Wikitty w = restore(securityToken, transaction, wikittyId);
- if(w == null) {
- return null;
- }
-
- if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
- throw new WikittyException(String.format(
- "Wikitty '%s' do not handle extension %s",
- wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
- }
- WikittyTree tree = new WikittyTree();
- WikittyTreeNode node = new WikittyTreeNodeImpl(w);
- tree.setNode(node);
-
- WikittyTreeNodeImpl exempleNode = new WikittyTreeNodeImpl();
- exempleNode.setParent(wikittyId);
-
- Criteria criteria = Search.query(exempleNode.getWikitty()).criteria()
- .setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS);
- PagedResult<String> childNodesId = findAllByCriteria(
- securityToken, transaction, criteria);
- for (String childNodeId : childNodesId.getAll()) {
- tree.addChild(restoreTree(securityToken, transaction, childNodeId));
- }
-
- return tree;
- }
-
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- WikittyTree tree = restoreTree(securityToken, transaction, wikittyId);
-
- transaction.commit();
- return tree;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't restore tree", eee);
- }
- }
-
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String thesaurusId) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- WikittyServiceEvent result = deleteTree(securityToken, transaction, thesaurusId);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't delete tree", eee);
- }
- }
-
- /**
- * Delete specified treenode and sub treenode.
- *
- * @param securityToken security token
- * @param transaction transaction
- * @param treeNodeId thesaurusId to delete
- * @return all id of delete nodes
- */
- protected WikittyServiceEvent deleteTree(String securityToken, WikittyTransaction transaction, String treeNodeId) {
- List<String> allTreeNodeId = getRecursiveTreeNodeId(securityToken, transaction, treeNodeId);
- WikittyServiceEvent result = delete(securityToken, transaction, allTreeNodeId);
- return result;
- }
-
- /**
- * Get recursive id of tree node children of {@code treeNodeId}.
- *
- * @param securityToken security token
- * @param transaction transaction
- * @param treeNodeId tree node id
- * @return all id of {@code treeNodeId}'s children
- */
- protected List<String> getRecursiveTreeNodeId(String securityToken, WikittyTransaction transaction, String treeNodeId) {
-
- Search search = Search.query();
- search = search.eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT, treeNodeId);
- Criteria criteria = search.criteria();
-
- PagedResult<String> childTreeNodeIds = findAllByCriteria(securityToken, transaction, criteria);
- List<String> treeNodeIds = new ArrayList<String>();
- treeNodeIds.add(treeNodeId);
- for (String childTreeNodeId : childTreeNodeIds.getAll()) {
- List<String> subTreeNodeIds = getRecursiveTreeNodeId(securityToken, transaction, childTreeNodeId);
- treeNodeIds.addAll(subTreeNodeIds);
- }
- return treeNodeIds;
- }
-
- @Override
- public Map.Entry<WikittyTreeNode, Integer> restoreNode(String securityToken,
- String wikittyId, Criteria filter) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- Wikitty w = restore(securityToken, transaction, wikittyId);
- if(w == null) {
- transaction.commit();
- return null;
- }
-
- if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
- throw new WikittyException(String.format(
- "Wikitty '%s' do not handle extension %s",
- wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
- }
-
- WikittyTreeNode node = new WikittyTreeNodeImpl(w);
- Integer count = getSearchEngin().findNodeCount(transaction, w, filter);
-
- HashMap.SimpleEntry<WikittyTreeNode, Integer> result =
- new SimpleEntry<WikittyTreeNode, Integer>(node, count);
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't restore node", eee);
- }
- }
-
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
- String wikittyId, Criteria filter) {
- WikittyTransaction transaction = new WikittyTransaction();
- try {
- transaction.begin();
-
- Wikitty w = restore(securityToken, transaction, wikittyId);
- if(w == null) {
- transaction.commit();
- return null;
- }
-
- if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
- throw new WikittyException(String.format(
- "Wikitty '%s' do not handle extension %s",
- wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
- }
-
- Map<WikittyTreeNode, Integer> result = new LinkedHashMap<WikittyTreeNode, Integer>();
-
- Map<String, Integer> search = getSearchEngin().findAllChildrenCount(
- transaction, w, filter);
- Set<Entry<String, Integer>> children = search.entrySet();
- for (Entry<String, Integer> child : children) {
- Integer count = child.getValue();
-
- String id = child.getKey();
- Wikitty wikitty = restore(securityToken, transaction, id);
- WikittyTreeNode node = new WikittyTreeNodeImpl(wikitty);
-
- result.put(node, count);
- }
-
- transaction.commit();
- return result;
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't restore children", eee);
- }
- }
-
- @Override
- public Wikitty restoreVersion(String securityToken,
- String wikittyId, String version) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public void syncEngin(final String securityToken) {
- final WikittyTransaction transaction = new WikittyTransaction();
- try {
- final int numberForCommit = 1000;
- final WikittySearchEngin searchEngin = getSearchEngin();
- final List<Wikitty> wikitties = new ArrayList<Wikitty>(numberForCommit);
-
- transaction.begin();
- searchEngin.clear(transaction);
- transaction.commit();
- transaction.begin();
-
- getWikittyStorage().scanWikitties(transaction, new WikittyStorage.Scanner() {
- int count = 0;
-
- @Override
- public void scan(String wikittyId) {
- Wikitty wikitty = restore(securityToken, transaction, wikittyId);
- Date deleteDate = wikitty.getDeleteDate();
- if(deleteDate == null) {
- count ++;
- wikitties.add(wikitty);
-
- if(count == numberForCommit) {
- // Reindex
- searchEngin.store(transaction, wikitties);
- transaction.commit();
- // Reinit
- count = 0;
- wikitties.clear();
- transaction.begin();
- }
- }
- }
- });
-
- // Last wikitties
- searchEngin.store(transaction, wikitties);
- transaction.commit();
- } catch (Exception eee) {
- transaction.rollback();
- throw new WikittyException("Can't sync searchable index with data", eee);
- }
- }
-
- /**
- * Question:
- * <li> on ne force pas le store de wikitty, ils vont donc avoir potentiellement
- * des versions differentes sur plusieurs serveurs, est-ce problematique ?
- * <li> on ne passe pas la date de suppression des wikitties, ils vont donc
- * avoir différente date de suppression sur différent serveur, est-ce problematique ?
- *
- *
- * @param securityToken
- * @param events
- * @return
- */
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- // indique qu'il faut vider la base avant de faire les ajouts
- boolean mustClear = false;
-
- // tous les objets a sauver
- Map<String, Wikitty> toAddWikitty = new LinkedHashMap<String, Wikitty>();
- // tous les id a supprimer
- Map<String, Date> toRemoveWikitty = new LinkedHashMap<String, Date>();
-
- // toutes les extensions a sauver
- Set<WikittyExtension> toAddExt = new LinkedHashSet<WikittyExtension>();
-
- // recherche un event avec un clear pour ne pas jouer des events inutiles
- // recherche un store + delete du meme wikitty
- // recherche le dernier store du wikitty
- for (WikittyServiceEvent e : events) {
- // check clear must be the first, if event have clear and other type
- // clear is all time play first
- if (e.getType().contains(
- WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
- || e.getType().contains(
- WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
- mustClear = true;
- toAddWikitty.clear();
- toRemoveWikitty.clear();
- toAddExt.clear();
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
- for (Wikitty w : e.getWikitties().values()) {
- toAddWikitty.put(w.getId(), w);
- }
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
- for (Map.Entry<String, Date> entry : e.getRemoveDate().entrySet()) {
- toAddWikitty.remove(entry.getKey());
- toRemoveWikitty.put(entry.getKey(), entry.getValue());
- }
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
- for (WikittyExtension ext : e.getExtensions().values()) {
- toAddExt.add(ext);
- }
- }
- }
-
- WikittyTransaction tx = new WikittyTransaction();
- try {
- tx.begin();
-
- // Actuellement il n'y a pas moyen de supprimer une extension (par surete)
- // donc on ne fait rien avec toRemoveExt
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- if (mustClear) {
- WikittyServiceEvent eventClear = clear(securityToken, tx);
- result.add(eventClear);
- }
- WikittyServiceEvent eventStoreExtension =
- storeExtension(securityToken, tx, toAddExt);
- result.add(eventStoreExtension);
-
- WikittyServiceEvent eventStoreWikitty =
- store(securityToken, tx, toAddWikitty.values(), false);
- result.add(eventStoreWikitty);
-
- WikittyServiceEvent eventDeleteWikitty =
- delete(securityToken, tx, toRemoveWikitty.keySet());
- result.add(eventDeleteWikitty);
-
- tx.commit();
- return result;
- } catch (Exception eee) {
- tx.rollback();
- throw new WikittyException("Can't replay data", eee);
- }
-
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- WikittyTransaction tx = new WikittyTransaction();
- try {
- tx.begin();
- boolean result = getWikittyStorage().exists(null, wikittyId);
- tx.commit();
- return result;
- } catch (Exception eee) {
- tx.rollback();
- throw new WikittyException("Can't test existance", eee);
- }
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- WikittyTransaction tx = new WikittyTransaction();
- try {
- tx.begin();
- boolean result = getWikittyStorage().isDeleted(tx, wikittyId);
- tx.commit();
- return result;
- } catch (Exception eee) {
- tx.rollback();
- throw new WikittyException("Can't test existance", eee);
- }
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,490 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.search.And;
-import org.nuiton.wikitty.search.BinaryOperator;
-import org.nuiton.wikitty.search.Element;
-import org.nuiton.wikitty.search.Restriction;
-
-/**
- * In memory implementation of WikittyService, currently used for test only.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceInMemory extends WikittyServiceImpl {
-
- //FIXME InMemory implementation is not usable for production. Must be reviewed.
- //FIXME The version increment must be done in 'prepare' method
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceInMemory.class);
-
- public static class WikittyStorageInMemory implements WikittyStorage {
- protected Map<String, Wikitty> wikitties = new LinkedHashMap<String, Wikitty>();
-
- @Override
- public WikittyServiceEvent store(WikittyTransaction transaction,
- Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- for (Wikitty wikitty : wikitties) {
- // begin with clone of wikitty to prevent modification of
- // wikitty passed as argument
- try {
- wikitty = wikitty.clone();
- } catch (CloneNotSupportedException eee) {
- throw new WikittyException("Can't clone ?", eee);
- }
-
- String actualVersion = null;
- Wikitty inMemoryWikitty = this.wikitties.get(wikitty.getId());
- if (inMemoryWikitty != null) {
- actualVersion = inMemoryWikitty.getVersion();
- }
- String requestedVersion = wikitty.getVersion();
-
- String newVersion = null;
- if (force) {
- if (actualVersion == null) { //no version in place
- if (requestedVersion == null) { //no version requested
- newVersion = WikittyUtil.DEFAULT_VERSION;
- } else { //version requested
- newVersion = requestedVersion;
- }
- } else { //version in place is not null
- if (requestedVersion == null ||
- requestedVersion.startsWith(WikittyUtil.DEFAULT_MAJOR_VERSION_PREFIX)) { //no version requested
- newVersion = WikittyUtil.incrementMajorRevision(actualVersion);
- } else if (WikittyUtil.versionEquals(actualVersion, requestedVersion)) { //same version
- // wikitty is not modified, do nothing
- continue;
- } else if (WikittyUtil.versionGreaterThan(requestedVersion, actualVersion)) { //requested version is newer
- newVersion = requestedVersion;
- } else { //requested version is obsolete
- throw new WikittyObsoleteException(String.format(
- "Your wikitty '%s' is obsolete (saving: '%s'; existing: '%s')", wikitty.getId(), requestedVersion, actualVersion));
- }
- }
- }
- else {
- if (WikittyUtil.versionEquals(actualVersion, requestedVersion)) {
- // no modification, continue
- continue;
- }
- else if (WikittyUtil.versionGreaterThan(actualVersion, requestedVersion)) {
- throw new WikittyObsoleteException(String.format(
- "Your wikitty '%s' is obsolete", wikitty.getId()));
- }
- else {
- newVersion = WikittyUtil.incrementMajorRevision(actualVersion);
- }
- }
- wikitty.setVersion(newVersion);
- wikitty.clearDirty();
-
- try {
- this.wikitties.put(wikitty.getId(), wikitty.clone());
- } catch (CloneNotSupportedException eee) {
- throw new WikittyException("Can't clone ?", eee);
- }
- result.addWikitty(wikitty);
- }
- return result;
- }
-
- @Override
- public WikittyServiceEvent delete(WikittyTransaction transaction, Collection<String> idList) throws WikittyException {
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- Date now = new Date();
- for (String id : idList) {
- Wikitty w = restore(transaction, id);
- if (w != null) {
- w.setDeleteDate(now);
- result.addRemoveDate(id, now);
- }
- }
- return result;
- }
-
- @Override
- public boolean exists(WikittyTransaction transaction, String id) {
- boolean result = wikitties.containsKey(id);
- return result;
- }
-
- @Override
- public boolean isDeleted(WikittyTransaction transaction, String id) {
- boolean result = false;
- Wikitty w = wikitties.get(id);
- if (w == null) {
- throw new WikittyException(String.format("No wikitty with id '%s'", id));
- } else {
- result = w.isDeleted();
- }
- return result;
- }
-
- @Override
- public Wikitty restore(WikittyTransaction transaction, String id, String ... fqFieldName) throws WikittyException {
- Wikitty result = wikitties.get(id);
- if (result.isDeleted()) {
- result = null;
- }
- return result;
- }
-
- @Override
- public void scanWikitties(WikittyTransaction transaction, Scanner scanner) {
- Collection<Wikitty> all = wikitties.values();
- for (Wikitty wikitty : all) {
- scanner.scan(wikitty.getId());
- }
- }
-
- @Override
- public WikittyServiceEvent clear(WikittyTransaction transaction) {
- wikitties = new LinkedHashMap<String, Wikitty>();
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY);
- return result;
- }
- }
-
- public static class WikittyExtensionStorageInMemory implements WikittyExtensionStorage {
- protected Map<String, WikittyExtension> extensions;
-
- public WikittyExtensionStorageInMemory() {
- this.extensions = new HashMap<String, WikittyExtension>();
- }
-
- @Override
- public WikittyServiceEvent store(WikittyTransaction transaction,
- Collection<WikittyExtension> exts) throws WikittyException {
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- for (WikittyExtension ext : exts) {
- // on ajoute que s'il n'y est pas deja
- if (!extensions.containsKey(ext.getId())) {
- extensions.put(ext.getId(), ext);
- result.addExtension(ext);
- }
- }
- return result;
- }
-
- @Override
- public boolean exists(WikittyTransaction transaction, String id) {
- boolean result = extensions.containsKey(id);
- return result;
- }
-
- @Override
- public List<String> getAllExtensionIds(WikittyTransaction transaction) {
- List<String> result = new ArrayList<String>(extensions.keySet());
- return result;
- }
-
- @Override
- public List<String> getAllExtensionsRequires(WikittyTransaction transaction,
- String extensionName) {
- ArrayList<String> ids = new ArrayList<String>();
-
- Collection<WikittyExtension> values = extensions.values();
- if (values != null) {
- for (WikittyExtension extension : values) {
- if (extensionName.equals(extension.getRequires())) {
- ids.add(extension.getId());
- }
- }
- }
-
- return ids;
- }
-
- @Override
- public String getLastVersion(WikittyTransaction transaction, String extName) {
- String result = null;
- Set<String> extensionIds = extensions.keySet();
- for (String extensionId : extensionIds) {
- String extensionVersion = WikittyExtension.computeVersion(extensionId);
- if(extensionId.startsWith(extName) && (result == null ||
- WikittyUtil.versionGreaterThan(extensionVersion, result))) {
- result = extensionVersion;
- }
- }
- return result;
- }
-
- @Override
- public WikittyExtension restore(WikittyTransaction transaction, String name, String version)
- throws WikittyException {
- String id = WikittyExtension.computeId(name, version);
- WikittyExtension result = extensions.get(id);
- if (result == null) {
- throw new WikittyException(String.format("No extension with id '%s'", id));
- }
- return result;
- }
-
- @Override
- public WikittyServiceEvent clear(WikittyTransaction transaction) {
- extensions = new HashMap<String, WikittyExtension>();
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION);
- return result;
- }
- }
-
- public static class WikittySearchEnginInMemory implements WikittySearchEngin {
-
- WikittyStorageInMemory wikittyStorage;
-
- public WikittySearchEnginInMemory(WikittyStorageInMemory wikittyStorage) {
- this.wikittyStorage = wikittyStorage;
- }
-
- @Override
- public void clear(WikittyTransaction transaction) {
- // do nothing
- }
-
- @Override
- public void store(WikittyTransaction transaction,
- Collection<Wikitty> wikitties) {
- }
-
- @Override
- public void delete(WikittyTransaction transaction,
- Collection<String> idList) throws WikittyException {
- }
-
-
- @Override
- public void delete(Collection<String> idList) throws WikittyException {
- }
-
- public boolean checkRestriction( Restriction restriction, Wikitty w ) {
- if ( restriction instanceof BinaryOperator ) {
- BinaryOperator binOp = (BinaryOperator) restriction;
-
- if ( binOp.getElement().getName().equals(Element.ELT_EXTENSION) ) {
- return w.hasExtension(binOp.getValue());
- }
-
- String fqfieldName = binOp.getElement().getName();
- if(Element.ELT_EXTENSION.equals(fqfieldName)) {
- return true;
- }
- else if (Element.ELT_ID.equals(fqfieldName)) {
- return w.getId().equals(binOp.getValue());
- }
-
- // Le check restriction, ne doit pas tester les champs
- // si les wikitty n'ont meme pas l'extension concerné
- String[] extName = fqfieldName.split("\\.");
- if (!w.hasField(extName[0], extName[1])) {
- return false;
- }
-
- Object o = w.getFqField( fqfieldName );
- FieldType t = w.getFieldType(fqfieldName);
- Object value = t.getValidValue(binOp.getValue());
- boolean checked = false;
- switch( restriction.getName() ) {
- case EQUALS:
- checked = value.equals(o);
- break;
- case LESS:
- checked = ((Comparable)o).compareTo( value ) < 0;
- break;
- case LESS_OR_EQUAL:
- checked = ((Comparable)o).compareTo( value ) <= 0;
- break;
- case GREATER:
- checked = ((Comparable)o).compareTo( value ) > 0;
- break;
- case GREATER_OR_EQUAL:
- checked = ((Comparable)o).compareTo( value ) >= 0;
- break;
- case NOT_EQUALS:
- checked = !value.equals(o);
- break;
- case ENDS_WITH:
- if (t.getType() != TYPE.STRING) {
- throw new WikittyException("Can't search for contents that 'ends with' on attribute type different of String. " +
- "Attribute " + fqfieldName + " is " + t.getType().name() );
- }
- checked = ((String) o).endsWith( (String) value );
- break;
- case STARTS_WITH:
- if (t.getType() != TYPE.STRING) {
- throw new WikittyException("Can't search for contents that 'starts with' on attribute type different of String. " +
- "Attribute " + fqfieldName + " is " + t.getType().name() );
- }
- checked = ((String) o).startsWith( (String) value );
- break;
- }
- return checked;
- } else if ( restriction instanceof And ) {
- And and = (And) restriction;
- for ( Restriction sub : and.getRestrictions() ) {
- if (!checkRestriction(sub, w)) {
- return false;
- }
- }
- return true;
- } else {
- throw new UnsupportedOperationException( restriction.getName() + " Search Not yet implemented");
- }
- }
-
- @Override
- public PagedResult<String> findAllByCriteria(WikittyTransaction transaction,
- Criteria criteria) {
- // throw new UnsupportedOperationException("Not supported yet.");
-
- int firstIndex = criteria.getFirstIndex();
- int endIndex = criteria.getEndIndex();
-
- List<String> ids = new LinkedList<String>();
- int currentIndex = 0;
-
- for( Entry<String, Wikitty> entry : wikittyStorage.wikitties.entrySet() ) {
- Wikitty w = entry.getValue();
- String id = entry.getKey();
- Restriction dto = criteria.getRestriction();
-
- if ( !w.isDeleted() && checkRestriction(dto, w) ) {
- currentIndex++;
- if (currentIndex > firstIndex) {
- ids.add(id);
- }
- if (endIndex >= 0 && currentIndex >= endIndex) {
- break;
- }
- }
-
- }
-
- return new PagedResult<String>(firstIndex, ids.size(), criteria.getRestriction().toString(), null, ids );
- }
-
- @Override
- public Integer findNodeCount(WikittyTransaction transaction, Wikitty w, Criteria filter) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public Map<String, Integer> findAllChildrenCount(WikittyTransaction transaction, Wikitty w, Criteria filter) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- }
-
- /**
- * if persistenceFile is not null, serialize all data to disk during store
- * operation and the file is reloaded during init
- */
- protected File persistenceFile = null;
-
- public WikittyServiceInMemory(ApplicationConfig config) {
- super(new WikittyExtensionStorageInMemory(),
- new WikittyStorageInMemory(),
- null);
- searchEngin = new WikittySearchEnginInMemory(
- (WikittyStorageInMemory) wikittyStorage);
-
- if (config != null) {
- boolean persist = config.getOptionAsBoolean(
- WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey());
- if (persist) {
- persistenceFile = config.getOptionAsFile(
- WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey());
- restoreFromPersistenceFile(persistenceFile);
- }
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- saveToPersistenceFile(persistenceFile);
-
- super.finalize();
- }
-
- protected void restoreFromPersistenceFile(File persistenceFile) {
- if (persistenceFile != null && persistenceFile.exists()) {
- try {
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(
- persistenceFile));
- ((WikittyExtensionStorageInMemory)extensionStorage).extensions = (Map) in.readObject();
- ((WikittyStorageInMemory)wikittyStorage).wikitties = (Map) in.readObject();
- in.close();
- } catch (Exception eee) {
- log.error("Can't read data file " + persistenceFile, eee);
- }
- }
- }
-
- public void saveToPersistenceFile(File persistenceFile) {
- if (persistenceFile != null) {
- try {
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- persistenceFile));
- out.writeObject(((WikittyExtensionStorageInMemory)extensionStorage).extensions);
- out.writeObject(((WikittyStorageInMemory)wikittyStorage).wikitties);
- out.close();
- } catch (IOException eee) {
- log.error("Can't write data file " + persistenceFile, eee);
- }
- }
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,57 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-/**
- * Permet d'ajouter des listeners sur les methodes de modification de
- * WikittyService.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public interface WikittyServiceListener {
-
- // this constant must be up to date with real method name
- // this is used during fire event
- final static public String PUT_WIKITTY_METHOD = "putWikitty";
- final static public String REMOVE_WIKITTY_METHOD = "removeWikitty";
- final static public String CLEAR_WIKITTY_METHOD = "clearWikitty";
- final static public String PUT_EXTENSION_METHOD = "putExtension";
- final static public String REMOVE_EXTENSION_METHOD = "removeExtension";
- final static public String CLEAR_EXTENSION_METHOD = "clearExtension";
-
- public void putWikitty(WikittyServiceEvent event);
- public void removeWikitty(WikittyServiceEvent event);
- public void clearWikitty(WikittyServiceEvent event);
-
- /** toto[1.0] */
- public void putExtension(WikittyServiceEvent event);
- public void clearExtension(WikittyServiceEvent event);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,700 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.util.ListenerSet;
-
-/**
- * Wikitty service notifier.
- *
- * Currently based on jgroups.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class WikittyServiceNotifier implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceNotifier.class);
-
- /** Service to delegate. */
- protected WikittyService ws;
-
- /** Wikitty service listener (all event). */
- protected ListenerSet<WikittyServiceListener> allWikittyServiceListeners;
-
- /** Wikitty service listener (only for local event). */
- protected ListenerSet<WikittyServiceListener> localWikittyServiceListeners;
-
- /** Wikitty service listener (only for remote event). */
- protected ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners;
-
- /** notifier */
- protected WikittyServiceListener notifier;
-
- /**
- * Tous les events en attentent d'etre envoyer aux listeners
- */
- protected LinkedBlockingQueue<WikittyServiceEvent> eventToSend;
-
- /** thread utilise pour evoyer les events */
- protected EventThread eventThread;
-
- /**
- * Constructor with configuration.
- *
- * @param ws delegate service
- * @param props properties (can be null)
- */
- public WikittyServiceNotifier(ApplicationConfig config, WikittyService ws) {
- // service
- this.ws = ws;
-
- // listeners
- allWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
- localWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
- remoteWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
-
- eventToSend = new LinkedBlockingQueue<WikittyServiceEvent>();
-
- eventThread = new EventThread(eventToSend,
- allWikittyServiceListeners, localWikittyServiceListeners,
- remoteWikittyServiceListeners);
-
- // can be null according to default constructor
- if (config != null) {
- notifier = new RemoteNotifier(config, this);
- }
- }
-
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- // not delegated
- switch (type) {
- case ALL :
- synchronized(allWikittyServiceListeners) {
- allWikittyServiceListeners.add(listener);
- }
- break;
- case LOCAL :
- synchronized(localWikittyServiceListeners) {
- localWikittyServiceListeners.add(listener);
- }
- break;
- case REMOTE :
- synchronized(remoteWikittyServiceListeners) {
- remoteWikittyServiceListeners.add(listener);
- }
- break;
- }
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- // not delegated
- switch (type) {
- case ALL :
- synchronized(allWikittyServiceListeners) {
- allWikittyServiceListeners.remove(listener);
- }
- break;
- case LOCAL :
- synchronized (localWikittyServiceListeners) {
- localWikittyServiceListeners.remove(listener);
- }
- break;
- case REMOTE :
- synchronized(remoteWikittyServiceListeners) {
- remoteWikittyServiceListeners.remove(listener);
- }
- break;
- }
- }
-
- @Override
- public String login(String login, String password) {
- return ws.login(login, password);
- }
-
- @Override
- public void logout(String securityToken) {
- ws.logout(securityToken);
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- return ws.canWrite(securityToken, wikitty);
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- return ws.canDelete(securityToken, wikittyId);
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- return ws.canRead(securityToken, wikittyId);
- }
-
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- WikittyServiceEvent result = ws.clear(securityToken);
- fireEvent(result);
- return result;
- }
-
- @Override
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
-
- // notify listeners
- fireEvent(result);
- return result;
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- // no notification
- return ws.getAllExtensionIds(securityToken);
- }
-
- @Override
- public List<String> getAllExtensionsRequires(
- String securityToken, String extensionName) {
- // no notification
- return ws.getAllExtensionsRequires(securityToken, extensionName);
- }
-
- @Override
- public WikittyServiceEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- WikittyServiceEvent result = ws.storeExtension(securityToken, exts);
- fireEvent(result);
- return result;
- }
-
- @Override
- public WikittyExtension restoreExtension(String securityToken, String id) {
- // no notification
- return ws.restoreExtension(securityToken, id);
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- // no notification
- return ws.restoreExtensionLastVersion(securityToken, name);
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> ids) {
- // no notification
- return ws.restore(securityToken, ids);
- }
-
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
- WikittyServiceEvent result = ws.delete(securityToken, ids);
- // notify listeners
- fireEvent(result);
- return result;
- }
-
- @Override
- public PagedResult<String> findAllByCriteria(String securityToken,
- Criteria criteria) {
- // no notification
- return ws.findAllByCriteria(securityToken, criteria);
- }
-
- @Override
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- // no notification
- return ws.findByCriteria(securityToken, criteria);
- }
-
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- // no notification
- return ws.restoreTree(securityToken, wikittyId);
- }
-
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
- WikittyServiceEvent result = ws.deleteTree(securityToken, wikittyId);
- fireEvent(result);
- return result;
- }
-
- @Override
- public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId,
- Criteria filter) {
- // no notification
- return ws.restoreNode(securityToken, wikittyId, filter);
- }
-
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
- String wikittyId, Criteria filter) {
- // no notification
- return ws.restoreChildren(securityToken, wikittyId, filter);
- }
-
- @Override
- public Wikitty restoreVersion(
- String securityToken, String wikittyId, String version) {
- // no notification
- return ws.restoreVersion(securityToken, wikittyId, version);
- }
-
- @Override
- public void syncEngin(String securityToken) {
- // no notification
- ws.syncEngin(securityToken);
- }
-
- /**
- * Fire event to all registred listener.
- *
- * Take care about {@link WikittyServiceEvent#isRemote()} for fire.
- *
- * @param event event to fire
- */
- protected void fireEvent(final WikittyServiceEvent event) {
- // ajout d'un thread, car si les listener doit
- // ouvrir une transaction WikittyTransaction
- // alors que celui qui lance l'event en a une ouverte
- // cela cause une exception JTA
- EventThread thread = getEventThread();
-
- // si le thread de notification est en cours d'arret on leve une exception
- if (thread.stopAsked()) {
- throw new WikittyException(
- "Event thread dispatcher is stopped, no more event can be send");
- } else {
- eventToSend.offer(event);
-
- if (!thread.isAlive()) {
- // on demarre le thread que lorsqu'il y a le premier event d'arrive
- thread.start();
- }
- }
- }
-
- /**
- * fire event passed in argument. Before fire, change source to current
- * WikittyServiceNotifier and set remote event to true.
- */
- public void processRemoteEvent(WikittyServiceEvent event) {
- //source is transient, add it here :
- event.setSource(this);
- event.setRemote(true); // received event became remote
- fireEvent(event);
- }
-
- /**
- * Retourne le dernier thread utiliser pour envoyer les events.
- *
- * @return
- */
- public EventThread getEventThread() {
- return eventThread;
- }
-
- @Override
- protected void finalize() throws Throwable {
- getEventThread().askStop();
- super.finalize();
- }
-
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- WikittyServiceEvent result = ws.replay(securityToken, events);
- // notify listeners
- fireEvent(result);
- return result;
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- return ws.exists(securityToken, wikittyId);
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- return ws.isDeleted(securityToken, wikittyId);
- }
-
- /**
- * Thread utilise pour envoyer les events. On rend accessible ce thread
- * pour pouvoir y acceder depuis l'exterieur (pour l'instant pour les tests
- * mais peut-etre plus tard du monitoring). Il permet a un thread d'attendre
- * qu'un evenement leve a une certaine heure est bien ete dispatchee grace a
- * la methode waitfor
- */
- static public class EventThread extends Thread {
-
- protected boolean mustBeRunning = true;
-
- protected SortedMap<Long, Object> waiter = new TreeMap<Long, Object>();
- /**
- * reference vers la collection qui contient les events a envoyer
- */
- protected LinkedBlockingQueue<WikittyServiceEvent> eventToSend;
-
- /** Wikitty service listener (all event). */
- protected ListenerSet<WikittyServiceListener> allWikittyServiceListeners;
-
- /** Wikitty service listener (only for local event). */
- protected ListenerSet<WikittyServiceListener> localWikittyServiceListeners;
-
- /** Wikitty service listener (only for remote event). */
- protected ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners;
-
- /** heure du dernier event envoye */
- protected long lastEventTime = 0;
-
- public EventThread(LinkedBlockingQueue<WikittyServiceEvent> eventToSend,
- ListenerSet<WikittyServiceListener> allWikittyServiceListeners,
- ListenerSet<WikittyServiceListener> localWikittyServiceListeners,
- ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners) {
- super("wikitty-event-thread");
- this.eventToSend = eventToSend;
- this.allWikittyServiceListeners = allWikittyServiceListeners;
- this.localWikittyServiceListeners = localWikittyServiceListeners;
- this.remoteWikittyServiceListeners = remoteWikittyServiceListeners;
- }
-
- /**
- * demande l'arret du thread, ne doit être appeler que par le finalize
- * du WikittyServiceNotifier
- */
- protected void askStop() {
- this.mustBeRunning = false;
- }
-
- /**
- * retourne vrai si on a demande l'arret du thread
- * @return
- */
- public boolean stopAsked() {
- return !mustBeRunning;
- }
-
- /**
- * thread that want wait for particulare event to be processed, can be
- * call this method with event time in argument. Used only in unit test
- * but this is necessary for test.
- */
- public void waitFor(long eventTime) throws InterruptedException {
- Object mutex = null;
- sleep(1); // sleep 1 millis to prevent problem with 2 events in same millis
- synchronized (waiter) {
- if (eventTime <= lastEventTime) {
- // le thread demande a attendre un event deja passe
- // on le met donc pas en attente
- if (log.isDebugEnabled()) {
- log.debug("event deja passe " + eventTime + " <= " + lastEventTime);
- }
- return;
- }
- mutex = waiter.get(eventTime);
- if (mutex == null) {
- mutex = new Object();
- waiter.put(eventTime, mutex);
- }
- }
- synchronized(mutex) {
- mutex.wait();
- }
- }
-
- @Override
- public void run() {
- while(mustBeRunning) {
- processEventQueue();
- }
- // le thread est arrete, force l'envoi de tous les events pour
- // liberer correctement tous les threads en attente
- // plus aucun event ne doit etre accepte dans la queue (voir method fireEvent)
- processEventQueue();
- }
-
- protected void processEventQueue() {
- try {
- WikittyServiceEvent event;
- // on attend pas indefiniment un event, car il faut verifier
- // aussi que personne n'a arrete le thread
- while (null != (event = eventToSend.poll(5, TimeUnit.SECONDS))) {
- try {
- synchronized (allWikittyServiceListeners) {
- for(WikittyServiceEvent.WikittyEventType type : event.getType()) {
- allWikittyServiceListeners.fire(
- type.listenerMethodName, event);
- }
- }
- } catch (Exception eee) {
- log.error("Can't notify listener", eee);
- }
- try {
- if (event.isRemote()) {
- synchronized (remoteWikittyServiceListeners) {
- for (WikittyServiceEvent.WikittyEventType type : event.getType()) {
- remoteWikittyServiceListeners.fire(
- type.listenerMethodName, event);
- }
- }
- } else {
- synchronized (localWikittyServiceListeners) {
- for (WikittyServiceEvent.WikittyEventType type : event.getType()) {
- localWikittyServiceListeners.fire(
- type.listenerMethodName, event);
- }
- }
- }
- } catch (Exception eee) {
- log.error("Can't notify listener", eee);
- }
- synchronized (waiter) {
- // on met a jour l'heure du dernier event envoye
- lastEventTime = event.getTime();
-
- // on previent les threads en attente si besoin
-
- // dans un premier temps on ne recupere que ceux
- // inferieur a event.getTime()
- SortedMap<Long, Object> subwaiter =
- waiter.headMap(event.getTime());
- for (Iterator<Map.Entry<Long, Object>> i = subwaiter.entrySet().iterator(); i.hasNext();) {
- Object mutex = i.next().getValue();
- i.remove();
- synchronized (mutex) {
- mutex.notifyAll();
- }
- }
- // dans un second temps on verifie si le suivant ne
- // serait pas egal a event.getTime()
- if (!waiter.isEmpty()) {
- Long time = waiter.firstKey();
- // il pourrait y avoir plusieurs event avec la meme heure
- // il faut bien tous les liberer
- while (time.equals(event.getTime())) {
- // il est bien egal on l'enleve aussi
- Object mutex = waiter.remove(time);
- synchronized (mutex) {
- mutex.notifyAll();
- }
-
- if (!waiter.isEmpty()) {
- time = waiter.firstKey();
- } else {
- break;
- }
- }
- }
- }
- }
- } catch (InterruptedException eee) {
- log.error("Notification thread error", eee);
- }
- }
- };
-
- /**
- * This interface must be implemented to send and received remote message.
- * Only sendMessage method is in interface but you must write receive
- * method too, but this method is protocol specific and can't appear in
- * interface
- */
- static public interface RemoteNotifierTransporter {
-
- /**
- * Send a jgroup message to all other channel member.
- *
- * @param event message to send
- */
- public void sendMessage(WikittyServiceEvent event) throws Exception;
- }
-
- /**
- * Class used to notify remote listener. This class is realy activate
- * only if wikitty.notifier.transporter.class configuration is found and
- * wikitty.service.event.propagateEvent is true
- */
- static public class RemoteNotifier implements WikittyServiceListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(RemoteNotifier.class);
-
- /** Notifier service reference reference. */
- protected WikittyServiceNotifier ws;
-
- /**
- * Indique si les objects sont propages (true) vers les autres caches ou
- * simplement supprimes des autres caches (false).
- *
- * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION
- */
- protected boolean propagateEvent = false;
- protected RemoteNotifierTransporter transporter;
-
- public RemoteNotifier(ApplicationConfig config, WikittyServiceNotifier ws) {
- // can be null according to default constructor
- if (config != null) {
- this.ws = ws;
-
- propagateEvent = config.getOptionAsBoolean(
- WikittyConfig.Option.WIKITTY_EVENT_PROPAGATE.getKey());
- if (log.isDebugEnabled()) {
- log.debug("Set propagateEvent option to " + propagateEvent);
- }
-
- if (propagateEvent) {
- transporter = WikittyServiceFactory.buildTransporter(config, ws);
- // add this as listener when transporter is created without error
- ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference
- }
- }
- if (log.isInfoEnabled()) {
- if (transporter == null) {
- log.info("RemoteNotifier synchronisation not used ");
- } else {
- log.info("RemoteNotifier transporter: " + transporter.getClass().getName());
- }
- }
- }
-
- /**
- * Send a jgroup message to all other channel member.
- *
- * @param event message to send
- */
- protected void sendMessage(WikittyServiceEvent event) {
- try {
- if (log.isDebugEnabled()) {
- log.debug("Try to send message : " + event);
- }
-
- transporter.sendMessage(event);
-
- if (log.isDebugEnabled()) {
- log.debug("Message is sent : " + event);
- }
- } catch (Exception eee) {
- if (log.isErrorEnabled()) {
- log.error("Can't send message", eee);
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
- */
- @Override
- public void putWikitty(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate putWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
- */
- @Override
- public void removeWikitty(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate removeWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
- */
- @Override
- public void clearWikitty(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate clearWikitty event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
- */
- @Override
- public void putExtension(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate putExtension event");
- }
- }
- }
-
- /*
- * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
- */
- @Override
- public void clearExtension(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate clearExtension event");
- }
- }
- }
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,819 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin
- * %%
- * 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;
-
-import static org.nuiton.i18n.I18n._;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.search.Search;
-
-/**
- *
- * FIXME add security policy level two on wikittyAuthorisation to prevent writing
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceSecurity implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceSecurity.class);
-
- protected WikittyServiceEnhanced ws;
-
- /** cache de l'id du groupe AppAdmin */
- transient protected String appAdminGroupId = null;
-
- /**
- *
- * @param config not use currently but needed in futur
- * @param ws
- */
- public WikittyServiceSecurity(ApplicationConfig config, WikittyService ws) {
- this.ws = new WikittyServiceEnhanced(ws);
- }
-
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- ws.addWikittyServiceListener(listener, type);
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- ws.addWikittyServiceListener(listener, type);
- }
-
- @Override
- public String login(String login, String password) {
- Wikitty user = ws.findByCriteria(null, Search.query().eq(
- WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
- if (user == null) {
- throw new IllegalArgumentException(String.format("no such account '%s'", login));
- } else {
- // check password is valid
- if (WikittyUserHelper.getPassword(user).equals(password)) {
- String tokenId = WikittyUtil.genSecurityTokenId();
- Wikitty wikittyToken = new WikittyImpl(tokenId);
- // force add extension to wikitty
- WikittyTokenHelper.addExtension(wikittyToken);
- WikittyTokenHelper.setUser(wikittyToken, user.getId());
- ws.store(null, Arrays.asList(wikittyToken), false);
- log.debug(String.format("token '%s' is for login '%s'",
- tokenId, login));
- return tokenId;
- } else {
- throw new SecurityException("bad password");
- }
- }
- }
-
- @Override
- public void logout(String securityToken) {
- if (securityToken == null) {
- throw new IllegalArgumentException("security token is null");
- } else {
- getUserId(securityToken); // will throw exception if token is not valid
- ws.delete(securityToken, Arrays.asList(securityToken));
- }
- }
-
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- String userId = getUserId(securityToken);
- if (isAppAdmin(securityToken, userId)) {
- // seul les AppAdmin on le droit a cette method
- WikittyServiceEvent result = ws.clear(securityToken);
- return result;
- } else {
- throw new SecurityException(_("user %s can't clear data", userId));
- }
- }
-
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- String userId = getUserId(securityToken);
- for (WikittyServiceEvent e : events) {
- if (e.getType().contains(
- WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
- || e.getType().contains(
- WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
- if (isAppAdmin(securityToken, userId)) {
- // seul les AppAdmin on le droit a cette method
- // les AppAdmin on meme le droit de tout faire, donc on
- // peut sortir de la boucle
- break;
- } else {
- throw new SecurityException(_("user %s can't clear data", userId));
- }
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
- checkStore(securityToken, e.getWikitties().values());
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
- checkDelete(securityToken, e.getRemoveDate().keySet());
- }
- if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
- checkStoreExtension(securityToken, e.getExtensions().values());
- }
- }
- WikittyServiceEvent result = ws.replay(securityToken, events);
- return result;
- }
-
-
- /**
- * if app-admin group exists, return true if given userId is app-admin
- * if app-admin group doesn't exists, return true if user is anonymous
- */
- protected boolean userIsAnonymousOrAppAdmin(String securityToken, String userId) {
- boolean userIsAnonymousOrAppAdmin = false;
-
- if (getAppAdminGroup(securityToken) == null) {
- if (securityToken == null) {
- // user is anonymous
- userIsAnonymousOrAppAdmin = true;
- }
- } else {
- if (isAppAdmin(securityToken, userId)) {
- // user is appAdmin
- userIsAnonymousOrAppAdmin = true;
- }
- }
-
- return userIsAnonymousOrAppAdmin;
- }
-
- @Override
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
- Collection<Wikitty> wikittiesToStore = checkStore(securityToken, wikitties);
- WikittyServiceEvent result = ws.store(securityToken, wikittiesToStore, force);
- return result;
- }
-
- /**
- * FIXME poussin 20101028 pourquoi retourner une liste ? soit on a le droit
- * de faire un store sur tout, on bien on refuse avec une exception
- * verifier que result ne sert bien a rien (surtout pas a filtrer)
- *
- * @param securityToken
- * @param wikitties
- * @return
- */
- protected Collection<Wikitty> checkStore(String securityToken, Collection<Wikitty> wikitties) {
- String userId = getUserId(securityToken);
- List<Wikitty> result = new ArrayList<Wikitty>();
- for (Wikitty wikitty : wikitties) {
-
- // usual case, a user want to store a wikitty
- Wikitty oldVersion = ws.restore(securityToken, wikitty.getId());
-
- Collection<String> newExtensions = new ArrayList<String>(wikitty.getExtensionNames());
- if (oldVersion != null) {
- // we already checked the rights for those extension
- // re-do the check has too much cost, avoid it
- newExtensions.removeAll(oldVersion.getExtensionNames());
- }
-
- // check that **reader** right on Security for all extension
- for (String extensionName: newExtensions) {
-
- Wikitty extensionRights = restoreExtensionAuthorisation(
- securityToken, extensionName);
- boolean canCreate = extensionRights == null ||
- canRead(securityToken, userId, null, extensionRights);
- if ( ! canCreate ) {
- throw new SecurityException(_(
- "user %s can't create instance of extension %s",
- userId, extensionRights));
- }
- }
-
- if (oldVersion != null) { // it's an update
-
- for (String fqFieldDirtyName : wikitty.getDirty()) {
-
- String concernedExtensionName = WikittyUtil.getExtensionNameFromFQFieldName(fqFieldDirtyName);
-
- if (log.isTraceEnabled()) {
- log.trace(String.format("will update field %s from extension %s",
- fqFieldDirtyName, concernedExtensionName));
- }
-
- boolean fieldRequireAdminRights = // true if field is a field of WikittyAuthorisation
- // concerned extension is "WikittyAuthorisation"
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION.equals(concernedExtensionName)
- // or concerned extension is something like "AnyExtension:WikittyAuthorisation"
- || WikittyAuthorisation.EXT_WIKITTYAUTHORISATION.equals(
- WikittyUtil.getMetaExtensionNameFromFQMetaExtensionName(concernedExtensionName));
-
- boolean canChange; // will be true if user can modify the value of this field
- // according to his level of rights
- if (fieldRequireAdminRights) {
- canChange = canAdmin(securityToken, userId, concernedExtensionName, wikitty);
- } else {
- canChange = canWrite(securityToken, userId, concernedExtensionName, wikitty);
- }
-
- if (canChange) {
- Object newValue = wikitty.getFqField(fqFieldDirtyName);
- oldVersion.setFqField(fqFieldDirtyName, newValue);
- } else {
- throw new SecurityException(_("user %s can't write field %s on wikitty %s",
- userId, fqFieldDirtyName, wikitty));
- }
- }
- }
-
- result.add(wikitty);
- }
- return result;
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> ids) {
- String userId = getUserId(securityToken);
- List<Wikitty> wikitties = ws.restore(securityToken, ids);
- for (Wikitty wikitty : wikitties) {
- if (wikitty != null) {
- refuseUnauthorizedRead(securityToken, userId, wikitty);
- }
- }
- return wikitties;
- }
-
- /** throw an exception if read is not allowed */
- protected void refuseUnauthorizedRead( String securityToken,
- String userId,
- Wikitty wikitty) {
- if (wikitty != null) {
- for (String extensionName : wikitty.getExtensionNames()) {
- if ( ! canRead(securityToken, userId, extensionName, wikitty)) {
- throw new SecurityException(_("user %s can't read extension %s on wikitty %s, it may be due to a global policy on the wikitty",
- userId, extensionName, wikitty));
- }
- }
- }
- }
-
- protected boolean canRead(String securityToken, String userId,
- String extensionName, Wikitty wikitty) {
-
- boolean canRead = false;
-
- // first, check per-extension rights
- if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
- extensionName)) {
- // there is a policy on the extension
- canRead = isReader(securityToken, userId, wikitty, extensionName)
- || canWrite(securityToken, userId, extensionName, wikitty);
- } else if ( ! canRead &&
- wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
- // there is no policy for this extension
- // but there is a policy for all extension of wikitty
- canRead = isReader(securityToken, userId, wikitty, null)
- || canWrite(securityToken, userId, extensionName, wikitty);
- } else {
- // no security policy, everything is allowed
- canRead = true;
- }
-
- return canRead;
- }
-
- protected boolean canWrite(String securityToken, String userId,
- String extensionName, Wikitty wikitty) {
- boolean canWrite = false;
-
- // first, check per-extension rights
- if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
- extensionName)) {
- // there is a policy on the extension of fqFieldDirtyName
- canWrite = isWriter(securityToken, userId, wikitty, extensionName)
- || canAdmin(securityToken, userId, extensionName, wikitty);
- } else if ( ! canWrite &&
- wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
- // there is no policy for this extension
- // but there is a policy for all extension of wikitty
- canWrite = isWriter(securityToken, userId, wikitty, null)
- || canAdmin(securityToken, userId, extensionName, wikitty);
- } else {
- // no security policy, everything is allowed
- canWrite = true;
- }
-
- return canWrite;
- }
-
- protected boolean canAdmin(String securityToken, String userId,
- String extensionName, Wikitty wikitty) {
-
- boolean canAdmin = false;
-
- // first, check per-extension rights
- if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
- extensionName)) {
- // there is a policy on the extension of fqFieldDirtyName
- canAdmin = isAdmin(securityToken, userId, wikitty, extensionName)
- || isOwner(securityToken, userId, wikitty, extensionName);
- } else if ( ! canAdmin &&
- wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
- // there is no policy for this extension
- // but there is a policy for all extension of wikitty
- canAdmin = isAdmin(securityToken, userId, wikitty, null)
- || isOwner(securityToken, userId, wikitty, null);
- } else if ( ! canAdmin ) {
- // still not admin, check appAdmin
- canAdmin = userIsAnonymousOrAppAdmin(securityToken, userId);
- }
-
- return canAdmin;
- }
-
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
- checkDelete(securityToken, ids);
- WikittyServiceEvent result = ws.delete(securityToken, ids);
- return result;
- }
-
- /**
- * Check if we can delete all id passed in argument
- * @param securityToken
- * @param ids
- */
- public void checkDelete(String securityToken, Collection<String> ids) {
- String userId = getUserId(securityToken);
- List<String> idsAsList = new ArrayList<String>(ids);
- List<Wikitty> wikitties = ws.restore(securityToken, idsAsList);
- for (Wikitty wikitty : wikitties) {
- for (String extensionName : wikitty.getExtensionNames()) {
- if ( ! canWrite(securityToken, userId, extensionName, wikitty)) {
- throw new SecurityException(_(
- "user %s doesn't have rights on extension %s on wikitty %s",
- userId, extensionName, wikitty));
- }
- }
- }
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- boolean result = true;
- String userId = getUserId(securityToken);
- for (String extName : wikitty.getExtensionNames()) {
- result = result && isWriter(securityToken, userId, wikitty, extName);
- if (!result) {
- break;
- }
- }
- return result;
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- boolean result = true;
- Wikitty wikitty = WikittyServiceEnhanced.restore(ws, securityToken, wikittyId);
- if (wikitty != null) {
- String userId = getUserId(securityToken);
- for (String extName : wikitty.getExtensionNames()) {
- result = result && isWriter(securityToken, userId, wikitty, extName);
- if (!result) {
- break;
- }
- }
- }
- return result;
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- boolean result = true;
- String userId = getUserId(securityToken);
- Wikitty wikitty = WikittyServiceEnhanced.restore(ws, securityToken, wikittyId);
- for (String extName : wikitty.getExtensionNames()) {
- result = result && isReader(securityToken, userId, wikitty, extName);
- if (!result) {
- break;
- }
- }
- return result;
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- // All people can read extension
- return ws.getAllExtensionIds(securityToken);
- }
-
- @Override
- public List<String> getAllExtensionsRequires(
- String securityToken, String extensionName) {
- // All people can read extension
- return ws.getAllExtensionsRequires(securityToken, extensionName);
- }
-
- /* *** storing and restoring extensions ***/
-
- protected void checkStoreExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- String userId = getUserId(securityToken);
- if ( ! userIsAnonymousOrAppAdmin(securityToken, userId)) {
- for (WikittyExtension extension : exts) {
- Wikitty extensionAuthorisation = restoreExtensionAuthorisation(securityToken, extension.getName());
- if (extensionAuthorisation != null) {
- // canWrite is true if this user can modify the field for this extension
- boolean canWrite = canWrite(securityToken, userId, null, extensionAuthorisation);
- if ( ! canWrite) {
- throw new SecurityException(_("user %s don't have write right for extension %s", userId, extension));
- }
- }
- }
- }
- }
-
- @Override
- public WikittyServiceEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- checkStoreExtension(securityToken, exts);
- return ws.storeExtension(securityToken, exts);
- }
-
- @Override
- public WikittyExtension restoreExtension(String securityToken, String id) {
- // All people can read extension
- return ws.restoreExtension(securityToken, id);
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- // All people can read extension
- return ws.restoreExtensionLastVersion(securityToken, name);
- }
-
- @Override
- public PagedResult<String> findAllByCriteria(String securityToken,
- Criteria criteria) {
- // All people can read PagedResult that contains only id
- PagedResult<String> result = ws.findAllByCriteria(securityToken, criteria);
- return result;
- }
-
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- String userId = getUserId(securityToken);
- WikittyTree restoredTree = ws.restoreTree(securityToken, wikittyId);
- checkRestoreTree(securityToken, userId, restoredTree);
- return restoredTree;
- }
-
- protected void checkRestoreTree(String securityToken, String userId, WikittyTree tree) {
- checkRestoreTreeNode(securityToken, userId, tree.node);
- for (WikittyTree subTree : tree.getChildren()) {
- checkRestoreTree(securityToken, userId, subTree);
- }
- }
-
-
- protected void checkRestoreTreeNode(String securityToken, String userId, WikittyTreeNode treeNode) {
- refuseUnauthorizedRead(securityToken, userId, treeNode.getWikitty());
- }
-
- @Override
- public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId, Criteria filter) {
- String userId = getUserId(securityToken);
- Entry<WikittyTreeNode, Integer> entry = ws.restoreNode(securityToken, wikittyId, filter);
- checkRestoreTreeNode(securityToken, userId, entry.getKey());
- return entry;
- }
-
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
- String wikittyId,
- Criteria filter) {
- String userId = getUserId(securityToken);
- Map<WikittyTreeNode, Integer> children = ws.restoreChildren(securityToken, wikittyId, filter);
- for (Map.Entry<WikittyTreeNode, Integer> child : children.entrySet()) {
- checkRestoreTreeNode(securityToken, userId, child.getKey());
- }
- return children;
- }
-
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String treeNodeId) {
- WikittyTreeNode treeNode = ws.restoreNode(securityToken, treeNodeId, null).getKey();
- Collection<Wikitty> wikitties = Arrays.asList(treeNode.getWikitty());
- checkStore(securityToken, wikitties);
- return ws.deleteTree(securityToken, treeNodeId);
- }
-
- @Override
- public Wikitty restoreVersion(String securityToken, String wikittyId, String version) {
- Wikitty wikitty = ws.restoreVersion(securityToken, wikittyId, version);
- String userId = getUserId(securityToken);
- refuseUnauthorizedRead(securityToken, userId, wikitty);
- return wikitty;
- }
-
- @Override
- public Wikitty findByCriteria(String securityToken,
- Criteria criteria) {
- Wikitty wikitty = ws.findByCriteria(securityToken, criteria);
- String userId = getUserId(securityToken);
- refuseUnauthorizedRead(securityToken, userId, wikitty);
- return wikitty;
- }
-
- @Override
- public void syncEngin(String securityToken) {
- String userId = getUserId(securityToken);
- if (isAppAdmin(securityToken, userId)) {
- // seul les AppAdmin on le droit a cette method
- ws.syncEngin(securityToken);
- } else {
- throw new SecurityException(_("user %s can't sync search engine",
- getUserId(securityToken)));
- }
- }
-
- //
- // Method helper to check right
- //
-
- /** tell who own a token (who got this token after login).
- * @param securityToken the token whose owner will be returned
- * @return a wikitty Id (wikitty has extension WikittyUser)
- */
- protected String getUserId(String securityToken) {
- String result = null;
- // recuperation de l'utilisateur associe au securityToken
- // le securityToken est aussi l'id de l'objet
- if (securityToken != null) {
- Wikitty securityTokenWikitty = ws.restore(securityToken, securityToken);
- if (securityTokenWikitty == null) {
- throw new SecurityException("bad (obsolete ?) token");
- } else {
- result = WikittyTokenHelper.getUser(securityTokenWikitty);
- }
- }
- return result;
- }
-
- /**
- *
- * @param securityToken
- * @param userId
- * @param wikitty
- * @param extensionName may be null
- * @return
- */
- protected boolean isReader(String securityToken, String userId, Wikitty wikitty, String extensionName) {
- boolean result;
- String metaFieldName = WikittyUtil.getMetaFieldName(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
- WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_READER);
- result = isMember(securityToken, userId, wikitty, metaFieldName, true);
- return result;
- }
-
- /**
- *
- * @param securityToken
- * @param userId
- * @param wikitty
- * @param extensionName may be null
- * @return
- */
- protected boolean isWriter(String securityToken, String userId, Wikitty wikitty, String extensionName) {
- boolean result;
- String metaFieldName = WikittyUtil.getMetaFieldName(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
- WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_WRITER);
- log.trace("meta field name " + metaFieldName);
- result = isMember(securityToken, userId, wikitty, metaFieldName);
- return result;
- }
-
- /**
- *
- * @param securityToken
- * @param userId
- * @param wikitty
- * @param extensionName may be null
- * @return
- */
- protected boolean isAdmin(String securityToken, String userId, Wikitty wikitty, String extensionName) {
- boolean result;
- String metaFieldName = WikittyUtil.getMetaFieldName(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
- WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_ADMIN);
- result = isMember(securityToken, userId, wikitty, metaFieldName);
- return result;
- }
-
- /** true if given user is owner
- *
- * @param securityToken
- * @param userId
- * @param wikitty
- * @param extensionName may be null
- * @return
- */
- protected boolean isOwner(String securityToken, String userId, Wikitty wikitty, String extensionName) {
-
- String metaFieldName = WikittyUtil.getMetaFieldName(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
- WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_OWNER);
-
- String actualExtensionName = WikittyUtil.getExtensionNameFromFQFieldName(metaFieldName);
- String fieldName = WikittyUtil.getFieldNameFromFQFieldName(metaFieldName);
-
- String owner = wikitty.getFieldAsString(actualExtensionName, fieldName);
-
- boolean isOwner;
- if (owner == null) {
- isOwner = false;
- } else {
- isOwner = owner.equals(userId);
- }
- return isOwner;
- }
-
- /** {@link #isMember(String, String, Wikitty, String, boolean)} with default value */
- protected boolean isMember(String securityToken, String userId, Wikitty extensionRights, String fqFieldName) {
- // by default, user is considered not member if he is not in the group, so passing "false"
- return isMember(securityToken, userId, extensionRights, fqFieldName, false);
- }
-
- /** check if a user is listed in a level of rights
- *
- * @param securityToken
- * @param userId the userId to look for
- * @param extensionRights a wikitty with WikittyAuthorisation as extension <strong>OR</strong> meta-extension
- * @param fqFieldName the field to look into, it should be one of the field of extension WikittyAuthorisation
- * it has to be a FQN and may contain an extension-name if using meta-extension
- * @param considerEmptyGroupAsMembership if true, an empty field value will be considered as
- * "every-one is in the group". Most of the time, it will be false but true should be
- * passed for "reader" level because user has right to read if he belongs to "reader" OR
- * if reader is empty
- * @return true if userId appear in the single/list of group/user of given field
- */
- protected boolean isMember(String securityToken, String userId,
- Wikitty extensionRights, String fqFieldName, boolean considerEmptyGroupAsMembership) {
-
- String extensionName = WikittyUtil.getExtensionNameFromFQFieldName(fqFieldName);
- String fieldName = WikittyUtil.getFieldNameFromFQFieldName(fqFieldName);
-
- Set<String> groupOrUser = extensionRights.getFieldAsSet(extensionName,
- fieldName,
- String.class);
-
- boolean isMember;
- if (groupOrUser == null || groupOrUser.isEmpty()) {
- isMember = considerEmptyGroupAsMembership;
- } else {
- isMember = isMember(securityToken, userId, groupOrUser);
- }
-
- if ( ! isMember) {
- // user don't have right on current object, check parent right
- String parentId = WikittyAuthorisationHelper.getParent(extensionRights);
- if (parentId != null) {
- Wikitty parent = ws.restore(securityToken, parentId);
- isMember = isMember(securityToken, userId, parent, fqFieldName);
- }
- }
- return isMember;
- }
-
- /** check if a given user belong to the group of app-admins. */
- protected boolean isAppAdmin(String securityToken, String userId) {
- Wikitty group = getAppAdminGroup(securityToken);
- Set<String> ids = WikittyGroupHelper.getMembers(group);
- boolean result = isMember(securityToken, userId, ids);
- return result;
- }
-
- /** get the wikitty with extension WikittyGroup that contains all app-admin. */
- protected Wikitty getAppAdminGroup(String securityToken) {
- Wikitty group;
- if (appAdminGroupId == null) {
- // 1er fois, on le recherche
- group = ws.findByCriteria(securityToken, Search.query().eq(
- WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME,
- WikittySecurityHelper.WIKITTY_APPADMIN_GROUP_NAME).criteria());
- // group peut-etre null s'il n'existe pas
- } else {
- // on a deja fait la recherche precedement, on essaie de reutilise
- // le meme id
- group = ws.restore(securityToken, appAdminGroupId);
- // group peut-etre null, si entre temps un admin a supprime le group
- }
-
- return group;
- }
-
- /**
- * Verifie recursivement si un utilisateur est dans un groupe qui peut etre
- * constitue d'autre groupe ou d'utilisateur
- *
- * @param userId l'utilisateur recherche
- * @param groupOrUser la liste des id d'utilisateurs ou d'autres groupes
- * @return vrai si userId est retrouve, false sinon
- */
- protected boolean isMember(
- String securityToken, String userId, Set<String> groupOrUser) {
- if (groupOrUser != null) {
- for (String id : groupOrUser) {
- if (id.equals(userId)) {
- return true;
- } else {
- Wikitty groupWikitty = ws.restore(securityToken, id);
- if (WikittyGroupHelper.hasExtension(groupWikitty)) {
- Set<String> members = WikittyGroupHelper.getMembers(groupWikitty);
- return isMember(securityToken, userId, members);
- }
- }
- }
- }
- return false; // not found in groupOrUser
- }
-
- /**
- * restore the wikitty authorisation attached to given extension.
- *
- * @return a wikitty with WikittyAuthorisation extension, or null if given
- * extension has no security policy attached
- */
- protected Wikitty restoreExtensionAuthorisation(String securityToken,
- WikittyExtension extension) {
- return restoreExtensionAuthorisation(securityToken, extension.getName());
- }
-
- /**
- * restore the wikitty authorisation attached to given extension.
- *
- * @return a wikitty with WikittyAuthorisation extension, or null if given
- * extension has no security policy attached
- */
- protected Wikitty restoreExtensionAuthorisation(String securityToken,
- String extensionName) {
- String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
- WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName);
- Wikitty wikittyAuthorisation = ws.restore(securityToken, wikittyAuthorisationId);
- if (wikittyAuthorisation == null) {
- log.debug(extensionName + " has no authorization attached");
- }
- return wikittyAuthorisation;
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- // no need security check for this action
- return ws.exists(securityToken, wikittyId);
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- // no need security check for this action
- return ws.isDeleted(securityToken, wikittyId);
- }
-
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,331 +0,0 @@
-package org.nuiton.wikitty;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceTransaction implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceTransaction.class);
-
- /** Real WikittyService */
- protected WikittyService ws;
- /** WikittyService used to store modified object */
- protected WikittyService tx;
-
- protected List<WikittyServiceEvent> events;
-
- /** if autoCommit > 0 all time events numbers element equals to this
- * autoCommit commit is call */
- protected int autoCommit = -1;
-
- public WikittyServiceTransaction(ApplicationConfig config, WikittyService ws) {
- this.ws = ws;
- // create new WikittyServiceInMemory not configured with default config
- // this WikittyServiceInMemory must be only in memory
- this.tx = new WikittyServiceInMemory(null);
- events = new LinkedList<WikittyServiceEvent>();
- }
-
- public void setAutoCommit(int autoCommit) {
- this.autoCommit = autoCommit;
- }
-
- public int getAutoCommit() {
- return autoCommit;
- }
-
- protected void addEvent(String securityToken, WikittyServiceEvent e) {
- events.add(e);
- if (autoCommit > 0 && events.size() >= autoCommit) {
- commit(securityToken);
- }
- }
-
- public void commit(String securityToken) {
- ws.replay(securityToken, events);
- this.tx.clear(null);
- events.clear();
- }
-
- public void rollback(String securityToken) {
- this.tx.clear(null);
- events.clear();
- }
-
- @Override
- public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- throw new UnsupportedOperationException(
- "You try to add listener on WikittyServiceTransaction,"
- + "this is an error desgin, you must add WikittyServiceNotifier"
- + "front of your WikittyServiceTransaction.");
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
- throw new UnsupportedOperationException(
- "You try to remove listener on WikittyServiceTransaction,"
- + "this is an error desgin, you must add WikittyServiceNotifier"
- + "front of your WikittyServiceTransaction.");
- }
-
- @Override
- public String login(String login, String password) {
- return ws.login(login, password);
- }
-
- /**
- * Question: est un comportement normale, lorsqu'on se delogue depuis une
- * transaction, on est deloguer partout ? je pense que oui
- * @param securityToken
- */
- @Override
- public void logout(String securityToken) {
- ws.logout(securityToken);
- }
-
- @Override
- public WikittyServiceEvent clear(String securityToken) {
- WikittyServiceEvent e = tx.clear(securityToken);
- addEvent(securityToken, e);
- return e;
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- // in transaction, we can do all. But not during commit
- return true;
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- // in transaction, we can do all. But not during commit
- return true;
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- boolean result = tx.exists(securityToken, wikittyId);
- if (!result) {
- // on ne l'a pas en local on va voir si on peut le lire en distant
- result = ws.canRead(securityToken, wikittyId);
- }
- return result;
- }
-
- @Override
- public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
- WikittyServiceEvent e = tx.replay(securityToken, events);
- events.add(e);
- return e;
- }
-
- @Override
- public WikittyServiceEvent store(
- String securityToken, Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent e = tx.store(securityToken, wikitties, force);
- addEvent(securityToken, e);
- return e;
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- HashSet<String> tmp = new HashSet<String>();
-
- tmp.addAll(tx.getAllExtensionIds(securityToken));
- tmp.addAll(ws.getAllExtensionIds(securityToken));
-
- List<String> result = new ArrayList<String>(tmp);
- return result;
- }
-
- @Override
- public List<String> getAllExtensionsRequires(String securityToken, String extensionName) {
- HashSet<String> tmp = new HashSet<String>();
-
- tmp.addAll(tx.getAllExtensionsRequires(securityToken, extensionName));
- tmp.addAll(ws.getAllExtensionsRequires(securityToken, extensionName));
-
- List<String> result = new ArrayList<String>(tmp);
- return result;
- }
-
- @Override
- public WikittyServiceEvent storeExtension(
- String securityToken, Collection<WikittyExtension> exts) {
- WikittyServiceEvent e = tx.storeExtension(securityToken, exts);
- addEvent(securityToken, e);
- return e;
- }
-
- @Override
- public WikittyExtension restoreExtension(
- String securityToken, String extensionId) {
- WikittyExtension result = tx.restoreExtension(securityToken, extensionId);
- if (result == null) {
- result = ws.restoreExtension(securityToken, extensionId);
- }
- return result;
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(
- String securityToken, String name) {
- WikittyExtension result =
- tx.restoreExtensionLastVersion(securityToken, name);
- if (result == null) {
- result = ws.restoreExtensionLastVersion(securityToken, name);
- }
- return result;
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> ids) {
- List<Wikitty> resultWS = ws.restore(securityToken, ids);
- List<Wikitty> resultTx = tx.restore(securityToken, ids);
- Wikitty[] result = resultWS.toArray(new Wikitty[resultWS.size()]);
- int i = 0;
- for (Wikitty w : resultTx) {
- String id = ids.get(i);
- // il faut prendre en compte que l'objet a pu etre supprime dans la
- // transaction donc meme s'il est null dans tx et pas dans ws, il
- // faut le mettre a null
- // si w n'a pas ete restore (null), mais qu'il exist, alors cela
- // veut dire qu'il est supprime.
- if (w != null || tx.exists(securityToken, id)) {
- // on remplace tout par les nouveaux de la transaction
- result[i] = w;
- }
- i++;
- }
- return Arrays.asList(result);
- }
-
- @Override
- public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
- // pour que tout fonctionne bien, il faut que les objets supprimer soit
- // dans la tx, car il faut avoir une vrai trace de cette suppression dans la tx
- List<Wikitty> wikitties = ws.restore(securityToken, new ArrayList<String>(ids));
- tx.store(securityToken, wikitties, true);
-
- WikittyServiceEvent e = tx.delete(securityToken, ids);
- addEvent(securityToken, e);
- return e;
- }
-
- @Override
- public PagedResult<String> findAllByCriteria(
- String securityToken, Criteria criteria) {
- PagedResult<String> resultTx = tx.findAllByCriteria(securityToken, criteria);
- PagedResult<String> resultWs = ws.findAllByCriteria(securityToken, criteria);
-
- // Il faut fusionner les deux resultats
- // - ne pas avoir de doublon
- // - ne pas retenir ceux supprimer dans la transaction
- // - fusionner les facettes (comment faire ?)
- // - respecter le range demander (comment faire, avec les suppressions possible ?)
- LinkedHashSet<String> ids = new LinkedHashSet<String>();
- ids.addAll(resultTx.getAll());
- ids.addAll(resultWs.getAll());
-
- int firstIndice = resultWs.getFirstIndice();
- // FIXME le resultat est faut, le nombre total n'est pas la somme des deux :(
- int numFound = resultTx.getNumFound() + resultWs.getNumFound();
- String queryString = resultWs.getQueryString();
- // FIXME les facettes sont fausses :(
- Map<String, List<FacetTopic>> facets = resultWs.getFacets();
- List<String> results = new ArrayList<String>(ids);
-
- PagedResult<String> result = new PagedResult<String>(
- firstIndice, numFound, queryString, facets, results);
- return result;
- }
-
- @Override
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- Wikitty result = null;
- PagedResult<String> ids = findAllByCriteria(securityToken, criteria);
- List<String> results = ids.getAll();
- if (results.size() > 0) {
- String id = results.get(0);
- List<Wikitty> wikitties = restore(
- securityToken, Collections.singletonList(id));
- result = wikitties.get(0);
- }
- return result;
- }
-
- @Override
- public WikittyTree restoreTree(String securityToken, String wikittyId) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public WikittyServiceEvent deleteTree(String securityToken, String treeNodeId) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId, Criteria filter) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken, String wikittyId, Criteria filter) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public Wikitty restoreVersion(String securityToken, String wikittyId, String version) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public void syncEngin(String securityToken) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- boolean result = tx.exists(securityToken, wikittyId);
- if (!result) {
- if (!tx.isDeleted(securityToken, wikittyId)) {
- result = ws.exists(securityToken, wikittyId);
- }
- }
- return result;
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- boolean result = tx.isDeleted(securityToken, wikittyId);
- // pas efface, peut-etre qu'il existe
- if (!result && !tx.exists(securityToken, wikittyId)) {
- // il n'est pas efface et il n'existe pas dans la tx,
- // on recherche dans ws
- result = ws.isDeleted(securityToken, wikittyId);
- }
- return result;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyStorage.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyStorage.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyStorage.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,116 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.Collection;
-
-/**
- * WikittyStorage is used to abstract data and extension storage in WikittyService.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public interface WikittyStorage {
-
- /**
- * Store wikitty in storage.
- *
- * @param transaction transaction
- * @param wikitties wikitty collection
- * @param force boolean force non version version increment on saved wikitty
- * or force version on wikitty creation (version 0.0)
- *
- * @return information usefull for client side update data
- */
- public WikittyServiceEvent store(WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force);
-
- /**
- * Return true if id exists in storage.
- *
- * @param transaction transaction
- * @param id id to check
- * @return {@code true} if wikitty id exists
- */
- public boolean exists(WikittyTransaction transaction, String id);
-
- /**
- * Return true if wikitty object with this id are marked deleted.
- *
- * @param transaction transaction
- * @param id id to check
- * @return {@code true} if wikitty id is deleted
- */
- public boolean isDeleted(WikittyTransaction transaction, String id);
-
- /**
- * Restore list of wikitty object.
- *
- * @param transaction transaction
- * @param id list of wikitty id
- * @param fqFieldName list of field that must be loaded, other fields
- * can be not loaded
- * @return found wikitty
- * @throws WikittyException if wikitty not found
- */
- public Wikitty restore(WikittyTransaction transaction, String id,
- String ... fqFieldName) throws WikittyException;
-
- /**
- * Delete all object with id argument.
- *
- * @param transaction transaction
- * @param idList
- * @return delete response
- * @throws WikittyException If id is not valid or don't exist.
- */
- public WikittyServiceEvent delete(WikittyTransaction transaction, Collection<String> idList) throws WikittyException;
-
- /**
- * Scan all wikitties with specific scanner, even if the wikitty is deleted.
- *
- * @param transaction transaction
- * @param scanner scanner
- */
- public void scanWikitties(WikittyTransaction transaction, Scanner scanner);
-
- /**
- * Call each time wikitty is scan.
- */
- public static interface Scanner {
- void scan(String wikittyId);
- }
-
- /**
- * Remove all wikitty.
- *
- * @param transaction transaction
- */
- public WikittyServiceEvent clear(WikittyTransaction transaction);
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,124 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.transaction.Status;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/***
- * Manage JTA transaction. You can store some information during execution.
- */
-public class WikittyTransaction {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyTransaction.class);
-
- /** permet d'attacher n'importe quoi a une transaction */
- protected Map<Object, Object> tagValues;
-
- /** cache static utilise par le WikittyServiceCached */
- transient protected WikittyCache cache = null;
-
- public WikittyTransaction() {
- tagValues = new HashMap<Object, Object>();
- }
-
- /**
- * FIXME poussin 20101027 a supprimer lorsque WikittyServiceTransaction
- * aura ete implante
- *
- * Visibilite 'default' car est uilise par WikittyServiceCached qui est dans
- * le meme package et a priori seulement lui en a besoin
- *
- * @return
- */
- WikittyCache getCache() {
- if (cache == null) {
- cache = new WikittyCache(false);
- }
- return cache;
- }
-
- public Object getTagValue(Object tag) {
- return tagValues.get(tag);
- }
-
- public void setTagValue(Object tag, Object value) {
- tagValues.put(tag, value);
- }
-
- public UserTransaction getUserTransaction() {
- return com.arjuna.ats.jta.UserTransaction.userTransaction();
- }
-
- public TransactionManager getTransactionManager() {
- return com.arjuna.ats.jta.TransactionManager.transactionManager();
- }
-
- public void begin() {
- UserTransaction userTransaction = getUserTransaction();
- try {
- if (log.isDebugEnabled()) {
- log.debug("Begin transaction");
- }
- userTransaction.setTransactionTimeout(3600); // FIXME: jru 20100115 error in service if call during lot of times
- userTransaction.begin();
- } catch (Exception eee) {
- throw new WikittyException("Error on begin JTA transaction", eee);
- }
- }
-
- public void commit() {
- UserTransaction userTransaction = getUserTransaction();
- try {
- if (log.isDebugEnabled()) {
- log.debug("Commit transaction");
- }
- userTransaction.commit();
- } catch (Exception eee) {
- throw new WikittyException("Error on commit JTA transaction", eee);
- }
- }
-
- public void rollback() {
- UserTransaction userTransaction = getUserTransaction();
- try {
- if(userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION
- && userTransaction.getStatus() != Status.STATUS_UNKNOWN) {
- if (log.isDebugEnabled()) {
- log.debug("Rollback transaction");
- }
- userTransaction.rollback();
- }
- } catch (Exception eee) {
- throw new WikittyException("Error on roolback JTA transaction", eee);
- }
- }
-}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTree.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTree.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTree.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -27,6 +27,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
public class WikittyTree implements Serializable {
@@ -39,6 +40,10 @@
public void setNode(WikittyTreeNode node) {
this.node = node;
}
+
+ public WikittyTreeNode getNode() {
+ return node;
+ }
public void addChild(WikittyTree tree) {
getChildren().add( tree );
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -25,6 +25,13 @@
package org.nuiton.wikitty;
+import org.nuiton.wikitty.entities.BusinessEntity;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.BusinessEntityWikitty;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.text.ParseException;
@@ -139,21 +146,21 @@
static public String parseField(String def, FieldType fieldType) {
Matcher match = fieldPattern.matcher(def);
if (match.matches()) {
- fieldType.type = FieldType.TYPE.parse(match.group(1));
+ fieldType.setType(FieldType.TYPE.parse(match.group(1)));
String name = match.group(2);
String lower = match.group(3);
if (lower != null) {
- fieldType.lowerBound = Integer.parseInt(lower);
+ fieldType.setLowerBound(Integer.parseInt(lower));
}
String upper = match.group(4);
if (upper != null) {
- fieldType.upperBound = Integer.parseInt(upper);
+ fieldType.setUpperBound(Integer.parseInt(upper));
}
String noupper = match.group(5);
if (noupper != null) {
- fieldType.upperBound = FieldType.NOLIMIT;
+ fieldType.setUpperBound(FieldType.NOLIMIT);
}
// parse group 8 before
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,216 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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;
-
-
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.UUID;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.XMPPConnection;
-import org.jivesoftware.smack.packet.Message;
-import org.jivesoftware.smack.packet.Packet;
-import org.jivesoftware.smackx.muc.DiscussionHistory;
-import org.jivesoftware.smackx.muc.MultiUserChat;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- * Transporter d'event via xmpp. Pour que ca fonctionne il faut un serveur
- * xmpp avec une room
- * <p>
- * Configuration
- * <li>wikitty.xmpp.server = adresse du serveur (ex: im.codelutin.com)
- * <li>wikitty.xmpp.room = adresse de la room (ex: wikitty-event(a)im.codelutin.com)
- * <li>wikitty.notification.persistent = [true|false] indique si on doit
- * recevoir tous les messages sans en loupe un seul. Pour cela il faut que la
- * room soit archivee. (FIXME poussin 20101014 pas encore implantee)
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class XMPPNotifierTransporter implements PacketListener,
- WikittyServiceNotifier.RemoteNotifierTransporter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(XMPPNotifierTransporter.class);
-
- static final public String PROPERTY_EVENT_NAME = "wikitty-event";
-
- /** Notifier service reference reference. */
- protected WikittyServiceNotifier ws;
-
- /** if persistent is true use Chat otherwize use MUC. Chat permit to
- received event missed after deconnection */
- protected boolean persistent = false;
-
- // Keep room addresse and pseudo to verify that messages event are not send by us
- protected String room;
- protected String pseudo;
-
- protected XMPPConnection connection;
- protected MultiUserChat muc;
-
- /**
- *
- * @param ws
- * @param props
- */
- public XMPPNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
- this.ws = ws;
- initXMPP(config);
- }
-
- /**
- * Si persistent est vrai alors il faut toujours utilise le meme user id
- *
- * @param props
- */
- protected void initXMPP(ApplicationConfig config) {
- persistent = config.getOptionAsBoolean(
- WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_NOTIFICATION_PERSISTENT.getKey());
- String server = config.getOption(
- WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER.getKey());
-
- // Keep them to verify that is not us notifications
- room = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM.getKey());
- pseudo = getUniqueLoginName();
- try {
- if (log.isInfoEnabled()) {
- log.info("Try to connect to xmpp serveur " + server +
- " with pseudo " + pseudo + " in room " + room +
- " persistent " + persistent);
- }
- connection = new XMPPConnection(server);
- connection.connect();
- connection.loginAnonymously();
-
- DiscussionHistory history = new DiscussionHistory();
- if (persistent) {
- // FIXME poussin 20101113 compute amount of log history to retrieve
- // MUC must be archived
- Date date = new Date();
- history.setSince(date);
- } else {
- history.setMaxChars(0);
- }
-
- // connection to the volatile room
- muc = new MultiUserChat(connection, room);
- muc.join(pseudo, "", history, 4000);
- muc.addMessageListener(this);
- } catch (Exception eee) {
- throw new WikittyException("Can't connect to xmpp serveur", eee);
- }
- }
-
- @Override
- public void sendMessage(WikittyServiceEvent event) throws Exception {
- Message message = muc.createMessage();
- message.setBody(event.getType().toString());
- message.setProperty(PROPERTY_EVENT_NAME, event);
-
- muc.sendMessage(message);
- }
-
- /**
- * used for MUC message
- * @param packet
- */
- @Override
- public void processPacket(Packet packet) {
-
- // Dont listen own events
- String name = room + "/" + pseudo;
- if (!name.equals(packet.getFrom())) {
-
- Object event = packet.getProperty(PROPERTY_EVENT_NAME);
-
- if (log.isDebugEnabled()) {
- log.debug("Receive message : " + event);
- }
-
- if (event instanceof WikittyServiceEvent) {
- ws.processRemoteEvent((WikittyServiceEvent)event);
- }
- }
- }
-
- /**
- * Recherche le meilleur nom a utiliser comme pseudo pour cette machine.
- * Un UUID est toujours ajouter en debut, pour potentiellement lancer
- * plusieurs application en meme temps sur la meme machine et etre sur que
- * le pseudo soit bien unique.
- *
- * Le pseudo, n'est pas seulement un UUID, pour pouvoir facilement faire
- * du debug en entrant dans le channel et voir les ip des machiens connectees
- *
- * @return
- */
- static public String getUniqueLoginName() {
- String result = UUID.randomUUID().toString();
- try {
- String ipv4 = null;
- String ipv6 = null;
- for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
- NetworkInterface netint = e.nextElement();
-
- for (Enumeration<InetAddress> a = netint.getInetAddresses(); a.hasMoreElements();) {
- InetAddress ip = a.nextElement();
- if (ip instanceof Inet4Address) {
- if ((ipv4 == null || "127.0.0.1".equals(ipv4))) {
- ipv4 = ip.getHostAddress();
- }
- } else if (ip instanceof Inet6Address) {
- if (ipv6 == null) {
- ipv6 = ip.getHostAddress();
- }
- } else {
- log.error("Can't get ip from no ipv4 and no ipv6: " + ip);
- }
- }
- }
-
- if (ipv4 != null) {
- result = ipv4 + "=" + result;
- } else if (ipv6 != null) {
- result = ipv6 + "=" + result;
- }
- } catch (Exception eee) {
- log.error("Can't compute unique name from network interface", eee);
- }
- return result;
- }
-
-}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nImpl.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nImpl.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nImpl.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,223 @@
+package org.nuiton.wikitty.addons;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.entities.BusinessEntityWikitty;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyI18nAbstract;
+
+/**
+ * WikittyI18n permet de gerer les traductions des champs des extensions.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyI18nImpl extends WikittyI18nAbstract
+ implements PropertyChangeListener {
+
+ private static final long serialVersionUID = 3824481585361443459L;
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyI18nImpl.class);
+
+ /** contient les translations sous une forme plus simple a utiliser */
+ transient protected Map<String, Map<String, String>> translationsCache = null;
+
+ /**
+ * WikittyI18nImpl :
+ */
+ public WikittyI18nImpl() {
+ super();
+ }
+
+ /**
+ * WikittyI18nImpl :
+ * @param wikitty
+ */
+ public WikittyI18nImpl(Wikitty wikitty) {
+ super(wikitty);
+ }
+
+ /**
+ * WikittyI18nImpl :
+ * @param businessEntityWikitty
+ */
+ public WikittyI18nImpl(BusinessEntityWikitty businessEntityWikitty) {
+ super(businessEntityWikitty.getWikitty());
+ }
+
+ /**
+ * WikittyAuthorisationImpl :
+ * @param extension
+ * @param wikitty
+ */
+
+ public WikittyI18nImpl(WikittyExtension extension, Wikitty wikitty) {
+ this(wikitty);
+ setExtensionForMetaExtension(extension);
+ }
+
+ /**
+ * On surcharge la methode pour se mettre listener des modifications de
+ * translation pour pouvoir vider le cache de translation
+ * @param wikitty
+ */
+ @Override
+ public void setWikitty(Wikitty wikitty) {
+ if (this.wikitty != null) {
+ this.wikitty.removePropertyChangeListener(
+ FQ_FIELD_WIKITTYI18N_TRANSLATIONS, this);
+ }
+ super.setWikitty(wikitty);
+ if (this.wikitty != null) {
+ this.wikitty.addPropertyChangeListener(
+ FQ_FIELD_WIKITTYI18N_TRANSLATIONS, this);
+ }
+ }
+
+ /**
+ * Retourne la translation pour un champs donne pour une lang donnee
+ * @param lang la langue souhaitee (ex: fr)
+ * @param field le champs souhaite (ex: name)
+ * @return la traduction
+ */
+ @Override
+ public String getTranslation(String lang, String field) {
+ parseAndCacheTranslations();
+
+ String result = null;
+ Map<String, String> l = translationsCache.get(lang);
+ if (l != null) {
+ result = l.get(field);
+ }
+
+ if (result == null) {
+ // no translation for this field, default return field in parameter
+ result = field;
+ }
+ return result;
+ }
+
+ /**
+ * Modifie la traduction d'un champs
+ * @param lang
+ * @param field
+ * @param trad
+ */
+ @Override
+ public void setTranslation(String lang, String field, String trad) {
+ parseAndCacheTranslations();
+ putInTranslationCache(lang, field, trad);
+ // on sauve temporairement le cache, car il va etre supprime
+ // suite au setTranslations, vu qu'il est a jour se serait dommage de
+ // devoir le reconstruire
+ Map<String, Map<String, String>> tmp = translationsCache;
+ String trans = convertToString(tmp);
+ setTranslations(trans);
+ // remet le cache sauvegarde en place
+ translationsCache = tmp;
+
+ // on indique que la lang a des traductions si besoin
+ if (getLang() == null || !getLang().contains(lang)) {
+ addLang(lang);
+ }
+ }
+
+ /**
+ * Parse les traductions et le met en cache
+ *
+ * Translations est de la forme:
+ * [fr:"name"="nom","firstname"="prenom"],[en:"name="name","firstname"="firstname"]
+ */
+ protected void parseAndCacheTranslations() {
+ if (translationsCache == null) {
+ String trans = getTranslations();
+ String[] langsFields = StringUtil.split(trans, ",");
+ for (String langFields : langsFields) {
+ // suppression des [ ]
+ langFields = langFields.substring(1, langFields.length() - 1);
+ int colonPos = langFields.indexOf(":");
+ // recuperation de la langue
+ String lang = langFields.substring(0, colonPos);
+ langFields = langFields.substring(colonPos + 1);
+ String[] fields = StringUtil.split(langFields, ",");
+ for (String field : fields) {
+ String[] fieldNameAndTrad = StringUtil.split(field, "=");
+ String fieldName = fieldNameAndTrad[0];
+ String fieldTrad = fieldNameAndTrad[1];
+
+ // suppression des "
+ fieldName = fieldName.substring(1, fieldName.length() - 1);
+ fieldTrad = fieldTrad.substring(1, fieldTrad.length() - 1);
+ putInTranslationCache(lang, fieldName, fieldTrad);
+ }
+ }
+ }
+ }
+
+ /**
+ * met un traduction en plus dans le cache
+ * @param lang
+ * @param field
+ * @param trans
+ */
+ protected void putInTranslationCache(String lang, String field, String trans) {
+ if (translationsCache == null) {
+ translationsCache = new HashMap<String, Map<String, String>>();
+ }
+ Map<String, String> l = translationsCache.get(lang);
+ if (l == null) {
+ l = new HashMap<String, String>();
+ translationsCache.put(lang, l);
+ }
+ l.put(field, trans);
+ }
+
+ /**
+ * converti le cache dans une representation string
+ * @param trans
+ * @return
+ */
+ protected String convertToString(Map<String, Map<String, String>> trans) {
+ StringBuilder result = new StringBuilder();
+ for (Map.Entry<String, Map<String, String>> l : trans.entrySet()) {
+ String lang = l.getKey();
+ result.append("[" + lang + ":");
+ for(Map.Entry<String, String> t : l.getValue().entrySet()) {
+ result.append("\"" + t.getKey() + "\"=\"" + t.getValue() + "\",");
+ }
+ // suppression de la derniere ,
+ if (result.charAt(result.length() - 1) == ',') {
+ result.deleteCharAt(result.length() - 1);
+ }
+ result.append("],");
+ }
+ if (result.charAt(result.length() - 1) == ',') {
+ result.deleteCharAt(result.length() - 1);
+ }
+ return result.toString();
+ }
+
+ /**
+ * Ecoute les events pour devalider le cache
+ * @param evt
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ String propName = evt.getPropertyName();
+ if (FQ_FIELD_WIKITTYI18N_TRANSLATIONS.equals(propName)) {
+ // la valeur a change on vide le cache
+ translationsCache = null;
+ }
+ }
+
+} //WikittyI18nImpl
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nUtil.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyI18nUtil.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nUtil.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyI18nUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,50 @@
+package org.nuiton.wikitty.addons;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyI18n;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyMetaExtensionUtil;
+import org.nuiton.wikitty.WikittyProxy;
+
+/**
+ *
+ * Cette classe sert a aider a la gestion multi-langue des extensions
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyI18nUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyI18nUtil.class);
+
+ /**
+ * Create or load WikittyExtensionTranslation for given extension.
+ * If created you must call store if you want keep it in storage
+ * @param proxy
+ * @param extension
+ * @return
+ */
+ static public WikittyI18n getI18n(WikittyProxy proxy, WikittyExtension extension) {
+ String id = WikittyMetaExtensionUtil.generateId(
+ WikittyI18n.EXT_WIKITTYI18N,
+ extension.getName());
+
+ WikittyI18n result;
+ Wikitty w = proxy.restore(id);
+ if (w == null) {
+ w = new WikittyImpl(id);
+ }
+ result = new WikittyI18nImpl(w);
+
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyImportExportService.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyImportExportService.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyImportExportService.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,267 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.entities.BusinessEntityWikitty;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyService;
+
+import org.nuiton.wikitty.addons.importexport.ExportTask;
+import org.nuiton.wikitty.addons.importexport.ImportExportCSV;
+import org.nuiton.wikitty.addons.importexport.ImportExportMethod;
+import org.nuiton.wikitty.addons.importexport.ImportExportXML;
+import org.nuiton.wikitty.addons.importexport.ImportTask;
+import org.nuiton.wikitty.addons.importexport.JobState;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ * Import/export service.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyImportExportService {
+
+ static public enum FORMAT {
+ XML(new ImportExportXML()),
+ CSV(new ImportExportCSV());
+
+ /** ieport == Importer/Exporter */
+ protected ImportExportMethod ieporter;
+ FORMAT(ImportExportMethod ieporter) {
+ this.ieporter = ieporter;
+ }
+
+ public ImportExportMethod ieporter() {
+ return ieporter;
+ }
+ };
+
+ /** directory path where export asynchronous file are stored */
+ protected String exportDirectory = "/tmp/";
+ /** url used by client to retrieve export file when job is ended */
+ protected String exportPublicURL = "file:///tmp/";
+
+ /** Executor that do import export task */
+ protected ExecutorService importExportExecutor;
+
+ /** contains all import or export task, key is job id send to client */
+ protected Map<String, Future<String>> importExportTask =
+ new HashMap<String, Future<String>>();
+
+ protected WikittyService ws;
+ protected String securityToken;
+
+ public WikittyImportExportService(
+ ApplicationConfig config, String securityToken, WikittyService ws) {
+ this.securityToken = securityToken;
+ this.ws = ws;
+
+ exportDirectory = config.getOption(
+ WikittyConfig.Option.WIKITTY_EXPORT_DIRECTORY.getKey());
+ exportPublicURL = config.getOption(
+ WikittyConfig.Option.WIKITTY_EXPORT_PUBLICURL.getKey());
+
+ int maxThread = config.getOptionAsInt(
+ WikittyConfig.Option.WIKITTY_EXPORT_THREADNUMBER.getKey());
+ this.importExportExecutor =
+ Executors.newFixedThreadPool(maxThread);
+ }
+
+ public WikittyService getWikittyService() {
+ return ws;
+ }
+
+ public String getExportDirectory() {
+ return exportDirectory;
+ }
+
+ public String getExportPublicURL() {
+ return exportPublicURL;
+ }
+
+ public void syncImport(FORMAT format, String s) {
+ Reader reader = new StringReader(s);
+ ImportTask task = new ImportTask(securityToken, ws, format, reader);
+ task.run();
+ }
+
+ public void syncImportFromUri(FORMAT format, String uri) {
+ try {
+ URL url = new URL(uri);
+ Reader reader = new InputStreamReader(url.openStream());
+ ImportTask task = new ImportTask(securityToken, ws, format, reader);
+ task.run();
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't import in format %s uri %s", format, uri), eee);
+ }
+ }
+
+ public String asyncImportFromUri(FORMAT format, String uri) {
+ try {
+ URL url = new URL(uri);
+ Reader reader = new InputStreamReader(url.openStream());
+ ImportTask task = new ImportTask(securityToken, ws, format, reader);
+ FutureTask<String> future = new FutureTask<String>(task, null);
+ importExportExecutor.submit(future);
+
+ String jobId = UUID.randomUUID().toString();
+ importExportTask.put(jobId, future);
+ return jobId;
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't import in format %s uri %s", format, uri), eee);
+ }
+ }
+
+ /**
+ * Asynchronous export by example.
+ *
+ * @param format export format
+ * @param e sample
+ * @return job id
+ */
+ public String asyncExportAllByExample(FORMAT format, BusinessEntityWikitty e) {
+ Criteria criteria = Search.query(e.getWikitty()).criteria();
+ String result = asyncExportAllByCriteria(format, criteria);
+ return result;
+ }
+
+ /**
+ * Synchronous export by example.
+ *
+ * @param format export format
+ * @param e sample
+ * @return export string
+ */
+ public String syncExportAllByExample(FORMAT format, BusinessEntityWikitty e) {
+ Criteria criteria = Search.query(e.getWikitty()).criteria();
+ String result = syncExportAllByCriteria(format, criteria);
+ return result;
+ }
+
+ /**
+ * Asynchronous export by criteria.
+ *
+ * @param format export format
+ * @param criteria criteria
+ * @return export as string
+ */
+ public String asyncExportAllByCriteria(FORMAT format, Criteria criteria) {
+ try {
+ String jobId = UUID.randomUUID().toString();
+
+ File file = new File(exportDirectory, jobId);
+ String url = exportPublicURL + jobId;
+ Writer result = new FileWriter(file);
+ ExportTask task = new ExportTask(
+ securityToken, ws, format, criteria, result);
+ FutureTask<String> future = new FutureTask<String>(task, url);
+ importExportExecutor.submit(future);
+
+ importExportTask.put(jobId, future);
+ return jobId;
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't export in format %s", format), eee);
+ }
+ }
+
+ /**
+ * Synchronous export by criteria.
+ *
+ * @param format export format
+ * @param criteria criteria
+ * @return export as string
+ */
+ public String syncExportAllByCriteria(FORMAT format, Criteria criteria) {
+ StringWriter result = new StringWriter();
+ ExportTask task = new ExportTask(
+ securityToken, ws, format, criteria, result);
+ task.run();
+ return result.toString();
+ }
+
+ /**
+ * Return job information.
+ *
+ * @param jobId job id
+ * @return job state
+ */
+ public JobState infoJob(String jobId) {
+ try {
+ Future<String> future = importExportTask.get(jobId);
+ JobState result = new JobState();
+ if (future.isDone()) {
+ result.status = "done";
+ result.resourceUri = future.get();
+ } else if (future.isCancelled()) {
+ result.status = "cancelled";
+ } else {
+ result.status = "inProgress";
+ }
+ return result;
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't retrieve job info for job %s", jobId), eee);
+ }
+ }
+
+ public void cancelJob(String jobId) {
+ Future<String> future = importExportTask.get(jobId);
+ future.cancel(true); // true to kill process, perhaps to strong ?
+ }
+
+ public void freeJobResource(String jobId) {
+ Future<String> future = importExportTask.remove(jobId);
+ if (future != null) {
+ File file = new File(exportDirectory, jobId);
+ file.delete();
+ }
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyLabelUtil.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyLabelUtil.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyLabelUtil.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/WikittyLabelUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,117 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 CodeLutin
+ * %%
+ * 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.addons;
+
+
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyLabelHelper;
+import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ * Util method to manage Label (add and find)
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyLabelUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyLabelUtil.class);
+
+ /**
+ * Add new lable to the wikitty object.
+ *
+ * @param proxy
+ * @param wikittyId object'id
+ * @param label label to add
+ */
+ static public void addLabel(WikittyProxy proxy, String wikittyId, String label) {
+ Wikitty w = proxy.restore(wikittyId);
+ WikittyLabelImpl l = new WikittyLabelImpl(w);
+ l.addLabels(label);
+ proxy.store(l);
+ }
+
+ /**
+ * Recherche tous les objets qui ont ce label
+ *
+ * @param proxy
+ * @param label
+ * @param firstIndex
+ * @param endIndex
+ * @return
+ */
+ static public PagedResult<Wikitty> findAllByLabel(WikittyProxy proxy,
+ String label, int firstIndex, int endIndex) {
+ WikittyLabelImpl l = new WikittyLabelImpl();
+ l.addLabels(label);
+
+ Criteria criteria = Search.query(l.getWikitty()).criteria()
+ .setFirstIndex(firstIndex).setEndIndex(endIndex);
+ PagedResult<Wikitty> result = proxy.findAllByCriteria(criteria);
+
+ return result;
+ }
+
+ /**
+ * Recherche le premier objet qui a ce label
+ * @param proxy
+ * @param label
+ * @return
+ */
+ static public Wikitty findByLabel(WikittyProxy proxy, String label) {
+ WikittyLabelImpl l = new WikittyLabelImpl();
+ l.addLabels(label);
+ Criteria criteria = Search.query(l.getWikitty()).criteria();
+ Wikitty result = proxy.findByCriteria(criteria);
+
+ return result;
+ }
+
+ /**
+ * Retrieve all labels applied on a wikitty object.
+ *
+ * @param proxy
+ * @param wikittyId
+ * @return set of label
+ */
+ static public Set<String> findAllAppliedLabels(WikittyProxy proxy, String wikittyId) {
+ Wikitty w = proxy.restore(wikittyId);
+ Set<String> result = WikittyLabelHelper.getLabels(w);
+
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ExportTask.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ExportTask.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ExportTask.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ExportTask.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,87 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import java.io.Writer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.addons.WikittyImportExportService.FORMAT;
+import org.nuiton.wikitty.search.operators.Element;
+
+public class ExportTask implements Runnable {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ImportTask.class);
+
+ protected WikittyService ws;
+ protected FORMAT format;
+ protected Criteria criteria;
+ protected Writer writer;
+ protected String securityToken;
+
+ public ExportTask(String securityToken,
+ WikittyService ws, FORMAT format, Criteria criteria, Writer writer) {
+ super();
+ this.securityToken = securityToken;
+ this.ws = ws;
+ this.format = format;
+ this.criteria = criteria;
+ this.writer = writer;
+ }
+
+ @Override
+ public void run() {
+ try {
+
+ // use a facet to get only extension used in export
+ // used for CSV export
+ criteria.addFacetField(Element.ELT_EXTENSION);
+
+ PagedResult<String> pageResultId = ws.findAllByCriteria(
+ securityToken, criteria);
+ long time = 0;
+ if (log.isInfoEnabled()) {
+ time = System.currentTimeMillis();
+ log.info("Export started");
+ }
+ // get Wikitty from Id
+ PagedResult<Wikitty> pageResult = pageResultId.cast(securityToken, ws);
+
+ ImportExportMethod exporter = format.ieporter();
+ exporter.exportWriter(securityToken, writer, ws, pageResult);
+ if (log.isInfoEnabled()) {
+ time = System.currentTimeMillis() - time;
+ log.info("Export in (ms)" + time);
+ }
+ } catch (Exception eee) {
+ throw new WikittyException("Error during export task", eee);
+ }
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportCSV.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportCSV.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportCSV.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportCSV.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,366 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.FacetTopic;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.Search;
+
+import au.com.bytecode.opencsv.CSVReader;
+import au.com.bytecode.opencsv.CSVWriter;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class ImportExportCSV implements ImportExportMethod {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ImportExportCSV.class);
+
+ /** Wikitty id header name. */
+ protected final static String FIELD_WIKITTY_ID = "Wikitty.Id";
+
+ /** Wikitty extensions header name. */
+ protected final static String FIELD_WIKITTY_EXT = "Wikitty.Ext";
+
+ /** Pattern form link queries. */
+ protected Pattern queryPattern = Pattern.compile("^((\\w+)\\.(\\w+))=(\"(.+)\"|([^\"]+))$");
+
+ @Override
+ public void importReader(String securityToken, Reader reader,
+ WikittyService ws) throws Exception {
+
+ // get index of wikitty.id field
+ int wikittyIdIndex = -1;
+ int wikittyExtIndex = -1;
+
+ // read header to get extension names
+ // and build two array for ext and fieldName
+ CSVReader csvReader = new CSVReader(reader);
+ String[] header = csvReader.readNext();
+ String[] ext = new String[header.length];
+ String[] fieldsName = new String[header.length];
+ for (int i = 0; i < header.length ; ++i) {
+ // wikitty id is technical (special management)
+ if (FIELD_WIKITTY_ID.equalsIgnoreCase(header[i])) {
+ wikittyIdIndex = i;
+ }
+ // wikitty ext is technical (special management)
+ else if (FIELD_WIKITTY_EXT.equalsIgnoreCase(header[i])) {
+ wikittyExtIndex = i;
+ }
+ else {
+ ext[i] = header[i].substring(0, header[i].indexOf("."));
+ fieldsName[i] = header[i].substring(header[i].indexOf(".") + 1);
+ }
+ }
+
+ // create a wikitty for each next line
+ String[] currentLine;
+ while ((currentLine = csvReader.readNext()) != null) {
+
+ // cas d'une ligne vide en fin de fichier
+ if (currentLine.length == 1) {
+ continue;
+ }
+
+ // build wikitty instance with id (if specified)
+ Wikitty currentWikitty = null;
+ if (wikittyIdIndex != -1) {
+ String wikittyId = currentLine[wikittyIdIndex];
+ if (StringUtils.isNotBlank(wikittyId)) {
+ currentWikitty = new WikittyImpl(wikittyId);
+ }
+ }
+ if (currentWikitty == null) {
+ currentWikitty = new WikittyImpl();
+ }
+
+ // add required extension (if specified)
+ if (wikittyExtIndex != -1) {
+ String extensionList = currentLine[wikittyExtIndex];
+ if (StringUtils.isNotBlank(extensionList)) {
+ String[] extensions = extensionList.split(",");
+ for (String extension : extensions) {
+ String extName = extension.trim();
+ addMissingExtension(
+ securityToken, ws, currentWikitty, extName);
+ }
+ }
+ }
+
+ // manage other fields
+ for (int i = 0; i < header.length ; ++i) {
+
+ // wikitty id column, already managed
+ if (i == wikittyIdIndex || i == wikittyExtIndex) {
+ continue;
+ }
+
+ String extName = ext[i];
+ String fieldName = fieldsName[i];
+ String value = currentLine[i];
+
+ // case null or empty
+ if (StringUtils.isNotEmpty(value)) {
+
+ // extension must exists on wikitty to set a field value
+ addMissingExtension(securityToken, ws, currentWikitty, extName);
+
+ // convert link values (if necessary)
+ value = convertLinkValues(securityToken, ws, value);
+
+ // add value to correct field
+ FieldType fieldType = currentWikitty.getFieldType(extName + "." + fieldName);
+ if (fieldType.isCollection()) {
+ String[] multiplesValues = StringUtil.split(value);
+ for (String multiplesValue : multiplesValues) {
+ // begin and ends with () only if fields
+ // has multiples values during import
+ if (multiplesValue.startsWith("(") && multiplesValue.endsWith(")")) {
+ multiplesValue = multiplesValue.substring(1, multiplesValue.length() - 1);
+ }
+
+ // remove non existant wikitty on Wikitty type field
+ if (fieldType.getType().equals(TYPE.WIKITTY)) {
+
+ // restore works (database) but solr criteria won't
+ List<Wikitty> wikitties = ws.restore(securityToken,
+ Collections.singletonList(multiplesValue));
+ if ( wikitties != null && wikitties.size() == 1 && wikitties.get(0) != null) {
+ currentWikitty.addToField(extName, fieldName, multiplesValue);
+ }
+ }
+ else {
+ currentWikitty.addToField(extName, fieldName, multiplesValue);
+ }
+ }
+ } else {
+ // remove non existant wikitty on Wikitty type field
+ if (fieldType.getType().equals(TYPE.WIKITTY)) {
+
+ // restore works (database) but solr criteria won't
+ List<Wikitty> wikitties = ws.restore(securityToken,
+ Collections.singletonList(value));
+ if ( wikitties != null && wikitties.size() == 1 && wikitties.get(0) != null) {
+ currentWikitty.setField(extName, fieldName, value);
+ }
+ }
+ else {
+ currentWikitty.setField(extName, fieldName, value);
+ }
+ }
+ }
+ }
+
+ // add it into datas
+ ws.store(securityToken, Collections.singleton(currentWikitty), true);
+ }
+ }
+
+ /**
+ * Recusively add missing extension of not exist and required extension too.
+ *
+ * @throws WikittyException if the extension does not exist in base
+ */
+ protected void addMissingExtension(String securityToken, WikittyService ws,
+ Wikitty currentWikitty, String extName) {
+ // extension must exists on wikitty to set a field value
+ if (!currentWikitty.hasExtension(extName)) {
+ WikittyExtension extension = ws.restoreExtensionLastVersion(
+ securityToken, extName);
+
+ if (extension != null) {
+ String requires = extension.getRequires();
+ if (StringUtils.isNotEmpty(requires)) {
+ // add required extensions BEFORE current
+ for (String require : requires.split(",")) {
+ String localRequire = require.trim();
+ addMissingExtension(securityToken, ws, currentWikitty, localRequire);
+ }
+ }
+
+ currentWikitty.addExtension(extension);
+ } else {
+ throw new WikittyException("Extension " + extName + " does not exist");
+ }
+ }
+ }
+
+ /**
+ * Convert internal queries to search for other real wikitty ids.
+ *
+ * @param value
+ * @return
+ */
+ protected String convertLinkValues(
+ String securityToken, WikittyService ws, String value) {
+
+ String originalValue = value;
+ String resultValue = "";
+ String separator = "";
+ boolean correctQueries = true;
+
+ // manage multiples query comma separated
+ try {
+ String[] queries = StringUtil.split(value, ",");
+
+ for (String query : queries) {
+ Matcher m = queryPattern.matcher(query.trim());
+ if (m.find()) {
+ String fqField = m.group(1);
+ String fValue = m.group(5);
+ if (fValue == null) {
+ // quoted value
+ fValue = m.group(6);
+ }
+ Criteria criteria = Search.query().eq(fqField, fValue).criteria();
+ Wikitty wikitty = ws.findByCriteria(securityToken, criteria);
+ if (wikitty == null) {
+ correctQueries = false;
+ }
+ else {
+ resultValue += separator + wikitty.getId();
+ separator = ",";
+ }
+ }
+ else {
+ // global parsing fail
+ // return original value
+ correctQueries = false;
+ }
+ }
+ }
+ catch (StringIndexOutOfBoundsException eee) {
+ if (log.isTraceEnabled()) {
+ log.trace("Can't split field on , skipping");
+ }
+ }
+
+ // if conversion has not been done, return original value
+ if (!correctQueries || StringUtils.isEmpty(resultValue)) {
+ resultValue = originalValue;
+ }
+ return resultValue;
+ }
+
+ @Override
+ public void exportWriter(String securityToken, Writer writer,
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception {
+
+ CSVWriter csvWriter = new CSVWriter(writer);
+
+ // write all data into writer
+ List<String> extensionHeader = new LinkedList<String>();
+ extensionHeader.add(FIELD_WIKITTY_ID);
+ extensionHeader.add(FIELD_WIKITTY_EXT);
+ for (FacetTopic topic : pagedResult.getTopic(Element.ELT_EXTENSION)) {
+ String extName = topic.getTopicName();
+
+ WikittyExtension extension = ws.restoreExtensionLastVersion(
+ securityToken, extName);
+ String ext = WikittyExtension.computeName(extName);
+ for (String fieldName : extension.getFieldNames()) {
+ extensionHeader.add(ext + "." + fieldName);
+ }
+ }
+ csvWriter.writeNext(extensionHeader.toArray(new String[extensionHeader.size()]));
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exporting wikitty : " + pagedResult.getAll().size() + " results");
+ }
+
+ // Export wikitty data
+ List<Wikitty> wikitties = pagedResult.getAll();
+ for (Wikitty w : wikitties) {
+
+ String[] wikittyField = new String[extensionHeader.size()];
+
+ // first, add technical id
+ wikittyField[extensionHeader.indexOf(FIELD_WIKITTY_ID)] = w.getId();
+ // second, add technical ext list
+ Collection<String> extNamesCollection = w.getExtensionNames();
+ String extNames = StringUtils.join(extNamesCollection, ',');
+ wikittyField[extensionHeader.indexOf(FIELD_WIKITTY_EXT)] = extNames;
+
+ // wikitty export must be composed of all field
+ // corresponding to header extensions names
+ for (String fieldName : w.fieldNames()) {
+ String currentField = "";
+
+ FieldType type = w.getFieldType(fieldName);
+ if (type.isCollection()) {
+ Object fqField = w.getFqField(fieldName);
+ if (fqField != null) {
+ String separator = "";
+ for (Object o : (Collection<?>) fqField) {
+ String fqFieldValue = WikittyUtil.toString(type, o);
+ currentField += separator + "(" + fqFieldValue + ")";
+ separator = ",";
+ }
+ }
+ } else {
+ String fqFieldValue = WikittyUtil.toString(type, w.getFqField(fieldName));
+ currentField = fqFieldValue;
+ }
+
+ wikittyField[extensionHeader.indexOf(fieldName)] = currentField;
+ }
+
+ csvWriter.writeNext(wikittyField);
+ }
+
+ csvWriter.close();
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportMethod.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportMethod.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportMethod.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportMethod.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,74 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import java.io.Reader;
+import java.io.Writer;
+
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+/**
+ * Import / export interface.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface ImportExportMethod {
+
+ /**
+ * Import data from reader.
+ *
+ * @param securityToken security token
+ * @param reader reader
+ * @param ws wikitty service
+ * @param transaction current transaction
+ * @param batchUpdate wikitty batch update helper
+ *
+ * @throws Exception
+ */
+ public void importReader(
+ String securityToken, Reader reader, WikittyService ws) throws Exception;
+
+ /**
+ * Export data to writer.
+ *
+ * @param securityToken security token
+ * @param writer writer
+ * @param ws wikitty service
+ * @param transaction current transaction
+ * @param pagedResult paged result
+ *
+ * @throws Exception
+ */
+ public void exportWriter(String securityToken, Writer writer,
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception;
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportXML.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportXML.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportXML.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportExportXML.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,199 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.services.WikittyTransaction;
+import org.nuiton.wikitty.WikittyUtil;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class ImportExportXML implements ImportExportMethod {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ImportExportXML.class);
+
+ @Override
+ public void importReader(String securityToken, Reader reader,
+ WikittyService ws) throws Exception {
+ XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
+ System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
+ factory.setNamespaceAware(true);
+ XmlPullParser xpp = factory.newPullParser();
+ xpp.setInput(reader);
+
+ WikittyExtension ext = null;
+ Wikitty w = null;
+ String CDATA = null;
+
+ int eventType;
+ do {
+ eventType = xpp.next();
+ String objectVersion = null;
+ if (eventType == XmlPullParser.START_DOCUMENT) {
+ log.info("start XML import at " + new Date());
+ } else if (eventType == XmlPullParser.START_TAG) {
+ String name = xpp.getName();
+ if ("extension".equals(name)) {
+ String extName = xpp.getAttributeValue(null, "name");
+ String version = xpp.getAttributeValue(null, "version");
+ String requires = xpp.getAttributeValue(null, "requires");
+ ext = new WikittyExtension(extName, version, requires,
+ new LinkedHashMap<String, FieldType>());
+ } else if ("object".equals(name)) {
+ String id = xpp.getAttributeValue(null, "id");
+ objectVersion = xpp.getAttributeValue(null, "version");
+ String extensions = xpp.getAttributeValue(null, "extensions");
+ w = new WikittyImpl(id);
+ String[] extensionList = extensions.split(",");
+ for (String extId : extensionList) {
+ String extName = WikittyExtension.computeName(extId);
+ String extVersion = WikittyExtension.computeVersion(extId);
+ extId = WikittyExtension.computeId(extName, extVersion);
+ WikittyExtension e = ws.restoreExtension(securityToken, extId);
+ if (e == null) {
+ throw new WikittyException("Extension not found : " + extId);
+ }
+ w.addExtension(e);
+ }
+ }
+ } else if (eventType == XmlPullParser.END_TAG) {
+ String name = xpp.getName();
+ if ("extension".equals(name)) {
+ ws.storeExtension(securityToken, Collections.singleton(ext));
+ ext = null;
+ } else if ("object".equals(name)) {
+ w.setVersion(objectVersion);
+ ws.store(securityToken, Collections.singleton(w), true);
+ w = null;
+ } else if (ext != null && "field".equals(name)) {
+ FieldType type = new FieldType();
+ String fieldName = WikittyUtil.parseField(CDATA, type);
+ ext.addField(fieldName, type);
+ } else if (ext != null && "tagvalues".equals(name)) {
+ Map<String, String> tagValues = WikittyUtil.tagValuesToMap(CDATA);
+ ext.setTagValues(tagValues);
+ } else if (w != null) {
+ String[] fq = name.split("\\.");
+ String extensionName = fq[0];
+ String fieldName = fq[1];
+ FieldType fieldType = w.getFieldType(name);
+ if (fieldType.isCollection()) {
+ w.addToField(extensionName, fieldName, CDATA);
+ } else {
+ w.setField(extensionName, fieldName, CDATA);
+ }
+ }
+ } else if (eventType == XmlPullParser.TEXT) {
+ CDATA = xpp.getText();
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+ }
+
+ @Override
+ public void exportWriter(String securityToken, Writer result,
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception {
+ // keep extension already done
+ Set<String> extDone = new HashSet<String>();
+ result.write("<wikengo>\n");
+
+ List<Wikitty> wikitties = pagedResult.getAll();
+ for (Wikitty w : wikitties) {
+ String extensionList = "";
+ for (WikittyExtension ext : w.getExtensions()) {
+ String id = ext.getId();
+ extensionList += "," + id;
+ if (!extDone.contains(id)) {
+ extDone.add(id);
+ result.write(" <extension name='" + ext.getName() + "' version='" + ext.getVersion() + (ext.getRequires() != null ? "' requires='" + ext.getRequires() : "") + "'>\n");
+ Map<String, String> tagValues = ext.getTagValues();
+ result.write(" <tagvalues>" + WikittyUtil.tagValuesToString(tagValues) + "</tagvalues>\n");
+ for (String fieldName : ext.getFieldNames()) {
+ String def = ext.getFieldType(fieldName).toDefinition(fieldName);
+ result.write(" <field>" + def + "</field>\n");
+ }
+ result.write(" </extension>\n");
+ }
+ }
+ if (!"".equals(extensionList)) {
+ // delete first ','
+ extensionList = extensionList.substring(1);
+ }
+ result.write(" <object id='" + w.getId() + "' version='" + w.getVersion() + "' extensions='" + extensionList + "'>\n");
+ for (String fieldName : w.fieldNames()) {
+ FieldType type = w.getFieldType(fieldName);
+ if (type.isCollection()) {
+ Object fqField = w.getFqField(fieldName);
+ if (fqField != null) {
+ for (Object o : (Collection) fqField) {
+ String fqFieldValue = WikittyUtil.toString(type, o);
+ if (fqFieldValue != null) {
+ fqFieldValue = StringEscapeUtils.escapeXml(fqFieldValue);
+ result.write(" <" + fieldName + ">" + fqFieldValue + "</" + fieldName + ">\n");
+ }
+ }
+ }
+ } else {
+ String fqFieldValue = WikittyUtil.toString(type, w.getFqField(fieldName));
+ if (fqFieldValue != null) {
+ fqFieldValue = StringEscapeUtils.escapeXml(fqFieldValue);
+ result.write(" <" + fieldName + ">" + fqFieldValue + "</" + fieldName + ">\n");
+ }
+ }
+ }
+ result.write(" </object>\n");
+ }
+ result.write("</wikengo>\n");
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportTask.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportTask.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportTask.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/ImportTask.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,80 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import java.io.Reader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.addons.WikittyImportExportService.FORMAT;
+import org.nuiton.wikitty.services.WikittyServiceTransaction;
+
+public class ImportTask implements Runnable {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(ImportTask.class);
+
+ protected WikittyService ws;
+ protected FORMAT format;
+ protected Reader reader;
+ protected ImportExportMethod importerExporter;
+ protected String securityToken;
+
+ public ImportTask(String securityToken,
+ WikittyService ws, FORMAT format, Reader reader) {
+ super();
+ this.securityToken = securityToken;
+ this.ws = ws;
+ this.format = format;
+ this.reader = reader;
+ }
+
+ @Override
+ public void run() {
+ WikittyServiceTransaction tx = new WikittyServiceTransaction(null, ws);
+ // TODO poussin 20101029 rendre configurable le l'auto commit '1000' pour l'import
+ tx.setAutoCommit(1000);
+ try {
+ long time = 0;
+ if (log.isInfoEnabled()) {
+ time = System.currentTimeMillis();
+ log.info("Import in (ms)" + time);
+ }
+ ImportExportMethod importer = format.ieporter();
+ importer.importReader(securityToken, reader, tx);
+
+ if (log.isInfoEnabled()) {
+ time = System.currentTimeMillis() - time;
+ log.info("Import in (ms)" + time);
+ }
+ // don't forget to commit :)
+ tx.commit(securityToken);
+ } catch (Exception eee) {
+ tx.rollback(securityToken);
+ throw new WikittyException("Error during import task", eee);
+ }
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/JobState.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/JobState.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/JobState.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/addons/importexport/JobState.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,48 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class JobState {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(JobState.class);
+
+ public String status; // or enum
+ /** if is an export, resourceUri is not null when job is ended */
+ public String resourceUri; // generated resource URI on that job
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntity.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntity.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntity.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntity.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,147 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * Used as parent interface to all Business class
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+// FIXME poussin 20100528 voir si cette interface est reellement necessaire. On pourra renommer BusinessEntityWikitty en BusinessEntity
+public interface BusinessEntity extends Serializable, Cloneable {
+
+ /**
+ * Return wikitty id (uuid).
+ *
+ * @return wikitty id
+ */
+ public String getWikittyId();
+
+ /**
+ * Return wikitty version (x.y).
+ *
+ * @return wikitty version
+ */
+ public String getWikittyVersion();
+
+ /**
+ * Return wikitty
+ *
+ * @return the wikitty actually storing the entity's data
+ * @since 2.2.1
+ */
+ public Wikitty getWikitty();
+
+ /**
+ * Only framework can use this method.
+ *
+ * @param version version to set
+ */
+ public void setWikittyVersion(String version);
+
+ /**
+ * Return list of all extension for this object.
+ *
+ * @return extension names
+ */
+ public Collection<String> getExtensionNames();
+
+ /**
+ * Return list of all field for this object.
+ *
+ * @param ext extension to get fields
+ * @return fields collections
+ */
+ public Collection<String> getExtensionFields(String ext);
+
+ /**
+ * Return field value for the specific extension and field.
+ *
+ * @param ext extension
+ * @param fieldName field name
+ * @return field value
+ */
+ public Object getField(String ext, String fieldName);
+
+ /**
+ * Set field value for the specific extension and field.
+ *
+ * This method don't check the type of value for this field.
+ *
+ * @param ext extension
+ * @param fieldName field name
+ * @param value value to set
+ */
+ public void setField(String ext, String fieldName, Object value);
+
+ /**
+ * Return the field type.
+ *
+ * @param ext extension
+ * @param fieldName field name
+ * @return feild type
+ */
+ public FieldType getFieldType(String ext, String fieldName);
+
+ /**
+ * Add {@link PropertyChangeListener}.
+ *
+ * @param listener listener to add
+ */
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ * Remove {@link PropertyChangeListener}.
+ *
+ * @param listener listener to remove
+ */
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+ /**
+ * Add {@link PropertyChangeListener} on {@code propertyName}.
+ *
+ * @param propertyName property name
+ * @param listener listener to add
+ */
+ void addPropertyChangeListener(String propertyName, PropertyChangeListener listener);
+
+ /**
+ * Remove {@link PropertyChangeListener} on {@code propertyName}
+ *
+ * @param propertyName property name
+ * @param listener listener listener to remove
+ */
+ void removePropertyChangeListener(String propertyName, PropertyChangeListener listener);
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityWikitty.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/BusinessEntityWikitty.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityWikitty.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/BusinessEntityWikitty.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,179 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Each business object will inherit of this class.
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class BusinessEntityWikitty implements BusinessEntity {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -4399752739887114180L;
+
+ /**
+ * Property change support.
+ *
+ * Warning, this transient field is null after deserialization.
+ */
+ protected transient PropertyChangeSupport propertyChangeSupport;
+
+ protected Wikitty wikitty;
+
+ public BusinessEntityWikitty(Wikitty wi) {
+ setWikitty(wi);
+ }
+
+ public BusinessEntityWikitty() {
+ this(new WikittyImpl());
+ }
+
+ protected PropertyChangeSupport getPropertyChangeSupport() {
+ if (propertyChangeSupport == null) {
+ propertyChangeSupport = new PropertyChangeSupport(this);
+ }
+ return propertyChangeSupport;
+ }
+
+ public String getWikittyId() {
+ String result = getWikitty().getId();
+ return result;
+ }
+
+ public String getWikittyVersion() {
+ String result = getWikitty().getVersion();
+ return result;
+ }
+
+ public void setWikittyVersion(String version) {
+ getWikitty().setVersion(version);
+ }
+
+ public void setWikitty(Wikitty wikitty) {
+ if(wikitty != null) {
+ for (WikittyExtension ext : getStaticExtensions()) {
+ wikitty.addExtension(ext);
+ }
+ }
+ this.wikitty = wikitty;
+ }
+
+ /**
+ * @see BusinessEntity#getWikitty()
+ */
+ public Wikitty getWikitty() {
+ return wikitty;
+ }
+
+ public Collection<String> getExtensionNames() {
+ Collection<String> result = getWikitty().getExtensionNames();
+ return result;
+ }
+
+ public Collection<String> getExtensionFields(String ext) {
+ Collection<String> result = getWikitty().getExtension(ext).getFieldNames();
+ return result;
+ }
+
+ public FieldType getFieldType(String ext, String fieldName) {
+ FieldType result = getWikitty().getExtension(ext).getFieldType(fieldName);
+ return result;
+ }
+
+ public Object getField(String ext, String fieldName) {
+ Object result = getWikitty().getFieldAsObject(ext, fieldName);
+ return result;
+ }
+
+ public void setField(String ext, String fieldName, Object value) {
+ getWikitty().setField(ext, fieldName, value);
+ }
+
+ public Collection<WikittyExtension> getStaticExtensions() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!BusinessEntityWikitty.class.isAssignableFrom(obj.getClass())) {
+ return false;
+ }
+ BusinessEntityWikitty wikitty = (BusinessEntityWikitty) obj;
+ return getWikittyId().equals(wikitty.getWikittyId());
+ }
+
+ @Override
+ public int hashCode() {
+ return getWikittyId().hashCode();
+ }
+
+ /*
+ * @see org.nuiton.wikitty.BusinessEntity#addPropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(listener);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.BusinessEntity#removePropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(listener);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.BusinessEntity#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+ */
+ @Override
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.BusinessEntity#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+ */
+ @Override
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/ExtensionFactory.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/ExtensionFactory.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/ExtensionFactory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/ExtensionFactory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,62 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.util.LinkedHashMap;
+
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+
+public class ExtensionFactory {
+
+ protected String name;
+ protected String version;
+ protected String requiredExtension;
+
+ protected LinkedHashMap<String, FieldType> fields;
+
+ protected ExtensionFactory(String name, String version) {
+ this.name = name;
+ this.version = version;
+ this.fields = new LinkedHashMap<String, FieldType>();
+ }
+
+ public static ExtensionFactory create(String name, String version) {
+ return new ExtensionFactory(name, version);
+ }
+
+ public FieldFactory addField(String name, TYPE fieldType) {
+ return new FieldFactory(this, name, fieldType);
+ }
+
+ public WikittyExtension extension() {
+ WikittyExtension ext = new WikittyExtension(name, version, requiredExtension, fields);
+ return ext;
+ }
+
+ protected void add(String fieldName, FieldType fieldType) {
+ fields.put(fieldName, fieldType);
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldFactory.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldFactory.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldFactory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldFactory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,91 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+
+public class FieldFactory {
+
+ protected ExtensionFactory parentFactory;
+ protected String fieldName;
+ protected TYPE type;
+ protected int minOccur = 0, maxOccur = 1;
+ protected boolean unique = false;
+ protected Map<String, String> tagValues = new HashMap<String, String>();
+
+ public FieldFactory(ExtensionFactory parentFactory, String fieldName, TYPE type) {
+ this.parentFactory = parentFactory;
+ this.fieldName = fieldName;
+ this.type = type;
+ }
+
+ public FieldFactory addField(String name, TYPE type) {
+ append();
+ return parentFactory.addField(name, type);
+ }
+
+ public WikittyExtension extension() {
+ append();
+ return parentFactory.extension();
+ }
+
+ protected void append() {
+ FieldType fieldType = new FieldType(type, minOccur, maxOccur);
+ for (Map.Entry<String, String> entry : tagValues.entrySet()) {
+ String tag = entry.getKey();
+ String value = entry.getValue();
+ fieldType.addTagValue(tag, value);
+ }
+ parentFactory.add(fieldName, fieldType);
+ }
+
+ public FieldFactory maxOccur(int max) {
+ maxOccur = max;
+ return this;
+ }
+
+ public FieldFactory minOccur(int min) {
+ minOccur = min;
+ return this;
+ }
+
+ public FieldFactory unique() {
+ addTagValue(FieldType.UNIQUE, "true");
+ return this;
+ }
+
+ public FieldFactory notNull() {
+ addTagValue(FieldType.NOT_NULL, "true");
+ return this;
+ }
+
+ public FieldFactory addTagValue(String tag, String value) {
+ tagValues.put(tag, value);
+ return this;
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FieldType.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,243 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class FieldType implements Serializable {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -4375308750387837026L;
+
+ /** tag/value use for unique */
+ static public String UNIQUE = "unique";
+ /** tag/value use for not null */
+ static public String NOT_NULL = "notNull";
+
+ static public enum TYPE {
+ BOOLEAN, DATE, NUMERIC, STRING, WIKITTY;
+
+ /**
+ * convert string to TYPE, this method accept not trimed and not well
+ * cased string (difference with valueOf)
+ * @param name
+ * @return TYPE else exception is throw
+ */
+ public static TYPE parse(String name) {
+ TYPE result = valueOf(name.trim().toUpperCase());
+ return result;
+ }
+ }
+
+ public static final int NOLIMIT = Integer.MAX_VALUE;
+
+ protected TYPE type;
+ protected int lowerBound;
+ protected int upperBound;
+
+ /** used to store tag/value used by client side ex: editor=xhtml */
+ Map<String, String> tagValues = new HashMap<String, String>();
+
+ public FieldType() {
+ }
+
+ public FieldType(TYPE type, int lowerBound, int upperBound) {
+ this.type = type;
+ this.lowerBound = lowerBound;
+ this.upperBound = upperBound;
+ }
+
+ public void addTagValue(String tag, String value) {
+ tagValues.put(tag, value);
+ }
+
+ public String getTagValue(String tag) {
+ String result = tagValues.get(tag);
+ return result;
+ }
+
+ public Set<String> getTagNames() {
+ return tagValues.keySet();
+ }
+
+ public Map<String, String> getTagValues() {
+ return tagValues;
+ }
+
+ public void setTagValues(Map<String, String> tagValues) {
+ this.tagValues = tagValues;
+ }
+
+ /**
+ * Return true if this field have upperBound > 1.
+ *
+ * @return {@code true} is field is collection
+ */
+ public boolean isCollection() {
+ return upperBound > 1;
+ }
+
+ /**
+ * Return string definition for this field.
+ *
+ * @param name field name used for definition
+ * @return field definition
+ */
+ public String toDefinition(String name) {
+ String result = type + " " + name;
+ if (lowerBound != 0 || upperBound != 0) {
+ if (upperBound != NOLIMIT) {
+ result += "[" + lowerBound + "-" + upperBound + "]";
+ } else {
+ result += "[" + lowerBound + "-*]";
+ }
+ }
+ result += WikittyUtil.tagValuesToString(tagValues);
+ return result;
+ }
+
+ /**
+ * Convert value in argument in right type for this FieldType. Don't support
+ * collection.
+ *
+ * @param value value to convert
+ * @return object in type of this FieldType
+ */
+ protected Object getContainedValidObject( Object value ) {
+ Object result = null;
+ switch (type) {
+ case DATE:
+ result = WikittyUtil.toDate(value); break;
+ case NUMERIC:
+ result = WikittyUtil.toBigDecimal(value); break;
+ case BOOLEAN:
+ result = WikittyUtil.toBoolean(value); break;
+ case STRING:
+ result = WikittyUtil.toString(value); break;
+ default:
+ // if type is not found then type is business type
+ // and is wikitty object
+ result = WikittyUtil.toWikitty(value); break;
+ }
+ return result;
+ }
+
+ /**
+ * Return a valid value for this field.
+ *
+ * @param value is casted if possible to an actual correct value.
+ * @return value validity
+ * @throws WikittyException if value can't be obtained
+ */
+ public Object getValidValue(Object value) throws WikittyException {
+ if (value == null && isNotNull()) {
+ throw new WikittyException("Value can't be null for this field");
+ }
+
+ Object result;
+ if (value == null) {
+ result = null;
+ } else if (isCollection()) {
+ if ( !(value instanceof Collection) ) {
+ throw new WikittyException( "A collection is expected for type "
+ + type.name() + "[" + lowerBound + " - " + upperBound + "]" );
+ }
+ Collection<Object> col;
+ if (isUnique()) {
+ col = new LinkedHashSet<Object>();
+ } else {
+ col = new ArrayList<Object>();
+ }
+
+ // copy all value in new collections
+ for ( Object o : (Collection<?>) value ) {
+ col.add( getContainedValidObject(o) );
+ }
+ result = col;
+ } else {
+ result = getContainedValidObject(value);
+ }
+ return result;
+ }
+
+ /**
+ * Test if value in argument is valid for this field type.
+ *
+ * @param value to test
+ * @return true if value is valid
+ */
+ public boolean isValidValue(Object value) {
+ return getValidValue(value) != null;
+ }
+
+ public TYPE getType() {
+ return type;
+ }
+
+ public void setType(TYPE type) {
+ this.type = type;
+ }
+
+ public int getLowerBound() {
+ return lowerBound;
+ }
+
+ public void setLowerBound(int lowerBound) {
+ this.lowerBound = lowerBound;
+ }
+
+ public int getUpperBound() {
+ return upperBound;
+ }
+
+ public void setUpperBound(int upperBound) {
+ this.upperBound = upperBound;
+ }
+
+ public boolean isUnique() {
+ return "true".equalsIgnoreCase(getTagValue(UNIQUE));
+ }
+
+ public boolean isNotNull() {
+ return "true".equalsIgnoreCase(getTagValue(NOT_NULL));
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Wikitty.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,228 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+public interface Wikitty extends Cloneable, Serializable {
+
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+ void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener);
+
+ void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener);
+
+ /**
+ * Replace all field of current wikitty with field found in w.
+ * This two wikitty must have same id
+ * @param w wikitty where we take information
+ */
+ void replace(Wikitty w);
+
+ String getId();
+
+ boolean isDeleted();
+
+ Date getDeleteDate();
+
+ /**
+ * Server only used
+ * @param delete
+ */
+ void setDeleteDate(Date delete);
+
+ void addExtension(WikittyExtension ext);
+
+ void addExtension(List<WikittyExtension> exts);
+
+ /** check that the wikitty has a metaExtension about a given extension.
+ * @param metaExtensionName the metaExtension to be checked
+ * @param extensionName an extension already added to the wikitty
+ * @since 2.2.0
+ */
+ boolean hasMetaExtension(String metaExtensionName,
+ String extensionName);
+
+ /** add a meta-extension about the given extension to this wikitty.
+ * @param metaExtension the metaExtension to add
+ * @param extension an extension already added to the wikitty
+ * @since 2.1
+ */
+ void addMetaExtension(WikittyExtension metaExtension,
+ WikittyExtension extension);
+
+
+ /** add a meta-extension on the given extension to this wikitty.
+ * @param metaExtension the metaExtension to add
+ * @param extensionFqn the name of the extension already added to the wikitty
+ * @since 2.1
+ */
+ void addMetaExtension(WikittyExtension metaExtension, String extensionFqn);
+
+ boolean hasExtension(String extName);
+
+ boolean hasField(String extName, String fieldName);
+
+ WikittyExtension getExtension(String ext);
+
+ Collection<String> getExtensionNames();
+
+ Collection<WikittyExtension> getExtensions();
+
+ Collection<WikittyExtension> getExtensionDependencies(String ext,
+ boolean recursively);
+
+ /**
+ * return field type for the given fieldName.
+ * @param fqfieldName fully qualified fieldName extension.fieldname
+ * @return field type
+ */
+ FieldType getFieldType(String fqfieldName);
+
+ void setField(String ext, String fieldName, Object value);
+
+ Object getFieldAsObject(String ext, String fieldName);
+
+ boolean getFieldAsBoolean(String ext, String fieldName);
+
+ BigDecimal getFieldAsBigDecimal(String ext, String fieldName);
+
+ int getFieldAsInt(String ext, String fieldName);
+
+ long getFieldAsLong(String ext, String fieldName);
+
+ float getFieldAsFloat(String ext, String fieldName);
+
+ double getFieldAsDouble(String ext, String fieldName);
+
+ String getFieldAsString(String ext, String fieldName);
+
+ Date getFieldAsDate(String ext, String fieldName);
+
+ /**
+ * return wikitty id and not wikitty objet because this method can be call
+ * on server or client side and it's better to keep conversion between id
+ * and objet to the caller
+ * @param ext extension name where this field must to be
+ * @param fieldName the field name
+ * @return id of wikitty object or null
+ * @throws org.nuiton.wikitty.WikittyException
+ */
+ String getFieldAsWikitty(String ext, String fieldName);
+
+ /**
+ * If object is a set, it is automatically transform to list.
+ * @param <E>
+ * @param clazz
+ * @return unmodifiable list
+ */
+ <E> List<E> getFieldAsList(String ext, String fieldName,
+ final Class<E> clazz);
+
+ /**
+ *
+ * @param <E>
+ * @param clazz
+ * @return unmodifiable list
+ */
+ <E> Set<E> getFieldAsSet(String ext, String fieldName, final Class<E> clazz);
+
+ void addToField(String ext, String fieldName, Object value);
+
+ void removeFromField(String ext, String fieldName, Object value);
+
+ void clearField(String ext, String fieldName);
+
+ /**
+ * Add an element in a field
+ * @param fqFieldName the fully qualified name of a collection field
+ * @param value the value to be added to the collection
+ * @since 2.2.0
+ */
+ void addToField(String fqFieldName, Object value);
+
+ /**
+ * Remove an element from a field
+ * @param fqFieldName the fully qualified name of a collection field
+ * @param value the value to be removed to the collection
+ * @since 2.2.0
+ */
+ void removeFromField(String fqFieldName, Object value);
+
+ /**
+ * Clear a field
+ * @param fqFieldName the fully qualified name of a collection field
+ * @since 2.2.0
+ */
+ void clearField(String fqFieldName);
+
+ Set<String> fieldNames();
+
+ /** get the value of and field given its fqn */
+ Object getFqField(String fqFieldName);
+
+ String getVersion();
+
+ /**
+ * Server only used
+ * @param version
+ */
+ void setVersion(String version);
+
+ /**
+ * get the field modified after wikitty was restored
+ * @return a set of fully qualified field names
+ * @since 2.2.0
+ */
+ Set<String> getDirty();
+
+ /** clear the lists of modified field since last restore. */
+ void clearDirty();
+
+
+ /** set the value of a field given is fqn.
+ * @param fieldName fqn (ex: extensionName.fieldName)
+ * @param value new value
+ */
+ void setFqField(String fieldName, Object value);
+
+ boolean isEmpty();
+
+ /**
+ * @see Cloneable#clone()
+ */
+ Wikitty clone() throws CloneNotSupportedException;
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCopyOnWrite.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,413 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyException;
+
+/** this class wrap a wikitty in a proxy that copy the wikitty before applying any change
+ *
+ * It is used for caching purpose. This class own a reference to an actual
+ * wikitty, multiple instance of this class can own some references to a same
+ * actual wikitty. To prevent the target to be modified, a copy is created
+ * to prevent side-effect.
+ *
+ * So, when a wikitty restored from cache is modified, a copy is modified, so
+ * if change are cancelled, next restore will restore the original and not
+ * the modified version (until the modified version is stored).
+ *
+ * used in {@link WikittyServiceCached}
+ */
+public class WikittyCopyOnWrite implements Wikitty {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log = LogFactory.getLog(WikittyCopyOnWrite.class);
+
+ protected Wikitty target;
+
+ protected boolean targetIsACopy = false;
+
+ /** only WikittyService with cache should create instances */
+ public WikittyCopyOnWrite(Wikitty target) {
+ this.target = target;
+ }
+
+ @Override
+ public void replace(Wikitty w) {
+ // test make a the copy once
+ if (targetIsACopy) {
+ target.replace(w);
+ } else {
+ try {
+ target = w.clone();
+ if (log.isTraceEnabled()) {
+ log.trace(this + " now has for target " + target);
+ }
+ } catch (CloneNotSupportedException eee) {
+ throw new WikittyException(String.format(
+ "unable to clone wikitty %s", target), eee);
+ }
+ targetIsACopy = true;
+ }
+ }
+
+ /** replace {@link #target} with a clone
+ *
+ * this method must be called to prevent any modification on target
+ */
+ protected void substituteTargetWithCopy() {
+ // test make a the copy once
+ if (! targetIsACopy) {
+ try {
+ target = target.clone();
+ if (log.isTraceEnabled()) {
+ log.trace(this + " now has for target " + target);
+ }
+ } catch (CloneNotSupportedException eee) {
+ throw new WikittyException(String.format(
+ "unable to clone wikitty %s", target), eee);
+ }
+ targetIsACopy = true;
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ // FIXME 20100804 bleny side-effect ?
+ return target.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ // FIXME 20100804 bleny side-effect ?
+ return target.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "[" + WikittyCopyOnWrite.class.getName() + "]" + target.toString();
+ }
+
+ @Override
+ public Wikitty clone() throws CloneNotSupportedException {
+ // return a clone of the target
+ return target.clone();
+ }
+
+ /* ** below are only delegation code with copy-on-write */
+
+ @Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ target.addPropertyChangeListener(listener);
+ }
+
+ @Override
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ target.removePropertyChangeListener(listener);
+ }
+
+ @Override
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ target.addPropertyChangeListener(propertyName, listener);
+ }
+
+ @Override
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ target.removePropertyChangeListener(propertyName, listener);
+ }
+
+ @Override
+ public String getId() {
+ return target.getId();
+ }
+
+ @Override
+ public boolean isDeleted() {
+ return target.isDeleted();
+ }
+
+ @Override
+ public Date getDeleteDate() {
+ return target.getDeleteDate();
+ }
+
+ @Override
+ public void setDeleteDate(Date delete) {
+ target.setDeleteDate(delete);
+ }
+
+ @Override
+ public void addExtension(WikittyExtension ext) {
+ substituteTargetWithCopy();
+ target.addExtension(ext);
+ }
+
+ @Override
+ public void addExtension(List<WikittyExtension> exts) {
+ substituteTargetWithCopy();
+ target.addExtension(exts);
+ }
+
+ @Override
+ public boolean hasExtension(String extName) {
+ return target.hasExtension(extName);
+ }
+
+ @Override
+ public boolean hasField(String extName, String fieldName) {
+ return target.hasField(extName, fieldName);
+ }
+
+ @Override
+ public WikittyExtension getExtension(String ext) {
+ return target.getExtension(ext);
+ }
+
+ @Override
+ public Collection<String> getExtensionNames() {
+ return target.getExtensionNames();
+ }
+
+ @Override
+ public Collection<WikittyExtension> getExtensions() {
+ return target.getExtensions();
+ }
+
+ @Override
+ public Collection<WikittyExtension> getExtensionDependencies(String ext,
+ boolean recursively) {
+ return target.getExtensionDependencies(ext, recursively);
+ }
+
+ @Override
+ public FieldType getFieldType(String fqfieldName) {
+ return target.getFieldType(fqfieldName);
+ }
+
+ @Override
+ public void setField(String ext, String fieldName, Object value) {
+ substituteTargetWithCopy();
+ target.setField(ext, fieldName, value);
+ }
+
+ @Override
+ public Object getFieldAsObject(String ext, String fieldName) {
+ return target.getFieldAsObject(ext, fieldName);
+ }
+
+ @Override
+ public boolean getFieldAsBoolean(String ext, String fieldName) {
+ return target.getFieldAsBoolean(ext, fieldName);
+ }
+
+ @Override
+ public BigDecimal getFieldAsBigDecimal(String ext, String fieldName) {
+ return target.getFieldAsBigDecimal(ext, fieldName);
+ }
+
+ @Override
+ public int getFieldAsInt(String ext, String fieldName) {
+ return target.getFieldAsInt(ext, fieldName);
+ }
+
+ @Override
+ public long getFieldAsLong(String ext, String fieldName) {
+ return target.getFieldAsLong(ext, fieldName);
+ }
+
+ @Override
+ public float getFieldAsFloat(String ext, String fieldName) {
+ return target.getFieldAsFloat(ext, fieldName);
+ }
+
+ @Override
+ public double getFieldAsDouble(String ext, String fieldName) {
+ return target.getFieldAsDouble(ext, fieldName);
+ }
+
+ @Override
+ public String getFieldAsString(String ext, String fieldName) {
+ return target.getFieldAsString(ext, fieldName);
+ }
+
+ @Override
+ public Date getFieldAsDate(String ext, String fieldName) {
+ return target.getFieldAsDate(ext, fieldName);
+ }
+
+ @Override
+ public String getFieldAsWikitty(String ext, String fieldName) {
+ return target.getFieldAsWikitty(ext, fieldName);
+ }
+
+ @Override
+ public <E> List<E> getFieldAsList(String ext, String fieldName,
+ Class<E> clazz) {
+ return target.getFieldAsList(ext, fieldName, clazz);
+ }
+
+ @Override
+ public <E> Set<E> getFieldAsSet(String ext, String fieldName, Class<E> clazz) {
+ return target.getFieldAsSet(ext, fieldName, clazz);
+ }
+
+ @Override
+ public void addToField(String ext, String fieldName, Object value) {
+ substituteTargetWithCopy();
+ target.addToField(ext, fieldName, value);
+ }
+
+ @Override
+ public void removeFromField(String ext, String fieldName, Object value) {
+ substituteTargetWithCopy();
+ target.removeFromField(ext, fieldName, value);
+ }
+
+ @Override
+ public void clearField(String ext, String fieldName) {
+ substituteTargetWithCopy();
+ target.clearField(ext, fieldName);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addToField(String, Object)
+ */
+ @Override
+ public void addToField(String fqFieldName, Object value) {
+ substituteTargetWithCopy();
+ target.addToField(fqFieldName, value);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#removeFromField(String, Object)
+ */
+ @Override
+ public void removeFromField(String fqFieldName, Object value) {
+ substituteTargetWithCopy();
+ target.removeFromField(fqFieldName, value);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#clearField(String)
+ */
+ @Override
+ public void clearField(String fqFieldName) {
+ substituteTargetWithCopy();
+ target.clearField(fqFieldName);
+ }
+
+ @Override
+ public Set<String> fieldNames() {
+ return target.fieldNames();
+ }
+
+ @Override
+ public Object getFqField(String fqFieldName) {
+ return target.getFqField(fqFieldName);
+ }
+
+ @Override
+ public String getVersion() {
+ return target.getVersion();
+ }
+
+ @Override
+ public void setVersion(String version) {
+ substituteTargetWithCopy();
+ target.setVersion(version);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#getDirty()
+ */
+ @Override
+ public Set<String> getDirty() {
+ return target.getDirty();
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#clearDirty()
+ */
+ @Override
+ public void clearDirty() {
+ substituteTargetWithCopy();
+ target.clearDirty();
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#setFqField(String, Object)
+ */
+ @Override
+ public void setFqField(String fieldName, Object value) {
+ substituteTargetWithCopy();
+ target.setFqField(fieldName, value);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return target.isEmpty();
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#hasMetaExtension(String, String)
+ */
+ @Override
+ public boolean hasMetaExtension(String metaExtensionName,
+ String extensionName) {
+ return target.hasMetaExtension(metaExtensionName, extensionName);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, WikittyExtension)
+ */
+ @Override
+ public void addMetaExtension(WikittyExtension metaExtension,
+ WikittyExtension extension) {
+ substituteTargetWithCopy();
+ target.addMetaExtension(metaExtension, extension);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, String)
+ */
+ @Override
+ public void addMetaExtension(WikittyExtension metaExtension,
+ String extensionFqn) {
+ substituteTargetWithCopy();
+ target.addMetaExtension(metaExtension, extensionFqn);
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyExtension.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtension.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyExtension.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyExtension.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,322 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyExtension implements Serializable {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -3598621577607442972L;
+
+ /** Field name pattern only word character [a-zA-Z_0-9] is accepted */
+ static protected Pattern fieldNamePattern = Pattern.compile("^\\w+$");
+
+ /**
+ * Property change support.
+ *
+ * Warning, this transient field is null after deserialization.
+ */
+ protected transient PropertyChangeSupport propertyChangeSupport;
+
+ /** Name of this extension. */
+ protected String name;
+
+ /**
+ * Name of other extension needed to put this extension to object.
+ *
+ * Warning : Multiples extensions are not supported yet.
+ *
+ * FIXME EC-20100420 multiples extensions need to work
+ */
+ protected String requires;
+
+ /**
+ * use to know version objet, when you change field number, type or other
+ * you must change version number.
+ */
+ protected String version = WikittyUtil.DEFAULT_VERSION;
+
+ /** used to store tag/value used by client side ex: updatedDate=101212 */
+ protected Map<String, String> tagValues = new HashMap<String, String>();
+
+ /**
+ * fields use ordered map, to keep order insertion of field
+ * key: field name
+ * value: field type
+ */
+ protected LinkedHashMap<String, FieldType> fields = new LinkedHashMap<String, FieldType>();
+
+ /**
+ * Default constructor.
+ *
+ * Used by hibernate.
+ */
+ public WikittyExtension() {
+
+ }
+
+ public WikittyExtension(String name) {
+ setName(name);
+ }
+
+ public WikittyExtension(String name, String version,
+ String requires, LinkedHashMap<String, FieldType> fields) {
+ if (version == null) {
+ throw new IllegalArgumentException("Version must not be null");
+ }
+ setName(name);
+ this.version = WikittyUtil.normalizeVersion(version);
+ this.requires = requires;
+ if (fields != null) {
+ for (Map.Entry<String, FieldType> entry : fields.entrySet()) {
+ String fieldName = entry.getKey();
+ FieldType fieldType = entry.getValue();
+ addField(fieldName, fieldType);
+ }
+ }
+ }
+
+ protected PropertyChangeSupport getPropertyChangeSupport() {
+ if (propertyChangeSupport == null) {
+ propertyChangeSupport = new PropertyChangeSupport(this);
+ }
+ return propertyChangeSupport;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
+ }
+
+ public WikittyExtension cloneForUpgrade() {
+ String nextRevision = WikittyUtil.incrementMajorRevision(getVersion());
+
+ LinkedHashMap<String, FieldType> nextFields = null;
+ if (fields != null) {
+ nextFields = new LinkedHashMap<String, FieldType>();
+ for (Map.Entry<String, FieldType> entry : fields.entrySet()) {
+ FieldType type = entry.getValue();
+ FieldType nextType = new FieldType(
+ type.getType(), type.getLowerBound(), type.getUpperBound());
+ Set<String> tagNames = type.getTagNames();
+ if (tagNames != null) {
+ for (String tagName : tagNames) {
+ String tagValue = type.getTagValue(tagName);
+ nextType.addTagValue(tagName, tagValue);
+ }
+ }
+ nextFields.put(entry.getKey(), nextType);
+ }
+ }
+
+ WikittyExtension result = new WikittyExtension(name, nextRevision, requires, nextFields);
+ return result;
+ }
+
+ /**
+ * Compute id for extension name and version in argument.
+ *
+ * @param name extension name
+ * @param version extension version
+ * @return extension string id
+ */
+ static public String computeId(String name, String version) {
+ String result = name + "[" + version + "]";
+ return result;
+ }
+
+ static public String computeName(String id) {
+ int i = id.lastIndexOf("[");
+ String result = id;
+ if (i != -1) {
+ result = id.substring(0, i);
+ }
+ return result;
+ }
+
+ static public String computeVersion(String id) {
+ int b = id.lastIndexOf("[");
+ int e = id.lastIndexOf("]");
+ String result = null;
+ if (b != -1 && e != -1) {
+ result = id.substring(b+1, e);
+ }
+ result = WikittyUtil.normalizeVersion(result);
+ return result;
+ }
+
+ public String getId() {
+ String result = computeId(getName(), getVersion());
+ return result;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set extension name.
+ *
+ * Check for invalid extension name (non alphanumeric characters).
+ *
+ * @param name name
+ */
+ public void setName(String name) {
+
+ // check alphanumeric characters
+ if (name == null) {
+ throw new IllegalArgumentException("Name must not be null");
+ }
+ if (!name.matches("\\w+")) {
+ throw new IllegalArgumentException("Name contains non alphanumeric characters");
+ }
+
+ this.name = name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getRequires() {
+ return requires;
+ }
+
+ public FieldType getFieldType(String fieldName) {
+ return fields.get(fieldName);
+ }
+
+ public Collection<String> getFieldNames() {
+ Collection<String> result = fields.keySet();
+ return result;
+ }
+
+ public void addField(String fieldName, FieldType type) {
+ Matcher matcher = fieldNamePattern.matcher(fieldName);
+ if(matcher.find()) {
+ fields.put(fieldName, type);
+ // TODO EC20100610 null for old value
+ getPropertyChangeSupport().firePropertyChange("fields", null, fields);
+ } else {
+ throw new IllegalArgumentException("For field name [" + fieldName +"], only word character [a-zA-Z_0-9] is accepted");
+ }
+ }
+
+ public void removeField(String fieldName) {
+ fields.remove(fieldName);
+ // TODO EC20100610 null for old value
+ getPropertyChangeSupport().firePropertyChange("fields", null, fields);
+ }
+
+ @Override
+ public int hashCode() {
+ return getId().hashCode();
+ }
+
+ public void addTagValue(String tag, String value) {
+ tagValues.put(tag, value);
+ // TODO EC20100610 null for old value
+ getPropertyChangeSupport().firePropertyChange("tagValues", null, tagValues);
+ }
+
+ public String getTagValue(String tag) {
+ String result = tagValues.get(tag);
+ return result;
+ }
+
+ public Set<String> getTagNames() {
+ return tagValues.keySet();
+ }
+
+ public Map<String, String> getTagValues() {
+ return tagValues;
+ }
+
+ public void setTagValues(Map<String, String> tagValues) {
+ Map<String, String> oldValue = this.tagValues;
+ this.tagValues = tagValues;
+ getPropertyChangeSupport().firePropertyChange("tagValues", oldValue, tagValues);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj instanceof WikittyExtension) {
+ WikittyExtension other = (WikittyExtension)obj;
+ result = this.getId().equals(other.getId());
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return getId();
+ }
+
+ public String toDefinition() {
+ String result = "Extension " + getId();
+ result += WikittyUtil.tagValuesToString(tagValues);
+ result += " {\n";
+ for (String fieldName : fields.keySet()) {
+ result += fields.get(fieldName).toDefinition(fieldName) + "\n";
+ }
+ result += "}";
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImpl.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,921 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.math.BigDecimal;
+import java.util.AbstractList;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.lang.ObjectUtils;
+import org.nuiton.util.ObjectUtil;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ * Wikitty implementation.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyImpl implements Wikitty {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 4910886672760691052L;
+
+ /** Technical id for this wikitty object. id must be never null. */
+ protected String id;
+
+ /** Current version of this wikitty object. */
+ protected String version = WikittyUtil.DEFAULT_VERSION;
+
+ /** If not null, date of deletion, if date this object is marked as deleted. */
+ protected Date deleteDate = null;
+
+ /**
+ * Used to add property change support to wikitty object.
+ *
+ * Warning, this field can be null after deserialization.
+ */
+ private transient PropertyChangeSupport propertyChange;
+
+ /**
+ * key: field name prefixed by extension name (dot separator)
+ * value: value of field
+ */
+ protected HashMap<String, Object> fieldValue = new HashMap<String, Object>();
+
+ /**
+ * all field name currently modified (field name = extension . fieldname)
+ */
+ protected Set<String> fieldDirty = new HashSet<String>();
+
+ /**
+ * Map is LinkedHashMap to maintains order like user want
+ * key: extension name
+ * value: extension definition
+ */
+ protected Map<String, WikittyExtension> extensions =
+ new LinkedHashMap<String, WikittyExtension>();
+
+
+ public WikittyImpl() {
+ this(null);
+ }
+
+ public WikittyImpl(String id) {
+ if (id == null) {
+ this.id = WikittyUtil.genUID();
+ } else {
+ this.id = id;
+ }
+ }
+
+ /**
+ * Replace all field of current wikitty with field found in w.
+ * This two wikitty must have same id.
+ *
+ * This method is used to clone Wikitty too
+ *
+ * @param w wikitty where we take information
+ */
+ @Override
+ public void replace(Wikitty w) {
+ // il faut que ce soit le meme objet mais pas la meme instance
+ // car ca ne sert a rien de copier un objet sur lui meme
+ if (this == w) {
+ return;
+ }
+ if (this.getId().equals(w.getId())) {
+ this.extensions.clear();
+ this.fieldValue.clear();
+ for (WikittyExtension ext : w.getExtensions()) {
+ String extName = ext.getName();
+ this.extensions.put(extName, ext);
+ for(String fieldName : ext.getFieldNames()) {
+ Object value = w.getFieldAsObject(extName, fieldName);
+ if (value != null) {
+ // seul les collections sont a cloner, sinon ce ne sont
+ // que des types primitifs immutable
+ if (value instanceof Collection && value instanceof Cloneable) {
+ try {
+ value = ObjectUtil.clone((Cloneable) value);
+ } catch (CloneNotSupportedException eee) {
+ throw new WikittyException(String.format(
+ "Can't copy field %s.%s",
+ ext.getName(), fieldName), eee);
+ }
+ }
+ this.setField(extName, fieldName, value);
+ }
+ }
+ }
+
+ // we must change version after field value copy, because
+ // copy increment version because it use setField method
+ this.version = w.getVersion();
+ this.deleteDate = w.getDeleteDate();
+
+ clearDirty();
+ } else {
+ throw new IllegalArgumentException("Wikitty in argument don't have same id");
+ }
+ }
+
+ /**
+ * Always call this method because field is transient.
+ *
+ * @return
+ */
+ protected PropertyChangeSupport getPropertyChangeSupport() {
+ if (propertyChange == null) {
+ propertyChange = new PropertyChangeSupport(this);
+ }
+ return propertyChange;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#addPropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ @Override
+ public synchronized void addPropertyChangeListener(
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(listener);
+ }
+
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#removePropertyChangeListener(java.beans.PropertyChangeListener)
+ */
+ @Override
+ public synchronized void removePropertyChangeListener(
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(listener);
+ }
+
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+ */
+ @Override
+ public synchronized void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
+ }
+
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+ */
+ @Override
+ public synchronized void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ getPropertyChangeSupport().removePropertyChangeListener(propertyName, listener);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getId()
+ */
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#isDeleted()
+ */
+ @Override
+ public boolean isDeleted() {
+ boolean result = deleteDate != null;
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getDeleteDate()
+ */
+ @Override
+ public Date getDeleteDate() {
+ return deleteDate;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#setDeleteDate(java.util.Date)
+ */
+ @Override
+ public void setDeleteDate(Date delete) {
+ this.deleteDate = delete;
+ }
+
+ /**
+ * Mark field as dirty.
+ *
+ * @param ext
+ * @param fieldName
+ */
+ protected void setFieldDirty(String ext, String fieldName,
+ Object oldValue, Object newValue) {
+ String key = ext + "." + fieldName;
+ fieldDirty.add(key);
+ version = WikittyUtil.incrementMinorRevision(version);
+ getPropertyChangeSupport().firePropertyChange(key, oldValue, newValue);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#addExtension(org.nuiton.wikitty.WikittyExtension)
+ */
+ @Override
+ public void addExtension(WikittyExtension ext) {
+ String required = ext.getRequires();
+ if (required != null && !required.isEmpty() &&
+ !extensions.containsKey(required)) {
+ throw new WikittyException(String.format(
+ "You try to add extension '%s' that" +
+ " required not available extension '%s' in this wikitty",
+ ext.getName(), required));
+ }
+ extensions.put(ext.name, ext);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#hasMetaExtension(String, String)
+ */
+ @Override
+ public boolean hasMetaExtension(String metaExtensionName,
+ String extensionName) {
+ String metaExtensionFQName = WikittyUtil.getFQMetaExtensionName(
+ metaExtensionName,
+ extensionName);
+ boolean hasMetaExtension = extensions.containsKey(metaExtensionFQName);
+ return hasMetaExtension;
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, WikittyExtension)
+ */
+ @Override
+ public void addMetaExtension(WikittyExtension metaExtension,
+ WikittyExtension extension) {
+ addMetaExtension(metaExtension, extension.getName());
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, String)
+ */
+ @Override
+ public void addMetaExtension(WikittyExtension metaExtension, String extensionName) {
+ if (hasExtension(extensionName)) {
+ String metaExtensionFQName = WikittyUtil.getFQMetaExtensionName(
+ metaExtension.getName(),
+ extensionName);
+ extensions.put(metaExtensionFQName, metaExtension);
+ } else {
+ throw new IllegalArgumentException("this wikitty doesn't have an extension named " + extensionName);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#addExtension(java.util.List)
+ */
+ @Override
+ public void addExtension(List<WikittyExtension> exts) {
+ for (WikittyExtension ext : exts) {
+ addExtension(ext);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#hasExtension(java.lang.String)
+ */
+ @Override
+ public boolean hasExtension(String extName) {
+ return extensions.containsKey(extName);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#hasField(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean hasField(String extName, String fieldName) {
+ boolean result = false;
+ WikittyExtension ext = extensions.get(extName);
+ if (ext != null) {
+ result = ext.getFieldType(fieldName) != null;
+ }
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getExtension(java.lang.String)
+ */
+ @Override
+ public WikittyExtension getExtension(String ext) {
+ WikittyExtension result = extensions.get(ext);
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getExtensionNames()
+ */
+ @Override
+ public Collection<String> getExtensionNames() {
+ Collection<String> result = extensions.keySet();
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getExtensions()
+ */
+ @Override
+ public Collection<WikittyExtension> getExtensions() {
+ Collection<WikittyExtension> result = extensions.values();
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getExtensionDependencies(java.lang.String, boolean)
+ */
+ @Override
+ public Collection<WikittyExtension> getExtensionDependencies(String ext, boolean recursively) {
+ Collection<WikittyExtension> result = new HashSet<WikittyExtension>();
+ Collection<WikittyExtension> all = extensions.values();
+ for (WikittyExtension dependency : all) {
+ String requires = dependency.getRequires();
+ if(requires != null && !requires.isEmpty() && requires.equals(ext)) {
+ result.add(dependency);
+ if(recursively) {
+ String dependencyName = dependency.getName();
+ Collection<WikittyExtension> dependencies = getExtensionDependencies(dependencyName, recursively);
+ result.addAll(dependencies);
+ }
+ }
+ }
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldType(java.lang.String)
+ */
+ @Override
+ public FieldType getFieldType(String fqfieldName) {
+ try {
+ String[] field = fqfieldName.split("\\.");
+ WikittyExtension ext = getExtension(field[0]);
+ if (ext == null) {
+ throw new WikittyException(String.format(
+ "Extension '%s' doesn't exists on wikitty '%s'", field[0], id));
+ } else {
+ String fieldName = field[1];
+ int crochet = fieldName.indexOf("[");
+ if (crochet != -1) {
+ fieldName = fieldName.substring(0, crochet);
+ }
+ FieldType result = ext.getFieldType(fieldName);
+ if (result == null) {
+ throw new WikittyException(String.format(
+ "field '%s' doesn't exists on extension '%s'", fieldName, field[0]));
+
+ }
+ return result;
+ }
+ } catch (Exception eee) {
+ throw new WikittyException(
+ String.format("Field %s is not a fully qualified field name", fqfieldName),
+ eee
+ );
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#setField(java.lang.String, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void setField(String ext, String fieldName, Object value) {
+ if (! hasField(ext, fieldName)) {
+ String def = "";
+ for ( WikittyExtension extension : extensions.values() ) {
+ def += extension.toDefinition() + "\n";
+ }
+ throw new WikittyException(String.format(
+ "field '%s' is not valid, extensions definition : %s", ext + "." + fieldName, def));
+ }
+ String key = ext + "." + fieldName;
+
+ // take old value if needed
+ Object oldValue = null;
+ if (getPropertyChangeSupport().hasListeners(key)) {
+ oldValue = fieldValue.get(key);
+ }
+
+ // put new value
+ FieldType fieldType = getExtension(ext).getFieldType(fieldName);
+ Object validValue = fieldType.getValidValue(value);
+ fieldValue.put(key, validValue);
+
+ // mark field dirty and call listener
+ setFieldDirty(ext, fieldName, oldValue, validValue);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsObject(java.lang.String, java.lang.String)
+ */
+ @Override
+ public Object getFieldAsObject(String ext, String fieldName) {
+ if (!hasField(ext, fieldName)) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid field",
+ ext + "." + fieldName));
+ }
+ String key = ext + "." + fieldName;
+ Object result = fieldValue.get(key);
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsBoolean(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean getFieldAsBoolean(String ext, String fieldName) {
+ Object value = getFieldAsObject(ext, fieldName);
+ try {
+ boolean result = WikittyUtil.toBoolean(value);
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid boolean",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsBigDecimal(java.lang.String, java.lang.String)
+ */
+ @Override
+ public BigDecimal getFieldAsBigDecimal(String ext, String fieldName) {
+ Object value = getFieldAsObject(ext, fieldName);
+ try {
+ BigDecimal result = WikittyUtil.toBigDecimal(value);
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid numeric",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsInt(java.lang.String, java.lang.String)
+ */
+ @Override
+ public int getFieldAsInt(String ext, String fieldName) {
+ try {
+ BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
+ int result = value.intValue();
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid int",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsLong(java.lang.String, java.lang.String)
+ */
+ @Override
+ public long getFieldAsLong(String ext, String fieldName) {
+ try {
+ BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
+ long result = value.longValue();
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid int",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsFloat(java.lang.String, java.lang.String)
+ */
+ @Override
+ public float getFieldAsFloat(String ext, String fieldName) {
+ try {
+ BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
+ float result = value.floatValue();
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid float",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsDouble(java.lang.String, java.lang.String)
+ */
+ @Override
+ public double getFieldAsDouble(String ext, String fieldName) {
+ try {
+ BigDecimal value = getFieldAsBigDecimal(ext, fieldName);
+ double result = value.doubleValue();
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid float",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsString(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getFieldAsString(String ext, String fieldName) {
+ Object value = getFieldAsObject(ext, fieldName);
+ try {
+ String result = WikittyUtil.toString(value);
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid String",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsDate(java.lang.String, java.lang.String)
+ */
+ @Override
+ public Date getFieldAsDate(String ext, String fieldName) {
+ Object value = getFieldAsObject(ext, fieldName);
+ try {
+ Date result = WikittyUtil.toDate(value);
+ return result;
+ } catch (WikittyException eee) {
+ throw new WikittyException(String.format(
+ "field '%s' is not a valid Date",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsWikitty(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getFieldAsWikitty(String ext, String fieldName) {
+ Object value = getFieldAsObject(ext, fieldName);
+ String result = WikittyUtil.toWikitty(value);
+ return result;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsList(java.lang.String, java.lang.String, java.lang.Class)
+ */
+ @Override
+ public <E> List<E> getFieldAsList(String ext, String fieldName, final Class<E> clazz) {
+ try {
+ final Collection<E> collection = (Collection<E>) getFieldAsObject(ext, fieldName);
+ if (collection != null) {
+ // return unmodiable collection that check type of element
+ return new AbstractList<E>() {
+ List<E> contained = new ArrayList<E>(collection);
+ @Override public E get(int index) {
+ return WikittyUtil.cast( contained.get(index), clazz );
+ }
+ @Override public int size() {
+ return contained.size();
+ }
+ };
+ }
+ return null;
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't get value to field '%s'",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFieldAsSet(java.lang.String, java.lang.String, java.lang.Class)
+ */
+ @Override
+ public <E> Set<E> getFieldAsSet(String ext, String fieldName, final Class<E> clazz) {
+ try {
+ final Set<E> result = (Set<E>) getFieldAsObject(ext, fieldName);
+ if (result != null) {
+ // return unmodifable Set
+ return new AbstractSet<E>() {
+ Set<E> contained = result;
+ @Override public int size() {
+ return contained.size();
+ }
+ @Override
+ public Iterator<E> iterator() {
+ return new Iterator<E>() {
+ Iterator containedIterator = contained.iterator();
+ public boolean hasNext() {
+ return containedIterator.hasNext();
+ }
+
+ public E next() {
+ Object o = containedIterator.next();
+ return WikittyUtil.cast(o, clazz);
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("Not supported operation");
+ }
+ };
+
+ }
+ };
+ }
+ return result;
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't get value to field '%s'",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#addToField(java.lang.String, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void addToField(String ext, String fieldName, Object value) {
+ try {
+ FieldType fieldType = getExtension(ext).getFieldType(fieldName);
+ Collection col = (Collection) getFieldAsObject(ext, fieldName);
+ if (col == null) {
+ if (fieldType.isUnique()) {
+ col = new HashSet();
+ } else {
+ col = new ArrayList();
+ }
+ col.add(value);
+ setField(ext, fieldName, col);
+ // no call dirty, because already done in setField
+ } else {
+ // check upper bound only if col exists,
+ // because ask upper bound == 0 is ridiculous
+
+ if (fieldType.isUnique()) {
+ if (!col.contains(value)) {
+ // only add if not already in collection (unique)
+ if (col.size() + 1 > fieldType.getUpperBound()) {
+ // if upper bound reached, throw an exception
+ throw new WikittyException(String.format(
+ "Can't add value for field '%s', upper bound is reached",
+ ext + "." + fieldName));
+ }
+ col.add(value);
+ setFieldDirty(ext, fieldName, null, col);
+ }
+ } else {
+ if (col.size() + 1 > fieldType.getUpperBound()) {
+ throw new WikittyException(String.format(
+ "Can't add value for field '%s', upper bound is reached",
+ ext + "." + fieldName));
+ }
+ col.add(value);
+ setFieldDirty(ext, fieldName, null, col);
+ }
+ }
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't add value to field '%s'",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#removeFromField(java.lang.String, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void removeFromField(String ext, String fieldName, Object value) {
+ try {
+ Collection col = (Collection) getFieldAsObject(ext, fieldName);
+ if (col != null) {
+ FieldType type = getExtension(ext).getFieldType(fieldName);
+ if (col.contains(value)) {
+ if (col.size() - 1 < type.getLowerBound()) {
+ throw new WikittyException(String.format(
+ "Can't remove value for field '%s', lower bound is reached",
+ ext + "." + fieldName));
+ } else {
+ if (col.remove(value)) {
+ // field is dirty only if remove is done
+ setFieldDirty(ext, fieldName, null, col);
+ }
+ }
+ }
+ }
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't remove value for field '%s'",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#clearField(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void clearField(String ext, String fieldName) {
+ FieldType type = getExtension(ext).getFieldType(fieldName);
+ if (type.getLowerBound() > 0) {
+ throw new WikittyException(String.format(
+ "Can't clear values for field '%s', lower bound is > 0",
+ ext + "." + fieldName));
+ }
+ try {
+ Collection col = (Collection) getFieldAsObject(ext, fieldName);
+ if (col != null) {
+ col.clear();
+ setFieldDirty(ext, fieldName, null, col);
+ }
+ } catch (Exception eee) {
+ throw new WikittyException(String.format(
+ "Can't clear value for field '%s'",
+ ext + "." + fieldName), eee);
+ }
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#addToField(String, Object)
+ */
+ @Override
+ public void addToField(String fqFieldName, Object value) {
+ String[] extAndField = fqFieldName.split("\\.");
+ addToField(extAndField[0], extAndField[1], value);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#removeFromField(String, Object)
+ */
+ @Override
+ public void removeFromField(String fqFieldName, Object value) {
+ String[] extAndField = fqFieldName.split("\\.");
+ removeFromField(extAndField[0], extAndField[1], value);
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#clearField(String)
+ */
+ @Override
+ public void clearField(String fqFieldName) {
+ String[] extAndField = fqFieldName.split("\\.");
+ clearField(extAndField[0], extAndField[1]);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj instanceof Wikitty) {
+ Wikitty other = (Wikitty) obj;
+ result = id.equals(other.getId());
+ }
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ if (id == null) {
+ return super.hashCode();
+ } else {
+ return id.hashCode();
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#fieldNames()
+ */
+ @Override
+ public Set<String> fieldNames() {
+ return fieldValue.keySet();
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getFqField(java.lang.String)
+ */
+ @Override
+ public Object getFqField(String fqFieldName) {
+ return fieldValue.get(fqFieldName);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#getVersion()
+ */
+ @Override
+ public String getVersion() {
+ return version;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#setVersion(java.lang.String)
+ */
+ @Override
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * @see org.nuiton.wikitty.Wikitty#getDirty()
+ */
+ public Set<String> getDirty() {
+ return fieldDirty;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#clearDirty()
+ */
+ @Override
+ public void clearDirty() {
+ fieldDirty.clear();
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#setFqField(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void setFqField(String fieldName, Object value) {
+ FieldType fieldType = getFieldType(fieldName);
+ Object validValue = fieldType.getValidValue(value);
+ fieldValue.put(fieldName, validValue);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.Wikitty#isEmpty()
+ */
+ @Override
+ public boolean isEmpty() {
+ return fieldValue.isEmpty();
+ }
+
+ @Override
+ public String toString() {
+ boolean cr = true;
+ String str = "[" + getId() + ":" + getVersion() + "] {";
+ for ( String extName : getExtensionNames() ) {
+ WikittyExtension ext = getExtension(extName);
+ str += (cr ? "\n" : "") + "\t<" + extName + ">\n";
+ cr = false;
+ for ( String fieldName : ext.getFieldNames() ) {
+ str += "\t\t" + fieldName + " = " + getFieldAsString(extName, fieldName) + "\n";
+ }
+ }
+ str += "}";
+ return str;
+ }
+
+ /**
+ * Clone is deep for extension and values
+ * @return
+ * @throws CloneNotSupportedException
+ */
+ @Override
+ public WikittyImpl clone() throws CloneNotSupportedException {
+ WikittyImpl result = new WikittyImpl(this.id);
+ result.replace(this);
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyMetaExtensionUtil.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyMetaExtensionUtil.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyMetaExtensionUtil.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyMetaExtensionUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,82 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.entities;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyMetaExtensionUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyMetaExtensionUtil.class);
+
+ private static String SEPARATOR = ":";
+
+ /**
+ * generate id for meta extension and extension
+ * @return a wikitty id
+ */
+ static public String generateId(
+ String metaExtensionName, String extensionName) {
+ return String.format("%s%s%s", metaExtensionName, SEPARATOR, extensionName);
+ }
+
+ /**
+ * Extract meta extension name from wikittyId. If Id is not meta extension
+ * id, return null
+ */
+ static public String extractMetaName(String id) {
+ String[] ids = id.split(SEPARATOR);
+ if (ids.length == 2) {
+ return ids[0];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Extract extension name from wikittyId. If Id is not meta extension
+ * id, return null
+ */
+ static public String extractExtName(String id) {
+ String[] ids = id.split(SEPARATOR);
+ if (ids.length == 2) {
+ return ids[1];
+ } else {
+ return null;
+ }
+ }
+
+}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/And.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/And.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/And.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,116 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * And operator is used to build conjunctive restriction for request on content.
- * It take at least 2 args. <br>
- * <br>
- * For example, use:
- * <ul>
- * <li>RestrictionHelper.and( restriction1, restriction2 )</li>
- * <li>RestrictionHelper.and( restriction1, restriction2, restriction3 )</li>
- * <li>RestrictionHelper.and(
- * my_JavaUtilList_Of_Restriction_Witch_Size_Is_Upper_Than2 )</li>
- * </ul>
- */
-public class And extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected List<Restriction> restrictions;
-
- /**
- * Default constructor
- */
- public And() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param restrictions
- */
- public And(List<Restriction> restrictions) {
- this();
- this.restrictions = restrictions;
- }
-
- /**
- * Return restrictions
- *
- * @return
- */
- public List<Restriction> getRestrictions() {
- return restrictions;
- }
-
- /**
- * Set a value to parameter restrictions.
- *
- * @param restrictions
- */
- public void setRestrictions(List<Restriction> restrictions) {
- this.restrictions = restrictions;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof And)) {
- return false;
- }
-
- final And and = (And) other;
-
- if ((restrictions == null && and.getRestrictions() != null)
- || (restrictions != null && !restrictions.equals(and
- .getRestrictions()))) {
- return false;
- }
-
- return true;
- }
-
- public int hashCode() {
- // equals use restrictions but unable to create hashCode from
- // restrictions because it is not
- // constant through time using arbitrary constant hash-code
- return And.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/AssociatedRestriction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/AssociatedRestriction.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/AssociatedRestriction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,57 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-public class AssociatedRestriction extends Restriction {
-
- private static final long serialVersionUID = 1L;
-
- private Restriction associatedRestriction;
- private Restriction embededRestriction;
- private Element element;
-
- public AssociatedRestriction(Restriction parentRestriction, Restriction embededRestriction, Element element) {
- this.associatedRestriction = parentRestriction;
- this.embededRestriction = embededRestriction;
- this.name = RestrictionName.ASSOCIATED;
- this.element = element;
- }
-
- public Restriction getParentRestrictionDto() {
- return associatedRestriction;
- }
-
- public Element getElement() {
- return element;
- }
-
- public void setElement(Element element) {
- this.element = element;
- }
-
- public Restriction getRestriction() {
- return embededRestriction;
- }
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Between.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Between.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Between.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,156 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Between operator is used to build restriction containing "min < element
- * < max" where element could be a Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.between( myElement , "15.5" , "22.5" )
- */
-public class Between extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected Element element;
- protected String min;
- protected String max;
-
- /**
- * Default constructor
- */
- public Between() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param element
- * @param min
- * @param max
- */
- public Between(Element element, String min, String max) {
- this.element = element;
- this.min = min;
- this.max = max;
- }
-
- /**
- * Return element
- *
- * @return
- */
- public Element getElement() {
- return element;
- }
-
- /**
- * Set a value to parameter element.
- *
- * @param element
- */
- public void setElement(Element element) {
- this.element = element;
- }
-
- /**
- * Return min
- *
- * @return
- */
- public String getMin() {
- return min;
- }
-
- /**
- * Set a value to parameter min.
- *
- * @param min
- */
- public void setMin(String min) {
- this.min = min;
- }
-
- /**
- * Return max
- *
- * @return
- */
- public String getMax() {
- return max;
- }
-
- /**
- * Set a value to parameter max.
- *
- * @param max
- */
- public void setMax(String max) {
- this.max = max;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Between)) {
- return false;
- }
-
- final Between between = (Between) other;
-
- if ((element == null && between.getElement() != null)
- || (element != null && !element.equals(between.getElement()))) {
- return false;
- }
- if ((min == null && between.getMin() != null)
- || (min != null && !min.equals(between.getMin()))) {
- return false;
- }
- if ((max == null && between.getMax() != null)
- || (max != null && !max.equals(between.getMax()))) {
- return false;
- }
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Between.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/BinaryOperator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/BinaryOperator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/BinaryOperator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,130 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * This class is an abstract class that's used to factor each operator that
- * handle two parameters (=, !=, <, <=, >, >=, end, begin).
- */
-public class BinaryOperator extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected Element element;
- protected String value;
-
- /**
- * Default constructor
- */
- public BinaryOperator() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param element
- * @param value
- */
- public BinaryOperator(Element element, String value) {
- this.element = element;
- this.value = value;
- }
-
- /**
- * Return element
- *
- * @return
- */
- public Element getElement() {
- return element;
- }
-
- /**
- * Set a value to parameter element.
- *
- * @param element
- */
- public void setElement(Element element) {
- this.element = element;
- }
-
- /**
- * Return value
- *
- * @return
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Set a value to parameter value.
- *
- * @param value
- */
- public void setValue(String value) {
- this.value = value;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof BinaryOperator)) {
- return false;
- }
-
- final BinaryOperator binaryOperator = (BinaryOperator) other;
-
- if ((element == null && binaryOperator.getElement() != null)
- || (element != null && !element.equals(binaryOperator
- .getElement()))) {
- return false;
- }
- if ((value == null && binaryOperator.getValue() != null)
- || (value != null && !value.equals(binaryOperator.getValue()))) {
- return false;
- }
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return BinaryOperator.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Contains.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Contains.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Contains.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,139 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * Contains operator is used to build restriction containing "(element like
- * *value1 or element like value1*) and (element like *value2 or element like
- * value2*)" where element could be a String, a multimedia, a text or an xhtml
- * <br>
- * <br>
- * For example, use:
- * <ul>
- * <li>RestrictionHelper.contains( myElement , "value1" )</li>
- * <li>RestrictionHelper.contains( myElement , "value1", "value2", ... )</li>
- * <li>RestrictionHelper.contains( myElement ,
- * a_list_containing_at_least_one_string )</li>
- * </ul>
- */
-public class Contains extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected Element element;
- protected List<String> value;
-
- /**
- * Default constructor
- */
- public Contains() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param element
- * @param value
- */
- public Contains(Element element, List<String> value) {
- this.element = element;
- this.value = value;
- }
-
- /**
- * Return element
- *
- * @return
- */
- public Element getElement() {
- return element;
- }
-
- /**
- * Set a value to parameter element.
- *
- * @param element
- */
- public void setElement(Element element) {
- this.element = element;
- }
-
- /**
- * Return value
- *
- * @return
- */
- public List<String> getValue() {
- return value;
- }
-
- /**
- * Set a value to parameter value.
- *
- * @param value
- */
- public void setValue(List<String> value) {
- this.value = value;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Contains)) {
- return false;
- }
-
- final Contains contains = (Contains) other;
-
- if ((element == null && contains.getElement() != null)
- || (element != null && !element.equals(contains.getElement())))
- return false;
- if ((value == null && contains.getValue() != null)
- || (value != null && !value.equals(contains.getValue())))
- return false;
-
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Contains.class.hashCode();
- }
-
-}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Criteria.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/Criteria.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Criteria.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Criteria.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,246 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search;
+
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.nuiton.wikitty.search.operators.Restriction;
+
+/**
+ * Criteria represent the search on the wikitty with restriction on field and
+ * informations on facet, pagination and sorting.
+ *<p>
+ * For search multiple extension use ALL_EXTENSIONS as extension name and
+ * specify field type.
+ * <p>
+ * Example : Criteria.ALL_EXTENSIONS + Criteria.SEPARATOR + <fieldName> + Criteria.SEPARATOR + FieldType.TYPE.<fieldType>
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class Criteria implements Serializable {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 2590223960861630283L;
+
+ /** Use to not limit result. */
+ static final public int ALL_ELEMENTS = -1;
+
+ /** Search on all extension. */
+ static final public String ALL_EXTENSIONS = "*";
+
+ /** Search on all values. */
+ static final public String ALL_VALUES = "*";
+
+ /** Separator between extension name, field name and type. */
+ static final public String SEPARATOR = ".";
+
+ /**
+ * Criteria can have name this help for presentation and is very
+ * useful for facet created by criteria.
+ */
+ protected String name;
+
+ /** All restriction on fields. */
+ protected Restriction restriction;
+
+ /** First index to get result. */
+ protected int firstIndex = 0;
+ /** Last index to get result. */
+ protected int endIndex = ALL_ELEMENTS;
+
+ /** Facet on criteria. */
+ protected List<Criteria> facetCriteria;
+ /** Facet on field. */
+ protected List<String> facetField;
+
+ /** Sort ascending on fields. */
+ protected List<String> sortAscending;
+ /** Sort descending on fields. */
+ protected List<String> sortDescending;
+
+ /**
+ * Default constructor.
+ */
+ public Criteria() {
+ }
+
+ /**
+ * Create named criteria.
+ *
+ * @param name criteria name
+ */
+ public Criteria(String name) {
+ this();
+ this.name = name;
+ }
+
+ /**
+ * Deserialize xml to criteria.
+ *
+ * @param xml xml to deserialize
+ * @return criteria criteria
+ */
+ public static Criteria fromXML(String xml) {
+ InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
+ XMLDecoder decoder = new XMLDecoder(inputStream);
+ Criteria criteria = (Criteria) decoder.readObject();
+ return criteria;
+ }
+
+ /**
+ * Serialize criteria to xml.
+ *
+ * @param criteria criteria to serialize
+ * @return xml string
+ */
+ public static String toXML(Criteria criteria) {
+ OutputStream outputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(outputStream);
+ encoder.writeObject(criteria);
+ encoder.close();
+ String result = outputStream.toString();
+ return result;
+ }
+
+ public Restriction getRestriction() {
+ return restriction;
+ }
+
+ public void setRestriction(Restriction restriction) {
+ this.restriction = restriction;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getFirstIndex() {
+ return firstIndex;
+ }
+
+ public Criteria setFirstIndex(int firstIndex) {
+ this.firstIndex = firstIndex;
+ return this;
+ }
+
+ public int getEndIndex() {
+ return endIndex;
+ }
+
+ public Criteria setEndIndex(int endIndex) {
+ this.endIndex = endIndex;
+ return this;
+ }
+
+ public List<Criteria> getFacetCriteria() {
+ return facetCriteria;
+ }
+
+ public Criteria addFacetCriteria(Criteria criteria) {
+ if (facetCriteria == null) {
+ facetCriteria = new ArrayList<Criteria>();
+ }
+ facetCriteria.add(criteria);
+ return this;
+ }
+
+ public Criteria setFacetCriteria(Criteria[] facetCriteria) {
+ this.facetCriteria = Arrays.asList(facetCriteria);
+ return this;
+ }
+
+ public List<String> getFacetField() {
+ return facetField;
+ }
+
+ public Criteria addFacetField(String field) {
+ if (facetField == null) {
+ facetField = new ArrayList<String>();
+ }
+ facetField.add(field);
+ return this;
+ }
+
+ public Criteria setFacetField(String[] facetField) {
+ this.facetField = Arrays.asList(facetField);
+ return this;
+ }
+
+ public List<String> getSortAscending() {
+ return sortAscending;
+ }
+
+ public Criteria addSortAscending(String field) {
+ if(sortAscending == null) {
+ sortAscending = new ArrayList<String>();
+ }
+ sortAscending.add(field);
+ return this;
+ }
+
+ public Criteria setSortAscending(String[] sortAscending) {
+ this.sortAscending = Arrays.asList(sortAscending);
+ return this;
+ }
+
+ public List<String> getSortDescending() {
+ return sortDescending;
+ }
+
+ public Criteria addSortDescending(String field) {
+ if(sortDescending == null) {
+ sortDescending = new ArrayList<String>();
+ }
+ sortDescending.add(field);
+ return this;
+ }
+
+ public Criteria setSortDescending(String[] sortDescending) {
+ this.sortDescending = Arrays.asList(sortDescending);
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return toXML(this);
+ }
+}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Element.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Element.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Element.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,66 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Search on field.
- *
- * @author ruchaud
- */
-public class Element implements Serializable {
-
- /** Represent a element on extension */
- public static String ELT_EXTENSION = "elt_extension";
-
- /** Represent a element on id */
- public static String ELT_ID = "elt_id";
-
- /** Represent type to search an element */
- public static enum ElementType {NUMERIC, STRING, WIKITTY, BOOLEAN, DATE};
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected String name;
-
- public Element() {
- super();
- }
-
- public Element(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/EndsWith.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/EndsWith.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/EndsWith.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,74 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * EndsWith operator is used to build restriction containing "element like
- * *value" where element could be a String, a multimedia, a text or an xhtml
- * <br>
- * <br>
- * For example, use: RestrictionHelper.end( myElement , "value" )
- */
-public class EndsWith extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public EndsWith() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof EndsWith)) {
- return false;
- }
-
- final EndsWith endsWith = (EndsWith) other;
-
- return super.equals(endsWith);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return EndsWith.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Equals.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Equals.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Equals.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,74 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Equals operator is used to build restriction containing "element == value"
- * where element could be an Id, a String, a multimedia, a closed list, an
- * Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.eq( myElement , "REF1234567890" )
- */
-public class Equals extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public Equals() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Equals)) {
- return false;
- }
-
- final Equals equals = (Equals) other;
-
- return super.equals(equals);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Equals.class.hashCode();
- }
-
-}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopic.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/FacetTopic.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopic.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopic.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class FacetTopic implements Serializable {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 1408493244549775810L;
+
+ protected String facetName;
+
+ protected String topicName;
+
+ protected int count;
+
+ public FacetTopic(String facetName, String topicName, int count) {
+ this.facetName = facetName;
+ this.topicName = topicName;
+ this.count = count;
+ }
+
+ public String getFacetName() {
+ return facetName;
+ }
+
+ public String getTopicName() {
+ return topicName;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Greater.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Greater.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Greater.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,74 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Greater operator is used to build restriction containing "element > value"
- * where element could be a Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.less( myElement ,
- * RestrictionHelper.DATE_FORMAT.format(new Date()) )
- */
-public class Greater extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public Greater() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Greater)) {
- return false;
- }
-
- final Greater greater = (Greater) other;
-
- return super.equals(greater);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Greater.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/GreaterOrEqual.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/GreaterOrEqual.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/GreaterOrEqual.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,74 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * GreatOrEqual operator is used to build restriction containing "element >=
- * value" where element could be a Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.greatEq( myElement ,
- * RestrictionHelper.DATE_FORMAT.format(new Date()) )
- */
-public class GreaterOrEqual extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public GreaterOrEqual() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof GreaterOrEqual)) {
- return false;
- }
-
- final GreaterOrEqual greaterOrEqual = (GreaterOrEqual) other;
-
- return super.equals(greaterOrEqual);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return GreaterOrEqual.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/In.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/In.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/In.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,141 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * Contains operator is used to build restriction containing "(element like
- * *value1 or element like value1*) and (element like *value2 or element like
- * value2*)" where element could be a String, a multimedia, a text or an xhtml
- * <br>
- * <br>
- * For example, use:
- * <ul>
- * <li>RestrictionHelper.contains( myElement , "value1" )</li>
- * <li>RestrictionHelper.contains( myElement , "value1", "value2", ... )</li>
- * <li>RestrictionHelper.contains( myElement ,
- * a_list_containing_at_least_one_string )</li>
- * </ul>
- */
-public class In extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected Element element;
- protected List<String> value;
-
- /**
- * Default constructor
- */
- public In() {
- super();
- name = RestrictionName.IN;
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param element
- * @param value
- */
- public In(Element element, List<String> value) {
- this.element = element;
- this.value = value;
- name = RestrictionName.IN;
- }
-
- /**
- * Return element
- *
- * @return
- */
- public Element getElement() {
- return element;
- }
-
- /**
- * Set a value to parameter element.
- *
- * @param element
- */
- public void setElement(Element element) {
- this.element = element;
- }
-
- /**
- * Return value
- *
- * @return
- */
- public List<String> getValue() {
- return value;
- }
-
- /**
- * Set a value to parameter value.
- *
- * @param value
- */
- public void setValue(List<String> value) {
- this.value = value;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param value
- * Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof In)) {
- return false;
- }
-
- final In contains = (In) other;
-
- if ((element == null && contains.getElement() != null)
- || (element != null && !element.equals(contains.getElement())))
- return false;
- if ((value == null && contains.getValue() != null)
- || (value != null && !value.equals(contains.getValue())))
- return false;
-
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return In.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Keyword.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Keyword.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Keyword.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,53 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-/**
- * Search keyword in all wikitty.
- *
- * @author ruchaud
- */
-public class Keyword extends Restriction {
-
- private static final long serialVersionUID = 1L;
-
- protected String value;
-
- public Keyword() {
- }
-
- public Keyword(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Less.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Less.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Less.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,73 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Less operator is used to build restriction containing "element < value"
- * where element could be a Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.less( myElement ,
- * RestrictionHelper.DATE_FORMAT.format(new Date()) )
- */
-public class Less extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public Less() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Less)) {
- return false;
- }
-
- final Less less = (Less) other;
-
- return super.equals(less);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Less.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/LessOrEqual.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/LessOrEqual.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/LessOrEqual.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,73 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * LessOrEqual operator is used to build restriction containing "element <=
- * value" where element could be a Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.lessEq( myElement ,
- * RestrictionHelper.DATE_FORMAT.format(new Date()) )
- */
-public class LessOrEqual extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public LessOrEqual() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof LessOrEqual)) {
- return false;
- }
-
- final LessOrEqual lessOrEqual = (LessOrEqual) other;
-
- return super.equals(lessOrEqual);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return LessOrEqual.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Like.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Like.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Like.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,58 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Like is use on String field type, to precise some particularity on search.
- *
- * @author ruchaud
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class Like extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- public enum SearchAs {AsText, ToLowerCase};
- protected SearchAs searchAs;
-
- public Like() {
- }
-
- public SearchAs getSearchAs() {
- return searchAs;
- }
-
- public void setSearchAs(SearchAs searchAs) {
- this.searchAs = searchAs;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Not.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Not.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Not.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,108 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * Not operator is used to build negative restriction for request on content.
- * <br>
- * <br>
- * For example, use: RestrictionHelper.not( RestrictionHelper.eq( myElement ,
- * "myValue" ) )
- */
-public class Not extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected Restriction restriction;
-
- /**
- * Default constructor
- */
- public Not() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param restriction
- */
- public Not(Restriction restriction) {
- this.restriction = restriction;
- }
-
- /**
- * Return restriction
- *
- * @return
- */
- public Restriction getRestriction() {
- return restriction;
- }
-
- /**
- * Set a value to parameter restriction.
- *
- * @param restriction
- */
- public void setRestriction(Restriction restriction) {
- this.restriction = restriction;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Not)) {
- return false;
- }
-
- final Not not = (Not) other;
-
- if ((restriction == null && not.getRestriction() != null)
- || (restriction != null && !restriction.equals(not
- .getRestriction()))) {
- return false;
- }
-
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Not.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/NotEquals.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/NotEquals.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/NotEquals.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,73 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * NotEquals operator is used to build restriction containing "element != value"
- * where element could be an Id, a String, a multimedia, a closed list, an
- * Integer, a Float or a Date. <br>
- * <br>
- * For example, use: RestrictionHelper.neq( myElement , "REF1234567890" )
- */
-public class NotEquals extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public NotEquals() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof NotEquals)) {
- return false;
- }
-
- final NotEquals notEquals = (NotEquals) other;
-
- return super.equals(notEquals);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return NotEquals.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Null.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Null.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Null.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,53 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-/**
- * Is null or is not null restriction
- *
- * @author ruchaud
- */
-public class Null extends Restriction {
-
- private static final long serialVersionUID = 1L;
-
- protected String fieldName;
-
- public Null() {
- }
-
- public Null(String fieldName) {
- this.fieldName = fieldName;
- }
-
- public String getFieldName() {
- return fieldName;
- }
-
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Or.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Or.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Or.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,113 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * Or operator is used to build disjunctive restriction for request on content.
- * It take at least 2 args. <br>
- * <br>
- * For example, use:
- * <ul>
- * <li>RestrictionHelper.or( restriction1, restriction2 )</li>
- * <li>RestrictionHelper.or( restriction1, restriction2, restriction3 )</li>
- * <li>RestrictionHelper.or(
- * my_JavaUtilList_Of_Restriction_Witch_Size_Is_Upper_Than2 )</li>
- * </ul>
- */
-public class Or extends Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected List<Restriction> restrictions;
-
- /**
- * Default constructor
- */
- public Or() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param restrictions
- */
- public Or(List<Restriction> restrictions) {
- this.restrictions = restrictions;
- }
-
- /**
- * Return restrictions
- *
- * @return
- */
- public List<Restriction> getRestrictions() {
- return restrictions;
- }
-
- /**
- * Set a value to parameter restrictions.
- *
- * @param restrictions
- */
- public void setRestrictions(List<Restriction> restrictions) {
- this.restrictions = restrictions;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Or)) {
- return false;
- }
-
- final Or or = (Or) other;
-
- if ((restrictions == null && or.getRestrictions() != null)
- || (restrictions != null && !restrictions.equals(or
- .getRestrictions())))
- return false;
-
- return true;
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Or.class.hashCode();
- }
-
-}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,293 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.entities.BusinessEntityWikitty;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ * Paged result containing result collection and facet topics.
+ *
+ * @param <T> paged result value type
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class PagedResult<T> implements Serializable {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(PagedResult.class);
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 8518774558223121855L;
+
+ /** indice element in global search result */
+ protected int firstIndice;
+ /** total number of result if we call the query for all possible result */
+ protected int numFound;
+ /** query really executed */
+ protected String queryString;
+ /** list of result in the wanted interval */
+ protected List<T> results;
+ /** facet asked or null if no facet */
+ protected Map<String, List<FacetTopic>> facets;
+
+ /**
+ * we don't initialize securityToken
+ *
+ * @param firstIndice
+ * @param numFound
+ * @param queryString
+ * @param facets
+ * @param results
+ */
+ public PagedResult(int firstIndice, int numFound, String queryString,
+ Map<String, List<FacetTopic>> facets, List<T> results) {
+ this.firstIndice = firstIndice;
+ this.numFound = numFound;
+ this.queryString = queryString;
+ this.facets = facets;
+ this.results = Collections.unmodifiableList(results);
+ }
+
+ /**
+ * Call {@link #cast(WikittyProxy, Class, boolean)} with
+ * autoconvert = true
+ *
+ * @param proxy used to retrieve securityToken and WikittyService
+ * @param clazz target PagedResult type
+ * @return new PagedResult, this result can have less elements that original
+ * for some reason (security, ...)
+ */
+ public <E extends BusinessEntityWikitty> PagedResult<E> cast(
+ WikittyProxy proxy, Class<E> clazz) {
+ return cast(proxy, clazz, true);
+ }
+
+ /**
+ * Convert all result to the wikitty type and return new PagedResult with
+ * this new result list.
+ *
+ * @param securityToken security token
+ * @param ws wikitty service
+ *
+ * @return new PagedResult, this result can have less elements that original
+ * for some reason (security, ...)
+ */
+ public PagedResult<Wikitty> cast(String securityToken, WikittyService ws) {
+ List<Wikitty> castedResult;
+
+ if (results.size() == 0) {
+ castedResult = new ArrayList<Wikitty>();
+ } else {
+ if (results.get(0) instanceof String) {
+ // le pagedresult courant contient des Ids
+ // Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
+ // ce PagedResult ne sait pas ce qu'il fait :)
+ List<String> ids = (List<String>) results;
+ castedResult = ws.restore(securityToken, ids);
+ } else {
+ throw new ClassCastException("PagedResult don't contains" +
+ " wikitty String id but " + results.get(0).getClass());
+ }
+ }
+ PagedResult<Wikitty> result = new PagedResult<Wikitty>(
+ firstIndice, numFound, queryString, facets, castedResult);
+ return result;
+ }
+
+ /**
+ * Convert all result to the wanted type and return new PagedResult with
+ * this new result list. If some result don't have the right extension (clazz)
+ * this extension is automatically added if autoconvert is true. Else
+ * an exception is thrown when result without extension is found.
+ *
+ * When you used autoconvert = false, you have a potentially problem when
+ * you have modified a BusinessEntity to have new extension and all your
+ * wikitty object are not uptodate in database.
+ *
+ * @param <E> class to cast into
+ * @param proxy used to retrieve securityToken and WikittyService
+ * @param autoconvert if autoconvert is false and object don't all needed
+ * extension, object is not put in the result
+ * @return new PagedResult, this result can have less elements that original
+ * for some reason (security, ...)
+ */
+ public <E extends BusinessEntityWikitty> PagedResult<E> cast(
+ WikittyProxy proxy, Class<E> clazz, boolean autoconvert) {
+ List<E> castedResult;
+
+ if (results.size() > 0 && results.get(0) instanceof String) {
+ // le pagedresult courant contient des Ids
+ // Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
+ // ce PagedResult ne sait pas ce qu'il fait :)
+ List<String> ids = (List<String>)results;
+ castedResult = proxy.restore(clazz, ids, !autoconvert);
+ } else {
+ castedResult = new ArrayList<E>(results.size());
+ E sample = WikittyUtil.newInstance(clazz);
+ Collection<WikittyExtension> wantedExtension = sample.getStaticExtensions();
+ for (T t : results) {
+ if (t == null) {
+ castedResult.add(null);
+ } else {
+ Wikitty w = null;
+ if (t instanceof Wikitty) {
+ w = (Wikitty) t;
+ } else if (t instanceof BusinessEntityWikitty) {
+ w = ((BusinessEntityWikitty) t).getWikitty();
+ } else {
+ throw new WikittyException(String.format(
+ "Illegal object result class '%s' can't convert it to wikitty",
+ t.getClass().getName(), clazz.getName()));
+ }
+
+ Collection<WikittyExtension> wikittyExtension = w.getExtensions();
+ if (autoconvert || wikittyExtension.containsAll(wantedExtension)) {
+ E e = WikittyUtil.newInstance(proxy.getSecurityToken(),
+ proxy.getWikittyService(), clazz, (Wikitty) t);
+ castedResult.add(e);
+ } else {
+ // silently pass current object, this object is not put
+ // in result
+ if (log.isDebugEnabled()) {
+ log.debug(_(
+ "Illegal object result class '%s' can't convert it to '%s'" +
+ "there is no same extension %s != %s",
+ t.getClass().getName(), clazz.getName(),
+ wikittyExtension, wantedExtension));
+ }
+ }
+ }
+ }
+ }
+ PagedResult<E> result = new PagedResult<E>(
+ firstIndice, numFound, queryString, facets, castedResult);
+ return result;
+ }
+
+ public int getFirstIndice() {
+ return firstIndice;
+ }
+
+ public int getNumFound() {
+ return numFound;
+ }
+
+ public String getQueryString() {
+ return queryString;
+ }
+
+ /**
+ * Return name of all facet used in query.
+ *
+ * @return result's facets names
+ */
+ public Collection<String> getFacetNames() {
+ Collection<String> result = facets.keySet();
+ return result;
+ }
+
+ /**
+ * Return all topic for the specified facet.
+ *
+ * @param facetName name of the wanted facet
+ * @return facet's topics
+ */
+ public List<FacetTopic> getTopic(String facetName) {
+ List<FacetTopic> result = facets.get(facetName);
+ return result;
+ }
+
+ /**
+ * Get map represent facets.
+ *
+ * @return all facets
+ */
+ public Map<String, List<FacetTopic>> getFacets() {
+ return facets;
+ }
+
+ /**
+ * Return the first element in result
+ *
+ * Can throw an exception if no element available
+ * @return first element
+ */
+ public T getFirst() {
+ T result = get(0);
+ return result;
+ }
+
+ /**
+ * Return element at index.
+ *
+ * @param i index
+ * @return element at index
+ */
+ public T get(int i) {
+ T result = results.get(i);
+ return result;
+ }
+
+ /**
+ * Return unmodifiable list of all result.
+ *
+ * @return all results
+ */
+ public List<T> getAll() {
+ return results;
+ }
+
+ /**
+ * Return the number of result in this object.
+ *
+ * @return result number
+ */
+ public int size() {
+ int result = results.size();
+ return result;
+ }
+
+}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Restriction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Restriction.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Restriction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,106 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * This element is a symbolic interface implemented by all operators used to
- * request contents (And, Or, Not, Equals, NotEquals, EndsWith, ...).
- */
-public class Restriction implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected RestrictionName name;
-
- /**
- * Default constructor
- */
- public Restriction() {
- super();
- }
-
- /**
- * Constructor with all parameters initialized
- *
- * @param name
- */
- public Restriction(RestrictionName name) {
- this();
- this.name = name;
- }
-
- /**
- * Return name
- *
- * @return
- */
- public RestrictionName getName() {
- return name;
- }
-
- /**
- * Set a value to parameter name.
- *
- * @param name
- */
- public void setName(RestrictionName name) {
- this.name = name;
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof Restriction)) {
- return false;
- }
-
- final Restriction restrictionDto = (Restriction) other;
-
- if ((name == null && restrictionDto.getName() != null)
- || (name != null && !name.equals(restrictionDto.getName()))) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return Restriction.class.hashCode();
- }
-
-}
\ No newline at end of file
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionHelper.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionHelper.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionHelper.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -24,6 +24,26 @@
*/
package org.nuiton.wikitty.search;
+import org.nuiton.wikitty.search.operators.RestrictionName;
+import org.nuiton.wikitty.search.operators.Restriction;
+import org.nuiton.wikitty.search.operators.StartsWith;
+import org.nuiton.wikitty.search.operators.Not;
+import org.nuiton.wikitty.search.operators.Like;
+import org.nuiton.wikitty.search.operators.EndsWith;
+import org.nuiton.wikitty.search.operators.And;
+import org.nuiton.wikitty.search.operators.Or;
+import org.nuiton.wikitty.search.operators.Less;
+import org.nuiton.wikitty.search.operators.Greater;
+import org.nuiton.wikitty.search.operators.GreaterOrEqual;
+import org.nuiton.wikitty.search.operators.Unlike;
+import org.nuiton.wikitty.search.operators.NotEquals;
+import org.nuiton.wikitty.search.operators.LessOrEqual;
+import org.nuiton.wikitty.search.operators.Keyword;
+import org.nuiton.wikitty.search.operators.Between;
+import org.nuiton.wikitty.search.operators.Null;
+import org.nuiton.wikitty.search.operators.Contains;
+import org.nuiton.wikitty.search.operators.Equals;
+import org.nuiton.wikitty.search.operators.Element;
import java.text.SimpleDateFormat;
import java.util.LinkedList;
import java.util.List;
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionName.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionName.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionName.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,56 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-/**
- * <p>
- * This enum contains all kind of restriction used to request content. It's used
- * by parser to create lucene request from RestrictionDto.
- * </p>
- */
-public enum RestrictionName {
- EQUALS,
- LIKE,
- UNLIKE,
- NOT_EQUALS,
- LESS,
- LESS_OR_EQUAL,
- GREATER,
- GREATER_OR_EQUAL,
- CONTAINS,
- STARTS_WITH,
- ENDS_WITH,
- NOT,
- AND,
- OR,
- BETWEEN,
- TRUE,
- FALSE,
- ASSOCIATED,
- IN,
- KEYWORD,
- IS_NULL,
- IS_NOT_NULL
-}
\ No newline at end of file
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Search.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Search.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Search.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -24,13 +24,16 @@
*/
package org.nuiton.wikitty.search;
+import org.nuiton.wikitty.search.operators.Restriction;
+import org.nuiton.wikitty.search.operators.Like;
+import org.nuiton.wikitty.search.operators.SubSearch;
+import org.nuiton.wikitty.search.operators.Element;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyUtil;
/**
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SearchOperand.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SearchOperand.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SearchOperand.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,34 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-/**
- * Represents the possible operands for client search. The supported type of
- * each AttributeSearchDto depends of its type.
- */
-public enum SearchOperand {
- EQUALS, NOT_EQUALS, LESS, LESS_OR_EQUALS, GREATER, GREATER_OR_EQUALS,
- BEGINS_WITH, ENDS_WITH, CONTAINS, NOT_CONTAINS, BETWEEN
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/StartsWith.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/StartsWith.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/StartsWith.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,73 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-/**
- * StartsWith operator is used to build restriction containing "element like
- * value*" where element could be a String, a multimedia, a text or an xhtml
- * <br>
- * <br>
- * For example, use: RestrictionHelper.start( myElement , "value" )
- */
-public class StartsWith extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- /**
- * Default constructor
- */
- public StartsWith() {
- super();
- }
-
- /**
- * Equality test based attributes values
- *
- * @param other Value to compare
- */
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof StartsWith)) {
- return false;
- }
-
- final StartsWith startsWith = (StartsWith) other;
-
- return super.equals(startsWith);
- }
-
- public int hashCode() {
- // equals use objects that are not constant through time
- // then, unable to create hashCode from those objects
- // returning a constant hash-code
- return StartsWith.class.hashCode();
- }
-
-}
\ No newline at end of file
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SubSearch.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SubSearch.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SubSearch.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,46 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-public class SubSearch extends Search {
-
- protected String foreignName;
- protected Search parent;
-
- public SubSearch(String foreignFieldName, Search search) {
- this.foreignName = foreignFieldName;
- this.parent = search;
- }
-
- @Override
- protected Restriction getRestrictions() throws UnsupportedOperationException {
- return new AssociatedRestriction(
- parent.criteria().getRestriction(),
- super.getRestrictions(),
- new Element(foreignName)
- );
- }
-
-}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Unlike.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Unlike.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Unlike.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,59 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.search;
-
-import java.io.Serializable;
-
-import org.nuiton.wikitty.search.Like.SearchAs;
-
-/**
- * UnLike is use on String field type, to precise some particularity on search
- * (case insensitive for example).
- *
- * @author martel
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class Unlike extends BinaryOperator implements Serializable {
-
- // serialVersionUID is used for serialization.
- private static final long serialVersionUID = 1L;
-
- protected SearchAs searchAs;
-
- public Unlike() {
- }
-
- public SearchAs getSearchAs() {
- return searchAs;
- }
-
- public void setSearchAs(SearchAs searchAs) {
- this.searchAs = searchAs;
- }
-
-}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/And.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/And.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/And.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/And.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,116 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * And operator is used to build conjunctive restriction for request on content.
+ * It take at least 2 args. <br>
+ * <br>
+ * For example, use:
+ * <ul>
+ * <li>RestrictionHelper.and( restriction1, restriction2 )</li>
+ * <li>RestrictionHelper.and( restriction1, restriction2, restriction3 )</li>
+ * <li>RestrictionHelper.and(
+ * my_JavaUtilList_Of_Restriction_Witch_Size_Is_Upper_Than2 )</li>
+ * </ul>
+ */
+public class And extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected List<Restriction> restrictions;
+
+ /**
+ * Default constructor
+ */
+ public And() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param restrictions
+ */
+ public And(List<Restriction> restrictions) {
+ this();
+ this.restrictions = restrictions;
+ }
+
+ /**
+ * Return restrictions
+ *
+ * @return
+ */
+ public List<Restriction> getRestrictions() {
+ return restrictions;
+ }
+
+ /**
+ * Set a value to parameter restrictions.
+ *
+ * @param restrictions
+ */
+ public void setRestrictions(List<Restriction> restrictions) {
+ this.restrictions = restrictions;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof And)) {
+ return false;
+ }
+
+ final And and = (And) other;
+
+ if ((restrictions == null && and.getRestrictions() != null)
+ || (restrictions != null && !restrictions.equals(and
+ .getRestrictions()))) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use restrictions but unable to create hashCode from
+ // restrictions because it is not
+ // constant through time using arbitrary constant hash-code
+ return And.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/AssociatedRestriction.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/AssociatedRestriction.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/AssociatedRestriction.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/AssociatedRestriction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+public class AssociatedRestriction extends Restriction {
+
+ private static final long serialVersionUID = 1L;
+
+ private Restriction associatedRestriction;
+ private Restriction embededRestriction;
+ private Element element;
+
+ public AssociatedRestriction(Restriction parentRestriction, Restriction embededRestriction, Element element) {
+ this.associatedRestriction = parentRestriction;
+ this.embededRestriction = embededRestriction;
+ this.name = RestrictionName.ASSOCIATED;
+ this.element = element;
+ }
+
+ public Restriction getParentRestrictionDto() {
+ return associatedRestriction;
+ }
+
+ public Element getElement() {
+ return element;
+ }
+
+ public void setElement(Element element) {
+ this.element = element;
+ }
+
+ public Restriction getRestriction() {
+ return embededRestriction;
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Between.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Between.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Between.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Between.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,156 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Between operator is used to build restriction containing "min < element
+ * < max" where element could be a Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.between( myElement , "15.5" , "22.5" )
+ */
+public class Between extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected Element element;
+ protected String min;
+ protected String max;
+
+ /**
+ * Default constructor
+ */
+ public Between() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param element
+ * @param min
+ * @param max
+ */
+ public Between(Element element, String min, String max) {
+ this.element = element;
+ this.min = min;
+ this.max = max;
+ }
+
+ /**
+ * Return element
+ *
+ * @return
+ */
+ public Element getElement() {
+ return element;
+ }
+
+ /**
+ * Set a value to parameter element.
+ *
+ * @param element
+ */
+ public void setElement(Element element) {
+ this.element = element;
+ }
+
+ /**
+ * Return min
+ *
+ * @return
+ */
+ public String getMin() {
+ return min;
+ }
+
+ /**
+ * Set a value to parameter min.
+ *
+ * @param min
+ */
+ public void setMin(String min) {
+ this.min = min;
+ }
+
+ /**
+ * Return max
+ *
+ * @return
+ */
+ public String getMax() {
+ return max;
+ }
+
+ /**
+ * Set a value to parameter max.
+ *
+ * @param max
+ */
+ public void setMax(String max) {
+ this.max = max;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Between)) {
+ return false;
+ }
+
+ final Between between = (Between) other;
+
+ if ((element == null && between.getElement() != null)
+ || (element != null && !element.equals(between.getElement()))) {
+ return false;
+ }
+ if ((min == null && between.getMin() != null)
+ || (min != null && !min.equals(between.getMin()))) {
+ return false;
+ }
+ if ((max == null && between.getMax() != null)
+ || (max != null && !max.equals(between.getMax()))) {
+ return false;
+ }
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Between.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/BinaryOperator.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/BinaryOperator.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/BinaryOperator.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/BinaryOperator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,130 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * This class is an abstract class that's used to factor each operator that
+ * handle two parameters (=, !=, <, <=, >, >=, end, begin).
+ */
+public class BinaryOperator extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected Element element;
+ protected String value;
+
+ /**
+ * Default constructor
+ */
+ public BinaryOperator() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param element
+ * @param value
+ */
+ public BinaryOperator(Element element, String value) {
+ this.element = element;
+ this.value = value;
+ }
+
+ /**
+ * Return element
+ *
+ * @return
+ */
+ public Element getElement() {
+ return element;
+ }
+
+ /**
+ * Set a value to parameter element.
+ *
+ * @param element
+ */
+ public void setElement(Element element) {
+ this.element = element;
+ }
+
+ /**
+ * Return value
+ *
+ * @return
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Set a value to parameter value.
+ *
+ * @param value
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof BinaryOperator)) {
+ return false;
+ }
+
+ final BinaryOperator binaryOperator = (BinaryOperator) other;
+
+ if ((element == null && binaryOperator.getElement() != null)
+ || (element != null && !element.equals(binaryOperator
+ .getElement()))) {
+ return false;
+ }
+ if ((value == null && binaryOperator.getValue() != null)
+ || (value != null && !value.equals(binaryOperator.getValue()))) {
+ return false;
+ }
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return BinaryOperator.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Contains.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Contains.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Contains.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Contains.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,139 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Contains operator is used to build restriction containing "(element like
+ * *value1 or element like value1*) and (element like *value2 or element like
+ * value2*)" where element could be a String, a multimedia, a text or an xhtml
+ * <br>
+ * <br>
+ * For example, use:
+ * <ul>
+ * <li>RestrictionHelper.contains( myElement , "value1" )</li>
+ * <li>RestrictionHelper.contains( myElement , "value1", "value2", ... )</li>
+ * <li>RestrictionHelper.contains( myElement ,
+ * a_list_containing_at_least_one_string )</li>
+ * </ul>
+ */
+public class Contains extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected Element element;
+ protected List<String> value;
+
+ /**
+ * Default constructor
+ */
+ public Contains() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param element
+ * @param value
+ */
+ public Contains(Element element, List<String> value) {
+ this.element = element;
+ this.value = value;
+ }
+
+ /**
+ * Return element
+ *
+ * @return
+ */
+ public Element getElement() {
+ return element;
+ }
+
+ /**
+ * Set a value to parameter element.
+ *
+ * @param element
+ */
+ public void setElement(Element element) {
+ this.element = element;
+ }
+
+ /**
+ * Return value
+ *
+ * @return
+ */
+ public List<String> getValue() {
+ return value;
+ }
+
+ /**
+ * Set a value to parameter value.
+ *
+ * @param value
+ */
+ public void setValue(List<String> value) {
+ this.value = value;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Contains)) {
+ return false;
+ }
+
+ final Contains contains = (Contains) other;
+
+ if ((element == null && contains.getElement() != null)
+ || (element != null && !element.equals(contains.getElement())))
+ return false;
+ if ((value == null && contains.getValue() != null)
+ || (value != null && !value.equals(contains.getValue())))
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Contains.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Element.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Element.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Element.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Element.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Search on field.
+ *
+ * @author ruchaud
+ */
+public class Element implements Serializable {
+
+ /** Represent a element on extension */
+ public static String ELT_EXTENSION = "elt_extension";
+
+ /** Represent a element on id */
+ public static String ELT_ID = "elt_id";
+
+ /** Represent type to search an element */
+ public static enum ElementType {NUMERIC, STRING, WIKITTY, BOOLEAN, DATE};
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected String name;
+
+ public Element() {
+ super();
+ }
+
+ public Element(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/EndsWith.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/EndsWith.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/EndsWith.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/EndsWith.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,74 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * EndsWith operator is used to build restriction containing "element like
+ * *value" where element could be a String, a multimedia, a text or an xhtml
+ * <br>
+ * <br>
+ * For example, use: RestrictionHelper.end( myElement , "value" )
+ */
+public class EndsWith extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public EndsWith() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof EndsWith)) {
+ return false;
+ }
+
+ final EndsWith endsWith = (EndsWith) other;
+
+ return super.equals(endsWith);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return EndsWith.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Equals.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Equals.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Equals.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Equals.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,74 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Equals operator is used to build restriction containing "element == value"
+ * where element could be an Id, a String, a multimedia, a closed list, an
+ * Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.eq( myElement , "REF1234567890" )
+ */
+public class Equals extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public Equals() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Equals)) {
+ return false;
+ }
+
+ final Equals equals = (Equals) other;
+
+ return super.equals(equals);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Equals.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Greater.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Greater.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Greater.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Greater.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,74 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Greater operator is used to build restriction containing "element > value"
+ * where element could be a Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.less( myElement ,
+ * RestrictionHelper.DATE_FORMAT.format(new Date()) )
+ */
+public class Greater extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public Greater() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Greater)) {
+ return false;
+ }
+
+ final Greater greater = (Greater) other;
+
+ return super.equals(greater);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Greater.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/GreaterOrEqual.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/GreaterOrEqual.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/GreaterOrEqual.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/GreaterOrEqual.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,74 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * GreatOrEqual operator is used to build restriction containing "element >=
+ * value" where element could be a Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.greatEq( myElement ,
+ * RestrictionHelper.DATE_FORMAT.format(new Date()) )
+ */
+public class GreaterOrEqual extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public GreaterOrEqual() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof GreaterOrEqual)) {
+ return false;
+ }
+
+ final GreaterOrEqual greaterOrEqual = (GreaterOrEqual) other;
+
+ return super.equals(greaterOrEqual);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return GreaterOrEqual.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/In.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/In.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/In.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/In.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,141 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Contains operator is used to build restriction containing "(element like
+ * *value1 or element like value1*) and (element like *value2 or element like
+ * value2*)" where element could be a String, a multimedia, a text or an xhtml
+ * <br>
+ * <br>
+ * For example, use:
+ * <ul>
+ * <li>RestrictionHelper.contains( myElement , "value1" )</li>
+ * <li>RestrictionHelper.contains( myElement , "value1", "value2", ... )</li>
+ * <li>RestrictionHelper.contains( myElement ,
+ * a_list_containing_at_least_one_string )</li>
+ * </ul>
+ */
+public class In extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected Element element;
+ protected List<String> value;
+
+ /**
+ * Default constructor
+ */
+ public In() {
+ super();
+ name = RestrictionName.IN;
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param element
+ * @param value
+ */
+ public In(Element element, List<String> value) {
+ this.element = element;
+ this.value = value;
+ name = RestrictionName.IN;
+ }
+
+ /**
+ * Return element
+ *
+ * @return
+ */
+ public Element getElement() {
+ return element;
+ }
+
+ /**
+ * Set a value to parameter element.
+ *
+ * @param element
+ */
+ public void setElement(Element element) {
+ this.element = element;
+ }
+
+ /**
+ * Return value
+ *
+ * @return
+ */
+ public List<String> getValue() {
+ return value;
+ }
+
+ /**
+ * Set a value to parameter value.
+ *
+ * @param value
+ */
+ public void setValue(List<String> value) {
+ this.value = value;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param value
+ * Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof In)) {
+ return false;
+ }
+
+ final In contains = (In) other;
+
+ if ((element == null && contains.getElement() != null)
+ || (element != null && !element.equals(contains.getElement())))
+ return false;
+ if ((value == null && contains.getValue() != null)
+ || (value != null && !value.equals(contains.getValue())))
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return In.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Keyword.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Keyword.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Keyword.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Keyword.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,53 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+/**
+ * Search keyword in all wikitty.
+ *
+ * @author ruchaud
+ */
+public class Keyword extends Restriction {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String value;
+
+ public Keyword() {
+ }
+
+ public Keyword(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Less.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Less.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Less.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Less.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Less operator is used to build restriction containing "element < value"
+ * where element could be a Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.less( myElement ,
+ * RestrictionHelper.DATE_FORMAT.format(new Date()) )
+ */
+public class Less extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public Less() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Less)) {
+ return false;
+ }
+
+ final Less less = (Less) other;
+
+ return super.equals(less);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Less.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/LessOrEqual.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/LessOrEqual.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/LessOrEqual.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/LessOrEqual.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * LessOrEqual operator is used to build restriction containing "element <=
+ * value" where element could be a Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.lessEq( myElement ,
+ * RestrictionHelper.DATE_FORMAT.format(new Date()) )
+ */
+public class LessOrEqual extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public LessOrEqual() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof LessOrEqual)) {
+ return false;
+ }
+
+ final LessOrEqual lessOrEqual = (LessOrEqual) other;
+
+ return super.equals(lessOrEqual);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return LessOrEqual.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Like.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Like.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Like.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Like.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,58 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Like is use on String field type, to precise some particularity on search.
+ *
+ * @author ruchaud
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class Like extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ public enum SearchAs {AsText, ToLowerCase};
+ protected SearchAs searchAs;
+
+ public Like() {
+ }
+
+ public SearchAs getSearchAs() {
+ return searchAs;
+ }
+
+ public void setSearchAs(SearchAs searchAs) {
+ this.searchAs = searchAs;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Not.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Not.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Not.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Not.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,108 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * Not operator is used to build negative restriction for request on content.
+ * <br>
+ * <br>
+ * For example, use: RestrictionHelper.not( RestrictionHelper.eq( myElement ,
+ * "myValue" ) )
+ */
+public class Not extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected Restriction restriction;
+
+ /**
+ * Default constructor
+ */
+ public Not() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param restriction
+ */
+ public Not(Restriction restriction) {
+ this.restriction = restriction;
+ }
+
+ /**
+ * Return restriction
+ *
+ * @return
+ */
+ public Restriction getRestriction() {
+ return restriction;
+ }
+
+ /**
+ * Set a value to parameter restriction.
+ *
+ * @param restriction
+ */
+ public void setRestriction(Restriction restriction) {
+ this.restriction = restriction;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Not)) {
+ return false;
+ }
+
+ final Not not = (Not) other;
+
+ if ((restriction == null && not.getRestriction() != null)
+ || (restriction != null && !restriction.equals(not
+ .getRestriction()))) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Not.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/NotEquals.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/NotEquals.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/NotEquals.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/NotEquals.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * NotEquals operator is used to build restriction containing "element != value"
+ * where element could be an Id, a String, a multimedia, a closed list, an
+ * Integer, a Float or a Date. <br>
+ * <br>
+ * For example, use: RestrictionHelper.neq( myElement , "REF1234567890" )
+ */
+public class NotEquals extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public NotEquals() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof NotEquals)) {
+ return false;
+ }
+
+ final NotEquals notEquals = (NotEquals) other;
+
+ return super.equals(notEquals);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return NotEquals.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Null.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Null.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Null.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Null.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,53 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+/**
+ * Is null or is not null restriction
+ *
+ * @author ruchaud
+ */
+public class Null extends Restriction {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String fieldName;
+
+ public Null() {
+ }
+
+ public Null(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Or.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Or.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Or.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Or.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,113 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Or operator is used to build disjunctive restriction for request on content.
+ * It take at least 2 args. <br>
+ * <br>
+ * For example, use:
+ * <ul>
+ * <li>RestrictionHelper.or( restriction1, restriction2 )</li>
+ * <li>RestrictionHelper.or( restriction1, restriction2, restriction3 )</li>
+ * <li>RestrictionHelper.or(
+ * my_JavaUtilList_Of_Restriction_Witch_Size_Is_Upper_Than2 )</li>
+ * </ul>
+ */
+public class Or extends Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected List<Restriction> restrictions;
+
+ /**
+ * Default constructor
+ */
+ public Or() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param restrictions
+ */
+ public Or(List<Restriction> restrictions) {
+ this.restrictions = restrictions;
+ }
+
+ /**
+ * Return restrictions
+ *
+ * @return
+ */
+ public List<Restriction> getRestrictions() {
+ return restrictions;
+ }
+
+ /**
+ * Set a value to parameter restrictions.
+ *
+ * @param restrictions
+ */
+ public void setRestrictions(List<Restriction> restrictions) {
+ this.restrictions = restrictions;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Or)) {
+ return false;
+ }
+
+ final Or or = (Or) other;
+
+ if ((restrictions == null && or.getRestrictions() != null)
+ || (restrictions != null && !restrictions.equals(or
+ .getRestrictions())))
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Or.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Restriction.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Restriction.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Restriction.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Restriction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,106 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * This element is a symbolic interface implemented by all operators used to
+ * request contents (And, Or, Not, Equals, NotEquals, EndsWith, ...).
+ */
+public class Restriction implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected RestrictionName name;
+
+ /**
+ * Default constructor
+ */
+ public Restriction() {
+ super();
+ }
+
+ /**
+ * Constructor with all parameters initialized
+ *
+ * @param name
+ */
+ public Restriction(RestrictionName name) {
+ this();
+ this.name = name;
+ }
+
+ /**
+ * Return name
+ *
+ * @return
+ */
+ public RestrictionName getName() {
+ return name;
+ }
+
+ /**
+ * Set a value to parameter name.
+ *
+ * @param name
+ */
+ public void setName(RestrictionName name) {
+ this.name = name;
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Restriction)) {
+ return false;
+ }
+
+ final Restriction restrictionDto = (Restriction) other;
+
+ if ((name == null && restrictionDto.getName() != null)
+ || (name != null && !name.equals(restrictionDto.getName()))) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return Restriction.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/RestrictionName.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/RestrictionName.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/RestrictionName.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/RestrictionName.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,56 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+/**
+ * <p>
+ * This enum contains all kind of restriction used to request content. It's used
+ * by parser to create lucene request from RestrictionDto.
+ * </p>
+ */
+public enum RestrictionName {
+ EQUALS,
+ LIKE,
+ UNLIKE,
+ NOT_EQUALS,
+ LESS,
+ LESS_OR_EQUAL,
+ GREATER,
+ GREATER_OR_EQUAL,
+ CONTAINS,
+ STARTS_WITH,
+ ENDS_WITH,
+ NOT,
+ AND,
+ OR,
+ BETWEEN,
+ TRUE,
+ FALSE,
+ ASSOCIATED,
+ IN,
+ KEYWORD,
+ IS_NULL,
+ IS_NOT_NULL
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SearchOperand.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SearchOperand.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SearchOperand.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SearchOperand.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,34 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+/**
+ * Represents the possible operands for client search. The supported type of
+ * each AttributeSearchDto depends of its type.
+ */
+public enum SearchOperand {
+ EQUALS, NOT_EQUALS, LESS, LESS_OR_EQUALS, GREATER, GREATER_OR_EQUALS,
+ BEGINS_WITH, ENDS_WITH, CONTAINS, NOT_CONTAINS, BETWEEN
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/StartsWith.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/StartsWith.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/StartsWith.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/StartsWith.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,73 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+/**
+ * StartsWith operator is used to build restriction containing "element like
+ * value*" where element could be a String, a multimedia, a text or an xhtml
+ * <br>
+ * <br>
+ * For example, use: RestrictionHelper.start( myElement , "value" )
+ */
+public class StartsWith extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default constructor
+ */
+ public StartsWith() {
+ super();
+ }
+
+ /**
+ * Equality test based attributes values
+ *
+ * @param other Value to compare
+ */
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof StartsWith)) {
+ return false;
+ }
+
+ final StartsWith startsWith = (StartsWith) other;
+
+ return super.equals(startsWith);
+ }
+
+ public int hashCode() {
+ // equals use objects that are not constant through time
+ // then, unable to create hashCode from those objects
+ // returning a constant hash-code
+ return StartsWith.class.hashCode();
+ }
+
+}
\ No newline at end of file
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SubSearch.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/SubSearch.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SubSearch.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/SubSearch.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,48 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import org.nuiton.wikitty.search.Search;
+
+public class SubSearch extends Search {
+
+ protected String foreignName;
+ protected Search parent;
+
+ public SubSearch(String foreignFieldName, Search search) {
+ this.foreignName = foreignFieldName;
+ this.parent = search;
+ }
+
+ @Override
+ protected Restriction getRestrictions() throws UnsupportedOperationException {
+ return new AssociatedRestriction(
+ parent.criteria().getRestriction(),
+ super.getRestrictions(),
+ new Element(foreignName)
+ );
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Unlike.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/Unlike.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Unlike.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/operators/Unlike.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,59 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.search.operators;
+
+import java.io.Serializable;
+
+import org.nuiton.wikitty.search.operators.Like.SearchAs;
+
+/**
+ * UnLike is use on String field type, to precise some particularity on search
+ * (case insensitive for example).
+ *
+ * @author martel
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class Unlike extends BinaryOperator implements Serializable {
+
+ // serialVersionUID is used for serialization.
+ private static final long serialVersionUID = 1L;
+
+ protected SearchAs searchAs;
+
+ public Unlike() {
+ }
+
+ public SearchAs getSearchAs() {
+ return searchAs;
+ }
+
+ public void setSearchAs(SearchAs searchAs) {
+ this.searchAs = searchAs;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/JGroupsNotifierTransporter.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/JGroupsNotifierTransporter.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/JGroupsNotifierTransporter.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,139 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jgroups.Channel;
+import org.jgroups.ChannelException;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.jgroups.ReceiverAdapter;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyException;
+
+/**
+ * JGroups notifier.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class JGroupsNotifierTransporter extends ReceiverAdapter
+ implements WikittyServiceNotifier.RemoteNotifierTransporter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class);
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+
+
+ /** JGroup channel. */
+ protected JChannel channel;
+
+ public JGroupsNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
+ this.ws = ws;
+
+ // can be null according to default constructor
+ if (config != null) {
+ // add notifier as listener
+ String jgroupChannel = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_JGROUP_CHANNELNAME.getKey());
+ if (!StringUtils.isBlank(jgroupChannel)) {
+ initChannel(jgroupChannel);
+ } else {
+ throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!");
+ }
+ }
+ }
+
+ /**
+ * Init jgroup channel.
+ *
+ * @param channelName channel name
+ */
+ protected void initChannel(String channelName) {
+ if (log.isDebugEnabled()) {
+ log.debug("Init jgroup communication channel...");
+ }
+
+ try {
+ // use default udp.xml in classpath
+ channel = new JChannel();
+ channel.setReceiver(this);
+
+ // don't receive messages sent by myself
+ channel.setOpt(Channel.LOCAL, false);
+
+ channel.connect(channelName);
+
+ if (log.isInfoEnabled()) {
+ log.info("JGroup communication channel initialized to "
+ + channel.getAddressAsString() + " ("
+ + channel.getClusterName() + ")");
+ log.info("Channel view: " + channel.getView());
+ }
+ } catch (ChannelException eee) {
+ throw new WikittyException("Can't initialize jgroup channel", eee);
+ }
+ }
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ @Override
+ public void sendMessage(WikittyServiceEvent event) throws Exception {
+ Message msg = new Message(null, null, event);
+ channel.send(msg);
+ }
+
+ /*
+ * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message)
+ */
+ @Override
+ public void receive(Message msg) {
+
+ Object message = msg.getObject();
+
+ if (log.isInfoEnabled()) {
+ log.info("Receive message : " + message);
+ }
+
+ if (message instanceof WikittyServiceEvent) {
+ WikittyServiceEvent event = (WikittyServiceEvent)message;
+ ws.processRemoteEvent(event);
+ }
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyCache.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyCache.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyCache.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,203 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyServiceListener;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyUtil;
+
+/**
+ * Cette classe sert a introduire du cache dans wikitty. Elle sert a centraliser
+ * tous les appels au cache pour pouvoir simplement changer de librairie de
+ * cache si necessaire, meme si pour l'instant on s'appuie le JDK
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyCache implements WikittyServiceListener {
+
+ static private Log log = LogFactory.getLog(WikittyCache.class);
+
+ /** keys are wikitty ids */
+ protected Map<String, Wikitty> wikittyCache;
+
+ /**
+ *
+ * @param config not used currently but necessary in futur to configure the cache
+ * Create a soft cache.
+ */
+ public WikittyCache(ApplicationConfig config) {
+ this(true);
+ }
+
+ /**
+ * Init cache with specific reference type.
+ *
+ * @param soft si vrai utilise un cache avec des reference Soft, sinon
+ * utilise des references static (utile pour les transactions)
+ */
+ public WikittyCache(boolean soft) {
+ if (soft) {
+ wikittyCache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
+ } else {
+ wikittyCache = new HashMap<String, Wikitty>();
+ }
+ }
+
+ public boolean existsWikitty(String id) {
+ Object o = wikittyCache.get(id);
+ boolean result = (o != null);
+ return result;
+ }
+
+ /**
+ * Return wikitty object if is in the cache, null otherwize.
+ *
+ * @param id
+ * @return wikitty object or null
+ */
+ public Wikitty getWikitty(String id) {
+ Wikitty result = wikittyCache.get(id);
+ return result;
+ }
+
+ /**
+ * Only realy put wikitty in cache, if not in cache or version is newer than
+ * one in cache
+ * @param e
+ */
+ public void putWikitty(Wikitty e) {
+ if (e == null) {
+ return;
+ }
+ Wikitty old = getWikitty(e.getId());
+ if (old == null
+ || WikittyUtil.versionGreaterThan(e.getVersion(), old.getVersion())) {
+ wikittyCache.put(e.getId(), e);
+
+ if (log.isTraceEnabled()) {
+ log.trace("Replace cached wikitty : new version " + e.getVersion() +
+ " > old version " + (old == null ? null : old.getVersion()));
+ }
+ }
+ else {
+ if (log.isTraceEnabled()) {
+ log.trace("Ignoring putWikittyEvent : new version " + e.getVersion() + " < old version " + old.getVersion());
+ }
+ }
+ }
+
+ /**
+ * batched put
+ * @param all
+ */
+ public void putAllWikitty(Collection<Wikitty> all) {
+ for (Wikitty w : all) {
+ putWikitty(w);
+ }
+ }
+
+ /**
+ * Remove wikitty from cache.
+ *
+ * @param id wikitty id to remove
+ */
+ public void removeWikitty(String id) {
+ wikittyCache.remove(id);
+ }
+
+ /**
+ * batched remove
+ * @param ids
+ */
+ public void removeAllWikitty(Collection<String> ids) {
+ for (String id : ids) {
+ removeWikitty(id);
+ }
+ }
+
+ /**
+ * Clear all cache.
+ */
+ public void clearWikitty() {
+ wikittyCache.clear();
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
+ */
+ @Override
+ public void clearWikitty(WikittyServiceEvent event) {
+ clearWikitty();
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
+ */
+ @Override
+ public void putWikitty(WikittyServiceEvent event) {
+ Collection<Wikitty> wikitties = event.getWikitties().values();
+ putAllWikitty(wikitties);
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
+ */
+ @Override
+ public void removeWikitty(WikittyServiceEvent event) {
+ for (String id : event.getRemoveDate().keySet()) {
+ removeWikitty(id);
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
+ */
+ @Override
+ public void putExtension(WikittyServiceEvent event) {
+
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
+ */
+ @Override
+ public void clearExtension(WikittyServiceEvent event) {
+
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigration.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigration.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigration.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,67 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.Wikitty;
+import java.util.HashMap;
+import java.util.Map;
+import org.nuiton.wikitty.WikittyService;
+
+/**
+ * Interface used to migrate Wikitty data from one WikittyExtension version
+ * to another version
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface WikittyExtensionMigration {
+
+ // TODO poussin 20090902 permit configuration of migrationRegistry by spring
+ /**
+ * use to put migration class for extension.
+ * key: extensionName, value: migration class
+ */
+ static public Map<String, WikittyExtensionMigration> migrationRegistry =
+ new HashMap<String, WikittyExtensionMigration>();
+
+ /**
+ * Migrate wikitty data from oldExt version to newExt.
+ *
+ * @param service Wikitty service that do migration
+ * @param wikitty Wikitty object that contains data in old version
+ * extension format
+ * @param oldExt old extension definition
+ * @param newExt new extension definition
+ * @return same wikitty as argument if nothing to do, or new wikitty
+ * if some modification is done
+ */
+ public Wikitty migrate(WikittyService service, Wikitty wikitty,
+ WikittyExtension oldExt, WikittyExtension newExt);
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigrationRename.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigrationRename.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyExtensionMigrationRename.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,142 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyService;
+
+/**
+ * Basic extension migration use to manage rename field name. Order to detect a
+ * rename, not creation a new field, you should use tag value "renameFrom" with
+ * name of use in before extension.
+ *
+ * Since 1.5, this class also take care about extension order.
+ *
+ * @author ruchaud
+ */
+public class WikittyExtensionMigrationRename implements WikittyExtensionMigration {
+
+ static private Log log = LogFactory.getLog(WikittyExtensionMigrationRename.class);
+
+ public static final String TAG_RENAME = "renameFrom";
+
+ /**
+ * Recursively add extension with requires ones (orderer).
+ * WikittyService used in this method must not have WikittyServiceSecurity
+ * in stack because we pass null as secuirtyToken to method. (TODO poussin
+ * 2010 verify this assertion, when we use Migration, we don't need
+ * Security)
+ *
+ * @param service service
+ * @param transaction current transaction to use
+ * @param wikitty wikitty to add extension to
+ * @param newExt extension to add
+ */
+ protected void addExtension(
+ WikittyService service, Wikitty wikitty, WikittyExtension newExt) {
+
+ // manage requires before current
+ String requires = newExt.getRequires();
+ if (StringUtils.isNotEmpty(requires)) {
+ for (String require : requires.split(",")) {
+ WikittyExtension newRequireExt =
+ service.restoreExtensionLastVersion(null, require);
+ addExtension(service, wikitty, newRequireExt);
+ }
+ }
+
+ // add current extension
+ wikitty.addExtension(newExt);
+ }
+
+ @Override
+ public Wikitty migrate(WikittyService service, Wikitty wikitty,
+ WikittyExtension oldExt, WikittyExtension newExt) {
+
+ String wikittyId = wikitty.getId();
+ String wikittyVersion = wikitty.getVersion();
+
+ Wikitty result = new WikittyImpl(wikittyId);
+ result.setVersion(wikittyVersion);
+
+ // Add all extension and replace old by the new
+ for (WikittyExtension extension : wikitty.getExtensions()) {
+ // add one by one to manage require
+
+ // during loop add new when old one is found
+ if (extension.equals(oldExt)) {
+ addExtension(service, result, newExt);
+ }
+ else {
+ addExtension(service, result, extension);
+ }
+ }
+
+ // Copy other values
+ Set<String> fqFieldNames = wikitty.fieldNames();
+ String extName = newExt.getName();
+ for (String fieldName : fqFieldNames) {
+ if(!fieldName.startsWith(extName + ".")) {
+ Object value = wikitty.getFqField(fieldName);
+ log.debug("Value " + fieldName + "=" + value);
+ result.setFqField(fieldName, value);
+ }
+ }
+
+ // Migrate field name
+ Collection<String> oldFieldNames = oldExt.getFieldNames();
+ Collection<String> newFieldNames = newExt.getFieldNames();
+ for (String fieldName : newFieldNames) {
+ FieldType fieldType = newExt.getFieldType(fieldName);
+
+ String renameFrom = fieldType.getTagValue(TAG_RENAME);
+ log.debug("Scan rename migration on " + extName + "." + fieldName + ":" + TAG_RENAME + "=" + renameFrom);
+
+ if(renameFrom != null && !renameFrom.isEmpty()) {
+ Object value = wikitty.getFieldAsObject(extName, renameFrom);
+ log.debug("Rename " + extName + "." + fieldName + "=" + value);
+ result.setField(extName, fieldName, value);
+ } else {
+ if(oldFieldNames.contains(fieldName)) {
+ Object value = wikitty.getFieldAsObject(extName, fieldName);
+ log.debug("Copy " + extName + "." + fieldName + "=" + value);
+ result.setField(extName, fieldName, value);
+ }
+ }
+ }
+
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittySecurityHelper.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySecurityHelper.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittySecurityHelper.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittySecurityHelper.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,152 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyAuthorisation;
+import org.nuiton.wikitty.entities.WikittyAuthorisationHelper;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyGroup;
+import org.nuiton.wikitty.entities.WikittyGroupImpl;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyMetaExtensionUtil;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittySecurityHelper {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittySecurityHelper.class);
+
+ /** nom du groupe des administrateurs de l'application */
+ static final public String WIKITTY_APPADMIN_GROUP_NAME = "WikittyAppAdmin";
+
+ /**
+ * get the id of a user given his login.
+ *
+ * @param securityToken a token
+ * @param login the login of the user to search for
+ * @return a wikitty id
+ */
+ static public String getUserWikittyId(WikittyProxy proxy, String login) {
+ String userWikittyId = null;
+ Wikitty user = proxy.findByCriteria(Search.query().eq(
+ WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
+ if (user != null) {
+ userWikittyId = user.getId();
+ }
+ return userWikittyId;
+ }
+
+ /**
+ * create appAdminGroup and add current user as first member
+ */
+ static public WikittyGroup createAppAdminGroup(WikittyUser user) {
+ WikittyGroup result = new WikittyGroupImpl();
+ result.setName(WIKITTY_APPADMIN_GROUP_NAME);
+
+ String firstUserId = user.getWikittyId();
+ result.addMembers(firstUserId);
+
+ return result;
+ }
+
+ /**
+ * create wikitty that represent a <strong>level 2</strong> security policy
+ * on the given extension.
+ *
+ * Store must check if this security policy doesn't already exist
+ *
+ */
+ static public Wikitty createExtensionAuthorisation(WikittyUser owner,
+ WikittyExtension extension) {
+
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
+ Wikitty result = new WikittyImpl(wikittyAuthorisationId);
+ WikittyAuthorisationHelper.addExtension(result);
+ WikittyAuthorisationHelper.setOwner(result, owner.getWikittyId());
+ return result;
+ }
+
+ static public Wikitty restoreExtensionAuthorisation(
+ WikittyProxy proxy, WikittyExtension extension) {
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extension.getName());
+ Wikitty result = proxy.restore(wikittyAuthorisationId);
+ return result;
+ }
+
+// /**
+// * @param securityToken token with rights to modify extension
+// * @param extensionRights a wikitty that has extension WikittyAuthorisation
+// */
+// static public void storeExtensionAuthorisation(String securityToken,
+// Wikitty extensionRights) {
+//
+// String userId = getUserId(securityToken);
+//
+// Wikitty oldVersion = ws.restore(securityToken, extensionRights.getId());
+//
+// // check that the extensionRights does not have
+// if (WikittyAuthorisationHelper.hasExtension(extensionRights)) {
+//
+// if (oldVersion == null) {
+// // if this exception is raised, you should use addExtensionAuthorisation()
+// throw new IllegalArgumentException("you can't store an authorisation for the fist time");
+//
+// } else {
+//
+// if ( userIsAnonymousOrAppAdmin(securityToken, userId) ||
+// canAdmin(securityToken, userId, null, oldVersion) ) {
+//
+// ws.store(securityToken, extensionRights);
+//
+// } else {
+// throw new SecurityException(String.format(
+// "user %s can't admin rights for this extension", userId));
+// }
+// }
+// } else {
+// throw new IllegalArgumentException(String.format(
+// "extensionRights %s is not a wikittyAuthorisation. It misses the extension",
+// extensionRights));
+// }
+// }
+//
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceCached.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceCached.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceCached.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,419 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.entities.WikittyCopyOnWrite;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyTree;
+
+/**
+ * Override some method of WikittyService to use cache
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceCached implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceCached.class);
+
+ /** Cache. */
+ protected WikittyCache cache = null;
+
+ /** Delegated wikitty service implementation. */
+ protected WikittyService ws;
+
+ /** cache policy (configuration)
+ *
+ * if true the cache will always restore copies of the wikitty
+ * if false the cache will restore wikitties that do a lazy copy when the
+ * wikitty is modified ({@link WikittyCopyOnWrite} instances)
+ *
+ * default set to false. To change this value, use
+ * {@link WikittyServiceCached#WikittyServiceCached(WikittyService, Properties)}
+ * and set the good property.
+ */
+ protected boolean allwaysRestoreCopies = false;
+
+ /**
+ * Constructor with configuration.
+ *
+ * @param ws delegate service
+ * @param props properties (can be null)
+ */
+ public WikittyServiceCached(ApplicationConfig config, WikittyService ws) {
+ this.ws = ws;
+ cache = new WikittyCache(config);
+ registerWikittyServiceListener(config);
+
+ if (config != null) {
+ // reading configuration and set allwaysRestoreCopies accordingly
+ allwaysRestoreCopies =
+ config.getOptionAsBoolean(WikittyConfig.Option.WIKITTY_CACHE_RESTORE_COPIES.getKey());
+ }
+ }
+
+ /** wrap the wikitty or copy it according to allwaysRestoreCopies value */
+ protected Wikitty wrapWikitty(Wikitty wikitty) {
+
+ // Restored wikitty can be null
+ if (wikitty == null) {
+ return null;
+ }
+
+ Wikitty result = null;
+ if (allwaysRestoreCopies) {
+ try {
+ result = wikitty.clone();
+ } catch (CloneNotSupportedException e) {
+ log.error("unable to clone " + wikitty, e);
+ }
+ }
+
+ // if allwaysRestoreCopies is false and above clone failed
+ if (result == null) {
+ result = new WikittyCopyOnWrite(wikitty);
+ }
+ return result;
+ }
+
+ /**
+ * Add cache as service listener if configuration request it.
+ *
+ * @param props properties (can be null)
+ */
+ protected void registerWikittyServiceListener(ApplicationConfig config) {
+ if (config != null) {
+ // add notifier as listener
+ boolean listenEvents = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_CACHE_LISTEN_REMOTEEVENTS.getKey());
+ if (listenEvents) {
+ // add service listener for synchronisation
+ // listener des remote event
+ addWikittyServiceListener(cache, ServiceListenerType.REMOTE);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Listen remote event on service");
+ }
+ }
+ }
+ }
+
+ @Override
+ public String login(String login, String password) {
+ return ws.login(login, password);
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ ws.logout(securityToken);
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ return ws.canWrite(securityToken, wikitty);
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ return ws.canDelete(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ return ws.canRead(securityToken, wikittyId);
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ WikittyServiceEvent result = ws.clear(securityToken);
+ cache.clearWikitty();
+ return result;
+ }
+
+ /**
+ * delete objets in cache
+ * @param ids
+ */
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ WikittyServiceEvent result = ws.delete(securityToken, ids);
+ cache.removeAllWikitty(ids);
+ return result;
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param criteria
+ * @return
+ */
+ @Override
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ // if we want to add cache for this method, we must clear cache when
+ // addLabel, store, storeExtension are called
+ return ws.findAllByCriteria(securityToken, criteria);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param securityToken
+ * @param criteria
+ * @param transaction
+ *
+ * @return
+ */
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ // if we want to add cache for this method, we must clear cache when
+ // addLabel, store, storeExtension are called
+ return ws.findByCriteria(securityToken, criteria);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @return
+ */
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ // TODO poussin 20100412: perhaps use cache for extension ?
+ return ws.getAllExtensionIds(securityToken);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param extensionName
+ * @return
+ */
+ @Override
+ public List<String> getAllExtensionsRequires(
+ String securityToken, String extensionName) {
+ // TODO poussin 20100412: perhaps use cache for extension ?
+ return ws.getAllExtensionsRequires(securityToken, extensionName);
+ }
+
+ /**
+ * Overriden to put all restored object from server in cache
+ *
+ * @param securityToken security token
+ * @param ids wikitty ids to restore
+ * @return wikitty list
+ */
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ ArrayList<String> notInCache = new ArrayList<String>();
+ // linked to maintains the ordre
+ LinkedHashMap<String, Wikitty> fromCache =
+ new LinkedHashMap<String, Wikitty>();
+ for (String id : ids) {
+ Wikitty w = cache.getWikitty(id);
+ fromCache.put(id, w); // put all to maintains order
+ if (w == null) { // if not found on cache, ask the server
+ notInCache.add(id);
+ }
+ }
+
+ // retrieve missing object
+ List<Wikitty> missingInCache = ws.restore(securityToken, notInCache);
+
+ cache.putAllWikitty(missingInCache);
+
+ for (Wikitty w : missingInCache) {
+ // add missing object
+ fromCache.put(w.getId(), w);
+ }
+
+ Collection<Wikitty> tmp = fromCache.values();
+
+ // wrap the resulting wikitties to prevent cache conflicts
+ ArrayList<Wikitty> result = new ArrayList<Wikitty>();
+ for (Wikitty w : tmp) {
+ result.add(wrapWikitty(w));
+ }
+
+ return result;
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param wikittyId
+ * @param filter
+ * @return
+ */
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(
+ String securityToken, String wikittyId, Criteria filter) {
+ // FIXME lookup in cache, and put in cache
+ return ws.restoreChildren(securityToken, wikittyId, filter);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param name
+ * @return
+ */
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ // TODO poussin 20100412: perhaps use cache for extension ?
+ return ws.restoreExtensionLastVersion(securityToken, name);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param wikittyId
+ * @param filter
+ * @return
+ */
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(
+ String securityToken, String wikittyId, Criteria filter) {
+ // FIXME lookup in cache, and put in cache
+ return ws.restoreNode(securityToken, wikittyId, filter);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param wikittyId
+ * @return
+ */
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ // FIXME lookup in cache, and put in cache
+ return ws.restoreTree(securityToken, wikittyId);
+ }
+
+ /**
+ * just wrap service method
+ *
+ * @param wikittyId
+ * @return
+ */
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
+ return ws.deleteTree(securityToken, wikittyId);
+ }
+
+ /**
+ * Overriden to put wikitty in cache
+ *
+ * @param wikitties
+ * @param force boolean force non version version increment on saved wikitty
+ * or force version on wikitty creation (version 0.0)
+ * @return
+ */
+ @Override
+ public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
+
+ cache.putAllWikitty(result.getWikitties().values());
+
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ // TODO poussin 20101029: perhaps use cache for extension ?
+ return ws.storeExtension(securityToken, exts);
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ // TODO poussin 20101029: perhaps use cache for extension ?
+ return ws.restoreExtension(securityToken, id);
+ }
+
+ @Override
+ public Wikitty restoreVersion(
+ String securityToken, String wikittyId, String version) {
+ // not put it in cache
+ return ws.restoreVersion(securityToken, wikittyId, version);
+ }
+
+ //
+ // Just delegate method
+ //
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ ws.addWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ ws.removeWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ ws.syncEngin(securityToken);
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ return ws.replay(securityToken, events);
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return ws.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceDelegator.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceDelegator.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceDelegator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,222 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyTree;
+
+/**
+ * Wikitty service delegator.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class WikittyServiceDelegator implements WikittyService {
+
+ /** Delegated wikitty service. */
+ protected WikittyService delegate;
+
+ public WikittyServiceDelegator() {
+ }
+
+ public WikittyServiceDelegator(WikittyService delegate) {
+ setDelegate(delegate);
+ }
+
+ /**
+ * Get delegated service.
+ *
+ * @return delegate service
+ */
+ public WikittyService getDelegate() {
+ return delegate;
+ }
+
+ /**
+ * Set delegated service.
+ *
+ * @param delegate delegate
+ */
+ public void setDelegate(WikittyService delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener,
+ ServiceListenerType type) {
+ delegate.addWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener,
+ ServiceListenerType type) {
+ delegate.removeWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public String login(String login, String password) {
+ return delegate.login(login, password);
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ delegate.logout(securityToken);
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ return delegate.clear(securityToken);
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ return delegate.replay(securityToken, events);
+ }
+
+ @Override
+ public WikittyServiceEvent store(
+ String securityToken, Collection<Wikitty> wikitties, boolean force) {
+ return delegate.store(securityToken, wikitties, force);
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ return delegate.getAllExtensionIds(securityToken);
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(String securityToken,
+ String extensionName) {
+ return delegate.getAllExtensionsRequires(securityToken, extensionName);
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ return delegate.storeExtension(securityToken, exts);
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ return delegate.restoreExtension(securityToken, id);
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ return delegate.restoreExtensionLastVersion(securityToken, name);
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> id) {
+ return delegate.restore(securityToken, id);
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ return delegate.delete(securityToken, ids);
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ return delegate.findAllByCriteria(securityToken, criteria);
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ return delegate.findByCriteria(securityToken, criteria);
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ return delegate.restoreTree(securityToken, wikittyId);
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
+ return delegate.deleteTree(securityToken, wikittyId);
+ }
+
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken,
+ String wikittyId, Criteria filter) {
+ return delegate.restoreNode(securityToken, wikittyId, filter);
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
+ String wikittyId, Criteria filter) {
+ return delegate.restoreChildren(securityToken, wikittyId, filter);
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken, String wikittyId,
+ String version) {
+ return delegate.restoreVersion(securityToken, wikittyId, version);
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ delegate.syncEngin(securityToken);
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ return delegate.canWrite(securityToken, wikitty);
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ return delegate.canDelete(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ return delegate.canRead(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return delegate.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return delegate.isDeleted(securityToken, wikittyId);
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEnhanced.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEnhanced.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEnhanced.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,82 @@
+package org.nuiton.wikitty.services;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.WikittyService;
+
+/**
+ * Same as delegator but with some helpfull method for developer. This new
+ * methods are methods with less arguments or simple argument and not collection
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceEnhanced extends WikittyServiceDelegator {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceEnhanced.class);
+
+ public WikittyServiceEnhanced(WikittyService service) {
+ super(service);
+ }
+
+ public WikittyServiceEvent store(String securityToken, Wikitty wikitty) {
+ return store(securityToken, Collections.singleton(wikitty), false);
+ }
+
+ public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties) {
+ return store(securityToken, wikitties, false);
+ }
+
+ public WikittyServiceEvent storeExtension(String securityToken,
+ WikittyExtension ext) {
+ return storeExtension(securityToken, Collections.singleton(ext));
+ }
+
+ /**
+ *
+ * @param securityToken security token
+ * @param id object id to restore
+ * @return the corresponding object, or null if object doesn't exist, is
+ * deleted or you don't have authorisation (you can check authorisation
+ * before call restore with {@link #canRead(java.lang.String, java.lang.String)}
+ */
+ public Wikitty restore(String securityToken, String id) {
+ Wikitty result = restore(this, securityToken, id);
+ return result;
+ }
+
+ public WikittyServiceEvent delete(String securityToken, String id) {
+ return delete(securityToken, Collections.singleton(id));
+ }
+
+ /**
+ * Conveniant static method usefull in other WikittyService implementation
+ * where we don't wan't instanciate WikittyServiceEnhanced
+ *
+ * @param securityToken security token
+ * @param id object id to restore
+ * @return the corresponding object, or null if object doesn't exist, is
+ * deleted or you don't have authorisation (you can check authorisation
+ * before call restore with {@link #canRead(java.lang.String, java.lang.String)}
+ */
+ static public Wikitty restore(WikittyService ws, String securityToken, String id) {
+ Wikitty result = null;
+ List<Wikitty> resultList =
+ ws.restore(securityToken, Collections.singletonList(id));
+ if (resultList != null && resultList.size() > 0) {
+ result = resultList.get(0);
+ }
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEvent.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEvent.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceEvent.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,308 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import com.thoughtworks.xstream.XStream;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+
+/**
+ * Wikitty service event.
+ *
+ * Contains :
+ * <ul>
+ * <li>Wikitty service as source
+ * <li>wikitties : wikitty added if type contains PUT_WIKITTY
+ * <li>ids & remove date : if type contains REMOVE_WIKITTY
+ * <li>extensions : extension added if type contains PUT_EXTENSION
+ * </ul>
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class WikittyServiceEvent extends EventObject {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 9017732163643700599L;
+
+ /** Message type (put, remove, clear...). */
+ static public enum WikittyEventType {
+ PUT_WIKITTY(WikittyServiceListener.PUT_WIKITTY_METHOD),
+ REMOVE_WIKITTY(WikittyServiceListener.REMOVE_WIKITTY_METHOD),
+ CLEAR_WIKITTY(WikittyServiceListener.CLEAR_WIKITTY_METHOD),
+ PUT_EXTENSION(WikittyServiceListener.PUT_EXTENSION_METHOD),
+ // il est impossible actuellement de supprimer des extensions
+// REMOVE_EXTENSION(WikittyServiceListener.REMOVE_EXTENSION_METHOD),
+ CLEAR_EXTENSION(WikittyServiceListener.CLEAR_EXTENSION_METHOD);
+
+ /** le nom de la methode du listener a appeler pour ce type d'event */
+ public String listenerMethodName;
+ WikittyEventType(String listenerMethodName) {
+ this.listenerMethodName = listenerMethodName;
+ }
+ }
+
+
+ /** unique event id, each event must have eventId, and event is sequence
+ * without hole. (ex: 0,1,2,3,4,5,6,...) */
+ protected long eventId;
+
+ /** Remote event (received from server). */
+ protected boolean remote;
+
+ /** event type, one event can have multiple type
+ * (ex: PUT_WIKITTY + PUT_EXTENSION */
+ protected EnumSet<WikittyEventType> type;
+
+ /** heure de creation de l'event */
+ protected long time;
+
+ /** Use by PUT_WIKITTY, all wikitties added */
+ protected Map<String, Wikitty> wikitties;
+
+ /** Use by REMOVE_WIKITTY. key: wikittyId, value: removed date */
+ protected Map<String, Date> removeDate;
+
+ /** Use by PUT_EXTENSION, all extensions added */
+ protected Map<String, WikittyExtension> extensions;
+
+ /**
+ * Constructor with source {@link WikittyService}.
+ *
+ * @param source wikitty service
+ * @param eventId unique event id
+ */
+ public WikittyServiceEvent(Object source) {
+ super(source);
+ this.time = System.currentTimeMillis();
+ this.type = EnumSet.noneOf(WikittyEventType.class);
+ }
+
+ /**
+ * Return time of event creation
+ * @return
+ */
+ public long getTime() {
+ return time;
+ }
+
+ /**
+ * To allow set transient source after deserialisation.
+ *
+ * @param source source
+ */
+ public void setSource(Object source) {
+ this.source = source;
+ }
+
+ public EnumSet<WikittyEventType> getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ */
+ public void addType(WikittyEventType type) {
+ this.type.add(type);
+ }
+
+ /**
+ * Is event remote.
+ *
+ * @return remote event
+ */
+ public boolean isRemote() {
+ return remote;
+ }
+
+ /**
+ * Change remote event property.
+ *
+ * @param remote remote
+ */
+ public void setRemote(boolean remote) {
+ this.remote = remote;
+ }
+
+ public long getEventId() {
+ return eventId;
+ }
+
+ /**
+ * This method must be call with right id, just before send message
+ * notification
+ * @param eventId
+ */
+ public void setEventId(long eventId) {
+ this.eventId = eventId;
+ }
+
+ public Map<String, Wikitty> getWikitties() {
+ return wikitties;
+ }
+
+ public void addWikitty(Wikitty wikitty) {
+ if (wikitties == null) {
+ wikitties = new LinkedHashMap<String, Wikitty>();
+ addType(WikittyEventType.PUT_WIKITTY);
+ }
+ this.wikitties.put(wikitty.getId(), wikitty);
+ }
+
+ public Map<String, Date> getRemoveDate() {
+ return removeDate;
+ }
+
+ public void addRemoveDate(String wikittyId, Date date) {
+ if (removeDate == null) {
+ removeDate = new HashMap<String, Date>();
+ addType(WikittyEventType.REMOVE_WIKITTY);
+ }
+ removeDate.put(wikittyId, date);
+ }
+
+ public Map<String, WikittyExtension> getExtensions() {
+ return extensions;
+ }
+
+ public void addExtension(WikittyExtension extension) {
+ if (extensions == null) {
+ extensions = new LinkedHashMap<String, WikittyExtension>();
+ addType(WikittyEventType.PUT_EXTENSION);
+ }
+ extensions.put(extension.getId(), extension);
+ }
+
+ /**
+ * Merge this event with event passed in arguement. Merged datas are:
+ * <li> type
+ * <li> wikitties
+ * <li> extensions
+ * <li> removeDate
+ *
+ * @param e
+ */
+ public void add(WikittyServiceEvent e) {
+ getType().addAll(e.getType());
+ if (e.getWikitties() != null) {
+ for (Map.Entry<String, Wikitty> i : e.getWikitties().entrySet()) {
+ addWikitty(i.getValue());
+ }
+ }
+ if (e.getExtensions() != null) {
+ for (Map.Entry<String, WikittyExtension> i : e.getExtensions().entrySet()) {
+ addExtension(i.getValue());
+ }
+ }
+ if (e.getRemoveDate() != null) {
+ for (Map.Entry<String, Date> i : e.getRemoveDate().entrySet()) {
+ addRemoveDate(i.getKey(), i.getValue());
+ }
+ }
+ }
+
+ /**
+ * Update data directly in object passed in argument.
+ * Actualy only version and deletion date are updated.
+ * <p>
+ * rem: during store action, no migration has done. Migration is only
+ * done during restore process. This implies that extension don't change
+ * after store. But another client, may can load wikitty with migration
+ * and store it, or add manualy some extension. In that case, stored wikitty
+ * has new/more extension that another client.
+ * <p>
+ * And internaly wikitty object is marked clean (not dirty)
+ * @param e
+ * @return wikitty passed in arguement or null, if event is CLEAR_WIKITTY
+ */
+ public Wikitty update(Wikitty e) {
+ // update version
+ String id = e.getId();
+ if (type.contains(WikittyEventType.CLEAR_WIKITTY)) {
+ e = null;
+ } else {
+ if (type.contains(WikittyEventType.PUT_WIKITTY)) {
+ Wikitty newWikitty = getWikitties().get(id);
+ e.replace(newWikitty);
+ }
+ if (type.contains(WikittyEventType.REMOVE_WIKITTY)) {
+ Date date = getRemoveDate().get(id);
+ e.setDeleteDate(date);
+ }
+ e.clearDirty();
+ }
+ return e;
+ }
+
+ @Override
+ public String toString() {
+ String toString = getClass().getName()
+ + "[source=" + source
+ + ", eventId=" + eventId
+ + ", time=" + time
+ + ", type=" + type
+ + ", remote=" + remote
+ + ", wikitties=" + wikitties
+ + ", removeDate=" + removeDate
+ + ", extensions=" + extensions
+ + "]";
+ return toString;
+ }
+
+ /**
+ * Permet de serializer en XML l'event. Pourrait etre utilise pour l'envoi
+ * sur un transporteur qui ne peremt pas la serialisation java
+ * @return
+ */
+ public String toXML() {
+ XStream xstream = new XStream();
+ xstream.setMode(XStream.NO_REFERENCES);
+ xstream.alias("event", WikittyServiceEvent.class);
+ String result = xstream.toXML(this);
+ return result;
+ }
+
+ /**
+ * Inverse de la methode toXML
+ * @param xml
+ * @return
+ */
+ static public WikittyServiceEvent fromXML(String xml) {
+ XStream xstream = new XStream();
+ xstream.alias("event", WikittyServiceEvent.class);
+ WikittyServiceEvent result = (WikittyServiceEvent)xstream.fromXML(xml);
+ return result;
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceImpl.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceImpl.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceImpl.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,1101 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.storage.WikittyExtensionStorage;
+import org.nuiton.wikitty.storage.WikittySearchEngin;
+import org.nuiton.wikitty.storage.WikittyStorage;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.AbstractMap.SimpleEntry;
+import java.util.LinkedHashSet;
+import java.util.Map.Entry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyTree;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ * WikittyService is main service
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceImpl implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceImpl.class);
+
+ /** Default migration use to migrate a wikitty in last extension version */
+ protected WikittyExtensionMigration defaultExtensionMigration =
+ new WikittyExtensionMigrationRename();
+
+ protected WikittySearchEngin searchEngin;
+ protected WikittyExtensionStorage extensionStorage;
+ protected WikittyStorage wikittyStorage;
+
+ /**
+ * FIXME poussin 20101027 remove it when all used WikittyServiceHelper.build
+ *
+ * Used by specific child
+ * {@link org.nuiton.wikitty.jdbc.WikittyServiceJDBC}
+ * {@link org.nuiton.wikitty.jdbc.WikittyServiceJPA}
+ * {@link org.nuiton.wikitty.jdbc.WikittyServiceHbase}
+ */
+ protected WikittyServiceImpl() {
+ }
+
+ public WikittyServiceImpl(WikittyExtensionStorage extensionStorage,
+ WikittyStorage wikittyStorage,
+ WikittySearchEngin searchEngin) {
+ this.extensionStorage = extensionStorage;
+ this.wikittyStorage = wikittyStorage;
+ this.searchEngin = searchEngin;
+ }
+
+ protected WikittySearchEngin getSearchEngin() {
+ return searchEngin;
+ }
+
+ protected WikittyExtensionStorage getExtensionStorage() {
+ return extensionStorage;
+ }
+
+ protected WikittyStorage getWikittyStorage() {
+ return wikittyStorage;
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyService#addWikittyServiceListener(org.nuiton.wikitty.WikittyServiceListener, org.nuiton.wikitty.WikittyService.ServiceListenerType)
+ */
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException("Can't add listener on " + WikittyServiceImpl.class.getName());
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyService#removeWikittyServiceListener(org.nuiton.wikitty.WikittyServiceListener, org.nuiton.wikitty.WikittyService.ServiceListenerType)
+ */
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException("Can't remove listener on " + WikittyServiceImpl.class.getName());
+ }
+
+ @Override
+ public String login(String login, String password) {
+ log.warn("login asked, but there is no security service");
+ return null;
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ log.warn("logout asked, but there is no security service");
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ return true;
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ return true;
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ return true;
+ }
+
+ protected void checkConstraint(Collection<Wikitty> wikitties) {
+ for(Wikitty w : wikitties) {
+ for(WikittyExtension ext : w.getExtensions()) {
+ for (String fieldName : ext.getFieldNames()) {
+ FieldType type = ext.getFieldType(fieldName);
+ if (type.isNotNull()) {
+ if (null == w.getFieldAsObject(ext.getName(), fieldName)) {
+ throw new WikittyException(String.format(
+ "Field %s must not be null", fieldName));
+ }
+ }
+ }
+ }
+ }
+ }
+
+// @Override
+// public UpdateResponse store(String securityToken, WikittyTransaction transaction,
+// Collection<Wikitty> wikitties, boolean force) {
+// if (!(wikitties instanceof Set)) {
+// // use all time Set to prevent duplicated wikitty in collection
+// wikitties = new LinkedHashSet<Wikitty>(wikitties);
+// }
+// checkConstraint(wikitties);
+//
+// // update/store extension if necessary
+// Set<WikittyExtension> allExtensions = new LinkedHashSet<WikittyExtension>();
+// for (Wikitty w : wikitties) {
+// // collect all extensions used by all wikitties
+// allExtensions.addAll(w.getExtensions());
+// }
+//
+// // try to commit command
+// UpdateResponse extUpdate = getExtensionStorage().store(transaction, allExtensions);
+// UpdateResponse wikUpdate = getWikittyStorage().store(transaction, wikitties, force);
+// UpdateResponse indexUpdate = getSearchEngin().store(transaction, wikitties);
+//
+// UpdateResponse result = new UpdateResponse();
+// // prepare update client response
+// result.add(extUpdate);
+// result.add(wikUpdate);
+// result.add(indexUpdate);
+//
+// return result;
+// }
+ @Override
+ public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent result = store(securityToken, null, wikitties, force);
+ return result;
+ }
+
+ protected WikittyServiceEvent store(String securityToken,
+ WikittyTransaction transaction,
+ Collection<Wikitty> wikitties, boolean force) {
+ if (!(wikitties instanceof Set)) {
+ // use all time Set to prevent duplicated wikitty in collection
+ wikitties = new LinkedHashSet<Wikitty>(wikitties);
+ }
+ checkConstraint(wikitties);
+
+ // update/store extension if necessary
+ Set<WikittyExtension> allExtensions = new LinkedHashSet<WikittyExtension>();
+ for (Wikitty w : wikitties) {
+ // collect all extensions used by all wikitties
+ allExtensions.addAll(w.getExtensions());
+ }
+
+ boolean txCreated = false;
+ try {
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ // try to commit command
+ WikittyServiceEvent extUpdate =
+ getExtensionStorage().store(transaction, allExtensions);
+ WikittyServiceEvent wikUpdate =
+ getWikittyStorage().store(transaction, wikitties, force);
+ getSearchEngin().store(transaction, wikitties);
+
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ // prepare update client response
+ result.add(extUpdate);
+ result.add(wikUpdate);
+
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Can't store wikitty", eee);
+ }
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ List<String> result = getExtensionStorage().getAllExtensionIds(transaction);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't retrieve all extension's ids", eee);
+ }
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(
+ String securityToken, String extensionName) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ List<String> result = getExtensionStorage()
+ .getAllExtensionsRequires(transaction, extensionName);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException(String.format(
+ "Can't retrieve all required extension for %s", extensionName), eee);
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(
+ String securityToken, Collection<WikittyExtension> exts) {
+ WikittyServiceEvent result = storeExtension(securityToken, null, exts);
+ return result;
+ }
+
+ protected WikittyServiceEvent storeExtension(String securityToken,
+ WikittyTransaction transaction, Collection<WikittyExtension> exts) {
+ boolean txCreated = false;
+ try {
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ WikittyServiceEvent result =
+ getExtensionStorage().store(transaction, exts);
+
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Can't store extensions", eee);
+ }
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(
+ String securityToken, String extensionId) {
+ WikittyExtension result = restoreExtension(securityToken, null, extensionId);
+ return result;
+ }
+
+ protected WikittyExtension restoreExtension(
+ String securityToken, WikittyTransaction transaction, String extensionId) {
+ boolean txCreated = false;
+ try {
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ //split the id to ensure that version is normalized
+ String name = WikittyExtension.computeName(extensionId);
+ String version = WikittyExtension.computeVersion(extensionId);
+
+ WikittyExtension result = getExtensionStorage().restore(transaction, name, version);
+
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Can't restore extensions", eee);
+ }
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ WikittyExtension result = restoreExtensionLastVersion(securityToken, null, name);
+ return result;
+ }
+
+ protected WikittyExtension restoreExtensionLastVersion(String securityToken,
+ WikittyTransaction transaction, String name) {
+ String version = getExtensionStorage().getLastVersion(transaction, name);
+ if(version == null) {
+ return null;
+ }
+
+ boolean txCreated = false;
+ try {
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ WikittyExtension result = getExtensionStorage().restore(transaction, name, version);
+
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Can't store extensions", eee);
+ }
+ }
+
+ protected Wikitty restore(String securityToken,
+ WikittyTransaction transaction, String id) {
+ if (id == null) {
+ return null;
+ }
+ if (!getWikittyStorage().exists(transaction, id)) {
+ // object doesn't exist, we return null
+ return null;
+ }
+
+ if (getWikittyStorage().isDeleted(transaction, id)) {
+ // object deleted, we return null
+ return null;
+ }
+ Wikitty result = getWikittyStorage().restore(transaction, id);
+ if(result != null) {
+ result = upgradeData(securityToken, transaction, result);
+ }
+ return result;
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ List<Wikitty> result = restore(securityToken, null, ids);
+ return result;
+ }
+
+ protected List<Wikitty> restore(String securityToken,
+ WikittyTransaction transaction, List<String> ids) {
+
+ List<Wikitty> result = new ArrayList<Wikitty>();
+ boolean txCreated = false;
+ try {
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ for (String id : ids) {
+ Wikitty w = restore(securityToken, transaction, id);
+ // on l'ajoutde tout le temps, meme si w est nul lorsqu'il y a
+ // une demande et qu'elle echoue on ajout
+ // bien null, pour qu'il y ait une correspondance 1 pour 1
+ // avec la demande
+ result.add(w);
+ }
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Can't restore wikitty", eee);
+ }
+ }
+
+// @Override
+// public Wikitty restore(String securityToken, String id) {
+// WikittyTransaction transaction = new WikittyTransaction();
+// try {
+// transaction.begin();
+//
+// Wikitty result = restore(securityToken, transaction, id);
+//
+// transaction.commit();
+// return result;
+// } catch (Exception eee) {
+// transaction.rollback();
+// throw new WikittyException("Can't restore wikitty", eee);
+// }
+// }
+
+ // FIXME poussin 20101029 use WikittyServiceTransaction and remove other transaction
+ protected Wikitty upgradeData(String securityToken,
+ WikittyTransaction transaction, Wikitty wikitty) {
+ Wikitty result = wikitty;
+
+ Collection<WikittyExtension> extensions = wikitty.getExtensions();
+ for (WikittyExtension extension : extensions) {
+ String extensionName = extension.getName();
+
+ if (log.isDebugEnabled()) {
+ log.debug("extensionName=" + extensionName);
+ }
+
+ WikittyExtension currentExtension = extension;
+ String currentExtensionVersion = currentExtension.getVersion();
+
+ WikittyExtension lastExtension = restoreExtensionLastVersion(
+ securityToken, transaction, extensionName);
+ String lastExtensionVersion = lastExtension.getVersion();
+
+ if (log.isDebugEnabled()) {
+ log.debug("lastExtensionVersion=" + lastExtensionVersion);
+ }
+
+ WikittyExtensionMigration migration =
+ WikittyExtensionMigration.migrationRegistry.get(extensionName);
+ if (migration == null) {
+ migration = defaultExtensionMigration;
+ }
+
+ // Loop on between extension in wikitty and last version
+ while(WikittyUtil.versionGreaterThan(lastExtensionVersion, currentExtensionVersion)) {
+
+ // Get extension after the current version
+ String nextExtensionVersion =
+ WikittyUtil.incrementMajorRevision(currentExtensionVersion);
+ String nextExtensionId =
+ WikittyExtension.computeId(extensionName, nextExtensionVersion);
+ WikittyExtension nextExtension = restoreExtension(
+ securityToken, transaction, nextExtensionId);
+
+ if (log.isDebugEnabled()) {
+ log.debug("currentExtensionVersion=" + currentExtensionVersion);
+ log.debug("nextExtensionVersion=" + nextExtensionVersion);
+ }
+
+ // Test if extension is never use in this version
+ if(nextExtension != null) {
+ result = migration.migrate(this, result,
+ currentExtension, nextExtension);
+ currentExtension = nextExtension;
+ }
+
+ // Follow
+ currentExtensionVersion = nextExtensionVersion;
+ }
+ }
+
+ return result;
+ }
+
+ protected WikittyServiceEvent delete(String securityToken, WikittyTransaction transaction,
+ Collection<String> ids) throws WikittyException {
+ // work only on valid id
+ Collection<Wikitty> storedWikitties = new LinkedHashSet<Wikitty>();
+ // copy ids because we can remove some element, and modify it
+ // use set to prevent id duplication and preformance (contains method call)
+ Set<String> idSet = new LinkedHashSet<String>(ids);
+ for (Iterator<String> i = idSet.iterator(); i.hasNext();) {
+ String id = i.next();
+ // test if wikitty exists
+ if (!getWikittyStorage().exists(transaction, id)) {
+ // don't exist, remove this id in id list
+ i.remove();
+ // go to the next id, because this id doesn't exist and can't
+ // be used in tree
+ continue;
+ }
+ if (getWikittyStorage().isDeleted(transaction, id)) {
+ // already deleted, remove this id in id list
+ i.remove();
+ // go to the next id, because this id already deleted and can't
+ // be used in tree
+ continue;
+ }
+
+ // Store node with have deleted node as parent
+ Criteria criteria =
+ Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT, id).criteria();
+ List<String> wikittyNodesId = findAllByCriteria(
+ securityToken, transaction, criteria).getAll();
+ for (String wikittyNodeId : wikittyNodesId) {
+ if(!idSet.contains(wikittyNodeId)) {
+ Wikitty treeNode = restore(
+ securityToken, transaction, wikittyNodeId);
+ WikittyTreeNodeHelper.setParent(treeNode, null);
+ storedWikitties.add(treeNode);
+ }
+ }
+
+ // Store node with have deleted child
+ criteria = Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_ATTACHMENT, id).criteria();
+ wikittyNodesId = findAllByCriteria(
+ securityToken, transaction, criteria).getAll();
+ for (String wikittyNodeId : wikittyNodesId) {
+ if(!idSet.contains(wikittyNodeId)) {
+ Wikitty treeNode = restore(
+ securityToken, transaction, wikittyNodeId);
+ WikittyTreeNodeHelper.removeAttachment(treeNode, id);
+ storedWikitties.add(treeNode);
+ }
+ }
+ }
+
+ WikittyServiceEvent eventDelete =
+ getWikittyStorage().delete(transaction, idSet);
+ getSearchEngin().delete(transaction, idSet);
+
+ WikittyServiceEvent eventStore =
+ store(securityToken, transaction, storedWikitties, false);
+
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ result.add(eventDelete);
+ result.add(eventStore);
+
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids){
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ WikittyServiceEvent result = delete(securityToken, transaction, ids);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't delete wikitty", eee);
+ }
+ }
+
+ /**
+ * Use with caution : It will delete ALL indexes from search engine !
+ * This operation should be disabled in production environment.
+ */
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+
+ WikittyServiceEvent result = clear(securityToken, transaction);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't clear all data", eee);
+ }
+ }
+
+ /**
+ * Use with caution : It will delete ALL indexes from search engine !
+ * This operation should be disabled in production environment.
+ */
+ protected WikittyServiceEvent clear(String securityToken, WikittyTransaction tx) {
+ getSearchEngin().clear(tx);
+ WikittyServiceEvent eventWik = getWikittyStorage().clear(tx);
+ WikittyServiceEvent eventExt = getExtensionStorage().clear(tx);
+
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ result.add(eventWik);
+ result.add(eventExt);
+ return result;
+ }
+
+ /**
+ * Assume that this PagedResult contains wikitty id as result and
+ * return new PagedResult with Wikitty instance
+ */
+ @Override
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ PagedResult<String> result = findAllByCriteria(securityToken, null, criteria);
+ return result;
+ }
+
+ protected PagedResult<String> findAllByCriteria(String securityToken,
+ WikittyTransaction transaction, Criteria criteria) {
+ try {
+ boolean txCreated = false;
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ PagedResult<String> result =
+ getSearchEngin().findAllByCriteria(transaction, criteria);
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Error during find", eee);
+ }
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ Wikitty result = findByCriteria(securityToken, null, criteria);
+ return result;
+ }
+
+ protected Wikitty findByCriteria(String securityToken,
+ WikittyTransaction transaction, Criteria criteria) {
+ try {
+ boolean txCreated = false;
+ if (transaction == null) {
+ transaction = new WikittyTransaction();
+ txCreated = true;
+ transaction.begin();
+ }
+
+ criteria.setFirstIndex(0).setEndIndex(1);
+ PagedResult<String> pages = findAllByCriteria(
+ securityToken, transaction, criteria);
+
+ Wikitty result = null;
+ if (pages.size() > 0) {
+ String id = pages.getFirst();
+ result = restore(securityToken, transaction, id);
+ }
+
+ if (txCreated) {
+ transaction.commit();
+ }
+ return result;
+ } catch (WikittyException ex) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw ex;
+ } catch (Exception eee) {
+ if (transaction != null) {
+ transaction.rollback();
+ }
+ throw new WikittyException("Error during find", eee);
+ }
+ }
+
+ protected WikittyTree restoreTree(String securityToken,
+ WikittyTransaction transaction, String wikittyId) {
+ Wikitty w = restore(securityToken, transaction, wikittyId);
+ if(w == null) {
+ return null;
+ }
+
+ if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
+ throw new WikittyException(String.format(
+ "Wikitty '%s' do not handle extension %s",
+ wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
+ }
+ WikittyTree tree = new WikittyTree();
+ WikittyTreeNode node = new WikittyTreeNodeImpl(w);
+ tree.setNode(node);
+
+ WikittyTreeNodeImpl exempleNode = new WikittyTreeNodeImpl();
+ exempleNode.setParent(wikittyId);
+
+ Criteria criteria = Search.query(exempleNode.getWikitty()).criteria()
+ .setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS);
+ PagedResult<String> childNodesId = findAllByCriteria(
+ securityToken, transaction, criteria);
+ for (String childNodeId : childNodesId.getAll()) {
+ tree.addChild(restoreTree(securityToken, transaction, childNodeId));
+ }
+
+ return tree;
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ WikittyTree tree = restoreTree(securityToken, transaction, wikittyId);
+
+ transaction.commit();
+ return tree;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't restore tree", eee);
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String thesaurusId) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ WikittyServiceEvent result = deleteTree(securityToken, transaction, thesaurusId);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't delete tree", eee);
+ }
+ }
+
+ /**
+ * Delete specified treenode and sub treenode.
+ *
+ * @param securityToken security token
+ * @param transaction transaction
+ * @param treeNodeId thesaurusId to delete
+ * @return all id of delete nodes
+ */
+ protected WikittyServiceEvent deleteTree(String securityToken, WikittyTransaction transaction, String treeNodeId) {
+ List<String> allTreeNodeId = getRecursiveTreeNodeId(securityToken, transaction, treeNodeId);
+ WikittyServiceEvent result = delete(securityToken, transaction, allTreeNodeId);
+ return result;
+ }
+
+ /**
+ * Get recursive id of tree node children of {@code treeNodeId}.
+ *
+ * @param securityToken security token
+ * @param transaction transaction
+ * @param treeNodeId tree node id
+ * @return all id of {@code treeNodeId}'s children
+ */
+ protected List<String> getRecursiveTreeNodeId(String securityToken, WikittyTransaction transaction, String treeNodeId) {
+
+ Search search = Search.query();
+ search = search.eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT, treeNodeId);
+ Criteria criteria = search.criteria();
+
+ PagedResult<String> childTreeNodeIds = findAllByCriteria(securityToken, transaction, criteria);
+ List<String> treeNodeIds = new ArrayList<String>();
+ treeNodeIds.add(treeNodeId);
+ for (String childTreeNodeId : childTreeNodeIds.getAll()) {
+ List<String> subTreeNodeIds = getRecursiveTreeNodeId(securityToken, transaction, childTreeNodeId);
+ treeNodeIds.addAll(subTreeNodeIds);
+ }
+ return treeNodeIds;
+ }
+
+ @Override
+ public Map.Entry<WikittyTreeNode, Integer> restoreNode(String securityToken,
+ String wikittyId, Criteria filter) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ Wikitty w = restore(securityToken, transaction, wikittyId);
+ if(w == null) {
+ transaction.commit();
+ return null;
+ }
+
+ if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
+ throw new WikittyException(String.format(
+ "Wikitty '%s' do not handle extension %s",
+ wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
+ }
+
+ WikittyTreeNode node = new WikittyTreeNodeImpl(w);
+ Integer count = getSearchEngin().findNodeCount(transaction, w, filter);
+
+ HashMap.SimpleEntry<WikittyTreeNode, Integer> result =
+ new SimpleEntry<WikittyTreeNode, Integer>(node, count);
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't restore node", eee);
+ }
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
+ String wikittyId, Criteria filter) {
+ WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ transaction.begin();
+
+ Wikitty w = restore(securityToken, transaction, wikittyId);
+ if(w == null) {
+ transaction.commit();
+ return null;
+ }
+
+ if ( !w.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE) ) {
+ throw new WikittyException(String.format(
+ "Wikitty '%s' do not handle extension %s",
+ wikittyId, WikittyTreeNode.EXT_WIKITTYTREENODE ));
+ }
+
+ Map<WikittyTreeNode, Integer> result = new LinkedHashMap<WikittyTreeNode, Integer>();
+
+ Map<String, Integer> search = getSearchEngin().findAllChildrenCount(
+ transaction, w, filter);
+ Set<Entry<String, Integer>> children = search.entrySet();
+ for (Entry<String, Integer> child : children) {
+ Integer count = child.getValue();
+
+ String id = child.getKey();
+ Wikitty wikitty = restore(securityToken, transaction, id);
+ WikittyTreeNode node = new WikittyTreeNodeImpl(wikitty);
+
+ result.put(node, count);
+ }
+
+ transaction.commit();
+ return result;
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't restore children", eee);
+ }
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken,
+ String wikittyId, String version) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void syncEngin(final String securityToken) {
+ final WikittyTransaction transaction = new WikittyTransaction();
+ try {
+ final int numberForCommit = 1000;
+ final WikittySearchEngin searchEngin = getSearchEngin();
+ final List<Wikitty> wikitties = new ArrayList<Wikitty>(numberForCommit);
+
+ transaction.begin();
+ searchEngin.clear(transaction);
+ transaction.commit();
+ transaction.begin();
+
+ getWikittyStorage().scanWikitties(transaction, new WikittyStorage.Scanner() {
+ int count = 0;
+
+ @Override
+ public void scan(String wikittyId) {
+ Wikitty wikitty = restore(securityToken, transaction, wikittyId);
+ Date deleteDate = wikitty.getDeleteDate();
+ if(deleteDate == null) {
+ count ++;
+ wikitties.add(wikitty);
+
+ if(count == numberForCommit) {
+ // Reindex
+ searchEngin.store(transaction, wikitties);
+ transaction.commit();
+ // Reinit
+ count = 0;
+ wikitties.clear();
+ transaction.begin();
+ }
+ }
+ }
+ });
+
+ // Last wikitties
+ searchEngin.store(transaction, wikitties);
+ transaction.commit();
+ } catch (Exception eee) {
+ transaction.rollback();
+ throw new WikittyException("Can't sync searchable index with data", eee);
+ }
+ }
+
+ /**
+ * Question:
+ * <li> on ne force pas le store de wikitty, ils vont donc avoir potentiellement
+ * des versions differentes sur plusieurs serveurs, est-ce problematique ?
+ * <li> on ne passe pas la date de suppression des wikitties, ils vont donc
+ * avoir différente date de suppression sur différent serveur, est-ce problematique ?
+ *
+ *
+ * @param securityToken
+ * @param events
+ * @return
+ */
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ // indique qu'il faut vider la base avant de faire les ajouts
+ boolean mustClear = false;
+
+ // tous les objets a sauver
+ Map<String, Wikitty> toAddWikitty = new LinkedHashMap<String, Wikitty>();
+ // tous les id a supprimer
+ Map<String, Date> toRemoveWikitty = new LinkedHashMap<String, Date>();
+
+ // toutes les extensions a sauver
+ Set<WikittyExtension> toAddExt = new LinkedHashSet<WikittyExtension>();
+
+ // recherche un event avec un clear pour ne pas jouer des events inutiles
+ // recherche un store + delete du meme wikitty
+ // recherche le dernier store du wikitty
+ for (WikittyServiceEvent e : events) {
+ // check clear must be the first, if event have clear and other type
+ // clear is all time play first
+ if (e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
+ || e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
+ mustClear = true;
+ toAddWikitty.clear();
+ toRemoveWikitty.clear();
+ toAddExt.clear();
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
+ for (Wikitty w : e.getWikitties().values()) {
+ toAddWikitty.put(w.getId(), w);
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
+ for (Map.Entry<String, Date> entry : e.getRemoveDate().entrySet()) {
+ toAddWikitty.remove(entry.getKey());
+ toRemoveWikitty.put(entry.getKey(), entry.getValue());
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
+ for (WikittyExtension ext : e.getExtensions().values()) {
+ toAddExt.add(ext);
+ }
+ }
+ }
+
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+
+ // Actuellement il n'y a pas moyen de supprimer une extension (par surete)
+ // donc on ne fait rien avec toRemoveExt
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ if (mustClear) {
+ WikittyServiceEvent eventClear = clear(securityToken, tx);
+ result.add(eventClear);
+ }
+ WikittyServiceEvent eventStoreExtension =
+ storeExtension(securityToken, tx, toAddExt);
+ result.add(eventStoreExtension);
+
+ WikittyServiceEvent eventStoreWikitty =
+ store(securityToken, tx, toAddWikitty.values(), false);
+ result.add(eventStoreWikitty);
+
+ WikittyServiceEvent eventDeleteWikitty =
+ delete(securityToken, tx, toRemoveWikitty.keySet());
+ result.add(eventDeleteWikitty);
+
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't replay data", eee);
+ }
+
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+ boolean result = getWikittyStorage().exists(null, wikittyId);
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't test existance", eee);
+ }
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+ boolean result = getWikittyStorage().isDeleted(tx, wikittyId);
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't test existance", eee);
+ }
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceInMemory.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceInMemory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceInMemory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,120 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import org.nuiton.wikitty.storage.WikittySearchEnginInMemory;
+import org.nuiton.wikitty.storage.WikittyExtensionStorageInMemory;
+import org.nuiton.wikitty.storage.WikittyStorageInMemory;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
+
+/**
+ * In memory implementation of WikittyService, currently used for test only.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceInMemory extends WikittyServiceImpl {
+
+ //FIXME InMemory implementation is not usable for production. Must be reviewed.
+ //FIXME The version increment must be done in 'prepare' method
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceInMemory.class);
+
+ /**
+ * if persistenceFile is not null, serialize all data to disk during store
+ * operation and the file is reloaded during init
+ */
+ protected File persistenceFile = null;
+
+ public WikittyServiceInMemory(ApplicationConfig config) {
+ super(new WikittyExtensionStorageInMemory(),
+ new WikittyStorageInMemory(),
+ null);
+ searchEngin = new WikittySearchEnginInMemory(
+ (WikittyStorageInMemory) wikittyStorage);
+
+ if (config != null) {
+ boolean persist = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey());
+ if (persist) {
+ persistenceFile = config.getOptionAsFile(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey());
+ restoreFromPersistenceFile(persistenceFile);
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ saveToPersistenceFile(persistenceFile);
+
+ super.finalize();
+ }
+
+ protected void restoreFromPersistenceFile(File persistenceFile) {
+ if (persistenceFile != null && persistenceFile.exists()) {
+ try {
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(
+ persistenceFile));
+ ((WikittyExtensionStorageInMemory)extensionStorage).setExtensions((Map) in.readObject());
+ ((WikittyStorageInMemory)wikittyStorage).setWikitties((Map) in.readObject());
+ in.close();
+ } catch (Exception eee) {
+ log.error("Can't read data file " + persistenceFile, eee);
+ }
+ }
+ }
+
+ public void saveToPersistenceFile(File persistenceFile) {
+ if (persistenceFile != null) {
+ try {
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
+ persistenceFile));
+ out.writeObject(((WikittyExtensionStorageInMemory)extensionStorage).getExtensions());
+ out.writeObject(((WikittyStorageInMemory)wikittyStorage).getWikitties());
+ out.close();
+ } catch (IOException eee) {
+ log.error("Can't write data file " + persistenceFile, eee);
+ }
+ }
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceListener.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceListener.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceListener.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+/**
+ * Permet d'ajouter des listeners sur les methodes de modification de
+ * WikittyService.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public interface WikittyServiceListener {
+
+ // this constant must be up to date with real method name
+ // this is used during fire event
+ final static public String PUT_WIKITTY_METHOD = "putWikitty";
+ final static public String REMOVE_WIKITTY_METHOD = "removeWikitty";
+ final static public String CLEAR_WIKITTY_METHOD = "clearWikitty";
+ final static public String PUT_EXTENSION_METHOD = "putExtension";
+ final static public String REMOVE_EXTENSION_METHOD = "removeExtension";
+ final static public String CLEAR_EXTENSION_METHOD = "clearExtension";
+
+ public void putWikitty(WikittyServiceEvent event);
+ public void removeWikitty(WikittyServiceEvent event);
+ public void clearWikitty(WikittyServiceEvent event);
+
+ /** toto[1.0] */
+ public void putExtension(WikittyServiceEvent event);
+ public void clearExtension(WikittyServiceEvent event);
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceNotifier.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceNotifier.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceNotifier.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,710 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.ListenerSet;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyServiceFactory;
+import org.nuiton.wikitty.WikittyTree;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+
+/**
+ * Wikitty service notifier.
+ *
+ * Currently based on jgroups.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class WikittyServiceNotifier implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceNotifier.class);
+
+ /** Service to delegate. */
+ protected WikittyService ws;
+
+ /** Wikitty service listener (all event). */
+ protected ListenerSet<WikittyServiceListener> allWikittyServiceListeners;
+
+ /** Wikitty service listener (only for local event). */
+ protected ListenerSet<WikittyServiceListener> localWikittyServiceListeners;
+
+ /** Wikitty service listener (only for remote event). */
+ protected ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners;
+
+ /** notifier */
+ protected WikittyServiceListener notifier;
+
+ /**
+ * Tous les events en attentent d'etre envoyer aux listeners
+ */
+ protected LinkedBlockingQueue<WikittyServiceEvent> eventToSend;
+
+ /** thread utilise pour evoyer les events */
+ protected EventThread eventThread;
+
+ /**
+ * Constructor with configuration.
+ *
+ * @param ws delegate service
+ * @param props properties (can be null)
+ */
+ public WikittyServiceNotifier(ApplicationConfig config, WikittyService ws) {
+ // service
+ this.ws = ws;
+
+ // listeners
+ allWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
+ localWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
+ remoteWikittyServiceListeners = new ListenerSet<WikittyServiceListener>();
+
+ eventToSend = new LinkedBlockingQueue<WikittyServiceEvent>();
+
+ eventThread = new EventThread(eventToSend,
+ allWikittyServiceListeners, localWikittyServiceListeners,
+ remoteWikittyServiceListeners);
+
+ // can be null according to default constructor
+ if (config != null) {
+ notifier = new RemoteNotifier(config, this);
+ }
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ // not delegated
+ switch (type) {
+ case ALL :
+ synchronized(allWikittyServiceListeners) {
+ allWikittyServiceListeners.add(listener);
+ }
+ break;
+ case LOCAL :
+ synchronized(localWikittyServiceListeners) {
+ localWikittyServiceListeners.add(listener);
+ }
+ break;
+ case REMOTE :
+ synchronized(remoteWikittyServiceListeners) {
+ remoteWikittyServiceListeners.add(listener);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ // not delegated
+ switch (type) {
+ case ALL :
+ synchronized(allWikittyServiceListeners) {
+ allWikittyServiceListeners.remove(listener);
+ }
+ break;
+ case LOCAL :
+ synchronized (localWikittyServiceListeners) {
+ localWikittyServiceListeners.remove(listener);
+ }
+ break;
+ case REMOTE :
+ synchronized(remoteWikittyServiceListeners) {
+ remoteWikittyServiceListeners.remove(listener);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public String login(String login, String password) {
+ return ws.login(login, password);
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ ws.logout(securityToken);
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ return ws.canWrite(securityToken, wikitty);
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ return ws.canDelete(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ return ws.canRead(securityToken, wikittyId);
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ WikittyServiceEvent result = ws.clear(securityToken);
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
+
+ // notify listeners
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ // no notification
+ return ws.getAllExtensionIds(securityToken);
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(
+ String securityToken, String extensionName) {
+ // no notification
+ return ws.getAllExtensionsRequires(securityToken, extensionName);
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ WikittyServiceEvent result = ws.storeExtension(securityToken, exts);
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ // no notification
+ return ws.restoreExtension(securityToken, id);
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ // no notification
+ return ws.restoreExtensionLastVersion(securityToken, name);
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ // no notification
+ return ws.restore(securityToken, ids);
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ WikittyServiceEvent result = ws.delete(securityToken, ids);
+ // notify listeners
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(String securityToken,
+ Criteria criteria) {
+ // no notification
+ return ws.findAllByCriteria(securityToken, criteria);
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ // no notification
+ return ws.findByCriteria(securityToken, criteria);
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ // no notification
+ return ws.restoreTree(securityToken, wikittyId);
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String wikittyId) {
+ WikittyServiceEvent result = ws.deleteTree(securityToken, wikittyId);
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId,
+ Criteria filter) {
+ // no notification
+ return ws.restoreNode(securityToken, wikittyId, filter);
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
+ String wikittyId, Criteria filter) {
+ // no notification
+ return ws.restoreChildren(securityToken, wikittyId, filter);
+ }
+
+ @Override
+ public Wikitty restoreVersion(
+ String securityToken, String wikittyId, String version) {
+ // no notification
+ return ws.restoreVersion(securityToken, wikittyId, version);
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ // no notification
+ ws.syncEngin(securityToken);
+ }
+
+ /**
+ * Fire event to all registred listener.
+ *
+ * Take care about {@link WikittyServiceEvent#isRemote()} for fire.
+ *
+ * @param event event to fire
+ */
+ protected void fireEvent(final WikittyServiceEvent event) {
+ // ajout d'un thread, car si les listener doit
+ // ouvrir une transaction WikittyTransaction
+ // alors que celui qui lance l'event en a une ouverte
+ // cela cause une exception JTA
+ EventThread thread = getEventThread();
+
+ // si le thread de notification est en cours d'arret on leve une exception
+ if (thread.stopAsked()) {
+ throw new WikittyException(
+ "Event thread dispatcher is stopped, no more event can be send");
+ } else {
+ eventToSend.offer(event);
+
+ if (!thread.isAlive()) {
+ // on demarre le thread que lorsqu'il y a le premier event d'arrive
+ thread.start();
+ }
+ }
+ }
+
+ /**
+ * fire event passed in argument. Before fire, change source to current
+ * WikittyServiceNotifier and set remote event to true.
+ */
+ public void processRemoteEvent(WikittyServiceEvent event) {
+ //source is transient, add it here :
+ event.setSource(this);
+ event.setRemote(true); // received event became remote
+ fireEvent(event);
+ }
+
+ /**
+ * Retourne le dernier thread utiliser pour envoyer les events.
+ *
+ * @return
+ */
+ public EventThread getEventThread() {
+ return eventThread;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ getEventThread().askStop();
+ super.finalize();
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ WikittyServiceEvent result = ws.replay(securityToken, events);
+ // notify listeners
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return ws.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
+ /**
+ * Thread utilise pour envoyer les events. On rend accessible ce thread
+ * pour pouvoir y acceder depuis l'exterieur (pour l'instant pour les tests
+ * mais peut-etre plus tard du monitoring). Il permet a un thread d'attendre
+ * qu'un evenement leve a une certaine heure est bien ete dispatchee grace a
+ * la methode waitfor
+ */
+ static public class EventThread extends Thread {
+
+ protected boolean mustBeRunning = true;
+
+ protected SortedMap<Long, Object> waiter = new TreeMap<Long, Object>();
+ /**
+ * reference vers la collection qui contient les events a envoyer
+ */
+ protected LinkedBlockingQueue<WikittyServiceEvent> eventToSend;
+
+ /** Wikitty service listener (all event). */
+ protected ListenerSet<WikittyServiceListener> allWikittyServiceListeners;
+
+ /** Wikitty service listener (only for local event). */
+ protected ListenerSet<WikittyServiceListener> localWikittyServiceListeners;
+
+ /** Wikitty service listener (only for remote event). */
+ protected ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners;
+
+ /** heure du dernier event envoye */
+ protected long lastEventTime = 0;
+
+ public EventThread(LinkedBlockingQueue<WikittyServiceEvent> eventToSend,
+ ListenerSet<WikittyServiceListener> allWikittyServiceListeners,
+ ListenerSet<WikittyServiceListener> localWikittyServiceListeners,
+ ListenerSet<WikittyServiceListener> remoteWikittyServiceListeners) {
+ super("wikitty-event-thread");
+ this.eventToSend = eventToSend;
+ this.allWikittyServiceListeners = allWikittyServiceListeners;
+ this.localWikittyServiceListeners = localWikittyServiceListeners;
+ this.remoteWikittyServiceListeners = remoteWikittyServiceListeners;
+ }
+
+ /**
+ * demande l'arret du thread, ne doit être appeler que par le finalize
+ * du WikittyServiceNotifier
+ */
+ protected void askStop() {
+ this.mustBeRunning = false;
+ }
+
+ /**
+ * retourne vrai si on a demande l'arret du thread
+ * @return
+ */
+ public boolean stopAsked() {
+ return !mustBeRunning;
+ }
+
+ /**
+ * thread that want wait for particulare event to be processed, can be
+ * call this method with event time in argument. Used only in unit test
+ * but this is necessary for test.
+ */
+ public void waitFor(long eventTime) throws InterruptedException {
+ Object mutex = null;
+ sleep(1); // sleep 1 millis to prevent problem with 2 events in same millis
+ synchronized (waiter) {
+ if (eventTime <= lastEventTime) {
+ // le thread demande a attendre un event deja passe
+ // on le met donc pas en attente
+ if (log.isDebugEnabled()) {
+ log.debug("event deja passe " + eventTime + " <= " + lastEventTime);
+ }
+ return;
+ }
+ mutex = waiter.get(eventTime);
+ if (mutex == null) {
+ mutex = new Object();
+ waiter.put(eventTime, mutex);
+ }
+ }
+ synchronized(mutex) {
+ mutex.wait();
+ }
+ }
+
+ @Override
+ public void run() {
+ while(mustBeRunning) {
+ processEventQueue();
+ }
+ // le thread est arrete, force l'envoi de tous les events pour
+ // liberer correctement tous les threads en attente
+ // plus aucun event ne doit etre accepte dans la queue (voir method fireEvent)
+ processEventQueue();
+ }
+
+ protected void processEventQueue() {
+ try {
+ WikittyServiceEvent event;
+ // on attend pas indefiniment un event, car il faut verifier
+ // aussi que personne n'a arrete le thread
+ while (null != (event = eventToSend.poll(5, TimeUnit.SECONDS))) {
+ try {
+ synchronized (allWikittyServiceListeners) {
+ for(WikittyServiceEvent.WikittyEventType type : event.getType()) {
+ allWikittyServiceListeners.fire(
+ type.listenerMethodName, event);
+ }
+ }
+ } catch (Exception eee) {
+ log.error("Can't notify listener", eee);
+ }
+ try {
+ if (event.isRemote()) {
+ synchronized (remoteWikittyServiceListeners) {
+ for (WikittyServiceEvent.WikittyEventType type : event.getType()) {
+ remoteWikittyServiceListeners.fire(
+ type.listenerMethodName, event);
+ }
+ }
+ } else {
+ synchronized (localWikittyServiceListeners) {
+ for (WikittyServiceEvent.WikittyEventType type : event.getType()) {
+ localWikittyServiceListeners.fire(
+ type.listenerMethodName, event);
+ }
+ }
+ }
+ } catch (Exception eee) {
+ log.error("Can't notify listener", eee);
+ }
+ synchronized (waiter) {
+ // on met a jour l'heure du dernier event envoye
+ lastEventTime = event.getTime();
+
+ // on previent les threads en attente si besoin
+
+ // dans un premier temps on ne recupere que ceux
+ // inferieur a event.getTime()
+ SortedMap<Long, Object> subwaiter =
+ waiter.headMap(event.getTime());
+ for (Iterator<Map.Entry<Long, Object>> i = subwaiter.entrySet().iterator(); i.hasNext();) {
+ Object mutex = i.next().getValue();
+ i.remove();
+ synchronized (mutex) {
+ mutex.notifyAll();
+ }
+ }
+ // dans un second temps on verifie si le suivant ne
+ // serait pas egal a event.getTime()
+ if (!waiter.isEmpty()) {
+ Long time = waiter.firstKey();
+ // il pourrait y avoir plusieurs event avec la meme heure
+ // il faut bien tous les liberer
+ while (time.equals(event.getTime())) {
+ // il est bien egal on l'enleve aussi
+ Object mutex = waiter.remove(time);
+ synchronized (mutex) {
+ mutex.notifyAll();
+ }
+
+ if (!waiter.isEmpty()) {
+ time = waiter.firstKey();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+ } catch (InterruptedException eee) {
+ log.error("Notification thread error", eee);
+ }
+ }
+ };
+
+ /**
+ * This interface must be implemented to send and received remote message.
+ * Only sendMessage method is in interface but you must write receive
+ * method too, but this method is protocol specific and can't appear in
+ * interface
+ */
+ static public interface RemoteNotifierTransporter {
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ public void sendMessage(WikittyServiceEvent event) throws Exception;
+ }
+
+ /**
+ * Class used to notify remote listener. This class is realy activate
+ * only if wikitty.notifier.transporter.class configuration is found and
+ * wikitty.service.event.propagateEvent is true
+ */
+ static public class RemoteNotifier implements WikittyServiceListener {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(RemoteNotifier.class);
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+
+ /**
+ * Indique si les objects sont propages (true) vers les autres caches ou
+ * simplement supprimes des autres caches (false).
+ *
+ * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION
+ */
+ protected boolean propagateEvent = false;
+ protected RemoteNotifierTransporter transporter;
+
+ public RemoteNotifier(ApplicationConfig config, WikittyServiceNotifier ws) {
+ // can be null according to default constructor
+ if (config != null) {
+ this.ws = ws;
+
+ propagateEvent = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_EVENT_PROPAGATE.getKey());
+ if (log.isDebugEnabled()) {
+ log.debug("Set propagateEvent option to " + propagateEvent);
+ }
+
+ if (propagateEvent) {
+ transporter = WikittyServiceFactory.buildTransporter(config, ws);
+ // add this as listener when transporter is created without error
+ ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference
+ }
+ }
+ if (log.isInfoEnabled()) {
+ if (transporter == null) {
+ log.info("RemoteNotifier synchronisation not used ");
+ } else {
+ log.info("RemoteNotifier transporter: " + transporter.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * Send a jgroup message to all other channel member.
+ *
+ * @param event message to send
+ */
+ protected void sendMessage(WikittyServiceEvent event) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Try to send message : " + event);
+ }
+
+ transporter.sendMessage(event);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Message is sent : " + event);
+ }
+ } catch (Exception eee) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't send message", eee);
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[])
+ */
+ @Override
+ public void putWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate putWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[])
+ */
+ @Override
+ public void removeWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate removeWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty()
+ */
+ @Override
+ public void clearWikitty(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate clearWikitty event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[])
+ */
+ @Override
+ public void putExtension(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate putExtension event");
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
+ */
+ @Override
+ public void clearExtension(WikittyServiceEvent event) {
+ if (propagateEvent) {
+ sendMessage(event);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Not master cache, do not propagate clearExtension event");
+ }
+ }
+ }
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,836 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 CodeLutin
+ * %%
+ * 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.services;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyAuthorisation;
+import org.nuiton.wikitty.entities.WikittyAuthorisationHelper;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyGroup;
+import org.nuiton.wikitty.entities.WikittyGroupHelper;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyMetaExtensionUtil;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.entities.WikittyTokenHelper;
+import org.nuiton.wikitty.WikittyTree;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.entities.WikittyUserHelper;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ *
+ * FIXME add security policy level two on wikittyAuthorisation to prevent writing
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceSecurity implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceSecurity.class);
+
+ protected WikittyServiceEnhanced ws;
+
+ /** cache de l'id du groupe AppAdmin */
+ transient protected String appAdminGroupId = null;
+
+ /**
+ *
+ * @param config not use currently but needed in futur
+ * @param ws
+ */
+ public WikittyServiceSecurity(ApplicationConfig config, WikittyService ws) {
+ this.ws = new WikittyServiceEnhanced(ws);
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ ws.addWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ ws.addWikittyServiceListener(listener, type);
+ }
+
+ @Override
+ public String login(String login, String password) {
+ Wikitty user = ws.findByCriteria(null, Search.query().eq(
+ WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
+ if (user == null) {
+ throw new IllegalArgumentException(String.format("no such account '%s'", login));
+ } else {
+ // check password is valid
+ if (WikittyUserHelper.getPassword(user).equals(password)) {
+ String tokenId = WikittyUtil.genSecurityTokenId();
+ Wikitty wikittyToken = new WikittyImpl(tokenId);
+ // force add extension to wikitty
+ WikittyTokenHelper.addExtension(wikittyToken);
+ WikittyTokenHelper.setUser(wikittyToken, user.getId());
+ ws.store(null, Arrays.asList(wikittyToken), false);
+ log.debug(String.format("token '%s' is for login '%s'",
+ tokenId, login));
+ return tokenId;
+ } else {
+ throw new SecurityException("bad password");
+ }
+ }
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ if (securityToken == null) {
+ throw new IllegalArgumentException("security token is null");
+ } else {
+ getUserId(securityToken); // will throw exception if token is not valid
+ ws.delete(securityToken, Arrays.asList(securityToken));
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ String userId = getUserId(securityToken);
+ if (isAppAdmin(securityToken, userId)) {
+ // seul les AppAdmin on le droit a cette method
+ WikittyServiceEvent result = ws.clear(securityToken);
+ return result;
+ } else {
+ throw new SecurityException(_("user %s can't clear data", userId));
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ String userId = getUserId(securityToken);
+ for (WikittyServiceEvent e : events) {
+ if (e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
+ || e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
+ if (isAppAdmin(securityToken, userId)) {
+ // seul les AppAdmin on le droit a cette method
+ // les AppAdmin on meme le droit de tout faire, donc on
+ // peut sortir de la boucle
+ break;
+ } else {
+ throw new SecurityException(_("user %s can't clear data", userId));
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
+ checkStore(securityToken, e.getWikitties().values());
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
+ checkDelete(securityToken, e.getRemoveDate().keySet());
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
+ checkStoreExtension(securityToken, e.getExtensions().values());
+ }
+ }
+ WikittyServiceEvent result = ws.replay(securityToken, events);
+ return result;
+ }
+
+
+ /**
+ * if app-admin group exists, return true if given userId is app-admin
+ * if app-admin group doesn't exists, return true if user is anonymous
+ */
+ protected boolean userIsAnonymousOrAppAdmin(String securityToken, String userId) {
+ boolean userIsAnonymousOrAppAdmin = false;
+
+ if (getAppAdminGroup(securityToken) == null) {
+ if (securityToken == null) {
+ // user is anonymous
+ userIsAnonymousOrAppAdmin = true;
+ }
+ } else {
+ if (isAppAdmin(securityToken, userId)) {
+ // user is appAdmin
+ userIsAnonymousOrAppAdmin = true;
+ }
+ }
+
+ return userIsAnonymousOrAppAdmin;
+ }
+
+ @Override
+ public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+ Collection<Wikitty> wikittiesToStore = checkStore(securityToken, wikitties);
+ WikittyServiceEvent result = ws.store(securityToken, wikittiesToStore, force);
+ return result;
+ }
+
+ /**
+ * FIXME poussin 20101028 pourquoi retourner une liste ? soit on a le droit
+ * de faire un store sur tout, on bien on refuse avec une exception
+ * verifier que result ne sert bien a rien (surtout pas a filtrer)
+ *
+ * @param securityToken
+ * @param wikitties
+ * @return
+ */
+ protected Collection<Wikitty> checkStore(String securityToken, Collection<Wikitty> wikitties) {
+ String userId = getUserId(securityToken);
+ List<Wikitty> result = new ArrayList<Wikitty>();
+ for (Wikitty wikitty : wikitties) {
+
+ // usual case, a user want to store a wikitty
+ Wikitty oldVersion = ws.restore(securityToken, wikitty.getId());
+
+ Collection<String> newExtensions = new ArrayList<String>(wikitty.getExtensionNames());
+ if (oldVersion != null) {
+ // we already checked the rights for those extension
+ // re-do the check has too much cost, avoid it
+ newExtensions.removeAll(oldVersion.getExtensionNames());
+ }
+
+ // check that **reader** right on Security for all extension
+ for (String extensionName: newExtensions) {
+
+ Wikitty extensionRights = restoreExtensionAuthorisation(
+ securityToken, extensionName);
+ boolean canCreate = extensionRights == null ||
+ canRead(securityToken, userId, null, extensionRights);
+ if ( ! canCreate ) {
+ throw new SecurityException(_(
+ "user %s can't create instance of extension %s",
+ userId, extensionRights));
+ }
+ }
+
+ if (oldVersion != null) { // it's an update
+
+ for (String fqFieldDirtyName : wikitty.getDirty()) {
+
+ String concernedExtensionName = WikittyUtil.getExtensionNameFromFQFieldName(fqFieldDirtyName);
+
+ if (log.isTraceEnabled()) {
+ log.trace(String.format("will update field %s from extension %s",
+ fqFieldDirtyName, concernedExtensionName));
+ }
+
+ boolean fieldRequireAdminRights = // true if field is a field of WikittyAuthorisation
+ // concerned extension is "WikittyAuthorisation"
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION.equals(concernedExtensionName)
+ // or concerned extension is something like "AnyExtension:WikittyAuthorisation"
+ || WikittyAuthorisation.EXT_WIKITTYAUTHORISATION.equals(
+ WikittyUtil.getMetaExtensionNameFromFQMetaExtensionName(concernedExtensionName));
+
+ boolean canChange; // will be true if user can modify the value of this field
+ // according to his level of rights
+ if (fieldRequireAdminRights) {
+ canChange = canAdmin(securityToken, userId, concernedExtensionName, wikitty);
+ } else {
+ canChange = canWrite(securityToken, userId, concernedExtensionName, wikitty);
+ }
+
+ if (canChange) {
+ Object newValue = wikitty.getFqField(fqFieldDirtyName);
+ oldVersion.setFqField(fqFieldDirtyName, newValue);
+ } else {
+ throw new SecurityException(_("user %s can't write field %s on wikitty %s",
+ userId, fqFieldDirtyName, wikitty));
+ }
+ }
+ }
+
+ result.add(wikitty);
+ }
+ return result;
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ String userId = getUserId(securityToken);
+ List<Wikitty> wikitties = ws.restore(securityToken, ids);
+ for (Wikitty wikitty : wikitties) {
+ if (wikitty != null) {
+ refuseUnauthorizedRead(securityToken, userId, wikitty);
+ }
+ }
+ return wikitties;
+ }
+
+ /** throw an exception if read is not allowed */
+ protected void refuseUnauthorizedRead( String securityToken,
+ String userId,
+ Wikitty wikitty) {
+ if (wikitty != null) {
+ for (String extensionName : wikitty.getExtensionNames()) {
+ if ( ! canRead(securityToken, userId, extensionName, wikitty)) {
+ throw new SecurityException(_("user %s can't read extension %s on wikitty %s, it may be due to a global policy on the wikitty",
+ userId, extensionName, wikitty));
+ }
+ }
+ }
+ }
+
+ protected boolean canRead(String securityToken, String userId,
+ String extensionName, Wikitty wikitty) {
+
+ boolean canRead = false;
+
+ // first, check per-extension rights
+ if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
+ extensionName)) {
+ // there is a policy on the extension
+ canRead = isReader(securityToken, userId, wikitty, extensionName)
+ || canWrite(securityToken, userId, extensionName, wikitty);
+ } else if ( ! canRead &&
+ wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
+ // there is no policy for this extension
+ // but there is a policy for all extension of wikitty
+ canRead = isReader(securityToken, userId, wikitty, null)
+ || canWrite(securityToken, userId, extensionName, wikitty);
+ } else {
+ // no security policy, everything is allowed
+ canRead = true;
+ }
+
+ return canRead;
+ }
+
+ protected boolean canWrite(String securityToken, String userId,
+ String extensionName, Wikitty wikitty) {
+ boolean canWrite = false;
+
+ // first, check per-extension rights
+ if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
+ extensionName)) {
+ // there is a policy on the extension of fqFieldDirtyName
+ canWrite = isWriter(securityToken, userId, wikitty, extensionName)
+ || canAdmin(securityToken, userId, extensionName, wikitty);
+ } else if ( ! canWrite &&
+ wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
+ // there is no policy for this extension
+ // but there is a policy for all extension of wikitty
+ canWrite = isWriter(securityToken, userId, wikitty, null)
+ || canAdmin(securityToken, userId, extensionName, wikitty);
+ } else {
+ // no security policy, everything is allowed
+ canWrite = true;
+ }
+
+ return canWrite;
+ }
+
+ protected boolean canAdmin(String securityToken, String userId,
+ String extensionName, Wikitty wikitty) {
+
+ boolean canAdmin = false;
+
+ // first, check per-extension rights
+ if (wikitty.hasMetaExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION,
+ extensionName)) {
+ // there is a policy on the extension of fqFieldDirtyName
+ canAdmin = isAdmin(securityToken, userId, wikitty, extensionName)
+ || isOwner(securityToken, userId, wikitty, extensionName);
+ } else if ( ! canAdmin &&
+ wikitty.hasExtension(WikittyAuthorisation.EXT_WIKITTYAUTHORISATION) ) {
+ // there is no policy for this extension
+ // but there is a policy for all extension of wikitty
+ canAdmin = isAdmin(securityToken, userId, wikitty, null)
+ || isOwner(securityToken, userId, wikitty, null);
+ } else if ( ! canAdmin ) {
+ // still not admin, check appAdmin
+ canAdmin = userIsAnonymousOrAppAdmin(securityToken, userId);
+ }
+
+ return canAdmin;
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ checkDelete(securityToken, ids);
+ WikittyServiceEvent result = ws.delete(securityToken, ids);
+ return result;
+ }
+
+ /**
+ * Check if we can delete all id passed in argument
+ * @param securityToken
+ * @param ids
+ */
+ public void checkDelete(String securityToken, Collection<String> ids) {
+ String userId = getUserId(securityToken);
+ List<String> idsAsList = new ArrayList<String>(ids);
+ List<Wikitty> wikitties = ws.restore(securityToken, idsAsList);
+ for (Wikitty wikitty : wikitties) {
+ for (String extensionName : wikitty.getExtensionNames()) {
+ if ( ! canWrite(securityToken, userId, extensionName, wikitty)) {
+ throw new SecurityException(_(
+ "user %s doesn't have rights on extension %s on wikitty %s",
+ userId, extensionName, wikitty));
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ boolean result = true;
+ String userId = getUserId(securityToken);
+ for (String extName : wikitty.getExtensionNames()) {
+ result = result && isWriter(securityToken, userId, wikitty, extName);
+ if (!result) {
+ break;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ boolean result = true;
+ Wikitty wikitty = WikittyServiceEnhanced.restore(ws, securityToken, wikittyId);
+ if (wikitty != null) {
+ String userId = getUserId(securityToken);
+ for (String extName : wikitty.getExtensionNames()) {
+ result = result && isWriter(securityToken, userId, wikitty, extName);
+ if (!result) {
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ boolean result = true;
+ String userId = getUserId(securityToken);
+ Wikitty wikitty = WikittyServiceEnhanced.restore(ws, securityToken, wikittyId);
+ for (String extName : wikitty.getExtensionNames()) {
+ result = result && isReader(securityToken, userId, wikitty, extName);
+ if (!result) {
+ break;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ // All people can read extension
+ return ws.getAllExtensionIds(securityToken);
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(
+ String securityToken, String extensionName) {
+ // All people can read extension
+ return ws.getAllExtensionsRequires(securityToken, extensionName);
+ }
+
+ /* *** storing and restoring extensions ***/
+
+ protected void checkStoreExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ String userId = getUserId(securityToken);
+ if ( ! userIsAnonymousOrAppAdmin(securityToken, userId)) {
+ for (WikittyExtension extension : exts) {
+ Wikitty extensionAuthorisation = restoreExtensionAuthorisation(securityToken, extension.getName());
+ if (extensionAuthorisation != null) {
+ // canWrite is true if this user can modify the field for this extension
+ boolean canWrite = canWrite(securityToken, userId, null, extensionAuthorisation);
+ if ( ! canWrite) {
+ throw new SecurityException(_("user %s don't have write right for extension %s", userId, extension));
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ checkStoreExtension(securityToken, exts);
+ return ws.storeExtension(securityToken, exts);
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ // All people can read extension
+ return ws.restoreExtension(securityToken, id);
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ // All people can read extension
+ return ws.restoreExtensionLastVersion(securityToken, name);
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(String securityToken,
+ Criteria criteria) {
+ // All people can read PagedResult that contains only id
+ PagedResult<String> result = ws.findAllByCriteria(securityToken, criteria);
+ return result;
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ String userId = getUserId(securityToken);
+ WikittyTree restoredTree = ws.restoreTree(securityToken, wikittyId);
+ checkRestoreTree(securityToken, userId, restoredTree);
+ return restoredTree;
+ }
+
+ protected void checkRestoreTree(String securityToken, String userId, WikittyTree tree) {
+ checkRestoreTreeNode(securityToken, userId, tree.getNode());
+ for (WikittyTree subTree : tree.getChildren()) {
+ checkRestoreTree(securityToken, userId, subTree);
+ }
+ }
+
+
+ protected void checkRestoreTreeNode(String securityToken, String userId, WikittyTreeNode treeNode) {
+ refuseUnauthorizedRead(securityToken, userId, treeNode.getWikitty());
+ }
+
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId, Criteria filter) {
+ String userId = getUserId(securityToken);
+ Entry<WikittyTreeNode, Integer> entry = ws.restoreNode(securityToken, wikittyId, filter);
+ checkRestoreTreeNode(securityToken, userId, entry.getKey());
+ return entry;
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
+ String wikittyId,
+ Criteria filter) {
+ String userId = getUserId(securityToken);
+ Map<WikittyTreeNode, Integer> children = ws.restoreChildren(securityToken, wikittyId, filter);
+ for (Map.Entry<WikittyTreeNode, Integer> child : children.entrySet()) {
+ checkRestoreTreeNode(securityToken, userId, child.getKey());
+ }
+ return children;
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String treeNodeId) {
+ WikittyTreeNode treeNode = ws.restoreNode(securityToken, treeNodeId, null).getKey();
+ Collection<Wikitty> wikitties = Arrays.asList(treeNode.getWikitty());
+ checkStore(securityToken, wikitties);
+ return ws.deleteTree(securityToken, treeNodeId);
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken, String wikittyId, String version) {
+ Wikitty wikitty = ws.restoreVersion(securityToken, wikittyId, version);
+ String userId = getUserId(securityToken);
+ refuseUnauthorizedRead(securityToken, userId, wikitty);
+ return wikitty;
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken,
+ Criteria criteria) {
+ Wikitty wikitty = ws.findByCriteria(securityToken, criteria);
+ String userId = getUserId(securityToken);
+ refuseUnauthorizedRead(securityToken, userId, wikitty);
+ return wikitty;
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ String userId = getUserId(securityToken);
+ if (isAppAdmin(securityToken, userId)) {
+ // seul les AppAdmin on le droit a cette method
+ ws.syncEngin(securityToken);
+ } else {
+ throw new SecurityException(_("user %s can't sync search engine",
+ getUserId(securityToken)));
+ }
+ }
+
+ //
+ // Method helper to check right
+ //
+
+ /** tell who own a token (who got this token after login).
+ * @param securityToken the token whose owner will be returned
+ * @return a wikitty Id (wikitty has extension WikittyUser)
+ */
+ protected String getUserId(String securityToken) {
+ String result = null;
+ // recuperation de l'utilisateur associe au securityToken
+ // le securityToken est aussi l'id de l'objet
+ if (securityToken != null) {
+ Wikitty securityTokenWikitty = ws.restore(securityToken, securityToken);
+ if (securityTokenWikitty == null) {
+ throw new SecurityException("bad (obsolete ?) token");
+ } else {
+ result = WikittyTokenHelper.getUser(securityTokenWikitty);
+ }
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param securityToken
+ * @param userId
+ * @param wikitty
+ * @param extensionName may be null
+ * @return
+ */
+ protected boolean isReader(String securityToken, String userId, Wikitty wikitty, String extensionName) {
+ boolean result;
+ String metaFieldName = WikittyUtil.getMetaFieldName(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
+ WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_READER);
+ result = isMember(securityToken, userId, wikitty, metaFieldName, true);
+ return result;
+ }
+
+ /**
+ *
+ * @param securityToken
+ * @param userId
+ * @param wikitty
+ * @param extensionName may be null
+ * @return
+ */
+ protected boolean isWriter(String securityToken, String userId, Wikitty wikitty, String extensionName) {
+ boolean result;
+ String metaFieldName = WikittyUtil.getMetaFieldName(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
+ WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_WRITER);
+ log.trace("meta field name " + metaFieldName);
+ result = isMember(securityToken, userId, wikitty, metaFieldName);
+ return result;
+ }
+
+ /**
+ *
+ * @param securityToken
+ * @param userId
+ * @param wikitty
+ * @param extensionName may be null
+ * @return
+ */
+ protected boolean isAdmin(String securityToken, String userId, Wikitty wikitty, String extensionName) {
+ boolean result;
+ String metaFieldName = WikittyUtil.getMetaFieldName(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
+ WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_ADMIN);
+ result = isMember(securityToken, userId, wikitty, metaFieldName);
+ return result;
+ }
+
+ /** true if given user is owner
+ *
+ * @param securityToken
+ * @param userId
+ * @param wikitty
+ * @param extensionName may be null
+ * @return
+ */
+ protected boolean isOwner(String securityToken, String userId, Wikitty wikitty, String extensionName) {
+
+ String metaFieldName = WikittyUtil.getMetaFieldName(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName,
+ WikittyAuthorisation.FIELD_WIKITTYAUTHORISATION_OWNER);
+
+ String actualExtensionName = WikittyUtil.getExtensionNameFromFQFieldName(metaFieldName);
+ String fieldName = WikittyUtil.getFieldNameFromFQFieldName(metaFieldName);
+
+ String owner = wikitty.getFieldAsString(actualExtensionName, fieldName);
+
+ boolean isOwner;
+ if (owner == null) {
+ isOwner = false;
+ } else {
+ isOwner = owner.equals(userId);
+ }
+ return isOwner;
+ }
+
+ /** {@link #isMember(String, String, Wikitty, String, boolean)} with default value */
+ protected boolean isMember(String securityToken, String userId, Wikitty extensionRights, String fqFieldName) {
+ // by default, user is considered not member if he is not in the group, so passing "false"
+ return isMember(securityToken, userId, extensionRights, fqFieldName, false);
+ }
+
+ /** check if a user is listed in a level of rights
+ *
+ * @param securityToken
+ * @param userId the userId to look for
+ * @param extensionRights a wikitty with WikittyAuthorisation as extension <strong>OR</strong> meta-extension
+ * @param fqFieldName the field to look into, it should be one of the field of extension WikittyAuthorisation
+ * it has to be a FQN and may contain an extension-name if using meta-extension
+ * @param considerEmptyGroupAsMembership if true, an empty field value will be considered as
+ * "every-one is in the group". Most of the time, it will be false but true should be
+ * passed for "reader" level because user has right to read if he belongs to "reader" OR
+ * if reader is empty
+ * @return true if userId appear in the single/list of group/user of given field
+ */
+ protected boolean isMember(String securityToken, String userId,
+ Wikitty extensionRights, String fqFieldName, boolean considerEmptyGroupAsMembership) {
+
+ String extensionName = WikittyUtil.getExtensionNameFromFQFieldName(fqFieldName);
+ String fieldName = WikittyUtil.getFieldNameFromFQFieldName(fqFieldName);
+
+ Set<String> groupOrUser = extensionRights.getFieldAsSet(extensionName,
+ fieldName,
+ String.class);
+
+ boolean isMember;
+ if (groupOrUser == null || groupOrUser.isEmpty()) {
+ isMember = considerEmptyGroupAsMembership;
+ } else {
+ isMember = isMember(securityToken, userId, groupOrUser);
+ }
+
+ if ( ! isMember) {
+ // user don't have right on current object, check parent right
+ String parentId = WikittyAuthorisationHelper.getParent(extensionRights);
+ if (parentId != null) {
+ Wikitty parent = ws.restore(securityToken, parentId);
+ isMember = isMember(securityToken, userId, parent, fqFieldName);
+ }
+ }
+ return isMember;
+ }
+
+ /** check if a given user belong to the group of app-admins. */
+ protected boolean isAppAdmin(String securityToken, String userId) {
+ Wikitty group = getAppAdminGroup(securityToken);
+ Set<String> ids = WikittyGroupHelper.getMembers(group);
+ boolean result = isMember(securityToken, userId, ids);
+ return result;
+ }
+
+ /** get the wikitty with extension WikittyGroup that contains all app-admin. */
+ protected Wikitty getAppAdminGroup(String securityToken) {
+ Wikitty group;
+ if (appAdminGroupId == null) {
+ // 1er fois, on le recherche
+ group = ws.findByCriteria(securityToken, Search.query().eq(
+ WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME,
+ WikittySecurityHelper.WIKITTY_APPADMIN_GROUP_NAME).criteria());
+ // group peut-etre null s'il n'existe pas
+ } else {
+ // on a deja fait la recherche precedement, on essaie de reutilise
+ // le meme id
+ group = ws.restore(securityToken, appAdminGroupId);
+ // group peut-etre null, si entre temps un admin a supprime le group
+ }
+
+ return group;
+ }
+
+ /**
+ * Verifie recursivement si un utilisateur est dans un groupe qui peut etre
+ * constitue d'autre groupe ou d'utilisateur
+ *
+ * @param userId l'utilisateur recherche
+ * @param groupOrUser la liste des id d'utilisateurs ou d'autres groupes
+ * @return vrai si userId est retrouve, false sinon
+ */
+ protected boolean isMember(
+ String securityToken, String userId, Set<String> groupOrUser) {
+ if (groupOrUser != null) {
+ for (String id : groupOrUser) {
+ if (id.equals(userId)) {
+ return true;
+ } else {
+ Wikitty groupWikitty = ws.restore(securityToken, id);
+ if (WikittyGroupHelper.hasExtension(groupWikitty)) {
+ Set<String> members = WikittyGroupHelper.getMembers(groupWikitty);
+ return isMember(securityToken, userId, members);
+ }
+ }
+ }
+ }
+ return false; // not found in groupOrUser
+ }
+
+ /**
+ * restore the wikitty authorisation attached to given extension.
+ *
+ * @return a wikitty with WikittyAuthorisation extension, or null if given
+ * extension has no security policy attached
+ */
+ protected Wikitty restoreExtensionAuthorisation(String securityToken,
+ WikittyExtension extension) {
+ return restoreExtensionAuthorisation(securityToken, extension.getName());
+ }
+
+ /**
+ * restore the wikitty authorisation attached to given extension.
+ *
+ * @return a wikitty with WikittyAuthorisation extension, or null if given
+ * extension has no security policy attached
+ */
+ protected Wikitty restoreExtensionAuthorisation(String securityToken,
+ String extensionName) {
+ String wikittyAuthorisationId = WikittyMetaExtensionUtil.generateId(
+ WikittyAuthorisation.EXT_WIKITTYAUTHORISATION, extensionName);
+ Wikitty wikittyAuthorisation = ws.restore(securityToken, wikittyAuthorisationId);
+ if (wikittyAuthorisation == null) {
+ log.debug(extensionName + " has no authorization attached");
+ }
+ return wikittyAuthorisation;
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ // no need security check for this action
+ return ws.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ // no need security check for this action
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceTransaction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,344 @@
+package org.nuiton.wikitty.services;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.FacetTopic;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyTree;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceTransaction implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceTransaction.class);
+
+ /** Real WikittyService */
+ protected WikittyService ws;
+ /** WikittyService used to store modified object */
+ protected WikittyService tx;
+
+ protected List<WikittyServiceEvent> events;
+
+ /** if autoCommit > 0 all time events numbers element equals to this
+ * autoCommit commit is call */
+ protected int autoCommit = -1;
+
+ public WikittyServiceTransaction(ApplicationConfig config, WikittyService ws) {
+ this.ws = ws;
+ // create new WikittyServiceInMemory not configured with default config
+ // this WikittyServiceInMemory must be only in memory
+ this.tx = new WikittyServiceInMemory(null);
+ events = new LinkedList<WikittyServiceEvent>();
+ }
+
+ public void setAutoCommit(int autoCommit) {
+ this.autoCommit = autoCommit;
+ }
+
+ public int getAutoCommit() {
+ return autoCommit;
+ }
+
+ protected void addEvent(String securityToken, WikittyServiceEvent e) {
+ events.add(e);
+ if (autoCommit > 0 && events.size() >= autoCommit) {
+ commit(securityToken);
+ }
+ }
+
+ public void commit(String securityToken) {
+ ws.replay(securityToken, events);
+ this.tx.clear(null);
+ events.clear();
+ }
+
+ public void rollback(String securityToken) {
+ this.tx.clear(null);
+ events.clear();
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException(
+ "You try to add listener on WikittyServiceTransaction,"
+ + "this is an error desgin, you must add WikittyServiceNotifier"
+ + "front of your WikittyServiceTransaction.");
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException(
+ "You try to remove listener on WikittyServiceTransaction,"
+ + "this is an error desgin, you must add WikittyServiceNotifier"
+ + "front of your WikittyServiceTransaction.");
+ }
+
+ @Override
+ public String login(String login, String password) {
+ return ws.login(login, password);
+ }
+
+ /**
+ * Question: est un comportement normale, lorsqu'on se delogue depuis une
+ * transaction, on est deloguer partout ? je pense que oui
+ * @param securityToken
+ */
+ @Override
+ public void logout(String securityToken) {
+ ws.logout(securityToken);
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ WikittyServiceEvent e = tx.clear(securityToken);
+ addEvent(securityToken, e);
+ return e;
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ // in transaction, we can do all. But not during commit
+ return true;
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ // in transaction, we can do all. But not during commit
+ return true;
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ boolean result = tx.exists(securityToken, wikittyId);
+ if (!result) {
+ // on ne l'a pas en local on va voir si on peut le lire en distant
+ result = ws.canRead(securityToken, wikittyId);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ WikittyServiceEvent e = tx.replay(securityToken, events);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public WikittyServiceEvent store(
+ String securityToken, Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent e = tx.store(securityToken, wikitties, force);
+ addEvent(securityToken, e);
+ return e;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ HashSet<String> tmp = new HashSet<String>();
+
+ tmp.addAll(tx.getAllExtensionIds(securityToken));
+ tmp.addAll(ws.getAllExtensionIds(securityToken));
+
+ List<String> result = new ArrayList<String>(tmp);
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(String securityToken, String extensionName) {
+ HashSet<String> tmp = new HashSet<String>();
+
+ tmp.addAll(tx.getAllExtensionsRequires(securityToken, extensionName));
+ tmp.addAll(ws.getAllExtensionsRequires(securityToken, extensionName));
+
+ List<String> result = new ArrayList<String>(tmp);
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(
+ String securityToken, Collection<WikittyExtension> exts) {
+ WikittyServiceEvent e = tx.storeExtension(securityToken, exts);
+ addEvent(securityToken, e);
+ return e;
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(
+ String securityToken, String extensionId) {
+ WikittyExtension result = tx.restoreExtension(securityToken, extensionId);
+ if (result == null) {
+ result = ws.restoreExtension(securityToken, extensionId);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ WikittyExtension result =
+ tx.restoreExtensionLastVersion(securityToken, name);
+ if (result == null) {
+ result = ws.restoreExtensionLastVersion(securityToken, name);
+ }
+ return result;
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ List<Wikitty> resultWS = ws.restore(securityToken, ids);
+ List<Wikitty> resultTx = tx.restore(securityToken, ids);
+ Wikitty[] result = resultWS.toArray(new Wikitty[resultWS.size()]);
+ int i = 0;
+ for (Wikitty w : resultTx) {
+ String id = ids.get(i);
+ // il faut prendre en compte que l'objet a pu etre supprime dans la
+ // transaction donc meme s'il est null dans tx et pas dans ws, il
+ // faut le mettre a null
+ // si w n'a pas ete restore (null), mais qu'il exist, alors cela
+ // veut dire qu'il est supprime.
+ if (w != null || tx.exists(securityToken, id)) {
+ // on remplace tout par les nouveaux de la transaction
+ result[i] = w;
+ }
+ i++;
+ }
+ return Arrays.asList(result);
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ // pour que tout fonctionne bien, il faut que les objets supprimer soit
+ // dans la tx, car il faut avoir une vrai trace de cette suppression dans la tx
+ List<Wikitty> wikitties = ws.restore(securityToken, new ArrayList<String>(ids));
+ tx.store(securityToken, wikitties, true);
+
+ WikittyServiceEvent e = tx.delete(securityToken, ids);
+ addEvent(securityToken, e);
+ return e;
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ PagedResult<String> resultTx = tx.findAllByCriteria(securityToken, criteria);
+ PagedResult<String> resultWs = ws.findAllByCriteria(securityToken, criteria);
+
+ // Il faut fusionner les deux resultats
+ // - ne pas avoir de doublon
+ // - ne pas retenir ceux supprimer dans la transaction
+ // - fusionner les facettes (comment faire ?)
+ // - respecter le range demander (comment faire, avec les suppressions possible ?)
+ LinkedHashSet<String> ids =
+ new LinkedHashSet<String>(resultTx.size() + resultWs.size());
+ ids.addAll(resultTx.getAll());
+ for (String id : resultWs.getAll()) {
+ if (tx.exists(securityToken, id) && ! tx.isDeleted(securityToken, id)) {
+ ids.add(id);
+ }
+ }
+
+ int firstIndice = resultWs.getFirstIndice();
+ // FIXME le resultat est faut, le nombre total n'est pas la somme des deux :(
+ int numFound = resultTx.getNumFound() + resultWs.getNumFound();
+ String queryString = resultWs.getQueryString();
+ // FIXME les facettes sont fausses :(
+ Map<String, List<FacetTopic>> facets = resultWs.getFacets();
+ List<String> results = new ArrayList<String>(ids);
+
+ PagedResult<String> result = new PagedResult<String>(
+ firstIndice, numFound, queryString, facets, results);
+ return result;
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ Wikitty result = null;
+ PagedResult<String> ids = findAllByCriteria(securityToken, criteria);
+ List<String> results = ids.getAll();
+ if (results.size() > 0) {
+ String id = results.get(0);
+ List<Wikitty> wikitties = restore(
+ securityToken, Collections.singletonList(id));
+ result = wikitties.get(0);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String treeNodeId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken, String wikittyId, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken, String wikittyId, String version) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ boolean result = tx.exists(securityToken, wikittyId);
+ if (!result) {
+ if (!tx.isDeleted(securityToken, wikittyId)) {
+ result = ws.exists(securityToken, wikittyId);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ boolean result = tx.isDeleted(securityToken, wikittyId);
+ // pas efface, peut-etre qu'il existe
+ if (!result && !tx.exists(securityToken, wikittyId)) {
+ // il n'est pas efface et il n'existe pas dans la tx,
+ // on recherche dans ws
+ result = ws.isDeleted(securityToken, wikittyId);
+ }
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,125 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyException;
+
+/***
+ * Manage JTA transaction. You can store some information during execution.
+ */
+public class WikittyTransaction {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyTransaction.class);
+
+ /** permet d'attacher n'importe quoi a une transaction */
+ protected Map<Object, Object> tagValues;
+
+ /** cache static utilise par le WikittyServiceCached */
+ transient protected WikittyCache cache = null;
+
+ public WikittyTransaction() {
+ tagValues = new HashMap<Object, Object>();
+ }
+
+ /**
+ * FIXME poussin 20101027 a supprimer lorsque WikittyServiceTransaction
+ * aura ete implante
+ *
+ * Visibilite 'default' car est uilise par WikittyServiceCached qui est dans
+ * le meme package et a priori seulement lui en a besoin
+ *
+ * @return
+ */
+ WikittyCache getCache() {
+ if (cache == null) {
+ cache = new WikittyCache(false);
+ }
+ return cache;
+ }
+
+ public Object getTagValue(Object tag) {
+ return tagValues.get(tag);
+ }
+
+ public void setTagValue(Object tag, Object value) {
+ tagValues.put(tag, value);
+ }
+
+ public UserTransaction getUserTransaction() {
+ return com.arjuna.ats.jta.UserTransaction.userTransaction();
+ }
+
+ public TransactionManager getTransactionManager() {
+ return com.arjuna.ats.jta.TransactionManager.transactionManager();
+ }
+
+ public void begin() {
+ UserTransaction userTransaction = getUserTransaction();
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Begin transaction");
+ }
+ userTransaction.setTransactionTimeout(3600); // FIXME: jru 20100115 error in service if call during lot of times
+ userTransaction.begin();
+ } catch (Exception eee) {
+ throw new WikittyException("Error on begin JTA transaction", eee);
+ }
+ }
+
+ public void commit() {
+ UserTransaction userTransaction = getUserTransaction();
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Commit transaction");
+ }
+ userTransaction.commit();
+ } catch (Exception eee) {
+ throw new WikittyException("Error on commit JTA transaction", eee);
+ }
+ }
+
+ public void rollback() {
+ UserTransaction userTransaction = getUserTransaction();
+ try {
+ if(userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION
+ && userTransaction.getStatus() != Status.STATUS_UNKNOWN) {
+ if (log.isDebugEnabled()) {
+ log.debug("Rollback transaction");
+ }
+ userTransaction.rollback();
+ }
+ } catch (Exception eee) {
+ throw new WikittyException("Error on roolback JTA transaction", eee);
+ }
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/XMPPNotifierTransporter.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/XMPPNotifierTransporter.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/XMPPNotifierTransporter.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,220 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.services;
+
+
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.UUID;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.muc.DiscussionHistory;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyException;
+
+/**
+ * Transporter d'event via xmpp. Pour que ca fonctionne il faut un serveur
+ * xmpp avec une room
+ * <p>
+ * Configuration
+ * <li>wikitty.xmpp.server = adresse du serveur (ex: im.codelutin.com)
+ * <li>wikitty.xmpp.room = adresse de la room (ex: wikitty-event(a)im.codelutin.com)
+ * <li>wikitty.notification.persistent = [true|false] indique si on doit
+ * recevoir tous les messages sans en loupe un seul. Pour cela il faut que la
+ * room soit archivee. (FIXME poussin 20101014 pas encore implantee)
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class XMPPNotifierTransporter implements PacketListener,
+ WikittyServiceNotifier.RemoteNotifierTransporter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(XMPPNotifierTransporter.class);
+
+ static final public String PROPERTY_EVENT_NAME = "wikitty-event";
+
+ /** Notifier service reference reference. */
+ protected WikittyServiceNotifier ws;
+
+ /** if persistent is true use Chat otherwize use MUC. Chat permit to
+ received event missed after deconnection */
+ protected boolean persistent = false;
+
+ // Keep room addresse and pseudo to verify that messages event are not send by us
+ protected String room;
+ protected String pseudo;
+
+ protected XMPPConnection connection;
+ protected MultiUserChat muc;
+
+ /**
+ *
+ * @param ws
+ * @param props
+ */
+ public XMPPNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
+ this.ws = ws;
+ initXMPP(config);
+ }
+
+ /**
+ * Si persistent est vrai alors il faut toujours utilise le meme user id
+ *
+ * @param props
+ */
+ protected void initXMPP(ApplicationConfig config) {
+ persistent = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_NOTIFICATION_PERSISTENT.getKey());
+ String server = config.getOption(
+ WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER.getKey());
+
+ // Keep them to verify that is not us notifications
+ room = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM.getKey());
+ pseudo = getUniqueLoginName();
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Try to connect to xmpp serveur " + server +
+ " with pseudo " + pseudo + " in room " + room +
+ " persistent " + persistent);
+ }
+ connection = new XMPPConnection(server);
+ connection.connect();
+ connection.loginAnonymously();
+
+ DiscussionHistory history = new DiscussionHistory();
+ if (persistent) {
+ // FIXME poussin 20101113 compute amount of log history to retrieve
+ // MUC must be archived
+ Date date = new Date();
+ history.setSince(date);
+ } else {
+ history.setMaxChars(0);
+ }
+
+ // connection to the volatile room
+ muc = new MultiUserChat(connection, room);
+ muc.join(pseudo, "", history, 4000);
+ muc.addMessageListener(this);
+ } catch (Exception eee) {
+ throw new WikittyException("Can't connect to xmpp serveur", eee);
+ }
+ }
+
+ @Override
+ public void sendMessage(WikittyServiceEvent event) throws Exception {
+ Message message = muc.createMessage();
+ message.setBody(event.getType().toString());
+ message.setProperty(PROPERTY_EVENT_NAME, event);
+
+ muc.sendMessage(message);
+ }
+
+ /**
+ * used for MUC message
+ * @param packet
+ */
+ @Override
+ public void processPacket(Packet packet) {
+
+ // Dont listen own events
+ String name = room + "/" + pseudo;
+ if (!name.equals(packet.getFrom())) {
+
+ Object event = packet.getProperty(PROPERTY_EVENT_NAME);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Receive message : " + event);
+ }
+
+ if (event instanceof WikittyServiceEvent) {
+ ws.processRemoteEvent((WikittyServiceEvent)event);
+ }
+ }
+ }
+
+ /**
+ * Recherche le meilleur nom a utiliser comme pseudo pour cette machine.
+ * Un UUID est toujours ajouter en debut, pour potentiellement lancer
+ * plusieurs application en meme temps sur la meme machine et etre sur que
+ * le pseudo soit bien unique.
+ *
+ * Le pseudo, n'est pas seulement un UUID, pour pouvoir facilement faire
+ * du debug en entrant dans le channel et voir les ip des machiens connectees
+ *
+ * @return
+ */
+ static public String getUniqueLoginName() {
+ String result = UUID.randomUUID().toString();
+ try {
+ String ipv4 = null;
+ String ipv6 = null;
+ for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
+ NetworkInterface netint = e.nextElement();
+
+ for (Enumeration<InetAddress> a = netint.getInetAddresses(); a.hasMoreElements();) {
+ InetAddress ip = a.nextElement();
+ if (ip instanceof Inet4Address) {
+ if ((ipv4 == null || "127.0.0.1".equals(ipv4))) {
+ ipv4 = ip.getHostAddress();
+ }
+ } else if (ip instanceof Inet6Address) {
+ if (ipv6 == null) {
+ ipv6 = ip.getHostAddress();
+ }
+ } else {
+ log.error("Can't get ip from no ipv4 and no ipv6: " + ip);
+ }
+ }
+ }
+
+ if (ipv4 != null) {
+ result = ipv4 + "=" + result;
+ } else if (ipv6 != null) {
+ result = ipv6 + "=" + result;
+ }
+ } catch (Exception eee) {
+ log.error("Can't compute unique name from network interface", eee);
+ }
+ return result;
+ }
+
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorage.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionStorage.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorage.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorage.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,111 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.storage;
+
+import java.util.Collection;
+import java.util.List;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface WikittyExtensionStorage {
+
+ /**
+ * Store extension in storage.
+ *
+ * @param transaction the current transaction
+ * @param extensions the extensions to store
+ * @return information usefull for client side update data
+ */
+ WikittyServiceEvent store(WikittyTransaction transaction,
+ Collection<WikittyExtension> extensions);
+
+ /**
+ * Return true if id exists in storage.
+ *
+ * @param transaction the current transaction
+ * @param id an extension id
+ * @return true if the extension exists
+ */
+ boolean exists(WikittyTransaction transaction, String id);
+
+ /**
+ * Return all extension ids.
+ *
+ * @param transaction the current transaction
+ * @return a list of extension ids
+ */
+ List<String> getAllExtensionIds(WikittyTransaction transaction);
+
+ /**
+ * Return all extension ids where the specified extensionName is required.
+ *
+ * @param transaction the current transaction
+ * @param extensionName the extension required
+ * @return a list of extension ids
+ */
+ List<String> getAllExtensionsRequires(WikittyTransaction transaction,
+ String extensionName);
+
+ /**
+ * return last version available for specified extension name.
+ *
+ * @param transaction the current transaction
+ * @param extName name of extension
+ * @return last version availble for this version, or null if extension
+ * doesn't exist
+ */
+ String getLastVersion(WikittyTransaction transaction, String extName);
+
+ /**
+ * Restore one extension from storage, if not found an exception is thrown.
+ *
+ * @param transaction the current transaction
+ * @param name extension name to restore
+ * @param version extension version to restore
+ * @return an extension
+ * @throws WikittyException if exception during restore
+ */
+ WikittyExtension restore(WikittyTransaction transaction, String name, String version)
+ throws WikittyException;
+
+ /**
+ * Remove all extensions.
+ *
+ * @param transaction transaction
+ */
+ public WikittyServiceEvent clear(WikittyTransaction transaction);
+
+}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorageInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorageInMemory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyExtensionStorageInMemory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,100 @@
+package org.nuiton.wikitty.storage;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+public class WikittyExtensionStorageInMemory implements WikittyExtensionStorage {
+
+ protected Map<String, WikittyExtension> extensions;
+
+ public WikittyExtensionStorageInMemory() {
+ this.extensions = new HashMap<String, WikittyExtension>();
+ }
+
+ public Map<String, WikittyExtension> getExtensions() {
+ return extensions;
+ }
+
+ public void setExtensions(Map<String, WikittyExtension> extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public WikittyServiceEvent store(WikittyTransaction transaction, Collection<WikittyExtension> exts) throws WikittyException {
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ for (WikittyExtension ext : exts) {
+ // on ajoute que s'il n'y est pas deja
+ if (!extensions.containsKey(ext.getId())) {
+ extensions.put(ext.getId(), ext);
+ result.addExtension(ext);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean exists(WikittyTransaction transaction, String id) {
+ boolean result = extensions.containsKey(id);
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(WikittyTransaction transaction) {
+ List<String> result = new ArrayList<String>(extensions.keySet());
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(WikittyTransaction transaction, String extensionName) {
+ ArrayList<String> ids = new ArrayList<String>();
+ Collection<WikittyExtension> values = extensions.values();
+ if (values != null) {
+ for (WikittyExtension extension : values) {
+ if (extensionName.equals(extension.getRequires())) {
+ ids.add(extension.getId());
+ }
+ }
+ }
+ return ids;
+ }
+
+ @Override
+ public String getLastVersion(WikittyTransaction transaction, String extName) {
+ String result = null;
+ Set<String> extensionIds = extensions.keySet();
+ for (String extensionId : extensionIds) {
+ String extensionVersion = WikittyExtension.computeVersion(extensionId);
+ if (extensionId.startsWith(extName) && (result == null || WikittyUtil.versionGreaterThan(extensionVersion, result))) {
+ result = extensionVersion;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyExtension restore(WikittyTransaction transaction, String name, String version) throws WikittyException {
+ String id = WikittyExtension.computeId(name, version);
+ WikittyExtension result = extensions.get(id);
+ if (result == null) {
+ throw new WikittyException(String.format("No extension with id '%s'", id));
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent clear(WikittyTransaction transaction) {
+ extensions = new HashMap<String, WikittyExtension>();
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION);
+ return result;
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngin.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittySearchEngin.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngin.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngin.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,96 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.storage;
+
+import java.util.Collection;
+import java.util.Map;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+/**
+ * WikittySearchEngin is used to abstract search engine used in WikittyService.
+ *
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface WikittySearchEngin {
+
+ /**
+ * Remove all data in index
+ */
+ public void clear(WikittyTransaction transaction);
+
+ /**
+ * Store wikitty in storage
+ * @return information usefull for client side update data
+ */
+ public void store(WikittyTransaction transaction,
+ Collection<Wikitty> wikitties);
+
+ /**
+ * Delete all object with idList argument. If id is not valid or don't exist.
+ *
+ * @param idList list of ids to delete
+ * @return <code>UpdateResponse</code>>
+ * @throws WikittyException
+ */
+ public void delete(WikittyTransaction transaction,
+ Collection<String> idList) throws WikittyException;
+
+ /**
+ * Delete all object with idList argument. idList is directly passed to search engine
+ * and is processed without any other kind of treatment.
+ *
+ * @param idList list of ids to delete
+ * @return <code>UpdateResponse</code>
+ * @throws WikittyException
+ */
+ public void delete(Collection<String> idList) throws WikittyException;
+
+ public PagedResult<String> findAllByCriteria(WikittyTransaction transaction, Criteria criteria);
+
+ /**
+ * Find count of child for a node
+ * @param w
+ * @return
+ */
+ public Integer findNodeCount(WikittyTransaction transaction, Wikitty w, Criteria filter);
+
+ /**
+ * Find all children ids with count for a node wikitty.
+ * @param w
+ * @return
+ */
+ public Map<String, Integer> findAllChildrenCount(WikittyTransaction transaction, Wikitty w, Criteria filter);
+
+}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEnginInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEnginInMemory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEnginInMemory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,146 @@
+package org.nuiton.wikitty.storage;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.search.operators.And;
+import org.nuiton.wikitty.search.operators.BinaryOperator;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.operators.Restriction;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+public class WikittySearchEnginInMemory implements WikittySearchEngin {
+
+ WikittyStorageInMemory wikittyStorage;
+
+ public WikittySearchEnginInMemory(WikittyStorageInMemory wikittyStorage) {
+ this.wikittyStorage = wikittyStorage;
+ }
+
+ @Override
+ public void clear(WikittyTransaction transaction) {
+ // do nothing
+ }
+
+ @Override
+ public void store(WikittyTransaction transaction, Collection<Wikitty> wikitties) {
+ }
+
+ @Override
+ public void delete(WikittyTransaction transaction, Collection<String> idList) throws WikittyException {
+ }
+
+ @Override
+ public void delete(Collection<String> idList) throws WikittyException {
+ }
+
+ public boolean checkRestriction(Restriction restriction, Wikitty w) {
+ if (restriction instanceof BinaryOperator) {
+ BinaryOperator binOp = (BinaryOperator) restriction;
+ if (binOp.getElement().getName().equals(Element.ELT_EXTENSION)) {
+ return w.hasExtension(binOp.getValue());
+ }
+ String fqfieldName = binOp.getElement().getName();
+ if (Element.ELT_EXTENSION.equals(fqfieldName)) {
+ return true;
+ } else if (Element.ELT_ID.equals(fqfieldName)) {
+ return w.getId().equals(binOp.getValue());
+ } // si les wikitty n'ont meme pas l'extension concerné
+ // Le check restriction, ne doit pas tester les champs
+ // si les wikitty n'ont meme pas l'extension concerné
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+ Object o = w.getFqField(fqfieldName);
+ FieldType t = w.getFieldType(fqfieldName);
+ Object value = t.getValidValue(binOp.getValue());
+ boolean checked = false;
+ switch (restriction.getName()) {
+ case EQUALS:
+ checked = value.equals(o);
+ break;
+ case LESS:
+ checked = ((Comparable) o).compareTo(value) < 0;
+ break;
+ case LESS_OR_EQUAL:
+ checked = ((Comparable) o).compareTo(value) <= 0;
+ break;
+ case GREATER:
+ checked = ((Comparable) o).compareTo(value) > 0;
+ break;
+ case GREATER_OR_EQUAL:
+ checked = ((Comparable) o).compareTo(value) >= 0;
+ break;
+ case NOT_EQUALS:
+ checked = !value.equals(o);
+ break;
+ case ENDS_WITH:
+ if (t.getType() != TYPE.STRING) {
+ throw new WikittyException("Can't search for contents that 'ends with' on attribute type different of String. " + "Attribute " + fqfieldName + " is " + t.getType().name());
+ }
+ checked = ((String) o).endsWith((String) value);
+ break;
+ case STARTS_WITH:
+ if (t.getType() != TYPE.STRING) {
+ throw new WikittyException("Can't search for contents that 'starts with' on attribute type different of String. " + "Attribute " + fqfieldName + " is " + t.getType().name());
+ }
+ checked = ((String) o).startsWith((String) value);
+ break;
+ }
+ return checked;
+ } else if (restriction instanceof And) {
+ And and = (And) restriction;
+ for (Restriction sub : and.getRestrictions()) {
+ if (!checkRestriction(sub, w)) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ throw new UnsupportedOperationException(restriction.getName() + " Search Not yet implemented");
+ }
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(WikittyTransaction transaction, Criteria criteria) {
+ // throw new UnsupportedOperationException("Not supported yet.");
+ int firstIndex = criteria.getFirstIndex();
+ int endIndex = criteria.getEndIndex();
+ List<String> ids = new LinkedList<String>();
+ int currentIndex = 0;
+ for (Entry<String, Wikitty> entry : wikittyStorage.getWikitties().entrySet()) {
+ Wikitty w = entry.getValue();
+ String id = entry.getKey();
+ Restriction dto = criteria.getRestriction();
+ if (!w.isDeleted() && checkRestriction(dto, w)) {
+ currentIndex++;
+ if (currentIndex > firstIndex) {
+ ids.add(id);
+ }
+ if (endIndex >= 0 && currentIndex >= endIndex) {
+ break;
+ }
+ }
+ }
+ return new PagedResult<String>(firstIndex, ids.size(), criteria.getRestriction().toString(), null, ids);
+ }
+
+ @Override
+ public Integer findNodeCount(WikittyTransaction transaction, Wikitty w, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<String, Integer> findAllChildrenCount(WikittyTransaction transaction, Wikitty w, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+}
Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorage.java (from rev 459, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyStorage.java)
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorage.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorage.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,120 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.storage;
+
+import java.util.Collection;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+/**
+ * WikittyStorage is used to abstract data and extension storage in WikittyService.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface WikittyStorage {
+
+ /**
+ * Store wikitty in storage.
+ *
+ * @param transaction transaction
+ * @param wikitties wikitty collection
+ * @param force boolean force non version version increment on saved wikitty
+ * or force version on wikitty creation (version 0.0)
+ *
+ * @return information usefull for client side update data
+ */
+ public WikittyServiceEvent store(WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force);
+
+ /**
+ * Return true if id exists in storage.
+ *
+ * @param transaction transaction
+ * @param id id to check
+ * @return {@code true} if wikitty id exists
+ */
+ public boolean exists(WikittyTransaction transaction, String id);
+
+ /**
+ * Return true if wikitty object with this id are marked deleted.
+ *
+ * @param transaction transaction
+ * @param id id to check
+ * @return {@code true} if wikitty id is deleted
+ */
+ public boolean isDeleted(WikittyTransaction transaction, String id);
+
+ /**
+ * Restore list of wikitty object.
+ *
+ * @param transaction transaction
+ * @param id list of wikitty id
+ * @param fqFieldName list of field that must be loaded, other fields
+ * can be not loaded
+ * @return found wikitty
+ * @throws WikittyException if wikitty not found
+ */
+ public Wikitty restore(WikittyTransaction transaction, String id,
+ String ... fqFieldName) throws WikittyException;
+
+ /**
+ * Delete all object with id argument.
+ *
+ * @param transaction transaction
+ * @param idList
+ * @return delete response
+ * @throws WikittyException If id is not valid or don't exist.
+ */
+ public WikittyServiceEvent delete(WikittyTransaction transaction, Collection<String> idList) throws WikittyException;
+
+ /**
+ * Scan all wikitties with specific scanner, even if the wikitty is deleted.
+ *
+ * @param transaction transaction
+ * @param scanner scanner
+ */
+ public void scanWikitties(WikittyTransaction transaction, Scanner scanner);
+
+ /**
+ * Call each time wikitty is scan.
+ */
+ public static interface Scanner {
+ void scan(String wikittyId);
+ }
+
+ /**
+ * Remove all wikitty.
+ *
+ * @param transaction transaction
+ */
+ public WikittyServiceEvent clear(WikittyTransaction transaction);
+
+}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorageInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorageInMemory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittyStorageInMemory.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,149 @@
+package org.nuiton.wikitty.storage;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.WikittyObsoleteException;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyTransaction;
+
+public class WikittyStorageInMemory implements WikittyStorage {
+
+ protected Map<String, Wikitty> wikitties = new LinkedHashMap<String, Wikitty>();
+
+ public Map<String, Wikitty> getWikitties() {
+ return wikitties;
+ }
+
+ public void setWikitties(Map<String, Wikitty> wikitties) {
+ this.wikitties = wikitties;
+ }
+
+ @Override
+ public WikittyServiceEvent store(WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ for (Wikitty wikitty : wikitties) {
+ // begin with clone of wikitty to prevent modification of
+ // wikitty passed as argument
+ try {
+ wikitty = wikitty.clone();
+ } catch (CloneNotSupportedException eee) {
+ throw new WikittyException("Can't clone ?", eee);
+ }
+ String actualVersion = null;
+ Wikitty inMemoryWikitty = this.wikitties.get(wikitty.getId());
+ if (inMemoryWikitty != null) {
+ actualVersion = inMemoryWikitty.getVersion();
+ }
+ String requestedVersion = wikitty.getVersion();
+ String newVersion = null;
+ if (force) {
+ if (actualVersion == null) {
+ //no version in place
+ if (requestedVersion == null) {
+ //no version requested
+ newVersion = WikittyUtil.DEFAULT_VERSION;
+ } else {
+ //version requested
+ newVersion = requestedVersion;
+ }
+ } else {
+ //version in place is not null
+ if (requestedVersion == null || requestedVersion.startsWith(WikittyUtil.DEFAULT_MAJOR_VERSION_PREFIX)) {
+ //no version requested
+ newVersion = WikittyUtil.incrementMajorRevision(actualVersion);
+ } else if (WikittyUtil.versionEquals(actualVersion, requestedVersion)) {
+ //same version
+ // wikitty is not modified, do nothing
+ continue;
+ } else if (WikittyUtil.versionGreaterThan(requestedVersion, actualVersion)) {
+ //requested version is newer
+ newVersion = requestedVersion;
+ } else {
+ //requested version is obsolete
+ throw new WikittyObsoleteException(String.format("Your wikitty '%s' is obsolete (saving: '%s'; existing: '%s')", wikitty.getId(), requestedVersion, actualVersion));
+ }
+ }
+ } else {
+ if (WikittyUtil.versionEquals(actualVersion, requestedVersion)) {
+ // no modification, continue
+ continue;
+ } else if (WikittyUtil.versionGreaterThan(actualVersion, requestedVersion)) {
+ throw new WikittyObsoleteException(String.format("Your wikitty '%s' is obsolete", wikitty.getId()));
+ } else {
+ newVersion = WikittyUtil.incrementMajorRevision(actualVersion);
+ }
+ }
+ wikitty.setVersion(newVersion);
+ wikitty.clearDirty();
+ try {
+ this.wikitties.put(wikitty.getId(), wikitty.clone());
+ } catch (CloneNotSupportedException eee) {
+ throw new WikittyException("Can't clone ?", eee);
+ }
+ result.addWikitty(wikitty);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent delete(WikittyTransaction transaction, Collection<String> idList) throws WikittyException {
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ Date now = new Date();
+ for (String id : idList) {
+ Wikitty w = restore(transaction, id);
+ if (w != null) {
+ w.setDeleteDate(now);
+ result.addRemoveDate(id, now);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean exists(WikittyTransaction transaction, String id) {
+ boolean result = wikitties.containsKey(id);
+ return result;
+ }
+
+ @Override
+ public boolean isDeleted(WikittyTransaction transaction, String id) {
+ boolean result = false;
+ Wikitty w = wikitties.get(id);
+ if (w == null) {
+ throw new WikittyException(String.format("No wikitty with id '%s'", id));
+ } else {
+ result = w.isDeleted();
+ }
+ return result;
+ }
+
+ @Override
+ public Wikitty restore(WikittyTransaction transaction, String id, String... fqFieldName) throws WikittyException {
+ Wikitty result = wikitties.get(id);
+ if (result.isDeleted()) {
+ result = null;
+ }
+ return result;
+ }
+
+ @Override
+ public void scanWikitties(WikittyTransaction transaction, Scanner scanner) {
+ Collection<Wikitty> all = wikitties.values();
+ for (Wikitty wikitty : all) {
+ scanner.scan(wikitty.getId());
+ }
+ }
+
+ @Override
+ public WikittyServiceEvent clear(WikittyTransaction transaction) {
+ wikitties = new LinkedHashMap<String, Wikitty>();
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY);
+ return result;
+ }
+}
Modified: trunk/wikitty-api/src/main/xmi/wikitty.properties
===================================================================
--- trunk/wikitty-api/src/main/xmi/wikitty.properties 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/main/xmi/wikitty.properties 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,7 +1,7 @@
-org.nuiton.wikitty.WikittyAuthorisation.class.tagvalue.version=1.0
-org.nuiton.wikitty.WikittyGroup.class.tagvalue.version=1.0
-org.nuiton.wikitty.WikittyLabel.class.tagvalue.version=1.0
-org.nuiton.wikitty.WikittyToken.class.tagvalue.version=1.0
-org.nuiton.wikitty.WikittyTreeNode.class.tagvalue.version=2.0
-org.nuiton.wikitty.WikittyUser.class.tagvalue.version=1.0
-org.nuiton.wikitty.WikittyI18n.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyAuthorisation.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyGroup.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyLabel.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyToken.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyTreeNode.class.tagvalue.version=2.0
+org.nuiton.wikitty.entities.WikittyUser.class.tagvalue.version=1.0
+org.nuiton.wikitty.entities.WikittyI18n.class.tagvalue.version=1.0
Modified: trunk/wikitty-api/src/main/xmi/wikitty.zargo
===================================================================
(Binary files differ)
Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,60 +0,0 @@
-package org.nuiton.wikitty;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyI18nTest {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyI18nTest.class);
-
- @Test
- public void testI18n() throws Exception {
- // creation d'un proxy sur un ws in memory
- WikittyConfig config = new WikittyConfig();
- WikittyService ws = new WikittyServiceInMemory(config);
- WikittyProxy proxy = new WikittyProxy(ws);
-
- // creation d'un label pour l'utiliser pour l'i18n
- WikittyLabel label = new WikittyLabelImpl();
- WikittyExtension ext =
- label.getWikitty().getExtension(WikittyLabel.EXT_WIKITTYLABEL);
-
- // recuperation de support i18n pour l'extension WikittyLabel
- WikittyI18n i18n = WikittyI18nUtil.getI18n(proxy, ext);
-
- // ajout d'une traduction pour le francais
- i18n.setTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS, "étiquette");
- proxy.store(i18n);
-
- String trad = i18n.getTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
- Assert.assertEquals("étiquette", trad);
- Assert.assertEquals(1, i18n.getLang().size());
- Assert.assertEquals("fr", i18n.getLang().iterator().next());
- Assert.assertEquals("[fr:\"labels\"=\"étiquette\"]", i18n.getTranslations());
-
- // ajout d'une traduction pour l'espagnole
- i18n.setTranslation("es", WikittyLabel.FIELD_WIKITTYLABEL_LABELS, "etiqueta");
-
- Assert.assertEquals(2, i18n.getLang().size());
-
- // on force le vidage du cache pour voir si le parsing se passe bien
- ((WikittyI18nImpl)i18n).translationsCache = null;
- trad = i18n.getTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
- Assert.assertEquals("étiquette", trad);
-
-// System.out.println(i18n.getTranslations());
- }
-
-}
Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,39 +0,0 @@
-package org.nuiton.wikitty;
-
-
-import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceHelperTest {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceHelperTest.class);
-
- @Test
- public void testBuild() throws Exception {
- Properties props = new Properties();
- props.setProperty(WikittyConfig.Option.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(),
- WikittyServiceInMemory.class.getName() + "," +
- WikittyServiceNotifier.class.getName() + "," +
- WikittyServiceCached.class.getName());
- WikittyConfig config = new WikittyConfig(props);
- WikittyService ws = WikittyServiceFactory.buildWikittyService(config);
-
- Assert.assertEquals(WikittyServiceCached.class, ws.getClass());
- ws = ((WikittyServiceCached)ws).ws;
- Assert.assertEquals(WikittyServiceNotifier.class, ws.getClass());
- ws = ((WikittyServiceNotifier)ws).ws;
- Assert.assertEquals(WikittyServiceInMemory.class, ws.getClass());
- }
-}
Deleted: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -1,56 +0,0 @@
-package org.nuiton.wikitty;
-
-import java.util.Collections;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class WikittyServiceTransactionTest {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(WikittyServiceTransactionTest.class);
-
- public WikittyServiceTransactionTest() {
- }
-
- @Test
- public void testTransaction() throws Exception {
- WikittyConfig config = new WikittyConfig();
- WikittyServiceInMemory ws = new WikittyServiceInMemory(config);
- WikittyServiceTransaction tx = new WikittyServiceTransaction(config, ws);
-
- // ajout d'objet hors transaction
- WikittyLabel label = new WikittyLabelImpl();
- label.addLabels("coucou");
- ws.store(null, null, Collections.singleton(label.getWikitty()), false);
-
- // on doit le retrouver dans la transation (meme si elle a ete ouverte avant)
- Wikitty wTx = WikittyServiceEnhanced.restore(tx, null, label.getWikittyId());
- Assert.assertEquals(label.getWikitty(), wTx);
-
- // on creer un objet dans la transaction
- WikittyLabel labelTx = new WikittyLabelImpl();
- labelTx.addLabels("coucouTx");
- tx.store(null, Collections.singleton(labelTx.getWikitty()), false);
-
- // on ne doit pas le retrouver hors de la transation
- Wikitty w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
- Assert.assertEquals(null, w);
-
- // on commit, du coup on doit retrouver l'objet
- tx.commit(null);
- w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
- Assert.assertEquals(labelTx.getWikitty(), w);
-
- }
-
-}
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/WikittyI18nTest.java (from rev 459, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/WikittyI18nTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/WikittyI18nTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,70 @@
+package org.nuiton.wikitty.addons;
+
+
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.addons.WikittyI18nUtil;
+import org.nuiton.wikitty.addons.WikittyI18nImpl;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.entities.WikittyI18n;
+import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.entities.WikittyLabelImpl;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyI18nTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyI18nTest.class);
+
+ @Test
+ public void testI18n() throws Exception {
+ // creation d'un proxy sur un ws in memory
+ WikittyConfig config = new WikittyConfig();
+ WikittyService ws = new WikittyServiceInMemory(config);
+ WikittyProxy proxy = new WikittyProxy(ws);
+
+ // creation d'un label pour l'utiliser pour l'i18n
+ WikittyLabel label = new WikittyLabelImpl();
+ WikittyExtension ext =
+ label.getWikitty().getExtension(WikittyLabel.EXT_WIKITTYLABEL);
+
+ // recuperation de support i18n pour l'extension WikittyLabel
+ WikittyI18n i18n = WikittyI18nUtil.getI18n(proxy, ext);
+
+ // ajout d'une traduction pour le francais
+ i18n.setTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS, "étiquette");
+ proxy.store(i18n);
+
+ String trad = i18n.getTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
+ Assert.assertEquals("étiquette", trad);
+ Assert.assertEquals(1, i18n.getLang().size());
+ Assert.assertEquals("fr", i18n.getLang().iterator().next());
+ Assert.assertEquals("[fr:\"labels\"=\"étiquette\"]", i18n.getTranslations());
+
+ // ajout d'une traduction pour l'espagnole
+ i18n.setTranslation("es", WikittyLabel.FIELD_WIKITTYLABEL_LABELS, "etiqueta");
+
+ Assert.assertEquals(2, i18n.getLang().size());
+
+ // on force le vidage du cache pour voir si le parsing se passe bien
+ ((WikittyI18nImpl)i18n).translationsCache = null;
+ trad = i18n.getTranslation("fr", WikittyLabel.FIELD_WIKITTYLABEL_LABELS);
+ Assert.assertEquals("étiquette", trad);
+
+// System.out.println(i18n.getTranslations());
+ }
+
+}
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/importexport/ImportExportCSVTest.java (from rev 459, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/importexport/ImportExportCSVTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/addons/importexport/ImportExportCSVTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,209 @@
+/*
+ * #%L
+ * Wikitty :: api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 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.addons.importexport;
+
+import org.nuiton.wikitty.addons.importexport.ImportExportCSV;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.addons.WikittyImportExportService;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.Search;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Test for CSV import export class
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:META-INF/spring/wikitty-test.xml")
+public class ImportExportCSVTest {
+
+ @Autowired
+ protected WikittyService ws ;
+
+ public WikittyService getWikittyService() {
+ return ws;
+ }
+
+ public void setWikittyService(WikittyService wikittyService) {
+ this.ws = wikittyService;
+ }
+
+ protected static final WikittyExtension extensionClient =
+ new WikittyExtension("Client", "1.0", null,
+ WikittyUtil.buildFieldMapExtension(
+ "String name"));
+
+ protected static final WikittyExtension extensionTag =
+ new WikittyExtension("Tag", "1.0", null,
+ WikittyUtil.buildFieldMapExtension(
+ "String tags"));
+
+ /**
+ * Test que le pattern match les bonnes choses.
+ */
+ @Test
+ public void testQueryPattern() {
+
+ ImportExportCSV task = new ImportExportCSV();
+ Pattern pattern = task.queryPattern;
+
+ Matcher m = pattern.matcher("rtet");
+ Assert.assertFalse(m.find());
+
+ m = pattern.matcher("Client=4e2e4a93-c412-46b8-beb9-e76e0f16740d");
+ Assert.assertFalse(m.find());
+
+ m = pattern.matcher("Client=4e2e4a93-c412-46b8-beb9-e76e0f16740d");
+ Assert.assertFalse(m.find());
+
+ m = pattern.matcher("Client.name=toto");
+ Assert.assertTrue(m.find());
+ Assert.assertEquals("Client.name", m.group(1));
+ Assert.assertEquals("Client", m.group(2));
+ Assert.assertEquals("name", m.group(3));
+ Assert.assertEquals("toto", m.group(4));
+
+ m = pattern.matcher("Client.name=toto");
+ Assert.assertTrue(m.find());
+ Assert.assertEquals("toto", m.group(6));
+
+ m = pattern.matcher("Client.name=\"toto\"");
+ Assert.assertTrue(m.find());
+ Assert.assertEquals("toto", m.group(5));
+
+ m = pattern.matcher("Client.name=\"toto");
+ Assert.assertFalse(m.find());
+
+ m = pattern.matcher("Client.name=\"to\"to\"");
+ Assert.assertTrue(m.find());
+ Assert.assertEquals("to\"to", m.group(5));
+
+ m = pattern.matcher("Client.name=toto\"");
+ Assert.assertFalse(m.find());
+ }
+
+ /**
+ * Test de parsing des valeurs multiples wikitty.
+ */
+ @Test
+ public void testMultipleFieldsParsing() {
+ String test = "(sdfsdf),(dfsdf),(fdsfsdfg),(sdfsdfqs)";
+ String[] result = StringUtil.split(test);
+ Assert.assertEquals(4, result.length);
+ Assert.assertEquals("(sdfsdf)", result[0]);
+ Assert.assertEquals("sdfsdf", result[0].substring(1, result[0].length() -1));
+ Assert.assertEquals("(dfsdf)", result[1]);
+ Assert.assertEquals("(fdsfsdfg)", result[2]);
+ Assert.assertEquals("(sdfsdfqs)", result[3]);
+
+ test = "(sdf\",\"sdf),(df()sdf),(fds\"(),()\"fsdfg),(sdfsdfqs)";
+ result = StringUtil.split(test);
+ Assert.assertEquals(4, result.length);
+ Assert.assertEquals("(sdf\",\"sdf)", result[0]);
+ Assert.assertEquals("(df()sdf)", result[1]);
+ Assert.assertEquals("(fds\"(),()\"fsdfg)", result[2]);
+ Assert.assertEquals("(sdfsdfqs)", result[3]);
+
+ test = "toto ?";
+ result = StringUtil.split(test);
+ Assert.assertEquals(1, result.length);
+ Assert.assertEquals("toto ?", result[0]);
+ }
+
+ /**
+ * Test l'import export.
+ */
+ @Test
+ public void testImport() {
+
+ // store required import extension
+ WikittyProxy proxy = new WikittyProxy(ws);
+ proxy.storeExtension(extensionClient);
+ proxy.storeExtension(WikittyTreeNodeImpl.extensionWikittyTreeNode);
+ proxy.storeExtension(extensionTag);
+
+ // declare import service
+ WikittyConfig config = new WikittyConfig();
+ WikittyImportExportService wsImport =
+ new WikittyImportExportService(config, null, ws);
+ String[] importFiles = {
+ "/csv/importclient.csv",
+ "/csv/importtree.csv",
+ "/csv/importtree2.csv"};
+ for (String importFile : importFiles) {
+ URL importFileURL = ImportExportCSVTest.class.getResource(importFile);
+ wsImport.syncImportFromUri(WikittyImportExportService.FORMAT.CSV,
+ importFileURL.toExternalForm());
+ }
+
+ // test extension support
+ Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, extensionTag.getName()).criteria();
+ PagedResult<String> pagedResult = ws.findAllByCriteria(null, criteria);
+ Assert.assertEquals(1, pagedResult.getNumFound());
+
+ // test normal import
+ Criteria criteria2 = Search.query().eq(extensionClient.getName() + ".name", "Toto").criteria();
+ PagedResult<String> pagedResult2 = ws.findAllByCriteria(null, criteria2);
+ Assert.assertEquals(1, pagedResult2.getNumFound());
+
+ // import attachment id that not exist, must be not imported
+ Criteria criteria3 = Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_NAME, "MyTreeNode").criteria();
+ PagedResult<WikittyTreeNode> pagedResult3 = proxy.findAllByCriteria(WikittyTreeNode.class, criteria3);
+ Assert.assertEquals(1, pagedResult3.getNumFound());
+ WikittyTreeNode myTreeNode = pagedResult3.getFirst();
+ Assert.assertEquals(1, myTreeNode.getAttachment().size());
+
+ // test des requetes imbriquées
+ Criteria criteria4 = Search.query().eq(WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT, myTreeNode.getWikittyId()).criteria();
+ PagedResult<WikittyTreeNode> pagedResult4 = proxy.findAllByCriteria(WikittyTreeNode.class, criteria4);
+ Assert.assertEquals(1, pagedResult4.getNumFound());
+ WikittyTreeNode mySubNode = pagedResult4.getFirst();
+ Assert.assertEquals("MySubNode", mySubNode.getName());
+ }
+}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/CommonTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/CommonTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/CommonTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -37,15 +37,15 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.WikittyTreeNode;
-import org.nuiton.wikitty.WikittyTreeNodeAbstract;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeAbstract;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.conform.StorageTest;
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/ExtensionFactoryTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/ExtensionFactoryTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/ExtensionFactoryTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -26,10 +26,10 @@
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.WikittyExtension;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.WikittyExtension;
public class ExtensionFactoryTest extends AbstractTestApi {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/SearchCriteriaTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/SearchCriteriaTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/SearchCriteriaTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -28,15 +28,15 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.search.And;
-import org.nuiton.wikitty.search.AssociatedRestriction;
-import org.nuiton.wikitty.search.Between;
-import org.nuiton.wikitty.search.BinaryOperator;
-import org.nuiton.wikitty.search.Equals;
-import org.nuiton.wikitty.search.Or;
-import org.nuiton.wikitty.search.Restriction;
-import org.nuiton.wikitty.search.RestrictionName;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.operators.And;
+import org.nuiton.wikitty.search.operators.AssociatedRestriction;
+import org.nuiton.wikitty.search.operators.Between;
+import org.nuiton.wikitty.search.operators.BinaryOperator;
+import org.nuiton.wikitty.search.operators.Equals;
+import org.nuiton.wikitty.search.operators.Or;
+import org.nuiton.wikitty.search.operators.Restriction;
+import org.nuiton.wikitty.search.operators.RestrictionName;
import org.nuiton.wikitty.search.Search;
public class SearchCriteriaTest extends AbstractTestApi {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/WikittyUtilTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/WikittyUtilTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/api/WikittyUtilTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -35,9 +35,9 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.WikittyLabelImpl;
-import org.nuiton.wikitty.WikittyExtension;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.WikittyUtil;
/**
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -36,11 +36,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.runner.RunWith;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyUtil;
import org.springframework.beans.factory.annotation.Autowired;
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -41,11 +41,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyImportExportService;
-import org.nuiton.wikitty.search.Element;
+import org.nuiton.wikitty.addons.WikittyImportExportService;
+import org.nuiton.wikitty.search.operators.Element;
import org.nuiton.wikitty.search.Search;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -34,10 +34,10 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -30,14 +30,14 @@
import java.util.List;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.PagedResult;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
import org.nuiton.wikitty.search.Search;
public class SearchTest extends AbstractTestConformance {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -45,23 +45,23 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.WikittyLabel;
-import org.nuiton.wikitty.PagedResult;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.search.PagedResult;
import org.nuiton.wikitty.WikittyTree;
-import org.nuiton.wikitty.WikittyTreeNode;
-import org.nuiton.wikitty.WikittyTreeNodeImpl;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
-import org.nuiton.wikitty.WikittyLabelUtil;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.addons.WikittyLabelUtil;
import org.nuiton.wikitty.WikittyObsoleteException;
import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
-import org.nuiton.wikitty.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.search.Element;
+import org.nuiton.wikitty.search.operators.Element;
import org.nuiton.wikitty.search.Search;
public abstract class StorageTest extends AbstractTestConformance {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/AbstractWikittyServiceTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/AbstractWikittyServiceTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/AbstractWikittyServiceTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -25,13 +25,13 @@
package org.nuiton.wikitty.layers;
import org.junit.Before;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
public abstract class AbstractWikittyServiceTest {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -34,10 +34,10 @@
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyServiceCached;
-import org.nuiton.wikitty.WikittyServiceInMemory;
+import org.nuiton.wikitty.services.WikittyServiceCached;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
/** test {@link WikittyServiceCached} */
public class WikittyServiceCachedTest extends AbstractWikittyServiceTest {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -34,21 +34,21 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyAuthorisation;
-import org.nuiton.wikitty.WikittyAuthorisationAbstract;
-import org.nuiton.wikitty.WikittyAuthorisationHelper;
-import org.nuiton.wikitty.WikittyAuthorisationImpl;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyAuthorisation;
+import org.nuiton.wikitty.entities.WikittyAuthorisationAbstract;
+import org.nuiton.wikitty.entities.WikittyAuthorisationHelper;
+import org.nuiton.wikitty.entities.WikittyAuthorisationImpl;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyGroup;
+import org.nuiton.wikitty.entities.WikittyGroup;
import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittySecurityHelper;
+import org.nuiton.wikitty.services.WikittySecurityHelper;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyServiceInMemory;
-import org.nuiton.wikitty.WikittyServiceSecurity;
-import org.nuiton.wikitty.WikittyUser;
-import org.nuiton.wikitty.WikittyUserImpl;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
+import org.nuiton.wikitty.services.WikittyServiceSecurity;
+import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.entities.WikittyUserImpl;
import org.nuiton.wikitty.WikittyUtil;
/** test {@link org.nuiton.wikitty.WikittyServiceSecurity}. */
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -37,14 +37,14 @@
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
-import org.nuiton.wikitty.WikittyServiceInMemory;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.api.AbstractTestApi;
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -7,9 +7,9 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.wikitty.WikittyService.ServiceListenerType;
-import org.nuiton.wikitty.WikittyServiceEvent;
-import org.nuiton.wikitty.WikittyServiceListener;
-import org.nuiton.wikitty.WikittyServiceNotifier;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyServiceListener;
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
/**
* Test si la notification par event fonctionne bien (les bons types d'event
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -36,8 +36,8 @@
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.junit.Test;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyServiceEvent;
-import org.nuiton.wikitty.XMPPNotifierTransporter;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.XMPPNotifierTransporter;
/**
*
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceHelperTest.java (from rev 459, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceHelperTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceHelperTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,45 @@
+package org.nuiton.wikitty.services;
+
+
+import org.nuiton.wikitty.services.WikittyServiceCached;
+import org.nuiton.wikitty.services.WikittyServiceNotifier;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
+import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyServiceFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceHelperTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceHelperTest.class);
+
+ @Test
+ public void testBuild() throws Exception {
+ Properties props = new Properties();
+ props.setProperty(WikittyConfig.Option.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(),
+ WikittyServiceInMemory.class.getName() + "," +
+ WikittyServiceNotifier.class.getName() + "," +
+ WikittyServiceCached.class.getName());
+ WikittyConfig config = new WikittyConfig(props);
+ WikittyService ws = WikittyServiceFactory.buildWikittyService(config);
+
+ Assert.assertEquals(WikittyServiceCached.class, ws.getClass());
+ ws = ((WikittyServiceCached)ws).ws;
+ Assert.assertEquals(WikittyServiceNotifier.class, ws.getClass());
+ ws = ((WikittyServiceNotifier)ws).ws;
+ Assert.assertEquals(WikittyServiceInMemory.class, ws.getClass());
+ }
+}
Copied: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceTransactionTest.java (from rev 459, trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java)
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceTransactionTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/services/WikittyServiceTransactionTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -0,0 +1,63 @@
+package org.nuiton.wikitty.services;
+
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceTransaction;
+import org.nuiton.wikitty.services.WikittyServiceInMemory;
+import java.util.Collections;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.entities.WikittyLabelImpl;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceTransactionTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceTransactionTest.class);
+
+ public WikittyServiceTransactionTest() {
+ }
+
+ @Test
+ public void testTransaction() throws Exception {
+ WikittyConfig config = new WikittyConfig();
+ WikittyServiceInMemory ws = new WikittyServiceInMemory(config);
+ WikittyServiceTransaction tx = new WikittyServiceTransaction(config, ws);
+
+ // ajout d'objet hors transaction
+ WikittyLabel label = new WikittyLabelImpl();
+ label.addLabels("coucou");
+ ws.store(null, Collections.singleton(label.getWikitty()), false);
+
+ // on doit le retrouver dans la transation (meme si elle a ete ouverte avant)
+ Wikitty wTx = WikittyServiceEnhanced.restore(tx, null, label.getWikittyId());
+ Assert.assertEquals(label.getWikitty(), wTx);
+
+ // on creer un objet dans la transaction
+ WikittyLabel labelTx = new WikittyLabelImpl();
+ labelTx.addLabels("coucouTx");
+ tx.store(null, Collections.singleton(labelTx.getWikitty()), false);
+
+ // on ne doit pas le retrouver hors de la transation
+ Wikitty w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
+ Assert.assertEquals(null, w);
+
+ // on commit, du coup on doit retrouver l'objet
+ tx.commit(null);
+ w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
+ Assert.assertEquals(labelTx.getWikitty(), w);
+
+ }
+
+}
Modified: trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml
===================================================================
--- trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-29 15:19:55 UTC (rev 461)
@@ -33,7 +33,7 @@
<bean name="wikittyConfig" class="org.nuiton.wikitty.WikittyConfig"/>
- <bean id="wikittyService" class="org.nuiton.wikitty.WikittyServiceInMemory">
+ <bean id="wikittyService" class="org.nuiton.wikitty.services.WikittyServiceInMemory">
<constructor-arg ref="wikittyConfig"/>
</bean>
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -133,14 +133,14 @@
addImport(clazz, WikittyTransformerUtil.BUSINESS_ENTITY_CLASS_FQN);
addImport(clazz, WikittyTransformerUtil.BUSINESS_ENTITY_WIKITTY_CLASS_FQN);
addImport(clazz, WikittyTransformerUtil.WIKITTY_CLASS_FQN);
- addImport(clazz, "org.nuiton.wikitty.WikittyExtension");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyExtension");
addImport(clazz, "org.nuiton.wikitty.WikittyUtil");
- addImport(clazz, "org.nuiton.wikitty.WikittyUser");
- addImport(clazz, "org.nuiton.wikitty.WikittyUserAbstract");
- addImport(clazz, "org.nuiton.wikitty.WikittyUserImpl");
- addImport(clazz, "org.nuiton.wikitty.WikittyTreeNode");
- addImport(clazz, "org.nuiton.wikitty.WikittyTreeNodeAbstract");
- addImport(clazz, "org.nuiton.wikitty.WikittyTreeNodeImpl");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUser");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserAbstract");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserImpl");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract");
+ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl");
addImport(clazz, java.util.List.class);
addImport(clazz, java.util.ArrayList.class);
addImport(clazz, java.util.Collection.class);
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -107,14 +107,14 @@
addImport(contract, WikittyTransformerUtil.BUSINESS_ENTITY_CLASS_FQN);
addImport(contract, WikittyTransformerUtil.BUSINESS_ENTITY_WIKITTY_CLASS_FQN);
addImport(contract, WikittyTransformerUtil.WIKITTY_CLASS_FQN);
- addImport(contract, "org.nuiton.wikitty.WikittyExtension");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyExtension");
addImport(contract, "org.nuiton.wikitty.WikittyUtil");
- addImport(contract, "org.nuiton.wikitty.WikittyUser");
- addImport(contract, "org.nuiton.wikitty.WikittyUserAbstract");
- addImport(contract, "org.nuiton.wikitty.WikittyUserImpl");
- addImport(contract, "org.nuiton.wikitty.WikittyTreeNode");
- addImport(contract, "org.nuiton.wikitty.WikittyTreeNodeAbstract");
- addImport(contract, "org.nuiton.wikitty.WikittyTreeNodeImpl");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUser");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserAbstract");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserImpl");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract");
+ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl");
addImport(contract, java.util.List.class);
addImport(contract, java.util.ArrayList.class);
addImport(contract, java.util.Collection.class);
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -52,14 +52,14 @@
addImport(helper, WikittyTransformerUtil.BUSINESS_ENTITY_CLASS_FQN);
addImport(helper, WikittyTransformerUtil.BUSINESS_ENTITY_WIKITTY_CLASS_FQN);
addImport(helper, WikittyTransformerUtil.WIKITTY_CLASS_FQN);
- addImport(helper, "org.nuiton.wikitty.WikittyExtension");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyExtension");
addImport(helper, "org.nuiton.wikitty.WikittyUtil");
- addImport(helper, "org.nuiton.wikitty.WikittyUser");
- addImport(helper, "org.nuiton.wikitty.WikittyUserAbstract");
- addImport(helper, "org.nuiton.wikitty.WikittyUserImpl");
- addImport(helper, "org.nuiton.wikitty.WikittyTreeNode");
- addImport(helper, "org.nuiton.wikitty.WikittyTreeNodeAbstract");
- addImport(helper, "org.nuiton.wikitty.WikittyTreeNodeImpl");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUser");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserAbstract");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserImpl");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract");
+ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl");
addImport(helper, java.util.List.class);
addImport(helper, java.util.ArrayList.class);
addImport(helper, java.util.Collection.class);
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -74,14 +74,14 @@
addImport(implementation, WikittyTransformerUtil.BUSINESS_ENTITY_CLASS_FQN);
addImport(implementation, WikittyTransformerUtil.BUSINESS_ENTITY_WIKITTY_CLASS_FQN);
addImport(implementation, WikittyTransformerUtil.WIKITTY_CLASS_FQN);
- addImport(implementation, "org.nuiton.wikitty.WikittyExtension");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyExtension");
addImport(implementation, "org.nuiton.wikitty.WikittyUtil");
- addImport(implementation, "org.nuiton.wikitty.WikittyUser");
- addImport(implementation, "org.nuiton.wikitty.WikittyUserAbstract");
- addImport(implementation, "org.nuiton.wikitty.WikittyUserImpl");
- addImport(implementation, "org.nuiton.wikitty.WikittyTreeNode");
- addImport(implementation, "org.nuiton.wikitty.WikittyTreeNodeAbstract");
- addImport(implementation, "org.nuiton.wikitty.WikittyTreeNodeImpl");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUser");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserAbstract");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyUserImpl");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract");
+ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl");
addImport(implementation, java.util.List.class);
addImport(implementation, java.util.ArrayList.class);
addImport(implementation, java.util.Collection.class);
Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java
===================================================================
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -37,10 +37,15 @@
/** utility class should not be instanciated */
private WikittyTransformerUtil() {}
- protected static final String BUSINESS_ENTITY_CLASS_FQN = "org.nuiton.wikitty.BusinessEntity";
- protected static final String BUSINESS_ENTITY_WIKITTY_CLASS_FQN = "org.nuiton.wikitty.BusinessEntityWikitty";
- protected static final String WIKITTY_CLASS_FQN = "org.nuiton.wikitty.Wikitty";
- protected static final String WIKITTY_EXTENSION_CLASS_FQN = "org.nuiton.wikitty.WikittyExtension";
+ protected static final String ENTITY_PACKAGE = "org.nuiton.wikitty.entities";
+ protected static final String BUSINESS_ENTITY_CLASS_FQN =
+ ENTITY_PACKAGE + ".BusinessEntity";
+ protected static final String BUSINESS_ENTITY_WIKITTY_CLASS_FQN =
+ ENTITY_PACKAGE + ".BusinessEntityWikitty";
+ protected static final String WIKITTY_CLASS_FQN =
+ ENTITY_PACKAGE + ".Wikitty";
+ protected static final String WIKITTY_EXTENSION_CLASS_FQN =
+ ENTITY_PACKAGE + ".WikittyExtension";
protected static final String TAG_VERSION = "version";
protected static final String TAG_ALTERNATIVE_NAME = "alternativeName";
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -58,13 +58,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.entities.FieldType;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyExtensionStorage;
-import org.nuiton.wikitty.WikittyServiceEvent;
-import org.nuiton.wikitty.WikittyTransaction;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.storage.WikittyExtensionStorage;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.services.WikittyTransaction;
import org.nuiton.wikitty.WikittyUtil;
/**
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -28,7 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyServiceImpl;
+import org.nuiton.wikitty.services.WikittyServiceImpl;
import org.nuiton.wikitty.solr.WikittySearchEnginSolr;
/**
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -71,16 +71,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyExtensionStorage;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.storage.WikittyExtensionStorage;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyObsoleteException;
-import org.nuiton.wikitty.WikittyServiceEvent;
-import org.nuiton.wikitty.WikittyStorage;
-import org.nuiton.wikitty.WikittyTransaction;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
+import org.nuiton.wikitty.storage.WikittyStorage;
+import org.nuiton.wikitty.services.WikittyTransaction;
import org.nuiton.wikitty.WikittyUtil;
/**
Modified: trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/Restriction2Solr.java
===================================================================
--- trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/Restriction2Solr.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/Restriction2Solr.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -35,30 +35,30 @@
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyTransaction;
-import org.nuiton.wikitty.search.And;
-import org.nuiton.wikitty.search.AssociatedRestriction;
-import org.nuiton.wikitty.search.Between;
-import org.nuiton.wikitty.search.Contains;
-import org.nuiton.wikitty.search.Element;
-import org.nuiton.wikitty.search.EndsWith;
-import org.nuiton.wikitty.search.Equals;
-import org.nuiton.wikitty.search.Greater;
-import org.nuiton.wikitty.search.GreaterOrEqual;
-import org.nuiton.wikitty.search.In;
-import org.nuiton.wikitty.search.Keyword;
-import org.nuiton.wikitty.search.Less;
-import org.nuiton.wikitty.search.LessOrEqual;
-import org.nuiton.wikitty.search.Like;
-import org.nuiton.wikitty.search.Not;
-import org.nuiton.wikitty.search.NotEquals;
-import org.nuiton.wikitty.search.Or;
-import org.nuiton.wikitty.search.Restriction;
+import org.nuiton.wikitty.services.WikittyTransaction;
+import org.nuiton.wikitty.search.operators.And;
+import org.nuiton.wikitty.search.operators.AssociatedRestriction;
+import org.nuiton.wikitty.search.operators.Between;
+import org.nuiton.wikitty.search.operators.Contains;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.operators.EndsWith;
+import org.nuiton.wikitty.search.operators.Equals;
+import org.nuiton.wikitty.search.operators.Greater;
+import org.nuiton.wikitty.search.operators.GreaterOrEqual;
+import org.nuiton.wikitty.search.operators.In;
+import org.nuiton.wikitty.search.operators.Keyword;
+import org.nuiton.wikitty.search.operators.Less;
+import org.nuiton.wikitty.search.operators.LessOrEqual;
+import org.nuiton.wikitty.search.operators.Like;
+import org.nuiton.wikitty.search.operators.Not;
+import org.nuiton.wikitty.search.operators.NotEquals;
+import org.nuiton.wikitty.search.operators.Or;
+import org.nuiton.wikitty.search.operators.Restriction;
import org.nuiton.wikitty.search.RestrictionHelper;
-import org.nuiton.wikitty.search.StartsWith;
-import org.nuiton.wikitty.search.Unlike;
-import org.nuiton.wikitty.search.Like.SearchAs;
-import org.nuiton.wikitty.search.Null;
+import org.nuiton.wikitty.search.operators.StartsWith;
+import org.nuiton.wikitty.search.operators.Unlike;
+import org.nuiton.wikitty.search.operators.Like.SearchAs;
+import org.nuiton.wikitty.search.operators.Null;
/**
* @author "Nicolas Chapurlat" <nicolas.chapurlat(a)logica.com>
Modified: trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -47,19 +47,19 @@
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.FacetTopic;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.PagedResult;
-import org.nuiton.wikitty.WikittyTreeNode;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.FacetTopic;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.WikittyException;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyExtensionStorage;
-import org.nuiton.wikitty.WikittySearchEngin;
-import org.nuiton.wikitty.WikittyTransaction;
-import org.nuiton.wikitty.search.Element;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.storage.WikittyExtensionStorage;
+import org.nuiton.wikitty.storage.WikittySearchEngin;
+import org.nuiton.wikitty.services.WikittyTransaction;
+import org.nuiton.wikitty.search.operators.Element;
import org.nuiton.wikitty.search.Search;
import com.arjuna.ats.arjuna.coordinator.BasicAction;
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -26,7 +26,7 @@
import org.junit.Before;
import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
public abstract class AbstractTestSolr {
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/SolrSearchTest.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/SolrSearchTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/SolrSearchTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -35,18 +35,18 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.FacetTopic;
-import org.nuiton.wikitty.PagedResult;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.FacetTopic;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.conform.AbstractTestConformance;
import org.nuiton.wikitty.conform.StorageTest;
-import org.nuiton.wikitty.search.Element;
-import org.nuiton.wikitty.search.Like;
-import org.nuiton.wikitty.search.Like.SearchAs;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.operators.Like;
+import org.nuiton.wikitty.search.operators.Like.SearchAs;
import org.nuiton.wikitty.search.RestrictionHelper;
import org.nuiton.wikitty.search.Search;
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/TreeTest.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/TreeTest.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/TreeTest.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -38,16 +38,16 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.ExtensionFactory;
-import org.nuiton.wikitty.FieldType.TYPE;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.ExtensionFactory;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
import org.nuiton.wikitty.WikittyTree;
-import org.nuiton.wikitty.WikittyTreeNode;
-import org.nuiton.wikitty.WikittyTreeNodeImpl;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
-import org.nuiton.wikitty.WikittyServiceEvent;
+import org.nuiton.wikitty.entities.WikittyTreeNode;
+import org.nuiton.wikitty.entities.WikittyTreeNodeImpl;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
+import org.nuiton.wikitty.services.WikittyServiceEvent;
import org.nuiton.wikitty.conform.StorageTest;
import org.nuiton.wikitty.search.Search;
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -26,9 +26,10 @@
package org.nuiton.wikitty.solr.test;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.wikitty.WikittyServiceImpl;
-import org.nuiton.wikitty.WikittyServiceInMemory;
+import org.nuiton.wikitty.services.WikittyServiceImpl;
import org.nuiton.wikitty.solr.WikittySearchEnginSolr;
+import org.nuiton.wikitty.storage.WikittyExtensionStorageInMemory;
+import org.nuiton.wikitty.storage.WikittyStorageInMemory;
/**
*
@@ -41,8 +42,8 @@
public class WikittyServiceSolr extends WikittyServiceImpl {
public WikittyServiceSolr(ApplicationConfig config) {
- extensionStorage = new WikittyServiceInMemory.WikittyExtensionStorageInMemory();
- wikittyStorage = new WikittyServiceInMemory.WikittyStorageInMemory();
+ extensionStorage = new WikittyExtensionStorageInMemory();
+ wikittyStorage = new WikittyStorageInMemory();
searchEngin = new WikittySearchEnginSolr(config, extensionStorage);
}
}
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/FieldExtension.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/FieldExtension.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/FieldExtension.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -28,8 +28,8 @@
*/
package org.nuiton.wikitty.ui;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.WikittyExtension;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.WikittyExtension;
/**
*
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -41,7 +41,7 @@
import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyServiceCached;
+import org.nuiton.wikitty.services.WikittyServiceCached;
import org.nuiton.wikitty.jdbc.WikittyServiceJDBC;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Model.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Model.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Model.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -26,12 +26,12 @@
import java.util.ArrayList;
import java.util.List;
-import org.nuiton.wikitty.Criteria;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyServiceEnhanced;
-import org.nuiton.wikitty.search.Element;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
+import org.nuiton.wikitty.search.operators.Element;
import org.nuiton.wikitty.search.Search;
/**
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -32,10 +32,10 @@
import javax.servlet.http.HttpSession;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyImpl;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.WikittyProxy;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyForm.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyForm.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyForm.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -29,10 +29,10 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
-import org.nuiton.wikitty.FieldType;
-import org.nuiton.wikitty.FieldType.TYPE;
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyExtension;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Datebox;
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyModel.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyModel.java 2010-10-29 15:19:06 UTC (rev 460)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyModel.java 2010-10-29 15:19:55 UTC (rev 461)
@@ -26,7 +26,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.entities.Wikitty;
import org.zkoss.zkplus.databind.BindingListModel;
import org.zkoss.zul.AbstractListModel;
import org.zkoss.zul.event.ListDataEvent;
1
0
r460 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty test/java/org/nuiton/wikitty
by bpoussin@users.nuiton.org 29 Oct '10
by bpoussin@users.nuiton.org 29 Oct '10
29 Oct '10
Author: bpoussin
Date: 2010-10-29 17:19:06 +0200 (Fri, 29 Oct 2010)
New Revision: 460
Url: http://nuiton.org/repositories/revision/wikitty/460
Log:
Repackage all classe in wikitty-api module
http://www.nuiton.org/issues/show/1003
Removed:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/
1
0
Author: tchemit
Date: 2010-10-29 10:30:33 +0200 (Fri, 29 Oct 2010)
New Revision: 459
Url: http://nuiton.org/repositories/revision/wikitty/459
Log:
Update mavenpom4redmine to 2.4.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-29 02:12:48 UTC (rev 458)
+++ trunk/pom.xml 2010-10-29 08:30:33 UTC (rev 459)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.4-SNAPSHOT</version>
+ <version>2.4</version>
</parent>
<!-- ************************************************************* -->
1
0
r458 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty main/java/org/nuiton/wikitty/importexport test/java/org/nuiton/wikitty test/java/org/nuiton/wikitty/conform test/java/org/nuiton/wikitty/importexport test/java/org/nuiton/wikitty/layers test/java/org/nuiton/wikitty/memory
by bpoussin@users.nuiton.org 29 Oct '10
by bpoussin@users.nuiton.org 29 Oct '10
29 Oct '10
Author: bpoussin
Date: 2010-10-29 04:12:48 +0200 (Fri, 29 Oct 2010)
New Revision: 458
Url: http://nuiton.org/repositories/revision/wikitty/458
Log:
utilisation de WikittyServiceTransaction pour l'import
suppression dans WikittyService (et d'autres classes) de toute reference a WikittyTransaction
http://www.nuiton.org/issues/show/1000
Removed:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/WikittyBatchUpdate.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ExportTask.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportCSV.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportMethod.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportXML.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportTask.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/PagedResult.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -101,46 +101,14 @@
/**
* Convert all result to the wikitty type and return new PagedResult with
* this new result list.
- *
- * @param securityToken security token
- * @param ws wikitty service
- * @return new PagedResult, this result can have less elements that original
- * for some reason (security, ...)
- */
- public PagedResult<Wikitty> cast(String securityToken, WikittyService ws) {
- List<Wikitty> castedResult;
-
- if (results.size() == 0) {
- castedResult = new ArrayList<Wikitty>();
- } else {
- if (results.get(0) instanceof String) {
- // le pagedresult courant contient des Ids
- // Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
- // ce PagedResult ne sait pas ce qu'il fait :)
- List<String> ids = (List<String>) results;
- castedResult = ws.restore(securityToken, null, ids);
- } else {
- throw new ClassCastException("PagedResult don't contains" +
- " wikitty String id but " + results.get(0).getClass());
- }
- }
- PagedResult<Wikitty> result = new PagedResult<Wikitty>(
- firstIndice, numFound, queryString, facets, castedResult);
- return result;
- }
-
- /**
- * Convert all result to the wikitty type and return new PagedResult with
- * this new result list.
*
* @param securityToken security token
* @param ws wikitty service
- * @param transaction transaction
*
* @return new PagedResult, this result can have less elements that original
* for some reason (security, ...)
*/
- public PagedResult<Wikitty> cast(String securityToken, WikittyService ws, WikittyTransaction transaction) {
+ public PagedResult<Wikitty> cast(String securityToken, WikittyService ws) {
List<Wikitty> castedResult;
if (results.size() == 0) {
@@ -151,7 +119,7 @@
// Si ce n'est pas le cas, ca veut dire que le developpeur utilisant
// ce PagedResult ne sait pas ce qu'il fait :)
List<String> ids = (List<String>) results;
- castedResult = ws.restore(securityToken, transaction, ids);
+ castedResult = ws.restore(securityToken, ids);
} else {
throw new ClassCastException("PagedResult don't contains" +
" wikitty String id but " + results.get(0).getClass());
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -190,14 +190,6 @@
}
/*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[])
- */
- @Override
- public void removeExtension(WikittyServiceEvent event) {
-
- }
-
- /*
* @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
*/
@Override
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigration.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -51,7 +51,6 @@
* Migrate wikitty data from oldExt version to newExt.
*
* @param service Wikitty service that do migration
- * @param transaction current transaction to use
* @param wikitty Wikitty object that contains data in old version
* extension format
* @param oldExt old extension definition
@@ -59,7 +58,7 @@
* @return same wikitty as argument if nothing to do, or new wikitty
* if some modification is done
*/
- public Wikitty migrate(WikittyService service, WikittyTransaction transaction,
- Wikitty wikitty, WikittyExtension oldExt, WikittyExtension newExt);
+ public Wikitty migrate(WikittyService service, Wikitty wikitty,
+ WikittyExtension oldExt, WikittyExtension newExt);
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyExtensionMigrationRename.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -58,16 +58,16 @@
* @param wikitty wikitty to add extension to
* @param newExt extension to add
*/
- protected void addExtension(WikittyService service, WikittyTransaction transaction, Wikitty wikitty, WikittyExtension newExt) {
+ protected void addExtension(
+ WikittyService service, Wikitty wikitty, WikittyExtension newExt) {
// manage requires before current
String requires = newExt.getRequires();
if (StringUtils.isNotEmpty(requires)) {
for (String require : requires.split(",")) {
WikittyExtension newRequireExt =
- service.restoreExtensionLastVersion(
- null, transaction, require);
- addExtension(service, transaction, wikitty, newRequireExt);
+ service.restoreExtensionLastVersion(null, require);
+ addExtension(service, wikitty, newRequireExt);
}
}
@@ -76,7 +76,8 @@
}
@Override
- public Wikitty migrate(WikittyService service, WikittyTransaction transaction, Wikitty wikitty, WikittyExtension oldExt, WikittyExtension newExt) {
+ public Wikitty migrate(WikittyService service, Wikitty wikitty,
+ WikittyExtension oldExt, WikittyExtension newExt) {
String wikittyId = wikitty.getId();
String wikittyVersion = wikitty.getVersion();
@@ -90,10 +91,10 @@
// during loop add new when old one is found
if (extension.equals(oldExt)) {
- addExtension(service, transaction, result, newExt);
+ addExtension(service, result, newExt);
}
else {
- addExtension(service, transaction, result, extension);
+ addExtension(service, result, extension);
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -195,19 +195,16 @@
String securityToken, List<WikittyServiceEvent> events);
/**
- * Manage Update and creation, action is done in transaction passed in
- * argument.
+ * Manage Update and creation.
*
* @param securityToken security token
- * @param transaction transaction used to do the action (can be null, if we
- * want new transaction)
* @param wikitties list of wikitty to be persisted
* @param force boolean force non version version increment on saved wikitty
* or force version on wikitty creation (version 0.0)
* @return update response
*/
- public WikittyServiceEvent store(String securityToken, WikittyTransaction transaction,
- Collection<Wikitty> wikitties, boolean force);
+ public WikittyServiceEvent store(
+ String securityToken, Collection<Wikitty> wikitties, boolean force);
/**
* Return all extension id (ex: "extName[version])").
@@ -228,56 +225,45 @@
public List<String> getAllExtensionsRequires(String securityToken, String extensionName);
/**
- * Manage Update and creation, action is done in transaction passed in
- * argument
+ * Manage Update and creation
*
* @param securityToken security token
- * @param transaction transaction used to do the action (can be null if we
- * want new transaction)
* @param exts list of wikitty extension to be persisted
* @return update response
*/
- public WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts);
+ public WikittyServiceEvent storeExtension(
+ String securityToken, Collection<WikittyExtension> exts);
/**
* Load extension from id. Id is 'name[version]'.
- * Action is done in transaction passed in argument.
*
* @param securityToken security token
- * @param transaction transaction used to do the action (can be null if we
- * want new transaction)
* @param extensionId
* @return the corresponding object, exception if no such object found.
*/
- public WikittyExtension restoreExtension(String securityToken,
- WikittyTransaction transaction, String extensionId);
+ public WikittyExtension restoreExtension(
+ String securityToken, String extensionId);
/**
* Search extension with name in last version.
*
* @param securityToken security token
- * @param transaction transaction used to do the action (can be null if we
- * want new transaction)
* @param name extension name
* @return the corresponding object, exception if no such object found.
*/
public WikittyExtension restoreExtensionLastVersion(
- String securityToken, WikittyTransaction transaction, String name);
+ String securityToken, String name);
/**
- * Restore wikitty using opened transaction.
+ * Restore wikitty
*
* @param securityToken security token
- * @param transaction transaction to use (can be null if we
- * want new transaction)
* @param id list of wikitty ids to restore
* @return list of corresponding wikitty, if one id is not valid (no object
* or deleted or no authorisation) this id return null and result list can
* have null elements
*/
- public List<Wikitty> restore(String securityToken,
- WikittyTransaction transaction, List<String> id);
+ public List<Wikitty> restore(String securityToken, List<String> id);
/**
* Delete all object if id exists.
@@ -290,13 +276,11 @@
/**
*
* @param securityToken security token
- * @param transaction (can be null if we
- * want new transaction)
* @param criteria
* @return
*/
- public PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria);
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria);
/**
* First lonely (or first one) wikitty object that match criteria, if no
@@ -305,12 +289,9 @@
*
* @param securityToken security token
* @param criteria
- * @param transaction (can be null if we
- * want new transaction)
* @return wikitty object or null
*/
- public Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria);
+ public Wikitty findByCriteria(String securityToken, Criteria criteria);
/*
* Classification
@@ -344,8 +325,8 @@
* @param wikittyId
* @return
*/
- public Map.Entry<WikittyTreeNode, Integer> restoreNode(String securityToken,
- String wikittyId, Criteria filter);
+ public Map.Entry<WikittyTreeNode, Integer> restoreNode(
+ String securityToken, String wikittyId, Criteria filter);
/**
* Retrieve all wikitties children with count (no recursively) of an other one
@@ -355,8 +336,8 @@
* @param wikittyId
* @return
*/
- public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken,
- String wikittyId, Criteria filter);
+ public Map<WikittyTreeNode, Integer> restoreChildren(
+ String securityToken, String wikittyId, Criteria filter);
/*
@@ -369,8 +350,8 @@
*
* @param securityToken security token
*/
- public Wikitty restoreVersion(String securityToken,
- String wikittyId, String version);
+ public Wikitty restoreVersion(
+ String securityToken, String wikittyId, String version);
/*
* admin
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -50,20 +50,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceCached.class);
- // FIXME REMOVE IT
-// /**
-// * Utiliser pour mettre à jour le cache en ecoutant les evenements
-// * sur le service.
-// *
-// * Le service {@link #ws} doit supporter l'enregistrement de listener.
-// */
-// static public final String WIKITTY_CACHE_LISTEN_REMOTEEVENTS =
-// "wikitty.service.cache.listenevents";
-//
-// /** used as property name in props given in the constructor */
-// public static final String WIKITTY_CACHE_RESTORE_COPIES =
-// "wikitty.service.cache.allwaysRestoreCopies";
-
/** Cache. */
protected WikittyCache cache = null;
@@ -206,12 +192,11 @@
* @return
*/
@Override
- public PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- // if we want to add cache for this method, we must use
- // transaction.getCache(), and we must clear cache when
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ // if we want to add cache for this method, we must clear cache when
// addLabel, store, storeExtension are called
- return ws.findAllByCriteria(securityToken, transaction, criteria);
+ return ws.findAllByCriteria(securityToken, criteria);
}
/**
@@ -224,11 +209,10 @@
* @return
*/
@Override
- public Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
// if we want to add cache for this method, we must clear cache when
// addLabel, store, storeExtension are called
- return ws.findByCriteria(securityToken, transaction, criteria);
+ return ws.findByCriteria(securityToken, criteria);
}
/**
@@ -259,12 +243,11 @@
* Overriden to put all restored object from server in cache
*
* @param securityToken security token
- * @param transaction transaction to use
* @param ids wikitty ids to restore
* @return wikitty list
*/
@Override
- public List<Wikitty> restore(String securityToken, WikittyTransaction transaction, List<String> ids) {
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
ArrayList<String> notInCache = new ArrayList<String>();
// linked to maintains the ordre
LinkedHashMap<String, Wikitty> fromCache =
@@ -278,7 +261,7 @@
}
// retrieve missing object
- List<Wikitty> missingInCache = ws.restore(securityToken, transaction, notInCache);
+ List<Wikitty> missingInCache = ws.restore(securityToken, notInCache);
cache.putAllWikitty(missingInCache);
@@ -320,10 +303,9 @@
*/
@Override
public WikittyExtension restoreExtensionLastVersion(
- String securityToken, WikittyTransaction transaction, String name) {
+ String securityToken, String name) {
// TODO poussin 20100412: perhaps use cache for extension ?
- // if use cache use transaction.getCache()
- return ws.restoreExtensionLastVersion(securityToken, transaction, name);
+ return ws.restoreExtensionLastVersion(securityToken, name);
}
/**
@@ -372,35 +354,26 @@
* @return
*/
@Override
- public WikittyServiceEvent store(String securityToken, WikittyTransaction transaction,
+ public WikittyServiceEvent store(String securityToken,
Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = ws.store(securityToken, transaction,
- wikitties, force);
+ WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
- if (transaction != null) {
- for (Wikitty w : wikitties) {
- result.update(w);
- }
- transaction.getCache().putAllWikitty(wikitties);
- }
-
+ cache.putAllWikitty(result.getWikitties().values());
+
return result;
}
@Override
public WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts) {
- // si on implante le cache pour cette methode, utiliser transaction.getCache()
- //throw new UnsupportedOperationException("Not supported yet.");
- return ws.storeExtension(securityToken, transaction, exts);
+ Collection<WikittyExtension> exts) {
+ // TODO poussin 20101029: perhaps use cache for extension ?
+ return ws.storeExtension(securityToken, exts);
}
@Override
- public WikittyExtension restoreExtension(String securityToken,
- WikittyTransaction transaction, String id) {
- // si on implante le cache pour cette methode, utiliser transaction.getCache()
- //throw new UnsupportedOperationException("Not supported yet.");
- return ws.restoreExtension(securityToken, transaction, id);
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ // TODO poussin 20101029: perhaps use cache for extension ?
+ return ws.restoreExtension(securityToken, id);
}
@Override
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -101,10 +101,9 @@
}
@Override
- public WikittyServiceEvent store(String securityToken,
- WikittyTransaction transaction, Collection<Wikitty> wikitties,
- boolean force) {
- return delegate.store(securityToken, transaction, wikitties, force);
+ public WikittyServiceEvent store(
+ String securityToken, Collection<Wikitty> wikitties, boolean force) {
+ return delegate.store(securityToken, wikitties, force);
}
@Override
@@ -120,27 +119,24 @@
@Override
public WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts) {
- return delegate.storeExtension(securityToken, transaction, exts);
+ Collection<WikittyExtension> exts) {
+ return delegate.storeExtension(securityToken, exts);
}
@Override
- public WikittyExtension restoreExtension(String securityToken,
- WikittyTransaction transaction, String id) {
- return delegate.restoreExtension(securityToken, transaction, id);
+ public WikittyExtension restoreExtension(String securityToken, String id) {
+ return delegate.restoreExtension(securityToken, id);
}
@Override
- public WikittyExtension restoreExtensionLastVersion(String securityToken,
- WikittyTransaction transaction, String name) {
- return delegate.restoreExtensionLastVersion(securityToken, transaction,
- name);
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ return delegate.restoreExtensionLastVersion(securityToken, name);
}
@Override
- public List<Wikitty> restore(String securityToken,
- WikittyTransaction transaction, List<String> id) {
- return delegate.restore(securityToken, transaction, id);
+ public List<Wikitty> restore(String securityToken, List<String> id) {
+ return delegate.restore(securityToken, id);
}
@Override
@@ -149,15 +145,14 @@
}
@Override
- public PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- return delegate.findAllByCriteria(securityToken, transaction, criteria);
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ return delegate.findAllByCriteria(securityToken, criteria);
}
@Override
- public Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- return delegate.findByCriteria(securityToken, transaction, criteria);
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ return delegate.findByCriteria(securityToken, criteria);
}
@Override
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEnhanced.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -26,38 +26,19 @@
}
public WikittyServiceEvent store(String securityToken, Wikitty wikitty) {
- return store(securityToken, null, Collections.singleton(wikitty), false);
+ return store(securityToken, Collections.singleton(wikitty), false);
}
public WikittyServiceEvent store(String securityToken,
Collection<Wikitty> wikitties) {
- return store(securityToken, null, wikitties, false);
+ return store(securityToken, wikitties, false);
}
- public WikittyServiceEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
- return store(securityToken, null, wikitties, force);
- }
-
public WikittyServiceEvent storeExtension(String securityToken,
WikittyExtension ext) {
- return storeExtension(securityToken, null, Collections.singleton(ext));
+ return storeExtension(securityToken, Collections.singleton(ext));
}
- public WikittyServiceEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- return storeExtension(securityToken, null, exts);
- }
-
- public WikittyExtension restoreExtension(String securityToken, String id) {
- return restoreExtension(securityToken, null, id);
- }
-
- public WikittyExtension restoreExtensionLastVersion(String securityToken,
- String name) {
- return restoreExtensionLastVersion(securityToken, null, name);
- }
-
/**
*
* @param securityToken security token
@@ -71,23 +52,10 @@
return result;
}
- public List<Wikitty> restore(String securityToken, List<String> id) {
- return restore(securityToken, null, id);
- }
-
public WikittyServiceEvent delete(String securityToken, String id) {
return delete(securityToken, Collections.singleton(id));
}
- public PagedResult<String> findAllByCriteria(String securityToken,
- Criteria criteria) {
- return findAllByCriteria(securityToken, null, criteria);
- }
-
- public Wikitty findByCriteria(String securityToken, Criteria criteria) {
- return findByCriteria(securityToken, null, criteria);
- }
-
/**
* Conveniant static method usefull in other WikittyService implementation
* where we don't wan't instanciate WikittyServiceEnhanced
@@ -100,8 +68,8 @@
*/
static public Wikitty restore(WikittyService ws, String securityToken, String id) {
Wikitty result = null;
- List<Wikitty> resultList = ws.restore(securityToken, null,
- Collections.singletonList(id));
+ List<Wikitty> resultList =
+ ws.restore(securityToken, Collections.singletonList(id));
if (resultList != null && resultList.size() > 0) {
result = resultList.get(0);
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -184,6 +184,12 @@
// }
@Override
public WikittyServiceEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent result = store(securityToken, null, wikitties, force);
+ return result;
+ }
+
+ protected WikittyServiceEvent store(String securityToken,
WikittyTransaction transaction,
Collection<Wikitty> wikitties, boolean force) {
if (!(wikitties instanceof Set)) {
@@ -272,7 +278,13 @@
}
@Override
- public WikittyServiceEvent storeExtension(String securityToken,
+ public WikittyServiceEvent storeExtension(
+ String securityToken, Collection<WikittyExtension> exts) {
+ WikittyServiceEvent result = storeExtension(securityToken, null, exts);
+ return result;
+ }
+
+ protected WikittyServiceEvent storeExtension(String securityToken,
WikittyTransaction transaction, Collection<WikittyExtension> exts) {
boolean txCreated = false;
try {
@@ -304,6 +316,12 @@
@Override
public WikittyExtension restoreExtension(
+ String securityToken, String extensionId) {
+ WikittyExtension result = restoreExtension(securityToken, null, extensionId);
+ return result;
+ }
+
+ protected WikittyExtension restoreExtension(
String securityToken, WikittyTransaction transaction, String extensionId) {
boolean txCreated = false;
try {
@@ -337,7 +355,13 @@
}
@Override
- public WikittyExtension restoreExtensionLastVersion(String securityToken,
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ WikittyExtension result = restoreExtensionLastVersion(securityToken, null, name);
+ return result;
+ }
+
+ protected WikittyExtension restoreExtensionLastVersion(String securityToken,
WikittyTransaction transaction, String name) {
String version = getExtensionStorage().getLastVersion(transaction, name);
if(version == null) {
@@ -393,7 +417,12 @@
}
@Override
- public List<Wikitty> restore(String securityToken,
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ List<Wikitty> result = restore(securityToken, null, ids);
+ return result;
+ }
+
+ protected List<Wikitty> restore(String securityToken,
WikittyTransaction transaction, List<String> ids) {
List<Wikitty> result = new ArrayList<Wikitty>();
@@ -446,6 +475,7 @@
// }
// }
+ // FIXME poussin 20101029 use WikittyServiceTransaction and remove other transaction
protected Wikitty upgradeData(String securityToken,
WikittyTransaction transaction, Wikitty wikitty) {
Wikitty result = wikitty;
@@ -493,7 +523,7 @@
// Test if extension is never use in this version
if(nextExtension != null) {
- result = migration.migrate(this, transaction, result,
+ result = migration.migrate(this, result,
currentExtension, nextExtension);
currentExtension = nextExtension;
}
@@ -630,7 +660,13 @@
* return new PagedResult with Wikitty instance
*/
@Override
- public PagedResult<String> findAllByCriteria(String securityToken,
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ PagedResult<String> result = findAllByCriteria(securityToken, null, criteria);
+ return result;
+ }
+
+ protected PagedResult<String> findAllByCriteria(String securityToken,
WikittyTransaction transaction, Criteria criteria) {
try {
boolean txCreated = false;
@@ -658,8 +694,14 @@
throw new WikittyException("Error during find", eee);
}
}
-
- public Wikitty findByCriteria(String securityToken,
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
+ Wikitty result = findByCriteria(securityToken, null, criteria);
+ return result;
+ }
+
+ protected Wikitty findByCriteria(String securityToken,
WikittyTransaction transaction, Criteria criteria) {
try {
boolean txCreated = false;
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -183,10 +183,9 @@
}
@Override
- public WikittyServiceEvent store(String securityToken, WikittyTransaction transaction,
+ public WikittyServiceEvent store(String securityToken,
Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent result = ws.store(securityToken, transaction,
- wikitties, force);
+ WikittyServiceEvent result = ws.store(securityToken, wikitties, force);
// notify listeners
fireEvent(result);
@@ -208,32 +207,29 @@
@Override
public WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts) {
- WikittyServiceEvent result = ws.storeExtension(
- securityToken, transaction, exts);
+ Collection<WikittyExtension> exts) {
+ WikittyServiceEvent result = ws.storeExtension(securityToken, exts);
fireEvent(result);
return result;
}
@Override
- public WikittyExtension restoreExtension(String securityToken,
- WikittyTransaction transaction, String id) {
+ public WikittyExtension restoreExtension(String securityToken, String id) {
// no notification
- return ws.restoreExtension(securityToken, transaction, id);
+ return ws.restoreExtension(securityToken, id);
}
@Override
public WikittyExtension restoreExtensionLastVersion(
- String securityToken, WikittyTransaction transaction, String name) {
+ String securityToken, String name) {
// no notification
- return ws.restoreExtensionLastVersion(securityToken, transaction, name);
+ return ws.restoreExtensionLastVersion(securityToken, name);
}
@Override
- public List<Wikitty> restore(String securityToken,
- WikittyTransaction transaction, List<String> ids) {
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
// no notification
- return ws.restore(securityToken, transaction, ids);
+ return ws.restore(securityToken, ids);
}
@Override
@@ -246,16 +242,15 @@
@Override
public PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
+ Criteria criteria) {
// no notification
- return ws.findAllByCriteria(securityToken, transaction, criteria);
+ return ws.findAllByCriteria(securityToken, criteria);
}
@Override
- public Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
// no notification
- return ws.findByCriteria(securityToken, transaction, criteria);
+ return ws.findByCriteria(securityToken, criteria);
}
@Override
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -80,7 +80,7 @@
@Override
public String login(String login, String password) {
- Wikitty user = ws.findByCriteria(null, null, Search.query().eq(
+ Wikitty user = ws.findByCriteria(null, Search.query().eq(
WikittyUser.FQ_FIELD_WIKITTYUSER_LOGIN, login).criteria());
if (user == null) {
throw new IllegalArgumentException(String.format("no such account '%s'", login));
@@ -92,7 +92,7 @@
// force add extension to wikitty
WikittyTokenHelper.addExtension(wikittyToken);
WikittyTokenHelper.setUser(wikittyToken, user.getId());
- ws.store(null, null, Arrays.asList(wikittyToken), false);
+ ws.store(null, Arrays.asList(wikittyToken), false);
log.debug(String.format("token '%s' is for login '%s'",
tokenId, login));
return tokenId;
@@ -180,9 +180,9 @@
@Override
public WikittyServiceEvent store(String securityToken,
- WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force) {
+ Collection<Wikitty> wikitties, boolean force) {
Collection<Wikitty> wikittiesToStore = checkStore(securityToken, wikitties);
- WikittyServiceEvent result = ws.store(securityToken, transaction, wikittiesToStore, force);
+ WikittyServiceEvent result = ws.store(securityToken, wikittiesToStore, force);
return result;
}
@@ -266,9 +266,9 @@
}
@Override
- public List<Wikitty> restore(String securityToken, WikittyTransaction transaction, List<String> ids) {
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
String userId = getUserId(securityToken);
- List<Wikitty> wikitties = ws.restore(securityToken, transaction, ids);
+ List<Wikitty> wikitties = ws.restore(securityToken, ids);
for (Wikitty wikitty : wikitties) {
if (wikitty != null) {
refuseUnauthorizedRead(securityToken, userId, wikitty);
@@ -380,7 +380,7 @@
public void checkDelete(String securityToken, Collection<String> ids) {
String userId = getUserId(securityToken);
List<String> idsAsList = new ArrayList<String>(ids);
- List<Wikitty> wikitties = ws.restore(securityToken, null, idsAsList);
+ List<Wikitty> wikitties = ws.restore(securityToken, idsAsList);
for (Wikitty wikitty : wikitties) {
for (String extensionName : wikitty.getExtensionNames()) {
if ( ! canWrite(securityToken, userId, extensionName, wikitty)) {
@@ -469,31 +469,29 @@
@Override
public WikittyServiceEvent storeExtension(String securityToken,
- WikittyTransaction transaction, Collection<WikittyExtension> exts) {
+ Collection<WikittyExtension> exts) {
checkStoreExtension(securityToken, exts);
- return ws.storeExtension(securityToken, transaction, exts);
+ return ws.storeExtension(securityToken, exts);
}
@Override
- public WikittyExtension restoreExtension(String securityToken,
- WikittyTransaction transaction, String id) {
+ public WikittyExtension restoreExtension(String securityToken, String id) {
// All people can read extension
- return ws.restoreExtension(securityToken, transaction, id);
+ return ws.restoreExtension(securityToken, id);
}
@Override
public WikittyExtension restoreExtensionLastVersion(
- String securityToken, WikittyTransaction transaction, String name) {
+ String securityToken, String name) {
// All people can read extension
- return ws.restoreExtensionLastVersion(securityToken, transaction, name);
+ return ws.restoreExtensionLastVersion(securityToken, name);
}
@Override
public PagedResult<String> findAllByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
+ Criteria criteria) {
// All people can read PagedResult that contains only id
- PagedResult<String> result = ws.findAllByCriteria(
- securityToken, transaction, criteria);
+ PagedResult<String> result = ws.findAllByCriteria(securityToken, criteria);
return result;
}
@@ -555,8 +553,8 @@
@Override
public Wikitty findByCriteria(String securityToken,
- WikittyTransaction transaction, Criteria criteria) {
- Wikitty wikitty = ws.findByCriteria(securityToken, transaction, criteria);
+ Criteria criteria) {
+ Wikitty wikitty = ws.findByCriteria(securityToken, criteria);
String userId = getUserId(securityToken);
refuseUnauthorizedRead(securityToken, userId, wikitty);
return wikitty;
@@ -737,7 +735,7 @@
Wikitty group;
if (appAdminGroupId == null) {
// 1er fois, on le recherche
- group = ws.findByCriteria(securityToken, null, Search.query().eq(
+ group = ws.findByCriteria(securityToken, Search.query().eq(
WikittyGroup.FQ_FIELD_WIKITTYGROUP_NAME,
WikittySecurityHelper.WIKITTY_APPADMIN_GROUP_NAME).criteria());
// group peut-etre null s'il n'existe pas
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -35,6 +35,10 @@
protected List<WikittyServiceEvent> events;
+ /** if autoCommit > 0 all time events numbers element equals to this
+ * autoCommit commit is call */
+ protected int autoCommit = -1;
+
public WikittyServiceTransaction(ApplicationConfig config, WikittyService ws) {
this.ws = ws;
// create new WikittyServiceInMemory not configured with default config
@@ -43,6 +47,21 @@
events = new LinkedList<WikittyServiceEvent>();
}
+ public void setAutoCommit(int autoCommit) {
+ this.autoCommit = autoCommit;
+ }
+
+ public int getAutoCommit() {
+ return autoCommit;
+ }
+
+ protected void addEvent(String securityToken, WikittyServiceEvent e) {
+ events.add(e);
+ if (autoCommit > 0 && events.size() >= autoCommit) {
+ commit(securityToken);
+ }
+ }
+
public void commit(String securityToken) {
ws.replay(securityToken, events);
this.tx.clear(null);
@@ -88,7 +107,7 @@
@Override
public WikittyServiceEvent clear(String securityToken) {
WikittyServiceEvent e = tx.clear(securityToken);
- events.add(e);
+ addEvent(securityToken, e);
return e;
}
@@ -122,9 +141,10 @@
}
@Override
- public WikittyServiceEvent store(String securityToken, WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force) {
- WikittyServiceEvent e = tx.store(securityToken, transaction, wikitties, force);
- events.add(e);
+ public WikittyServiceEvent store(
+ String securityToken, Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent e = tx.store(securityToken, wikitties, force);
+ addEvent(securityToken, e);
return e;
}
@@ -151,34 +171,38 @@
}
@Override
- public WikittyServiceEvent storeExtension(String securityToken, WikittyTransaction transaction, Collection<WikittyExtension> exts) {
- WikittyServiceEvent e = tx.storeExtension(securityToken, transaction, exts);
- events.add(e);
+ public WikittyServiceEvent storeExtension(
+ String securityToken, Collection<WikittyExtension> exts) {
+ WikittyServiceEvent e = tx.storeExtension(securityToken, exts);
+ addEvent(securityToken, e);
return e;
}
@Override
- public WikittyExtension restoreExtension(String securityToken, WikittyTransaction transaction, String extensionId) {
- WikittyExtension result = tx.restoreExtension(securityToken, transaction, extensionId);
+ public WikittyExtension restoreExtension(
+ String securityToken, String extensionId) {
+ WikittyExtension result = tx.restoreExtension(securityToken, extensionId);
if (result == null) {
- result = ws.restoreExtension(securityToken, transaction, extensionId);
+ result = ws.restoreExtension(securityToken, extensionId);
}
return result;
}
@Override
- public WikittyExtension restoreExtensionLastVersion(String securityToken, WikittyTransaction transaction, String name) {
- WikittyExtension result = tx.restoreExtensionLastVersion(securityToken, transaction, name);
+ public WikittyExtension restoreExtensionLastVersion(
+ String securityToken, String name) {
+ WikittyExtension result =
+ tx.restoreExtensionLastVersion(securityToken, name);
if (result == null) {
- result = ws.restoreExtension(securityToken, transaction, name);
+ result = ws.restoreExtensionLastVersion(securityToken, name);
}
return result;
}
@Override
- public List<Wikitty> restore(String securityToken, WikittyTransaction transaction, List<String> ids) {
- List<Wikitty> resultWS = ws.restore(securityToken, transaction, ids);
- List<Wikitty> resultTx = tx.restore(securityToken, transaction, ids);
+ public List<Wikitty> restore(String securityToken, List<String> ids) {
+ List<Wikitty> resultWS = ws.restore(securityToken, ids);
+ List<Wikitty> resultTx = tx.restore(securityToken, ids);
Wikitty[] result = resultWS.toArray(new Wikitty[resultWS.size()]);
int i = 0;
for (Wikitty w : resultTx) {
@@ -201,18 +225,19 @@
public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
// pour que tout fonctionne bien, il faut que les objets supprimer soit
// dans la tx, car il faut avoir une vrai trace de cette suppression dans la tx
- List<Wikitty> wikitties = ws.restore(securityToken, null, new ArrayList<String>(ids));
- tx.store(securityToken, null, wikitties, true);
+ List<Wikitty> wikitties = ws.restore(securityToken, new ArrayList<String>(ids));
+ tx.store(securityToken, wikitties, true);
WikittyServiceEvent e = tx.delete(securityToken, ids);
- events.add(e);
+ addEvent(securityToken, e);
return e;
}
@Override
- public PagedResult<String> findAllByCriteria(String securityToken, WikittyTransaction transaction, Criteria criteria) {
- PagedResult<String> resultTx = tx.findAllByCriteria(securityToken, transaction, criteria);
- PagedResult<String> resultWs = ws.findAllByCriteria(securityToken, transaction, criteria);
+ public PagedResult<String> findAllByCriteria(
+ String securityToken, Criteria criteria) {
+ PagedResult<String> resultTx = tx.findAllByCriteria(securityToken, criteria);
+ PagedResult<String> resultWs = ws.findAllByCriteria(securityToken, criteria);
// Il faut fusionner les deux resultats
// - ne pas avoir de doublon
@@ -237,14 +262,14 @@
}
@Override
- public Wikitty findByCriteria(String securityToken, WikittyTransaction transaction, Criteria criteria) {
+ public Wikitty findByCriteria(String securityToken, Criteria criteria) {
Wikitty result = null;
- PagedResult<String> ids = findAllByCriteria(securityToken, transaction, criteria);
+ PagedResult<String> ids = findAllByCriteria(securityToken, criteria);
List<String> results = ids.getAll();
if (results.size() > 0) {
String id = results.get(0);
List<Wikitty> wikitties = restore(
- securityToken, transaction, Collections.singletonList(id));
+ securityToken, Collections.singletonList(id));
result = wikitties.get(0);
}
return result;
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -744,7 +744,7 @@
if (WikittyUtil.versionGreaterThan(newVersion, oldVersion)) {
wikittyService.storeExtension(
- securityToken, null, Arrays.asList(ext));
+ securityToken, Arrays.asList(ext));
upgradeData = true;
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ExportTask.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ExportTask.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ExportTask.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -32,7 +32,6 @@
import org.nuiton.wikitty.Wikitty;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyTransaction;
import org.nuiton.wikitty.WikittyImportExportService.FORMAT;
import org.nuiton.wikitty.search.Element;
@@ -42,7 +41,6 @@
static private Log log = LogFactory.getLog(ImportTask.class);
protected WikittyService ws;
- protected WikittyTransaction transaction;
protected FORMAT format;
protected Criteria criteria;
protected Writer writer;
@@ -53,7 +51,6 @@
super();
this.securityToken = securityToken;
this.ws = ws;
- this.transaction = new WikittyTransaction();
this.format = format;
this.criteria = criteria;
this.writer = writer;
@@ -62,31 +59,28 @@
@Override
public void run() {
try {
- transaction.begin();
// use a facet to get only extension used in export
// used for CSV export
criteria.addFacetField(Element.ELT_EXTENSION);
PagedResult<String> pageResultId = ws.findAllByCriteria(
- securityToken, transaction, criteria);
+ securityToken, criteria);
long time = 0;
if (log.isInfoEnabled()) {
time = System.currentTimeMillis();
log.info("Export started");
}
// get Wikitty from Id
- PagedResult<Wikitty> pageResult = pageResultId.cast(securityToken, ws, transaction);
+ PagedResult<Wikitty> pageResult = pageResultId.cast(securityToken, ws);
ImportExportMethod exporter = format.ieporter();
- exporter.exportWriter(securityToken, writer, ws, transaction, pageResult);
+ exporter.exportWriter(securityToken, writer, ws, pageResult);
if (log.isInfoEnabled()) {
time = System.currentTimeMillis() - time;
log.info("Export in (ms)" + time);
}
- transaction.commit();
} catch (Exception eee) {
- transaction.rollback();
throw new WikittyException("Error during export task", eee);
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportCSV.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportCSV.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportCSV.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -79,8 +79,7 @@
@Override
public void importReader(String securityToken, Reader reader,
- WikittyService ws, WikittyTransaction transaction,
- WikittyBatchUpdate batchUpdate) throws Exception {
+ WikittyService ws) throws Exception {
// get index of wikitty.id field
int wikittyIdIndex = -1;
@@ -135,7 +134,8 @@
String[] extensions = extensionList.split(",");
for (String extension : extensions) {
String extName = extension.trim();
- addMissingExtension(securityToken, ws, transaction, currentWikitty, extName);
+ addMissingExtension(
+ securityToken, ws, currentWikitty, extName);
}
}
}
@@ -156,10 +156,10 @@
if (StringUtils.isNotEmpty(value)) {
// extension must exists on wikitty to set a field value
- addMissingExtension(securityToken, ws, transaction, currentWikitty, extName);
+ addMissingExtension(securityToken, ws, currentWikitty, extName);
// convert link values (if necessary)
- value = convertLinkValues(securityToken, transaction, ws, value);
+ value = convertLinkValues(securityToken, ws, value);
// add value to correct field
FieldType fieldType = currentWikitty.getFieldType(extName + "." + fieldName);
@@ -176,7 +176,8 @@
if (fieldType.getType().equals(TYPE.WIKITTY)) {
// restore works (database) but solr criteria won't
- List<Wikitty> wikitties = ws.restore(securityToken, transaction, Collections.singletonList(multiplesValue));
+ List<Wikitty> wikitties = ws.restore(securityToken,
+ Collections.singletonList(multiplesValue));
if ( wikitties != null && wikitties.size() == 1 && wikitties.get(0) != null) {
currentWikitty.addToField(extName, fieldName, multiplesValue);
}
@@ -190,7 +191,8 @@
if (fieldType.getType().equals(TYPE.WIKITTY)) {
// restore works (database) but solr criteria won't
- List<Wikitty> wikitties = ws.restore(securityToken, transaction, Collections.singletonList(value));
+ List<Wikitty> wikitties = ws.restore(securityToken,
+ Collections.singletonList(value));
if ( wikitties != null && wikitties.size() == 1 && wikitties.get(0) != null) {
currentWikitty.setField(extName, fieldName, value);
}
@@ -203,7 +205,7 @@
}
// add it into datas
- batchUpdate.addWikitty(currentWikitty);
+ ws.store(securityToken, Collections.singleton(currentWikitty), true);
}
}
@@ -213,11 +215,11 @@
* @throws WikittyException if the extension does not exist in base
*/
protected void addMissingExtension(String securityToken, WikittyService ws,
- WikittyTransaction transaction, Wikitty currentWikitty, String extName) {
+ Wikitty currentWikitty, String extName) {
// extension must exists on wikitty to set a field value
if (!currentWikitty.hasExtension(extName)) {
WikittyExtension extension = ws.restoreExtensionLastVersion(
- securityToken, transaction, extName);
+ securityToken, extName);
if (extension != null) {
String requires = extension.getRequires();
@@ -225,7 +227,7 @@
// add required extensions BEFORE current
for (String require : requires.split(",")) {
String localRequire = require.trim();
- addMissingExtension(securityToken, ws, transaction, currentWikitty, localRequire);
+ addMissingExtension(securityToken, ws, currentWikitty, localRequire);
}
}
@@ -243,7 +245,7 @@
* @return
*/
protected String convertLinkValues(
- String securityToken, WikittyTransaction transaction, WikittyService ws, String value) {
+ String securityToken, WikittyService ws, String value) {
String originalValue = value;
String resultValue = "";
@@ -264,7 +266,7 @@
fValue = m.group(6);
}
Criteria criteria = Search.query().eq(fqField, fValue).criteria();
- Wikitty wikitty = ws.findByCriteria(securityToken, transaction, criteria);
+ Wikitty wikitty = ws.findByCriteria(securityToken, criteria);
if (wikitty == null) {
correctQueries = false;
}
@@ -295,8 +297,7 @@
@Override
public void exportWriter(String securityToken, Writer writer,
- WikittyService ws, WikittyTransaction transaction,
- PagedResult<Wikitty> pagedResult) throws Exception {
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception {
CSVWriter csvWriter = new CSVWriter(writer);
@@ -308,7 +309,7 @@
String extName = topic.getTopicName();
WikittyExtension extension = ws.restoreExtensionLastVersion(
- securityToken, transaction, extName);
+ securityToken, extName);
String ext = WikittyExtension.computeName(extName);
for (String fieldName : extension.getFieldNames()) {
extensionHeader.add(ext + "." + fieldName);
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportMethod.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportMethod.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportMethod.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -55,9 +55,8 @@
*
* @throws Exception
*/
- public void importReader(String securityToken, Reader reader,
- WikittyService ws, WikittyTransaction transaction,
- WikittyBatchUpdate batchUpdate) throws Exception;
+ public void importReader(
+ String securityToken, Reader reader, WikittyService ws) throws Exception;
/**
* Export data to writer.
@@ -71,6 +70,5 @@
* @throws Exception
*/
public void exportWriter(String securityToken, Writer writer,
- WikittyService ws, WikittyTransaction transaction,
- PagedResult<Wikitty> pagedResult) throws Exception;
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception;
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportXML.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportXML.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportExportXML.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -28,6 +28,7 @@
import java.io.Reader;
import java.io.Writer;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -65,8 +66,7 @@
@Override
public void importReader(String securityToken, Reader reader,
- WikittyService ws, WikittyTransaction transaction,
- WikittyBatchUpdate batchUpdate) throws Exception {
+ WikittyService ws) throws Exception {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
factory.setNamespaceAware(true);
@@ -101,7 +101,7 @@
String extName = WikittyExtension.computeName(extId);
String extVersion = WikittyExtension.computeVersion(extId);
extId = WikittyExtension.computeId(extName, extVersion);
- WikittyExtension e = batchUpdate.getExtension(extId);
+ WikittyExtension e = ws.restoreExtension(securityToken, extId);
if (e == null) {
throw new WikittyException("Extension not found : " + extId);
}
@@ -111,11 +111,11 @@
} else if (eventType == XmlPullParser.END_TAG) {
String name = xpp.getName();
if ("extension".equals(name)) {
- batchUpdate.addExtension(ext);
+ ws.storeExtension(securityToken, Collections.singleton(ext));
ext = null;
} else if ("object".equals(name)) {
w.setVersion(objectVersion);
- batchUpdate.addWikitty(w);
+ ws.store(securityToken, Collections.singleton(w), true);
w = null;
} else if (ext != null && "field".equals(name)) {
FieldType type = new FieldType();
@@ -143,8 +143,7 @@
@Override
public void exportWriter(String securityToken, Writer result,
- WikittyService ws, WikittyTransaction transaction,
- PagedResult<Wikitty> pagedResult) throws Exception {
+ WikittyService ws, PagedResult<Wikitty> pagedResult) throws Exception {
// keep extension already done
Set<String> extDone = new HashSet<String>();
result.write("<wikengo>\n");
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportTask.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportTask.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/ImportTask.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -29,8 +29,8 @@
import org.apache.commons.logging.LogFactory;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyTransaction;
import org.nuiton.wikitty.WikittyImportExportService.FORMAT;
+import org.nuiton.wikitty.WikittyServiceTransaction;
public class ImportTask implements Runnable {
@@ -38,7 +38,6 @@
static private Log log = LogFactory.getLog(ImportTask.class);
protected WikittyService ws;
- protected WikittyTransaction transaction;
protected FORMAT format;
protected Reader reader;
protected ImportExportMethod importerExporter;
@@ -51,33 +50,30 @@
this.ws = ws;
this.format = format;
this.reader = reader;
- this.transaction = new WikittyTransaction();
}
@Override
public void run() {
+ WikittyServiceTransaction tx = new WikittyServiceTransaction(null, ws);
+ // TODO poussin 20101029 rendre configurable le l'auto commit '1000' pour l'import
+ tx.setAutoCommit(1000);
try {
- transaction.begin();
- WikittyBatchUpdate batchUpdate = new WikittyBatchUpdate(
- securityToken, ws, transaction);
-
long time = 0;
if (log.isInfoEnabled()) {
time = System.currentTimeMillis();
log.info("Import in (ms)" + time);
}
ImportExportMethod importer = format.ieporter();
- importer.importReader(securityToken, reader, ws, transaction, batchUpdate);
+ importer.importReader(securityToken, reader, tx);
if (log.isInfoEnabled()) {
time = System.currentTimeMillis() - time;
log.info("Import in (ms)" + time);
}
- // don't forget to flush batchUpdate :)
- batchUpdate.flush();
- transaction.commit();
+ // don't forget to commit :)
+ tx.commit(securityToken);
} catch (Exception eee) {
- transaction.rollback();
+ tx.rollback(securityToken);
throw new WikittyException("Error during import task", eee);
}
}
Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/WikittyBatchUpdate.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/WikittyBatchUpdate.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/importexport/WikittyBatchUpdate.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -1,97 +0,0 @@
-/*
- * #%L
- * Wikitty :: api
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 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.importexport;
-
-import org.nuiton.wikitty.Wikitty;
-import org.nuiton.wikitty.WikittyExtension;
-import org.nuiton.wikitty.WikittyService;
-import org.nuiton.wikitty.WikittyTransaction;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Class used for import process, this class retain numberForCommit object
- * before to send it to storage.
- */
-public class WikittyBatchUpdate {
-
- // TODO poussin 20090902 do configurable numberForCommit
- protected int numberForCommit = 1000;
- protected int currentAdded = 0;
- protected Map<String, WikittyExtension> exts = new HashMap<String, WikittyExtension>();
- protected List<Wikitty> wikitties = new LinkedList<Wikitty>();
- protected WikittyService ws;
- protected WikittyTransaction transaction;
- protected String securityToken;
-
- public WikittyBatchUpdate(String securityToken,
- WikittyService ws, WikittyTransaction transaction) {
- super();
- this.securityToken = securityToken;
- this.ws = ws;
- this.transaction = transaction;
- }
-
- public void addExtension(WikittyExtension ext) {
- exts.put(ext.getId(), ext);
- inc();
- }
-
- public void addWikitty(Wikitty w) {
- wikitties.add(w);
- inc();
- }
-
- /**
- * search extension in local extension list and if missed restore
- * extension from internal WikittyService
- * @param id
- * @return extension
- */
- public WikittyExtension getExtension(String id) {
- WikittyExtension result = exts.get(id);
- if (result == null) {
- result = ws.restoreExtension(securityToken, transaction, id);
- }
- return result;
- }
-
- public void flush() {
- ws.storeExtension(securityToken, transaction, exts.values());
- ws.store(securityToken, transaction, wikitties, true);
- exts.clear();
- wikitties.clear();
- currentAdded = 0;
- }
-
- protected void inc() {
- currentAdded++;
- if (currentAdded >= numberForCommit) {
- flush();
- }
- }
-}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -40,7 +40,7 @@
// on creer un objet dans la transaction
WikittyLabel labelTx = new WikittyLabelImpl();
labelTx.addLabels("coucouTx");
- tx.store(null, null, Collections.singleton(labelTx.getWikitty()), false);
+ tx.store(null, Collections.singleton(labelTx.getWikitty()), false);
// on ne doit pas le retrouver hors de la transation
Wikitty w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/AbstractTestConformance.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -154,7 +154,7 @@
Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
result.add( w );
}
- ws.store(null, null, result, false);
+ ws.store(null, result, false);
return result;
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -165,7 +165,7 @@
"7ca86742-5957-4659-b12f-4915cbef9193",
"77d7640c-573d-421c-a7e9-9b70bd025983"
};
- List<Wikitty> wikitties = ws.restore(null, null, Arrays.asList(ids));
+ List<Wikitty> wikitties = ws.restore(null, Arrays.asList(ids));
assertEquals(3, wikitties.size());
}
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/PerformanceBenchMark.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -78,7 +78,7 @@
FieldType fieldType = new FieldType(FieldType.TYPE.STRING, 1, 1);
extension.addField("field" + i, fieldType);
}
- wikittyService.storeExtension(null, null, Arrays.asList(extension));
+ wikittyService.storeExtension(null, Arrays.asList(extension));
Collection<Wikitty> wikitties = new ArrayList<Wikitty>(WIKITTY_SIZE);
for (int i = 0; i < WIKITTY_SIZE; i++) {
@@ -90,7 +90,7 @@
wikitties.add(wikitty);
}
long start = System.currentTimeMillis();
- wikittyService.store(null, null, wikitties, false);
+ wikittyService.store(null, wikitties, false);
long end = System.currentTimeMillis();
log.info("[Performance" + fieldSize + "] Write times : " + ((end - start) / 1000) + "s");
@@ -98,7 +98,7 @@
start = System.currentTimeMillis();
for (int i = 0; i < WIKITTY_SIZE; i++) {
int nextInt = random.nextInt(WIKITTY_SIZE);
- wikittyService.restore(null, null, Arrays.asList("Performance" + fieldSize + "id" + nextInt));
+ wikittyService.restore(null, Arrays.asList("Performance" + fieldSize + "id" + nextInt));
}
end = System.currentTimeMillis();
log.info("[Performance" + fieldSize + "] Read times : " + ((end - start) / 1000) + "s");
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/SearchTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -84,13 +84,13 @@
w.setField(ext.getName(), "birth", "19/04/1968 15:12");
wikitties.add( w );
- ws.store(null, null, wikitties, false);
+ ws.store(null, wikitties, false);
// Testing search on a date criteria
Criteria criteria = Search.query()
.gt("testExt.birth", "19/04/1968 15:00")
.criteria();
- PagedResult<String> result = ws.findAllByCriteria(null, null, criteria);
+ PagedResult<String> result = ws.findAllByCriteria(null, criteria);
List<String> found = result.getAll();
assertEquals(1, found.size());
Wikitty wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -100,7 +100,7 @@
criteria = Search.query()
.ge("testExt.birth", "19/04/1968")
.criteria();
- result = ws.findAllByCriteria(null, null, criteria);
+ result = ws.findAllByCriteria(null, criteria);
found = result.getAll();
assertEquals(2, found.size());
wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -109,7 +109,7 @@
criteria = Search.query()
.eq("testExt.name", "Guillaume")
.criteria();
- result = ws.findAllByCriteria(null, null, criteria);
+ result = ws.findAllByCriteria(null, criteria);
found = result.getAll();
assertEquals(1, found.size());
wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -118,7 +118,7 @@
criteria = Search.query()
.eq("testExt.age", "125")
.criteria();
- result = ws.findAllByCriteria(null, null, criteria);
+ result = ws.findAllByCriteria(null, criteria);
found = result.getAll();
assertEquals(1, found.size());
wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -127,7 +127,7 @@
criteria = Search.query()
.gt("testExt.age", "10")
.criteria();
- result = ws.findAllByCriteria(null, null, criteria);
+ result = ws.findAllByCriteria(null, criteria);
found = result.getAll();
assertEquals(2, found.size());
wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -139,7 +139,7 @@
exemple.addExtension(ext);
exemple.setField(ext.getName(), "name", "Guillaume");
exemple.setField(ext.getName(), "age", "27");
- result = ws.findAllByCriteria(null, null, Search.query(exemple).criteria() );
+ result = ws.findAllByCriteria(null, Search.query(exemple).criteria() );
found = result.getAll();
assertEquals(1, found.size());
wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(0));
@@ -149,7 +149,7 @@
exemple.addExtension(ext);
exemple.setField(ext.getName(), "name", "Guillaume");
exemple.setField(ext.getName(), "age", "125");
- result = ws.findAllByCriteria(null, null, Search.query(exemple).criteria() );
+ result = ws.findAllByCriteria(null, Search.query(exemple).criteria() );
found = result.getAll();
assertEquals(0, found.size());
// log.info( found.get(0).getFieldAsString(ext.getName(), "name") );
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -72,7 +72,7 @@
public void testStoreRestoreBasics() throws Exception {
Wikitty w = createBasicWikitty();
String id = w.getId();
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
w = WikittyServiceEnhanced.restore(ws, null, id);
assertTrue(w.hasExtension(EXTNAME));
for ( int i = 0; i < 3; i++ ) {
@@ -82,11 +82,11 @@
@Test
public void testExtensionMethod() throws Exception {
- ws.storeExtension(null, null, Collections.singletonList(EXT_TEST));
+ ws.storeExtension(null, Collections.singletonList(EXT_TEST));
List<String> extIds = ws.getAllExtensionIds(null);
log.debug("extIds: " + extIds);
assertEquals(1, extIds.size());
- WikittyExtension ext = ws.restoreExtension(null, null, extIds.get(0));
+ WikittyExtension ext = ws.restoreExtension(null, extIds.get(0));
assertEquals(EXT_TEST.getName(), ext.getName());
assertEquals(EXT_TEST.getVersion(), ext.getVersion());
assertEquals(EXT_TEST, ext);
@@ -94,12 +94,12 @@
@Test
public void testExtensionRequires() throws Exception {
- ws.storeExtension(null, null, Arrays.asList(EXT_REQUIRED, EXT_REQUIRES));
+ ws.storeExtension(null, Arrays.asList(EXT_REQUIRED, EXT_REQUIRES));
List<String> extIds = ws.getAllExtensionsRequires(null, EXTREQUIRED);
log.debug("extIds: " + extIds);
assertEquals(1, extIds.size());
- WikittyExtension ext = ws.restoreExtension(null, null, extIds.get(0));
+ WikittyExtension ext = ws.restoreExtension(null, extIds.get(0));
assertEquals(EXT_REQUIRES.getName(), ext.getName());
assertEquals(EXT_REQUIRES.getVersion(), ext.getVersion());
assertEquals(EXT_REQUIRES, ext);
@@ -130,9 +130,9 @@
wikitties.add( w );
ids.add( w.getId() );
}
- ws.store(null, null, wikitties, false);
+ ws.store(null, wikitties, false);
- wikitties = ws.restore(null, null, ids);
+ wikitties = ws.restore(null, ids);
int wIndex = 0;
for ( String wValue : wValues ) {
Wikitty w = wikitties.get(wIndex);
@@ -170,7 +170,7 @@
Wikitty w = null;
// should be ignored (?)
try {
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
fail("store(null) Must throw an exception !");
} catch (Exception e) {
// OK !
@@ -178,7 +178,7 @@
w = new WikittyImpl();
String id = w.getId();
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
w = WikittyServiceEnhanced.restore(ws, null, id);
assertEquals( id, w.getId() );
}
@@ -192,12 +192,12 @@
"String other[0-n] unique=true notNull=true"
));
- ws.storeExtension(null, null, Collections.singletonList(ext));
+ ws.storeExtension(null, Collections.singletonList(ext));
Wikitty w = new WikittyImpl();
w.addExtension(ext);
try {
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
Assert.fail("not null contraint don't work on String");
} catch (WikittyException eee) {
eee.printStackTrace();
@@ -206,7 +206,7 @@
w.setField("TestConstraint", "id", "toto");
try {
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
Assert.fail("not null contraint don't work in Collection");
} catch (WikittyException eee) {
eee.printStackTrace();
@@ -214,17 +214,17 @@
}
w.addToField("TestConstraint", "other", "titi");
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
w.addToField("TestConstraint", "ext", "tata");
w.addToField("TestConstraint", "ext", "titi");
- ws.store(null, null, Collections.singletonList(w), false);
+ ws.store(null, Collections.singletonList(w), false);
Wikitty w2 = WikittyServiceEnhanced.restore(ws, null, w.getId());
w2.addToField("TestConstraint", "ext", "tata"); // tata ne doit pas s'ajouter
w2.addToField("TestConstraint", "ext", "toto");
- ws.store(null, null, Collections.singletonList(w2), false);
+ ws.store(null, Collections.singletonList(w2), false);
Wikitty w3 = WikittyServiceEnhanced.restore(ws, null, w.getId());
HashSet set = new HashSet(Arrays.asList("tata", "titi", "toto"));
@@ -256,7 +256,7 @@
Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
wikitties.add( w );
}
- ws.store(null, null, wikitties, false);
+ ws.store(null, wikitties, false);
// search test
Wikitty w = new WikittyImpl();
@@ -264,10 +264,10 @@
w.setField(EXT_TEST.getName(), "fieldName1", "003309");
Criteria criteria = Search.query(w).criteria()
.addSortDescending(EXT_TEST.getName() + ".fieldName0");
- PagedResult<String> resultFind = ws.findAllByCriteria(null, null, criteria);
+ PagedResult<String> resultFind = ws.findAllByCriteria(null, criteria);
assertEquals(2, resultFind.size());
- List<Wikitty> wikittyFind = ws.restore(null, null, resultFind.getAll());
+ List<Wikitty> wikittyFind = ws.restore(null, resultFind.getAll());
assertEquals(wikitties.subList(0, 2), wikittyFind);
}
@@ -301,7 +301,7 @@
Wikitty w = createWikitty( wValue, EXTNAME, EXT_TEST );
wikitties.add( w );
}
- ws.store(null, null, wikitties, false);
+ ws.store(null, wikitties, false);
// search test
Wikitty w = new WikittyImpl();
@@ -311,7 +311,7 @@
.setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS)
.addFacetField(EXT_TEST.getName()+".fieldName0")
.addFacetField(EXT_TEST.getName()+".fieldName1");
- PagedResult<String> resultFind = ws.findAllByCriteria(null, null, criteria);
+ PagedResult<String> resultFind = ws.findAllByCriteria(null, criteria);
List<String> facetNames = new ArrayList<String>(resultFind.getFacetNames());
Collections.sort(facetNames);
@@ -353,7 +353,7 @@
for( Wikitty w : wikitties ) {
oldIdVersion.put(w.getId(), w.getVersion());
}
- WikittyServiceEvent response = ws.store(null, null, wikitties, false);
+ WikittyServiceEvent response = ws.store(null, wikitties, false);
for (Wikitty w : wikitties) {
response.update(w);
String v1 = w.getVersion();
@@ -368,7 +368,7 @@
w.addExtension(EXT_TEST);
w.setField(EXT_TEST.getName(), "fieldName0", "chaiseICI");
Criteria criteria = Search.query(w).criteria();
- Wikitty resultFind = ws.findByCriteria(null, null, criteria);
+ Wikitty resultFind = ws.findByCriteria(null, criteria);
Wikitty wikittySource = wikitties.get(1);
assertEquals(w.getFieldAsString(EXT_TEST.getName(), "fieldName0"),
@@ -389,7 +389,7 @@
// test to find deleted wikitty
// test if solr index is coherent with database
Criteria criteria1 = Search.query().eq(Element.ELT_ID, wikittySource.getId()).criteria();
- Wikitty searchedWikitty1 = ws.findByCriteria(null, null, criteria1);
+ Wikitty searchedWikitty1 = ws.findByCriteria(null, criteria1);
Assert.assertNotNull(searchedWikitty1);
ws.delete(null, Collections.singletonList(wikittySource.getId()));
@@ -400,7 +400,7 @@
// test to find deleted wikitty
// test if solr index is coherent with database
Criteria criteria2 = Search.query().eq(Element.ELT_ID, wikittySource.getId()).criteria();
- Wikitty searchedWikitty2 = ws.findByCriteria(null, null, criteria2);
+ Wikitty searchedWikitty2 = ws.findByCriteria(null, criteria2);
Assert.assertNull(searchedWikitty2);
}
@@ -464,7 +464,7 @@
// leaf.addChild( subLeaf.getWikittyId() );
}
}
- ws.store(null, null, wikittyNodes, false); // store treeNodes.
+ ws.store(null, wikittyNodes, false); // store treeNodes.
Wikitty table = wikitties.get(0);
Wikitty chaise = wikitties.get(1);
@@ -489,8 +489,8 @@
Criteria criteria = Search.query(node.getWikitty()).criteria()
.setFirstIndex(0).setEndIndex(Criteria.ALL_ELEMENTS);
- List<String> wikittiesId = ws.findAllByCriteria(null, null, criteria).getAll();
- List<Wikitty> wikitties = ws.restore(null, null, wikittiesId);
+ List<String> wikittiesId = ws.findAllByCriteria(null, criteria).getAll();
+ List<Wikitty> wikitties = ws.restore(null, wikittiesId);
for ( Wikitty child : wikitties ) {
if (!child.hasExtension(WikittyTreeNode.EXT_WIKITTYTREENODE)) {
continue;
@@ -504,7 +504,7 @@
fail( "Unable to find node " + nodeName + " inside " + currentNode.getName() );
}
currentNode.addAttachment(wikitty.getId());
- ws.store(null, null, Collections.singletonList(currentNode.getWikitty()), false);
+ ws.store(null, Collections.singletonList(currentNode.getWikitty()), false);
}
/**
@@ -557,23 +557,23 @@
Wikitty myWikitty = new WikittyImpl();
myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
myWikitty.setField(WikittyTreeNode.EXT_WIKITTYTREENODE, WikittyTreeNode.FIELD_WIKITTYTREENODE_NAME, "name");
- ws.store(null, null, Collections.singletonList(myWikitty), false);
+ ws.store(null, Collections.singletonList(myWikitty), false);
Assert.assertEquals("1.0", myWikitty.getVersion());
// store 2 : no modification
- ws.store(null, null, Collections.singletonList(myWikitty), false);
+ ws.store(null, Collections.singletonList(myWikitty), false);
Assert.assertEquals("1.0", myWikitty.getVersion());
// store 3 : modification
myWikitty.setField(WikittyTreeNode.EXT_WIKITTYTREENODE, WikittyTreeNode.FIELD_WIKITTYTREENODE_NAME, "new name");
- ws.store(null, null, Collections.singletonList(myWikitty), false);
+ ws.store(null, Collections.singletonList(myWikitty), false);
Assert.assertEquals("2.0", myWikitty.getVersion());
// store 4 : new wikitty with same wikitty id (obsolete)
Wikitty myNewWikitty = new WikittyImpl(myWikitty.getId());
myWikitty.setField(WikittyTreeNode.EXT_WIKITTYTREENODE, WikittyTreeNode.FIELD_WIKITTYTREENODE_NAME, "new wikitty");
try {
- ws.store(null, null, Collections.singletonList(myNewWikitty), false);
+ ws.store(null, Collections.singletonList(myNewWikitty), false);
Assert.fail("Test must throw WikittyObsoleteException");
}
catch (WikittyObsoleteException ex) {
@@ -583,12 +583,12 @@
}
// store 4 : same but with force (increased by force)
- ws.store(null, null, Collections.singletonList(myNewWikitty), true);
+ ws.store(null, Collections.singletonList(myNewWikitty), true);
Assert.assertEquals("3.0", myNewWikitty.getVersion());
// store 5 : fix version (not increased by force)
myNewWikitty.setVersion("11.0");
- ws.store(null, null, Collections.singletonList(myNewWikitty), true);
+ ws.store(null, Collections.singletonList(myNewWikitty), true);
Assert.assertEquals("11.0", myNewWikitty.getVersion());
}
@@ -602,7 +602,7 @@
Wikitty myWikitty = new WikittyImpl();
myWikitty.addExtension(WikittyTreeNodeImpl.extensions);
myWikitty.setField(WikittyTreeNode.EXT_WIKITTYTREENODE, WikittyTreeNode.FIELD_WIKITTYTREENODE_NAME, "name");
- ws.store(null, null, Collections.singletonList(myWikitty), false);
+ ws.store(null, Collections.singletonList(myWikitty), false);
// delete
ws.delete(null, Collections.singletonList(myWikitty.getId()));
@@ -611,7 +611,7 @@
Assert.assertNull(restoredWikitty);
// store again
- ws.store(null, null, Collections.singletonList(myWikitty), false);
+ ws.store(null, Collections.singletonList(myWikitty), false);
restoredWikitty =
WikittyServiceEnhanced.restore(ws, null, myWikitty.getId());
Assert.assertNotNull(restoredWikitty);
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -183,12 +183,12 @@
// test extension support
Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, extensionTag.getName()).criteria();
- PagedResult<String> pagedResult = ws.findAllByCriteria(null, null, criteria);
+ PagedResult<String> pagedResult = ws.findAllByCriteria(null, criteria);
Assert.assertEquals(1, pagedResult.getNumFound());
// test normal import
Criteria criteria2 = Search.query().eq(extensionClient.getName() + ".name", "Toto").criteria();
- PagedResult<String> pagedResult2 = ws.findAllByCriteria(null, null, criteria2);
+ PagedResult<String> pagedResult2 = ws.findAllByCriteria(null, criteria2);
Assert.assertEquals(1, pagedResult2.getNumFound());
// import attachment id that not exist, must be not imported
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -47,7 +47,7 @@
WikittyConfig config = new WikittyConfig();
setService(new WikittyServiceCached(config, new WikittyServiceInMemory(config)));
token = service.login(null, null);
- service.store(token, null, Collections.singletonList(getaWikitty()), false);
+ service.store(token, Collections.singletonList(getaWikitty()), false);
}
/** setting a field value doesn't corrupt cache */
@@ -73,7 +73,7 @@
List<String> idsToRestore = new ArrayList<String>();
idsToRestore.add(getaWikitty().getId());
- List<Wikitty> otherWikitties = service.restore(token, null, idsToRestore);
+ List<Wikitty> otherWikitties = service.restore(token, idsToRestore);
Wikitty anotherWikitty = otherWikitties.get(0);
// we set the value of a field
@@ -81,7 +81,7 @@
// now let's suppose, the user cancel its modification
// we don't have call store()
- otherWikitties = service.restore(token, null, idsToRestore);
+ otherWikitties = service.restore(token, idsToRestore);
anotherWikitty = otherWikitties.get(0);
// the remaining wikitty should hold old value
@@ -99,7 +99,7 @@
setService(new WikittyServiceCached(config, new WikittyServiceInMemory(config)));
token = service.login(null, null);
- service.store(token, null, Collections.singletonList(getaWikitty()), false);
+ service.store(token, Collections.singletonList(getaWikitty()), false);
// restoring two times the same wikitty should produces two different copies
Wikitty anotherWikitty = service.restore(token, getaWikitty().getId());
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -121,8 +121,8 @@
log.debug("initial wikitty rights" + authorizations);
- service.storeExtension(token, null, Collections.singletonList(extension));
- service.store(token, null, Collections.singletonList(authorizations), false);
+ service.storeExtension(token, Collections.singletonList(extension));
+ service.store(token, Collections.singletonList(authorizations), false);
// Wikitty extensionAuthorisation =
@@ -176,7 +176,7 @@
// now try to make a valid token invalid
service.logout(readerToken);
try {
- service.store(readerToken, null, Collections.singletonList(getaWikitty()), false);
+ service.store(readerToken, Collections.singletonList(getaWikitty()), false);
fail();
} catch (SecurityException e) {}
}
@@ -195,7 +195,7 @@
auth.addReader(readerId);
log.debug("will store wikitty" + getaWikitty());
- service.store(ownerToken, null, Collections.singletonList(getaWikitty()), false);
+ service.store(ownerToken, Collections.singletonList(getaWikitty()), false);
try {
Wikitty restoredWikitty = service.restore(null, getaWikitty().getId());
@@ -210,7 +210,7 @@
public void testWriterRightOnWikitty() {
getaWikitty().addExtension(WikittyAuthorisationAbstract.extensionWikittyAuthorisation);
WikittyAuthorisation auth = new WikittyAuthorisationImpl(getaWikitty());
- service.store(ownerToken, null, Collections.singletonList(getaWikitty()), false);
+ service.store(ownerToken, Collections.singletonList(getaWikitty()), false);
WikittyProxy proxy = new WikittyProxy(service);
String adminId = WikittySecurityHelper.getUserWikittyId(proxy, "admin");
@@ -223,7 +223,7 @@
log.debug("will store wikitty" + getaWikitty());
try {
- service.store(writerToken, null, Collections.singletonList(getaWikitty()), false);
+ service.store(writerToken, Collections.singletonList(getaWikitty()), false);
fail("an exception should have been raised");
} catch (SecurityException e) {
log.info("raised exception : " + e);
@@ -241,28 +241,28 @@
public void checkReaderRightOnExtension() {
try {
- service.store(noRightsToken, null, Collections.singletonList(getaWikitty()), false);
+ service.store(noRightsToken, Collections.singletonList(getaWikitty()), false);
fail("an exception should have been raised");
} catch (SecurityException e) {
log.debug("creating a wikitty without rights", e);
}
try {
- service.restoreExtension(noRightsToken, null, extension.getId());
+ service.restoreExtension(noRightsToken, extension.getId());
} catch (SecurityException e) {
fail("no exception should have been raised");
}
try {
- service.restoreExtensionLastVersion(noRightsToken, null, extension.getName());
+ service.restoreExtensionLastVersion(noRightsToken, extension.getName());
} catch (SecurityException e) {
fail("no exception should have been raised");
}
try {
- service.store(readerToken, null, Collections.singletonList(getaWikitty()), false);
- service.restoreExtension(readerToken, null, extension.getId());
- service.restoreExtensionLastVersion(readerToken, null, extension.getName());
+ service.store(readerToken, Collections.singletonList(getaWikitty()), false);
+ service.restoreExtension(readerToken, extension.getId());
+ service.restoreExtensionLastVersion(readerToken, extension.getName());
} catch (SecurityException e) {
fail("an exception has been raised");
}
@@ -274,16 +274,16 @@
FieldType fieldType = new FieldType(FieldType.TYPE.STRING, 0, 1);
- service.restoreExtensionLastVersion(writerToken, null, extension.getName());
+ service.restoreExtensionLastVersion(writerToken, extension.getName());
extension.addField("new_field", fieldType);
try {
- service.storeExtension(readerToken, null, Collections.singletonList(extension));
+ service.storeExtension(readerToken, Collections.singletonList(extension));
fail("an exception should have been raised");
} catch (SecurityException e) {}
try {
- service.storeExtension(writerToken, null, Collections.singletonList(extension));
+ service.storeExtension(writerToken, Collections.singletonList(extension));
} catch (SecurityException e) {
fail("an exception has been raised");
}
@@ -314,11 +314,11 @@
log.debug("will store rights " + extensionAuthorisation);
try {
- service.store(writerToken, null, Collections.singletonList(extensionAuthorisation), false);
+ service.store(writerToken, Collections.singletonList(extensionAuthorisation), false);
fail("an exception should habe raised");
} catch (SecurityException e) {}
- service.store(adminToken, null, Collections.singletonList(extensionAuthorisation), false);
+ service.store(adminToken, Collections.singletonList(extensionAuthorisation), false);
// now, restore and check that rights are preserved
extensionAuthorisation =
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-29 00:35:39 UTC (rev 457)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-29 02:12:48 UTC (rev 458)
@@ -95,7 +95,7 @@
ext
);
String id = w.getId();
- wikittyService.store(null, null, Collections.singletonList(w), false);
+ wikittyService.store(null, Collections.singletonList(w), false);
((WikittyServiceInMemory)wikittyService).saveToPersistenceFile(tempPersistFile);
wikittyService = new WikittyServiceInMemory( config );
1
0
r457 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty test/java/org/nuiton/wikitty test/java/org/nuiton/wikitty/notification
by bpoussin@users.nuiton.org 29 Oct '10
by bpoussin@users.nuiton.org 29 Oct '10
29 Oct '10
Author: bpoussin
Date: 2010-10-29 02:35:39 +0200 (Fri, 29 Oct 2010)
New Revision: 457
Url: http://nuiton.org/repositories/revision/wikitty/457
Log:
add WikittyServiceTransaction and small test
http://www.nuiton.org/issues/show/1000
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyService.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -167,6 +167,34 @@
public boolean canRead(String securityToken, String wikittyId);
/**
+ * true if wikitty with id exists, even wikitty is deleted
+ */
+ public boolean exists(String securityToken, String wikittyId);
+
+ /**
+ * true if wikitty is deleted, throw an exception if id don't exist
+ * @param securityToken
+ * @param wikittyId
+ * @return
+ */
+ public boolean isDeleted(String securityToken, String wikittyId);
+
+ /**
+ * Replay all events in argument on this WikittyService
+ *
+ * @param securityToken security token
+ * @param events event to replay
+ * @return new event that represent all event passed in argument.
+ * if arguement have: store, store, delete, clear, store. Return event
+ * resume all by only one clear + store, because all action before clear is
+ * not necessary. Similarly for store + delete for the same object.
+ * (note: perhaps this broke history, when history are implanted and
+ * two serveur must have same history ?)
+ */
+ public WikittyServiceEvent replay(
+ String securityToken, List<WikittyServiceEvent> events);
+
+ /**
* Manage Update and creation, action is done in transaction passed in
* argument.
*
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -429,4 +429,19 @@
ws.syncEngin(securityToken);
}
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ return ws.replay(securityToken, events);
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return ws.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceDelegator.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -96,6 +96,11 @@
}
@Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ return delegate.replay(securityToken, events);
+ }
+
+ @Override
public WikittyServiceEvent store(String securityToken,
WikittyTransaction transaction, Collection<Wikitty> wikitties,
boolean force) {
@@ -202,4 +207,14 @@
public boolean canRead(String securityToken, String wikittyId) {
return delegate.canRead(securityToken, wikittyId);
}
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return delegate.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return delegate.isDeleted(securityToken, wikittyId);
+ }
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -61,7 +61,8 @@
REMOVE_WIKITTY(WikittyServiceListener.REMOVE_WIKITTY_METHOD),
CLEAR_WIKITTY(WikittyServiceListener.CLEAR_WIKITTY_METHOD),
PUT_EXTENSION(WikittyServiceListener.PUT_EXTENSION_METHOD),
- REMOVE_EXTENSION(WikittyServiceListener.REMOVE_EXTENSION_METHOD),
+ // il est impossible actuellement de supprimer des extensions
+// REMOVE_EXTENSION(WikittyServiceListener.REMOVE_EXTENSION_METHOD),
CLEAR_EXTENSION(WikittyServiceListener.CLEAR_EXTENSION_METHOD);
/** le nom de la methode du listener a appeler pour ce type d'event */
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -599,14 +599,9 @@
try {
transaction.begin();
- getSearchEngin().clear(transaction);
- WikittyServiceEvent eventWik = getWikittyStorage().clear(transaction);
- WikittyServiceEvent eventExt = getExtensionStorage().clear(transaction);
+
+ WikittyServiceEvent result = clear(securityToken, transaction);
- WikittyServiceEvent result = new WikittyServiceEvent(this);
- result.add(eventWik);
- result.add(eventExt);
-
transaction.commit();
return result;
} catch (Exception eee) {
@@ -616,6 +611,21 @@
}
/**
+ * Use with caution : It will delete ALL indexes from search engine !
+ * This operation should be disabled in production environment.
+ */
+ protected WikittyServiceEvent clear(String securityToken, WikittyTransaction tx) {
+ getSearchEngin().clear(tx);
+ WikittyServiceEvent eventWik = getWikittyStorage().clear(tx);
+ WikittyServiceEvent eventExt = getExtensionStorage().clear(tx);
+
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ result.add(eventWik);
+ result.add(eventExt);
+ return result;
+ }
+
+ /**
* Assume that this PagedResult contains wikitty id as result and
* return new PagedResult with Wikitty instance
*/
@@ -913,4 +923,122 @@
}
}
+ /**
+ * Question:
+ * <li> on ne force pas le store de wikitty, ils vont donc avoir potentiellement
+ * des versions differentes sur plusieurs serveurs, est-ce problematique ?
+ * <li> on ne passe pas la date de suppression des wikitties, ils vont donc
+ * avoir différente date de suppression sur différent serveur, est-ce problematique ?
+ *
+ *
+ * @param securityToken
+ * @param events
+ * @return
+ */
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ // indique qu'il faut vider la base avant de faire les ajouts
+ boolean mustClear = false;
+
+ // tous les objets a sauver
+ Map<String, Wikitty> toAddWikitty = new LinkedHashMap<String, Wikitty>();
+ // tous les id a supprimer
+ Map<String, Date> toRemoveWikitty = new LinkedHashMap<String, Date>();
+
+ // toutes les extensions a sauver
+ Set<WikittyExtension> toAddExt = new LinkedHashSet<WikittyExtension>();
+
+ // recherche un event avec un clear pour ne pas jouer des events inutiles
+ // recherche un store + delete du meme wikitty
+ // recherche le dernier store du wikitty
+ for (WikittyServiceEvent e : events) {
+ // check clear must be the first, if event have clear and other type
+ // clear is all time play first
+ if (e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
+ || e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
+ mustClear = true;
+ toAddWikitty.clear();
+ toRemoveWikitty.clear();
+ toAddExt.clear();
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
+ for (Wikitty w : e.getWikitties().values()) {
+ toAddWikitty.put(w.getId(), w);
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
+ for (Map.Entry<String, Date> entry : e.getRemoveDate().entrySet()) {
+ toAddWikitty.remove(entry.getKey());
+ toRemoveWikitty.put(entry.getKey(), entry.getValue());
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
+ for (WikittyExtension ext : e.getExtensions().values()) {
+ toAddExt.add(ext);
+ }
+ }
+ }
+
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+
+ // Actuellement il n'y a pas moyen de supprimer une extension (par surete)
+ // donc on ne fait rien avec toRemoveExt
+ WikittyServiceEvent result = new WikittyServiceEvent(this);
+ if (mustClear) {
+ WikittyServiceEvent eventClear = clear(securityToken, tx);
+ result.add(eventClear);
+ }
+ WikittyServiceEvent eventStoreExtension =
+ storeExtension(securityToken, tx, toAddExt);
+ result.add(eventStoreExtension);
+
+ WikittyServiceEvent eventStoreWikitty =
+ store(securityToken, tx, toAddWikitty.values(), false);
+ result.add(eventStoreWikitty);
+
+ WikittyServiceEvent eventDeleteWikitty =
+ delete(securityToken, tx, toRemoveWikitty.keySet());
+ result.add(eventDeleteWikitty);
+
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't replay data", eee);
+ }
+
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+ boolean result = getWikittyStorage().exists(null, wikittyId);
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't test existance", eee);
+ }
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ WikittyTransaction tx = new WikittyTransaction();
+ try {
+ tx.begin();
+ boolean result = getWikittyStorage().isDeleted(tx, wikittyId);
+ tx.commit();
+ return result;
+ } catch (Exception eee) {
+ tx.rollback();
+ throw new WikittyException("Can't test existance", eee);
+ }
+ }
+
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -146,8 +146,10 @@
Date now = new Date();
for (String id : idList) {
Wikitty w = restore(transaction, id);
- w.setDeleteDate(now);
- result.addRemoveDate(id, now);
+ if (w != null) {
+ w.setDeleteDate(now);
+ result.addRemoveDate(id, now);
+ }
}
return result;
}
@@ -176,9 +178,6 @@
if (result.isDeleted()) {
result = null;
}
- if (result == null) {
- throw new WikittyException(String.format("No wikitty with id '%s'", id));
- }
return result;
}
@@ -442,12 +441,14 @@
searchEngin = new WikittySearchEnginInMemory(
(WikittyStorageInMemory) wikittyStorage);
- boolean persist = config.getOptionAsBoolean(
- WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey());
- if (persist) {
- persistenceFile = config.getOptionAsFile(
- WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey());
- restoreFromPersistenceFile(persistenceFile);
+ if (config != null) {
+ boolean persist = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey());
+ if (persist) {
+ persistenceFile = config.getOptionAsFile(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey());
+ restoreFromPersistenceFile(persistenceFile);
+ }
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceListener.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -52,7 +52,6 @@
/** toto[1.0] */
public void putExtension(WikittyServiceEvent event);
- public void removeExtension(WikittyServiceEvent event);
public void clearExtension(WikittyServiceEvent event);
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -34,7 +34,6 @@
import java.util.TreeMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -353,6 +352,24 @@
super.finalize();
}
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ WikittyServiceEvent result = ws.replay(securityToken, events);
+ // notify listeners
+ fireEvent(result);
+ return result;
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ return ws.exists(securityToken, wikittyId);
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
/**
* Thread utilise pour envoyer les events. On rend accessible ce thread
* pour pouvoir y acceder depuis l'exterieur (pour l'instant pour les tests
@@ -672,20 +689,6 @@
}
/*
- * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[])
- */
- @Override
- public void removeExtension(WikittyServiceEvent event) {
- if (propagateEvent) {
- sendMessage(event);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Not master cache, do not propagate removeExtension event");
- }
- }
- }
-
- /*
* @see org.nuiton.wikitty.WikittyServiceListener#clearExtension()
*/
@Override
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -124,6 +124,38 @@
}
}
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ String userId = getUserId(securityToken);
+ for (WikittyServiceEvent e : events) {
+ if (e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY)
+ || e.getType().contains(
+ WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION)) {
+ if (isAppAdmin(securityToken, userId)) {
+ // seul les AppAdmin on le droit a cette method
+ // les AppAdmin on meme le droit de tout faire, donc on
+ // peut sortir de la boucle
+ break;
+ } else {
+ throw new SecurityException(_("user %s can't clear data", userId));
+ }
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_WIKITTY)) {
+ checkStore(securityToken, e.getWikitties().values());
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY)) {
+ checkDelete(securityToken, e.getRemoveDate().keySet());
+ }
+ if (e.getType().contains(WikittyServiceEvent.WikittyEventType.PUT_EXTENSION)) {
+ checkStoreExtension(securityToken, e.getExtensions().values());
+ }
+ }
+ WikittyServiceEvent result = ws.replay(securityToken, events);
+ return result;
+ }
+
+
/**
* if app-admin group exists, return true if given userId is app-admin
* if app-admin group doesn't exists, return true if user is anonymous
@@ -154,9 +186,18 @@
return result;
}
+ /**
+ * FIXME poussin 20101028 pourquoi retourner une liste ? soit on a le droit
+ * de faire un store sur tout, on bien on refuse avec une exception
+ * verifier que result ne sert bien a rien (surtout pas a filtrer)
+ *
+ * @param securityToken
+ * @param wikitties
+ * @return
+ */
protected Collection<Wikitty> checkStore(String securityToken, Collection<Wikitty> wikitties) {
String userId = getUserId(securityToken);
- List<Wikitty> wikittiesToStore = new ArrayList<Wikitty>();
+ List<Wikitty> result = new ArrayList<Wikitty>();
for (Wikitty wikitty : wikitties) {
// usual case, a user want to store a wikitty
@@ -219,9 +260,9 @@
}
}
- wikittiesToStore.add(wikitty);
+ result.add(wikitty);
}
- return wikittiesToStore;
+ return result;
}
@Override
@@ -326,6 +367,17 @@
@Override
public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ checkDelete(securityToken, ids);
+ WikittyServiceEvent result = ws.delete(securityToken, ids);
+ return result;
+ }
+
+ /**
+ * Check if we can delete all id passed in argument
+ * @param securityToken
+ * @param ids
+ */
+ public void checkDelete(String securityToken, Collection<String> ids) {
String userId = getUserId(securityToken);
List<String> idsAsList = new ArrayList<String>(ids);
List<Wikitty> wikitties = ws.restore(securityToken, null, idsAsList);
@@ -338,8 +390,6 @@
}
}
}
- WikittyServiceEvent result = ws.delete(securityToken, ids);
- return result;
}
@Override
@@ -755,5 +805,17 @@
return wikittyAuthorisation;
}
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ // no need security check for this action
+ return ws.exists(securityToken, wikittyId);
+ }
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ // no need security check for this action
+ return ws.isDeleted(securityToken, wikittyId);
+ }
+
+
}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceTransaction.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -0,0 +1,306 @@
+package org.nuiton.wikitty;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceTransaction implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceTransaction.class);
+
+ /** Real WikittyService */
+ protected WikittyService ws;
+ /** WikittyService used to store modified object */
+ protected WikittyService tx;
+
+ protected List<WikittyServiceEvent> events;
+
+ public WikittyServiceTransaction(ApplicationConfig config, WikittyService ws) {
+ this.ws = ws;
+ // create new WikittyServiceInMemory not configured with default config
+ // this WikittyServiceInMemory must be only in memory
+ this.tx = new WikittyServiceInMemory(null);
+ events = new LinkedList<WikittyServiceEvent>();
+ }
+
+ public void commit(String securityToken) {
+ ws.replay(securityToken, events);
+ this.tx.clear(null);
+ events.clear();
+ }
+
+ public void rollback(String securityToken) {
+ this.tx.clear(null);
+ events.clear();
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException(
+ "You try to add listener on WikittyServiceTransaction,"
+ + "this is an error desgin, you must add WikittyServiceNotifier"
+ + "front of your WikittyServiceTransaction.");
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyServiceListener listener, ServiceListenerType type) {
+ throw new UnsupportedOperationException(
+ "You try to remove listener on WikittyServiceTransaction,"
+ + "this is an error desgin, you must add WikittyServiceNotifier"
+ + "front of your WikittyServiceTransaction.");
+ }
+
+ @Override
+ public String login(String login, String password) {
+ return ws.login(login, password);
+ }
+
+ /**
+ * Question: est un comportement normale, lorsqu'on se delogue depuis une
+ * transaction, on est deloguer partout ? je pense que oui
+ * @param securityToken
+ */
+ @Override
+ public void logout(String securityToken) {
+ ws.logout(securityToken);
+ }
+
+ @Override
+ public WikittyServiceEvent clear(String securityToken) {
+ WikittyServiceEvent e = tx.clear(securityToken);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ // in transaction, we can do all. But not during commit
+ return true;
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ // in transaction, we can do all. But not during commit
+ return true;
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ boolean result = tx.exists(securityToken, wikittyId);
+ if (!result) {
+ // on ne l'a pas en local on va voir si on peut le lire en distant
+ result = ws.canRead(securityToken, wikittyId);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent replay(String securityToken, List<WikittyServiceEvent> events) {
+ WikittyServiceEvent e = tx.replay(securityToken, events);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public WikittyServiceEvent store(String securityToken, WikittyTransaction transaction, Collection<Wikitty> wikitties, boolean force) {
+ WikittyServiceEvent e = tx.store(securityToken, transaction, wikitties, force);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ HashSet<String> tmp = new HashSet<String>();
+
+ tmp.addAll(tx.getAllExtensionIds(securityToken));
+ tmp.addAll(ws.getAllExtensionIds(securityToken));
+
+ List<String> result = new ArrayList<String>(tmp);
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(String securityToken, String extensionName) {
+ HashSet<String> tmp = new HashSet<String>();
+
+ tmp.addAll(tx.getAllExtensionsRequires(securityToken, extensionName));
+ tmp.addAll(ws.getAllExtensionsRequires(securityToken, extensionName));
+
+ List<String> result = new ArrayList<String>(tmp);
+ return result;
+ }
+
+ @Override
+ public WikittyServiceEvent storeExtension(String securityToken, WikittyTransaction transaction, Collection<WikittyExtension> exts) {
+ WikittyServiceEvent e = tx.storeExtension(securityToken, transaction, exts);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken, WikittyTransaction transaction, String extensionId) {
+ WikittyExtension result = tx.restoreExtension(securityToken, transaction, extensionId);
+ if (result == null) {
+ result = ws.restoreExtension(securityToken, transaction, extensionId);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(String securityToken, WikittyTransaction transaction, String name) {
+ WikittyExtension result = tx.restoreExtensionLastVersion(securityToken, transaction, name);
+ if (result == null) {
+ result = ws.restoreExtension(securityToken, transaction, name);
+ }
+ return result;
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, WikittyTransaction transaction, List<String> ids) {
+ List<Wikitty> resultWS = ws.restore(securityToken, transaction, ids);
+ List<Wikitty> resultTx = tx.restore(securityToken, transaction, ids);
+ Wikitty[] result = resultWS.toArray(new Wikitty[resultWS.size()]);
+ int i = 0;
+ for (Wikitty w : resultTx) {
+ String id = ids.get(i);
+ // il faut prendre en compte que l'objet a pu etre supprime dans la
+ // transaction donc meme s'il est null dans tx et pas dans ws, il
+ // faut le mettre a null
+ // si w n'a pas ete restore (null), mais qu'il exist, alors cela
+ // veut dire qu'il est supprime.
+ if (w != null || tx.exists(securityToken, id)) {
+ // on remplace tout par les nouveaux de la transaction
+ result[i] = w;
+ }
+ i++;
+ }
+ return Arrays.asList(result);
+ }
+
+ @Override
+ public WikittyServiceEvent delete(String securityToken, Collection<String> ids) {
+ // pour que tout fonctionne bien, il faut que les objets supprimer soit
+ // dans la tx, car il faut avoir une vrai trace de cette suppression dans la tx
+ List<Wikitty> wikitties = ws.restore(securityToken, null, new ArrayList<String>(ids));
+ tx.store(securityToken, null, wikitties, true);
+
+ WikittyServiceEvent e = tx.delete(securityToken, ids);
+ events.add(e);
+ return e;
+ }
+
+ @Override
+ public PagedResult<String> findAllByCriteria(String securityToken, WikittyTransaction transaction, Criteria criteria) {
+ PagedResult<String> resultTx = tx.findAllByCriteria(securityToken, transaction, criteria);
+ PagedResult<String> resultWs = ws.findAllByCriteria(securityToken, transaction, criteria);
+
+ // Il faut fusionner les deux resultats
+ // - ne pas avoir de doublon
+ // - ne pas retenir ceux supprimer dans la transaction
+ // - fusionner les facettes (comment faire ?)
+ // - respecter le range demander (comment faire, avec les suppressions possible ?)
+ LinkedHashSet<String> ids = new LinkedHashSet<String>();
+ ids.addAll(resultTx.getAll());
+ ids.addAll(resultWs.getAll());
+
+ int firstIndice = resultWs.getFirstIndice();
+ // FIXME le resultat est faut, le nombre total n'est pas la somme des deux :(
+ int numFound = resultTx.getNumFound() + resultWs.getNumFound();
+ String queryString = resultWs.getQueryString();
+ // FIXME les facettes sont fausses :(
+ Map<String, List<FacetTopic>> facets = resultWs.getFacets();
+ List<String> results = new ArrayList<String>(ids);
+
+ PagedResult<String> result = new PagedResult<String>(
+ firstIndice, numFound, queryString, facets, results);
+ return result;
+ }
+
+ @Override
+ public Wikitty findByCriteria(String securityToken, WikittyTransaction transaction, Criteria criteria) {
+ Wikitty result = null;
+ PagedResult<String> ids = findAllByCriteria(securityToken, transaction, criteria);
+ List<String> results = ids.getAll();
+ if (results.size() > 0) {
+ String id = results.get(0);
+ List<Wikitty> wikitties = restore(
+ securityToken, transaction, Collections.singletonList(id));
+ result = wikitties.get(0);
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyTree restoreTree(String securityToken, String wikittyId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public WikittyServiceEvent deleteTree(String securityToken, String treeNodeId) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Entry<WikittyTreeNode, Integer> restoreNode(String securityToken, String wikittyId, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Map<WikittyTreeNode, Integer> restoreChildren(String securityToken, String wikittyId, Criteria filter) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken, String wikittyId, String version) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void syncEngin(String securityToken) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ boolean result = tx.exists(securityToken, wikittyId);
+ if (!result) {
+ if (!tx.isDeleted(securityToken, wikittyId)) {
+ result = ws.exists(securityToken, wikittyId);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ boolean result = tx.isDeleted(securityToken, wikittyId);
+ // pas efface, peut-etre qu'il existe
+ if (!result && !tx.exists(securityToken, wikittyId)) {
+ // il n'est pas efface et il n'existe pas dans la tx,
+ // on recherche dans ws
+ result = ws.isDeleted(securityToken, wikittyId);
+ }
+ return result;
+ }
+
+}
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceTransactionTest.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -0,0 +1,56 @@
+package org.nuiton.wikitty;
+
+import java.util.Collections;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceTransactionTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceTransactionTest.class);
+
+ public WikittyServiceTransactionTest() {
+ }
+
+ @Test
+ public void testTransaction() throws Exception {
+ WikittyConfig config = new WikittyConfig();
+ WikittyServiceInMemory ws = new WikittyServiceInMemory(config);
+ WikittyServiceTransaction tx = new WikittyServiceTransaction(config, ws);
+
+ // ajout d'objet hors transaction
+ WikittyLabel label = new WikittyLabelImpl();
+ label.addLabels("coucou");
+ ws.store(null, null, Collections.singleton(label.getWikitty()), false);
+
+ // on doit le retrouver dans la transation (meme si elle a ete ouverte avant)
+ Wikitty wTx = WikittyServiceEnhanced.restore(tx, null, label.getWikittyId());
+ Assert.assertEquals(label.getWikitty(), wTx);
+
+ // on creer un objet dans la transaction
+ WikittyLabel labelTx = new WikittyLabelImpl();
+ labelTx.addLabels("coucouTx");
+ tx.store(null, null, Collections.singleton(labelTx.getWikitty()), false);
+
+ // on ne doit pas le retrouver hors de la transation
+ Wikitty w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
+ Assert.assertEquals(null, w);
+
+ // on commit, du coup on doit retrouver l'objet
+ tx.commit(null);
+ w = WikittyServiceEnhanced.restore(ws, null, labelTx.getWikittyId());
+ Assert.assertEquals(labelTx.getWikitty(), w);
+
+ }
+
+}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-28 13:59:11 UTC (rev 456)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-29 00:35:39 UTC (rev 457)
@@ -46,8 +46,8 @@
wsn.removeWikittyServiceListener(l, ServiceListenerType.ALL);
sendEvent(wsn, false);
- // donc au total seulement 6 events on du etre envoye
- Assert.assertEquals(6, nbEvent);
+ // donc au total seulement 5 events on du etre envoye
+ Assert.assertEquals(5, nbEvent);
}
@@ -117,20 +117,6 @@
}
{
WikittyServiceEvent event = new WikittyServiceEvent("test");
- event.addType(WikittyServiceEvent.WikittyEventType.REMOVE_EXTENSION);
- wsn.processRemoteEvent(event);
- wsn.getEventThread().waitFor(event.getTime());
- if (hasListener) {
- Assert.assertEquals(
- EnumSet.of(WikittyServiceEvent.WikittyEventType.REMOVE_EXTENSION),
- lastEvent);
- } else {
- Assert.assertEquals(null, lastEvent);
- }
- lastEvent = null;
- }
- {
- WikittyServiceEvent event = new WikittyServiceEvent("test");
event.addType(WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION);
wsn.processRemoteEvent(event);
wsn.getEventThread().waitFor(event.getTime());
@@ -187,15 +173,6 @@
}
@Override
- public void removeExtension(WikittyServiceEvent event) {
- nbEvent++;
- Assert.assertEquals(
- EnumSet.of(WikittyServiceEvent.WikittyEventType.REMOVE_EXTENSION),
- event.getType());
- lastEvent = event.getType();
- }
-
- @Override
public void clearExtension(WikittyServiceEvent event) {
nbEvent++;
Assert.assertEquals(
1
0
Author: bpoussin
Date: 2010-10-28 15:59:11 +0200 (Thu, 28 Oct 2010)
New Revision: 456
Url: http://nuiton.org/repositories/revision/wikitty/456
Log:
ajout de la notion d'AddOn
Modified:
trunk/src/site/rst/index.rst
Modified: trunk/src/site/rst/index.rst
===================================================================
--- trunk/src/site/rst/index.rst 2010-10-28 13:54:03 UTC (rev 455)
+++ trunk/src/site/rst/index.rst 2010-10-28 13:59:11 UTC (rev 456)
@@ -73,12 +73,16 @@
Les services additionnels existants:
-- notion de label (pour étiqueter des objets)
- sécurité: authentification et autorisation
- cache
- notification (synchronisation de deux serveurs, notification en
client/serveur, listener sur les modifications)
+
+Les addons complémentaires:
+
+- notion de label (pour étiqueter des objets)
- import/export
+- internationnalisation (i18n)
Concept technique
=================
@@ -103,6 +107,11 @@
Il est donc possible d'ajouter de nouveau service de haut niveau, ou
d'ajouter de nouvelle façon de stocker l'information.
+Pour certain besoin il n'y a pas besoin d'implanter une nouvelle
+chouche (WikittyService). On parle alors de AddOn. C'est addon travail
+directement grace à l'API WikittyService, c'est le cas par exemple de
+l'import/export.
+
La partie cliente des applications ne travail qu'avec le WikittyProxy qui
masque la notion d'objet Wikitty pour retourner des beans metiers facilement
manipulable par le développeur.
1
0
Author: bpoussin
Date: 2010-10-28 15:54:03 +0200 (Thu, 28 Oct 2010)
New Revision: 455
Url: http://nuiton.org/repositories/revision/wikitty/455
Log:
New WikittyConfig to centralise all configuration
http://www.nuiton.org/issues/show/997
New Class WikittyServiceFactory to create au WikittyService declared in configuration (use picocontainer)
Suppress hessian serveur module from build, application can directly use Factory to replace it
http://www.nuiton.org/issues/show/1001
Import/Export use configuration
http://www.nuiton.org/issues/show/822
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java
Modified:
trunk/pom.xml
trunk/wikitty-api/pom.xml
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml
trunk/wikitty-api/src/test/resources/csv/importtree.csv
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java
trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
trunk/wikitty-jdbc-impl/src/test/resources/META-INF/spring/wikitty-test.xml
trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java
trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java
trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyZkService.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/pom.xml 2010-10-28 13:54:03 UTC (rev 455)
@@ -26,12 +26,18 @@
<module>wikitty-ui-zk</module>
<module>wikitty-hessian-client</module>
- <module>wikitty-hessian-server</module>
+<!-- REMOVE use WikittyServiceHelper.build now <module>wikitty-hessian-server</module> -->
</modules>
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ <version>2.11.2</version>
+ <scope>compile</scope>
+ </dependency>
<!--dependency>
<groupId>junit</groupId>
Modified: trunk/wikitty-api/pom.xml
===================================================================
--- trunk/wikitty-api/pom.xml 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/pom.xml 2010-10-28 13:54:03 UTC (rev 455)
@@ -48,6 +48,12 @@
<!-- COMPILE -->
<dependency>
+ <groupId>org.picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -24,7 +24,6 @@
*/
package org.nuiton.wikitty;
-import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@@ -34,6 +33,7 @@
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
+import org.nuiton.util.ApplicationConfig;
/**
* JGroups notifier.
@@ -50,16 +50,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class);
- /**
- * Utilisation du canal de communication basé sur jgroups avec
- * comme identifiant d'application le nom de canal en option.
- *
- * Si ce nom est vide, jgroups n'est pas utilisé.
- * Si {@link #WIKITTY_EVENT_PROPAGATE_OPTION} est a true et que cette
- * options est vide, une exception est levée.
- */
- static public final String WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION = "wikitty.service.event.jgroupschannelname";
-
/** Notifier service reference reference. */
protected WikittyServiceNotifier ws;
@@ -67,13 +57,13 @@
/** JGroup channel. */
protected JChannel channel;
- public JGroupsNotifierTransporter(WikittyServiceNotifier ws, Properties props) {
+ public JGroupsNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
this.ws = ws;
// can be null according to default constructor
- if (props != null) {
+ if (config != null) {
// add notifier as listener
- String jgroupChannel = props.getProperty(WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION);
+ String jgroupChannel = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_JGROUP_CHANNELNAME.getKey());
if (!StringUtils.isBlank(jgroupChannel)) {
initChannel(jgroupChannel);
} else {
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyCache.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -32,6 +32,7 @@
import org.apache.commons.collections.map.ReferenceMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
/**
* Cette classe sert a introduire du cache dans wikitty. Elle sert a centraliser
@@ -52,9 +53,11 @@
protected Map<String, Wikitty> wikittyCache;
/**
+ *
+ * @param config not used currently but necessary in futur to configure the cache
* Create a soft cache.
*/
- public WikittyCache() {
+ public WikittyCache(ApplicationConfig config) {
this(true);
}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfig.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -0,0 +1,321 @@
+package org.nuiton.wikitty;
+
+import java.io.File;
+import java.util.Properties;
+import static org.nuiton.i18n.I18n._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.ArgumentsParserException;
+
+/**
+ * Configuration de tous les modules Wikitty. La configuration par defaut doit
+ * permettre un bon fonctionnement de wikitty pour quelqu'un souhaitant faire un
+ * essaie rapide. La configuration actuelle:
+ * <li> wikitty-config.properties comme fichier de configuration
+ * <li> WikittyServiceInMemory
+ * <li> pas de notification reseau
+ * <li> /tmp pour les exports
+ *
+ * Si on utilise WikittyServiceImpl au lieu de WikittyServiceInMemory par defaut
+ * <li> base h2 embarque
+ * <li> solr
+ *
+ * Si on utilise la notification des events
+ * <li> transporter XMPPNotifierTransporter
+ * <li> serveur im.codelutin.com
+ * <li> room test(a)conference.im.codelutin.com
+ *
+ * Des la creation de l'objet les fichiers de configuration sont recherches.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyConfig extends ApplicationConfig {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyConfig.class);
+
+ /**
+ * Create WikittyConfig with default value and load wikitty-config.properties
+ */
+ public WikittyConfig() {
+ super();
+ init();
+ try {
+ parse(null);
+ } catch (ArgumentsParserException eee) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't load wikitty configuration", eee);
+ }
+ }
+ }
+
+ /**
+ * Create WikittyConfig and load particular configuration filename
+ * @param configFilename
+ */
+ public WikittyConfig(String configFilename) {
+ setDefaultOption(Option.WIKITTY_CONFIG_FILE.getKey(), configFilename);
+ }
+
+ /**
+ * Create WikittyConfig and use props as default value
+ * @param props
+ */
+ public WikittyConfig(Properties props) {
+ this();
+
+ // iterate with Properties method and not with Hashtable method to
+ // prevent missed value with chained Properties object
+ for (String key : props.stringPropertyNames()) {
+ setDefaultOption(key, props.getProperty(key));
+ }
+ }
+
+ protected void init() {
+ // init configuration with default options
+ for (Option o : Option.values()) {
+ if (o.defaultValue != null) {
+ setDefaultOption(o.key, o.defaultValue);
+ }
+ }
+
+ // init actions
+ for (Action a : Action.values()) {
+ for (String alias : a.aliases) {
+ addActionAlias(alias, a.action);
+ }
+ }
+ }
+
+ /**
+ * Configuration option for all modules
+ */
+ public static enum Option implements OptionDef {
+
+ WIKITTY_CONFIG_FILE(
+ CONFIG_FILE_NAME,
+ _("Main configuration wikitty file"),
+ "wikitty-config.properties", String.class, true, true),
+
+ WIKITTY_STORAGE_JDBC_QUERY_FILE(
+ "wikitty.storage.jdbc.queryfile",
+ _("JDBC query configuration file"),
+ "wikitty-jdbc-query.properties", String.class, false, false),
+
+ WIKITTY_STORAGE_JDBC_DRIVER(
+ "wikitty.storage.jdbc.driver",
+ _("JDBC driver name"),
+ "org.h2.Driver", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_URL(
+ "wikitty.storage.jdbc.host",
+ _("JDBC url"),
+ "jdbc:h2:file:./target/data/data", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_LOGIN(
+ "wikitty.storage.jdbc.login",
+ _("JDBC login name"),
+ "sa", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_PASSWORD(
+ "wikitty.storage.jdbc.password",
+ _("JDBC password"),
+ "", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_XADATASOURCE(
+ "wikitty.storage.jdbc.xadatasource",
+ _("JDBC xadatasource driver"),
+ "org.h2.jdbcx.JdbcDataSource", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_XADATASOURCE_H2_URL(
+ "wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.URL",
+ _("JDBC xadatasource property h2 url"),
+ "jdbc:h2:file:./target/data/data", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_XADATASOURCE_H2_USER(
+ "wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.user",
+ _("JDBC xadatasource property h2 username"),
+ "sa", String.class, false, false),
+ WIKITTY_STORAGE_JDBC_XADATASOURCE_H2_PASSWORD(
+ "wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.password",
+ _("JDBC xadatasource property h2 password"),
+ "", String.class, false, false),
+
+ WIKITTY_SEARCHENGINE_SOLR_DIRECTORY_DATA(
+ "wikitty.searchengine.solr.directory.data",
+ _("Solr data directory"),
+ "./target/data/solr", File.class, false, false),
+
+
+ WIKITTY_WIKITTYSERVICE_COMPONENTS(
+ "wikitty.WikittyService.components",
+ _("WikittyService to use (list must be in right order. "
+ + "ex: org.nuiton.wikitty.WikittyServiceImpl,org.nuiton.wikitty.WikittyServiceNotifier,org.nuiton.wikitty.WikittyServiceCached,org.nuiton.wikitty.WikittyServiceSecurity)"),
+ WikittyServiceInMemory.class.getName(), String.class, false, false),
+
+ WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE(
+ "wikitty.WikittyServiceInMemory.persistence",
+ _("Indique si les donnees sont stocker entre deux utilisations."),
+ "false", Boolean.class, false, false),
+ WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE(
+ "wikitty.WikittyServiceInMemory.persistence.file",
+ _("Fichier ou les donnees sont stocker"),
+ "/tmp/wikitty-inmemory.ser", File.class, false, false),
+
+
+ WIKITTY_WIKITTYSERVICEIMPL_COMPONENTS(
+ "wikitty.WikittyServiceImpl.components",
+ _("WikittyServiceImpl component to use (ExtensionStorage, WikittyStorage, SearchEngine)"),
+ "org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC,"
+ + "org.nuiton.wikitty.jdbc.WikittyStorageJDBC,"
+ + "org.nuiton.wikitty.solr.WikittySearchEnginSolr", String.class, false, false),
+
+ WIKITTY_EXPORT_THREADNUMBER(
+ "wikitty.addon.export.threadnumber",
+ _("number of thread used to export task"),
+ "1", Integer.class, false, false),
+ WIKITTY_EXPORT_DIRECTORY(
+ "wikitty.addon.export.directory",
+ _("directory path where export asynchronous file are stored"),
+ "/tmp", String.class, false, false),
+ WIKITTY_EXPORT_PUBLICURL(
+ "wikitty.addon.export.publicurl",
+ _("url used by client to retrieve export file when job is ended"),
+ "file:///tmp/", String.class, false, false),
+
+ WIKITTY_CACHE_LISTEN_REMOTEEVENTS(
+ "wikitty.service.cache.listenevents",
+ _("Indique si le service de cache ecoute les events reseaux"),
+ "false", Boolean.class, false, false),
+ WIKITTY_CACHE_RESTORE_COPIES(
+ "wikitty.service.cache.allwaysRestoreCopies",
+ _("Indique si le cache retourne des copies des objets ou des proxies"),
+ "false", Boolean.class, false, false),
+
+ WIKITTY_EVENT_PROPAGATE(
+ "wikitty.service.event.propagate",
+ _("Indique si le service d'event propage sur le reseau les evenements"),
+ "false", Boolean.class, false, false),
+ WIKITTY_EVENT_PROPAGATE_TRANSPORTER(
+ "wikitty.service.event.propagate.transporter",
+ _("La classe du transporter a utiliser pour la propagation reseau"),
+ XMPPNotifierTransporter.class.getName(), Class.class, false, false),
+
+ WIKITTY_EVENT_TRANSPORTER_JGROUP_CHANNELNAME(
+ "wikitty.service.event.transporter.jgroups.channelname",
+ _("channel name for jgroups transporter"),
+ null, String.class, false, false),
+
+ WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER(
+ "wiktty.service.event.transporter.xmpp.server",
+ _("XMPP server to use for XMPP transporter"),
+ "im.codelutin.com", String.class, false, false),
+ WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM(
+ "wikitty.service.event.transporter.xmpp.room",
+ _("Room to use for XMPP transporter"),
+ "test(a)conference.im.codelutin.com", String.class, false, false),
+ WIKITTY_EVENT_TRANSPORTER_XMPP_NOTIFICATION_PERSISTENT(
+ "wikitty.service.event.transporter.xmpp.notification.persistent",
+ _("If true client try to retrieve missed message during client"
+ + "stopped. For that room must have history activated"),
+ "false", Boolean.class, false, false),
+
+ // achitecture client serveur
+ WIKITTY_SERVER_HESSIAN_ENDPOINT(
+ "wikitty.server.hessian.endpoint",
+ _("Hessian serveur URL"),
+ null, String.class, false, false);
+
+ public String key;
+ public String description;
+ public String defaultValue;
+ public Class<?> type;
+ public boolean isTransient;
+ public boolean isFinal;
+
+ private Option(String key, String description, String defaultValue, Class<?> type, boolean isTransient, boolean isFinal) {
+ this.key = key;
+ this.description = description;
+ this.defaultValue = defaultValue;
+ this.type = type;
+ this.isTransient = isTransient;
+ this.isFinal = isFinal;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ @Override
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+ @Override
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ @Override
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ @Override
+ public void setTransient(boolean isTransient) {
+ this.isTransient = isTransient;
+ }
+
+ @Override
+ public void setFinal(boolean isFinal) {
+ this.isFinal = isFinal;
+ }
+ }
+
+ public static enum Action {
+
+ HELP(_("Wikitty help"),
+ WikittyConfig.class.getName() + "#help", "-h", "--help");
+
+ public String description;
+ public String action;
+ public String[] aliases;
+
+ private Action(String description, String action, String... aliases) {
+ this.description = description;
+ this.action = action;
+ this.aliases = aliases;
+ }
+ }
+
+ static public void help() {
+ System.out.println("Wikitty configuration and action");
+ System.out.println("Options (set with --option <key> <value>:");
+ for (WikittyConfig.Option o : WikittyConfig.Option.values()) {
+ log.debug("\t" + o.key + "(" + o.defaultValue + "):" + o.description);
+ }
+
+ log.debug("Actions:");
+ for (WikittyConfig.Action a : WikittyConfig.Action.values()) {
+ log.debug("\t" + java.util.Arrays.toString(a.aliases) + "(" + a.action + "):" + a.description);
+ }
+ System.exit(0);
+ }
+
+}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyImportExportService.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -39,6 +39,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.importexport.ExportTask;
import org.nuiton.wikitty.importexport.ImportExportCSV;
@@ -74,18 +75,13 @@
}
};
- // FIXME poussin 20090902 next 3 variables must be read from configuration file
- /** number of thread used to import/export task */
- protected static final int MAX_IMPORT_EXPORT_THREAD = 1;
/** directory path where export asynchronous file are stored */
- protected static final String EXPORT_DIRECTORY = "/tmp/";
+ protected String exportDirectory = "/tmp/";
/** url used by client to retrieve export file when job is ended */
- protected static final String EXPORT_URL = "file:///tmp/";
+ protected String exportPublicURL = "file:///tmp/";
/** Executor that do import export task */
- protected ExecutorService importExportExecutor =
- // TODO poussin 20090902 do thread number configurable
- Executors.newFixedThreadPool(MAX_IMPORT_EXPORT_THREAD);
+ protected ExecutorService importExportExecutor;
/** contains all import or export task, key is job id send to client */
protected Map<String, Future<String>> importExportTask =
@@ -94,15 +90,34 @@
protected WikittyService ws;
protected String securityToken;
- public WikittyImportExportService(String securityToken, WikittyService ws) {
+ public WikittyImportExportService(
+ ApplicationConfig config, String securityToken, WikittyService ws) {
this.securityToken = securityToken;
this.ws = ws;
+
+ exportDirectory = config.getOption(
+ WikittyConfig.Option.WIKITTY_EXPORT_DIRECTORY.getKey());
+ exportPublicURL = config.getOption(
+ WikittyConfig.Option.WIKITTY_EXPORT_PUBLICURL.getKey());
+
+ int maxThread = config.getOptionAsInt(
+ WikittyConfig.Option.WIKITTY_EXPORT_THREADNUMBER.getKey());
+ this.importExportExecutor =
+ Executors.newFixedThreadPool(maxThread);
}
public WikittyService getWikittyService() {
return ws;
}
+ public String getExportDirectory() {
+ return exportDirectory;
+ }
+
+ public String getExportPublicURL() {
+ return exportPublicURL;
+ }
+
public void syncImport(FORMAT format, String s) {
Reader reader = new StringReader(s);
ImportTask task = new ImportTask(securityToken, ws, format, reader);
@@ -175,8 +190,8 @@
try {
String jobId = UUID.randomUUID().toString();
- File file = new File(EXPORT_DIRECTORY, jobId);
- String url = EXPORT_URL + jobId;
+ File file = new File(exportDirectory, jobId);
+ String url = exportPublicURL + jobId;
Writer result = new FileWriter(file);
ExportTask task = new ExportTask(
securityToken, ws, format, criteria, result);
@@ -239,7 +254,7 @@
public void freeJobResource(String jobId) {
Future<String> future = importExportTask.remove(jobId);
if (future != null) {
- File file = new File(EXPORT_DIRECTORY, jobId);
+ File file = new File(exportDirectory, jobId);
file.delete();
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceCached.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -31,11 +31,10 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
/**
* Override some method of WikittyService to use cache
@@ -51,17 +50,20 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceCached.class);
- /**
- * Utiliser pour mettre à jour le cache en ecoutant les evenements
- * sur le service.
- *
- * Le service {@link #ws} doit supporter l'enregistrement de listener.
- */
- static public final String WIKITTY_CACHE_LISTENEVENTS_OPTION = "wikitty.service.cache.listenevents";
+ // FIXME REMOVE IT
+// /**
+// * Utiliser pour mettre à jour le cache en ecoutant les evenements
+// * sur le service.
+// *
+// * Le service {@link #ws} doit supporter l'enregistrement de listener.
+// */
+// static public final String WIKITTY_CACHE_LISTEN_REMOTEEVENTS =
+// "wikitty.service.cache.listenevents";
+//
+// /** used as property name in props given in the constructor */
+// public static final String WIKITTY_CACHE_RESTORE_COPIES =
+// "wikitty.service.cache.allwaysRestoreCopies";
- /** used as property name in props given in the constructor */
- public static final String WIKITTY_CACHE_ALLWAYS_RESTORE_COPIES_POLICY_OPTION = "wikitty.service.cache.allwaysRestoreCopies";
-
/** Cache. */
protected WikittyCache cache = null;
@@ -80,14 +82,15 @@
*/
protected boolean allwaysRestoreCopies = false;
- /**
- * Default constructor.
- *
- * @param ws delegate service
- */
- public WikittyServiceCached(WikittyService ws) {
- this(ws, null);
- }
+ // FIXME 20101027 REMOVE IT when WikittyConfig is used everywhere
+// /**
+// * Default constructor.
+// *
+// * @param ws delegate service
+// */
+// public WikittyServiceCached(WikittyService ws) {
+// this(null, ws);
+// }
/**
* Constructor with configuration.
@@ -95,15 +98,15 @@
* @param ws delegate service
* @param props properties (can be null)
*/
- public WikittyServiceCached(WikittyService ws, Properties props) {
+ public WikittyServiceCached(ApplicationConfig config, WikittyService ws) {
this.ws = ws;
- cache = new WikittyCache();
- registerWikittyServiceListener(props);
-
- // reading configuration and set allwaysRestoreCopies accordingly
- if (props != null && props.containsKey(WIKITTY_CACHE_ALLWAYS_RESTORE_COPIES_POLICY_OPTION)) {
- allwaysRestoreCopies = Boolean.parseBoolean(
- props.getProperty(WIKITTY_CACHE_ALLWAYS_RESTORE_COPIES_POLICY_OPTION));
+ cache = new WikittyCache(config);
+ registerWikittyServiceListener(config);
+
+ if (config != null) {
+ // reading configuration and set allwaysRestoreCopies accordingly
+ allwaysRestoreCopies =
+ config.getOptionAsBoolean(WikittyConfig.Option.WIKITTY_CACHE_RESTORE_COPIES.getKey());
}
}
@@ -136,12 +139,12 @@
*
* @param props properties (can be null)
*/
- protected void registerWikittyServiceListener(Properties props) {
-
- if (props != null) {
+ protected void registerWikittyServiceListener(ApplicationConfig config) {
+ if (config != null) {
// add notifier as listener
- String listenEvents = props.getProperty(WIKITTY_CACHE_LISTENEVENTS_OPTION, "false");
- if ("true".equalsIgnoreCase(listenEvents)) {
+ boolean listenEvents = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_CACHE_LISTEN_REMOTEEVENTS.getKey());
+ if (listenEvents) {
// add service listener for synchronisation
// listener des remote event
addWikittyServiceListener(cache, ServiceListenerType.REMOTE);
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -26,15 +26,12 @@
package org.nuiton.wikitty;
import com.thoughtworks.xstream.XStream;
-import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.EventObject;
import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.Map;
-import java.util.Set;
/**
* Wikitty service event.
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceFactory.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -0,0 +1,156 @@
+package org.nuiton.wikitty;
+
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.containers.TransientPicoContainer;
+
+/**
+ * Point d'entre de wikitty, permet de recuperer un WikittyService pour
+ * travailler
+ *
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceFactory {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceFactory.class);
+
+ // FIXME REMOVE IT
+// /**
+// * Construit l'enchainement des differents WikittyService comme decrit
+// * dans le fichier de configuration via la cle:
+// * wikitty.WikittyService.components
+// * <p>
+// * Chaque composant de l'enchainement peut avoir lui aussi ses propres
+// * composants dans une cle:
+// * wikitty.[nom simple de la classe].components *
+// *
+// * @param props
+// * @return
+// */
+// static public WikittyService buildWikittyService(Properties props) {
+// WikittyConfig config = new WikittyConfig(props);
+// return buildWikittyService(config);
+// }
+
+ /**
+ * Construit l'enchainement des differents WikittyService comme decrit
+ * dans le fichier de configuration via la cle:
+ * wikitty.WikittyService.components
+ * <p>
+ * Chaque composant de l'enchainement peut avoir lui aussi ses propres
+ * composants dans une cle:
+ * wikitty.[nom simple de la classe].components *
+ *
+ * @param config
+ * @return
+ */
+ static public WikittyService buildWikittyService(ApplicationConfig config) {
+ WikittyService result = null;
+
+ List<Class> layers = getComponents(config, WikittyService.class);
+
+ MutablePicoContainer pico = new TransientPicoContainer();
+ pico.addComponent(config);
+ for (Class<WikittyService> clazz : layers) {
+ pico.addComponent(WikittyService.class, clazz);
+
+ // on cree un container specifique pour l'instanciate de cette objet
+ // avec tous les composants dont il a besoin
+ MutablePicoContainer childPico = getChildContainer(config, pico, clazz);
+ result = childPico.getComponent(clazz);
+
+ pico.removeComponent(WikittyService.class);
+ pico.removeComponent("parent");
+ pico.addComponent("parent", result);
+ }
+ return result;
+ }
+
+ static public WikittyServiceNotifier.RemoteNotifierTransporter buildTransporter(
+ ApplicationConfig config, WikittyServiceNotifier notifier) {
+ Class<WikittyServiceNotifier.RemoteNotifierTransporter> transporterClass =
+ (Class<WikittyServiceNotifier.RemoteNotifierTransporter>)config.getOptionAsClass(
+ WikittyConfig.Option.WIKITTY_EVENT_PROPAGATE_TRANSPORTER.getKey());
+
+ MutablePicoContainer pico = new TransientPicoContainer();
+ pico.addComponent(config);
+ pico.addComponent(notifier);
+ WikittyServiceNotifier.RemoteNotifierTransporter result =
+ pico.getComponent(transporterClass);
+ return result;
+ }
+
+ /**
+ * Retourne un nouveau container fils de celui passe en parametre et dans
+ * lequel on a injecte tous les composans necessaire a clazz comme decrit
+ * dans le fichier de configuration
+ *
+ * @param config
+ * @param parent
+ * @param clazz
+ * @return
+ */
+ static protected MutablePicoContainer getChildContainer(
+ ApplicationConfig config, MutablePicoContainer parent, Class clazz) {
+ List<Class> comps = getComponents(config, clazz);
+ MutablePicoContainer result = makeChildContainer(parent, comps);
+ return result;
+ }
+
+ /**
+ * Recherche dans la config une key de la forme
+ * <pre>
+ * wikitty.[nom simple de la classe].components
+ * </pre>
+ * Par exemple pour org.nuiton.wikitty.WikittyService le nom simple est
+ * WikittyService.
+ * La valeur doit contenir une liste de classes separer par des ','.
+ * *
+ * @param config
+ * @param clazz
+ * @return la liste de classe trouvee ou null si la cle n'existe pas
+ */
+ static protected List<Class> getComponents(ApplicationConfig config, Class clazz) {
+ List<Class> result = null;
+
+ String key = "wikitty." + clazz.getSimpleName() + ".components";
+
+ String componentsString = config.getOption(key);
+ if (componentsString != null) {
+ String[] componentsList = componentsString.split(",");
+ result = (List<Class>) ClassUtils.convertClassNamesToClasses(
+ Arrays.asList(componentsList));
+ }
+ return result;
+ }
+
+ /**
+ * Cree un nouveau container et injecte les classes donnees en parametre
+ * @param parent
+ * @param comps
+ * @return
+ */
+ static protected MutablePicoContainer makeChildContainer(
+ MutablePicoContainer parent, List<Class> comps) {
+ MutablePicoContainer result = parent.makeChildContainer();
+ if (comps != null) {
+ for (Class clazz : comps) {
+ result.addComponent(clazz);
+ }
+ }
+ return result;
+ }
+}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceImpl.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -65,13 +65,14 @@
protected WikittyStorage wikittyStorage;
/**
+ * FIXME poussin 20101027 remove it when all used WikittyServiceHelper.build
+ *
* Used by specific child
* {@link org.nuiton.wikitty.jdbc.WikittyServiceJDBC}
* {@link org.nuiton.wikitty.jdbc.WikittyServiceJPA}
* {@link org.nuiton.wikitty.jdbc.WikittyServiceHbase}
*/
protected WikittyServiceImpl() {
-
}
public WikittyServiceImpl(WikittyExtensionStorage extensionStorage,
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceInMemory.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -44,6 +44,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.FieldType.TYPE;
import org.nuiton.wikitty.search.And;
import org.nuiton.wikitty.search.BinaryOperator;
@@ -429,56 +430,58 @@
}
/**
- * if persitenceFile is not null, serialize all data to disk during store
+ * if persistenceFile is not null, serialize all data to disk during store
* operation and the file is reloaded during init
*/
- protected File persitenceFile = null;
+ protected File persistenceFile = null;
-// protected WikittyStorage wikittyStorage;
-// protected WikittyExtensionStorage extensionStorage;
-// protected WikittySearchEngin searchEngin;
-
- public WikittyServiceInMemory() {
+ public WikittyServiceInMemory(ApplicationConfig config) {
super(new WikittyExtensionStorageInMemory(),
new WikittyStorageInMemory(),
null);
searchEngin = new WikittySearchEnginInMemory(
(WikittyStorageInMemory) wikittyStorage);
+
+ boolean persist = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey());
+ if (persist) {
+ persistenceFile = config.getOptionAsFile(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey());
+ restoreFromPersistenceFile(persistenceFile);
+ }
}
- public WikittyServiceInMemory(File persitenceFile) {
- this();
- this.persitenceFile = persitenceFile;
- if (persitenceFile != null && persitenceFile.exists()) {
+ @Override
+ protected void finalize() throws Throwable {
+ saveToPersistenceFile(persistenceFile);
+
+ super.finalize();
+ }
+
+ protected void restoreFromPersistenceFile(File persistenceFile) {
+ if (persistenceFile != null && persistenceFile.exists()) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
- persitenceFile));
+ persistenceFile));
((WikittyExtensionStorageInMemory)extensionStorage).extensions = (Map) in.readObject();
((WikittyStorageInMemory)wikittyStorage).wikitties = (Map) in.readObject();
in.close();
} catch (Exception eee) {
- log.error("Can't read data file " + persitenceFile, eee);
+ log.error("Can't read data file " + persistenceFile, eee);
}
}
}
- @Override
- protected void finalize() throws Throwable {
- saveToPersistenceFile();
-
- super.finalize();
- }
-
- public void saveToPersistenceFile() {
- if (persitenceFile != null) {
+ public void saveToPersistenceFile(File persistenceFile) {
+ if (persistenceFile != null) {
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- persitenceFile));
+ persistenceFile));
out.writeObject(((WikittyExtensionStorageInMemory)extensionStorage).extensions);
out.writeObject(((WikittyStorageInMemory)wikittyStorage).wikitties);
out.close();
} catch (IOException eee) {
- log.error("Can't write data file " + persitenceFile, eee);
+ log.error("Can't write data file " + persistenceFile, eee);
}
}
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -26,14 +26,10 @@
package org.nuiton.wikitty;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.LinkedBlockingQueue;
@@ -85,21 +81,12 @@
protected EventThread eventThread;
/**
- * Default constructor.
- *
- * @param ws delegate service
- */
- public WikittyServiceNotifier(WikittyService ws) {
- this(ws, null);
- }
-
- /**
* Constructor with configuration.
*
* @param ws delegate service
* @param props properties (can be null)
*/
- public WikittyServiceNotifier(WikittyService ws, Properties props) {
+ public WikittyServiceNotifier(ApplicationConfig config, WikittyService ws) {
// service
this.ws = ws;
@@ -115,8 +102,8 @@
remoteWikittyServiceListeners);
// can be null according to default constructor
- if (props != null) {
- notifier = new RemoteNotifier(this, props);
+ if (config != null) {
+ notifier = new RemoteNotifier(config, this);
}
}
@@ -566,13 +553,6 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(RemoteNotifier.class);
- /**
- * Indique si les objects sont propages (true) vers les autres caches ou
- * simplement supprimes des autres caches (false). Default to {@code false}.
- */
- static public final String WIKITTY_EVENT_PROPAGATE_OPTION = "wikitty.service.event.propagateEvent";
- /** notifier class name in configuration that this service must used */
- static final public String WIKITTY_NOTIFIER_TRANSPORTER_CLASS = "wikitty.notifier.transporter.class";
/** Notifier service reference reference. */
protected WikittyServiceNotifier ws;
@@ -586,34 +566,22 @@
protected boolean propagateEvent = false;
protected RemoteNotifierTransporter transporter;
- public RemoteNotifier(WikittyServiceNotifier ws, Properties props) {
+ public RemoteNotifier(ApplicationConfig config, WikittyServiceNotifier ws) {
// can be null according to default constructor
- if (props != null) {
+ if (config != null) {
this.ws = ws;
- if (!props.containsKey(WIKITTY_NOTIFIER_TRANSPORTER_CLASS)) {
- props.setProperty(WIKITTY_NOTIFIER_TRANSPORTER_CLASS, JGroupsNotifierTransporter.class.getName());
- }
- ApplicationConfig config = new ApplicationConfig(props);
-
- propagateEvent = config.getOptionAsBoolean(WIKITTY_EVENT_PROPAGATE_OPTION);
+ propagateEvent = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_EVENT_PROPAGATE.getKey());
if (log.isDebugEnabled()) {
log.debug("Set propagateEvent option to " + propagateEvent);
}
- Class transporterClass = config.getOptionAsClass(
- WIKITTY_NOTIFIER_TRANSPORTER_CLASS);
- try {
- transporter = (RemoteNotifierTransporter) ConstructorUtils.invokeConstructor(transporterClass,
- new Object[]{ws, props},
- new Class[]{WikittyServiceNotifier.class, Properties.class});
- } catch (Exception eee) {
- throw new WikittyException("Can't create notifier: "
- + transporterClass.getName(), eee);
+ if (propagateEvent) {
+ transporter = WikittyServiceFactory.buildTransporter(config, ws);
+ // add this as listener when transporter is created without error
+ ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference
}
-
- // add this as listener when transporter is created without error
- ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference
}
if (log.isInfoEnabled()) {
if (transporter == null) {
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceSecurity.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -36,6 +36,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.search.Search;
/**
@@ -58,7 +59,12 @@
/** cache de l'id du groupe AppAdmin */
transient protected String appAdminGroupId = null;
- public WikittyServiceSecurity(WikittyService ws) {
+ /**
+ *
+ * @param config not use currently but needed in futur
+ * @param ws
+ */
+ public WikittyServiceSecurity(ApplicationConfig config, WikittyService ws) {
this.ws = new WikittyServiceEnhanced(ws);
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyTransaction.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -51,6 +51,9 @@
}
/**
+ * FIXME poussin 20101027 a supprimer lorsque WikittyServiceTransaction
+ * aura ete implante
+ *
* Visibilite 'default' car est uilise par WikittyServiceCached qui est dans
* le meme package et a priori seulement lui en a besoin
*
@@ -58,7 +61,7 @@
*/
WikittyCache getCache() {
if (cache == null) {
- cache = new WikittyCache();
+ cache = new WikittyCache(false);
}
return cache;
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -32,7 +32,6 @@
import java.net.NetworkInterface;
import java.util.Date;
import java.util.Enumeration;
-import java.util.Properties;
import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -68,10 +67,6 @@
static private Log log = LogFactory.getLog(XMPPNotifierTransporter.class);
static final public String PROPERTY_EVENT_NAME = "wikitty-event";
- static final public String WIKITTY_XMPP_SERVER = "wikitty.xmpp.server";
- static final public String WIKITTY_XMPP_ROOM = "wikitty.xmpp.room";
- static final public String WIKITTY_NOTIFICATION_PERSISTENT =
- "wikitty.notification.persistent";
/** Notifier service reference reference. */
protected WikittyServiceNotifier ws;
@@ -92,9 +87,9 @@
* @param ws
* @param props
*/
- public XMPPNotifierTransporter(WikittyServiceNotifier ws, Properties props) {
+ public XMPPNotifierTransporter(ApplicationConfig config, WikittyServiceNotifier ws) {
this.ws = ws;
- initXMPP(props);
+ initXMPP(config);
}
/**
@@ -102,14 +97,14 @@
*
* @param props
*/
- protected void initXMPP(Properties props) {
- ApplicationConfig config = new ApplicationConfig(props);
+ protected void initXMPP(ApplicationConfig config) {
+ persistent = config.getOptionAsBoolean(
+ WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_NOTIFICATION_PERSISTENT.getKey());
+ String server = config.getOption(
+ WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER.getKey());
- persistent = config.getOptionAsBoolean(WIKITTY_NOTIFICATION_PERSISTENT);
- String server = config.getOption(WIKITTY_XMPP_SERVER);
-
// Keep them to verify that is not us notifications
- room = config.getOption(WIKITTY_XMPP_ROOM);
+ room = config.getOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM.getKey());
pseudo = getUniqueLoginName();
try {
if (log.isInfoEnabled()) {
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyI18nTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -22,7 +22,8 @@
@Test
public void testI18n() throws Exception {
// creation d'un proxy sur un ws in memory
- WikittyService ws = new WikittyServiceInMemory();
+ WikittyConfig config = new WikittyConfig();
+ WikittyService ws = new WikittyServiceInMemory(config);
WikittyProxy proxy = new WikittyProxy(ws);
// creation d'un label pour l'utiliser pour l'i18n
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/WikittyServiceHelperTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -0,0 +1,39 @@
+package org.nuiton.wikitty;
+
+
+import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyServiceHelperTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyServiceHelperTest.class);
+
+ @Test
+ public void testBuild() throws Exception {
+ Properties props = new Properties();
+ props.setProperty(WikittyConfig.Option.WIKITTY_WIKITTYSERVICE_COMPONENTS.getKey(),
+ WikittyServiceInMemory.class.getName() + "," +
+ WikittyServiceNotifier.class.getName() + "," +
+ WikittyServiceCached.class.getName());
+ WikittyConfig config = new WikittyConfig(props);
+ WikittyService ws = WikittyServiceFactory.buildWikittyService(config);
+
+ Assert.assertEquals(WikittyServiceCached.class, ws.getClass());
+ ws = ((WikittyServiceCached)ws).ws;
+ Assert.assertEquals(WikittyServiceNotifier.class, ws.getClass());
+ ws = ((WikittyServiceNotifier)ws).ws;
+ Assert.assertEquals(WikittyServiceInMemory.class, ws.getClass());
+ }
+}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/ImportExportTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -43,6 +43,7 @@
import org.junit.Test;
import org.nuiton.wikitty.Criteria;
import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyImportExportService;
import org.nuiton.wikitty.search.Element;
import org.nuiton.wikitty.search.Search;
@@ -59,7 +60,8 @@
protected WikittyImportExportService getImportExportService() {
if (ieService == null) {
- ieService = new WikittyImportExportService(null, ws);
+ WikittyConfig config = new WikittyConfig();
+ ieService = new WikittyImportExportService(config, null, ws);
}
return ieService;
}
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -35,6 +35,7 @@
import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.Criteria;
import org.nuiton.wikitty.PagedResult;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyTreeNode;
import org.nuiton.wikitty.WikittyTreeNodeImpl;
import org.nuiton.wikitty.WikittyExtension;
@@ -167,11 +168,17 @@
proxy.storeExtension(extensionTag);
// declare import service
- WikittyImportExportService wsImport = new WikittyImportExportService(null, ws);
- String[] importFiles = {"/csv/importclient.csv", "/csv/importtree.csv", "/csv/importtree2.csv"};
+ WikittyConfig config = new WikittyConfig();
+ WikittyImportExportService wsImport =
+ new WikittyImportExportService(config, null, ws);
+ String[] importFiles = {
+ "/csv/importclient.csv",
+ "/csv/importtree.csv",
+ "/csv/importtree2.csv"};
for (String importFile : importFiles) {
URL importFileURL = ImportExportCSVTest.class.getResource(importFile);
- wsImport.syncImportFromUri(WikittyImportExportService.FORMAT.CSV, importFileURL.toExternalForm());
+ wsImport.syncImportFromUri(WikittyImportExportService.FORMAT.CSV,
+ importFileURL.toExternalForm());
}
// test extension support
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceCachedTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -35,6 +35,7 @@
import org.junit.Before;
import org.junit.Test;
import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyServiceCached;
import org.nuiton.wikitty.WikittyServiceInMemory;
@@ -43,7 +44,8 @@
@Before
public void setUpWikittyServiceCachedTest() {
- setService(new WikittyServiceCached(new WikittyServiceInMemory()));
+ WikittyConfig config = new WikittyConfig();
+ setService(new WikittyServiceCached(config, new WikittyServiceInMemory(config)));
token = service.login(null, null);
service.store(token, null, Collections.singletonList(getaWikitty()), false);
}
@@ -90,10 +92,12 @@
@Test
public void testRestoreAllwaysCopyPolicy() throws Exception {
- Properties props = new Properties();
- props.setProperty(WikittyServiceCached.WIKITTY_CACHE_ALLWAYS_RESTORE_COPIES_POLICY_OPTION, "true");
+ WikittyConfig config = new WikittyConfig();
+ config.setOption(
+ WikittyConfig.Option.WIKITTY_CACHE_RESTORE_COPIES.getKey(),
+ "true");
- setService(new WikittyServiceCached(new WikittyServiceInMemory(), props));
+ setService(new WikittyServiceCached(config, new WikittyServiceInMemory(config)));
token = service.login(null, null);
service.store(token, null, Collections.singletonList(getaWikitty()), false);
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/layers/WikittyServiceSecurityTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -40,6 +40,7 @@
import org.nuiton.wikitty.WikittyAuthorisationAbstract;
import org.nuiton.wikitty.WikittyAuthorisationHelper;
import org.nuiton.wikitty.WikittyAuthorisationImpl;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyGroup;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittySecurityHelper;
@@ -67,9 +68,11 @@
@Before
public void setUpWikittyServiceSecurityTest() {
- WikittyService inMemoryService = new WikittyServiceInMemory();
+ WikittyConfig config = new WikittyConfig();
+ WikittyService inMemoryService = new WikittyServiceInMemory(config);
- WikittyServiceSecurity securityService = new WikittyServiceSecurity(inMemoryService);
+ WikittyServiceSecurity securityService =
+ new WikittyServiceSecurity(config, inMemoryService);
/** /
// FIXME 20101005 bleny implementation should be able to allow
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/memory/InMemoryStorageTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -40,6 +40,7 @@
import org.nuiton.wikitty.ExtensionFactory;
import org.nuiton.wikitty.FieldType.TYPE;
import org.nuiton.wikitty.Wikitty;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyExtension;
import org.nuiton.wikitty.WikittyImpl;
import org.nuiton.wikitty.WikittyServiceEnhanced;
@@ -53,7 +54,8 @@
@Before
public void init() throws Exception {
- wikittyService = new WikittyServiceInMemory();
+ WikittyConfig config = new WikittyConfig();
+ wikittyService = new WikittyServiceInMemory(config);
}
protected static DateFormat dateFormater = new SimpleDateFormat("dd/MM/yyyy");
@@ -70,7 +72,14 @@
tempPersistFile.delete();
tempPersistFile.deleteOnExit();
- wikittyService = new WikittyServiceInMemory( tempPersistFile );
+ WikittyConfig config = new WikittyConfig();
+ config.setOption(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE.getKey(),
+ "true");
+ config.setOption(
+ WikittyConfig.Option.WIKITTY_WIKITTYSERVICEINMEMORY_PERSISTENCE_FILE.getKey(),
+ tempPersistFile.getPath());
+ wikittyService = new WikittyServiceInMemory(config);
String extName = "MyExtName";
WikittyExtension ext = ExtensionFactory.create("MyExtName", "1")
.addField("fieldName0", TYPE.NUMERIC)
@@ -87,9 +96,9 @@
);
String id = w.getId();
wikittyService.store(null, null, Collections.singletonList(w), false);
- ((WikittyServiceInMemory)wikittyService).saveToPersistenceFile();
+ ((WikittyServiceInMemory)wikittyService).saveToPersistenceFile(tempPersistFile);
- wikittyService = new WikittyServiceInMemory( tempPersistFile );
+ wikittyService = new WikittyServiceInMemory( config );
w = WikittyServiceEnhanced.restore(wikittyService, null, id);
assertTrue( w.hasField(extName, "fieldName0") );
assertEquals( 123, w.getFieldAsInt(extName, "fieldName0") );
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/WikittyServiceNotificationTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -35,7 +35,7 @@
*/
@Test
public void testEvent() throws Exception {
- WikittyServiceNotifier wsn = new WikittyServiceNotifier(null);
+ WikittyServiceNotifier wsn = new WikittyServiceNotifier(null, null);
Listener l = new Listener();
// test d'envoi et de bonne reception
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/notification/XMPPNotificationTest.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -26,9 +26,7 @@
import java.util.Date;
-import java.util.HashSet;
import java.util.Properties;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jivesoftware.smack.PacketListener;
@@ -36,8 +34,8 @@
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;
-import org.jivesoftware.smackx.muc.RoomInfo;
import org.junit.Test;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyServiceEvent;
import org.nuiton.wikitty.XMPPNotifierTransporter;
@@ -58,13 +56,13 @@
public void testXMPP() throws Exception {
String server = "im.codelutin.com";
String room = "test(a)conference.im.codelutin.com";
- Properties props = new Properties();
- props.setProperty(XMPPNotifierTransporter.WIKITTY_XMPP_SERVER, server);
- props.setProperty(XMPPNotifierTransporter.WIKITTY_XMPP_ROOM, room);
+ WikittyConfig config = new WikittyConfig();
+ config.setOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_SERVER.getKey(), server);
+ config.setOption(WikittyConfig.Option.WIKITTY_EVENT_TRANSPORTER_XMPP_ROOM.getKey(), room);
// Envoi d'un message avec le transporter normal
- XMPPNotifierTransporter xmpp = new XMPPNotifierTransporter(null, props);
+ XMPPNotifierTransporter xmpp = new XMPPNotifierTransporter(config, null);
WikittyServiceEvent event = new WikittyServiceEvent("test");
event.addRemoveDate("theId", new Date());
Modified: trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml
===================================================================
--- trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-28 13:54:03 UTC (rev 455)
@@ -31,9 +31,12 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ <bean name="wikittyConfig" class="org.nuiton.wikitty.WikittyConfig"/>
+
+ <bean id="wikittyService" class="org.nuiton.wikitty.WikittyServiceInMemory">
+ <constructor-arg ref="wikittyConfig"/>
+ </bean>
- <bean id="wikittyService" class="org.nuiton.wikitty.WikittyServiceInMemory" />
-
<context:annotation-config/>
<context:component-scan base-package="org.nuiton.wikitty"/>
Modified: trunk/wikitty-api/src/test/resources/csv/importtree.csv
===================================================================
--- trunk/wikitty-api/src/test/resources/csv/importtree.csv 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-api/src/test/resources/csv/importtree.csv 2010-10-28 13:54:03 UTC (rev 455)
@@ -1,3 +1,3 @@
"Wikitty.Id","Wikitty.Ext","WikittyTreeNode.name","WikittyTreeNode.parent","WikittyTreeNode.attachment"
"4f6fc798-41f8-48d7-9398-119ef6ab02b6",,"MyRootNode",,
-"1142aa4c-af5a-4264-9918-9f72d9ef9d59","Tag","MyTreeNode","4f6fc798-41f8-48d7-9398-119ef6ab02b6","(fbcc8aed-7f67-4e3c-a9aa-221373765f8d),(677ee1e7-239f-416c-a353-6e56bc0451e2)"
+"1142aa4c-af5a-4264-9918-9f72d9ef9d59","Tag","MyTreeNode","4f6fc798-41f8-48d7-9398-119ef6ab02b6","(fbcc8aed-7f67-4e3c-a9aa-221373765f8d),(677ee1e7-239f-416c-a353-6e56bc0451e2_dont-exist)"
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -41,12 +41,6 @@
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.QUERY_SELECT_WHERE;
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.TABLE_EXTENSION_ADMIN;
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.TABLE_EXTENSION_DATA;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.commitJDBCConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.doQuery;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.getConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.getJDBCConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.loadProperties;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.rollbackJDBCConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -63,7 +57,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.FieldType;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyExtension;
import org.nuiton.wikitty.WikittyExtensionStorage;
@@ -85,7 +81,8 @@
static protected Log log = LogFactory.getLog(WikittyExtensionStorageJDBC.class);
/** Properties file */
- protected final Properties conf;
+ protected final Properties jdbcQuery;
+ protected ApplicationConfig config;
/** cache for extension key: ext id (extname[extversion]) value: WikittyExtension */
protected Map<String, WikittyExtension> extensionCache =
@@ -94,31 +91,33 @@
/** cache for last extension version; key: extName value: extVersion */
transient protected Map<String, String> lastVersion = null;
- public WikittyExtensionStorageJDBC() {
- this(null);
- }
+ // FIXME REMOVE IT
+// public WikittyExtensionStorageJDBC() {
+// this(null);
+// }
- public WikittyExtensionStorageJDBC(Properties properties) {
- conf = loadProperties(properties);
- Connection connectionTest = getJDBCConnection(conf);
+ public WikittyExtensionStorageJDBC(ApplicationConfig config) {
+ this.config = config;
+ jdbcQuery = WikittyJDBCUtil.loadQuery(config);
+ Connection connectionTest = WikittyJDBCUtil.getJDBCConnection(config);
try {
// If test of existance work, no exception and do nothing
// if exception try to create databse
Statement statementTest = connectionTest.createStatement();
- statementTest.execute(conf.getProperty(QUERY_CREATION_EXTENSION_ADMIN_TEST));
- statementTest.execute(conf.getProperty(QUERY_CREATION_EXTENSION_DATA_TEST));
+ statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_ADMIN_TEST));
+ statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA_TEST));
} catch(SQLException silentError) {
if (log.isInfoEnabled()) {
log.info("try to create extension database");
}
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
Statement statement = connection.createStatement();
- statement.execute(conf.getProperty(QUERY_CREATION_EXTENSION_ADMIN));
- statement.execute(conf.getProperty(QUERY_CREATION_EXTENSION_DATA));
- commitJDBCConnection(connection);
+ statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_ADMIN));
+ statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA));
+ WikittyJDBCUtil.commitJDBCConnection(connection);
} catch (SQLException eee) {
- rollbackJDBCConnection(connection);
+ WikittyJDBCUtil.rollbackJDBCConnection(connection);
throw new WikittyException("Can't create table for extension storage", eee);
} finally {
WikittyJDBCUtil.closeQuietly(connection);
@@ -133,13 +132,13 @@
Collection<WikittyExtension> extensions)
throws WikittyException {
WikittyServiceEvent result = new WikittyServiceEvent(this);
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
for (WikittyExtension ext : extensions) {
// extension id is extension name with version
String id = ext.getId();
//select all the data with the id "id"
- String query = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String query = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
COL_VERSION, TABLE_EXTENSION_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1, id);
@@ -148,7 +147,8 @@
//if the data is not already recorded
if (!versionResultSet.next()) {
result.addExtension(ext);
- doQuery(connection, conf.getProperty(QUERY_INSERT_EXTENSION_ADMIN),
+ WikittyJDBCUtil.doQuery(connection,
+ jdbcQuery.getProperty(QUERY_INSERT_EXTENSION_ADMIN),
ext.getId(),
ext.getName(),
ext.getVersion(),
@@ -156,7 +156,8 @@
WikittyUtil.tagValuesToString(ext.getTagValues()));
for (String fieldName : ext.getFieldNames()) {
FieldType type = ext.getFieldType(fieldName);
- doQuery(connection, conf.getProperty(QUERY_INSERT_EXTENSION_DATA),
+ WikittyJDBCUtil.doQuery(connection,
+ jdbcQuery.getProperty(QUERY_INSERT_EXTENSION_DATA),
ext.getId(), fieldName, type.toDefinition(fieldName));
}
} else {
@@ -180,10 +181,10 @@
@Override
public boolean exists(WikittyTransaction transaction, String id) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
//select the data with teh id "id" in the admin table
- String q = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
COL_ID, TABLE_EXTENSION_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(q);
statement.setString(1, id);
@@ -200,13 +201,13 @@
@Override
public List<String> getAllExtensionIds(WikittyTransaction transaction) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
List<String> result = new ArrayList<String>();
Statement statement = connection.createStatement();
//get all extensions names and versions
ResultSet resultSet = statement.executeQuery(
- String.format(conf.getProperty(QUERY_SELECT),
+ String.format(jdbcQuery.getProperty(QUERY_SELECT),
COL_ID, TABLE_EXTENSION_ADMIN));
while (resultSet.next()) {
@@ -224,10 +225,10 @@
@Override
public List<String> getAllExtensionsRequires(WikittyTransaction transaction,
String extensionName) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
List<String> result = new ArrayList<String>();
- String q = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
COL_ID, TABLE_EXTENSION_ADMIN, COL_REQUIRES);
PreparedStatement statement = connection.prepareStatement(q);
@@ -260,12 +261,12 @@
if (lastVersion == null) {
// create cache for futur call
Map<String, String> tmp = new HashMap<String, String>();
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
Statement statement = connection.createStatement();
//get all extensions names and versions
ResultSet resultSet = statement.executeQuery(
- String.format(conf.getProperty(QUERY_SELECT),
+ String.format(jdbcQuery.getProperty(QUERY_SELECT),
COL_NAME + "," + COL_VERSION, TABLE_EXTENSION_ADMIN));
while (resultSet.next()) {
String name = resultSet.getString(COL_NAME);
@@ -294,11 +295,11 @@
String id = WikittyExtension.computeId(name, version);
WikittyExtension result = extensionCache.get(id);
if (result == null) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
//get the data with the id "id" in the admin table
- String q = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
"*", TABLE_EXTENSION_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(q);
statement.setString(1, id);
@@ -312,7 +313,7 @@
new LinkedHashMap<String, FieldType>();
//get the data with the id "id" in the data table
- String qdata = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String qdata = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
"*", TABLE_EXTENSION_DATA, COL_ID);
PreparedStatement sta = connection.prepareStatement(qdata);
sta.setString(1, id);
@@ -349,10 +350,10 @@
@Override
public WikittyServiceEvent clear(WikittyTransaction transaction) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
lastVersion = null;
- doQuery(connection, conf.getProperty(QUERY_CLEAR_EXTENSION));
+ WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(QUERY_CLEAR_EXTENSION));
WikittyServiceEvent result = new WikittyServiceEvent(this);
result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION);
return result;
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -49,6 +49,8 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyException;
/**
@@ -145,16 +147,16 @@
static final public String QUERY_INSERT_EXTENSION_DATA =
"jdbc.queries.insert.extension.data";
- /** JDBC JDBC_DRIVER property name */
- static protected String JDBC_DRIVER = "jdbc.con.driver";
- /** JDBC_HOST property name */
- static protected String JDBC_HOST = "jdbc.con.host";
- /** JDBC_USER_NAME property name */
- static protected String JDBC_USER_NAME = "jdbc.con.userName";
- /** JDBC_PASSWORD property name */
- static protected String JDBC_PASSWORD = "jdbc.con.password";
- /** JDBC_XADATASOURCE property name */
- static protected String JDBC_XADATASOURCE = "jdbc.xadatasource";
+// /** JDBC JDBC_DRIVER property name */
+// static protected String JDBC_DRIVER = "jdbc.con.driver";
+// /** JDBC_HOST property name */
+// static protected String JDBC_HOST = "jdbc.con.host";
+// /** JDBC_USER_NAME property name */
+// static protected String JDBC_USER_NAME = "jdbc.con.userName";
+// /** JDBC_PASSWORD property name */
+// static protected String JDBC_PASSWORD = "jdbc.con.password";
+// /** JDBC_XADATASOURCE property name */
+// static protected String JDBC_XADATASOURCE = "jdbc.xadatasource";
/** admin table name */
static protected String TABLE_WIKITTY_ADMIN = "wikitty_admin";
@@ -172,20 +174,22 @@
* @param properties custom properties to override default configuration
* @return the properties for the connection and the queries
*/
- public static synchronized Properties loadProperties(Properties properties) {
- Properties queryConfig = new Properties();
- Properties databaseConfig = new Properties(queryConfig);
+ public static synchronized Properties loadQuery(ApplicationConfig config) {
+ Properties result = new Properties();
+// Properties databaseConfig = new Properties(queryConfig);
InputStream streamQuery = null;
- InputStream streamConfig = null;
+// InputStream streamConfig = null;
try {
// FIXME poussin 20100112 perhaps used nuitonutil.ApplicationConfig
-
+
+ String wikittyQueryFile = config.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_QUERY_FILE.getKey());
// queries
- URL url = ClassLoader.getSystemResource("wikitty-jdbc-query.properties");
+ URL url = ClassLoader.getSystemResource(wikittyQueryFile);
if (url == null) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- url = contextClassLoader.getResource("wikitty-jdbc-query.properties");
+ url = contextClassLoader.getResource(wikittyQueryFile);
}
if (log.isInfoEnabled()) {
@@ -193,42 +197,43 @@
}
// url can't be null
streamQuery = url.openStream();
- queryConfig.load(streamQuery);
-
- // config
- url = ClassLoader.getSystemResource("wikitty-jdbc-config.properties");
- if (url == null) {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- url = contextClassLoader.getResource("wikitty-jdbc-config.properties");
- }
+ result.load(streamQuery);
- if (url == null) {
- if (log.isInfoEnabled()) {
- log.info("No wikitty-jdbc-config.properties file found in classpath (skip default configuration loading)");
- }
- }
- else {
- if (log.isInfoEnabled()) {
- log.info("Reading resource from: " + url);
- }
- streamConfig = url.openStream();
- databaseConfig.load(streamConfig);
- }
-
- // extra config
- if (properties != null) {
- databaseConfig.putAll(properties);
- }
+ // FIXME REMOVE IT
+// // config
+// url = ClassLoader.getSystemResource("wikitty-jdbc-config.properties");
+// if (url == null) {
+// ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+// url = contextClassLoader.getResource("wikitty-jdbc-config.properties");
+// }
+//
+// if (url == null) {
+// if (log.isInfoEnabled()) {
+// log.info("No wikitty-jdbc-config.properties file found in classpath (skip default configuration loading)");
+// }
+// }
+// else {
+// if (log.isInfoEnabled()) {
+// log.info("Reading resource from: " + url);
+// }
+// streamConfig = url.openStream();
+// databaseConfig.load(streamConfig);
+// }
+//
+// // extra config
+// if (properties != null) {
+// databaseConfig.putAll(properties);
+// }
} catch (IOException eee) {
throw new WikittyException("Unable to load property file", eee);
}
finally {
IOUtils.closeQuietly(streamQuery);
- IOUtils.closeQuietly(streamConfig);
+// IOUtils.closeQuietly(streamConfig);
}
- return databaseConfig;
+ return result;
}
private static Map<String, BasicManagedDataSource> dataSources =
@@ -241,12 +246,23 @@
* @param conf configuration
* @return a new Connection (db transaction)
*/
- public static synchronized Connection getConnection(Properties conf) {
+ public static synchronized Connection getConnection(ApplicationConfig conf) {
+ String driver = conf.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_DRIVER.getKey());
+ String host = conf.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_URL.getKey());
+ String username = conf.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_LOGIN.getKey());
+ String password = conf.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_PASSWORD.getKey());
+
+ String xaDataSourceClassName = conf.getOption(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_XADATASOURCE.getKey());;
try {
- TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
+ TransactionManager transactionManager =
+ com.arjuna.ats.jta.TransactionManager.transactionManager();
- String jdbcUrl = String.format("%s:%s@%s", conf.getProperty(JDBC_USER_NAME),
- conf.getProperty(JDBC_PASSWORD), conf.getProperty(JDBC_HOST));
+ String jdbcUrl = String.format("%s:%s@%s", username, password, host);
if (!dataSources.containsKey(jdbcUrl)) {
log.info("Creating BasicManagedDataSource for: " + jdbcUrl);
@@ -255,7 +271,6 @@
BasicManagedDataSource dataSource = new BasicManagedDataSource();
// if xadatasource
- String xaDataSourceClassName = conf.getProperty(JDBC_XADATASOURCE);
if(xaDataSourceClassName != null) {
XADataSource xaDataSource = (XADataSource) Class.forName(xaDataSourceClassName).newInstance();
@@ -263,10 +278,14 @@
Set<String> fields = beanMap.keySet();
// Inject properties in xadatasource
- for(Entry<Object, Object> properties : conf.entrySet()) {
+ for(Entry<Object, Object> properties : conf.getFlatOptions().entrySet()) {
String propertyName = (String) properties.getKey();
- if (propertyName.startsWith(JDBC_XADATASOURCE + "." + xaDataSourceClassName + ".")) {
- propertyName = propertyName.replaceFirst(JDBC_XADATASOURCE + "." + xaDataSourceClassName + ".", "");
+ if (propertyName.startsWith(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_XADATASOURCE.getKey()
+ + "." + xaDataSourceClassName + ".")) {
+ propertyName = propertyName.replaceFirst(
+ WikittyConfig.Option.WIKITTY_STORAGE_JDBC_XADATASOURCE.getKey()
+ + "." + xaDataSourceClassName + ".", "");
if(fields.contains(propertyName)) {
String propertyValue = (String) properties.getValue();
BeanUtils.setProperty(xaDataSource, propertyName, propertyValue);
@@ -281,10 +300,10 @@
}
// else standard datasource
- dataSource.setDriverClassName(conf.getProperty(JDBC_DRIVER));
- dataSource.setUrl(conf.getProperty(JDBC_HOST));
- dataSource.setUsername(conf.getProperty(JDBC_USER_NAME));
- dataSource.setPassword(conf.getProperty(JDBC_PASSWORD));
+ dataSource.setDriverClassName(driver);
+ dataSource.setUrl(host);
+ dataSource.setUsername(username);
+ dataSource.setPassword(password);
dataSource.setTransactionManager(transactionManager);
dataSources.put(jdbcUrl, dataSource);
@@ -297,7 +316,7 @@
} catch(Exception eee) {
throw new WikittyException(String.format(
"Can't connect to database %s %s with login %s",
- JDBC_DRIVER, JDBC_HOST, JDBC_USER_NAME), eee);
+ driver, host, username), eee);
}
}
@@ -320,9 +339,9 @@
* @return a new Connection (db transaction)
* @throws SQLException if the connection fails
*/
- public static synchronized Connection getJDBCConnection(Properties conf) {
+ public static synchronized Connection getJDBCConnection(ApplicationConfig config) {
try {
- Connection connection = getConnection(conf);
+ Connection connection = getConnection(config);
connection.setAutoCommit(false);
return connection;
} catch(SQLException eee) {
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyServiceJDBC.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -25,9 +25,9 @@
package org.nuiton.wikitty.jdbc;
-import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.WikittyServiceImpl;
import org.nuiton.wikitty.solr.WikittySearchEnginSolr;
@@ -43,16 +43,17 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittyServiceJDBC.class);
- public WikittyServiceJDBC() {
- extensionStorage = new WikittyExtensionStorageJDBC();
- wikittyStorage = new WikittyStorageJDBC(extensionStorage);
- searchEngin = new WikittySearchEnginSolr(extensionStorage);
- }
+ // FIXME REMOVE IT
+// public WikittyServiceJDBC() {
+// extensionStorage = new WikittyExtensionStorageJDBC();
+// wikittyStorage = new WikittyStorageJDBC(extensionStorage);
+// searchEngin = new WikittySearchEnginSolr(extensionStorage);
+// }
- public WikittyServiceJDBC(Properties config) {
+ public WikittyServiceJDBC(ApplicationConfig config) {
extensionStorage = new WikittyExtensionStorageJDBC(config);
- wikittyStorage = new WikittyStorageJDBC(extensionStorage, config);
- searchEngin = new WikittySearchEnginSolr(extensionStorage);
+ wikittyStorage = new WikittyStorageJDBC(config, extensionStorage);
+ searchEngin = new WikittySearchEnginSolr(config, extensionStorage);
}
}
Modified: trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-jdbc-impl/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -49,12 +49,6 @@
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.QUERY_UPDATE_WIKITTY_ADMIN;
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.TABLE_WIKITTY_ADMIN;
import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.TABLE_WIKITTY_DATA;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.commitJDBCConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.doQuery;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.getConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.getJDBCConnection;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.loadProperties;
-import static org.nuiton.wikitty.jdbc.WikittyJDBCUtil.rollbackJDBCConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -76,6 +70,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.FieldType;
import org.nuiton.wikitty.Wikitty;
import org.nuiton.wikitty.WikittyException;
@@ -102,41 +97,44 @@
static protected Log log = LogFactory.getLog(WikittyStorageJDBC.class);
/** Properties file */
- protected final Properties conf;
+ protected final Properties jdbcQuery;
+ protected ApplicationConfig config;
/** used to parse list field from hbase data. ex: extension.fieldname[11/15] */
static final private Pattern listFieldPattern =
Pattern.compile("(.*)\\[(\\d+)/(\\d+)\\]");
protected WikittyExtensionStorage extensionStorage;
+
+ // FIXME REMOVE IT
+// public WikittyStorageJDBC(WikittyExtensionStorage extensionStorage) {
+// this(extensionStorage, null);
+// }
- public WikittyStorageJDBC(WikittyExtensionStorage extensionStorage) {
- this(extensionStorage, null);
- }
-
- public WikittyStorageJDBC(WikittyExtensionStorage extensionStorage, Properties properties) {
+ public WikittyStorageJDBC(ApplicationConfig config, WikittyExtensionStorage extensionStorage) {
+ this.config = config;
this.extensionStorage = extensionStorage;
- conf = loadProperties(properties);
- Connection connectionTest = getJDBCConnection(conf);
+ jdbcQuery = WikittyJDBCUtil.loadQuery(config);
+ Connection connectionTest = WikittyJDBCUtil.getJDBCConnection(config);
try {
// If test of existance work, no exception and do nothing
// if exception try to create databse
Statement statementTest = connectionTest.createStatement();
- statementTest.execute(conf.getProperty(QUERY_CREATION_WIKITTY_ADMIN_TEST));
- statementTest.execute(conf.getProperty(QUERY_CREATION_WIKITTY_DATA_TEST));
+ statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_ADMIN_TEST));
+ statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA_TEST));
} catch (SQLException silentError) {
if (log.isInfoEnabled()) {
log.info("try to create wikitty database");
}
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
Statement statement = connection.createStatement();
- statement.execute(conf.getProperty(QUERY_CREATION_WIKITTY_ADMIN));
- statement.execute(conf.getProperty(QUERY_CREATION_WIKITTY_DATA));
- commitJDBCConnection(connection);
+ statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_ADMIN));
+ statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA));
+ WikittyJDBCUtil.commitJDBCConnection(connection);
} catch (SQLException eee) {
- rollbackJDBCConnection(connection);
+ WikittyJDBCUtil.rollbackJDBCConnection(connection);
throw new WikittyException("Can't create table for wikitty storage", eee);
} finally {
WikittyJDBCUtil.closeQuietly(connection);
@@ -170,11 +168,11 @@
@Override
public WikittyServiceEvent store(WikittyTransaction transaction,
Collection<Wikitty> wikitties, boolean force) throws WikittyException {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
WikittyServiceEvent result = new WikittyServiceEvent(this);
for (Wikitty wikitty : wikitties) {
- String query = String.format(conf.getProperty(QUERY_SELECT_TWO_WHERE),
+ String query = String.format(jdbcQuery.getProperty(QUERY_SELECT_TWO_WHERE),
COL_VERSION, COL_DELETION_DATE, TABLE_WIKITTY_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1, wikitty.getId());
@@ -227,10 +225,14 @@
}
if (wikittyAlreadyExists) {
- doQuery(connection, conf.getProperty(QUERY_DELETE_WIKITTY_DATA), wikitty.getId());
+ WikittyJDBCUtil.doQuery(connection,
+ jdbcQuery.getProperty(QUERY_DELETE_WIKITTY_DATA),
+ wikitty.getId());
}
else {
- doQuery(connection, conf.getProperty(QUERY_INSERT_WIKITTY_ADMIN), wikitty.getId(), newVersion, "");
+ WikittyJDBCUtil.doQuery(connection,
+ jdbcQuery.getProperty(QUERY_INSERT_WIKITTY_ADMIN),
+ wikitty.getId(), newVersion, "");
}
@@ -245,8 +247,9 @@
for (int i = 0; i < list.size(); i++) {
Object value = list.get(i);
String colName = getColName(type.getType());
- String q = String.format(conf.getProperty(QUERY_INSERT_WIKITTY_DATA), colName);
- doQuery(connection, q,
+ String q = String.format(jdbcQuery.getProperty(
+ QUERY_INSERT_WIKITTY_DATA), colName);
+ WikittyJDBCUtil.doQuery(connection, q,
wikitty.getId(),
ext.getName() + "." + fieldName + "[" + i + "/" + list.size() + "]",
value);
@@ -262,14 +265,16 @@
Object value = wikitty.getFieldAsObject(ext.getName(), fieldName);
if (value != null) {
String colName = getColName(type.getType());
- String q = String.format(conf.getProperty(QUERY_INSERT_WIKITTY_DATA), colName);
- doQuery(connection, q,
+ String q = String.format(jdbcQuery.getProperty(
+ QUERY_INSERT_WIKITTY_DATA), colName);
+ WikittyJDBCUtil.doQuery(connection, q,
wikitty.getId(),
ext.getName() + "." + fieldName,
value);
} else {
if (type.isNotNull()) {
- throw new WikittyException(String.format("Field %s in extension %s can't be null",
+ throw new WikittyException(String.format(
+ "Field %s in extension %s can't be null",
fieldName, ext.getName()));
}
}
@@ -283,8 +288,9 @@
}
// update extensions in wikitty object
- String q = conf.getProperty(QUERY_UPDATE_WIKITTY_ADMIN);
- doQuery(connection, q, newVersion, extensionList, null, wikitty.getId());
+ String q = jdbcQuery.getProperty(QUERY_UPDATE_WIKITTY_ADMIN);
+ WikittyJDBCUtil.doQuery(connection, q, newVersion, extensionList,
+ null, wikitty.getId());
wikitty.setVersion(newVersion);
wikitty.clearDirty();
@@ -301,10 +307,10 @@
@Override
public boolean exists(WikittyTransaction transaction, String id) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
//select the data with the id "id" in the admin table
- String q = String.format(conf.getProperty(QUERY_SELECT_WHERE), COL_ID,
+ String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE), COL_ID,
TABLE_WIKITTY_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(q);
statement.setString(1, id);
@@ -321,10 +327,10 @@
@Override
public boolean isDeleted(WikittyTransaction transaction, String id) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
//select the data with the id "id" in the admin table
- String q = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
COL_DELETION_DATE, TABLE_WIKITTY_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(q);
statement.setString(1, id);
@@ -347,10 +353,10 @@
@Override
public Wikitty restore(WikittyTransaction transaction,
String id, String... fqFieldName) throws WikittyException {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
//select the data with the id "id" in the admin table
- String q = String.format(conf.getProperty(
+ String q = String.format(jdbcQuery.getProperty(
QUERY_SELECT_WHERE_NOTDELETED), "*", TABLE_WIKITTY_ADMIN, COL_ID);
PreparedStatement statement = connection.prepareStatement(q);
statement.setString(1, id);
@@ -360,7 +366,7 @@
String version = adminResultSet.getString(COL_VERSION);
String extensionList = adminResultSet.getString(COL_EXTENSION);
//select the data with the id "id" in the data table
- String qdata = String.format(conf.getProperty(QUERY_SELECT_WHERE),
+ String qdata = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
"*", TABLE_WIKITTY_DATA, COL_ID);
PreparedStatement sta = connection.prepareStatement(qdata);
sta.setString(1, id);
@@ -383,7 +389,7 @@
@Override
public WikittyServiceEvent delete(WikittyTransaction transaction, Collection<String> ids) throws WikittyException {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
WikittyServiceEvent result = new WikittyServiceEvent(this);
Date now = new Date();
@@ -399,7 +405,8 @@
"Wikitty with id '%s' is already deleted", id));
}
// addVersionUpdate delete date field
- doQuery(connection, conf.getProperty(QUERY_DELETE_WIKITTY_ADMIN), id);
+ WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(
+ QUERY_DELETE_WIKITTY_ADMIN), id);
result.addRemoveDate(id, now);
}
@@ -414,14 +421,14 @@
@Override
public void scanWikitties(WikittyTransaction transaction, Scanner scanner) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
Statement statement = connection.createStatement();
// get all wikitties
// fails with QUERY_SELECT
ResultSet resultSet = statement.executeQuery(
- String.format(conf.getProperty(QUERY_SELECT_NOTDELETED),
+ String.format(jdbcQuery.getProperty(QUERY_SELECT_NOTDELETED),
COL_ID, TABLE_WIKITTY_ADMIN));
while (resultSet.next()) {
@@ -558,9 +565,9 @@
@Override
public WikittyServiceEvent clear(WikittyTransaction transaction) {
- Connection connection = getConnection(conf);
+ Connection connection = WikittyJDBCUtil.getConnection(config);
try {
- doQuery(connection, conf.getProperty(QUERY_CLEAR_WIKITTY));
+ WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(QUERY_CLEAR_WIKITTY));
WikittyServiceEvent result = new WikittyServiceEvent(this);
result.addType(WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY);
return result;
Modified: trunk/wikitty-jdbc-impl/src/test/resources/META-INF/spring/wikitty-test.xml
===================================================================
--- trunk/wikitty-jdbc-impl/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-jdbc-impl/src/test/resources/META-INF/spring/wikitty-test.xml 2010-10-28 13:54:03 UTC (rev 455)
@@ -31,8 +31,12 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <bean name="wikittyService" class="org.nuiton.wikitty.jdbc.WikittyServiceJDBC"/>
+ <bean name="wikittyConfig" class="org.nuiton.wikitty.WikittyConfig"/>
+ <bean name="wikittyService" class="org.nuiton.wikitty.jdbc.WikittyServiceJDBC">
+ <constructor-arg ref="wikittyConfig"/>
+ </bean>
+
<context:annotation-config/>
<context:component-scan base-package="org.nuiton.wikitty"/>
Modified: trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-solr-impl/src/main/java/org/nuiton/wikitty/solr/WikittySearchEnginSolr.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -33,7 +33,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -70,6 +69,8 @@
import com.arjuna.ats.arjuna.state.OutputObjectState;
import com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord;
import java.io.File;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
/**
*
@@ -84,7 +85,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(WikittySearchEnginSolr.class);
- /** Solr data dir config option name. */
+ /** Solr data dir, this name are used directly by SolR, don't change it. */
static final protected String SOLR_DATA_DIR_CONFIG = "solr.data.dir";
/** id field in solr */
@@ -477,14 +478,15 @@
/** JTA resource */
protected SolrResource solrResource;
- /**
- * Init wikitty search engin on solr embedded server.
- *
- * @param extensionStorage extension storage
- */
- public WikittySearchEnginSolr(WikittyExtensionStorage extensionStorage) {
- this(extensionStorage, null);
- }
+ // FIXME REMOVE IT
+// /**
+// * Init wikitty search engin on solr embedded server.
+// *
+// * @param extensionStorage extension storage
+// */
+// public WikittySearchEnginSolr(WikittyExtensionStorage extensionStorage) {
+// this(extensionStorage, null);
+// }
/**
* Init wikitty search engin on solr embedded server.
@@ -492,11 +494,13 @@
* @param extensionStorage extension storage
* @param properties properties (can be null)
*/
- public WikittySearchEnginSolr(WikittyExtensionStorage extensionStorage, Properties properties) {
+ public WikittySearchEnginSolr(
+ ApplicationConfig config, WikittyExtensionStorage extensionStorage) {
// init system env solr.data.dir
- if (properties != null) {
- String solrDataDir = properties.getProperty(SOLR_DATA_DIR_CONFIG);
+ if (config != null) {
+ String solrDataDir = config.getOption(
+ WikittyConfig.Option.WIKITTY_SEARCHENGINE_SOLR_DIRECTORY_DATA.getKey());
// make sure that dir exists
if (solrDataDir != null) {
File file = new File(solrDataDir);
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/AbstractTestSolr.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -25,12 +25,13 @@
package org.nuiton.wikitty.solr.test;
import org.junit.Before;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyServiceEnhanced;
public abstract class AbstractTestSolr {
protected WikittyServiceEnhanced ws =
- new WikittyServiceEnhanced(new WikittyServiceSolr());
+ new WikittyServiceEnhanced(new WikittyServiceSolr(new WikittyConfig()));
@Before
public void deleteAll() throws Exception {
Modified: trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java
===================================================================
--- trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-solr-impl/src/test/java/org/nuiton/wikitty/solr/test/WikittyServiceSolr.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -25,6 +25,7 @@
package org.nuiton.wikitty.solr.test;
+import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.WikittyServiceImpl;
import org.nuiton.wikitty.WikittyServiceInMemory;
import org.nuiton.wikitty.solr.WikittySearchEnginSolr;
@@ -39,9 +40,9 @@
*/
public class WikittyServiceSolr extends WikittyServiceImpl {
- public WikittyServiceSolr() {
+ public WikittyServiceSolr(ApplicationConfig config) {
extensionStorage = new WikittyServiceInMemory.WikittyExtensionStorageInMemory();
wikittyStorage = new WikittyServiceInMemory.WikittyStorageInMemory();
- searchEngin = new WikittySearchEnginSolr(extensionStorage);
+ searchEngin = new WikittySearchEnginSolr(config, extensionStorage);
}
}
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -38,6 +38,7 @@
import org.apache.commons.lang.UnhandledException;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
+import org.nuiton.wikitty.WikittyConfig;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyServiceCached;
@@ -245,8 +246,9 @@
protected WikittyProxy createLocalProxy(Properties properties, String login, String password) {
WikittyProxy proxy = new WikittyProxy();
try {
- WikittyService ws = new WikittyServiceJDBC(properties);
- ws = new WikittyServiceCached(ws);
+ WikittyConfig config = new WikittyConfig(properties);
+ WikittyService ws = new WikittyServiceJDBC(config);
+ ws = new WikittyServiceCached(config, ws);
proxy.setWikittyService(ws);
} catch (Exception eee) {
return null;
Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyZkService.java
===================================================================
--- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyZkService.java 2010-10-27 09:06:35 UTC (rev 454)
+++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyZkService.java 2010-10-28 13:54:03 UTC (rev 455)
@@ -34,7 +34,7 @@
public WikittyZkService() throws IOException {
WikittyZkConfig config = WikittyZkConfig.getInstance();
- instance = new WikittyServiceJDBC(config.getFlatOptions());
+ instance = new WikittyServiceJDBC(config);
}
public WikittyService getWikittyService() {
1
0