Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 1653 discussions
r826 - trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc
by bpoussin@users.nuiton.org 20 Apr '11
by bpoussin@users.nuiton.org 20 Apr '11
20 Apr '11
Author: bpoussin
Date: 2011-04-20 23:42:24 +0200 (Wed, 20 Apr 2011)
New Revision: 826
Url: http://nuiton.org/repositories/revision/wikitty/826
Log:
si on sauve avec une nouvelle extension sans modifier son numero de version, cela plantait :(
maintenant, on a seulement un message d'erreur dans les logs
Modified:
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-20 21:01:17 UTC (rev 825)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-20 21:42:24 UTC (rev 826)
@@ -511,7 +511,16 @@
while (resultSet.next()) {
// fqfieldName fully qualified fieldName (extention.fieldname)
String fqfieldName = resultSet.getString(COL_FIELDNAME);
- if (isAcceptedField(acceptedField, fqfieldName)) {
+ // si le champs est dans la base sur l'objet mais non declarer sur
+ // l'extension, on ne charge pas ce champs (ceci arrive si, quelqu'un
+ // a modifier une extension, sans modifier sa version :(
+ if (!result.hasField(fqfieldName)) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Stored field not found in this"
+ + " extension version, perhaps you have change"
+ + " extension without change version", fqfieldName));
+ }
+ } else if (isAcceptedField(acceptedField, fqfieldName)) {
FieldType type = result.getFieldType(fqfieldName);
Object value = null;
switch (type.getType()) {
1
0
r825 - in trunk/wikitty-api/src/main/java/org/nuiton/wikitty: . entities services
by bpoussin@users.nuiton.org 20 Apr '11
by bpoussin@users.nuiton.org 20 Apr '11
20 Apr '11
Author: bpoussin
Date: 2011-04-20 23:01:17 +0200 (Wed, 20 Apr 2011)
New Revision: 825
Url: http://nuiton.org/repositories/revision/wikitty/825
Log:
- prise en charge de parametre null dans diffentes methods
- ajout de la methode store avec varargs
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.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/WikittyImpl.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -46,7 +46,6 @@
import org.nuiton.wikitty.services.WikittyServiceEnhanced;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -219,7 +218,27 @@
return w;
}
+ // TODO poussin 20110420 je ne sais pas comment creer un tableau de E pour
+ // le retouner. Donc je retourne la liste au lieu d'un toArray sur celle-ci
+ public <E extends BusinessEntity> List<E> store(E e1, E e2, E... eN) {
+ List<E> es = new ArrayList<E>(eN.length + 2);
+ Collections.addAll(es, e1, e2);
+ Collections.addAll(es, eN);
+ List<E> result = store(es);
+ return result;
+ }
+
+ public Wikitty[] store(Wikitty w1, Wikitty w2, Wikitty... wN) {
+ List<Wikitty> ws = new ArrayList<Wikitty>(wN.length + 2);
+ Collections.addAll(ws, w1, w2);
+ Collections.addAll(ws, wN);
+
+ List<Wikitty> resultList = storeWikitty(ws);
+ Wikitty[] result = resultList.toArray(new Wikitty[resultList.size()]);
+ return result;
+ }
+
/**
* Store to WikittyService objects.
*
@@ -232,8 +251,12 @@
// prepare data to send to service
List<Wikitty> wikitties = new ArrayList<Wikitty>(objets.size());
for (E e : objets) {
- Wikitty w = ((BusinessEntityImpl)e).getWikitty();
- wikitties.add(w);
+ if (e == null) {
+ wikitties.add(null);
+ } else {
+ Wikitty w = ((BusinessEntityImpl)e).getWikitty();
+ wikitties.add(w);
+ }
}
// call the service with Wikitty
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/Wikitty.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -102,6 +102,8 @@
boolean hasField(String extName, String fieldName);
+ boolean hasField(String fqfieldName);
+
WikittyExtension getExtension(String ext);
Collection<String> getExtensionNames();
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyCopyOnWrite.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -197,6 +197,11 @@
}
@Override
+ public boolean hasField(String fqfieldName) {
+ return target.hasField(fqfieldName);
+ }
+
+ @Override
public WikittyExtension getExtension(String ext) {
return target.getExtension(ext);
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/WikittyImpl.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -365,6 +365,15 @@
return result;
}
+ @Override
+ public boolean hasField(String fqfieldName) {
+ String extName = WikittyExtension.extractExtensionName(fqfieldName);
+ String fieldName = WikittyExtension.extractFieldName(fqfieldName);
+
+ boolean result = hasField(extName, fieldName);
+ return result;
+ }
+
/*
* @see org.nuiton.wikitty.Wikitty#getExtension(java.lang.String)
*/
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyEvent.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -268,23 +268,25 @@
* @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);
- // can be null if wikitty is already saved (uptodate), then this wikitty is not re-saved
- if (newWikitty != null) {
- e.replaceWith(newWikitty);
+ if (e != null) {
+ // 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);
+ // can be null if wikitty is already saved (uptodate), then this wikitty is not re-saved
+ if (newWikitty != null) {
+ e.replaceWith(newWikitty);
+ }
}
+ if (type.contains(WikittyEventType.REMOVE_WIKITTY)) {
+ Date date = getRemoveDate().get(id);
+ e.setDeleteDate(date);
+ }
+ e.clearDirty();
}
- if (type.contains(WikittyEventType.REMOVE_WIKITTY)) {
- Date date = getRemoveDate().get(id);
- e.setDeleteDate(date);
- }
- e.clearDirty();
}
return e;
}
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceSecurity.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -218,7 +218,9 @@
protected void checkStore(String securityToken, Collection<Wikitty> wikitties) {
String userId = getUserId(securityToken);
for (Wikitty wikitty : wikitties) {
-
+ if (wikitty == null) {
+ continue;
+ }
// usual case, a user want to store a wikitty
Wikitty oldVersion = WikittyServiceEnhanced.restore(
getDelegate(), securityToken, wikitty.getId());
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2011-04-20 15:50:20 UTC (rev 824)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2011-04-20 21:01:17 UTC (rev 825)
@@ -175,6 +175,9 @@
// use all time Set to prevent duplicated wikitty in collection
wikitties = new LinkedHashSet<Wikitty>(wikitties);
}
+ // suppress null wikitty
+ wikitties.remove(null);
+
checkConstraint(wikitties);
// update/store extension if necessary
@@ -774,9 +777,13 @@
List<PagedResult<String>> result =
new ArrayList<PagedResult<String>>(criteria.size());
for (Criteria c : criteria) {
- PagedResult<String> searchResult =
- getSearchEngine().findAllByCriteria(tx, c);
- result.add(searchResult);
+ if (c == null) {
+ result.add(null);
+ } else {
+ PagedResult<String> searchResult =
+ getSearchEngine().findAllByCriteria(tx, c);
+ result.add(searchResult);
+ }
}
if (txBeginHere) {
1
0
r824 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 20 Apr '11
by mfortun@users.nuiton.org 20 Apr '11
20 Apr '11
Author: mfortun
Date: 2011-04-20 17:50:20 +0200 (Wed, 20 Apr 2011)
New Revision: 824
Url: http://nuiton.org/repositories/revision/wikitty/824
Log:
* change how determine mimetype for a file, add a class to do that
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java 2011-04-20 15:50:20 UTC (rev 824)
@@ -0,0 +1,72 @@
+package org.nuiton.wikitty.publication.synchro;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Class used to determine mimetype for an extension, used to determine type of
+ * wikittypub (data or text) with the extension and the mime type
+ *
+ *
+ * @author mfortun
+ *
+ */
+public class MimeTypePubHelper {
+
+ protected Map<String, String> mapExtensionMime;
+ protected List<String> mimePubText;
+ public static String DEFAULT_MIME_TYPE = "application/octet-stream";
+
+ public MimeTypePubHelper() {
+ this.mapExtensionMime = new HashMap<String, String>();
+ this.mimePubText = new ArrayList<String>();
+
+ // TODO create a property file to store and handle mimetype for pub
+ // text
+ mimePubText.add("application/javascript");
+
+ mapExtensionMime.put("wp", "application/javascript");
+ mapExtensionMime.put("jpg", "image/jpeg");
+ mapExtensionMime.put("png", "image/png");
+ }
+
+ public Map<String, String> getMapExtensionMime() {
+ return mapExtensionMime;
+ }
+
+ public void setMapExtensionMime(Map<String, String> mapExtensionMime) {
+ this.mapExtensionMime = mapExtensionMime;
+ }
+
+ public List<String> getMimePubText() {
+ return mimePubText;
+ }
+
+ public void setMimePubText(List<String> mimePubText) {
+ this.mimePubText = mimePubText;
+ }
+
+ public String getMimeForExtension(String ext) {
+ String result = mapExtensionMime.get(ext);
+
+ if (result == null) {
+ result = DEFAULT_MIME_TYPE;
+ }
+
+ return result;
+ }
+
+ public boolean isPubTextMime(String mimeType) {
+ return mimePubText.contains(mimeType);
+ }
+
+ public void addMimeForPubText(String mime) {
+ mimePubText.add(mime);
+ }
+
+ public void addExtensionMime(String extension, String mime) {
+ mapExtensionMime.put(extension, mime);
+ }
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/MimeTypePubHelper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 14:45:47 UTC (rev 823)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 15:50:20 UTC (rev 824)
@@ -42,7 +42,6 @@
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.activation.MimetypesFileTypeMap;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
@@ -100,7 +99,7 @@
protected File homeFile;
protected boolean recursion;
protected String label;
- protected List<String> pubTextMimeType;
+
static public String META_CURRENT_LABEL = "current.label";
@@ -126,6 +125,8 @@
static public String PROPERTY_DIRECTORY = ".wp";
+
+ protected MimeTypePubHelper mimeHelper;
/**
* Constructor with the working directory
*
@@ -140,11 +141,8 @@
*/
try {
- this.pubTextMimeType = new ArrayList<String>();
+ this.mimeHelper = new MimeTypePubHelper();
- // TODO create a property file to store and handle mimetype for pub
- // text
- pubTextMimeType.add("application/javascript");
String url = app.getOption(WikittyPublication.WIKITTY_OPTION_URL);
URI uri = new URI(url);
@@ -332,7 +330,7 @@
File wikittyFile = null;
if (w.hasExtension(WikittyPubData.EXT_WIKITTYPUBDATA)) {
name = WikittyPubDataHelper.getName(w);
- String mime = WikittyPubDataHelper.getMimeType(w);
+ // String mime = WikittyPubDataHelper.getMimeType(w);
byte[] content = WikittyPubDataHelper.getContent(w);
extension = WikittyPubDataHelper.getFileExtension(w);
@@ -347,7 +345,7 @@
} else if (w
.hasExtension(WikittyPubText.EXT_WIKITTYPUBTEXT)) {
name = WikittyPubTextHelper.getName(w);
- String mime = WikittyPubTextHelper.getMimeType(w);
+ //String mime = WikittyPubTextHelper.getMimeType(w);
String content = WikittyPubTextHelper.getContent(w);
extension = WikittyPubTextHelper.getFileExtension(w);
@@ -1056,15 +1054,7 @@
}
- /**
- * return if the mime type is associate to a wikittypubtext
- *
- * @param mime
- * @return
- */
- public boolean isMimeWikittyPubText(String mime) {
- return pubTextMimeType.contains(mime);
- }
+
/**
* Method that create a list of the properties directory
@@ -1174,9 +1164,9 @@
String extension = FileUtil.extension(fileToTransform);
String name = FileUtil.basename(completeName, "." + extension);
- MimetypesFileTypeMap mapMime = new MimetypesFileTypeMap();
+
// search for the mimetype
- String mimeType = mapMime.getContentType(fileToTransform);
+ String mimeType = mimeHelper.getMimeForExtension(extension);
// load properties
File wikittyParentDir = new File(path);
@@ -1188,7 +1178,7 @@
.getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL));
// create the correct wikittypubxxx
- if (isMimeWikittyPubText(mimeType)) {
+ if (mimeHelper.isPubTextMime(mimeType)) {
result.addExtension(WikittyPubTextImpl.extensionWikittyPubText);
WikittyPubTextHelper.setName(result, name);
WikittyPubTextHelper.setMimeType(result, mimeType);
@@ -1217,11 +1207,7 @@
File propertyFile = new File(starts + File.separator
+ PROPERTY_DIRECTORY);
-
- // TODO mfortun-2011-04-18 have to work on labels
- // actually starts + label have to be the same.
- // first starts and label.
-
+
if (!propertyFile.exists() || !propertyFile.isDirectory()) {
propertyFile.mkdir();
1
0
r823 - in trunk/wikitty-publication/src/main: java/org/nuiton/wikitty/publication/synchro resources
by mfortun@users.nuiton.org 20 Apr '11
by mfortun@users.nuiton.org 20 Apr '11
20 Apr '11
Author: mfortun
Date: 2011-04-20 16:45:47 +0200 (Wed, 20 Apr 2011)
New Revision: 823
Url: http://nuiton.org/repositories/revision/wikitty/823
Log:
* javadoc
* change of property file due to testing
* add a method that check if there was a modification in a file and increment the minor version of the wikitty
* correct a bug with label/directory there was a mismatch.
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties
trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 12:22:19 UTC (rev 822)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 14:45:47 UTC (rev 823)
@@ -46,11 +46,9 @@
/**
* Main class of the sync part of wikitty publication, this class is the entry
- * point for sync operation : import, checkout, commit, delete, relocate and
- * update.
+ * point for sync operation. Existing, delete and update.
*
*
- *
* @author mfortun
*
*/
@@ -59,18 +57,29 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
final static private Log log = LogFactory.getLog(WikittyPublication.class);
+ /**
+ * option for the url of a wikitty service
+ */
static public String WIKITTY_OPTION_URL = "wikitty.service.server.url";
+ /**
+ * option for the component class use to interract with the wikittyService
+ */
static public String WIKITTY_OPTION_COMPONENT = "wikitty.WikittyService.components";
static protected ApplicationConfig applicationConfig;
- /*
- * static string for allias, wrong named attribut TODO mfortun-2011-04-06
- * need to set better name
+
+ /**
+ * for recursion option
*/
-
static public String IS_RECURSION_OPTION = "isRecur";
+ /**
+ * for delete option
+ */
static public String IS_DELETE_OPTION = "delete";
+ /**
+ * for existing option
+ */
static public String IS_EXISTING_OPTION = "existing";
static public String LABEL_KEY = "working.label";
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 12:22:19 UTC (rev 822)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 14:45:47 UTC (rev 823)
@@ -42,10 +42,7 @@
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-import javax.activation.MimeType;
import javax.activation.MimetypesFileTypeMap;
-
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
@@ -55,8 +52,6 @@
import org.nuiton.util.FileUtil;
import org.nuiton.util.MD5InputStream;
import org.nuiton.util.StringUtil;
-import org.nuiton.wikitty.WikittyConfig;
-import org.nuiton.wikitty.WikittyConfigOption;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyUtil;
@@ -74,9 +69,7 @@
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl;
import org.nuiton.wikitty.search.Criteria;
-
import org.nuiton.wikitty.search.PagedResult;
-
import org.nuiton.wikitty.search.TreeNodeResult;
import org.nuiton.wikitty.search.operators.And;
import org.nuiton.wikitty.search.operators.AssociatedRestriction;
@@ -147,19 +140,15 @@
*/
try {
-
this.pubTextMimeType = new ArrayList<String>();
-
- //TODO create a property file to store and handle mimetype for pub text
+
+ // TODO create a property file to store and handle mimetype for pub
+ // text
pubTextMimeType.add("application/javascript");
-
-
-
+
String url = app.getOption(WikittyPublication.WIKITTY_OPTION_URL);
URI uri = new URI(url);
- this.label = uri.getFragment();
-
this.homeFile = new File(uri.getPath());
if (homeFile == null || !homeFile.exists()) {
@@ -167,6 +156,12 @@
homeFile = new File(cur.getAbsolutePath());
}
+ this.label = uri.getFragment();
+
+ if (label == null) {
+ label = homeFile.getName();
+ }
+
this.recursion = app
.getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION);
@@ -379,7 +374,8 @@
metaProperties.store();
// write common properties
- writeWikittyFileProperties(wikittyFile, w.getId());
+ writeWikittyFileProperties(wikittyFile, w.getId(),
+ w.getVersion());
}
}
}
@@ -676,7 +672,6 @@
checked = ((String) o).endsWith((String) value);
break;
case STARTS_WITH:
- System.out.println(t.isCollection());
if (t.getType() != TYPE.STRING) {
throw new WikittyException(
"Can't search for contents that 'starts with' on attribute type different of String. "
@@ -933,7 +928,12 @@
List<Criteria> criteria) {
Map<String, Wikitty> wikitties = new HashMap<String, Wikitty>();
try {
- harvestNew(homeFile, label);
+ String labelToDir = this.labelToPath(label);
+ File starts = new File (homeFile.getAbsolutePath()+File.separator+labelToDir);
+ if (starts.exists()){
+ harvestNewCheckModifications(starts, label);
+ }
+
BidiMap map = harvestLocalWikitties(homeFile, true);
for (Object o : map.keySet()) {
@@ -945,7 +945,7 @@
}
} catch (Exception e) {
- // TODO Auto-generated catch block
+ // TODO mfortun-2011-04-20 really handle exception
e.printStackTrace();
}
@@ -1056,10 +1056,6 @@
}
-
-
-
-
/**
* return if the mime type is associate to a wikittypubtext
*
@@ -1177,8 +1173,8 @@
String extension = FileUtil.extension(fileToTransform);
String name = FileUtil.basename(completeName, "." + extension);
-
- MimetypesFileTypeMap mapMime= new MimetypesFileTypeMap();
+
+ MimetypesFileTypeMap mapMime = new MimetypesFileTypeMap();
// search for the mimetype
String mimeType = mapMime.getContentType(fileToTransform);
@@ -1216,7 +1212,8 @@
return result;
}
- protected void harvestNew(File starts, String label) throws Exception {
+ protected void harvestNewCheckModifications(File starts, String label)
+ throws Exception {
File propertyFile = new File(starts + File.separator
+ PROPERTY_DIRECTORY);
@@ -1240,27 +1237,79 @@
for (File child : starts.listFiles()) {
if (child.isDirectory()
&& !child.getName().equals(PROPERTY_DIRECTORY)) {
- harvestNew(child,
- label + WIKITTYLABEL_SEPARATOR + child.getName());
+ harvestNewCheckModifications(child, label
+ + WIKITTYLABEL_SEPARATOR + child.getName());
} else if (!child.isDirectory()) {
+ // check if file is a wikitty by check if they is a id/file name
+ // in the correct properties file
List<String> filesWikitty = new ArrayList<String>();
filesWikitty.addAll(CollectionUtil.toGenericCollection(
ids.values(), String.class));
// if file is not a wikitty create it.
if (!filesWikitty.contains(child.getName())) {
- writeWikittyFileProperties(child, null);
+ writeWikittyFileProperties(child, null, null);
+ } else {
+ checkModifications(child);
}
}
}
}
- protected void writeWikittyFileProperties(File towrite, String wikittyID)
- throws Exception {
+ protected void checkModifications(File child) throws Exception {
+ // will check if there was modification with checksum
+ BufferedInputStream input = new BufferedInputStream(
+ new FileInputStream(child));
+
+ byte[] byt = MD5InputStream.hash(input);
+
+ String localMd5 = StringUtil.asHex(byt);
+
+ PropertiesExtended meta = getWikittyPublicationProperties(
+ child.getParentFile(), WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ String registeredMD5 = meta.getProperty(META_PREFIX_KEY_CHECKSUM
+ + child.getName());
+ // compare the different checksum
+ if (!localMd5.equals(registeredMD5)) {
+ // increment version and set new checksum
+ String currentVersion = meta.getProperty(META_PREFIX_KEY_VERSION
+ + child.getName());
+ meta.setProperty(META_PREFIX_KEY_VERSION + child.getName(),
+ WikittyUtil.incrementMinorRevision(currentVersion));
+ meta.setProperty(META_PREFIX_KEY_CHECKSUM + child.getName(),
+ localMd5);
+ }
+ meta.store();
+ }
+
+ /**
+ * write in properties file property about the file corresponding to a
+ * wikitty. If the file does not match a wikitty yet set wikittyID and
+ * Wikittyversion to null
+ *
+ * @param towrite
+ * the file
+ * @param wikittyID
+ * wiitty id, null if wikitty does not exist yet
+ * @param wikittyVersion
+ * wikitty version, null if wikitty not exist yet
+ * @throws Exception
+ */
+ protected void writeWikittyFileProperties(File towrite, String wikittyID,
+ String wikittyVersion) throws Exception {
+
if (towrite.exists() && !towrite.isDirectory()) {
Wikitty wikitty = new WikittyImpl(wikittyID);
+ if (wikittyVersion != null) {
+ wikitty.setVersion(wikittyVersion);
+ } else {
+ // simulate operations en wikitty if new
+ wikitty.setVersion(WikittyUtil.incrementMinorRevision(wikitty
+ .getVersion()));
+ }
File parent = towrite.getParentFile();
@@ -1324,4 +1373,17 @@
return result;
}
+
+ public String labelToPath (String label){
+ String result = label;
+
+ result = result.replace(".", File.separator);
+
+ // correct the pb with directory name begin by .
+ result = result.replace(File.separator + File.separator,
+ File.separator + ".");
+
+ return result;
+ }
+
}
Modified: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties
===================================================================
--- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties 2011-04-20 12:22:19 UTC (rev 822)
+++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties 2011-04-20 14:45:47 UTC (rev 823)
@@ -22,4 +22,4 @@
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
-wikitty.data.directory=/var/lib/wikitty-publication/codelutin2
+wikitty.data.directory=/var/lib/wikitty-publication/codelutin/
Modified: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties
===================================================================
--- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2011-04-20 12:22:19 UTC (rev 822)
+++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2011-04-20 14:45:47 UTC (rev 823)
@@ -22,7 +22,9 @@
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
-wikitty.data.directory=./target2/data
+
+wikitty.data.directory=./targetBD1/data
+wikitty.service.server.url=http://localhost:1111/wikitty
wikitty.storage.jdbc.queryfile=wikitty-jdbc-query.properties
wikitty.storage.jdbc.driver=org.h2.Driver
wikitty.storage.jdbc.host=jdbc:h2:file:${wikitty.data.directory}/data/db
@@ -40,7 +42,7 @@
org.nuiton.wikitty.services.WikittyServiceSecurity,\
org.nuiton.wikitty.services.WikittyServiceAccessStat,\
org.nuiton.wikitty.services.WikittyServiceCajoServer
-wikitty.service.server.url=http://localhost:1111/wikitty
+
wikitty.WikittyServiceStorage.components=org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC,\
org.nuiton.wikitty.jdbc.WikittyStorageJDBC,\
org.nuiton.wikitty.storage.solr.WikittySearchEngineSolr
1
0
r822 - in trunk/wikitty-publication/src/main: java/org/nuiton/wikitty/publication/synchro xmi
by mfortun@users.nuiton.org 20 Apr '11
by mfortun@users.nuiton.org 20 Apr '11
20 Apr '11
Author: mfortun
Date: 2011-04-20 14:22:19 +0200 (Wed, 20 Apr 2011)
New Revision: 822
Url: http://nuiton.org/repositories/revision/wikitty/822
Log:
* #1475 add field for file's extension in wikittypub
* change method to determine mimetype
* correct static values
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
trunk/wikitty-publication/src/main/xmi/wikitty-publication.zargo
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 08:53:21 UTC (rev 821)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 12:22:19 UTC (rev 822)
@@ -59,6 +59,9 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
final static private Log log = LogFactory.getLog(WikittyPublication.class);
+ static public String WIKITTY_OPTION_URL = "wikitty.service.server.url";
+ static public String WIKITTY_OPTION_COMPONENT = "wikitty.WikittyService.components";
+
static protected ApplicationConfig applicationConfig;
/*
@@ -289,16 +292,16 @@
result.setOptions(applicationConfig.getFlatOptions());
String url = uri.toASCIIString();
if (uri.getScheme().equals("file")) {
- result.setOption("wikitty.WikittyService.components",
+ result.setOption(WIKITTY_OPTION_COMPONENT,
"org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem");
} else if (uri.getScheme().equals("cajo")) {
- result.setOption("wikitty.WikittyService.components",
+ result.setOption(WIKITTY_OPTION_COMPONENT,
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
// remove fragment from the uri.
url = url.replaceAll("\\#.*", "");
} else if (uri.getScheme().equals("hessian")) {
- result.setOption("wikitty.WikittyService.components",
+ result.setOption(WIKITTY_OPTION_COMPONENT,
"org.nuiton.wikitty.services.WikittyServiceHessianClient");
// remove fragment from the uri.
url = url.replaceAll("\\#.*", "");
@@ -312,7 +315,7 @@
log.info("set url " + url + " with component :"
+ result.getOption("wikitty.WikittyService.components"));
- result.setOption("wikitty.service.server.url", url);
+ result.setOption(WIKITTY_OPTION_URL, url);
return result;
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 08:53:21 UTC (rev 821)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 12:22:19 UTC (rev 822)
@@ -43,6 +43,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.activation.MimeType;
+import javax.activation.MimetypesFileTypeMap;
+
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
@@ -52,6 +55,8 @@
import org.nuiton.util.FileUtil;
import org.nuiton.util.MD5InputStream;
import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.WikittyConfig;
+import org.nuiton.wikitty.WikittyConfigOption;
import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
import org.nuiton.wikitty.WikittyUtil;
@@ -102,6 +107,7 @@
protected File homeFile;
protected boolean recursion;
protected String label;
+ protected List<String> pubTextMimeType;
static public String META_CURRENT_LABEL = "current.label";
@@ -140,7 +146,16 @@
* this
*/
try {
- String url = app.getOption("wikitty.service.server.url");
+
+
+ this.pubTextMimeType = new ArrayList<String>();
+
+ //TODO create a property file to store and handle mimetype for pub text
+ pubTextMimeType.add("application/javascript");
+
+
+
+ String url = app.getOption(WikittyPublication.WIKITTY_OPTION_URL);
URI uri = new URI(url);
this.label = uri.getFragment();
@@ -279,8 +294,6 @@
public WikittyEvent store(String securityToken,
Collection<Wikitty> wikitties, boolean force) {
-
-
try {
for (Wikitty w : wikitties) {
@@ -327,7 +340,7 @@
String mime = WikittyPubDataHelper.getMimeType(w);
byte[] content = WikittyPubDataHelper.getContent(w);
- extension = extensionFormimeType(mime);
+ extension = WikittyPubDataHelper.getFileExtension(w);
wikittyFile = new File(path + File.separator + name
+ "." + extension);
@@ -342,7 +355,7 @@
String mime = WikittyPubTextHelper.getMimeType(w);
String content = WikittyPubTextHelper.getContent(w);
- extension = extensionFormimeType(mime);
+ extension = WikittyPubTextHelper.getFileExtension(w);
wikittyFile = new File(path + File.separator + name
+ "." + extension);
@@ -353,15 +366,8 @@
}
if (wikittyFile != null) {
- // prepare for checksum
- BufferedInputStream input = new BufferedInputStream(
- new FileInputStream(wikittyFile));
- byte[] byt = MD5InputStream.hash(input);
-
- String localMd5 = StringUtil.asHex(byt);
-
- // load meta properties
+ // write current label
PropertiesExtended metaProperties = getWikittyPublicationProperties(
wikittyParenFile,
WIKITTY_FILE_META_PROPERTIES_FILE);
@@ -370,22 +376,10 @@
.setProperty(
WikittyPublicationFileSystem.META_CURRENT_LABEL,
ourDir);
-
- metaProperties.setProperty(META_PREFIX_KEY_VERSION
- + wikittyFile.getName(), w.getVersion());
-
- metaProperties.setProperty(META_PREFIX_KEY_CHECKSUM
- + wikittyFile.getName(), localMd5);
- // save
metaProperties.store();
- // load id properties
- PropertiesExtended idProperties = getWikittyPublicationProperties(
- wikittyParenFile, WIKITTY_ID_PROPERTIES_FILE);
- // update
- idProperties.setProperty(w.getId(),
- wikittyFile.getName());
- // save
- idProperties.store();
+
+ // write common properties
+ writeWikittyFileProperties(wikittyFile, w.getId());
}
}
}
@@ -955,8 +949,6 @@
e.printStackTrace();
}
-
-
List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
// for each criteria
@@ -1064,133 +1056,18 @@
}
- /**
- * Transform an object into a wikitty object in this case a File into a
- * wikittyPubText/Data
- *
- * @param fileToTransform
- * the objet to transform
- * @param starts
- * the home directory of the fileToTransform use to contruct the
- * label
- * @return the wikitty
- * @throws Exception
- */
- /*
- * TODO mfortun-2011-04-07 correct the Exception's type
- */
- protected Wikitty fileToWikitty(File fileToTransform, File starts,
- boolean writeProperties) throws Exception {
- String completeName = fileToTransform.getName();
- // isolate extension and file name
- String extension = FileUtil.extension(fileToTransform);
- String name = FileUtil.basename(completeName, "." + extension);
- // search for the mimetype
- String mimeType = mimeTypeForExtension(extension);
- // prepare wikitty basics
- Wikitty result = new WikittyImpl();
- result.addExtension(WikittyLabelImpl.extensionWikittyLabel);
- // creation of the label
- /*
- * TODO mfortun-2011-04-08 find a better way to do this ?
- */
- String pathToFile = fileToTransform.getParent();
- String pathToStart = starts.getCanonicalPath();
- String startDirName = starts.getName();
-
- /*
- * remove path from root to start dir to have path from start to current
- * working dir e.g.: if current file=
- * /home/foo/bob/chaine.chaussette.tar.gz and starts dir = /home/foo/
- * then path will be = foo/bob
- */
- String path = startDirName + pathToFile.replaceAll(pathToStart, "");
-
- /*
- * FIXME actually with a dot as a wikittylabel_separator, when
- * restauring label to directory it destroy directory that containt dot
- * in the name e.g.: /home/truc.machin/bob
- */
-
- String label = path.replaceAll(File.separator, WIKITTYLABEL_SEPARATOR);
-
- WikittyLabelHelper.addLabels(result, label);
-
- // complete with the correct extension with content
- if (isMimeWikittyPubText(mimeType)) {
- result.addExtension(WikittyPubTextImpl.extensionWikittyPubText);
- WikittyPubTextHelper.setName(result, name);
- WikittyPubTextHelper.setMimeType(result, mimeType);
- WikittyPubTextHelper.setContent(result,
- FileUtil.readAsString(fileToTransform));
- } else {
- result.addExtension(WikittyPubDataImpl.extensionWikittyPubData);
- WikittyPubDataHelper.setName(result, name);
- WikittyPubDataHelper.setMimeType(result, mimeType);
- WikittyPubDataHelper.setContent(result,
- FileUtil.fileToByte(fileToTransform));
- }
-
- return result;
-
- }
-
/**
- * Return the mime type for an extension name Extension
- *
- * @param ext
- * @return
- */
- static public String mimeTypeForExtension(String ext) {
- /*
- * TODO mfortun-2011-04-08 really implements this method create a double
- * hashMap for this kind of key/value collection
- */
- if (ext.equalsIgnoreCase("ws")) {
- return "application/javascript";
- } else {
- return "image/png";
- }
-
- }
-
- /**
- * Return the extension for a mime type opposite to mimeTypeForExtension
- *
- * @param ext
- * @return
- */
- static public String extensionFormimeType(String mime) {
- /*
- * TODO mfortun-2011-04-11 really implements this method
- */
- if (mime.equalsIgnoreCase("ws")) {
- return "ws";
- } else {
- return "ws";
- }
-
- }
-
- /**
* return if the mime type is associate to a wikittypubtext
*
* @param mime
* @return
*/
- static public boolean isMimeWikittyPubText(String mime) {
- /*
- * TODO mfortun-2011-04-08 really implements this method
- */
- if (mime.equalsIgnoreCase("application/javascript")) {
- return true;
- } else {
- return false;
- }
+ public boolean isMimeWikittyPubText(String mime) {
+ return pubTextMimeType.contains(mime);
}
/**
@@ -1300,8 +1177,10 @@
String extension = FileUtil.extension(fileToTransform);
String name = FileUtil.basename(completeName, "." + extension);
+
+ MimetypesFileTypeMap mapMime= new MimetypesFileTypeMap();
// search for the mimetype
- String mimeType = mimeTypeForExtension(extension);
+ String mimeType = mapMime.getContentType(fileToTransform);
// load properties
File wikittyParentDir = new File(path);
@@ -1319,12 +1198,14 @@
WikittyPubTextHelper.setMimeType(result, mimeType);
WikittyPubTextHelper.setContent(result,
FileUtil.readAsString(fileToTransform));
+ WikittyPubTextHelper.setFileExtension(result, extension);
} else {
result.addExtension(WikittyPubDataImpl.extensionWikittyPubData);
WikittyPubDataHelper.setName(result, name);
WikittyPubDataHelper.setMimeType(result, mimeType);
WikittyPubDataHelper.setContent(result,
FileUtil.fileToByte(fileToTransform));
+ WikittyPubDataHelper.setFileExtension(result, extension);
}
// re set the version
@@ -1336,10 +1217,14 @@
}
protected void harvestNew(File starts, String label) throws Exception {
- System.out.println(homeFile + "harvestn new");
+
File propertyFile = new File(starts + File.separator
+ PROPERTY_DIRECTORY);
+ // TODO mfortun-2011-04-18 have to work on labels
+ // actually starts + label have to be the same.
+ // first starts and label.
+
if (!propertyFile.exists() || !propertyFile.isDirectory()) {
propertyFile.mkdir();
Modified: trunk/wikitty-publication/src/main/xmi/wikitty-publication.zargo
===================================================================
(Binary files differ)
1
0
r821 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 20 Apr '11
by mfortun@users.nuiton.org 20 Apr '11
20 Apr '11
Author: mfortun
Date: 2011-04-20 10:53:21 +0200 (Wed, 20 Apr 2011)
New Revision: 821
Url: http://nuiton.org/repositories/revision/wikitty/821
Log:
* correct search on wikitty publication file system works
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-19 15:56:51 UTC (rev 820)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 08:53:21 UTC (rev 821)
@@ -279,6 +279,8 @@
public WikittyEvent store(String securityToken,
Collection<Wikitty> wikitties, boolean force) {
+
+
try {
for (Wikitty w : wikitties) {
@@ -620,6 +622,7 @@
}
// recupere la valeur dans le wikitty
Object o = w.getFqField(fqfieldName);
+
// recupere le type de la valeur
FieldType t = w.getFieldType(fqfieldName);
// convertie la valeur a verifier dans le meme type que la valeur
@@ -632,12 +635,9 @@
// dans le inmemory on doit retrouve des collections et non pas
// des objets seuls :(
value = Collections.singleton(value);
- //FIXME mfortun-2011-04-19 ici ça fait bugger plus loin
- // vu que on met dans une collection la valeur du startwith
- //et que plus loin on tente de caster cette collection en string
}
value = t.getValidValue(value);
-
+
boolean checked = false;
switch (restriction.getName()) {
@@ -691,9 +691,33 @@
+ " is "
+ t.getType().name());
}
- System.out.println(value.getClass());
- System.out.println(value);
- checked = ((String) o).startsWith((String) value);
+
+ // FIXME mfortun-2011-04-20 rustine pour champs multivalué de
+ // type string
+ // et restriction startwith dessus. ça marche mais faudrait
+ // quelque chose de plus
+ // propre, et surtout généraliser pour toutes les restrictions
+
+ if (o instanceof Collection<?>
+ && value instanceof Collection<?>) {
+
+ for (Object val : (Collection) value) {
+
+ String valu = (String) val;
+
+ for (Object oo : (Collection) o) {
+ String cotainedO = (String) oo;
+ if (cotainedO != null) {
+ checked = checked || cotainedO.startsWith(valu);
+ }
+ }
+
+ }
+
+ } else {
+
+ checked = ((String) o).startsWith((String) value);
+ }
break;
}
return checked;
@@ -931,6 +955,8 @@
e.printStackTrace();
}
+
+
List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
// for each criteria
@@ -946,9 +972,8 @@
String id = entry.getKey();
Wikitty w = entry.getValue();
// if macth
- System.out.println(restriction);
if (checkRestriction(restriction, w)) {
-
+
// increment result number
currentIndex++;
if (currentIndex > firstIndex) {
@@ -1282,10 +1307,6 @@
File wikittyParentDir = new File(path);
PropertiesExtended props = getWikittyPublicationProperties(
wikittyParentDir, WIKITTY_FILE_META_PROPERTIES_FILE);
- // re set the version
- result.setVersion(props
- .getProperty(WikittyPublicationFileSystem.META_PREFIX_KEY_VERSION
- + completeName));
// set the current label
WikittyLabelHelper.addLabels(result, props
@@ -1306,16 +1327,19 @@
FileUtil.fileToByte(fileToTransform));
}
+ // re set the version
+ result.setVersion(props
+ .getProperty(WikittyPublicationFileSystem.META_PREFIX_KEY_VERSION
+ + completeName));
+
return result;
}
protected void harvestNew(File starts, String label) throws Exception {
-
-
-
+ System.out.println(homeFile + "harvestn new");
File propertyFile = new File(starts + File.separator
+ PROPERTY_DIRECTORY);
-
+
if (!propertyFile.exists() || !propertyFile.isDirectory()) {
propertyFile.mkdir();
@@ -1327,12 +1351,13 @@
WIKITTY_FILE_META_PROPERTIES_FILE);
meta.put(META_CURRENT_LABEL, label);
+ meta.store();
for (File child : starts.listFiles()) {
if (child.isDirectory()
&& !child.getName().equals(PROPERTY_DIRECTORY)) {
harvestNew(child,
label + WIKITTYLABEL_SEPARATOR + child.getName());
- } else if (!child.isDirectory()){
+ } else if (!child.isDirectory()) {
List<String> filesWikitty = new ArrayList<String>();
filesWikitty.addAll(CollectionUtil.toGenericCollection(
@@ -1348,7 +1373,7 @@
protected void writeWikittyFileProperties(File towrite, String wikittyID)
throws Exception {
-
+
if (towrite.exists() && !towrite.isDirectory()) {
Wikitty wikitty = new WikittyImpl(wikittyID);
1
0
r820 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 19 Apr '11
by mfortun@users.nuiton.org 19 Apr '11
19 Apr '11
Author: mfortun
Date: 2011-04-19 17:56:51 +0200 (Tue, 19 Apr 2011)
New Revision: 820
Url: http://nuiton.org/repositories/revision/wikitty/820
Log:
* add support for the search on wikittyFileSytem
* add method to detect new file and create wikitty
* add method to write wikitty property file
* correct/merge method
* code have to be cleaned.
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-19 14:39:07 UTC (rev 819)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-19 15:56:51 UTC (rev 820)
@@ -30,26 +30,38 @@
import java.io.FileReader;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.CollectionUtil;
import org.nuiton.util.FileUtil;
import org.nuiton.util.MD5InputStream;
import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.WikittyException;
import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyUtil;
+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.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyLabelImpl;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
@@ -57,10 +69,25 @@
import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper;
import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl;
import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.search.FacetTopic;
+
import org.nuiton.wikitty.search.PagedResult;
-import org.nuiton.wikitty.search.Search;
+
import org.nuiton.wikitty.search.TreeNodeResult;
+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.Contains;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.search.operators.False;
+import org.nuiton.wikitty.search.operators.In;
+import org.nuiton.wikitty.search.operators.Keyword;
+import org.nuiton.wikitty.search.operators.Not;
+import org.nuiton.wikitty.search.operators.Null;
+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.operators.True;
import org.nuiton.wikitty.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyListener;
@@ -90,6 +117,8 @@
static public String WIKITTY_FILE_META_PROPERTIES_FILE = "meta.properties";
+ static public String WIKITTY_FILE_SERVICE = "ws.properties";
+
/*
* Need a different file for id and meta information about wikittiesFiles
* because with this solution we can simply read the ids with props.keySet()
@@ -452,61 +481,7 @@
FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
- // create the wikitty with his id
- Wikitty wikitty = new WikittyImpl(wikid);
- // add label extension
- wikitty.addExtension(WikittyLabelImpl.extensionWikittyLabel);
-
- // preparation for mime research and file research
- String path = localisation.getPath();
- String completeName = localisation.getFileName();
-
- // search for the file
- File fileToTransform = new File(path + File.separator
- + completeName);
-
- String extension = FileUtil.extension(fileToTransform);
- String name = FileUtil.basename(completeName, "."
- + extension);
- // search for the mimetype
- String mimeType = mimeTypeForExtension(extension);
-
- // load properties
- File wikittyParentDir = new File(path);
- PropertiesExtended props = getWikittyPublicationProperties(
- wikittyParentDir, WIKITTY_FILE_META_PROPERTIES_FILE);
- // re set the version
- wikitty.setVersion(props
- .getProperty(WikittyPublicationFileSystem.META_PREFIX_KEY_VERSION
- + completeName));
-
- // set the current label
- WikittyLabelHelper
- .addLabels(
- wikitty,
- props.getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL));
-
- /*
- * TODO mfortun-2011-04-12 need to merge part of this code
- * with filetowikitty method 'cause it is basically the same
- */
-
- // create the correct wikittypubxxx
- if (isMimeWikittyPubText(mimeType)) {
- wikitty.addExtension(WikittyPubTextImpl.extensionWikittyPubText);
- WikittyPubTextHelper.setName(wikitty, name);
- WikittyPubTextHelper.setMimeType(wikitty, mimeType);
- WikittyPubTextHelper.setContent(wikitty,
- FileUtil.readAsString(fileToTransform));
- } else {
- wikitty.addExtension(WikittyPubDataImpl.extensionWikittyPubData);
- WikittyPubDataHelper.setName(wikitty, name);
- WikittyPubDataHelper.setMimeType(wikitty, mimeType);
- WikittyPubDataHelper.setContent(wikitty,
- FileUtil.fileToByte(fileToTransform));
- }
-
- result.add(wikitty);
+ result.add(this.restore(wikid, localisation));
}
}
} catch (Exception e) {
@@ -581,47 +556,453 @@
return result;
}
+ /**
+ * Write by jcouteau, used to check if a wikitty check a restriction
+ *
+ * @see org.nuiton.wikitty.storage.WikittySearchEngineInMemory#checkRestriction
+ *
+ * @param restriction
+ * the restriction
+ * @param w
+ * the wikitty to check
+ * @return if the wikitty check the restriction
+ */
+ public boolean checkRestriction(Restriction restriction, Wikitty w) {
+ if (restriction instanceof BinaryOperator) {
+ BinaryOperator binOp = (BinaryOperator) restriction;
+
+ String fqfieldName = binOp.getElement().getName();
+
+ // Checks on extensions
+ if (Element.ELT_EXTENSION.equals(fqfieldName)) {
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case NOT_EQUALS:
+ checked = !w.getExtensionNames().contains(binOp.getValue());
+ break;
+ case EQUALS:
+ checked = w.getExtensionNames().contains(binOp.getValue());
+ break;
+ }
+
+ return checked;
+
+ // Checks on id
+ } else if (Element.ELT_ID.equals(fqfieldName)) {
+
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case NOT_EQUALS:
+ checked = !w.getId().equals(binOp.getValue());
+ break;
+ case EQUALS:
+ checked = w.getId().equals(binOp.getValue());
+ break;
+ }
+
+ return checked;
+ }
+
+ // 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 true in case of not equals
+ if (RestrictionName.NOT_EQUALS == restriction.getName()) {
+ return true;
+ }
+
+ return false;
+ }
+ // recupere la valeur dans le wikitty
+ Object o = w.getFqField(fqfieldName);
+ // recupere le type de la valeur
+ FieldType t = w.getFieldType(fqfieldName);
+ // convertie la valeur a verifier dans le meme type que la valeur
+ // du wikitty
+ Object value = binOp.getValue();
+ if (!(value instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ value = Collections.singleton(value);
+ //FIXME mfortun-2011-04-19 ici ça fait bugger plus loin
+ // vu que on met dans une collection la valeur du startwith
+ //et que plus loin on tente de caster cette collection en string
+ }
+ value = t.getValidValue(value);
+
+ boolean checked = false;
+
+ switch (restriction.getName()) {
+ case EQUALS:
+ if (value instanceof String && o instanceof String) {
+
+ String pattern = (String) value;
+ pattern = pattern.replace("*", "\\p{ASCII}*");
+ pattern = pattern.replace("?", "\\p{ASCII}");
+
+ Pattern p = Pattern.compile(pattern);
+ Matcher m = p.matcher((String) o);
+ checked = m.matches();
+ } else {
+ 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:
+ System.out.println(t.isCollection());
+ 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());
+ }
+ System.out.println(value.getClass());
+ System.out.println(value);
+ checked = ((String) o).startsWith((String) value);
+ break;
+ }
+ return checked;
+ } else if (restriction instanceof Null) {
+ Null nullRes = (Null) restriction;
+
+ String fqfieldName = nullRes.getFieldName();
+
+ // check my wikitty got the right extension before doing anything.
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+ // get the value in the wikitty
+ Object o = w.getFqField(fqfieldName);
+
+ // No null on extensions, always return false
+ if (fqfieldName.equals(Element.ELT_EXTENSION)) {
+ return false;
+ }
+
+ // No null on ids, always return false
+ if (fqfieldName.equals(Element.ELT_ID)) {
+ return false;
+ }
+
+ boolean checked = false;
+
+ switch (nullRes.getName()) {
+ case IS_NULL:
+ checked = (o == null);
+ break;
+ case IS_NOT_NULL:
+ checked = (o != null);
+ break;
+ }
+
+ return checked;
+
+ } else if (restriction instanceof In) {
+ In in = (In) restriction;
+ String fqfieldName = in.getElement().getName();
+ String testedValue = String.valueOf(w.getFqField(fqfieldName));
+ for (String value : in.getValue()) {
+ if (testedValue.equals(value)) {
+ return true;
+ }
+ }
+
+ return false;
+
+ } else if (restriction instanceof True) {
+ return true;
+ } else if (restriction instanceof False) {
+ return false;
+ } else if (restriction instanceof Contains) {
+ Contains contains = (Contains) restriction;
+
+ String fqfieldName = contains.getElement().getName();
+ List<String> values = contains.getValue();
+
+ String extension = WikittyUtil
+ .getExtensionNameFromFQFieldName(fqfieldName);
+ String fieldName = WikittyUtil
+ .getFieldNameFromFQFieldName(fqfieldName);
+
+ if (!w.hasField(extension, fieldName)) {
+ return false;
+ }
+
+ // Get field as string and then split it to take into account not
+ // multivalued fields.
+ String testedValuesAsString = w.getFieldAsString(extension,
+ fieldName);
+
+ if ('[' == testedValuesAsString.charAt(0)) {
+ testedValuesAsString = testedValuesAsString.substring(1,
+ testedValuesAsString.length());
+ }
+
+ List<String> testedValues = Arrays.asList(testedValuesAsString
+ .split(","));
+
+ for (Object value : values) {
+ if (!testedValues.contains(String.valueOf(value))) {
+ return false;
+ }
+ }
+
+ return true;
+
+ } else if (restriction instanceof And) {
+ And and = (And) restriction;
+ for (Restriction sub : and.getRestrictions()) {
+ if (!checkRestriction(sub, w)) {
+ return false;
+ }
+ }
+ return true;
+ } else if (restriction instanceof Or) {
+ Or or = (Or) restriction;
+ for (Restriction sub : or.getRestrictions()) {
+ if (checkRestriction(sub, w)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (restriction instanceof Keyword) {
+ Keyword keyword = (Keyword) restriction;
+
+ String value = keyword.getValue();
+
+ for (String fieldName : w.getAllFieldNames()) {
+ String testedValue = String.valueOf(w.getFqField(fieldName));
+ if (testedValue.contains(value)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (restriction instanceof Not) {
+ Not or = (Not) restriction;
+ Restriction sub = or.getRestriction();
+ return !checkRestriction(sub, w);
+ } else if (restriction instanceof AssociatedRestriction) {
+
+ AssociatedRestriction ass = (AssociatedRestriction) restriction;
+
+ String fqfieldName = ass.getElement().getName();
+
+ // check my wikitty got the right extension before doing anything.
+ String[] extName = fqfieldName.split("\\.");
+ if (!w.hasField(extName[0], extName[1])) {
+ return false;
+ }
+ // get the value in the wikitty, it is a wikitty's id
+ Object o = w.getFqField(fqfieldName);
+
+ // Get sub-restriction
+ Restriction sub = ass.getRestriction();
+
+ Criteria associatedSearch = new Criteria();
+ associatedSearch.setRestriction(sub);
+
+ // find everything that validate the sub-restriction
+
+ List<Criteria> dummyList = new ArrayList<Criteria>();
+ dummyList.add(associatedSearch);
+ // same as proxy for "fix" unique param to list param
+ PagedResult<String> associatedResult = findAllByCriteria("",
+ dummyList).get(0);
+
+ List<String> associatedList = associatedResult.getAll();
+
+ // Check that my field is contained in the sub-restriction results.
+ return associatedList.contains(String.valueOf(o));
+ } else if (restriction instanceof Between) {
+
+ Between op = (Between) restriction;
+
+ Object max = op.getMax();
+ Object min = op.getMin();
+
+ // No between on extensions, always return false
+ if (op.getElement().getName().equals(Element.ELT_EXTENSION)) {
+ return false;
+ }
+
+ // No between on ids, always return false
+ if (op.getElement().getName().equals(Element.ELT_ID)) {
+ return false;
+ }
+
+ String fqfieldName = op.getElement().getName();
+
+ // 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;
+ }
+
+ // recupere la valeur dans le wikitty
+ Object o = w.getFqField(fqfieldName);
+
+ // recupere le type de la valeur
+ FieldType t = w.getFieldType(fqfieldName);
+
+ if (!(min instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ min = Collections.singleton(min);
+ }
+ min = t.getValidValue(min);
+
+ if (!(max instanceof Collection) && t.isCollection()) {
+ // on doit encapsuler dans une collection, car la creation
+ // de la requete ajoute autant de v == o && ... que de valeurs
+ // dans la collection (champs multi-value solr). Mais
+ // dans le inmemory on doit retrouve des collections et non pas
+ // des objets seuls :(
+ max = Collections.singleton(max);
+ }
+ max = t.getValidValue(max);
+
+ return ((Comparable) o).compareTo(min) >= 0
+ && ((Comparable) o).compareTo(max) <= 0;
+ } else {
+ throw new UnsupportedOperationException(restriction.getName()
+ + " Search Not yet implemented");
+ }
+ }
+
@Override
public List<PagedResult<String>> findAllByCriteria(String securityToken,
List<Criteria> criteria) {
- List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
- List<String> rr= new ArrayList<String>();
- Map<String, List<FacetTopic>> map= new HashMap<String, List<FacetTopic>>();
- PagedResult<String> pp= new PagedResult<String>(0,0,
- "", map, rr);
- result.add(pp);
-
- /*
- * TODO mfortun-2011-04-18 ici faire une vrai gestion des critérias
- * pas simple histoire de comparaison avec critéria préconstruit.
- * voir avec jcouteau comment lui à faire pour son implémentation
- * des critérias.
- * Dans un premier temps s'occuper uniquement des types pub et sur label
- * name = machin
- */
-
- for (Criteria cr: criteria){
- System.out.println(cr.getName());
-
-
-
+ Map<String, Wikitty> wikitties = new HashMap<String, Wikitty>();
+ try {
+ harvestNew(homeFile, label);
+ BidiMap map = harvestLocalWikitties(homeFile, true);
+
+ for (Object o : map.keySet()) {
+ String id = (String) o;
+ FileSystemWIkittyId location = (FileSystemWIkittyId) map
+ .get(id);
+ wikitties.put(id, restore(id, location));
+
+ }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
-
-
- return result;
+ List<PagedResult<String>> result = new ArrayList<PagedResult<String>>();
+ // for each criteria
+ for (Criteria cr : criteria) {
+ // prepare restriction on result
+ int firstIndex = cr.getFirstIndex();
+ int endIndex = cr.getEndIndex();
+ List<String> ids = new LinkedList<String>();
+ int currentIndex = 0;
+ Restriction restriction = cr.getRestriction();
+ // for each wikitty check if it match the resttriction
+ for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
+ String id = entry.getKey();
+ Wikitty w = entry.getValue();
+ // if macth
+ System.out.println(restriction);
+ if (checkRestriction(restriction, w)) {
+
+ // increment result number
+ currentIndex++;
+ if (currentIndex > firstIndex) {
+ ids.add(id);
+ }
+ // if the number of wikitty found is match
+ // stop the search for other wikitty
+ if (endIndex >= 0 && currentIndex >= endIndex) {
+ break;
+ }
+ }
+ }
+ result.add(new PagedResult<String>(firstIndex, ids.size(),
+ restriction.toString(), null, ids));
+ }
+ return result;
}
@Override
public List<String> findByCriteria(String securityToken,
List<Criteria> criteria) {
- List<String> result = new ArrayList<String>();
- result.add("");
-
+ List<String> result = new ArrayList<String>();
- System.out.println(criteria.get(0).getRestriction());
- return result;
+ Map<String, Wikitty> wikitties = new HashMap<String, Wikitty>();
+
+ // for each criteria
+ for (Criteria cr : criteria) {
+ // prepare restriction on result
+ int firstIndex = cr.getFirstIndex();
+ int endIndex = cr.getEndIndex();
+ List<String> ids = new LinkedList<String>();
+ int currentIndex = 0;
+ Restriction restriction = cr.getRestriction();
+ // for each wikitty check if it match the resttriction
+ for (Entry<String, Wikitty> entry : wikitties.entrySet()) {
+ String id = entry.getKey();
+ Wikitty w = entry.getValue();
+ // if macth
+ if (checkRestriction(restriction, w)) {
+ // increment result number
+ currentIndex++;
+ if (currentIndex > firstIndex) {
+ ids.add(id);
+ }
+ // if the number of wikitty found is match
+ // stop the search for other wikitty
+ if (endIndex >= 0 && currentIndex >= endIndex) {
+ break;
+ }
+ }
+ }
+ result.addAll(ids);
+ }
+ return result;
}
@Override
@@ -673,8 +1054,8 @@
/*
* TODO mfortun-2011-04-07 correct the Exception's type
*/
- static public Wikitty fileToWikitty(File fileToTransform, File starts)
- throws Exception {
+ protected Wikitty fileToWikitty(File fileToTransform, File starts,
+ boolean writeProperties) throws Exception {
String completeName = fileToTransform.getName();
// isolate extension and file name
@@ -788,39 +1169,6 @@
}
/**
- * Creates all the file system require from a label path in the working
- * directory
- *
- * @param label
- * the path string
- * @return if all the path was created
- * @throws Exception
- */
- protected boolean createFilesFromLabelPath(String label) throws Exception {
-
- label = label.replace(".", File.separator);
- label = label.replace(File.separator + File.separator, File.separator
- + ".");
- String[] pathElements = StringUtil.split(label, File.separator);
-
- boolean result = false;
-
- if (homeFile.exists() && homeFile.isDirectory()) {
- String path = homeFile.getCanonicalPath();
- result = true;
- for (int i = 0; i < pathElements.length; i++) {
-
- path = path + File.separator + pathElements[i];
- File temp = new File(path);
- FileUtil.createDirectoryIfNecessary(temp);
- result = result && temp.exists();
- }
- }
-
- return result;
- }
-
- /**
* Method that create a list of the properties directory
*
* @param starts
@@ -911,4 +1259,159 @@
return result;
}
+ protected Wikitty restore(String id, FileSystemWIkittyId fileId)
+ throws Exception {
+
+ Wikitty result = new WikittyImpl(id);
+
+ result.addExtension(WikittyLabelImpl.extensionWikittyLabel);
+
+ // preparation for mime research and file research
+ String path = fileId.getPath();
+ String completeName = fileId.getFileName();
+
+ // search for the file
+ File fileToTransform = new File(path + File.separator + completeName);
+
+ String extension = FileUtil.extension(fileToTransform);
+ String name = FileUtil.basename(completeName, "." + extension);
+ // search for the mimetype
+ String mimeType = mimeTypeForExtension(extension);
+
+ // load properties
+ File wikittyParentDir = new File(path);
+ PropertiesExtended props = getWikittyPublicationProperties(
+ wikittyParentDir, WIKITTY_FILE_META_PROPERTIES_FILE);
+ // re set the version
+ result.setVersion(props
+ .getProperty(WikittyPublicationFileSystem.META_PREFIX_KEY_VERSION
+ + completeName));
+
+ // set the current label
+ WikittyLabelHelper.addLabels(result, props
+ .getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL));
+
+ // create the correct wikittypubxxx
+ if (isMimeWikittyPubText(mimeType)) {
+ result.addExtension(WikittyPubTextImpl.extensionWikittyPubText);
+ WikittyPubTextHelper.setName(result, name);
+ WikittyPubTextHelper.setMimeType(result, mimeType);
+ WikittyPubTextHelper.setContent(result,
+ FileUtil.readAsString(fileToTransform));
+ } else {
+ result.addExtension(WikittyPubDataImpl.extensionWikittyPubData);
+ WikittyPubDataHelper.setName(result, name);
+ WikittyPubDataHelper.setMimeType(result, mimeType);
+ WikittyPubDataHelper.setContent(result,
+ FileUtil.fileToByte(fileToTransform));
+ }
+
+ return result;
+ }
+
+ protected void harvestNew(File starts, String label) throws Exception {
+
+
+
+ File propertyFile = new File(starts + File.separator
+ + PROPERTY_DIRECTORY);
+
+ if (!propertyFile.exists() || !propertyFile.isDirectory()) {
+ propertyFile.mkdir();
+
+ }
+
+ PropertiesExtended ids = getWikittyPublicationProperties(starts,
+ WIKITTY_ID_PROPERTIES_FILE);
+ PropertiesExtended meta = getWikittyPublicationProperties(starts,
+ WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ meta.put(META_CURRENT_LABEL, label);
+ for (File child : starts.listFiles()) {
+ if (child.isDirectory()
+ && !child.getName().equals(PROPERTY_DIRECTORY)) {
+ harvestNew(child,
+ label + WIKITTYLABEL_SEPARATOR + child.getName());
+ } else if (!child.isDirectory()){
+
+ List<String> filesWikitty = new ArrayList<String>();
+ filesWikitty.addAll(CollectionUtil.toGenericCollection(
+ ids.values(), String.class));
+ // if file is not a wikitty create it.
+ if (!filesWikitty.contains(child.getName())) {
+ writeWikittyFileProperties(child, null);
+ }
+ }
+ }
+
+ }
+
+ protected void writeWikittyFileProperties(File towrite, String wikittyID)
+ throws Exception {
+
+ if (towrite.exists() && !towrite.isDirectory()) {
+ Wikitty wikitty = new WikittyImpl(wikittyID);
+
+ File parent = towrite.getParentFile();
+
+ PropertiesExtended id = getWikittyPublicationProperties(parent,
+ WIKITTY_ID_PROPERTIES_FILE);
+ PropertiesExtended meta = getWikittyPublicationProperties(parent,
+ WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ id.put(wikitty.getId(), towrite.getName());
+
+ BufferedInputStream input = new BufferedInputStream(
+ new FileInputStream(towrite));
+
+ byte[] byt = MD5InputStream.hash(input);
+
+ String localMd5 = StringUtil.asHex(byt);
+
+ meta.put(META_PREFIX_KEY_VERSION + towrite.getName(),
+ wikitty.getVersion());
+ meta.put(META_PREFIX_KEY_CHECKSUM + towrite.getName(), localMd5);
+
+ id.store();
+ meta.store();
+ } else {
+ // TODO mfortun-2011-04-19 set proper type of exception
+ throw new Exception();
+ }
+
+ }
+
+ /**
+ * Creates all the file system require from a label path in the working
+ * directory
+ *
+ * @param label
+ * the path string
+ * @return if all the path was created
+ * @throws Exception
+ */
+ protected boolean createFilesFromLabelPath(String label) throws Exception {
+
+ label = label.replace(".", File.separator);
+ label = label.replace(File.separator + File.separator, File.separator
+ + ".");
+ String[] pathElements = StringUtil.split(label, File.separator);
+
+ boolean result = false;
+
+ if (homeFile.exists() && homeFile.isDirectory()) {
+ String path = homeFile.getCanonicalPath();
+ result = true;
+ for (int i = 0; i < pathElements.length; i++) {
+
+ path = path + File.separator + pathElements[i];
+ File temp = new File(path);
+ FileUtil.createDirectoryIfNecessary(temp);
+ result = result && temp.exists();
+ }
+ }
+
+ return result;
+ }
+
}
1
0
r819 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search
by bpoussin@users.nuiton.org 19 Apr '11
by bpoussin@users.nuiton.org 19 Apr '11
19 Apr '11
Author: bpoussin
Date: 2011-04-19 16:39:07 +0200 (Tue, 19 Apr 2011)
New Revision: 819
Url: http://nuiton.org/repositories/revision/wikitty/819
Log:
Evolution #1471: PagedResult must be Iterable
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java 2011-04-19 10:52:13 UTC (rev 818)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/PagedResult.java 2011-04-19 14:39:07 UTC (rev 819)
@@ -25,6 +25,7 @@
package org.nuiton.wikitty.search;
+import java.util.Iterator;
import static org.nuiton.i18n.I18n._;
import java.io.Serializable;
@@ -55,7 +56,7 @@
* Last update: $Date$
* by : $Author$
*/
-public class PagedResult<T> implements Serializable {
+public class PagedResult<T> implements Serializable, Iterable<T> {
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(PagedResult.class);
@@ -350,4 +351,13 @@
return result;
}
+ /**
+ * Iterate on result, same as getAll().iterator().
+ * @return
+ */
+ public Iterator<T> iterator() {
+ Iterator<T> result = getAll().iterator();
+ return result;
+ }
+
}
1
0
r818 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search
by bpoussin@users.nuiton.org 19 Apr '11
by bpoussin@users.nuiton.org 19 Apr '11
19 Apr '11
Author: bpoussin
Date: 2011-04-19 12:52:13 +0200 (Tue, 19 Apr 2011)
New Revision: 818
Url: http://nuiton.org/repositories/revision/wikitty/818
Log:
Evolution #1469: Add compartor for FacetTopic, useful to order facet on count or name
petit oublie de prendre en compte le ignoreCase :(
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java 2011-04-18 17:24:56 UTC (rev 817)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java 2011-04-19 10:52:13 UTC (rev 818)
@@ -27,7 +27,12 @@
}
public int compare(FacetTopic o1, FacetTopic o2) {
- int result = o1.getTopicName().compareTo(o2.getTopicName());
+ int result;
+ if (ignoreCase) {
+ result = o1.getTopicName().compareToIgnoreCase(o2.getTopicName());
+ } else {
+ result = o1.getTopicName().compareTo(o2.getTopicName());
+ }
return result;
}
}
1
0
r817 - in trunk/wikitty-api/src: main/java/org/nuiton/wikitty/search test/java/org/nuiton/wikitty test/java/org/nuiton/wikitty/search
by bpoussin@users.nuiton.org 18 Apr '11
by bpoussin@users.nuiton.org 18 Apr '11
18 Apr '11
Author: bpoussin
Date: 2011-04-18 19:24:56 +0200 (Mon, 18 Apr 2011)
New Revision: 817
Url: http://nuiton.org/repositories/revision/wikitty/817
Log:
Evolution #1469: Add compartor for FacetTopic, useful to order facet on count or name
Added:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicCountComparator.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicCountComparator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicCountComparator.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicCountComparator.java 2011-04-18 17:24:56 UTC (rev 817)
@@ -0,0 +1,26 @@
+package org.nuiton.wikitty.search;
+
+import java.util.Comparator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class FacetTopicCountComparator implements Comparator<FacetTopic> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(FacetTopicCountComparator.class);
+
+ public int compare(FacetTopic o1, FacetTopic o2) {
+ int thisVal = o1.getCount();
+ int anotherVal = o2.getCount();
+ // code recupere de Integer.compareTo
+ return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+ }
+}
Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java (rev 0)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/FacetTopicNameComparator.java 2011-04-18 17:24:56 UTC (rev 817)
@@ -0,0 +1,33 @@
+package org.nuiton.wikitty.search;
+
+import java.util.Comparator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class FacetTopicNameComparator implements Comparator<FacetTopic> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(FacetTopicNameComparator.class);
+
+ protected boolean ignoreCase = true;
+
+ public FacetTopicNameComparator() {
+ }
+
+ public FacetTopicNameComparator(boolean ignoreCase) {
+ this.ignoreCase = ignoreCase;
+ }
+
+ public int compare(FacetTopic o1, FacetTopic o2) {
+ int result = o1.getTopicName().compareTo(o2.getTopicName());
+ return result;
+ }
+}
Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java (rev 0)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/search/FacetTopicTest.java 2011-04-18 17:24:56 UTC (rev 817)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011 poussin. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.nuiton.wikitty.search;
+
+import java.util.TreeSet;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author poussin
+ */
+public class FacetTopicTest {
+
+ /**
+ * Test of toString method, of class FacetTopic.
+ */
+ @Test
+ public void testNameComparator() {
+ TreeSet<FacetTopic> countSort = new TreeSet<FacetTopic>(new FacetTopicCountComparator());
+ TreeSet<FacetTopic> nameSort = new TreeSet<FacetTopic>(new FacetTopicNameComparator(false));
+ TreeSet<FacetTopic> nameIgnoreCaseSort = new TreeSet<FacetTopic>(new FacetTopicNameComparator(true));
+
+ FacetTopic a5 = new FacetTopic("test", "a", 5);
+ FacetTopic b4 = new FacetTopic("test", "b", 4);
+ FacetTopic c3 = new FacetTopic("test", "c", 3);
+ FacetTopic d2 = new FacetTopic("test", "d", 2);
+ FacetTopic e1 = new FacetTopic("test", "e", 1);
+ FacetTopic A0 = new FacetTopic("test", "A", 0);
+
+
+ countSort.add(a5);
+ nameSort.add(a5);
+ nameIgnoreCaseSort.add(a5);
+
+ countSort.add(b4);
+ nameSort.add(b4);
+ nameIgnoreCaseSort.add(b4);
+
+ countSort.add(c3);
+ nameSort.add(c3);
+ nameIgnoreCaseSort.add(c3);
+
+ countSort.add(d2);
+ nameSort.add(d2);
+ nameIgnoreCaseSort.add(d2);
+
+ countSort.add(e1);
+ nameSort.add(e1);
+ nameIgnoreCaseSort.add(e1);
+
+ countSort.add(A0);
+ nameSort.add(A0);
+ nameIgnoreCaseSort.add(A0);
+
+ //TODO poussin 20110418 faire de vrai assert, mais comme faire au plus simple ?
+ System.out.println("count: " + countSort);
+ System.out.println("nameSort: " + nameSort);
+ System.out.println("nameIgnoreCaseSort: " + nameIgnoreCaseSort);
+ }
+}
1
0