Author: mfortun Date: 2011-04-20 16:45:47 +0200 (Wed, 20 Apr 2011) New Revision: 823 Url: http://nuiton.org/repositories/revision/wikitty/823 Log: * javadoc * change of property file due to testing * add a method that check if there was a modification in a file and increment the minor version of the wikitty * correct a bug with label/directory there was a mismatch. Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 12:22:19 UTC (rev 822) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-20 14:45:47 UTC (rev 823) @@ -46,11 +46,9 @@ /** * Main class of the sync part of wikitty publication, this class is the entry - * point for sync operation : import, checkout, commit, delete, relocate and - * update. + * point for sync operation. Existing, delete and update. * * - * * @author mfortun * */ @@ -59,18 +57,29 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ final static private Log log = LogFactory.getLog(WikittyPublication.class); + /** + * option for the url of a wikitty service + */ static public String WIKITTY_OPTION_URL = "wikitty.service.server.url"; + /** + * option for the component class use to interract with the wikittyService + */ static public String WIKITTY_OPTION_COMPONENT = "wikitty.WikittyService.components"; static protected ApplicationConfig applicationConfig; - /* - * static string for allias, wrong named attribut TODO mfortun-2011-04-06 - * need to set better name + + /** + * for recursion option */ - static public String IS_RECURSION_OPTION = "isRecur"; + /** + * for delete option + */ static public String IS_DELETE_OPTION = "delete"; + /** + * for existing option + */ static public String IS_EXISTING_OPTION = "existing"; static public String LABEL_KEY = "working.label"; Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 12:22:19 UTC (rev 822) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-20 14:45:47 UTC (rev 823) @@ -42,10 +42,7 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; - -import javax.activation.MimeType; import javax.activation.MimetypesFileTypeMap; - import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.bidimap.DualHashBidiMap; import org.apache.commons.logging.Log; @@ -55,8 +52,6 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.MD5InputStream; import org.nuiton.util.StringUtil; -import org.nuiton.wikitty.WikittyConfig; -import org.nuiton.wikitty.WikittyConfigOption; import org.nuiton.wikitty.WikittyException; import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.WikittyUtil; @@ -74,9 +69,7 @@ import org.nuiton.wikitty.publication.entities.WikittyPubTextHelper; import org.nuiton.wikitty.publication.entities.WikittyPubTextImpl; import org.nuiton.wikitty.search.Criteria; - import org.nuiton.wikitty.search.PagedResult; - import org.nuiton.wikitty.search.TreeNodeResult; import org.nuiton.wikitty.search.operators.And; import org.nuiton.wikitty.search.operators.AssociatedRestriction; @@ -147,19 +140,15 @@ */ try { - this.pubTextMimeType = new ArrayList<String>(); - - //TODO create a property file to store and handle mimetype for pub text + + // TODO create a property file to store and handle mimetype for pub + // text pubTextMimeType.add("application/javascript"); - - - + String url = app.getOption(WikittyPublication.WIKITTY_OPTION_URL); URI uri = new URI(url); - this.label = uri.getFragment(); - this.homeFile = new File(uri.getPath()); if (homeFile == null || !homeFile.exists()) { @@ -167,6 +156,12 @@ homeFile = new File(cur.getAbsolutePath()); } + this.label = uri.getFragment(); + + if (label == null) { + label = homeFile.getName(); + } + this.recursion = app .getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION); @@ -379,7 +374,8 @@ metaProperties.store(); // write common properties - writeWikittyFileProperties(wikittyFile, w.getId()); + writeWikittyFileProperties(wikittyFile, w.getId(), + w.getVersion()); } } } @@ -676,7 +672,6 @@ checked = ((String) o).endsWith((String) value); break; case STARTS_WITH: - System.out.println(t.isCollection()); if (t.getType() != TYPE.STRING) { throw new WikittyException( "Can't search for contents that 'starts with' on attribute type different of String. " @@ -933,7 +928,12 @@ List<Criteria> criteria) { Map<String, Wikitty> wikitties = new HashMap<String, Wikitty>(); try { - harvestNew(homeFile, label); + String labelToDir = this.labelToPath(label); + File starts = new File (homeFile.getAbsolutePath()+File.separator+labelToDir); + if (starts.exists()){ + harvestNewCheckModifications(starts, label); + } + BidiMap map = harvestLocalWikitties(homeFile, true); for (Object o : map.keySet()) { @@ -945,7 +945,7 @@ } } catch (Exception e) { - // TODO Auto-generated catch block + // TODO mfortun-2011-04-20 really handle exception e.printStackTrace(); } @@ -1056,10 +1056,6 @@ } - - - - /** * return if the mime type is associate to a wikittypubtext * @@ -1177,8 +1173,8 @@ String extension = FileUtil.extension(fileToTransform); String name = FileUtil.basename(completeName, "." + extension); - - MimetypesFileTypeMap mapMime= new MimetypesFileTypeMap(); + + MimetypesFileTypeMap mapMime = new MimetypesFileTypeMap(); // search for the mimetype String mimeType = mapMime.getContentType(fileToTransform); @@ -1216,7 +1212,8 @@ return result; } - protected void harvestNew(File starts, String label) throws Exception { + protected void harvestNewCheckModifications(File starts, String label) + throws Exception { File propertyFile = new File(starts + File.separator + PROPERTY_DIRECTORY); @@ -1240,27 +1237,79 @@ for (File child : starts.listFiles()) { if (child.isDirectory() && !child.getName().equals(PROPERTY_DIRECTORY)) { - harvestNew(child, - label + WIKITTYLABEL_SEPARATOR + child.getName()); + harvestNewCheckModifications(child, label + + WIKITTYLABEL_SEPARATOR + child.getName()); } else if (!child.isDirectory()) { + // check if file is a wikitty by check if they is a id/file name + // in the correct properties file List<String> filesWikitty = new ArrayList<String>(); filesWikitty.addAll(CollectionUtil.toGenericCollection( ids.values(), String.class)); // if file is not a wikitty create it. if (!filesWikitty.contains(child.getName())) { - writeWikittyFileProperties(child, null); + writeWikittyFileProperties(child, null, null); + } else { + checkModifications(child); } } } } - protected void writeWikittyFileProperties(File towrite, String wikittyID) - throws Exception { + protected void checkModifications(File child) throws Exception { + // will check if there was modification with checksum + BufferedInputStream input = new BufferedInputStream( + new FileInputStream(child)); + + byte[] byt = MD5InputStream.hash(input); + + String localMd5 = StringUtil.asHex(byt); + + PropertiesExtended meta = getWikittyPublicationProperties( + child.getParentFile(), WIKITTY_FILE_META_PROPERTIES_FILE); + + String registeredMD5 = meta.getProperty(META_PREFIX_KEY_CHECKSUM + + child.getName()); + // compare the different checksum + if (!localMd5.equals(registeredMD5)) { + // increment version and set new checksum + String currentVersion = meta.getProperty(META_PREFIX_KEY_VERSION + + child.getName()); + meta.setProperty(META_PREFIX_KEY_VERSION + child.getName(), + WikittyUtil.incrementMinorRevision(currentVersion)); + meta.setProperty(META_PREFIX_KEY_CHECKSUM + child.getName(), + localMd5); + } + meta.store(); + } + + /** + * write in properties file property about the file corresponding to a + * wikitty. If the file does not match a wikitty yet set wikittyID and + * Wikittyversion to null + * + * @param towrite + * the file + * @param wikittyID + * wiitty id, null if wikitty does not exist yet + * @param wikittyVersion + * wikitty version, null if wikitty not exist yet + * @throws Exception + */ + protected void writeWikittyFileProperties(File towrite, String wikittyID, + String wikittyVersion) throws Exception { + if (towrite.exists() && !towrite.isDirectory()) { Wikitty wikitty = new WikittyImpl(wikittyID); + if (wikittyVersion != null) { + wikitty.setVersion(wikittyVersion); + } else { + // simulate operations en wikitty if new + wikitty.setVersion(WikittyUtil.incrementMinorRevision(wikitty + .getVersion())); + } File parent = towrite.getParentFile(); @@ -1324,4 +1373,17 @@ return result; } + + public String labelToPath (String label){ + String result = label; + + result = result.replace(".", File.separator); + + // correct the pb with directory name begin by . + result = result.replace(File.separator + File.separator, + File.separator + "."); + + return result; + } + } Modified: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties =================================================================== --- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties 2011-04-20 12:22:19 UTC (rev 822) +++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-codelutin.properties 2011-04-20 14:45:47 UTC (rev 823) @@ -22,4 +22,4 @@ # <http://www.gnu.org/licenses/lgpl-3.0.html>. # #L% ### -wikitty.data.directory=/var/lib/wikitty-publication/codelutin2 +wikitty.data.directory=/var/lib/wikitty-publication/codelutin/ Modified: trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties =================================================================== --- trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2011-04-20 12:22:19 UTC (rev 822) +++ trunk/wikitty-publication/src/main/resources/wikitty-publication-ws-default.properties 2011-04-20 14:45:47 UTC (rev 823) @@ -22,7 +22,9 @@ # <http://www.gnu.org/licenses/lgpl-3.0.html>. # #L% ### -wikitty.data.directory=./target2/data + +wikitty.data.directory=./targetBD1/data +wikitty.service.server.url=http://localhost:1111/wikitty wikitty.storage.jdbc.queryfile=wikitty-jdbc-query.properties wikitty.storage.jdbc.driver=org.h2.Driver wikitty.storage.jdbc.host=jdbc:h2:file:${wikitty.data.directory}/data/db @@ -40,7 +42,7 @@ org.nuiton.wikitty.services.WikittyServiceSecurity,\ org.nuiton.wikitty.services.WikittyServiceAccessStat,\ org.nuiton.wikitty.services.WikittyServiceCajoServer -wikitty.service.server.url=http://localhost:1111/wikitty + wikitty.WikittyServiceStorage.components=org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC,\ org.nuiton.wikitty.jdbc.WikittyStorageJDBC,\ org.nuiton.wikitty.storage.solr.WikittySearchEngineSolr