r1184 - in trunk: wikitty-publication/src/main/java/org/nuiton/wikitty/publication wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro wikitty-publication-ui/src/main/java/org/nuiton/wikitty/publication/ui/action
Author: mfortun Date: 2011-08-25 11:00:58 +0200 (Thu, 25 Aug 2011) New Revision: 1184 Url: http://nuiton.org/repositories/revision/wikitty/1184 Log: *move commit/update properties requirement/handling to synchronise class *add method to wpContext Modified: trunk/wikitty-publication-ui/src/main/java/org/nuiton/wikitty/publication/ui/action/PublicationActionEval.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PublicationContext.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PublicationContext.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PublicationContext.java 2011-08-24 16:40:25 UTC (rev 1183) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/PublicationContext.java 2011-08-25 09:00:58 UTC (rev 1184) @@ -33,6 +33,8 @@ List<String> getMandatoryArguments(); + String getArgument(String name); + String getArgument(String name, String defaultValue); String getContentType(); 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-08-24 16:40:25 UTC (rev 1183) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-08-25 09:00:58 UTC (rev 1184) @@ -37,7 +37,6 @@ import org.nuiton.wikitty.WikittyUtil; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyExtension; -import org.nuiton.wikitty.entities.WikittyField; import org.nuiton.wikitty.entities.WikittyImpl; import org.nuiton.wikitty.entities.WikittyLabel; import org.nuiton.wikitty.entities.WikittyLabelHelper; @@ -126,11 +125,6 @@ static public String META_PREFIX_KEY_ID = "id."; /** - * The file name of the wikitty service property - */ - static public String WIKITTY_FILE_SERVICE = "ws.properties"; - - /** * the file name of the property directory */ static public String PROPERTY_DIRECTORY = ".wp"; @@ -184,40 +178,7 @@ log.info("HomeDir:" + homeFile + "Label:" + label); - File homeProperty = new File(homeFile.getAbsolutePath() - + File.separator + PROPERTY_DIRECTORY); - if (!homeProperty.exists()) { - homeProperty.mkdir(); - } - - // write/update the "home property file" - PropertiesExtended propertyWikittyService = getWikittyPublicationProperties( - homeFile, WIKITTY_FILE_SERVICE); - - // the original label use to create if not exist - if (!propertyWikittyService - .containsKey(WikittyPublicationSynchronize.LABEL_KEY)) { - log.debug("Writing home property label" - + propertyWikittyService.getOrigin()); - propertyWikittyService.setProperty( - WikittyPublicationSynchronize.LABEL_KEY, label); - } - // the service use to update or commit - String uriService = app - .getOption(WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR); - if (uriService != null) { - log.debug("Writing home property service on:" - + propertyWikittyService.getOrigin() + " uri" + uriService); - - propertyWikittyService - .setProperty( - WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR, - uriService); - } - - propertyWikittyService.store(); - recursion = true; if (app.getOptions().containsKey( WikittyPublicationSynchronize.IS_RECURSION_OPTION)) { @@ -1114,49 +1075,4 @@ } - /** - * Use to search and return the home property that containt informations - * about wikitty service use to synchronise a wikitty publication file - * system - * - * @param start - * the directory where starts the search - * @return PropertiesExtended the home property - * @throws IOException - * if error while reading property file - */ - static public File searchWikittyPublicationHomePropertie(File start) - throws IOException { - - log.info("Search for home propertie from :" + start); - - if (start != null && start.exists() && start.isDirectory()) { - - // recursion, we search in the parents for the home property file - // those which containt the wikitty service property withe the - // adress of the interlocuteur - - File propertyDirectory = new File(start.getCanonicalPath() - + File.separator + PROPERTY_DIRECTORY); - - if (propertyDirectory.exists()) { - File propertie = new File(propertyDirectory.getCanonicalPath() - + File.separator + WIKITTY_FILE_SERVICE); - if (propertie.exists()) { - return start; - } - } - - return searchWikittyPublicationHomePropertie(start.getParentFile()); - } else { - if (start == null) { - throw new IOException("Start cannot be null"); - } - if (!start.exists()) { - throw new IOException(start + " doen't exist"); - } - throw new IOException(start + " is not a directory"); - } - } - } Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java 2011-08-24 16:40:25 UTC (rev 1183) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationSynchronize.java 2011-08-25 09:00:58 UTC (rev 1184) @@ -45,6 +45,7 @@ import org.nuiton.wikitty.search.Search; import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -116,6 +117,21 @@ */ static public String HESSIAN_URI_PREFIX = "hessian"; + + /** + * The file name of the wikitty service property + */ + static public String WIKITTY_FILE_SERVICE = "ws.properties"; + + /* + * Two flag for commit/update mechanism + * if main true and flag commit false and if service is servive over + * file system, so write property to "know" the last service used to + * synchronise + */ + static protected boolean MAIN_ENABLE=false; + static protected boolean FLAG_COMMIT_UPDATE=false; + static { applicationConfig = new ApplicationConfig(); @@ -172,6 +188,8 @@ * @throws ArgumentsParserException */ static public void main(String[] args) throws Exception { + MAIN_ENABLE = true; + // parsing applicationConfig.parse(args); // execution @@ -485,6 +503,9 @@ WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS .getKey(), WikittyPublicationFileSystem.class .getName()); + + + writeProperty(url); } else if (uri.getScheme().equals(CAJO_URI_PREFIX)) { result.setOption( WikittyConfigOption.WIKITTY_WIKITTYSERVICE_COMPONENTS @@ -542,7 +563,9 @@ static protected void commitUpdateDelegate(String label, boolean isCommit, String... uriFileSystem) throws Exception { - + + FLAG_COMMIT_UPDATE = true; + File currentDir = new File(FileUtil.getCurrentDirectory() .getAbsolutePath()); @@ -587,12 +610,11 @@ case 0: // search for the home property dir that containt uri to the wikitty // service - File homePropertyDir = WikittyPublicationFileSystem - .searchWikittyPublicationHomePropertie(currentDir); + File homePropertyDir = searchWikittyPublicationHomePropertie(currentDir); homeProperty = WikittyPublicationFileSystem .getWikittyPublicationProperties(homePropertyDir, - WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); + WIKITTY_FILE_SERVICE); // load the wikitty service uri (distant one) wikittyServiceInter = homeProperty @@ -631,7 +653,7 @@ File workingDir = new File(originUri.getPath()); homeProperty = WikittyPublicationFileSystem .getWikittyPublicationProperties(workingDir, - WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); + WIKITTY_FILE_SERVICE); wikittyServiceInter = (String) homeProperty .get(WIKITTY_SERVICE_INTERLOCUTEUR); @@ -687,4 +709,113 @@ + "''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''"; System.out.println(usage); } + + + /** + * Called when syncrhonising with file system, used to store info about + * the "other" service used. Infos used when try to commit + * update from a service over file system + * @param label + */ + protected static void writeProperty(String ur) { + try { + URI uri = new URI(ur); + String label = uri.getFragment(); + + File homeFile = new File(uri.getPath()); + + + File homeProperty = new File(homeFile.getAbsolutePath() + + File.separator + + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); + + if (!homeProperty.exists()) { + homeProperty.mkdir(); + } + + // write/update the "home property file" + PropertiesExtended propertyWikittyService; + + propertyWikittyService = WikittyPublicationFileSystem + .getWikittyPublicationProperties(homeFile, + WIKITTY_FILE_SERVICE); + + // the original label use to create if not exist + if (!propertyWikittyService + .containsKey(WikittyPublicationSynchronize.LABEL_KEY)) { + log.debug("Writing home property label" + + propertyWikittyService.getOrigin()); + propertyWikittyService.setProperty( + WikittyPublicationSynchronize.LABEL_KEY, label); + } + // the service use to update or commit + String uriService = applicationConfig + .getOption(WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR); + if (uriService != null) { + log.debug("Writing home property service on:" + + propertyWikittyService.getOrigin() + " uri" + + uriService); + + propertyWikittyService + .setProperty( + WikittyPublicationSynchronize.WIKITTY_SERVICE_INTERLOCUTEUR, + uriService); + } + + propertyWikittyService.store(); + + } catch (Exception e) { + //TODO mfortun-2011-08-25 + if (log.isErrorEnabled()) { + log.error("Error while writing properties for commit update", e); + } + } + + } + + + /** + * Use to search and return the home property that containt informations + * about wikitty service use to synchronise a wikitty publication file + * system + * + * @param start + * the directory where starts the search + * @return PropertiesExtended the home property + * @throws IOException + * if error while reading property file + */ + static public File searchWikittyPublicationHomePropertie(File start) + throws IOException { + + log.info("Search for home propertie from :" + start); + + if (start != null && start.exists() && start.isDirectory()) { + + // recursion, we search in the parents for the home property file + // those which containt the wikitty service property withe the + // adress of the interlocuteur + + File propertyDirectory = new File(start.getCanonicalPath() + + File.separator + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); + + if (propertyDirectory.exists()) { + File propertie = new File(propertyDirectory.getCanonicalPath() + + File.separator + WIKITTY_FILE_SERVICE); + if (propertie.exists()) { + return start; + } + } + + return searchWikittyPublicationHomePropertie(start.getParentFile()); + } else { + if (start == null) { + throw new IOException("Start cannot be null"); + } + if (!start.exists()) { + throw new IOException(start + " doen't exist"); + } + throw new IOException(start + " is not a directory"); + } + } } Modified: trunk/wikitty-publication-ui/src/main/java/org/nuiton/wikitty/publication/ui/action/PublicationActionEval.java =================================================================== --- trunk/wikitty-publication-ui/src/main/java/org/nuiton/wikitty/publication/ui/action/PublicationActionEval.java 2011-08-24 16:40:25 UTC (rev 1183) +++ trunk/wikitty-publication-ui/src/main/java/org/nuiton/wikitty/publication/ui/action/PublicationActionEval.java 2011-08-25 09:00:58 UTC (rev 1184) @@ -495,4 +495,9 @@ return result; } + @Override + public String getArgument(String name) { + return getArgument(name, StringUtils.EMPTY); + } + }
participants (1)
-
mfortun@users.nuiton.org