Author: mfortun Date: 2011-04-28 15:31:52 +0200 (Thu, 28 Apr 2011) New Revision: 844 Url: http://nuiton.org/repositories/revision/wikitty/844 Log: * commit/update basically works * correct a bug with label in synchronization Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-27 17:46:44 UTC (rev 843) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-28 13:31:52 UTC (rev 844) @@ -37,6 +37,7 @@ import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; import org.nuiton.util.FileUtil; +import org.nuiton.util.StringUtil; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.WikittyServiceFactory; import org.nuiton.wikitty.WikittyUtil; @@ -151,6 +152,10 @@ static public void synchronisation(String origin, String target) throws URISyntaxException { + + System.out.println(origin); + System.out.println(target); + boolean isRecur = applicationConfig .getOptionAsBoolean(IS_RECURSION_OPTION); @@ -189,7 +194,7 @@ WikittyServiceFactory.buildWikittyService(temp2)); String labelOrigin = uriOrigin.getFragment(); - String labelTarget = uriOrigin.getFragment(); + String labelTarget = uriTarget.getFragment(); Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur); Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur); @@ -239,8 +244,8 @@ for (String labels : saveLabelOrigin) { if (isRecur && labels.startsWith(labelOrigin)) { - String finalLabelTarge = labels.replace(labelOrigin, - labelTarget); + String finalLabelTarge = new String(labels.replace( + labelOrigin, labelTarget)); targetLabels.add(finalLabelTarge); } else if (!isRecur && labels.equals(labelOrigin)) { targetLabels.add(labelTarget); @@ -433,6 +438,23 @@ static public void update(String... uriFileSystem) throws Exception { + // only difference between update and commit is the param's order + // when calling synchronisation method + commitUpdateDelegate(false, uriFileSystem); + + } + + static public void commit(String... uriFileSystem) throws Exception { + + // only difference between update and commit is the param's order + // when calling synchronisation method + commitUpdateDelegate(true, uriFileSystem); + + } + + protected static void commitUpdateDelegate(boolean isCommit, + String... uriFileSystem) throws Exception { + /* * Alors c'est facile si on a un élément dans le param c'est que on * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on @@ -448,26 +470,34 @@ * et pareil on va construire les adresses pour faire une synchro */ - } + // update is from wikitty service store to wikitty service File System - static public void commit(String... uriFileSystem) throws Exception { + String wikittyServiceInter = ""; + String wikittyServiceFileSystem = ""; + String wikittyServiceInterSave = ""; - String target = ""; - String origin = ""; - File currentDir = new File(FileUtil.getCurrentDirectory() .getAbsolutePath()); - + String labelInitial = ""; PropertiesExtended homePorperty = null; + // Check number of argument switch (uriFileSystem.length) { + // if none, then the current dir have to be commit. case 0: + // search for the home property dir that containt uri to the wikitty + // service + File homePropertyDir = WikittyPublicationFileSystem + .searchWikittyPublicationHomePropertie(currentDir); homePorperty = WikittyPublicationFileSystem - .searchWikittyPublicationHomePropertie(currentDir); + .getWikittyPublicationProperties(homePropertyDir, + WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); - target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR); + // load the wikitty service uri (distant one) + wikittyServiceInter = homePorperty + .getProperty(WIKITTY_SERVICE_INTERLOCUTEUR); - // construct the current uri for origin + // construct the current uri for wikitty service file system // search the current label PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem .getWikittyPublicationProperties( @@ -476,58 +506,61 @@ String labelCurrent = metaPropertiesExtended .getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL); - origin = "file:///" + currentDir.getAbsolutePath() + "#" - + labelCurrent; + // construct uri of the wikitty publication file system + wikittyServiceFileSystem = "file://" + + homePropertyDir.getAbsolutePath() + "#" + labelCurrent; + labelInitial = homePorperty.getProperty(LABEL_KEY); + wikittyServiceInterSave = wikittyServiceInter; + wikittyServiceInter += labelCurrent.replaceFirst(labelInitial, ""); - synchronisation(origin, target); break; - + // if a param is set it mean that the uri of the File system is set case 1: - origin = uriFileSystem[0]; - URI originUri = new URI(origin); + wikittyServiceFileSystem = uriFileSystem[0]; + URI originUri = new URI(wikittyServiceFileSystem); + // check if uri of wikitty publication file system is well formed, + // must be a file "protocol" if (!originUri.getScheme().equals("file")) { // Exception } + // then search for the home property file to load the wikitty + // service uri File workingDir = new File(originUri.getPath()); homePorperty = WikittyPublicationFileSystem - .searchWikittyPublicationHomePropertie(workingDir); + .getWikittyPublicationProperties(workingDir, + WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); - target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR); + wikittyServiceInter = (String) homePorperty + .get(WIKITTY_SERVICE_INTERLOCUTEUR); - // TODO mfortun 2011-04-27 do something on labels ? + labelInitial = homePorperty.getProperty(LABEL_KEY); + wikittyServiceInterSave = wikittyServiceInter; + wikittyServiceInter += originUri.getFragment().replaceFirst( + labelInitial, ""); - synchronisation(origin, target); break; + // Exception, correct number of argument is 0 or 1 default: // exception break; } + // delegate to synchronisation + // only difference between update and commit is the param's order + if (isCommit) { + synchronisation(wikittyServiceFileSystem, wikittyServiceInter); - /* - * Alors c'est facile si on a un élément dans le param c'est que on - * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on - * doit aller chercher ensuite dans le dossier donné l'adresse du - * wikitty service. Notons que si il y a un élément ça doit forcément - * être une uri avec le protocole file. après on appelle simplement la - * méthode synchro avec l'ordre correct entre uritarget et uri origin. - * - * dans le cas ou ya pas d'argument ça veut dire que on doit - * commit/update le dossier courant donc aller chercher dans - * l'arborescence l'adresse du wikitty service. - * - * et pareil on va construire les adresses pour faire une synchro - */ - + } else { + synchronisation(wikittyServiceInter, wikittyServiceFileSystem); + } + // FIXME mfortun-2011-04-28 find a better way to do this, it's needed + // because of the labels and how construct label for the wikitty service + // interlocuteur + homePorperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR, + wikittyServiceInterSave); + homePorperty.store(); } - /* - * TODO mfortun-2011-04-18 plus tard il faudra rajouter un fonctionnement - * commit update à la commande sync, en se servant de l'adresse du wikitty - * service que l'on aura enregitré quelque part. Un commit/update sera juste - * un alias sur le sync classique en se servant d'une adresse enregistré - * dans un fichier et une adresse en ligne de commande - */ } Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-27 17:46:44 UTC (rev 843) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-28 13:31:52 UTC (rev 844) @@ -216,16 +216,18 @@ + File.separator + PROPERTY_DIRECTORY); if (!homeProperty.exists()) { - homeProperty.createNewFile(); + homeProperty.mkdir(); } // write/update the "home property file" PropertiesExtended propertyWikittyService = getWikittyPublicationProperties( homeFile, WIKITTY_FILE_SERVICE); - // the original label use to create - propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY, - this.label); + // the original label use to create if not exist + if (!propertyWikittyService.containsKey(WikittyPublication.LABEL_KEY)) { + propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY, + this.label); + } // the service use to update or commit propertyWikittyService .setProperty( @@ -237,6 +239,7 @@ this.recursion = app .getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION); + // TODO mfotun-2011-04-28 add a support for filtered file with a property file this.directoryNameBlackList = new ArrayList<String>(); directoryNameBlackList.add(".svn"); directoryNameBlackList.add(".git"); @@ -1603,8 +1606,8 @@ * @throws IOException * if error while reading property file */ - static public PropertiesExtended searchWikittyPublicationHomePropertie( - File start) throws IOException { + static public File searchWikittyPublicationHomePropertie(File start) + throws IOException { if (start != null && start.exists() && start.isDirectory()) { @@ -1619,7 +1622,7 @@ File propertie = new File(propertyDirectory.getCanonicalPath() + File.separator + WIKITTY_FILE_SERVICE); if (propertie.exists()) { - return new PropertiesExtended(propertie); + return start; } }