r811 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
Author: mfortun Date: 2011-04-15 14:50:48 +0200 (Fri, 15 Apr 2011) New Revision: 811 Url: http://nuiton.org/repositories/revision/wikitty/811 Log: * sync operations completed Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.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-15 10:49:16 UTC (rev 810) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-15 12:50:48 UTC (rev 811) @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,6 +42,7 @@ import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.WikittyServiceFactory; +import org.nuiton.wikitty.WikittyUtil; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyLabel; import org.nuiton.wikitty.entities.WikittyLabelHelper; @@ -112,7 +114,6 @@ // parsing applicationConfig.parse(args); - System.out.println("ffff"); // execution applicationConfig.doAction(0); @@ -124,8 +125,6 @@ boolean isRecur = applicationConfig .getOptionAsBoolean(IS_RECURSION_OPTION); - applicationConfig.setOption("ponay", "george"); - /* * TODO mfortun-2011-04-14 handle exception if uri format does not match */ @@ -137,20 +136,22 @@ .getOptionAsBoolean(IS_DELETE_OPTION); boolean isExisting = applicationConfig .getOptionAsBoolean(IS_EXISTING_OPTION); + // update operation is the default operation + boolean isUpdate = !isDelete && !isExisting; /* - * TODO mfortun-2011-04-14 add setoption to application config to - * retrieve correct wikitty service with correct args e.g. for file : + * necessary to have property correctly initialize in order to obtaint + * the correct implementation of the wikitty service */ - if (uriOrigin.getScheme().equals("file")) { - applicationConfig - .setOption("wikitty.WikittyService.components", - "org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem"); - } + // once on the service origin + setUpApplicationConfigServerConnector(uriOrigin); WikittyProxy proxyOrigin = new WikittyProxy( WikittyServiceFactory.buildWikittyService(applicationConfig)); + // once on the service target + setUpApplicationConfigServerConnector(uriTarget); + WikittyProxy proxyTarget = new WikittyProxy( WikittyServiceFactory.buildWikittyService(applicationConfig)); @@ -170,53 +171,66 @@ List<String> listTarget = proxyTarget.findAllIdByCriteria(critTarget) .getAll(); - /* - * Algo update origin, target: wikitty service quelconque: -on - * vachercher sur origin les wikitty avec le label ciblé (recur ou non) - * -on va chercher sur target les wikitty avec le label ciblé (recur ou - * non) - * - * Tout ceux qui sont dans origin et pas target on les envois sans se - * poser de question (c'est les nouveaux) - * - * Pour ceux en commun on va faire une différence sur les versions si - * version orign est plus récente que celle sur target on envoit gérer - * ici la problématique de merge ? - * - * sinon pas plus récente on fait rien. - */ + // construct list of wikitty contained in both location + List<String> existInBoth = new ArrayList<String>(); + existInBoth.addAll(listOrigin); + existInBoth.retainAll(listTarget); + // construct list of wikitty contained only in origin location + List<String> existOnlyOnOrigin = new ArrayList<String>(); + existOnlyOnOrigin.addAll(listOrigin); + existOnlyOnOrigin.removeAll(listTarget); + + // construct list of wikitty contained only in target location + List<String> existOnlyOnTarget = new ArrayList<String>(); + existOnlyOnTarget.addAll(listTarget); + existOnlyOnTarget.removeAll(listOrigin); + /* - * Algo delete - * - * origin, target: wikitty service quelconque: -on va chercher sur - * origin les wikitty avec le label ciblé (recur ou non) -on va chercher - * sur target les wikitty avec le label ciblé (recur ou non) - * - * Tout ceux qui sont dans origin et pas target on en fait rien. Ceux en - * commun on n'en fait rien non plus. - * - * Ceux qui sont uniquement dans target on les met à jour en virant le - * label correspondant + * if option is update send wikitty that are not in the target. */ + if (isUpdate) { + List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin); + proxyTarget.storeWikitty(newWikitties); + + } /* - * Algo existing - * - * origin, target: wikitty service quelconque: -on va chercher sur - * origin les wikitty avec le label ciblé (recur ou non) -on va chercher - * sur target les wikitty avec le label ciblé (recur ou non) - * - * Tout ceux qui sont dans origin et pas target on en fait rien, et pour - * le reste application du même algo que pour update classique - * - * Pour ceux en commun on va faire une différence sur les versions si - * version orign est plus récente que celle sur target on envoit gérer - * ici la problématique de merge ? - * - * sinon pas plus récente on fait rien. + * if option delete remove those who are on the target but not on origin */ + if (isDelete) { + for (String id : existOnlyOnTarget) { + Wikitty w = proxyTarget.restore(id); + WikittyLabelHelper.removeLabels(w, labelTarget); + + proxyTarget.store(w); + } + } else { + /* + * case existing and update, update those which are on both location + */ + for (String id : existInBoth){ + Wikitty fromTarget = proxyTarget.restore(id); + Wikitty fromOrigin = proxyOrigin.restore(id); + + String idTarget = fromTarget.getId(); + String idOrigin = fromOrigin.getId(); + //check version for update + if (WikittyUtil.versionGreaterThan(idOrigin, idTarget)){ + Set<String> setLabelTarget= WikittyLabelHelper.getLabels(fromTarget); + //replace labels origins, by target + WikittyLabelHelper.setLabels(fromOrigin, setLabelTarget); + //send modified origin to target wikitty service + proxyTarget.store(fromOrigin); + } + } + + + + } + + } /** @@ -259,4 +273,33 @@ } + /** + * Use to setup correct url property in the application config and correct + * component for the wikittyservice + * + * @param uri + * of the targeted wikitty service + */ + static protected void setUpApplicationConfigServerConnector(URI uri) { + + if (uri.getScheme().equals("file")) { + applicationConfig + .setOption("wikitty.WikittyService.components", + "org.nuiton.wikitty.publication.synchro.WikittyPublicationFileSystem"); + } + + if (uri.getScheme().equals("cajo")) { + applicationConfig.setOption("wikitty.WikittyService.components", + "org.nuiton.wikitty.services.WikittyServiceCajoClient"); + } + + if (uri.getScheme().equals("hessian")) { + applicationConfig.setOption("wikitty.WikittyService.components", + "org.nuiton.wikitty.services.WikittyServiceHessianClient"); + } + + applicationConfig.setOption("wikitty.service.server.url", + uri.toASCIIString()); + + } }
participants (1)
-
mfortun@users.nuiton.org