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
April 2011
- 6 participants
- 99 discussions
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
r816 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 18 Apr '11
by mfortun@users.nuiton.org 18 Apr '11
18 Apr '11
Author: mfortun
Date: 2011-04-18 18:03:15 +0200 (Mon, 18 Apr 2011)
New Revision: 816
Url: http://nuiton.org/repositories/revision/wikitty/816
Log:
* correct bug with url construction for the wikittypublicationfilesystem
* criteria search for wikittypublicationfilesystem beginning
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
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-18 14:19:45 UTC (rev 815)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-18 16:03:15 UTC (rev 816)
@@ -24,8 +24,6 @@
*/
package org.nuiton.wikitty.publication.synchro;
-import gnu.cajo.Cajo;
-
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@@ -39,17 +37,12 @@
import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
-import org.nuiton.wikitty.entities.WikittyUser;
-import org.nuiton.wikitty.entities.WikittyUserHelper;
-import org.nuiton.wikitty.entities.WikittyUserImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubText;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.Search;
-import org.nuiton.wikitty.services.WikittyServiceCajoClient;
/**
* Main class of the sync part of wikitty publication, this class is the entry
@@ -77,6 +70,8 @@
static public String IS_DELETE_OPTION = "delete";
static public String IS_EXISTING_OPTION = "existing";
+ static public String LABEL_KEY = "working.label";
+
/**
* @param args
* @throws ArgumentsParserException
@@ -292,31 +287,42 @@
// transfert main properties to new application config
result.setOptions(applicationConfig.getFlatOptions());
-
+ String url = uri.toASCIIString();
if (uri.getScheme().equals("file")) {
result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem");
} else if (uri.getScheme().equals("cajo")) {
result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
+
+ // remove fragment from the uri.
+ url = url.replaceAll("\\#.*", "");
} else if (uri.getScheme().equals("hessian")) {
result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ // remove fragment from the uri.
+ url = url.replaceAll("\\#.*", "");
}
- String url = uri.toASCIIString();
- // remove fragment from the uri.
- url = url.replaceAll("\\#.*", "");
- // set protocol to http no use finally
+ // set protocol to http, no use finally
/*
* url = url.replaceFirst("["+uri.getScheme()+"]", "http");
*/
-
- log.info("set url " + url + " with component :"+ result.getOption("wikitty.WikittyService.components"));
+ log.info("set url " + url + " with component :"
+ + result.getOption("wikitty.WikittyService.components"));
+
result.setOption("wikitty.service.server.url", url);
return result;
}
+
+ /*
+ * TODO mfortun-2011-04-18 plus tard il faudra rajouter un fonctionnement
+ * commit update à la commande sync, en se servant de l'adresse du wikitty
+ * service que l'on aura enregitré quelque part. Un commit/update sera juste
+ * un alias sur le sync classique en se servant d'une adresse enregistré
+ * dans un fichier et une adresse en ligne de commande
+ */
}
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-18 14:19:45 UTC (rev 815)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-18 16:03:15 UTC (rev 816)
@@ -31,7 +31,9 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.collections.BidiMap;
@@ -55,7 +57,9 @@
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.services.WikittyEvent;
import org.nuiton.wikitty.services.WikittyListener;
@@ -171,7 +175,9 @@
@Override
public String login(String login, String password) {
- return "chausette";
+ // TODO mfortun-2011-04-18
+ throw new UnsupportedOperationException("not yet implemented");
+ //
}
@@ -345,7 +351,8 @@
PropertiesExtended idProperties = getWikittyPublicationProperties(
wikittyParenFile, WIKITTY_ID_PROPERTIES_FILE);
// update
- idProperties.setProperty(w.getId(), wikittyFile.getName());
+ idProperties.setProperty(w.getId(),
+ wikittyFile.getName());
// save
idProperties.store();
}
@@ -577,19 +584,44 @@
@Override
public List<PagedResult<String>> findAllByCriteria(String securityToken,
List<Criteria> criteria) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ 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());
+
+
+
+ }
+
+
+ return result;
+
}
@Override
public List<String> findByCriteria(String securityToken,
List<Criteria> criteria) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ List<String> result = new ArrayList<String>();
+ result.add("");
+
+ System.out.println(criteria.get(0).getRestriction());
+ return result;
}
@Override
@@ -788,8 +820,6 @@
return result;
}
-
-
/**
* Method that create a list of the properties directory
*
1
0
r815 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 18 Apr '11
by mfortun@users.nuiton.org 18 Apr '11
18 Apr '11
Author: mfortun
Date: 2011-04-18 16:19:45 +0200 (Mon, 18 Apr 2011)
New Revision: 815
Url: http://nuiton.org/repositories/revision/wikitty/815
Log:
* synchronisation between wikitty service works.
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
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-18 08:59:39 UTC (rev 814)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-18 14:19:45 UTC (rev 815)
@@ -39,9 +39,11 @@
import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.WikittyUtil;
import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyImpl;
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.entities.WikittyUserHelper;
import org.nuiton.wikitty.entities.WikittyUserImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubText;
@@ -65,8 +67,6 @@
final static private Log log = LogFactory.getLog(WikittyPublication.class);
static protected ApplicationConfig applicationConfig;
-
-
/*
* static string for allias, wrong named attribut TODO mfortun-2011-04-06
@@ -131,7 +131,6 @@
URI uriTarget = new URI(target);
-
boolean isDelete = applicationConfig
.getOptionAsBoolean(IS_DELETE_OPTION);
boolean isExisting = applicationConfig
@@ -144,7 +143,7 @@
* the correct implementation of the wikitty service
*/
// once on the service origin
- ApplicationConfig temp1 =setUpApplicationConfigServerConnector(uriOrigin);
+ ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin);
WikittyProxy proxyOrigin = new WikittyProxy(
WikittyServiceFactory.buildWikittyService(temp1));
@@ -154,20 +153,7 @@
WikittyProxy proxyTarget = new WikittyProxy(
WikittyServiceFactory.buildWikittyService(temp2));
-
-
- WikittyUser test1= new WikittyUserImpl();
- test1.setLogin("chaussetteé");
-
- WikittyUser test2= new WikittyUserImpl();
- test2.setLogin("chaussette");
-
- proxyOrigin.store(test1);
- System.out.println(test1.getWikittyVersion());
- test1.setLogin("ponay");
- proxyTarget.store(test1);
- //proxyTarget.st
-
+
/*
* TODO mfortun-2011-04-14 voir comment on fait quand les deux uris
* déclare des labels en fragment, si on les composent ensemble ou un
@@ -179,8 +165,6 @@
Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur);
Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur);
-
-
List<String> listOrigin = proxyOrigin.findAllIdByCriteria(critOrigin)
.getAll();
List<String> listTarget = proxyTarget.findAllIdByCriteria(critTarget)
@@ -201,13 +185,11 @@
existOnlyOnTarget.addAll(listTarget);
existOnlyOnTarget.removeAll(listOrigin);
-
-
/*
* if option is update send wikitty that are not in the target.
*/
if (isUpdate) {
-
+
List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin);
proxyTarget.storeWikitty(newWikitties);
@@ -227,27 +209,33 @@
/*
* case existing and update, update those which are on both location
*/
- for (String id : existInBoth){
+ for (String id : existInBoth) {
Wikitty fromTarget = proxyTarget.restore(id);
Wikitty fromOrigin = proxyOrigin.restore(id);
-
- String idTarget = fromTarget.getId();
- String idOrigin = fromOrigin.getId();
- //check version for update
- if (WikittyUtil.versionGreaterThan(idOrigin, idTarget)){
- Set<String> setLabelTarget= WikittyLabelHelper.getLabels(fromTarget);
- //replace labels origins, by target
- WikittyLabelHelper.setLabels(fromOrigin, setLabelTarget);
- //send modified origin to target wikitty service
- proxyTarget.store(fromOrigin);
+
+ String versionTarget = fromTarget.getVersion();
+
+ String versionOrigin = fromOrigin.getVersion();
+
+ // check version for update
+
+ /*
+ * TODO mfortun-2011-14-18 do something for labels at this time
+ * we replace origin labels y target's labels if we udpate.
+ */
+ if (WikittyUtil
+ .versionGreaterThan(versionOrigin, versionTarget)) {
+ Set<String> setLabelTarget = WikittyLabelHelper
+ .getLabels(fromTarget);
+ // replace labels origins, by targets label
+ WikittyLabelHelper.setLabels(fromOrigin, setLabelTarget);
+ // send modified origin to target wikitty service
+ proxyTarget.store(fromOrigin);
}
}
-
-
- }
+ }// */
-
}
/**
@@ -297,41 +285,38 @@
* @param uri
* of the targeted wikitty service
*/
- static protected ApplicationConfig setUpApplicationConfigServerConnector(URI uri) {
+ static protected ApplicationConfig setUpApplicationConfigServerConnector(
+ URI uri) {
-
-
-
ApplicationConfig result = new ApplicationConfig();
-
-
+
+ // transfert main properties to new application config
result.setOptions(applicationConfig.getFlatOptions());
- if (uri.getScheme().equals("file")) {
- result
- .setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem");
- }
- if (uri.getScheme().equals("cajo")) {
+ if (uri.getScheme().equals("file")) {
result.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem");
+ } else if (uri.getScheme().equals("cajo")) {
+ result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- if (uri.getScheme().equals("hessian")) {
+ } else if (uri.getScheme().equals("hessian")) {
result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceHessianClient");
}
-
- String url= uri.toASCIIString().replace("#wp", "");
-
- //FIXME mfortun-2011-04-15 correct url by removing fragment
- result.setOption("wikitty.service.server.url",
- url);
-
+ String url = uri.toASCIIString();
+ // remove fragment from the uri.
+ url = url.replaceAll("\\#.*", "");
+ // set protocol to http no use finally
+ /*
+ * url = url.replaceFirst("["+uri.getScheme()+"]", "http");
+ */
+
+ log.info("set url " + url + " with component :"+ result.getOption("wikitty.WikittyService.components"));
+
+ result.setOption("wikitty.service.server.url", url);
+
return result;
-
-
}
}
1
0
r814 - in trunk/wikitty-publication/src/main: java/org/nuiton/wikitty/publication/synchro resources
by mfortun@users.nuiton.org 18 Apr '11
by mfortun@users.nuiton.org 18 Apr '11
18 Apr '11
Author: mfortun
Date: 2011-04-18 10:59:39 +0200 (Mon, 18 Apr 2011)
New Revision: 814
Url: http://nuiton.org/repositories/revision/wikitty/814
Log:
* need to debug store to see what going on and why two store on the wame wikitty by two different wikitty service won't work
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.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-15 15:54:11 UTC (rev 813)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-18 08:59:39 UTC (rev 814)
@@ -24,6 +24,8 @@
*/
package org.nuiton.wikitty.publication.synchro;
+import gnu.cajo.Cajo;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@@ -39,10 +41,13 @@
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyLabel;
import org.nuiton.wikitty.entities.WikittyLabelHelper;
+import org.nuiton.wikitty.entities.WikittyUser;
+import org.nuiton.wikitty.entities.WikittyUserImpl;
import org.nuiton.wikitty.publication.entities.WikittyPubData;
import org.nuiton.wikitty.publication.entities.WikittyPubText;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.search.Search;
+import org.nuiton.wikitty.services.WikittyServiceCajoClient;
/**
* Main class of the sync part of wikitty publication, this class is the entry
@@ -60,6 +65,8 @@
final static private Log log = LogFactory.getLog(WikittyPublication.class);
static protected ApplicationConfig applicationConfig;
+
+
/*
* static string for allias, wrong named attribut TODO mfortun-2011-04-06
@@ -124,6 +131,7 @@
URI uriTarget = new URI(target);
+
boolean isDelete = applicationConfig
.getOptionAsBoolean(IS_DELETE_OPTION);
boolean isExisting = applicationConfig
@@ -136,17 +144,30 @@
* the correct implementation of the wikitty service
*/
// once on the service origin
- setUpApplicationConfigServerConnector(uriOrigin);
+ ApplicationConfig temp1 =setUpApplicationConfigServerConnector(uriOrigin);
WikittyProxy proxyOrigin = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(applicationConfig));
+ WikittyServiceFactory.buildWikittyService(temp1));
// once on the service target
- setUpApplicationConfigServerConnector(uriTarget);
+ ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget);
WikittyProxy proxyTarget = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(applicationConfig));
-
+ WikittyServiceFactory.buildWikittyService(temp2));
+
+
+ WikittyUser test1= new WikittyUserImpl();
+ test1.setLogin("chaussetteé");
+
+ WikittyUser test2= new WikittyUserImpl();
+ test2.setLogin("chaussette");
+
+ proxyOrigin.store(test1);
+ System.out.println(test1.getWikittyVersion());
+ test1.setLogin("ponay");
+ proxyTarget.store(test1);
+ //proxyTarget.st
+
/*
* TODO mfortun-2011-04-14 voir comment on fait quand les deux uris
* déclare des labels en fragment, si on les composent ensemble ou un
@@ -158,6 +179,8 @@
Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur);
Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur);
+
+
List<String> listOrigin = proxyOrigin.findAllIdByCriteria(critOrigin)
.getAll();
List<String> listTarget = proxyTarget.findAllIdByCriteria(critTarget)
@@ -178,12 +201,12 @@
existOnlyOnTarget.addAll(listTarget);
existOnlyOnTarget.removeAll(listOrigin);
+
+
/*
* if option is update send wikitty that are not in the target.
*/
if (isUpdate) {
-
- //FIXME mfortun-2011-04-15 something wrong it does not works
List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin);
proxyTarget.storeWikitty(newWikitties);
@@ -274,28 +297,41 @@
* @param uri
* of the targeted wikitty service
*/
- static protected void setUpApplicationConfigServerConnector(URI uri) {
+ static protected ApplicationConfig setUpApplicationConfigServerConnector(URI uri) {
+
+
+
+ ApplicationConfig result = new ApplicationConfig();
+
+
+ result.setOptions(applicationConfig.getFlatOptions());
if (uri.getScheme().equals("file")) {
- applicationConfig
+ result
.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem");
}
if (uri.getScheme().equals("cajo")) {
- applicationConfig.setOption("wikitty.WikittyService.components",
+ result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
}
if (uri.getScheme().equals("hessian")) {
- applicationConfig.setOption("wikitty.WikittyService.components",
+ result.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceHessianClient");
}
+ String url= uri.toASCIIString().replace("#wp", "");
+
//FIXME mfortun-2011-04-15 correct url by removing fragment
- applicationConfig.setOption("wikitty.service.server.url",
- uri.toASCIIString());
+ result.setOption("wikitty.service.server.url",
+ url);
+
+ 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-15 15:54:11 UTC (rev 813)
+++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties 2011-04-18 08:59:39 UTC (rev 814)
@@ -22,4 +22,4 @@
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
-wikitty.data.directory=/var/lib/wikitty-publication/codelutin
+wikitty.data.directory=/var/lib/wikitty-publication/codelutin2
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-15 15:54:11 UTC (rev 813)
+++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2011-04-18 08:59:39 UTC (rev 814)
@@ -22,7 +22,7 @@
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
# #L%
###
-wikitty.data.directory=./target/data
+wikitty.data.directory=./target2/data
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
1
0