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
Author: jcouteau
Date: 2011-04-13 17:28:26 +0200 (Wed, 13 Apr 2011)
New Revision: 803
Url: http://nuiton.org/repositories/revision/wikitty/803
Log:
Fix pom
Modified:
trunk/wikitty-publication/pom.xml
Modified: trunk/wikitty-publication/pom.xml
===================================================================
--- trunk/wikitty-publication/pom.xml 2011-04-13 15:15:32 UTC (rev 802)
+++ trunk/wikitty-publication/pom.xml 2011-04-13 15:28:26 UTC (rev 803)
@@ -24,13 +24,13 @@
</dependency>
<dependency>
<groupId>org.nuiton.wikitty</groupId>
- <artifactId>wikitty-jdbc-impl</artifactId>
+ <artifactId>wikitty-jdbc</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.nuiton.wikitty</groupId>
- <artifactId>wikitty-solr-impl</artifactId>
+ <artifactId>wikitty-solr</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
@@ -71,19 +71,6 @@
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.nuiton.wikitty</groupId>
- <artifactId>wikitty-solr</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.nuiton.wikitty</groupId>
- <artifactId>wikitty-jdbc</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
</dependencies>
<!-- ************************************************************* -->
1
0
r802 - in trunk/wikitty-publication: . src/main/java/org/nuiton/wikitty/publication
by mfortun@users.nuiton.org 13 Apr '11
by mfortun@users.nuiton.org 13 Apr '11
13 Apr '11
Author: mfortun
Date: 2011-04-13 17:15:32 +0200 (Wed, 13 Apr 2011)
New Revision: 802
Url: http://nuiton.org/repositories/revision/wikitty/802
Log:
* remove old class
Removed:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
Modified:
trunk/wikitty-publication/pom.xml
Modified: trunk/wikitty-publication/pom.xml
===================================================================
--- trunk/wikitty-publication/pom.xml 2011-04-13 15:12:01 UTC (rev 801)
+++ trunk/wikitty-publication/pom.xml 2011-04-13 15:15:32 UTC (rev 802)
@@ -72,6 +72,18 @@
<artifactId>commons-fileupload</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-solr</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-jdbc</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
<!-- ************************************************************* -->
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java 2011-04-13 15:12:01 UTC (rev 801)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java 2011-04-13 15:15:32 UTC (rev 802)
@@ -1,76 +0,0 @@
-package org.nuiton.wikitty.publication;
-
-/**
- *
- * Class usefull to save location and file name of a wikitty on a file system
- *
- * @author mfortun
- *
- */
-public class FileSystemWIkittyId {
-
- protected String fileName;
- protected String path;
-
- public String getFileName() {
- return fileName;
- }
-
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public FileSystemWIkittyId(String fileName, String path) {
- super();
- this.setFileName(fileName);
- this.setPath(path);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result
- + ((fileName == null) ? 0 : fileName.hashCode());
- result = prime * result + ((path == null) ? 0 : path.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof FileSystemWIkittyId)) {
- return false;
- }
- FileSystemWIkittyId other = (FileSystemWIkittyId) obj;
- if (fileName == null) {
- if (other.fileName != null) {
- return false;
- }
- } else if (!fileName.equals(other.fileName)) {
- return false;
- }
- if (path == null) {
- if (other.path != null) {
- return false;
- }
- } else if (!path.equals(other.path)) {
- return false;
- }
- return true;
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java 2011-04-13 15:12:01 UTC (rev 801)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java 2011-04-13 15:15:32 UTC (rev 802)
@@ -1,39 +0,0 @@
-package org.nuiton.wikitty.publication;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.util.Properties;
-
-/**
- * Class usefull when load properties file, update, delete, then save again
- * File used to load properties is store.
- *
- * @author mfortun
- *
- */
-public class PropertiesExtended extends Properties {
-
- /**
- *
- */
- private static final long serialVersionUID = -264337198024996529L;
-
- protected File origin;
-
- public PropertiesExtended(File origin) throws Exception {
- super();
- this.load(origin);
-
- }
-
- public void load(File file) throws Exception {
- this.origin = file;
- this.load(new FileReader(origin));
- }
-
- public void store() throws Exception {
- this.store(new FileWriter(origin), "");
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-13 15:12:01 UTC (rev 801)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-13 15:15:32 UTC (rev 802)
@@ -1,803 +0,0 @@
-/*
- * #%L
- * Wikitty :: publication
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin mfortun
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.publication;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.commons.collections.BidiMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.ApplicationConfig;
-import org.nuiton.util.ArgumentsParserException;
-import org.nuiton.util.CollectionUtil;
-import org.nuiton.util.FileUtil;
-import org.nuiton.wikitty.WikittyProxy;
-import org.nuiton.wikitty.WikittyServiceFactory;
-import org.nuiton.wikitty.entities.Wikitty;
-import org.nuiton.wikitty.entities.WikittyLabel;
-import org.nuiton.wikitty.entities.WikittyLabelHelper;
-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.PagedResult;
-import org.nuiton.wikitty.search.Search;
-
-/**
- * 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.
- *
- *
- *
- * @author mfortun
- *
- */
-public class WikittyPublication {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- 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
- * need to set better name
- */
-
- /*
- * FIXME mfortun-2011-04-11 need to migrate static value to another class ?
- */
- static public String WITTY_SERVICE_KEY = "wikitty.service.server.url";
- static public String NO_RECURSION_KEY = "norecursion";
- static public String DIRECTORY_KEY = "directory";
- static public String HESSIAN_PROTOCOL_KEY = "hessian";
-
- static public String DEFAULT_PROPERTY_NAME_SEP = ".";
-
- static public String PROPERTY_DIRECTORY = ".wp";
- static public String WIKITTYPUBLICATION_PROPERTIES_FILE = "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()
- */
- static public String WIKITTY_ID_PROPERTIES_FILE = "ids.properties";
- static public String WIKITTY_FILE_META_PROPERTIES_FILE = "meta.properties";
-
- /*
- * in the WIKITTY_FILE_META_PROP ERTIES_FILE the keys for version are:
- * filename + META_SUFFIX_KEY_VERSION we save the id too because with this
- * solution un case of delete we can easily read the id and make operation
- * on the wikitty
- */
- static public String META_SUFFIX_KEY_VERSION = "version";
- static public String META_SUFFIX_KEY_CHECKSUM = "checksum";
- static public String META_SUFFIX_KEY_ID = "id";
-
- static public String META_CURRENT_LABEL = "current.label";
-
- /**
- * @param args
- * @throws ArgumentsParserException
- */
- static public void main(String[] args) throws Exception {
-
- /*
- *
- */
-
- // on va creer un wikitty proxy pour le lien avec le wikitty qui stock
- // mes trucs
- // et on va avoir un wikittypublicationfilesystem pour stocker sur le
- // local et tout
- // soucis du wikittyFS c'est de savoir dans quel dossier il va taffer ?
- // a moins qu'il prenne un directory de travail
-
- /*
- * ws.properties :wikitty.service= http://www.adresse.com:8080
- *
- * wikittypubs.properties script.js=numéroVersion7 id.script.js= id du
- * wikitty scripttut.js=numéroVersion id.scripttut.js= id du wikitty
- * image.png=numéroVersion id.image.png= id du wikitty label=
- * racine.directory2, racine.directory22
- */
-
- applicationConfig = new ApplicationConfig();
-
- // allias for the url of the wikitty service
- applicationConfig.addAlias("--ws", "--option", WITTY_SERVICE_KEY);
-
- applicationConfig.addAlias("--dir", "--option", DIRECTORY_KEY);
-
- /*
- * TODO mfortun-2011-04-05 once application fixed setdefault value and
- * enumclass for initialisation
- */
-
- // allias for norecursion
- applicationConfig.addAlias("--norecursion", "--option",
- NO_RECURSION_KEY, "true");
-
- // allias for the protocole
- applicationConfig.addAlias("--hessian", "--option",
- HESSIAN_PROTOCOL_KEY, "true");
-
- // allias for all the action
- applicationConfig.addAlias("wp import", "--option", "import");
- applicationConfig.addAlias("wp checkout", "--option", "checkout");
- applicationConfig.addAlias("wp relocate", "--option", "relocate");
- applicationConfig.addAlias("wp commit", "--option", "commit");
- applicationConfig.addAlias("wp delete", "--option", "delete");
- applicationConfig.addAlias("wp update", "--option", "update");
-
- applicationConfig
- .addActionAlias("import",
- "org.nuiton.wikitty.publication.WikittyPublication#importToWikitty");
-
- applicationConfig
- .addActionAlias("checkout",
- "org.nuiton.wikitty.publication.WikittyPublication#checkoutFromWikitty");
-
- applicationConfig
- .addActionAlias("relocate",
- "org.nuiton.wikitty.publication.WikittyPublication#relocateWikitty");
-
- applicationConfig
- .addActionAlias("commit",
- "org.nuiton.wikitty.publication.WikittyPublication#commitToWikitty");
-
- applicationConfig
- .addActionAlias("delete",
- "org.nuiton.wikitty.publication.WikittyPublication#deleteFromWikitty");
-
- applicationConfig
- .addActionAlias("update",
- "org.nuiton.wikitty.publication.WikittyPublication#updateFromWikitty");
-
- // parsing
- applicationConfig.parse(args);
- // execution
- applicationConfig.doAction(0);
-
- }
-
- /**
- * Method that import the content of a directory into a wikitty service
- */
- static public void importToWikitty() throws Exception {
-
- boolean noRecur = applicationConfig
- .getOptionAsBoolean(NO_RECURSION_KEY);
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
- String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
-
- log.info("import : wikittyservice: " + wikittyService + " noresursion="
- + noRecur + " directory= " + dir.getAbsolutePath());
- // usage: wp --norecursion --ws http://truc.com import --dir /home/Manou
-
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
-
- System.out.println(applicationConfig
- .getOption("wikitty.service.server.url"));
-
- // real code:
- WikittyProxy remoteWikittyService = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(applicationConfig));
-
- remoteWikittyService.clear();
- // load the list of file
- List<File> toTransfert = listFile(dir, !noRecur);
-
- List<Wikitty> listWikitty = new ArrayList<Wikitty>();
- // transform file into wikitties
-
- for (File fileToTransform : toTransfert) {
- listWikitty.add(WikittyPublicationFileSystem.fileToWikitty(
- fileToTransform, dir));
- }
-
- // send the wikitties
- remoteWikittyService.storeWikitty(listWikitty);
-
- }
-
- /*
- * TODO mfortun-2011-04-05 just prototyping, remove when really implements
- * the method linked: importToWikitty
- */
- static public void printDirectory(File dir, boolean recur) {
-
- System.out.println("<dir " + dir.getName() + ">");
- for (File child : dir.listFiles()) {
- if (child.isDirectory() && recur
- && !child.getName().equals(PROPERTY_DIRECTORY)) {
- printDirectory(child, recur);
- } else if (!child.isDirectory()) {
- System.out.println(child.getAbsolutePath());
- }
- }
- System.out.println("</dir " + dir.getName() + ">");
- }
-
- /**
- * Method that create the list of file needed to commit, delete, update
- * import. It harvest file in order to transform them into wikitties
- *
- * @param starts
- * harvested directory
- * @param recursivly
- * boolean id the directory have to be harvest
- * @return list of harvested file
- */
- static protected List<File> listFile(File starts, boolean recursivly) {
- List<File> result = new ArrayList<File>();
- if (!starts.isDirectory()) {
- result.add(starts);
- }
- for (File child : starts.listFiles()) {
- if (child.isDirectory() && recursivly
- && !child.getName().equals(PROPERTY_DIRECTORY)) {
- // Directory don't have to be harvest
- // result.add(child);
- result.addAll(listFile(child, recursivly));
- } else if (!child.isDirectory()) {
- result.add(child);
- }
- }
- return result;
- }
-
- /**
- * Method that checkout a label recursivly or not into a local directory
- * from a wikitty service
- */
- static public void checkoutFromWikitty(String label) throws Exception {
-
- boolean noRecur = applicationConfig
- .getOptionAsBoolean(NO_RECURSION_KEY);
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
- String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- log.info("checkout : wikittyservice: " + wikittyService
- + " noresursion=" + noRecur + " directory= "
- + dir.getAbsolutePath() + "Label a checkout " + label
- + "HessianProtocol=" + hessianProtocole);
-
- if (hessianProtocole) {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- } else {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- WikittyProxy remoteWikittyService = new WikittyProxy(
- WikittyServiceFactory.buildWikittyService(applicationConfig));
- WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
- dir, !noRecur, label);
-
- // Construct the criteria
- Criteria labelCriteria;
- Search mainRequest = Search.query();
- Search subRoqu = mainRequest.or();
-
- // must have the type of wikittypubtext/wikittypubdata
- subRoqu.exteq(WikittyPubText.EXT_WIKITTYPUBTEXT).exteq(
- WikittyPubData.EXT_WIKITTYPUBDATA);
- if (noRecur) {
- // and extension with the name strictly equals to the label (no
- // recursivity)
- labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
- .eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
- .criteria();
-
- } else {
- // and extension with the name that containt the label (recursivity)
- labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
- .sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
- .criteria();
- }
-
- // request to the proxy
- PagedResult<Wikitty> pageResult = remoteWikittyService
- .findAllByCriteria(labelCriteria);
-
- List<Wikitty> wikittiesToWrite = pageResult.getAll();
-
- // write the proper properties file!
- writeHomePropertyFile(dir);
-
- // write the wikities
- localWikittyService.store("", wikittiesToWrite, true);
-
- /*
- * obtain the list of wikittypub and write then in the file system with
- * the appropriate wikittyservice !
- */
-
- /*
- * on va commencer par vérifier les arguments ''wp checkout
- * [--norecursion] [url du WikittyService] [Label à extraire] [directory
- * local d'accueil]'' on doit avoir trois string dans le unparsed: url,
- * label, directory et potentiellement quelque chose dans le getoption
- * recursion
- */
-
- }
-
- /**
- * Relocate the default url of the wikitty service
- */
- static public void relocateWikitty() throws Exception {
-
- /*
- * log.info("checkout : wikittyservice: " + wikittyService +
- * " noresursion=" + noRecur + " directory= " + dir.getAbsolutePath()
- * +"Label a checkout " +label+ "HessianProtocol="+hessianProtocole);
- */
-
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
- String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- File wpHomeDir;
-
- System.out
- .println("search the directory of .wp file to write new properties file");
- // search for the home directory
- if (null == dir || !dir.exists()) {
- wpHomeDir = searchWikittyPublicationHomeDir(new File("."));
- } else {
- wpHomeDir = new File(dir.getCanonicalFile() + File.separator
- + PROPERTY_DIRECTORY);
- }
-
- Properties oldProperties = new Properties();
-
- // TODO mfortun-2011-04-06 catch exception instead of throws
- File propertiesFile = new File(wpHomeDir + File.separator
- + WIKITTYPUBLICATION_PROPERTIES_FILE);
- // load the old file just for loggin
- oldProperties.load(new FileReader(propertiesFile));
-
- log.info("Try relocate :" + "wikitty service:"
- + oldProperties.getProperty(WITTY_SERVICE_KEY) + " by "
- + wikittyService + " HessianProtocol: " + hessianProtocole
- + " File : " + propertiesFile.getCanonicalPath());
-
- // Creation of the new properties file
- Properties props = new Properties();
- props.put(WITTY_SERVICE_KEY, wikittyService);
- if (hessianProtocole) {
- props.put("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- } else {
- props.put("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- // save the new property file
- props.store(new FileWriter(propertiesFile), "");
-
- /*
- * on va commencer par vérifier les arguments ''wp relocate [nouvelle
- * url du WikittyService par defaut] [directory a relocaliser]'' on doit
- * avoir trois string dans le unparsed: url et directory
- */
-
- }
-
- /**
- * commit the current wikittyworkspace into a wikitty service
- */
- static public void commitToWikitty() throws Exception {
-
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
-
- File wpHomeDir;
- if (null == dir || !dir.exists()) {
- /*
- * si pas de dir on commit le dossier courant
- */
- dir = new File(".");
-
- }
- // on va chercher le home dir
- wpHomeDir = searchWikittyPublicationHomeDir(dir);
-
- Properties properties = new Properties();
-
- // TODO mfortun-2011-04-06 catch exception instead of throws
- File propertiesFile = new File(wpHomeDir.getCanonicalPath()
- + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
- // load the old file just for loggin
- properties.load(new FileReader(propertiesFile));
-
- // on va rajouter les propriété de notre file
- applicationConfig.setOptions(properties);
-
- boolean noRecur = applicationConfig
- .getOptionAsBoolean(NO_RECURSION_KEY);
-
- String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- if (hessianProtocole) {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- } else {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- log.info("commit " + " wikitty-service" + wikittyService
- + "noRecurs : " + noRecur + " hessian Protocole :"
- + hessianProtocole + "directory : " + dir.getAbsolutePath());
-
- System.out.println("try to commit: ");
- printDirectory(dir, !noRecur);
-
- // faire la liste des fichiers à commit
- // avec récursivité si c'etransfert d'histoire entre svnst demandé.
- // et les transformer en wikitty, vérifier les versions et tout.
-
- /*
- * parcours l'arborescence des fichiers celon que on soit recursif ou
- * non plutot que faire la liste fichier, on va aller lire les ids dans
- * les fichiers de propriétés.
- *
- * Ensuite on creer le wikittyserviceFileSysteme avec le répertoire de
- * travail et lui on lui donner les ids avec lesquels il va travailler
- * et aller chercher les fichiers de propriétés pour retrouver les files
- * et creer les wikittypub correspondant.
- *
- * Pour faire un commit il ne suffira pas de faire un restore
- * finalement, il faudra faire un search aussi puisque on va se
- * retrouver à faire des new wikitty p'etre éclaircir ce point plus
- * tard. Pour le moment ne pas se poser de question trop, et faire sans
- * nouveau fichier.
- */
-
- // création du proxy
-
- /*
- * on va commencer par vérifier les arguments ''wp commit
- * [--norecursion] [--ws (url du WikittyService)] [répertoire à
- * pousser]'' on doit avoir deux string dans le unparsed et
- * potentiellement quelque chose dans le getoption recursion
- */
-
- }
-
- /**
- * delete a file or directory from the workspace it remove the label from
- * the wikitty
- *
- * @throws Exception
- */
- static public void deleteFromWikitty(File toDelete) throws Exception {
-
- // check args
- if (null == toDelete || !toDelete.exists()) {
- // Exception
-
- } else {
-
- File currentDir = new File(FileUtil.getCurrentDirectory()
- .getAbsolutePath());
- File wpHomeDir = searchWikittyPublicationHomeDir(currentDir);
- // search for the .wp home dir to load props
-
- // then load proxy
-
- // if toDelete is a directory do something different from usualy
- // recursivly remove labels
-
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
-
- Properties properties = new Properties();
-
- // TODO mfortun-2011-04-06 catch exception instead of throws
- File propertiesFile = new File(wpHomeDir.getCanonicalPath()
- + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
- // load the old file just for loggin
- properties.load(new FileReader(propertiesFile));
-
- // on va rajouter les propriété de notre file
- applicationConfig.setOptions(properties);
-
- String wikittyService = applicationConfig
- .getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- if (hessianProtocole) {
- applicationConfig
- .setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- } else {
- applicationConfig.setOption(
- "wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- log.info("Delete " + " wikitty-service" + wikittyService
- + " hessian Protocole :" + hessianProtocole
- + "file to delete : " + toDelete.getAbsolutePath());
- // on va chercher le home dir
- wpHomeDir = searchWikittyPublicationHomeDir(dir);
-
- WikittyProxy remoteWikittyService = new WikittyProxy(
- WikittyServiceFactory
- .buildWikittyService(applicationConfig));
- WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
- dir);
-
- if (toDelete.isDirectory()) {
-
- BidiMap deleteMap = WikittyPublicationFileSystem
- .harvestLocalWikitties(toDelete, true);
- List<String> ids = new ArrayList<String>();
- ids = new ArrayList<String>();
- ids.addAll(CollectionUtil.toGenericCollection(
- deleteMap.keySet(), String.class));
-
- for (String key : ids) {
- // restore wikitty
- Wikitty wd = remoteWikittyService.restore(key);
-
- // searh for the label to delete from the wikitty
- FileSystemWIkittyId location = (FileSystemWIkittyId) deleteMap
- .get(key);
-
- File wikittyFileParent = new File(location.getPath());
- PropertiesExtended metaExtended = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(
- wikittyFileParent,
- WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
-
- String currentLabel = metaExtended
- .getProperty(META_CURRENT_LABEL);
- // remove label
- WikittyLabelHelper.removeLabels(wd, currentLabel);
- // save the wikitty
- remoteWikittyService.store(wd);
- }
-
- localWikittyService.delete("", ids);
- // if it was a directory the wikitty file service does not have
- // delete it
-
- FileUtil.deleteRecursively(toDelete);
- } else {
- // infos about file about to delete
- String name = toDelete.getName();
- File parentFile = toDelete.getParentFile();
- // search of it's id
- PropertiesExtended metaProps = WikittyPublicationFileSystem
- .getWikittyPublicationProperties(
- parentFile,
- WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
-
- String id = metaProps.getProperty(name
- + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_ID);
- // his label
- String label = metaProps
- .getProperty(WikittyPublication.META_CURRENT_LABEL);
-
- // restore wikitty remote
-
- Wikitty wd = remoteWikittyService.restore(id);
-
- // remove label
-
- WikittyLabelHelper.removeLabels(wd, label);
- // save the wikitty remote
- remoteWikittyService.store(wd);
-
- List<String> ids = new ArrayList<String>();
- ids.add(id);
- // delete localy
- localWikittyService.delete("", ids);
- }
-
- }
-
- /*
- * on va commencer par vérifier les arguments ''wp delete [--ws (url du
- * WikittyService)] [répertoire ou fichier à supprimer]'' on doit avoir
- * un string dans le unparsed et après pour pour le wikittyservice bah
- * on tape dedans en fonction de si elle a été précisé en ligne de
- * commande applicationConfig se débrouille
- */
- }
-
- /**
- * update the current workspace from a wikitty
- */
- static public void updateFromWikitty() throws Exception {
-
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
-
- File wpHomeDir;
- if (null == dir || !dir.exists()) {
- /*
- * si pas de dir on update le dossier courant
- */
- dir = new File(".");
-
- }
- // on va chercher le home dir
- wpHomeDir = searchWikittyPublicationHomeDir(dir);
-
- Properties properties = new Properties();
-
- // TODO mfortun-2011-04-06 catch exception instead of throws
- File propertiesFile = new File(wpHomeDir.getCanonicalPath()
- + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
- // load the old file just for loggin
- properties.load(new FileReader(propertiesFile));
-
- // on va rajouter les propriété de notre file
- applicationConfig.setOptions(properties);
-
- boolean noRecur = applicationConfig
- .getOptionAsBoolean(NO_RECURSION_KEY);
-
- String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- if (hessianProtocole) {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceHessianClient");
- } else {
- applicationConfig.setOption("wikitty.WikittyService.components",
- "org.nuiton.wikitty.services.WikittyServiceCajoClient");
- }
-
- log.info("update " + " wikitty-service" + wikittyService
- + "noRecurs : " + noRecur + " hessian Protocole :"
- + hessianProtocole + "directory : " + dir.getAbsolutePath());
-
- System.out.println("try to update: ");
- printDirectory(dir, !noRecur);
-
- /*
- * on va commencer par vérifier les arguments * ''wp update
- * [--norecursion] [--ws (url du WikittyService)] [répertoire à mettre à
- * jour]'' normalement un string dans unparsed et potentiellement
- * quelque chose dans le recursion
- */
- }
-
- /**
- *
- * Use to search in the file system the directory that containt the .wp dir
- * that containt the properties file for the wikitty service's adresse
- *
- * @param start
- * @return File the directory container of the master property file
- * @throws Exception
- */
- static protected File searchWikittyPublicationHomeDir(File start)
- throws Exception {
-
- if (start != null && start.exists() && start.isDirectory()) {
- // on va retourner le dossier .wp home
-
- // method récursiv qui remonte dans les parents pour retrouver.
-
- File propertyDirectory = new File(start.getCanonicalPath()
- + File.separator + PROPERTY_DIRECTORY);
-
- if (propertyDirectory.exists()) {
- File propertie = new File(propertyDirectory.getCanonicalPath()
- + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
- if (propertie.exists()) {
- return propertyDirectory;
- }
- }
-
- return searchWikittyPublicationHomeDir(start.getParentFile());
- } else {
- // Exception
- /*
- * TODO mfortun-2011-04-06 write/set the appropriate exception here
- */
- return null;
- }
- }
-
- static protected void writeHomePropertyFile(File homeDir) throws Exception {
-
- if (homeDir.exists()) {
- File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
- String wikittyService = applicationConfig
- .getOption(WITTY_SERVICE_KEY);
- boolean hessianProtocole = applicationConfig
- .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
- // TODO mfortun-2011-04-11 find a better way to manage component
- // property
- String propertyCompo = applicationConfig
- .getOption("wikitty.WikittyService.components");
- // write the proper properties file!
- Properties props = new Properties();
- props.put(WITTY_SERVICE_KEY, wikittyService);
-
- props.put("wikitty.WikittyService.components", propertyCompo);
-
- // create the properties directory
- File wpDirectory = new File(homeDir.getCanonicalPath()
- + File.separator + PROPERTY_DIRECTORY + File.separator);
- if (!wpDirectory.exists()) {
- wpDirectory.mkdir();
- }
-
- File propertiesFiles = new File(wpDirectory.getCanonicalPath()
- + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
-
- props.store(new FileWriter(propertiesFiles), "");
- }
- }
-
- /**
- * Method that create a list of the properties directory
- *
- * @param starts
- * harvested directory
- * @param recursivly
- * @return list of harvested file
- */
- static public List<File> harvestPropertyDirectory(File starts,
- boolean recursivly) {
-
- List<File> result = new ArrayList<File>();
-
- for (File child : starts.listFiles()) {
-
- if (child.isDirectory()
- && child.getName().equals(PROPERTY_DIRECTORY)) {
- result.add(child);
- } else if (child.isDirectory() && recursivly) {
- result.addAll(harvestPropertyDirectory(child, recursivly));
- }
- }
- return result;
-
- }
-
-}
Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 15:12:01 UTC (rev 801)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 15:15:32 UTC (rev 802)
@@ -1,836 +0,0 @@
-/*
- * #%L
- * Wikitty :: publication
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 - 2011 CodeLutin mfortun
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.publication;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-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;
-import org.apache.commons.collections.bidimap.DualHashBidiMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.FileUtil;
-import org.nuiton.util.MD5InputStream;
-import org.nuiton.util.StringUtil;
-import org.nuiton.wikitty.WikittyService;
-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.publication.entities.WikittyPubData;
-import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
-import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
-import org.nuiton.wikitty.publication.entities.WikittyPubText;
-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.services.WikittyEvent;
-import org.nuiton.wikitty.services.WikittyListener;
-
-public class WikittyPublicationFileSystem implements WikittyService {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- final static private Log log = LogFactory
- .getLog(WikittyPublicationFileSystem.class);
-
- static public String WIKITTYLABEL_SEPARATOR = ".";
-
- protected File homeFile;
- protected boolean recursion;
- protected String label;
-
- /**
- * Constructor with the working directory
- *
- * @param home
- * the home directory
- */
- public WikittyPublicationFileSystem(File home, boolean recur, String label) {
- this.setHomeFile(home);
- this.setRecursion(recur);
- this.setLabel(label);
- }
-
-
-
-
- public WikittyPublicationFileSystem(File homeFile) {
- this(homeFile, true, "");
-
- }
-
-
-
-
- public File getHomeFile() {
- return homeFile;
- }
-
- public void setHomeFile(File homeFile) {
- this.homeFile = homeFile;
- }
-
- public boolean isRecursion() {
- return recursion;
- }
-
- public void setRecursion(boolean recursion) {
- this.recursion = recursion;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- @Override
- public void addWikittyServiceListener(WikittyListener listener,
- ServiceListenerType type) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- //
-
- }
-
- @Override
- public void removeWikittyServiceListener(WikittyListener listener,
- ServiceListenerType type) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- //
-
- }
-
- @Override
- public String login(String login, String password) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public void logout(String securityToken) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- //
-
- }
-
- @Override
- public WikittyEvent clear(String securityToken) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public boolean canWrite(String securityToken, Wikitty wikitty) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return false;
-
- }
-
- @Override
- public boolean canDelete(String securityToken, String wikittyId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return false;
-
- }
-
- @Override
- public boolean canRead(String securityToken, String wikittyId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return false;
-
- }
-
- @Override
- public boolean exists(String securityToken, String wikittyId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return false;
-
- }
-
- @Override
- public boolean isDeleted(String securityToken, String wikittyId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return false;
-
- }
-
- @Override
- public WikittyEvent replay(String securityToken, List<WikittyEvent> events,
- boolean force) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyEvent store(String securityToken,
- Collection<Wikitty> wikitties, boolean force) {
-
- try {
-
- for (Wikitty w : wikitties) {
-
- Set<String> set = WikittyLabelHelper.getLabels(w);
- String ourDir = "";
-
- // search for our label
- for (String name : set) {
- if (!recursion && name.equalsIgnoreCase(label)) {
- ourDir = name;
- } else if (recursion && name.startsWith(label)) {
- ourDir = name;
- }
- }
-
- // create the directories from the label
- boolean pathFilecreated = createFilesFromLabelPath(ourDir);
-
- if (pathFilecreated) {
- // create the path with the label
- String path = homeFile.getCanonicalFile() + File.separator
- + ourDir.replace(".", File.separator);
-
- // correct the pb with directory name begin by .
- path = path.replace(File.separator + File.separator,
- File.separator + ".");
-
- // create the propertie directory if necessary
- File propertieDirectory = new File(path + File.separator
- + WikittyPublication.PROPERTY_DIRECTORY);
- if (!propertieDirectory.exists()
- || !propertieDirectory.isDirectory()) {
- propertieDirectory.mkdir();
- }
- // load/create meta propertie file
- File propertieFile = new File(
- propertieDirectory.getCanonicalPath()
- + File.separator
- + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
- if (!propertieFile.exists()) {
- propertieFile.createNewFile();
- }
-
- // load/create id propertie file
- File idPropertieFile = new File(
- propertieDirectory.getCanonicalPath()
- + File.separator
- + WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
- if (!idPropertieFile.exists()) {
- idPropertieFile.createNewFile();
- }
-
- String name = "";
- String extension = "";
-
- File wikittyFile = null;
- if (w.hasExtension(WikittyPubData.EXT_WIKITTYPUBDATA)) {
- name = WikittyPubDataHelper.getName(w);
- String mime = WikittyPubDataHelper.getMimeType(w);
- byte[] content = WikittyPubDataHelper.getContent(w);
-
- extension = extensionFormimeType(mime);
-
- wikittyFile = new File(path + File.separator + name
- + "." + extension);
-
- wikittyFile.createNewFile();
-
- FileUtil.byteToFile(content, wikittyFile);
-
- } else if (w
- .hasExtension(WikittyPubText.EXT_WIKITTYPUBTEXT)) {
- name = WikittyPubTextHelper.getName(w);
- String mime = WikittyPubTextHelper.getMimeType(w);
- String content = WikittyPubTextHelper.getContent(w);
-
- extension = extensionFormimeType(mime);
-
- wikittyFile = new File(path + File.separator + name
- + "." + extension);
-
- wikittyFile.createNewFile();
-
- FileUtil.writeString(wikittyFile, content);
- }
-
- 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
- Properties metaProperties = new Properties();
- metaProperties.load(new FileReader(propertieFile));
- // update
- metaProperties.setProperty(
- WikittyPublication.META_CURRENT_LABEL, ourDir);
-
- metaProperties.setProperty(name + "." + extension
- + ".version", w.getVersion());
- metaProperties.setProperty(name + "." + extension
- + ".id", w.getId());
- metaProperties.setProperty(name + "." + extension
- + ".checksum", localMd5);
- // save
- metaProperties.store(new FileWriter(propertieFile), "");
- // load id properties
- Properties idProperties = new Properties();
- idProperties.load(new FileReader(idPropertieFile));
- // update
- idProperties.setProperty(w.getId(), name + "."
- + extension);
- // save
- idProperties.store(new FileWriter(idPropertieFile), "");
- }
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- // TODO mfortun-2011-04-12 really handle exceptions
- }
-
- WikittyEvent result = new WikittyEvent(this);
-
- return result;
- }
-
- @Override
- public List<String> getAllExtensionIds(String securityToken) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public List<String> getAllExtensionsRequires(String securityToken,
- String extensionName) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyEvent storeExtension(String securityToken,
- Collection<WikittyExtension> exts) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyEvent deleteExtension(String securityToken,
- Collection<String> extNames) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyExtension restoreExtension(String securityToken,
- String extensionId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyExtension restoreExtensionLastVersion(String securityToken,
- String name) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public List<Wikitty> restore(String securityToken, List<String> id) {
- List<Wikitty> result = new ArrayList<Wikitty>();
- try {
- BidiMap locations = harvestLocalWikitties(homeFile, recursion);
-
- for (String wikid : id) {
- Object value = locations.get(wikid);
-
- if (value == null) {
- locations = locations.inverseBidiMap();
- value = locations.get(wikid);
- }
-
- if (value != null) {
-
- 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
- Properties props = new Properties();
- File propsFile = new File(
- path
- + File.separator
- + WikittyPublication.PROPERTY_DIRECTORY
- + File.separator
- + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
- props.load(new FileReader(propsFile));
- // re set the id
- wikitty.setVersion(props.getProperty(completeName
- + WikittyPublication.META_SUFFIX_KEY_ID));
-
- // set the current label
- WikittyLabelHelper
- .addLabels(
- wikitty,
- props.getProperty(WikittyPublication.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);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- // TODO mfortun-2011-01-12 really handle exception
- }
- return result;
- }
-
- @Override
- public WikittyEvent delete(String securityToken, Collection<String> ids) {
-
- try {
- BidiMap location = harvestLocalWikitties(homeFile, true);
-
- for (String id : ids) {
-
- Object value = location.get(id);
-
- if (value == null) {
- location = location.inverseBidiMap();
- value = location.get(id);
- }
-
- if (value != null) {
-
- FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
-
- String path = localisation.getPath();
- String fileName = localisation.getFileName();
-
- // load properties
- PropertiesExtended propsProperties = getWikittyPublicationProperties(new File(
- path), WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
-
- // update
- propsProperties.remove(fileName
- + WikittyPublication.META_SUFFIX_KEY_CHECKSUM);
- propsProperties.remove(fileName
- + WikittyPublication.META_SUFFIX_KEY_ID);
- propsProperties.remove(fileName
- + WikittyPublication.META_SUFFIX_KEY_VERSION);
-
- // resave
- propsProperties.store();
-
- // load properties
- PropertiesExtended idProperties = getWikittyPublicationProperties(new File(
- path), WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
- // update
- idProperties.remove(id);
- // resave
- idProperties.store();
-
- File wikittyFile = new File(path + File.separator
- + fileName);
-
- if (wikittyFile.exists()) {
- wikittyFile.delete();
- }
-
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- // TODO mfortun-2011-04-13 really handle exception
- }
-
- WikittyEvent result = new WikittyEvent(this);
- return result;
- }
-
- @Override
- public List<PagedResult<String>> findAllByCriteria(String securityToken,
- List<Criteria> criteria) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public List<String> findByCriteria(String securityToken,
- List<Criteria> criteria) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public WikittyEvent deleteTree(String securityToken, String treeNodeId) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public TreeNodeResult<String> findTreeNode(String securityToken,
- String wikittyId, int depth, boolean count, Criteria filter) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public Wikitty restoreVersion(String securityToken, String wikittyId,
- String version) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
-
- }
-
- @Override
- public void syncSearchEngine(String securityToken) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- //
-
- }
-
- /**
- * 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
- */
- static public Wikitty fileToWikitty(File fileToTransform, File starts)
- 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;
- }
- }
-
- /**
- * 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;
- }
-
- /**
- *
- * @param starts
- * @param recursivly
- * @return
- * @throws Exception
- */
- static public BidiMap harvestLocalWikitties(File starts, boolean recursivly)
- throws Exception {
- BidiMap result = new DualHashBidiMap();
-
- List<File> propertiesDirectory = WikittyPublication
- .harvestPropertyDirectory(starts, recursivly);
-
- for (File propsDir : propertiesDirectory) {
-
- Properties idProps = new Properties();
- File idFile = new File(propsDir.getCanonicalPath() + File.separator
- + WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
- if (idFile.exists()) {
- idProps.load(new FileReader(idFile));
- }
-
- Set<Object> ids = idProps.keySet();
-
- for (Object id : ids) {
- String name = idProps.getProperty((String) id);
- String path = propsDir.getParent();
- FileSystemWIkittyId value = new FileSystemWIkittyId(name, path);
-
- result.put((String) id, value );
- }
-
- }
-
- /*
- * Pour l'arborescence des fichiers on va aller chercher les fichiers de
- * propriété id et meta dans le dossier .wp pour aller récup les labels
- * courant et les id liés on va renvoyer la map
- *
- * id, label
- */
-
- return result;
- }
-
- static public PropertiesExtended getWikittyPublicationProperties(File starts, String name)
- throws Exception {
-
- File propertieDirectory = new File(starts.getCanonicalPath()
- + File.separator + WikittyPublication.PROPERTY_DIRECTORY);
-
- // load/create meta propertie file
- File propertieFile = new File(propertieDirectory.getCanonicalPath()
- + File.separator
- + name);
- if (!propertieFile.exists()) {
- propertieFile.createNewFile();
- }
-
- PropertiesExtended result = new PropertiesExtended(propertieFile);
-
- return result;
- }
-
-
-
-
-}
1
0
r801 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 13 Apr '11
by mfortun@users.nuiton.org 13 Apr '11
13 Apr '11
Author: mfortun
Date: 2011-04-13 17:12:01 +0200 (Wed, 13 Apr 2011)
New Revision: 801
Url: http://nuiton.org/repositories/revision/wikitty/801
Log:
* new package for the synchro part.
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/FileSystemWIkittyId.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java
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
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/FileSystemWIkittyId.java (from rev 798, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/FileSystemWIkittyId.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/FileSystemWIkittyId.java 2011-04-13 15:12:01 UTC (rev 801)
@@ -0,0 +1,76 @@
+package org.nuiton.wikitty.publication.synchro;
+
+/**
+ *
+ * Class usefull to save location and file name of a wikitty on a file system
+ *
+ * @author mfortun
+ *
+ */
+public class FileSystemWIkittyId {
+
+ protected String fileName;
+ protected String path;
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public FileSystemWIkittyId(String fileName, String path) {
+ super();
+ this.setFileName(fileName);
+ this.setPath(path);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((fileName == null) ? 0 : fileName.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof FileSystemWIkittyId)) {
+ return false;
+ }
+ FileSystemWIkittyId other = (FileSystemWIkittyId) obj;
+ if (fileName == null) {
+ if (other.fileName != null) {
+ return false;
+ }
+ } else if (!fileName.equals(other.fileName)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/FileSystemWIkittyId.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java (from rev 798, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java 2011-04-13 15:12:01 UTC (rev 801)
@@ -0,0 +1,39 @@
+package org.nuiton.wikitty.publication.synchro;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.Properties;
+
+/**
+ * Class usefull when load properties file, update, delete, then save again
+ * File used to load properties is store.
+ *
+ * @author mfortun
+ *
+ */
+public class PropertiesExtended extends Properties {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -264337198024996529L;
+
+ protected File origin;
+
+ public PropertiesExtended(File origin) throws Exception {
+ super();
+ this.load(origin);
+
+ }
+
+ public void load(File file) throws Exception {
+ this.origin = file;
+ this.load(new FileReader(origin));
+ }
+
+ public void store() throws Exception {
+ this.store(new FileWriter(origin), "");
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/PropertiesExtended.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java (from rev 798, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-13 15:12:01 UTC (rev 801)
@@ -0,0 +1,803 @@
+/*
+ * #%L
+ * Wikitty :: publication
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin mfortun
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication.synchro;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.collections.BidiMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.ArgumentsParserException;
+import org.nuiton.util.CollectionUtil;
+import org.nuiton.util.FileUtil;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyServiceFactory;
+import org.nuiton.wikitty.entities.Wikitty;
+import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.entities.WikittyLabelHelper;
+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.PagedResult;
+import org.nuiton.wikitty.search.Search;
+
+/**
+ * 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.
+ *
+ *
+ *
+ * @author mfortun
+ *
+ */
+public class WikittyPublication {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ 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
+ * need to set better name
+ */
+
+ /*
+ * FIXME mfortun-2011-04-11 need to migrate static value to another class ?
+ */
+ static public String WITTY_SERVICE_KEY = "wikitty.service.server.url";
+ static public String NO_RECURSION_KEY = "norecursion";
+ static public String DIRECTORY_KEY = "directory";
+ static public String HESSIAN_PROTOCOL_KEY = "hessian";
+
+ static public String DEFAULT_PROPERTY_NAME_SEP = ".";
+
+ static public String PROPERTY_DIRECTORY = ".wp";
+ static public String WIKITTYPUBLICATION_PROPERTIES_FILE = "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()
+ */
+ static public String WIKITTY_ID_PROPERTIES_FILE = "ids.properties";
+ static public String WIKITTY_FILE_META_PROPERTIES_FILE = "meta.properties";
+
+ /*
+ * in the WIKITTY_FILE_META_PROP ERTIES_FILE the keys for version are:
+ * filename + META_SUFFIX_KEY_VERSION we save the id too because with this
+ * solution un case of delete we can easily read the id and make operation
+ * on the wikitty
+ */
+ static public String META_SUFFIX_KEY_VERSION = "version";
+ static public String META_SUFFIX_KEY_CHECKSUM = "checksum";
+ static public String META_SUFFIX_KEY_ID = "id";
+
+ static public String META_CURRENT_LABEL = "current.label";
+
+ /**
+ * @param args
+ * @throws ArgumentsParserException
+ */
+ static public void main(String[] args) throws Exception {
+
+ /*
+ *
+ */
+
+ // on va creer un wikitty proxy pour le lien avec le wikitty qui stock
+ // mes trucs
+ // et on va avoir un wikittypublicationfilesystem pour stocker sur le
+ // local et tout
+ // soucis du wikittyFS c'est de savoir dans quel dossier il va taffer ?
+ // a moins qu'il prenne un directory de travail
+
+ /*
+ * ws.properties :wikitty.service= http://www.adresse.com:8080
+ *
+ * wikittypubs.properties script.js=numéroVersion7 id.script.js= id du
+ * wikitty scripttut.js=numéroVersion id.scripttut.js= id du wikitty
+ * image.png=numéroVersion id.image.png= id du wikitty label=
+ * racine.directory2, racine.directory22
+ */
+
+ applicationConfig = new ApplicationConfig();
+
+ // allias for the url of the wikitty service
+ applicationConfig.addAlias("--ws", "--option", WITTY_SERVICE_KEY);
+
+ applicationConfig.addAlias("--dir", "--option", DIRECTORY_KEY);
+
+ /*
+ * TODO mfortun-2011-04-05 once application fixed setdefault value and
+ * enumclass for initialisation
+ */
+
+ // allias for norecursion
+ applicationConfig.addAlias("--norecursion", "--option",
+ NO_RECURSION_KEY, "true");
+
+ // allias for the protocole
+ applicationConfig.addAlias("--hessian", "--option",
+ HESSIAN_PROTOCOL_KEY, "true");
+
+ // allias for all the action
+ applicationConfig.addAlias("wp import", "--option", "import");
+ applicationConfig.addAlias("wp checkout", "--option", "checkout");
+ applicationConfig.addAlias("wp relocate", "--option", "relocate");
+ applicationConfig.addAlias("wp commit", "--option", "commit");
+ applicationConfig.addAlias("wp delete", "--option", "delete");
+ applicationConfig.addAlias("wp update", "--option", "update");
+
+ applicationConfig
+ .addActionAlias("import",
+ "org.nuiton.wikitty.publication.WikittyPublication#importToWikitty");
+
+ applicationConfig
+ .addActionAlias("checkout",
+ "org.nuiton.wikitty.publication.WikittyPublication#checkoutFromWikitty");
+
+ applicationConfig
+ .addActionAlias("relocate",
+ "org.nuiton.wikitty.publication.WikittyPublication#relocateWikitty");
+
+ applicationConfig
+ .addActionAlias("commit",
+ "org.nuiton.wikitty.publication.WikittyPublication#commitToWikitty");
+
+ applicationConfig
+ .addActionAlias("delete",
+ "org.nuiton.wikitty.publication.WikittyPublication#deleteFromWikitty");
+
+ applicationConfig
+ .addActionAlias("update",
+ "org.nuiton.wikitty.publication.WikittyPublication#updateFromWikitty");
+
+ // parsing
+ applicationConfig.parse(args);
+ // execution
+ applicationConfig.doAction(0);
+
+ }
+
+ /**
+ * Method that import the content of a directory into a wikitty service
+ */
+ static public void importToWikitty() throws Exception {
+
+ boolean noRecur = applicationConfig
+ .getOptionAsBoolean(NO_RECURSION_KEY);
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+ String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
+
+ log.info("import : wikittyservice: " + wikittyService + " noresursion="
+ + noRecur + " directory= " + dir.getAbsolutePath());
+ // usage: wp --norecursion --ws http://truc.com import --dir /home/Manou
+
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+
+ System.out.println(applicationConfig
+ .getOption("wikitty.service.server.url"));
+
+ // real code:
+ WikittyProxy remoteWikittyService = new WikittyProxy(
+ WikittyServiceFactory.buildWikittyService(applicationConfig));
+
+ remoteWikittyService.clear();
+ // load the list of file
+ List<File> toTransfert = listFile(dir, !noRecur);
+
+ List<Wikitty> listWikitty = new ArrayList<Wikitty>();
+ // transform file into wikitties
+
+ for (File fileToTransform : toTransfert) {
+ listWikitty.add(WikittyPublicationFileSystem.fileToWikitty(
+ fileToTransform, dir));
+ }
+
+ // send the wikitties
+ remoteWikittyService.storeWikitty(listWikitty);
+
+ }
+
+ /*
+ * TODO mfortun-2011-04-05 just prototyping, remove when really implements
+ * the method linked: importToWikitty
+ */
+ static public void printDirectory(File dir, boolean recur) {
+
+ System.out.println("<dir " + dir.getName() + ">");
+ for (File child : dir.listFiles()) {
+ if (child.isDirectory() && recur
+ && !child.getName().equals(PROPERTY_DIRECTORY)) {
+ printDirectory(child, recur);
+ } else if (!child.isDirectory()) {
+ System.out.println(child.getAbsolutePath());
+ }
+ }
+ System.out.println("</dir " + dir.getName() + ">");
+ }
+
+ /**
+ * Method that create the list of file needed to commit, delete, update
+ * import. It harvest file in order to transform them into wikitties
+ *
+ * @param starts
+ * harvested directory
+ * @param recursivly
+ * boolean id the directory have to be harvest
+ * @return list of harvested file
+ */
+ static protected List<File> listFile(File starts, boolean recursivly) {
+ List<File> result = new ArrayList<File>();
+ if (!starts.isDirectory()) {
+ result.add(starts);
+ }
+ for (File child : starts.listFiles()) {
+ if (child.isDirectory() && recursivly
+ && !child.getName().equals(PROPERTY_DIRECTORY)) {
+ // Directory don't have to be harvest
+ // result.add(child);
+ result.addAll(listFile(child, recursivly));
+ } else if (!child.isDirectory()) {
+ result.add(child);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Method that checkout a label recursivly or not into a local directory
+ * from a wikitty service
+ */
+ static public void checkoutFromWikitty(String label) throws Exception {
+
+ boolean noRecur = applicationConfig
+ .getOptionAsBoolean(NO_RECURSION_KEY);
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+ String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ log.info("checkout : wikittyservice: " + wikittyService
+ + " noresursion=" + noRecur + " directory= "
+ + dir.getAbsolutePath() + "Label a checkout " + label
+ + "HessianProtocol=" + hessianProtocole);
+
+ if (hessianProtocole) {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ } else {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+ }
+
+ WikittyProxy remoteWikittyService = new WikittyProxy(
+ WikittyServiceFactory.buildWikittyService(applicationConfig));
+ WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
+ dir, !noRecur, label);
+
+ // Construct the criteria
+ Criteria labelCriteria;
+ Search mainRequest = Search.query();
+ Search subRoqu = mainRequest.or();
+
+ // must have the type of wikittypubtext/wikittypubdata
+ subRoqu.exteq(WikittyPubText.EXT_WIKITTYPUBTEXT).exteq(
+ WikittyPubData.EXT_WIKITTYPUBDATA);
+ if (noRecur) {
+ // and extension with the name strictly equals to the label (no
+ // recursivity)
+ labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ .eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
+ .criteria();
+
+ } else {
+ // and extension with the name that containt the label (recursivity)
+ labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ .sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
+ .criteria();
+ }
+
+ // request to the proxy
+ PagedResult<Wikitty> pageResult = remoteWikittyService
+ .findAllByCriteria(labelCriteria);
+
+ List<Wikitty> wikittiesToWrite = pageResult.getAll();
+
+ // write the proper properties file!
+ writeHomePropertyFile(dir);
+
+ // write the wikities
+ localWikittyService.store("", wikittiesToWrite, true);
+
+ /*
+ * obtain the list of wikittypub and write then in the file system with
+ * the appropriate wikittyservice !
+ */
+
+ /*
+ * on va commencer par vérifier les arguments ''wp checkout
+ * [--norecursion] [url du WikittyService] [Label à extraire] [directory
+ * local d'accueil]'' on doit avoir trois string dans le unparsed: url,
+ * label, directory et potentiellement quelque chose dans le getoption
+ * recursion
+ */
+
+ }
+
+ /**
+ * Relocate the default url of the wikitty service
+ */
+ static public void relocateWikitty() throws Exception {
+
+ /*
+ * log.info("checkout : wikittyservice: " + wikittyService +
+ * " noresursion=" + noRecur + " directory= " + dir.getAbsolutePath()
+ * +"Label a checkout " +label+ "HessianProtocol="+hessianProtocole);
+ */
+
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+ String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ File wpHomeDir;
+
+ System.out
+ .println("search the directory of .wp file to write new properties file");
+ // search for the home directory
+ if (null == dir || !dir.exists()) {
+ wpHomeDir = searchWikittyPublicationHomeDir(new File("."));
+ } else {
+ wpHomeDir = new File(dir.getCanonicalFile() + File.separator
+ + PROPERTY_DIRECTORY);
+ }
+
+ Properties oldProperties = new Properties();
+
+ // TODO mfortun-2011-04-06 catch exception instead of throws
+ File propertiesFile = new File(wpHomeDir + File.separator
+ + WIKITTYPUBLICATION_PROPERTIES_FILE);
+ // load the old file just for loggin
+ oldProperties.load(new FileReader(propertiesFile));
+
+ log.info("Try relocate :" + "wikitty service:"
+ + oldProperties.getProperty(WITTY_SERVICE_KEY) + " by "
+ + wikittyService + " HessianProtocol: " + hessianProtocole
+ + " File : " + propertiesFile.getCanonicalPath());
+
+ // Creation of the new properties file
+ Properties props = new Properties();
+ props.put(WITTY_SERVICE_KEY, wikittyService);
+ if (hessianProtocole) {
+ props.put("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ } else {
+ props.put("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+ }
+
+ // save the new property file
+ props.store(new FileWriter(propertiesFile), "");
+
+ /*
+ * on va commencer par vérifier les arguments ''wp relocate [nouvelle
+ * url du WikittyService par defaut] [directory a relocaliser]'' on doit
+ * avoir trois string dans le unparsed: url et directory
+ */
+
+ }
+
+ /**
+ * commit the current wikittyworkspace into a wikitty service
+ */
+ static public void commitToWikitty() throws Exception {
+
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+
+ File wpHomeDir;
+ if (null == dir || !dir.exists()) {
+ /*
+ * si pas de dir on commit le dossier courant
+ */
+ dir = new File(".");
+
+ }
+ // on va chercher le home dir
+ wpHomeDir = searchWikittyPublicationHomeDir(dir);
+
+ Properties properties = new Properties();
+
+ // TODO mfortun-2011-04-06 catch exception instead of throws
+ File propertiesFile = new File(wpHomeDir.getCanonicalPath()
+ + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
+ // load the old file just for loggin
+ properties.load(new FileReader(propertiesFile));
+
+ // on va rajouter les propriété de notre file
+ applicationConfig.setOptions(properties);
+
+ boolean noRecur = applicationConfig
+ .getOptionAsBoolean(NO_RECURSION_KEY);
+
+ String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ if (hessianProtocole) {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ } else {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+ }
+
+ log.info("commit " + " wikitty-service" + wikittyService
+ + "noRecurs : " + noRecur + " hessian Protocole :"
+ + hessianProtocole + "directory : " + dir.getAbsolutePath());
+
+ System.out.println("try to commit: ");
+ printDirectory(dir, !noRecur);
+
+ // faire la liste des fichiers à commit
+ // avec récursivité si c'etransfert d'histoire entre svnst demandé.
+ // et les transformer en wikitty, vérifier les versions et tout.
+
+ /*
+ * parcours l'arborescence des fichiers celon que on soit recursif ou
+ * non plutot que faire la liste fichier, on va aller lire les ids dans
+ * les fichiers de propriétés.
+ *
+ * Ensuite on creer le wikittyserviceFileSysteme avec le répertoire de
+ * travail et lui on lui donner les ids avec lesquels il va travailler
+ * et aller chercher les fichiers de propriétés pour retrouver les files
+ * et creer les wikittypub correspondant.
+ *
+ * Pour faire un commit il ne suffira pas de faire un restore
+ * finalement, il faudra faire un search aussi puisque on va se
+ * retrouver à faire des new wikitty p'etre éclaircir ce point plus
+ * tard. Pour le moment ne pas se poser de question trop, et faire sans
+ * nouveau fichier.
+ */
+
+ // création du proxy
+
+ /*
+ * on va commencer par vérifier les arguments ''wp commit
+ * [--norecursion] [--ws (url du WikittyService)] [répertoire à
+ * pousser]'' on doit avoir deux string dans le unparsed et
+ * potentiellement quelque chose dans le getoption recursion
+ */
+
+ }
+
+ /**
+ * delete a file or directory from the workspace it remove the label from
+ * the wikitty
+ *
+ * @throws Exception
+ */
+ static public void deleteFromWikitty(File toDelete) throws Exception {
+
+ // check args
+ if (null == toDelete || !toDelete.exists()) {
+ // Exception
+
+ } else {
+
+ File currentDir = new File(FileUtil.getCurrentDirectory()
+ .getAbsolutePath());
+ File wpHomeDir = searchWikittyPublicationHomeDir(currentDir);
+ // search for the .wp home dir to load props
+
+ // then load proxy
+
+ // if toDelete is a directory do something different from usualy
+ // recursivly remove labels
+
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+
+ Properties properties = new Properties();
+
+ // TODO mfortun-2011-04-06 catch exception instead of throws
+ File propertiesFile = new File(wpHomeDir.getCanonicalPath()
+ + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
+ // load the old file just for loggin
+ properties.load(new FileReader(propertiesFile));
+
+ // on va rajouter les propriété de notre file
+ applicationConfig.setOptions(properties);
+
+ String wikittyService = applicationConfig
+ .getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ if (hessianProtocole) {
+ applicationConfig
+ .setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ } else {
+ applicationConfig.setOption(
+ "wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+ }
+
+ log.info("Delete " + " wikitty-service" + wikittyService
+ + " hessian Protocole :" + hessianProtocole
+ + "file to delete : " + toDelete.getAbsolutePath());
+ // on va chercher le home dir
+ wpHomeDir = searchWikittyPublicationHomeDir(dir);
+
+ WikittyProxy remoteWikittyService = new WikittyProxy(
+ WikittyServiceFactory
+ .buildWikittyService(applicationConfig));
+ WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
+ dir);
+
+ if (toDelete.isDirectory()) {
+
+ BidiMap deleteMap = WikittyPublicationFileSystem
+ .harvestLocalWikitties(toDelete, true);
+ List<String> ids = new ArrayList<String>();
+ ids = new ArrayList<String>();
+ ids.addAll(CollectionUtil.toGenericCollection(
+ deleteMap.keySet(), String.class));
+
+ for (String key : ids) {
+ // restore wikitty
+ Wikitty wd = remoteWikittyService.restore(key);
+
+ // searh for the label to delete from the wikitty
+ FileSystemWIkittyId location = (FileSystemWIkittyId) deleteMap
+ .get(key);
+
+ File wikittyFileParent = new File(location.getPath());
+ PropertiesExtended metaExtended = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(
+ wikittyFileParent,
+ WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ String currentLabel = metaExtended
+ .getProperty(META_CURRENT_LABEL);
+ // remove label
+ WikittyLabelHelper.removeLabels(wd, currentLabel);
+ // save the wikitty
+ remoteWikittyService.store(wd);
+ }
+
+ localWikittyService.delete("", ids);
+ // if it was a directory the wikitty file service does not have
+ // delete it
+
+ FileUtil.deleteRecursively(toDelete);
+ } else {
+ // infos about file about to delete
+ String name = toDelete.getName();
+ File parentFile = toDelete.getParentFile();
+ // search of it's id
+ PropertiesExtended metaProps = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(
+ parentFile,
+ WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ String id = metaProps.getProperty(name
+ + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_ID);
+ // his label
+ String label = metaProps
+ .getProperty(WikittyPublication.META_CURRENT_LABEL);
+
+ // restore wikitty remote
+
+ Wikitty wd = remoteWikittyService.restore(id);
+
+ // remove label
+
+ WikittyLabelHelper.removeLabels(wd, label);
+ // save the wikitty remote
+ remoteWikittyService.store(wd);
+
+ List<String> ids = new ArrayList<String>();
+ ids.add(id);
+ // delete localy
+ localWikittyService.delete("", ids);
+ }
+
+ }
+
+ /*
+ * on va commencer par vérifier les arguments ''wp delete [--ws (url du
+ * WikittyService)] [répertoire ou fichier à supprimer]'' on doit avoir
+ * un string dans le unparsed et après pour pour le wikittyservice bah
+ * on tape dedans en fonction de si elle a été précisé en ligne de
+ * commande applicationConfig se débrouille
+ */
+ }
+
+ /**
+ * update the current workspace from a wikitty
+ */
+ static public void updateFromWikitty() throws Exception {
+
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+
+ File wpHomeDir;
+ if (null == dir || !dir.exists()) {
+ /*
+ * si pas de dir on update le dossier courant
+ */
+ dir = new File(".");
+
+ }
+ // on va chercher le home dir
+ wpHomeDir = searchWikittyPublicationHomeDir(dir);
+
+ Properties properties = new Properties();
+
+ // TODO mfortun-2011-04-06 catch exception instead of throws
+ File propertiesFile = new File(wpHomeDir.getCanonicalPath()
+ + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
+ // load the old file just for loggin
+ properties.load(new FileReader(propertiesFile));
+
+ // on va rajouter les propriété de notre file
+ applicationConfig.setOptions(properties);
+
+ boolean noRecur = applicationConfig
+ .getOptionAsBoolean(NO_RECURSION_KEY);
+
+ String wikittyService = applicationConfig.getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ if (hessianProtocole) {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceHessianClient");
+ } else {
+ applicationConfig.setOption("wikitty.WikittyService.components",
+ "org.nuiton.wikitty.services.WikittyServiceCajoClient");
+ }
+
+ log.info("update " + " wikitty-service" + wikittyService
+ + "noRecurs : " + noRecur + " hessian Protocole :"
+ + hessianProtocole + "directory : " + dir.getAbsolutePath());
+
+ System.out.println("try to update: ");
+ printDirectory(dir, !noRecur);
+
+ /*
+ * on va commencer par vérifier les arguments * ''wp update
+ * [--norecursion] [--ws (url du WikittyService)] [répertoire à mettre à
+ * jour]'' normalement un string dans unparsed et potentiellement
+ * quelque chose dans le recursion
+ */
+ }
+
+ /**
+ *
+ * Use to search in the file system the directory that containt the .wp dir
+ * that containt the properties file for the wikitty service's adresse
+ *
+ * @param start
+ * @return File the directory container of the master property file
+ * @throws Exception
+ */
+ static protected File searchWikittyPublicationHomeDir(File start)
+ throws Exception {
+
+ if (start != null && start.exists() && start.isDirectory()) {
+ // on va retourner le dossier .wp home
+
+ // method récursiv qui remonte dans les parents pour retrouver.
+
+ File propertyDirectory = new File(start.getCanonicalPath()
+ + File.separator + PROPERTY_DIRECTORY);
+
+ if (propertyDirectory.exists()) {
+ File propertie = new File(propertyDirectory.getCanonicalPath()
+ + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
+ if (propertie.exists()) {
+ return propertyDirectory;
+ }
+ }
+
+ return searchWikittyPublicationHomeDir(start.getParentFile());
+ } else {
+ // Exception
+ /*
+ * TODO mfortun-2011-04-06 write/set the appropriate exception here
+ */
+ return null;
+ }
+ }
+
+ static protected void writeHomePropertyFile(File homeDir) throws Exception {
+
+ if (homeDir.exists()) {
+ File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
+ String wikittyService = applicationConfig
+ .getOption(WITTY_SERVICE_KEY);
+ boolean hessianProtocole = applicationConfig
+ .getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
+
+ // TODO mfortun-2011-04-11 find a better way to manage component
+ // property
+ String propertyCompo = applicationConfig
+ .getOption("wikitty.WikittyService.components");
+ // write the proper properties file!
+ Properties props = new Properties();
+ props.put(WITTY_SERVICE_KEY, wikittyService);
+
+ props.put("wikitty.WikittyService.components", propertyCompo);
+
+ // create the properties directory
+ File wpDirectory = new File(homeDir.getCanonicalPath()
+ + File.separator + PROPERTY_DIRECTORY + File.separator);
+ if (!wpDirectory.exists()) {
+ wpDirectory.mkdir();
+ }
+
+ File propertiesFiles = new File(wpDirectory.getCanonicalPath()
+ + File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
+
+ props.store(new FileWriter(propertiesFiles), "");
+ }
+ }
+
+ /**
+ * Method that create a list of the properties directory
+ *
+ * @param starts
+ * harvested directory
+ * @param recursivly
+ * @return list of harvested file
+ */
+ static public List<File> harvestPropertyDirectory(File starts,
+ boolean recursivly) {
+
+ List<File> result = new ArrayList<File>();
+
+ for (File child : starts.listFiles()) {
+
+ if (child.isDirectory()
+ && child.getName().equals(PROPERTY_DIRECTORY)) {
+ result.add(child);
+ } else if (child.isDirectory() && recursivly) {
+ result.addAll(harvestPropertyDirectory(child, recursivly));
+ }
+ }
+ return result;
+
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java (from rev 800, trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java)
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-13 15:12:01 UTC (rev 801)
@@ -0,0 +1,836 @@
+/*
+ * #%L
+ * Wikitty :: publication
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2011 CodeLutin mfortun
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.publication.synchro;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+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;
+import org.apache.commons.collections.bidimap.DualHashBidiMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.MD5InputStream;
+import org.nuiton.util.StringUtil;
+import org.nuiton.wikitty.WikittyService;
+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.publication.entities.WikittyPubData;
+import org.nuiton.wikitty.publication.entities.WikittyPubDataHelper;
+import org.nuiton.wikitty.publication.entities.WikittyPubDataImpl;
+import org.nuiton.wikitty.publication.entities.WikittyPubText;
+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.services.WikittyEvent;
+import org.nuiton.wikitty.services.WikittyListener;
+
+public class WikittyPublicationFileSystem implements WikittyService {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ final static private Log log = LogFactory
+ .getLog(WikittyPublicationFileSystem.class);
+
+ static public String WIKITTYLABEL_SEPARATOR = ".";
+
+ protected File homeFile;
+ protected boolean recursion;
+ protected String label;
+
+ /**
+ * Constructor with the working directory
+ *
+ * @param home
+ * the home directory
+ */
+ public WikittyPublicationFileSystem(File home, boolean recur, String label) {
+ this.setHomeFile(home);
+ this.setRecursion(recur);
+ this.setLabel(label);
+ }
+
+
+
+
+ public WikittyPublicationFileSystem(File homeFile) {
+ this(homeFile, true, "");
+
+ }
+
+
+
+
+ public File getHomeFile() {
+ return homeFile;
+ }
+
+ public void setHomeFile(File homeFile) {
+ this.homeFile = homeFile;
+ }
+
+ public boolean isRecursion() {
+ return recursion;
+ }
+
+ public void setRecursion(boolean recursion) {
+ this.recursion = recursion;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ @Override
+ public void addWikittyServiceListener(WikittyListener listener,
+ ServiceListenerType type) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ //
+
+ }
+
+ @Override
+ public void removeWikittyServiceListener(WikittyListener listener,
+ ServiceListenerType type) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ //
+
+ }
+
+ @Override
+ public String login(String login, String password) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public void logout(String securityToken) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ //
+
+ }
+
+ @Override
+ public WikittyEvent clear(String securityToken) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public boolean canWrite(String securityToken, Wikitty wikitty) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return false;
+
+ }
+
+ @Override
+ public boolean canDelete(String securityToken, String wikittyId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return false;
+
+ }
+
+ @Override
+ public boolean canRead(String securityToken, String wikittyId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return false;
+
+ }
+
+ @Override
+ public boolean exists(String securityToken, String wikittyId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return false;
+
+ }
+
+ @Override
+ public boolean isDeleted(String securityToken, String wikittyId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return false;
+
+ }
+
+ @Override
+ public WikittyEvent replay(String securityToken, List<WikittyEvent> events,
+ boolean force) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyEvent store(String securityToken,
+ Collection<Wikitty> wikitties, boolean force) {
+
+ try {
+
+ for (Wikitty w : wikitties) {
+
+ Set<String> set = WikittyLabelHelper.getLabels(w);
+ String ourDir = "";
+
+ // search for our label
+ for (String name : set) {
+ if (!recursion && name.equalsIgnoreCase(label)) {
+ ourDir = name;
+ } else if (recursion && name.startsWith(label)) {
+ ourDir = name;
+ }
+ }
+
+ // create the directories from the label
+ boolean pathFilecreated = createFilesFromLabelPath(ourDir);
+
+ if (pathFilecreated) {
+ // create the path with the label
+ String path = homeFile.getCanonicalFile() + File.separator
+ + ourDir.replace(".", File.separator);
+
+ // correct the pb with directory name begin by .
+ path = path.replace(File.separator + File.separator,
+ File.separator + ".");
+
+ // create the propertie directory if necessary
+ File propertieDirectory = new File(path + File.separator
+ + WikittyPublication.PROPERTY_DIRECTORY);
+ if (!propertieDirectory.exists()
+ || !propertieDirectory.isDirectory()) {
+ propertieDirectory.mkdir();
+ }
+ // load/create meta propertie file
+ File propertieFile = new File(
+ propertieDirectory.getCanonicalPath()
+ + File.separator
+ + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+ if (!propertieFile.exists()) {
+ propertieFile.createNewFile();
+ }
+
+ // load/create id propertie file
+ File idPropertieFile = new File(
+ propertieDirectory.getCanonicalPath()
+ + File.separator
+ + WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
+ if (!idPropertieFile.exists()) {
+ idPropertieFile.createNewFile();
+ }
+
+ String name = "";
+ String extension = "";
+
+ File wikittyFile = null;
+ if (w.hasExtension(WikittyPubData.EXT_WIKITTYPUBDATA)) {
+ name = WikittyPubDataHelper.getName(w);
+ String mime = WikittyPubDataHelper.getMimeType(w);
+ byte[] content = WikittyPubDataHelper.getContent(w);
+
+ extension = extensionFormimeType(mime);
+
+ wikittyFile = new File(path + File.separator + name
+ + "." + extension);
+
+ wikittyFile.createNewFile();
+
+ FileUtil.byteToFile(content, wikittyFile);
+
+ } else if (w
+ .hasExtension(WikittyPubText.EXT_WIKITTYPUBTEXT)) {
+ name = WikittyPubTextHelper.getName(w);
+ String mime = WikittyPubTextHelper.getMimeType(w);
+ String content = WikittyPubTextHelper.getContent(w);
+
+ extension = extensionFormimeType(mime);
+
+ wikittyFile = new File(path + File.separator + name
+ + "." + extension);
+
+ wikittyFile.createNewFile();
+
+ FileUtil.writeString(wikittyFile, content);
+ }
+
+ 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
+ Properties metaProperties = new Properties();
+ metaProperties.load(new FileReader(propertieFile));
+ // update
+ metaProperties.setProperty(
+ WikittyPublication.META_CURRENT_LABEL, ourDir);
+
+ metaProperties.setProperty(name + "." + extension
+ + ".version", w.getVersion());
+ metaProperties.setProperty(name + "." + extension
+ + ".id", w.getId());
+ metaProperties.setProperty(name + "." + extension
+ + ".checksum", localMd5);
+ // save
+ metaProperties.store(new FileWriter(propertieFile), "");
+ // load id properties
+ Properties idProperties = new Properties();
+ idProperties.load(new FileReader(idPropertieFile));
+ // update
+ idProperties.setProperty(w.getId(), name + "."
+ + extension);
+ // save
+ idProperties.store(new FileWriter(idPropertieFile), "");
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO mfortun-2011-04-12 really handle exceptions
+ }
+
+ WikittyEvent result = new WikittyEvent(this);
+
+ return result;
+ }
+
+ @Override
+ public List<String> getAllExtensionIds(String securityToken) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public List<String> getAllExtensionsRequires(String securityToken,
+ String extensionName) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyEvent storeExtension(String securityToken,
+ Collection<WikittyExtension> exts) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyEvent deleteExtension(String securityToken,
+ Collection<String> extNames) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyExtension restoreExtension(String securityToken,
+ String extensionId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyExtension restoreExtensionLastVersion(String securityToken,
+ String name) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public List<Wikitty> restore(String securityToken, List<String> id) {
+ List<Wikitty> result = new ArrayList<Wikitty>();
+ try {
+ BidiMap locations = harvestLocalWikitties(homeFile, recursion);
+
+ for (String wikid : id) {
+ Object value = locations.get(wikid);
+
+ if (value == null) {
+ locations = locations.inverseBidiMap();
+ value = locations.get(wikid);
+ }
+
+ if (value != null) {
+
+ 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
+ Properties props = new Properties();
+ File propsFile = new File(
+ path
+ + File.separator
+ + WikittyPublication.PROPERTY_DIRECTORY
+ + File.separator
+ + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+ props.load(new FileReader(propsFile));
+ // re set the id
+ wikitty.setVersion(props.getProperty(completeName
+ + WikittyPublication.META_SUFFIX_KEY_ID));
+
+ // set the current label
+ WikittyLabelHelper
+ .addLabels(
+ wikitty,
+ props.getProperty(WikittyPublication.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);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO mfortun-2011-01-12 really handle exception
+ }
+ return result;
+ }
+
+ @Override
+ public WikittyEvent delete(String securityToken, Collection<String> ids) {
+
+ try {
+ BidiMap location = harvestLocalWikitties(homeFile, true);
+
+ for (String id : ids) {
+
+ Object value = location.get(id);
+
+ if (value == null) {
+ location = location.inverseBidiMap();
+ value = location.get(id);
+ }
+
+ if (value != null) {
+
+ FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
+
+ String path = localisation.getPath();
+ String fileName = localisation.getFileName();
+
+ // load properties
+ PropertiesExtended propsProperties = getWikittyPublicationProperties(new File(
+ path), WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ // update
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_CHECKSUM);
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_ID);
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_VERSION);
+
+ // resave
+ propsProperties.store();
+
+ // load properties
+ PropertiesExtended idProperties = getWikittyPublicationProperties(new File(
+ path), WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
+ // update
+ idProperties.remove(id);
+ // resave
+ idProperties.store();
+
+ File wikittyFile = new File(path + File.separator
+ + fileName);
+
+ if (wikittyFile.exists()) {
+ wikittyFile.delete();
+ }
+
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO mfortun-2011-04-13 really handle exception
+ }
+
+ WikittyEvent result = new WikittyEvent(this);
+ return result;
+ }
+
+ @Override
+ public List<PagedResult<String>> findAllByCriteria(String securityToken,
+ List<Criteria> criteria) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public List<String> findByCriteria(String securityToken,
+ List<Criteria> criteria) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public WikittyEvent deleteTree(String securityToken, String treeNodeId) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public TreeNodeResult<String> findTreeNode(String securityToken,
+ String wikittyId, int depth, boolean count, Criteria filter) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public Wikitty restoreVersion(String securityToken, String wikittyId,
+ String version) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ // return null;
+
+ }
+
+ @Override
+ public void syncSearchEngine(String securityToken) {
+ // TODO mfortun-2011-04-05
+ throw new UnsupportedOperationException("not yet implemented");
+ //
+
+ }
+
+ /**
+ * 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
+ */
+ static public Wikitty fileToWikitty(File fileToTransform, File starts)
+ 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;
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ *
+ * @param starts
+ * @param recursivly
+ * @return
+ * @throws Exception
+ */
+ static public BidiMap harvestLocalWikitties(File starts, boolean recursivly)
+ throws Exception {
+ BidiMap result = new DualHashBidiMap();
+
+ List<File> propertiesDirectory = WikittyPublication
+ .harvestPropertyDirectory(starts, recursivly);
+
+ for (File propsDir : propertiesDirectory) {
+
+ Properties idProps = new Properties();
+ File idFile = new File(propsDir.getCanonicalPath() + File.separator
+ + WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
+ if (idFile.exists()) {
+ idProps.load(new FileReader(idFile));
+ }
+
+ Set<Object> ids = idProps.keySet();
+
+ for (Object id : ids) {
+ String name = idProps.getProperty((String) id);
+ String path = propsDir.getParent();
+ FileSystemWIkittyId value = new FileSystemWIkittyId(name, path);
+
+ result.put((String) id, value );
+ }
+
+ }
+
+ /*
+ * Pour l'arborescence des fichiers on va aller chercher les fichiers de
+ * propriété id et meta dans le dossier .wp pour aller récup les labels
+ * courant et les id liés on va renvoyer la map
+ *
+ * id, label
+ */
+
+ return result;
+ }
+
+ static public PropertiesExtended getWikittyPublicationProperties(File starts, String name)
+ throws Exception {
+
+ File propertieDirectory = new File(starts.getCanonicalPath()
+ + File.separator + WikittyPublication.PROPERTY_DIRECTORY);
+
+ // load/create meta propertie file
+ File propertieFile = new File(propertieDirectory.getCanonicalPath()
+ + File.separator
+ + name);
+ if (!propertieFile.exists()) {
+ propertieFile.createNewFile();
+ }
+
+ PropertiesExtended result = new PropertiesExtended(propertieFile);
+
+ return result;
+ }
+
+
+
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r800 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication
by mfortun@users.nuiton.org 13 Apr '11
by mfortun@users.nuiton.org 13 Apr '11
13 Apr '11
Author: mfortun
Date: 2011-04-13 17:09:09 +0200 (Wed, 13 Apr 2011)
New Revision: 800
Url: http://nuiton.org/repositories/revision/wikitty/800
Log:
* remove unwanted import
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 14:57:37 UTC (rev 799)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 15:09:09 UTC (rev 800)
@@ -41,11 +41,7 @@
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
-import org.apache.velocity.texen.util.PropertiesUtil;
-import org.nuiton.util.CollectionUtil;
import org.nuiton.util.FileUtil;
-import org.nuiton.util.LRUMapMultiKey;
import org.nuiton.util.MD5InputStream;
import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.WikittyService;
1
0
r799 - in trunk: wikitty-api/src/main/java/org/nuiton/wikitty/entities wikitty-api/src/test/java/org/nuiton/wikitty/conform wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr wikitty-solr/src/main/resources wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr
by jcouteau@users.nuiton.org 13 Apr '11
by jcouteau@users.nuiton.org 13 Apr '11
13 Apr '11
Author: jcouteau
Date: 2011-04-13 16:57:37 +0200 (Wed, 13 Apr 2011)
New Revision: 799
Url: http://nuiton.org/repositories/revision/wikitty/799
Log:
Change indexation of fields. Now multivalued and non multivalued fields are indexed in a different way so that sort on not multivalued field is available
Added:
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java
Removed:
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/TypeFieldModifier.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java
trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/Restriction2Solr.java
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrUtil.java
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySolrConstant.java
trunk/wikitty-solr/src/main/resources/schema.xml
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearch2Test.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolrTest.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/entities/FieldType.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -59,7 +59,7 @@
* convert string to TYPE, this method accept not trimed and not well
* cased string (difference with valueOf)
* @param name
- * @return TYPE else exception is throw
+ * @return TYPE else exception is thrown
*/
public static TYPE parse(String name) {
TYPE result = valueOf(name.trim().toUpperCase());
Modified: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java
===================================================================
--- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/conform/StorageTest.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -259,7 +259,7 @@
@Test
public void testStoreFindAll() throws Exception {
- // create some wikitty to permit search test
+ // create some wikitty to permit search test
List<Wikitty> wikitties = new ArrayList<Wikitty>();
String[] wValues = new String[] {
// wikitty[ 0 ]
@@ -289,10 +289,10 @@
w.setField(EXT_TEST.getName(), "fieldName1", "003309");
Criteria criteria = Search.query(w).criteria()
.addSortDescending(EXT_TEST.getName() + ".fieldName0");
- PagedResult<String> resultFind = getProxy().findAllIdByCriteria(criteria);
+ PagedResult<Wikitty> resultFind = getProxy().findAllByCriteria(criteria);
assertEquals(2, resultFind.size());
- List<Wikitty> wikittyFind = getProxy().restore(resultFind.getAll());
+ List<Wikitty> wikittyFind = resultFind.getAll();
assertEquals(wikitties.subList(0, 2), wikittyFind);
}
Deleted: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -1,42 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-solr-impl
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.storage.solr;
-
-import org.nuiton.wikitty.services.WikittyTransaction;
-
-
-/**
- * use to permit client to modify fieldname during query generation
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public interface FieldModifier {
- public String convertToSolr(WikittyTransaction transaction, String fieldname);
- public String convertToField(WikittyTransaction transaction, String solrName);
-}
Copied: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java (from rev 797, trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/TypeFieldModifier.java)
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java (rev 0)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/FieldModifier.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -0,0 +1,144 @@
+/*
+ * #%L
+ * Wikitty :: wikitty-solr-impl
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.storage.solr;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.wikitty.WikittyUtil;
+import org.nuiton.wikitty.entities.FieldType;
+import org.nuiton.wikitty.entities.FieldType.TYPE;
+import org.nuiton.wikitty.entities.WikittyExtension;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.services.WikittyTransaction;
+import org.nuiton.wikitty.storage.WikittyExtensionStorage;
+
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_ALL_EXTENSIONS;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_EXTENSIONS;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_ID;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BINARY;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BINARY_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BOOLEAN;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_DATE;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_NUMERIC;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_STRING;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_WIKITTY;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BOOLEAN_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_DATE_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_NUMERIC_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_STRING_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_WIKITTY_MULTIVALUED;
+
+/**
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class FieldModifier {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(FieldModifier.class);
+
+ protected WikittyExtensionStorage extensionStorage;
+
+ public FieldModifier(WikittyExtensionStorage extensionStorage) {
+ this.extensionStorage = extensionStorage;
+ }
+
+ public String convertToSolr(WikittyTransaction transaction, String fqfieldname) {
+ String result = fqfieldname;
+ String[] searchField = fqfieldname.split(WikittyUtil.FQ_FIELD_NAME_SEPARATOR_REGEX);
+
+ if (Element.ELT_EXTENSION.equals(fqfieldname)) {
+ result = SOLR_EXTENSIONS;
+
+ } else if (Element.ELT_ID.equals(fqfieldname)) {
+ result = SOLR_ID;
+
+ } else if (searchField.length >= 2) {
+ String extName = searchField[0];
+ String fieldName = searchField[1];
+
+ if (Criteria.ALL_EXTENSIONS.equals(extName)) {
+ fqfieldname = SOLR_ALL_EXTENSIONS
+ + WikittyUtil.FQ_FIELD_NAME_SEPARATOR + fieldName;
+ }
+
+ if (searchField.length >= 3) {
+ // TODO poussin 20101209 je ne vois pas dans quel cas on passe ici
+ String fieldNameType = searchField[2];
+ TYPE type = FieldType.TYPE.valueOf(fieldNameType);
+ result = SolrUtil.getSolrFieldName(fqfieldname, type);
+ return result;
+ }
+
+ // Search type of field in extension
+ String version =
+ extensionStorage.getLastVersion(transaction, extName);
+ if (version != null) { // not valid extension if version == null
+ WikittyExtension ext = extensionStorage.restore(
+ transaction, extName, version);
+ FieldType fieldType = ext.getFieldType(fieldName);
+ if (log.isDebugEnabled()) {
+ log.debug(ext.toDefinition() + " for " + fieldName);
+ }
+ if (fieldType != null) { // type can be null if extension version differ
+ TYPE type = fieldType.getType();
+ if (fieldType.isCollection()) {
+ result = SolrUtil.getSolrCollectionFieldName(fqfieldname, type);
+ } else {
+ result = SolrUtil.getSolrFieldName(fqfieldname, type);
+ }
+ return result;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public String convertToField(WikittyTransaction transaction, String solrName) {
+ String fieldName = solrName.replaceAll(
+ "(" + SUFFIX_BINARY + "$)"
+ + "|(" + SUFFIX_BOOLEAN + "$)"
+ + "|(" + SUFFIX_DATE + "$)"
+ + "|(" + SUFFIX_STRING + "$)"
+ + "|(" + SUFFIX_WIKITTY + "$)"
+ + "|(" + SUFFIX_NUMERIC + "$)"
+ + "|(" + SUFFIX_BINARY_MULTIVALUED + "$)"
+ + "|(" + SUFFIX_BOOLEAN_MULTIVALUED + "$)"
+ + "|(" + SUFFIX_DATE_MULTIVALUED + "$)"
+ + "|(" + SUFFIX_STRING_MULTIVALUED + "$)"
+ + "|(" + SUFFIX_WIKITTY_MULTIVALUED + "$)"
+ + "|(" + SUFFIX_NUMERIC_MULTIVALUED + "$)", "");
+ if (SOLR_EXTENSIONS.equals(fieldName)) {
+ fieldName = Element.ELT_EXTENSION;
+ }
+ return fieldName;
+ }
+}
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/Restriction2Solr.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/Restriction2Solr.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/Restriction2Solr.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -71,22 +71,9 @@
private static final int MAX_SUBQUERY_RESULT = 100;
- final static protected FieldModifier dummyFieldModifier = new FieldModifier() {
- public String convertToSolr(WikittyTransaction transaction, String fieldname) {
- return fieldname;
- }
- public String convertToField(WikittyTransaction transaction, String solrName) {
- return solrName;
- }
- };
-
protected FieldModifier fieldModifer;
protected WikittyTransaction transaction;
- public Restriction2Solr() {
- this(null, dummyFieldModifier);
- }
-
// TODO 20101201 jru improve manage transaction and fieldModifeir in helper
public Restriction2Solr(WikittyTransaction transaction, FieldModifier fieldModifer) {
this.transaction = transaction;
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrUtil.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrUtil.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrUtil.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -45,6 +45,12 @@
import org.nuiton.wikitty.entities.WikittyTreeNode;
import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_ID;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BINARY_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BOOLEAN_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_DATE_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_NUMERIC_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_STRING_MULTIVALUED;
+import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_WIKITTY_MULTIVALUED;
import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.TREENODE_PARENTS;
import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.TREENODE_ATTACHED;
import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BINARY;
@@ -167,7 +173,7 @@
* @return Map key:TreeNode id, value; solr document associate with id
* @since 3.1
*/
- static public Map<String, SolrDocument> findAllByField(
+ static public Map<String, SolrDocument> findAllByField(
SolrServer solrServer, String solrField, Collection<String> ids) {
Map<String, SolrDocument> result = new HashMap<String, SolrDocument>();
if (ids != null && ids.size() > 0) {
@@ -224,7 +230,7 @@
/**
* if you change this method, change
- * {@link TypeFieldModifier#convertToField(org.nuiton.wikitty.services.WikittyTransaction, java.lang.String)}
+ * {@link FieldModifier#convertToField(org.nuiton.wikitty.services.WikittyTransaction, java.lang.String)}
* too
*
* @param fqfieldName FQ field name
@@ -251,6 +257,34 @@
}
/**
+ * if you change this method, change
+ * {@link FieldModifier#convertToField(org.nuiton.wikitty.services.WikittyTransaction, java.lang.String)}
+ * too
+ *
+ * @param fqfieldName FQ field name
+ * @param type of field
+ * @return field name
+ */
+ static public String getSolrCollectionFieldName(String fqfieldName, TYPE type) {
+ switch (type) {
+ case BINARY:
+ return fqfieldName + SUFFIX_BINARY_MULTIVALUED;
+ case BOOLEAN:
+ return fqfieldName + SUFFIX_BOOLEAN_MULTIVALUED;
+ case DATE:
+ return fqfieldName + SUFFIX_DATE_MULTIVALUED;
+ case STRING:
+ return fqfieldName + SUFFIX_STRING_MULTIVALUED;
+ case NUMERIC:
+ return fqfieldName + SUFFIX_NUMERIC_MULTIVALUED;
+ case WIKITTY:
+ return fqfieldName + SUFFIX_WIKITTY_MULTIVALUED;
+ default:
+ return fqfieldName;
+ }
+ }
+
+ /**
* Copy solr document
*
* @param source solr document source
Deleted: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/TypeFieldModifier.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/TypeFieldModifier.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/TypeFieldModifier.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -1,135 +0,0 @@
-/*
- * #%L
- * Wikitty :: wikitty-solr-impl
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.storage.solr;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.wikitty.WikittyUtil;
-import org.nuiton.wikitty.entities.FieldType;
-import org.nuiton.wikitty.entities.FieldType.TYPE;
-import org.nuiton.wikitty.entities.WikittyExtension;
-import org.nuiton.wikitty.search.Criteria;
-import org.nuiton.wikitty.search.operators.Element;
-import org.nuiton.wikitty.services.WikittyTransaction;
-import org.nuiton.wikitty.storage.WikittyExtensionStorage;
-
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_ALL_EXTENSIONS;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_EXTENSIONS;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SOLR_ID;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BINARY;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_BOOLEAN;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_DATE;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_NUMERIC;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_STRING;
-import static org.nuiton.wikitty.storage.solr.WikittySolrConstant.SUFFIX_WIKITTY;
-
-/**
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class TypeFieldModifier implements FieldModifier {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TypeFieldModifier.class);
-
- protected WikittyExtensionStorage extensionStorage;
-
- public TypeFieldModifier(WikittyExtensionStorage extensionStorage) {
- this.extensionStorage = extensionStorage;
- }
-
- @Override
- public String convertToSolr(WikittyTransaction transaction, String fqfieldname) {
- String result = fqfieldname;
- String[] searchField = fqfieldname.split(WikittyUtil.FQ_FIELD_NAME_SEPARATOR_REGEX);
-
- if (Element.ELT_EXTENSION.equals(fqfieldname)) {
- result = SOLR_EXTENSIONS;
-
- } else if (Element.ELT_ID.equals(fqfieldname)) {
- result = SOLR_ID;
-
- } else if (searchField.length >= 2) {
- String extName = searchField[0];
- String fieldName = searchField[1];
-
- if (Criteria.ALL_EXTENSIONS.equals(extName)) {
- fqfieldname = SOLR_ALL_EXTENSIONS
- + WikittyUtil.FQ_FIELD_NAME_SEPARATOR + fieldName;
- }
-
- if (searchField.length >= 3) {
- // TODO poussin 20101209 je ne vois pas dans quel cas on passe ici
- String fieldNameType = searchField[2];
- TYPE type = FieldType.TYPE.valueOf(fieldNameType);
- result = SolrUtil.getSolrFieldName(fqfieldname, type);
- return result;
- }
-
- // Search type of field in extension
- String version =
- extensionStorage.getLastVersion(transaction, extName);
- if (version != null) { // not valid extension if version == null
- WikittyExtension ext = extensionStorage.restore(
- transaction, extName, version);
- FieldType fieldType = ext.getFieldType(fieldName);
- if (log.isDebugEnabled()) {
- log.debug(ext.toDefinition() + " for " + fieldName);
- }
- if (fieldType != null) { // type can be null if extension version differ
- TYPE type = fieldType.getType();
- result = SolrUtil.getSolrFieldName(fqfieldname, type);
- return result;
- }
- }
- }
-
- return result;
- }
-
- /**
- * if you change this, change
- * {@link WikittySearchEngineSolr#getSolrFieldName(java.lang.String, org.nuiton.wikitty.entities.FieldType.TYPE)}
- * too
- */
- @Override
- public String convertToField(WikittyTransaction transaction, String solrName) {
- String fieldName = solrName.replaceAll(
- "(" + SUFFIX_BINARY + "$)"
- + "|(" + SUFFIX_BOOLEAN + "$)"
- + "|(" + SUFFIX_DATE + "$)"
- + "|(" + SUFFIX_STRING + "$)"
- + "|(" + SUFFIX_WIKITTY + "$)"
- + "|(" + SUFFIX_NUMERIC + "$)", "");
- if (SOLR_EXTENSIONS.equals(fieldName)) {
- fieldName = Element.ELT_EXTENSION;
- }
- return fieldName;
- }
-}
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -87,7 +87,7 @@
protected SolrServer solrServer;
/** Field modifier use to transform to solr format */
- protected TypeFieldModifier fieldModifier;
+ protected FieldModifier fieldModifier;
/** JTA resource */
protected SolrResource solrResource;
@@ -134,7 +134,7 @@
CoreContainer coreContainer = initializer.initialize();
solrServer = new EmbeddedSolrServer(coreContainer, "");
- fieldModifier = new TypeFieldModifier(extensionStorage);
+ fieldModifier = new FieldModifier(extensionStorage);
solrResource = new SolrResource(solrServer);
} catch (Exception eee) {
@@ -421,7 +421,7 @@
newAtts = null;
}
- addToIndexDocument(newDoc, TYPE.WIKITTY, field, newAtts);
+ addToIndexDocument(newDoc, TYPE.WIKITTY, field, newAtts, true);
solrResource.addDoc(id, newDoc);
}
}
@@ -615,7 +615,7 @@
// constitue de l'id et de l'indexation d'arbre qui sera
// reutilise lors du store de reel objet
doc = new SolrInputDocument();
- addToIndexDocument(doc, null, SOLR_ID, attId);
+ addToIndexDocument(doc, null, SOLR_ID, attId, true);
} else if (doc == null) {
doc = new SolrInputDocument();
SolrUtil.copySolrDocument(oldDoc, doc);
@@ -829,17 +829,13 @@
for (SolrDocument d : solrResults) {
String id = (String) d.getFieldValue(SOLR_ID);
- List<String> parentIds = (List<String>) d.getFieldValue(SolrUtil.getSolrFieldName(
+ String parentId = (String) d.getFieldValue(SolrUtil.getSolrFieldName(
WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT,
TYPE.WIKITTY));
int nb = counts.containsKey(id) ? counts.get(id) : 0;
TreeNodeResult<String> child = new TreeNodeResult<String>(id, nb);
allTreeNodeResult.put(id, child);
- if (parentIds != null) {
- for (String parentId : parentIds) {
childParent.put(id, parentId);
- }
- }
}
// construction de l'arbre avant de le retourner
for(Map.Entry<String, TreeNodeResult<String>> e : allTreeNodeResult.entrySet()) {
@@ -868,12 +864,19 @@
}
protected void addToIndexDocument(SolrInputDocument doc,
- TYPE type, String fqfieldName, Object fieldValue) {
+ TYPE type, String fqfieldName, Object fieldValue,
+ boolean collection) {
if (fqfieldName.startsWith(SOLR_WIKITTY_PREFIX)) {
doc.remove(fqfieldName);
doc.addField(fqfieldName, fieldValue);
} else {
- String solrFqFieldName = SolrUtil.getSolrFieldName(fqfieldName, type);
+ String solrFqFieldName;
+
+ if (collection) {
+ solrFqFieldName = SolrUtil.getSolrCollectionFieldName(fqfieldName, type);
+ } else {
+ solrFqFieldName = SolrUtil.getSolrFieldName(fqfieldName, type);
+ }
// #all.<fieldname>
// permet de faire des recherches inter extension sur un champs ayant
@@ -913,6 +916,7 @@
protected void addToIndexDocument(SolrInputDocument doc, Wikitty w, String fqfieldName) {
TYPE type = null;
Object fieldValue;
+ boolean collection = false;
if (SOLR_ID.equals(fqfieldName)) {
// extra field #id
fieldValue = w.getId();
@@ -923,11 +927,12 @@
// un champs normal
FieldType fieldType = w.getFieldType(fqfieldName);
type = fieldType.getType();
+ collection = fieldType.isCollection();
fieldValue = w.getFqField(fqfieldName);
}
- addToIndexDocument(doc, type, fqfieldName, fieldValue);
+ addToIndexDocument(doc, type, fqfieldName, fieldValue, collection);
}
/**
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySolrConstant.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySolrConstant.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySolrConstant.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -85,6 +85,13 @@
static final public String SUFFIX_STRING = "_s";
static final public String SUFFIX_WIKITTY = "_w";
+ static final public String SUFFIX_BINARY_MULTIVALUED = "_bim";
+ static final public String SUFFIX_BOOLEAN_MULTIVALUED = "_bm";
+ static final public String SUFFIX_NUMERIC_MULTIVALUED = "_dm";
+ static final public String SUFFIX_DATE_MULTIVALUED = "_dtm";
+ static final public String SUFFIX_STRING_MULTIVALUED = "_sm";
+ static final public String SUFFIX_WIKITTY_MULTIVALUED = "_wm";
+
static final public String SUFFIX_STRING_LOWERCASE = "_c";
static final public String SUFFIX_STRING_FULLTEXT = "_t";
Modified: trunk/wikitty-solr/src/main/resources/schema.xml
===================================================================
--- trunk/wikitty-solr/src/main/resources/schema.xml 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/main/resources/schema.xml 2011-04-13 14:57:37 UTC (rev 799)
@@ -122,8 +122,8 @@
<fields>
- <!-- WARNING ALL DATA MUST BE STORED, WE MUST CAN REINDEX WIKITTY WITH
- INDEXED BECAUSE FOR HIEARCHICAL FACET, THERE ARE COPY OF DOCUMENT -->
+ <!-- WARNING ALL DATA MUST BE STORED, WE MUST BE ABLE TO REINDEX WIKITTY WITH
+ INDEXED BECAUSE OF HIERARCHICAL FACET, THERE ARE COPY OF DOCUMENT -->
<field name="#id" type="string" required="true" indexed="true" stored="true" multiValued="false"/>
<field name="#extensions" type="string" indexed="true" stored="true" multiValued="true"/>
@@ -141,12 +141,18 @@
<dynamicField name="*_s_t" type="text" indexed="true" stored="false" multiValued="true"/>
<!-- on indexe pas les binary field -->
- <dynamicField name="*_bi" type="binary" indexed="false" stored="false" multiValued="true"/>
- <dynamicField name="*_b" type="boolean" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_d" type="numeric" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="true"/>
- <dynamicField name="*_w" type="wikitty" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_bi" type="binary" indexed="false" stored="false" multiValued="false"/>
+ <dynamicField name="*_b" type="boolean" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_d" type="numeric" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_w" type="wikitty" indexed="true" stored="true" multiValued="false"/>
+ <dynamicField name="*_bim" type="binary" indexed="false" stored="false" multiValued="true"/>
+ <dynamicField name="*_bm" type="boolean" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dm" type="numeric" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_dtm" type="date" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_sm" type="string" indexed="true" stored="true" multiValued="true"/>
+ <dynamicField name="*_wm" type="wikitty" indexed="true" stored="true" multiValued="true"/>
<!-- all other field, needed if we do query with unregistered extension.
No result is returned but is the right behavior -->
@@ -172,6 +178,11 @@
<copyField source="*_dt" dest="#fulltext"/>
<copyField source="*_s" dest="#fulltext"/>
<copyField source="*_w" dest="#fulltext"/>
+ <copyField source="*_bm" dest="#fulltext"/>
+ <copyField source="*_dm" dest="#fulltext"/>
+ <copyField source="*_dtm" dest="#fulltext"/>
+ <copyField source="*_sm" dest="#fulltext"/>
+ <copyField source="*_wm" dest="#fulltext"/>
<!-- copy String field for to lower case version -->
<copyField source="*_s" dest="*_s_c"/>
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -35,7 +35,7 @@
protected WikittyProxy proxy = null;
- protected static WikittyConfig instance = new WikittyConfig();
+ protected static WikittyConfig instance = new WikittyConfig("wikitty-config-sample-inmemory.properties");
protected static WikittyServiceEnhanced ws;
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearch2Test.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearch2Test.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearch2Test.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -37,7 +37,7 @@
WikittyService service;
- static protected WikittyConfig config = new WikittyConfig();
+ static protected WikittyConfig config = new WikittyConfig("wikitty-config-sample-inmemory.properties");
@BeforeClass
public static void initTests() {
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolrTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolrTest.java 2011-04-13 14:40:47 UTC (rev 798)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolrTest.java 2011-04-13 14:57:37 UTC (rev 799)
@@ -62,7 +62,7 @@
protected static WikittyServiceSolr ws;
- protected static WikittyConfig instance = new WikittyConfig();
+ protected static WikittyConfig instance = new WikittyConfig("wikitty-config-sample-inmemory.properties");
protected WikittyProxy proxy = new WikittyProxy(ws);
1
0
r798 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication
by mfortun@users.nuiton.org 13 Apr '11
by mfortun@users.nuiton.org 13 Apr '11
13 Apr '11
Author: mfortun
Date: 2011-04-13 16:40:47 +0200 (Wed, 13 Apr 2011)
New Revision: 798
Url: http://nuiton.org/repositories/revision/wikitty/798
Log:
* New class to handle properties and save it again in the same file used to load them
* add hashcode and equals methods in the filseSystemWikittyId
* implements the delete operation in the wikittyPublicationFileSytem
* implemtens delete function
* add method to search/create/load wikittypublication properties file
Added:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java 2011-04-13 09:32:21 UTC (rev 797)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/FileSystemWIkittyId.java 2011-04-13 14:40:47 UTC (rev 798)
@@ -34,4 +34,43 @@
this.setPath(path);
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((fileName == null) ? 0 : fileName.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof FileSystemWIkittyId)) {
+ return false;
+ }
+ FileSystemWIkittyId other = (FileSystemWIkittyId) obj;
+ if (fileName == null) {
+ if (other.fileName != null) {
+ return false;
+ }
+ } else if (!fileName.equals(other.fileName)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
}
Added: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java (rev 0)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java 2011-04-13 14:40:47 UTC (rev 798)
@@ -0,0 +1,39 @@
+package org.nuiton.wikitty.publication;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.Properties;
+
+/**
+ * Class usefull when load properties file, update, delete, then save again
+ * File used to load properties is store.
+ *
+ * @author mfortun
+ *
+ */
+public class PropertiesExtended extends Properties {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -264337198024996529L;
+
+ protected File origin;
+
+ public PropertiesExtended(File origin) throws Exception {
+ super();
+ this.load(origin);
+
+ }
+
+ public void load(File file) throws Exception {
+ this.origin = file;
+ this.load(new FileReader(origin));
+ }
+
+ public void store() throws Exception {
+ this.store(new FileWriter(origin), "");
+ }
+
+}
Property changes on: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PropertiesExtended.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-13 09:32:21 UTC (rev 797)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-13 14:40:47 UTC (rev 798)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 - 2011 CodeLutin
+ * Copyright (C) 2010 - 2011 CodeLutin mfortun
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -27,29 +27,27 @@
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import org.apache.commons.collections.BidiMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
-import org.nuiton.util.StringUtil;
+import org.nuiton.util.CollectionUtil;
+import org.nuiton.util.FileUtil;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.entities.Wikitty;
import org.nuiton.wikitty.entities.WikittyLabel;
+import org.nuiton.wikitty.entities.WikittyLabelHelper;
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.PagedResult;
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
@@ -514,9 +512,12 @@
// check args
if (null == toDelete || !toDelete.exists()) {
// Exception
+
} else {
- File wpHomeDir = searchWikittyPublicationHomeDir(new File("."));
+ File currentDir = new File(FileUtil.getCurrentDirectory()
+ .getAbsolutePath());
+ File wpHomeDir = searchWikittyPublicationHomeDir(currentDir);
// search for the .wp home dir to load props
// then load proxy
@@ -526,9 +527,6 @@
File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
- // on va chercher le home dir
- wpHomeDir = searchWikittyPublicationHomeDir(dir);
-
Properties properties = new Properties();
// TODO mfortun-2011-04-06 catch exception instead of throws
@@ -558,10 +556,83 @@
log.info("Delete " + " wikitty-service" + wikittyService
+ " hessian Protocole :" + hessianProtocole
+ "file to delete : " + toDelete.getAbsolutePath());
+ // on va chercher le home dir
+ wpHomeDir = searchWikittyPublicationHomeDir(dir);
- System.out.println("try to delete: ");
- printDirectory(dir, true);
+ WikittyProxy remoteWikittyService = new WikittyProxy(
+ WikittyServiceFactory
+ .buildWikittyService(applicationConfig));
+ WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
+ dir);
+ if (toDelete.isDirectory()) {
+
+ BidiMap deleteMap = WikittyPublicationFileSystem
+ .harvestLocalWikitties(toDelete, true);
+ List<String> ids = new ArrayList<String>();
+ ids = new ArrayList<String>();
+ ids.addAll(CollectionUtil.toGenericCollection(
+ deleteMap.keySet(), String.class));
+
+ for (String key : ids) {
+ // restore wikitty
+ Wikitty wd = remoteWikittyService.restore(key);
+
+ // searh for the label to delete from the wikitty
+ FileSystemWIkittyId location = (FileSystemWIkittyId) deleteMap
+ .get(key);
+
+ File wikittyFileParent = new File(location.getPath());
+ PropertiesExtended metaExtended = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(
+ wikittyFileParent,
+ WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ String currentLabel = metaExtended
+ .getProperty(META_CURRENT_LABEL);
+ // remove label
+ WikittyLabelHelper.removeLabels(wd, currentLabel);
+ // save the wikitty
+ remoteWikittyService.store(wd);
+ }
+
+ localWikittyService.delete("", ids);
+ // if it was a directory the wikitty file service does not have
+ // delete it
+
+ FileUtil.deleteRecursively(toDelete);
+ } else {
+ // infos about file about to delete
+ String name = toDelete.getName();
+ File parentFile = toDelete.getParentFile();
+ // search of it's id
+ PropertiesExtended metaProps = WikittyPublicationFileSystem
+ .getWikittyPublicationProperties(
+ parentFile,
+ WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ String id = metaProps.getProperty(name
+ + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_ID);
+ // his label
+ String label = metaProps
+ .getProperty(WikittyPublication.META_CURRENT_LABEL);
+
+ // restore wikitty remote
+
+ Wikitty wd = remoteWikittyService.restore(id);
+
+ // remove label
+
+ WikittyLabelHelper.removeLabels(wd, label);
+ // save the wikitty remote
+ remoteWikittyService.store(wd);
+
+ List<String> ids = new ArrayList<String>();
+ ids.add(id);
+ // delete localy
+ localWikittyService.delete("", ids);
+ }
+
}
/*
@@ -651,6 +722,7 @@
File propertyDirectory = new File(start.getCanonicalPath()
+ File.separator + PROPERTY_DIRECTORY);
+
if (propertyDirectory.exists()) {
File propertie = new File(propertyDirectory.getCanonicalPath()
+ File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
@@ -658,6 +730,7 @@
return propertyDirectory;
}
}
+
return searchWikittyPublicationHomeDir(start.getParentFile());
} else {
// Exception
@@ -668,56 +741,6 @@
}
}
- static protected HashMap<String, String> deleteFile(File toDelete)
- throws Exception {
- HashMap<String, String> result = new HashMap<String, String>();
-
- String pathToProperty = toDelete.getCanonicalFile() + File.separator
- + PROPERTY_DIRECTORY + File.separator;
- // load properties files
- File metaFile = new File(pathToProperty
- + WIKITTY_FILE_META_PROPERTIES_FILE);
- Properties metaProperties = new Properties();
- metaProperties.load(new FileReader(metaFile));
-
- File idFile = new File(pathToProperty + WIKITTY_ID_PROPERTIES_FILE);
- Properties idProperties = new Properties();
- idProperties.load(new FileReader(idFile));
-
- if (toDelete.isDirectory()) {
- for (File child : toDelete.listFiles()) {
- if (child.isDirectory()
- && !child.getName().equals(PROPERTY_DIRECTORY)) {
- result.putAll(deleteFile(child));
- }
- }
-
- } else {
-
- String id = metaProperties.getProperty(toDelete.getName()
- + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_ID);
- String label = metaProperties.getProperty(META_CURRENT_LABEL);
-
- result.put(id, label);
- // remove from properties
- idProperties.remove(id);
-
- metaProperties.remove(toDelete.getName()
- + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_ID);
- metaProperties.remove(toDelete.getName()
- + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_CHECKSUM);
- metaProperties.remove(toDelete.getName()
- + DEFAULT_PROPERTY_NAME_SEP + META_SUFFIX_KEY_VERSION);
- }
-
- metaProperties.store(new FileWriter(metaFile), "");
- idProperties.store(new FileWriter(idFile), "");
-
- toDelete.delete();
- return result;
-
- }
-
static protected void writeHomePropertyFile(File homeDir) throws Exception {
if (homeDir.exists()) {
@@ -776,4 +799,5 @@
return result;
}
+
}
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 09:32:21 UTC (rev 797)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationFileSystem.java 2011-04-13 14:40:47 UTC (rev 798)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 - 2011 CodeLutin
+ * Copyright (C) 2010 - 2011 CodeLutin mfortun
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -37,9 +37,15 @@
import java.util.Properties;
import java.util.Set;
+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.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.apache.velocity.texen.util.PropertiesUtil;
+import org.nuiton.util.CollectionUtil;
import org.nuiton.util.FileUtil;
+import org.nuiton.util.LRUMapMultiKey;
import org.nuiton.util.MD5InputStream;
import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.WikittyService;
@@ -84,6 +90,17 @@
this.setLabel(label);
}
+
+
+
+ public WikittyPublicationFileSystem(File homeFile) {
+ this(homeFile, true, "");
+
+ }
+
+
+
+
public File getHomeFile() {
return homeFile;
}
@@ -393,65 +410,80 @@
public List<Wikitty> restore(String securityToken, List<String> id) {
List<Wikitty> result = new ArrayList<Wikitty>();
try {
- Map<String, FileSystemWIkittyId> locations = harvestLocalWikitties(
- homeFile, recursion);
+ BidiMap locations = harvestLocalWikitties(homeFile, recursion);
for (String wikid : id) {
- FileSystemWIkittyId localisation = locations.get(wikid);
- // create the wikitty with his id
- Wikitty wikitty = new WikittyImpl(wikid);
- // add label extension
- wikitty.addExtension(WikittyLabelImpl.extensionWikittyLabel);
+ Object value = locations.get(wikid);
- // preparation for mime research and file research
- String path = localisation.getPath();
- String completeName = localisation.getFileName();
+ if (value == null) {
+ locations = locations.inverseBidiMap();
+ value = locations.get(wikid);
+ }
- // search for the file
- File fileToTransform = new File(path + File.separator
- + completeName);
+ if (value != null) {
- String extension = FileUtil.extension(fileToTransform);
- String name = FileUtil.basename(completeName, "." + extension);
- // search for the mimetype
- String mimeType = mimeTypeForExtension(extension);
+ FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
- // load properties
- Properties props = new Properties();
- File propsFile = new File(path + File.separator
- + WikittyPublication.PROPERTY_DIRECTORY
- + File.separator
- + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
- props.load(new FileReader(propsFile));
- // re set the id
- wikitty.setVersion(props.getProperty(completeName
- + WikittyPublication.META_SUFFIX_KEY_ID));
+ // create the wikitty with his id
+ Wikitty wikitty = new WikittyImpl(wikid);
+ // add label extension
+ wikitty.addExtension(WikittyLabelImpl.extensionWikittyLabel);
- // set the current label
- WikittyLabelHelper.addLabels(wikitty, props
- .getProperty(WikittyPublication.META_CURRENT_LABEL));
+ // preparation for mime research and file research
+ String path = localisation.getPath();
+ String completeName = localisation.getFileName();
- /*
- * TODO mfortun-2011-04-12 need to merge part of this code with
- * filetowikitty method 'cause it is basically the same
- */
+ // search for the file
+ File fileToTransform = new File(path + File.separator
+ + completeName);
- // 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));
+ String extension = FileUtil.extension(fileToTransform);
+ String name = FileUtil.basename(completeName, "."
+ + extension);
+ // search for the mimetype
+ String mimeType = mimeTypeForExtension(extension);
+
+ // load properties
+ Properties props = new Properties();
+ File propsFile = new File(
+ path
+ + File.separator
+ + WikittyPublication.PROPERTY_DIRECTORY
+ + File.separator
+ + WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+ props.load(new FileReader(propsFile));
+ // re set the id
+ wikitty.setVersion(props.getProperty(completeName
+ + WikittyPublication.META_SUFFIX_KEY_ID));
+
+ // set the current label
+ WikittyLabelHelper
+ .addLabels(
+ wikitty,
+ props.getProperty(WikittyPublication.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(wikitty);
}
} catch (Exception e) {
e.printStackTrace();
@@ -462,10 +494,65 @@
@Override
public WikittyEvent delete(String securityToken, Collection<String> ids) {
- // TODO mfortun-2011-04-05
- throw new UnsupportedOperationException("not yet implemented");
- // return null;
+ try {
+ BidiMap location = harvestLocalWikitties(homeFile, true);
+
+ for (String id : ids) {
+
+ Object value = location.get(id);
+
+ if (value == null) {
+ location = location.inverseBidiMap();
+ value = location.get(id);
+ }
+
+ if (value != null) {
+
+ FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
+
+ String path = localisation.getPath();
+ String fileName = localisation.getFileName();
+
+ // load properties
+ PropertiesExtended propsProperties = getWikittyPublicationProperties(new File(
+ path), WikittyPublication.WIKITTY_FILE_META_PROPERTIES_FILE);
+
+ // update
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_CHECKSUM);
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_ID);
+ propsProperties.remove(fileName
+ + WikittyPublication.META_SUFFIX_KEY_VERSION);
+
+ // resave
+ propsProperties.store();
+
+ // load properties
+ PropertiesExtended idProperties = getWikittyPublicationProperties(new File(
+ path), WikittyPublication.WIKITTY_ID_PROPERTIES_FILE);
+ // update
+ idProperties.remove(id);
+ // resave
+ idProperties.store();
+
+ File wikittyFile = new File(path + File.separator
+ + fileName);
+
+ if (wikittyFile.exists()) {
+ wikittyFile.delete();
+ }
+
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO mfortun-2011-04-13 really handle exception
+ }
+
+ WikittyEvent result = new WikittyEvent(this);
+ return result;
}
@Override
@@ -689,15 +776,10 @@
* @return
* @throws Exception
*/
- static public Map<String, FileSystemWIkittyId> harvestLocalWikitties(
- File starts, boolean recursivly) throws Exception {
- Map<String, FileSystemWIkittyId> result = new HashMap<String, FileSystemWIkittyId>();
+ static public BidiMap harvestLocalWikitties(File starts, boolean recursivly)
+ throws Exception {
+ BidiMap result = new DualHashBidiMap();
- /*
- * TODO mfortun-2011-04-12 find a better way to have cohesion class that
- * call another class that call last class <_<. May be a class for file
- * access/harvest method
- */
List<File> propertiesDirectory = WikittyPublication
.harvestPropertyDirectory(starts, recursivly);
@@ -717,7 +799,7 @@
String path = propsDir.getParent();
FileSystemWIkittyId value = new FileSystemWIkittyId(name, path);
- result.put((String) id, value);
+ result.put((String) id, value );
}
}
@@ -733,4 +815,26 @@
return result;
}
+ static public PropertiesExtended getWikittyPublicationProperties(File starts, String name)
+ throws Exception {
+
+ File propertieDirectory = new File(starts.getCanonicalPath()
+ + File.separator + WikittyPublication.PROPERTY_DIRECTORY);
+
+ // load/create meta propertie file
+ File propertieFile = new File(propertieDirectory.getCanonicalPath()
+ + File.separator
+ + name);
+ if (!propertieFile.exists()) {
+ propertieFile.createNewFile();
+ }
+
+ PropertiesExtended result = new PropertiesExtended(propertieFile);
+
+ return result;
+ }
+
+
+
+
}
1
0
Author: echatellier
Date: 2011-04-13 11:32:21 +0200 (Wed, 13 Apr 2011)
New Revision: 797
Url: http://nuiton.org/repositories/revision/wikitty/797
Log:
Fix name
Added:
trunk/wikitty-jdbc/src/test/resources/postgres-wikitty-config.properties
Copied: trunk/wikitty-jdbc/src/test/resources/postgres-wikitty-config.properties (from rev 796, trunk/wikitty-jdbc/src/test/resources/postrges-wikitty-config.properties)
===================================================================
--- trunk/wikitty-jdbc/src/test/resources/postgres-wikitty-config.properties (rev 0)
+++ trunk/wikitty-jdbc/src/test/resources/postgres-wikitty-config.properties 2011-04-13 09:32:21 UTC (rev 797)
@@ -0,0 +1,33 @@
+###
+# #%L
+# Wikitty :: wikitty-jdbc-impl
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+wikitty.storage.jdbc.driver=org.postgresql.Driver
+wikitty.storage.jdbc.host=jdbc:postgresql://localhost/test
+wikitty.storage.jdbc.password=password
+wikitty.storage.jdbc.login=test
+wikitty.storage.jdbc.xadatasource=org.postgresql.xa.PGXADataSource
+wikitty.storage.jdbc.xadatasource.org.postgresql.xa.PGXADataSource.serverName=localhost
+wikitty.storage.jdbc.xadatasource.org.postgresql.xa.PGXADataSource.databaseName=test
+wikitty.storage.jdbc.xadatasource.org.postgresql.xa.PGXADataSource.password=password
+wikitty.storage.jdbc.xadatasource.org.postgresql.xa.PGXADataSource.user=test
\ No newline at end of file
1
0
r796 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication
by mfortun@users.nuiton.org 13 Apr '11
by mfortun@users.nuiton.org 13 Apr '11
13 Apr '11
Author: mfortun
Date: 2011-04-13 09:41:02 +0200 (Wed, 13 Apr 2011)
New Revision: 796
Url: http://nuiton.org/repositories/revision/wikitty/796
Log:
* remove sub label property, no use finally.
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-12 16:19:00 UTC (rev 795)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublication.java 2011-04-13 07:41:02 UTC (rev 796)
@@ -51,7 +51,6 @@
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
* point for sync operation : import, checkout, commit, delete, relocate and
@@ -73,7 +72,7 @@
* static string for allias, wrong named attribut TODO mfortun-2011-04-06
* need to set better name
*/
-
+
/*
* FIXME mfortun-2011-04-11 need to migrate static value to another class ?
*/
@@ -105,7 +104,6 @@
static public String META_SUFFIX_KEY_ID = "id";
static public String META_CURRENT_LABEL = "current.label";
- static public String META_SUB_LABEL = "sub.label";
/**
* @param args
@@ -304,15 +302,12 @@
applicationConfig.setOption("wikitty.WikittyService.components",
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
}
-
+
WikittyProxy remoteWikittyService = new WikittyProxy(
WikittyServiceFactory.buildWikittyService(applicationConfig));
WikittyPublicationFileSystem localWikittyService = new WikittyPublicationFileSystem(
dir, !noRecur, label);
-
-
-
// Construct the criteria
Criteria labelCriteria;
Search mainRequest = Search.query();
@@ -335,18 +330,15 @@
.criteria();
}
-
-
// request to the proxy
- PagedResult<Wikitty> pageResult= remoteWikittyService.findAllByCriteria(labelCriteria);
-
+ PagedResult<Wikitty> pageResult = remoteWikittyService
+ .findAllByCriteria(labelCriteria);
+
List<Wikitty> wikittiesToWrite = pageResult.getAll();
-
-
-
+
// write the proper properties file!
writeHomePropertyFile(dir);
-
+
// write the wikities
localWikittyService.store("", wikittiesToWrite, true);
@@ -355,8 +347,6 @@
* the appropriate wikittyservice !
*/
-
-
/*
* on va commencer par vérifier les arguments ''wp checkout
* [--norecursion] [url du WikittyService] [Label à extraire] [directory
@@ -701,21 +691,6 @@
result.putAll(deleteFile(child));
}
}
- // remove label from current label list
- /*
- * TODO mfortun-2011-04-07 it's ugly change this, if we keep the
- * property linked
- */
- String[] currents = StringUtil.split(
- metaProperties.getProperty(META_SUB_LABEL), ",");
- ArrayList<String> subLabel = new ArrayList<String>();
- for (String sub : currents) {
- if (!sub.endsWith(toDelete.getName())) {
- subLabel.add(sub);
- }
- }
- String subLabelResult = StringUtil.join(subLabel, ",", true);
- metaProperties.put(META_SUB_LABEL, subLabelResult);
} else {
@@ -743,19 +718,17 @@
}
-
- static protected void writeHomePropertyFile(File homeDir) throws Exception{
-
-
+ static protected void writeHomePropertyFile(File homeDir) throws Exception {
+
if (homeDir.exists()) {
File dir = applicationConfig.getOptionAsFile(DIRECTORY_KEY);
String wikittyService = applicationConfig
.getOption(WITTY_SERVICE_KEY);
boolean hessianProtocole = applicationConfig
.getOptionAsBoolean(HESSIAN_PROTOCOL_KEY);
-
-
- //TODO mfortun-2011-04-11 find a better way to manage component property
+
+ // TODO mfortun-2011-04-11 find a better way to manage component
+ // property
String propertyCompo = applicationConfig
.getOption("wikitty.WikittyService.components");
// write the proper properties file!
@@ -767,43 +740,40 @@
// create the properties directory
File wpDirectory = new File(homeDir.getCanonicalPath()
+ File.separator + PROPERTY_DIRECTORY + File.separator);
- if (!wpDirectory.exists() ) {
+ if (!wpDirectory.exists()) {
wpDirectory.mkdir();
}
-
File propertiesFiles = new File(wpDirectory.getCanonicalPath()
+ File.separator + WIKITTYPUBLICATION_PROPERTIES_FILE);
-
-
props.store(new FileWriter(propertiesFiles), "");
}
}
-
-
+
/**
- * Method that create a list of the properties directory
+ * Method that create a list of the properties directory
*
* @param starts
* harvested directory
* @param recursivly
* @return list of harvested file
*/
- static public List<File> harvestPropertyDirectory (File starts, boolean recursivly){
-
- List<File> result = new ArrayList<File>();
-
- for (File child : starts.listFiles()) {
-
- if (child.isDirectory() && child.getName().equals(PROPERTY_DIRECTORY)) {
- result.add(child);
- } else if (child.isDirectory() && recursivly){
- result.addAll(harvestPropertyDirectory(child, recursivly));
- }
+ static public List<File> harvestPropertyDirectory(File starts,
+ boolean recursivly) {
+
+ List<File> result = new ArrayList<File>();
+
+ for (File child : starts.listFiles()) {
+
+ if (child.isDirectory()
+ && child.getName().equals(PROPERTY_DIRECTORY)) {
+ result.add(child);
+ } else if (child.isDirectory() && recursivly) {
+ result.addAll(harvestPropertyDirectory(child, recursivly));
}
- return result;
-
-
+ }
+ return result;
+
}
}
1
0
r795 - trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr
by jcouteau@users.nuiton.org 12 Apr '11
by jcouteau@users.nuiton.org 12 Apr '11
12 Apr '11
Author: jcouteau
Date: 2011-04-12 18:19:00 +0200 (Tue, 12 Apr 2011)
New Revision: 795
Url: http://nuiton.org/repositories/revision/wikitty/795
Log:
Put beforeclass in each test instead of abstract
Modified:
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java
trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2011-04-12 16:08:25 UTC (rev 794)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/AbstractTestSolr.java 2011-04-12 16:19:00 UTC (rev 795)
@@ -51,12 +51,4 @@
ws.clear(null);
}
- @BeforeClass
- public static void initTests() throws Exception {
-
- SolrTestHelper.initTests(instance);
-
- ws = new WikittyServiceEnhanced(new WikittyServiceSolr(instance));
- }
-
}
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java 2011-04-12 16:08:25 UTC (rev 794)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrSearchTest.java 2011-04-12 16:19:00 UTC (rev 795)
@@ -40,6 +40,7 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.util.CollectionUtil;
import org.nuiton.wikitty.search.Criteria;
@@ -57,6 +58,7 @@
import org.nuiton.wikitty.search.RestrictionHelper;
import org.nuiton.wikitty.search.Search;
import org.nuiton.wikitty.search.operators.Like;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
public class SolrSearchTest extends AbstractTestSolr {
@@ -66,6 +68,14 @@
protected WikittyExtension extProduct;
protected WikittyExtension extTest;
+ @BeforeClass
+ public static void initTests() throws Exception {
+
+ SolrTestHelper.initTests(instance);
+
+ ws = new WikittyServiceEnhanced(new WikittyServiceSolr(instance));
+ }
+
@Before
public void createTestData() throws Exception {
extCategory = new WikittyExtension("Category", "1", null,
Modified: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java
===================================================================
--- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 2011-04-12 16:08:25 UTC (rev 794)
+++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/TreeTest.java 2011-04-12 16:19:00 UTC (rev 795)
@@ -40,6 +40,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.nuiton.wikitty.search.Criteria;
import org.nuiton.wikitty.entities.ExtensionFactory;
@@ -54,6 +55,7 @@
import org.nuiton.wikitty.entities.WikittyTreeNodeHelper;
import org.nuiton.wikitty.search.Search;
import org.nuiton.wikitty.search.TreeNodeResult;
+import org.nuiton.wikitty.services.WikittyServiceEnhanced;
/**
*
@@ -75,6 +77,14 @@
createTestData();
}
+ @BeforeClass
+ public static void initTests() throws Exception {
+
+ SolrTestHelper.initTests(instance);
+
+ ws = new WikittyServiceEnhanced(new WikittyServiceSolr(instance));
+ }
+
/**
* Create a extension, use to store element in tree
*/
1
0
r794 - trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr
by jcouteau@users.nuiton.org 12 Apr '11
by jcouteau@users.nuiton.org 12 Apr '11
12 Apr '11
Author: jcouteau
Date: 2011-04-12 18:08:25 +0200 (Tue, 12 Apr 2011)
New Revision: 794
Url: http://nuiton.org/repositories/revision/wikitty/794
Log:
Fix search on Treenodes
Modified:
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java 2011-04-12 15:31:01 UTC (rev 793)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/WikittySearchEngineSolr.java 2011-04-12 16:08:25 UTC (rev 794)
@@ -828,13 +828,18 @@
// de construire l'arbre
for (SolrDocument d : solrResults) {
String id = (String) d.getFieldValue(SOLR_ID);
- String parentId = (String) d.getFieldValue(SolrUtil.getSolrFieldName(
+
+ List<String> parentIds = (List<String>) d.getFieldValue(SolrUtil.getSolrFieldName(
WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_PARENT,
TYPE.WIKITTY));
int nb = counts.containsKey(id) ? counts.get(id) : 0;
TreeNodeResult<String> child = new TreeNodeResult<String>(id, nb);
allTreeNodeResult.put(id, child);
- childParent.put(id, parentId);
+ if (parentIds != null) {
+ for (String parentId : parentIds) {
+ childParent.put(id, parentId);
+ }
+ }
}
// construction de l'arbre avant de le retourner
for(Map.Entry<String, TreeNodeResult<String>> e : allTreeNodeResult.entrySet()) {
@@ -843,7 +848,9 @@
if (allTreeNodeResult.containsKey(parentId)) {
TreeNodeResult<String> child = e.getValue();
TreeNodeResult<String> parent = allTreeNodeResult.get(parentId);
- parent.add(child);
+ if (parent != child) {
+ parent.add(child);
+ }
}
}
result = allTreeNodeResult.get(wikittyId);
1
0