java - Versionhistory of node disappered after restore parentnode to lower version jackrabbit -


given fact have versionable node versionable subnode. checkin first node 1 subnode version 1.0. add new subnode on parentnode (1.1). if restore parentnode on version 1.0 can see theres first checkedin subnode available. when wanna restore parent version 1.1 , try versionhistory second subnode ill receive pathnotfoundexception while querying. did ...restore(abspath, restoretoversion, false);

public static final string lesson = "lesson_"; public static final string filecard = "filecard_"; public static final string user = "user_"; public static final string del = "/"; public static final simpledateformat dateformat = new simpledateformat("dd.mm.yyyy hh:mm");  /**  *   * @param entitylist  * @param userid  * @throws ioexception  *   * neue lektion wurde im desktop client angelegt ode vorhandene geändert.   * abhängig davon wird hier ein neuer lektionsknoten angelegt oder der vorhandene geändert.  * jedem knoten wird das serialisierte lessonentity als property angehängt.  */ public void insertlesson(list<lessonentity> entitylist, string userid) throws ioexception {      session session = jrrepository.getinstance().getsession();     workspace ws = session.getworkspace();     try {         node usernode = handlelessonparentnodes(entitylist.get(0), userid, session);          (lessonentity lessonentity : entitylist) {              // check wether lesson node exists             if (usernode.hasnode(lesson + lessonentity.getid())) {                 node lessonnode = usernode.getnode(lesson + lessonentity.getid());                  ws.getversionmanager().checkout(lessonnode.getpath());                 lessonnode.setproperty("data", jrutils.serializobject(lessonentity));                 session.save();                 ws.getversionmanager().checkin(lessonnode.getpath());              } else {                 // if not add new 1                 insertnewlessonnode(userid, lessonentity, session);             }         }      } catch (repositoryexception e) {         // todo auto-generated catch block         e.printstacktrace();     } {          session.logout();     }  }  /**  *   * @param filecardentitylist  * @param userid  * @throws ioexception  *   * neue filecard wurde im desktop client angelegt oder vorhandene geändert.   * abhängig davon wird hier das gleiche gemacht.  * jedem knoten wird das serialisierte filecardentity als property angehängt.  */ public void insertfilecards(list<filecardentity> filecardentitylist, string userid) {      session session = jrrepository.getinstance().getsession();     workspace ws = session.getworkspace();      try {          node lessonnode = null;         boolean createnewlessonversion = true;         (filecardentity filecardentity : filecardentitylist) {              lessonnode = handlefilecardparentnodes(filecardentity, userid, session);             nodecheckout(lessonnode, session);              // check wether filecardnode exists             if (lessonnode.hasnode(filecard + filecardentity.getid())) {                 node filecardnode = lessonnode.getnode(filecard + filecardentity.getid());                  nodecheckout(filecardnode, session);                  filecardnode.setproperty("data", jrutils.serializobject(filecardentity));                 filecardnode.setproperty("versiondate", calendar.getinstance().gettimeinmillis());                  session.save();                 nodecheckin(filecardnode, session);              } else {                 // if not add new 1                 if(createnewlessonversion){                     nodecheckin(lessonnode, session);                     nodecheckout(lessonnode, session);                     createnewlessonversion = false;                 }                 insertnewfilecardnode(lessonnode, filecardentity, userid, session);             }         }      } catch (repositoryexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     } {         session.logout();     }  }   public node insertnewusernode(string userid, session session) throws itemexistsexception, pathnotfoundexception, versionexception, constraintviolationexception, lockexception, repositoryexception {     node usernode = session.getrootnode().addnode(user + userid);     session.save();     return usernode; }  public node insertnewlessonnode(string userid, lessonentity lessonentity, session session) throws pathnotfoundexception, repositoryexception, ioexception {     // adds usernode if not there     node usernode = handlelessonparentnodes(lessonentity, userid, session);      node lessonnode = usernode.addnode(lesson + lessonentity.getid(), "nt:unstructured");     lessonnode.addmixin("mix:versionable");     lessonnode.setproperty("id", lessonentity.getid());     lessonnode.setproperty("data", jrutils.serializobject(lessonentity));     session.save();     session.getworkspace().getversionmanager().checkin(lessonnode.getpath());      return lessonnode; }  public node insertnewfilecardnode(node lessonnode, filecardentity filecardentity, string userid, session session) throws unsupportedrepositoryoperationexception, repositoryexception, ioexception {      node filecardnode = null;     filecardnode = lessonnode.addnode(filecard + filecardentity.getid(), "nt:unstructured");     filecardnode.addmixin("mix:versionable");     filecardnode.setproperty("data", jrutils.serializobject(filecardentity));     filecardnode.setproperty("versiondate", calendar.getinstance().gettimeinmillis());     session.save();     session.getworkspace().getversionmanager().checkin(lessonnode.getpath() + del + filecard + filecardentity.getid());      return filecardnode; }  /**  *   * @param lessonid  * @param filecardid  * @param userid  * @param versionname  * @throws pathnotfoundexception  * @throws repositoryexception  * @throws ioexception  * @throws classnotfoundexception  *   * stellt eine version dieser filecard wieder und lädt sie auf den server.   */ public void restorefilecard(string lessonid, string filecardid, string userid, string versionname) throws pathnotfoundexception, repositoryexception, ioexception, classnotfoundexception {      session session = jrrepository.getinstance().getsession();     string usernodepath = session.getrootnode().getnode(user + userid).getpath();     string abspath = usernodepath + del + lesson + lessonid + del + filecard + filecardid;     versionhistory versionhistory = getversionhistory(session, abspath);     versioniterator iterator = versionhistory.getallversions();      filecardentity cardentity = null;      while (iterator.hasnext()) {         version version = (version) iterator.next();         if (version.getname().equals(versionname)) {             node node = version.getfrozennode();             value value = node.getproperty("data").getvalue();             object ob = jrutils.deserializeobject(value.getbinary());              cardentity = (filecardentity) ob;         }     }      session.getworkspace().getversionmanager().restore(abspath, versionname, false);     list<filecardentity> updatelist = new arraylist<filecardentity>();     cardentity.setlastmodified(new date());     updatelist.add(cardentity);     filecarddao.updatefilecardlist(userid, updatelist);      session.logout(); }   /**  *   * @param lessonid  * @param userid  * @param restoretoversion  * @throws sqlexception  * @throws versionexception  * @throws itemexistsexception  * @throws unsupportedrepositoryoperationexception  * @throws lockexception  * @throws invaliditemstateexception  * @throws repositoryexception  *   * stellt eine version dieser lektion inklusive der derzeit aktiven filekarten wieder und lädt sie auf den server.  */ public void restorelesson(string lessonid, string userid, string restoretoversion) throws sqlexception, versionexception, itemexistsexception, unsupportedrepositoryoperationexception, lockexception, invaliditemstateexception, repositoryexception {     session session = jrrepository.getinstance().getsession();     string usernodepath = session.getrootnode().getnode(user + userid).getpath();     string abspath = usernodepath + del + lesson + lessonid;     string baseversion = getbaseversion(session, abspath).getname();     versionhistory versionhistory = getversionhistory(session, abspath);     version version = versionhistory.getversion(restoretoversion);     lessonentity lessonentity = null;     list<filecardentity> list = new arraylist<filecardentity>();      node frozennode = version.getfrozennode();     value value = frozennode.getproperty("data").getvalue();      object ob = jrutils.deserializeobject(value.getbinary());      lessonentity = (lessonentity) ob;      list = handlefilecards(session, restoretoversion, abspath, baseversion);      list<lessonentity> updatelist = new arraylist<lessonentity>();     lessonentity.setlastmodified(new date());     lessonentity.setstatus(statustype.active);     updatelist.add(lessonentity);     lessondao.updatelessons(updatelist, userid);      if (list != null && list.size() > 0) {         (filecardentity cardentity : list) {             cardentity.setlastmodified(new date());         }         filecarddao.updatefilecardlist(userid, list);      }      session.getworkspace().getversionmanager().restore(abspath, restoretoversion, false);      session.logout();  }  /**  *   * @param session  * @param requestedversion  * @param abspath  * @param currentversion  * @return list<filecardentity>  * @throws valueformatexception  * @throws pathnotfoundexception  * @throws repositoryexception  *   * hier werden die jeweiligen filecards identifiziert, die zwischen der jetzigen version und der gewünschten version liegen.  * die jeweiliegen filecards werden entsprechend ihres verhaltens mit <statustype> markiert und als java objekte zurückgegeben.  */ private list<filecardentity> handlefilecards(session session, string requestedversion, string abspath, string currentversion) throws valueformatexception, pathnotfoundexception, repositoryexception {      map<string, filecardentity> requestedfilecardmap = new hashmap<string, filecardentity>();     map<string, filecardentity> currentfilecardmap = new hashmap<string, filecardentity>();     list<filecardentity> requestedlist = new arraylist<filecardentity>();     // currentversion     version currversion = getversionhistory(session, abspath).getversion(currentversion);     node lektion = currversion.getfrozennode();      (nodeiterator iterator2 = lektion.getnodes(); iterator2.hasnext();) {         node filecardentitynode = (node) iterator2.next();         version baseversion = getbaseversion(session, abspath + del + filecardentitynode.getname());         node filecardfrozennode = baseversion.getfrozennode();          if (filecardfrozennode.hasproperty("data")) {              value filecardproperty = filecardfrozennode.getproperty("data").getvalue();             object obj = jrutils.deserializeobject(filecardproperty.getbinary());              filecardentity cardentity = (filecardentity) obj;             currentfilecardmap.put(filecardentitynode.getname(), cardentity);         }     }      // requested version     node reqfrozennode = null;     version reqversion = getversionhistory(session, abspath).getversion(requestedversion);      reqfrozennode = reqversion.getfrozennode();      (nodeiterator iterator3 = reqfrozennode.getnodes(); iterator3.hasnext();) {         node fcnode = (node) iterator3.next();         version filecardversion = determinefilecardversion(session, reqversion, abspath, fcnode);         fcnode = filecardversion.getfrozennode();          if (fcnode.hasproperty("data")) {             value value = fcnode.getproperty("data").getvalue();             filecardentity cardentity = (filecardentity) jrutils.deserializeobject(value.getbinary());             string name = filecard + cardentity.getid();             requestedfilecardmap.put(name, cardentity);         }     }      (map.entry<string, filecardentity> entry : currentfilecardmap.entryset()) {         filecardentity cardentity = entry.getvalue();          // angeforderte version hat die selbe filekarte         if (requestedfilecardmap.containskey(entry.getkey())) {             addtoreturnlist(requestedlist, statustype.active, cardentity);             requestedfilecardmap.remove(entry.getkey());             // angeforderte version hat nicht diese filekarte         } else if (!requestedfilecardmap.containskey(entry.getkey())) {             addtoreturnlist(requestedlist, statustype.removed, cardentity);         }     }      (map.entry<string, filecardentity> entry : requestedfilecardmap.entryset()) {         filecardentity cardentity = entry.getvalue();          // angeforderte version hat filekarte die in der currentversion         // nicht drin war         if (!currentfilecardmap.containskey(entry.getkey())) {             addtoreturnlist(requestedlist, statustype.active, cardentity);         }     }      return requestedlist;  }  /**  *   * @param session  * @param lektionsversion  * @param abspath  * @param filecardfrozennode  * @return version  * @throws unsupportedrepositoryoperationexception  * @throws repositoryexception  *   * hier wird die jewilige filecardversion identifiziert die zum zeitpunkt der lektionsversion aktiv war.  */ private version determinefilecardversion(session session, version lektionsversion, string abspath, node filecardfrozennode) throws unsupportedrepositoryoperationexception, repositoryexception {     calendar nextlessonstart = lektionsversion.getlinearpredecessor().getcreated();     version preversion = null;     versionhistory filecardhistory = null;     try{         filecardhistory = getversionhistory(session, abspath + del + filecardfrozennode.getname());     }catch(pathnotfoundexception pne){          filecardhistory = getversionhistory(session, session.getrootnode().getpath() + filecardfrozennode.getname());     }     (versioniterator iterator = filecardhistory.getallversions(); iterator.hasnext();) {         version filecardversion = (version) iterator.next();         if (!filecardversion.getname().startswith("jcr:root")) {             calendar fc = filecardversion.getcreated();             if (fc.before(nextlessonstart)) {                 preversion = filecardversion;             } else {                 if (null == preversion) {                     return filecardversion;                 }             }         }     }     return preversion;  }   public node handlefilecardparentnodes(filecardentity entity, string userid, session session) throws pathnotfoundexception, repositoryexception, ioexception {     if (!islessonnodeavailable(entity, userid, session)) {         lessonentity lessonentity = lessondao.get(entity.getlesson().getid());         return insertnewlessonnode(userid, lessonentity, session);     } else {         return session.getnode(del + user + userid + del + lesson + entity.getlesson().getid());     }  }  public node handlelessonparentnodes(lessonentity entity, string userid, session session) throws pathnotfoundexception, repositoryexception, ioexception {     if (!isusernodeavailable(userid, session)) {         return insertnewusernode(userid, session);     } else {         return session.getnode(del + user + userid);     }  }  private void nodecheckout(node node, session session) throws versionexception, unsupportedrepositoryoperationexception, invaliditemstateexception, lockexception, repositoryexception {     session.getworkspace().getversionmanager().checkout(node.getpath()); }  private void nodecheckin(node node, session session) throws versionexception, unsupportedrepositoryoperationexception, invaliditemstateexception, lockexception, repositoryexception {     session.getworkspace().getversionmanager().checkin(node.getpath()); }  public versionhistory getversionhistory(session session, string abspath) throws unsupportedrepositoryoperationexception, repositoryexception {     return session.getworkspace().getversionmanager().getversionhistory(abspath); }  private version getbaseversion(session session, string abspath) throws unsupportedrepositoryoperationexception, repositoryexception {     return session.getworkspace().getversionmanager().getbaseversion(abspath); }  private boolean isusernodeavailable(string userid, session session) throws pathnotfoundexception, repositoryexception {     return session.getrootnode().hasnode(user + userid);  }  private void addtoreturnlist(list<filecardentity> list, statustype status, filecardentity entity) {     entity.setstatus(status);     list.add(entity); }  private boolean islessonnodeavailable(filecardentity entity, string userid, session session) throws pathnotfoundexception, repositoryexception, ioexception {     lessonentity lessonentity = entity.getlesson();     if (null == lessonentity)         return false;      node usernode = null;     if (!isusernodeavailable(userid, session)) {         usernode = insertnewusernode(userid, session);     }      usernode = session.getnode(del + user + userid);      return usernode.hasnode(lesson + lessonentity.getid());  } 

is ist possible versionhistory deleted subnode restoring parentnode version subnode doesent exists ?

any appreciated ....thanks in advance !!

additional code comment

first have able version lessons , filecards undependend. reason why made both versionable. in client creates lesson , filecard, synchs server. first insertlesson called , version 1.0 created. insertfilecard called , generates lessonversion 1.1, filecardversion 1.0. client creates new filecard , synchs, second filecard created , lesson version 1.2. restore lesson version 1.1 restorelesson method. inside call handlefilecard method checks filecard differences between current , requested lesson versions. no problem far version 1.1 restored , remember, @ time had 1 filecard. try switch lesson version 1.2. in handlefilecards method determinefilecardversion called should return version of filecard @ time given lesson version active . inside try catch approach test additional possibilities versionhistory of filecard added lesson version 1.2. no success, versionhistory filecard seems gone after restore lesson version 1.1.... hope isnt , sry bad english :)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -