Author: mfortun Date: 2011-04-29 12:33:12 +0200 (Fri, 29 Apr 2011) New Revision: 846 Url: http://nuiton.org/repositories/revision/wikitty/846 Log: * add logging 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-28 13:53:40 UTC (rev 845) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 10:33:12 UTC (rev 846) @@ -30,14 +30,13 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Map.Entry; import java.util.Set; - 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.FileUtil; -import org.nuiton.util.StringUtil; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.WikittyServiceFactory; import org.nuiton.wikitty.WikittyUtil; @@ -97,6 +96,13 @@ */ static public String LABEL_KEY = "working.label"; + /* + * Class don't have to be instantiate + */ + private WikittyPublication() { + + } + /** * @param args * @throws ArgumentsParserException @@ -153,16 +159,9 @@ 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); - URI uriOrigin = new URI(origin); - - URI uriTarget = new URI(target); - boolean isDelete = applicationConfig .getOptionAsBoolean(IS_DELETE_OPTION); boolean isExisting = applicationConfig @@ -170,6 +169,14 @@ // update operation is the default operation boolean isUpdate = !isDelete && !isExisting; + log.info("Sync uri origin: " + origin + " uri target: " + target + + " isRecur:" + isRecur + " isUpdate:" + isUpdate + + " isDelete:" + isDelete + "isExisting:" + isExisting); + + URI uriOrigin = new URI(origin); + + URI uriTarget = new URI(target); + /* * necessary to have property correctly initialize in order to obtain * the correct implementation of the wikitty service @@ -219,6 +226,25 @@ existOnlyOnTarget.addAll(listTarget); existOnlyOnTarget.removeAll(listOrigin); + if (log.isDebugEnabled()) { + log.debug("Wikitty exist on both: " + existInBoth.size()); + for (String ex : existInBoth) { + log.debug(ex); + } + + log.debug("Wikitty exist only on origin: " + + existOnlyOnOrigin.size()); + for (String ex : existOnlyOnOrigin) { + log.debug(ex); + } + + log.debug("Wikitty exist only on target: " + + existOnlyOnTarget.size()); + for (String ex : existOnlyOnTarget) { + log.debug(ex); + } + } + /* * FIXME mfortun-2011-04-27 remove all that stuff for the safety of the * version when a solution rise for the wikitty version @@ -229,6 +255,8 @@ */ if (isUpdate) { + log.info("Store on target new wikitty"); + List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin); for (Wikitty wikittyNew : newWikitties) { @@ -286,6 +314,8 @@ */ if (isDelete) { + log.info("Remove from target deleted wikitty"); + for (String id : existOnlyOnTarget) { Wikitty w = proxyTarget.restore(id); @@ -296,6 +326,8 @@ } } else { + + log.info("Update existing wikitty"); /* * case existing and update, update those which are on both location */ @@ -360,8 +392,11 @@ static protected Criteria constructCriteriaLabelRecur(String label, boolean isRecur) { + log.info("Construct criteria with label: " + label + " isRecur:" + + isRecur); + // Construct the criteria - Criteria labelCriteria; + Criteria criteriaOnLabels; Search mainRequest = Search.query(); Search subRoqu = mainRequest.or(); @@ -371,7 +406,7 @@ if (isRecur) { // and extension with the name that containt the label (recursivity) - labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL) + criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL) .sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label) .criteria(); @@ -379,12 +414,15 @@ // and extension with the name strictly equals to the label (no // recursivity) - labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL) + criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL) .eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label) .criteria(); } - return labelCriteria; + + log.debug(criteriaOnLabels); + + return criteriaOnLabels; } @@ -397,6 +435,9 @@ */ static protected ApplicationConfig setUpApplicationConfigServerConnector( URI uri) { + + log.info("Construct application config for uri: " + uri); + // prepare new application config ApplicationConfig result = new ApplicationConfig(); @@ -432,6 +473,8 @@ result.setOption(WIKITTY_OPTION_URL, url); + log.debug("Application config: " + result.getFlatOptions()); + return result; } @@ -455,6 +498,22 @@ protected static void commitUpdateDelegate(boolean isCommit, String... uriFileSystem) throws Exception { + File currentDir = new File(FileUtil.getCurrentDirectory() + .getAbsolutePath()); + + if (isCommit) { + log.info("Commit args.length:+" + uriFileSystem.length); + } else { + log.info("Update args.length:+" + uriFileSystem.length); + } + + if (log.isDebugEnabled()) { + for (String args : uriFileSystem) { + log.debug(args); + } + log.debug("Current dir:" + currentDir); + } + /* * 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 @@ -476,10 +535,8 @@ String wikittyServiceFileSystem = ""; String wikittyServiceInterSave = ""; - File currentDir = new File(FileUtil.getCurrentDirectory() - .getAbsolutePath()); String labelInitial = ""; - PropertiesExtended homePorperty = null; + PropertiesExtended homeProperty = null; // Check number of argument switch (uriFileSystem.length) { // if none, then the current dir have to be commit. @@ -489,12 +546,12 @@ File homePropertyDir = WikittyPublicationFileSystem .searchWikittyPublicationHomePropertie(currentDir); - homePorperty = WikittyPublicationFileSystem + homeProperty = WikittyPublicationFileSystem .getWikittyPublicationProperties(homePropertyDir, WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); // load the wikitty service uri (distant one) - wikittyServiceInter = homePorperty + wikittyServiceInter = homeProperty .getProperty(WIKITTY_SERVICE_INTERLOCUTEUR); // construct the current uri for wikitty service file system @@ -509,7 +566,7 @@ // construct uri of the wikitty publication file system wikittyServiceFileSystem = "file://" + homePropertyDir.getAbsolutePath() + "#" + labelCurrent; - labelInitial = homePorperty.getProperty(LABEL_KEY); + labelInitial = homeProperty.getProperty(LABEL_KEY); wikittyServiceInterSave = wikittyServiceInter; wikittyServiceInter += labelCurrent.replaceFirst(labelInitial, ""); @@ -527,14 +584,14 @@ // then search for the home property file to load the wikitty // service uri File workingDir = new File(originUri.getPath()); - homePorperty = WikittyPublicationFileSystem + homeProperty = WikittyPublicationFileSystem .getWikittyPublicationProperties(workingDir, WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE); - wikittyServiceInter = (String) homePorperty + wikittyServiceInter = (String) homeProperty .get(WIKITTY_SERVICE_INTERLOCUTEUR); - labelInitial = homePorperty.getProperty(LABEL_KEY); + labelInitial = homeProperty.getProperty(LABEL_KEY); wikittyServiceInterSave = wikittyServiceInter; wikittyServiceInter += originUri.getFragment().replaceFirst( labelInitial, ""); @@ -547,20 +604,31 @@ // exception break; } + + if (log.isDebugEnabled()) { + + log.debug("homeProperty :" + homeProperty.getOrigin()); + for (Entry<Object, Object> ee : homeProperty.entrySet()) { + log.debug(ee.getKey() + "=" + ee.getValue()); + } + + log.debug("wikitty Inter:" + wikittyServiceInter + + " wikittyFileSystem" + wikittyServiceFileSystem); + } + // delegate to synchronisation // only difference between update and commit is the param's order if (isCommit) { synchronisation(wikittyServiceFileSystem, wikittyServiceInter); - } 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, + homeProperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR, wikittyServiceInterSave); - homePorperty.store(); + homeProperty.store(); } } 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-28 13:53:40 UTC (rev 845) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-29 10:33:12 UTC (rev 846) @@ -212,6 +212,8 @@ label = homeFile.getName(); } + log.info("HomeDir:" + homeFile + "Label:" + label); + File homeProperty = new File(homeFile.getAbsolutePath() + File.separator + PROPERTY_DIRECTORY); @@ -225,21 +227,27 @@ // the original label use to create if not exist if (!propertyWikittyService.containsKey(WikittyPublication.LABEL_KEY)) { + log.debug("Writing home property label" + + propertyWikittyService.getOrigin()); propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY, this.label); } // the service use to update or commit - propertyWikittyService - .setProperty( - WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR, - app.getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR)); + String uriService = app + .getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR); + log.debug("Writing home property service on:" + + propertyWikittyService.getOrigin() + " uri" + uriService); + propertyWikittyService.setProperty( + WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR, uriService); + propertyWikittyService.store(); this.recursion = app .getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION); - // TODO mfotun-2011-04-28 add a support for filtered file with a property file + // 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"); @@ -367,17 +375,22 @@ */ public WikittyEvent store(String securityToken, Collection<Wikitty> wikitties, boolean force) { + log.info("Store wikitty: " + wikitties.size() + " isForce" + force); WikittyEvent result = new WikittyEvent(this); try { for (Wikitty w : wikitties) { + log.debug("Works on : " + w); Set<String> set = WikittyLabelHelper.getLabels(w); String ourDir = ""; // search for our label recursion determine how search the label // if have to match exactly or startswith + log.debug("Sets of labels (" + "isRecur" + recursion + + " label:" + label + ")"); for (String name : set) { + log.debug(name); if (!recursion && name.equalsIgnoreCase(label)) { ourDir = name; } else if (recursion && name.startsWith(label)) { @@ -396,9 +409,13 @@ .get(w.getId()); if (idSystem != null) { + File wikittyFile = new File(idSystem.getPath() + File.separator + idSystem.getFileName()); + log.debug("Deleted wikitty id:" + w.getId() + " File:" + + wikittyFile); + if (wikittyFile.exists()) { wikittyFile.delete(); } @@ -436,6 +453,7 @@ // construct the file differently if wikittyPubData or // wikittyPubText if (w.hasExtension(WikittyPubData.EXT_WIKITTYPUBDATA)) { + log.debug("Wikitty has wikittyPubData Ext"); name = WikittyPubDataHelper.getName(w); // String mime = WikittyPubDataHelper.getMimeType(w); byte[] content = WikittyPubDataHelper.getContent(w); @@ -451,6 +469,7 @@ } else if (w .hasExtension(WikittyPubText.EXT_WIKITTYPUBTEXT)) { + log.debug("Wikitty has wikittyPubText Ext"); name = WikittyPubTextHelper.getName(w); // String mime = WikittyPubTextHelper.getMimeType(w); String content = WikittyPubTextHelper.getContent(w); @@ -463,6 +482,9 @@ wikittyFile.createNewFile(); FileUtil.writeString(wikittyFile, content); + } else { + // unsupported kind of wikitty, just jump. + continue; } // if file properly write, write wikittyProperties @@ -553,6 +575,7 @@ */ public List<Wikitty> restore(String securityToken, List<String> id) { List<Wikitty> result = new ArrayList<Wikitty>(); + log.info("restore wikitty, number: " + id.size()); try { // construct the starts file from the label and the working // directory @@ -582,9 +605,14 @@ return result; } + /* + * TODO mfortun-2011-04-29 see if method really needed ? + */ @Override public WikittyEvent delete(String securityToken, Collection<String> ids) { + log.info("Delete called wikitty size:" + ids.size()); + try { // load localisation of all the wikitties BidiMap location = harvestLocalWikitties(homeFile, true); @@ -593,6 +621,8 @@ Object value = location.get(id); + log.debug("delete wikitty id: " + id + " corresponding file :" + + value); if (value != null) { FileSystemWIkittyId localisation = (FileSystemWIkittyId) value; @@ -1034,6 +1064,7 @@ BidiMap map = harvestLocalWikitties(starts, true); // put all local wikitties in a map + for (Object o : map.keySet()) { String id = (String) o; FileSystemWIkittyId location = (FileSystemWIkittyId) map @@ -1063,6 +1094,10 @@ String id = entry.getKey(); Wikitty w = entry.getValue(); // if macth + + log.debug("Check restriction for wikitty: " + w + + " Restriction:" + restriction); + if (checkRestriction(restriction, w)) { // increment result number @@ -1129,6 +1164,10 @@ String id = entry.getKey(); Wikitty w = entry.getValue(); // if macth + + log.debug("Check restriction for wikitty: " + w + + " Restriction:" + restriction); + if (checkRestriction(restriction, w)) { // increment result number currentIndex++; @@ -1191,6 +1230,8 @@ */ public List<File> harvestPropertyDirectory(File starts, boolean recursivly) { + log.info("harvest property directory starts:" + starts + "isRecur" + + recursivly); List<File> result = new ArrayList<File>(); for (File child : starts.listFiles()) { @@ -1218,12 +1259,15 @@ throws Exception { BidiMap result = new DualHashBidiMap(); + log.info("harvest localWikitty"); List<File> propertiesDirectory = harvestPropertyDirectory(starts, recursivly); // use the list of property to retrieve wikitty for (File propsDir : propertiesDirectory) { + log.debug("harvest wikitty on " + propertiesDirectory); + Properties idProps = new Properties(); File idFile = new File(propsDir.getCanonicalPath() + File.separator + WikittyPublicationFileSystem.WIKITTY_ID_PROPERTIES_FILE); @@ -1235,11 +1279,14 @@ // simply load the id property file to retrieve wikitty id // with the path to the propertyfile and the value of the file // construct FileSytemWikittyId + log.debug("List of file/wikitty"); for (Object id : ids) { String name = idProps.getProperty((String) id); String path = propsDir.getParent(); FileSystemWIkittyId value = new FileSystemWIkittyId(name, path); + log.debug("ID:" + id + " fileInformation:" + value); + result.put((String) id, value); } @@ -1273,6 +1320,8 @@ static public PropertiesExtended getWikittyPublicationProperties( File starts, String name) throws IOException { + log.debug("getwikittyPublicationProperties :" + name + " on dir:" + + starts); File propertieDirectory = new File(starts.getCanonicalPath() + File.separator + WikittyPublicationFileSystem.PROPERTY_DIRECTORY); @@ -1305,6 +1354,8 @@ protected Wikitty restore(String id, FileSystemWIkittyId fileId) throws IOException { + log.debug("restore wikitty id:" + id + " file: " + fileId); + Wikitty result = new WikittyImpl(id); result.addExtension(WikittyLabelImpl.extensionWikittyLabel); @@ -1333,6 +1384,8 @@ // create the correct wikittypubxxx if (mimeHelper.isPubTextMime(mimeType)) { + log.debug("restore wikitty id:" + id + " file: " + fileId + + " pubTextType"); result.addExtension(WikittyPubTextImpl.extensionWikittyPubText); WikittyPubTextHelper.setName(result, name); WikittyPubTextHelper.setMimeType(result, mimeType); @@ -1340,6 +1393,8 @@ FileUtil.readAsString(fileToTransform)); WikittyPubTextHelper.setFileExtension(result, extension); } else { + log.debug("restore wikitty id:" + id + " file: " + fileId + + " pubDataType"); result.addExtension(WikittyPubDataImpl.extensionWikittyPubData); WikittyPubDataHelper.setName(result, name); WikittyPubDataHelper.setMimeType(result, mimeType); @@ -1372,6 +1427,8 @@ protected void harvestNewCheckModificationsAndDeleted(File starts, String label) throws IOException { + log.info("Check for wikitty on disk: new, deleted and modified. Directory:" + + starts + " Label:" + label); // write property directory if not exist File propertyFile = new File(starts + File.separator + PROPERTY_DIRECTORY); @@ -1428,6 +1485,8 @@ // check for the deleted if (filesWikitty.size() != listChildFileNonDir.size()) { + log.info("remove wikitty informations for deleted file"); + meta = getWikittyPublicationProperties(starts, WIKITTY_FILE_META_PROPERTIES_FILE); @@ -1435,6 +1494,7 @@ for (String fileRemoved : filesWikitty) { + log.debug("remove wikitty informations for:" + filesWikitty); // remove properties ids.remove(meta.get(META_PREFIX_KEY_ID + fileRemoved)); @@ -1461,6 +1521,8 @@ */ protected void checkModifications(File child) throws IOException { + log.info("Check if there was modification on :" + child); + // will check if there was modification with checksum BufferedInputStream input = new BufferedInputStream( new FileInputStream(child)); @@ -1503,6 +1565,9 @@ protected void writeWikittyFileProperties(File towrite, String wikittyID, String wikittyVersion) throws IOException { + log.info("Write wikitty information file: " + towrite + " Id:" + + wikittyID + " version:" + wikittyVersion); + if (towrite.exists() && !towrite.isDirectory()) { Wikitty wikitty = new WikittyImpl(wikittyID); if (wikittyVersion != null) { @@ -1539,7 +1604,7 @@ meta.store(); } else { throw new IOException(towrite.toString() - + " not exist or isn't a directory"); + + " not exist or is a directory"); } } @@ -1557,6 +1622,8 @@ label = labelToPath(label); + log.info("Create directory from path:" + label); + String[] pathElements = StringUtil.split(label, File.separator); boolean result = false; @@ -1584,6 +1651,7 @@ * @return the correct path */ public String labelToPath(String label) { + String result = label; result = result.replace(".", File.separator); @@ -1592,6 +1660,8 @@ result = result.replace(File.separator + File.separator, File.separator + "."); + log.info("Convert label to path: " + label + " path:" + result); + return result; } @@ -1609,6 +1679,8 @@ 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 @@ -1628,11 +1700,13 @@ return searchWikittyPublicationHomePropertie(start.getParentFile()); } else { - // Exception - /* - * TODO mfortun-2011-04-27 write/set the appropriate exception here - */ - return null; + 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"); } }