From 288917911f481ce048907d40c1e267f4034c6aeb Mon Sep 17 00:00:00 2001 From: sasinda Date: Wed, 15 Aug 2012 21:03:29 +0530 Subject: [PATCH] Added comment upload logic to RAL create. edit parent pom. --- pom.xml | 3 +- xwiki-android-client/AndroidManifest.xml | 13 +- .../xwiki/android/client/dev/QuickTest.java | 118 ++- .../org/xwiki/android/rest/ral/Verifier.java | 5 +- .../android/rest/ral/XmlDocumentRao.java | 237 +++-- .../xwiki/android/xmodel/entity/Comment.java | 378 +++---- .../xwiki/android/xmodel/entity/Document.java | 941 +++++++++--------- .../xmodel/xobjects/XDateProperty.java | 7 +- .../xmodel/xobjects/XDoubleProperty.java | 6 + .../xmodel/xobjects/XFloatProperty.java | 6 + .../xmodel/xobjects/XIntegerProperty.java | 52 +- .../xmodel/xobjects/XLongProperty.java | 47 +- .../org/xwiki/android/rest/HttpConnector.java | 2 +- .../android/rest/XWikiRestConnecion.java | 4 +- xwiki-android-test-core/project.properties | 3 +- .../rest/ral/test/TestDocumentRaoCreate.java | 493 ++++----- 16 files changed, 1279 insertions(+), 1036 deletions(-) diff --git a/pom.xml b/pom.xml index 321fadf..0e45fd6 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,7 @@ zip - ${xwikiExecutionDirectory}/../ + ${xwikiServerUnpackDirectory} ${xwiki.test.skipUnpack} @@ -181,6 +181,7 @@ false ${project.parent.basedir}/target/test-server/xwiki-enterprise-jetty-${xwiki.db}-${xwiki.xe.version} 0 + ${project.parent.basedir}/target/test-server/ try to keep the number seq of created obj in + // server, if objects are numbered. + // keeping seq makes parallelizations hard. But this semantic must be guaranteed by the RAL Create + // methods. Note: when paralleling You have to add work for jobs at points in this algo. Do it in + // another strategy. + LinkedList obList = new LinkedList();// 'cause we need to add in the middle + class Index + { public Index(int first, int last) - { + { this.first = first; this.last = last; } + int first; int last; } - Map indexes=new HashMap(10);//for < 10 classes of objs. - - Map edObjs = pad.getEditedObjects(); //objects added using set method. explicitly palced at smplObject.number - - A:for(String k: edObjs.keySet()){ - String ss[]=k.split("/"); - String clsName=ss[0]; - Object o=edObjs.get(k); - Index i= indexes.get(clsName); - if(i==null){//new class + Map indexes = new HashMap(10);// for < 10 classes of objs. + + Map edObjs = pad.getEditedObjects(); // objects added using set method. explicitly + // palced at smplObject.number + + A: for (String k : edObjs.keySet()) { + String ss[] = k.split("/"); + String clsName = ss[0]; + Object o = edObjs.get(k); + Index i = indexes.get(clsName); + if (i == null) {// new class obList.add(o); - int first=obList.size()-1; - int last=first; - indexes.put(clsName, new Index(first,last)); - }else{ - int last=i.last; - for(int j=i.first; j<=last;j++){ - Object curr=obList.get(j); - if(o.getNumber() newObjects = pad.getNewObjects(); - - A:for(Object o:newObjects){ - String clsName=o.getClassName(); - Index i=indexes.get(clsName); - if(i==null){//this is new object - obList.add(o); - int first=obList.size()-1; - int last=first; - indexes.put(clsName, new Index(first, last)); - }else{ - int first=i.first; - int last=i.last; - - Object prev=obList.get(first); - for(int j=first+1; j<=last; j++){ - Object curr=obList.get(j); - if(curr.getNumber()-prev.getNumber()>1){ - obList.add(j, o); - last++; - i.last=last; - continue A; //restart from A. - } + + A: for (Object o : newObjects) { + String clsName = o.getClassName(); + Index i = indexes.get(clsName); + if (i == null) {// this is new object + obList.add(o); + int first = obList.size() - 1; + int last = first; + indexes.put(clsName, new Index(first, last)); + } else { + int first = i.first; + int last = i.last; + + Object prev = obList.get(first); + for (int j = first + 1; j <= last; j++) { + Object curr = obList.get(j); + if (curr.getNumber() - prev.getNumber() > 1) { + obList.add(j, o); + last++; + i.last = last; + continue A; // restart from A. + } } - //if did not get added add to the end. - obList.add(last+1,o); - i.last= ++last; + // if did not get added add to the end. + obList.add(last + 1, o); + i.last = ++last; } - + } - //end algo - - //upload objects. + // end algo + + // upload objects. for (Object object : obList) { api.addObject(wikiName, spaceName, pageName, object); - } + } + + List newCmnts = pad.getNewComments(); + List edCmnts = pad.getEditedComments(); + Comparator comparator = new Comparator() + { + @Override + public int compare(Object object1, Object object2) + { + // we are sure that edited Comments coming as Objects get there number prop filled to comment + // id; + return object1.getNumber() - object2.getNumber(); + } + }; + Collections.sort(edCmnts, comparator); + // start order comment upload. Try create the setComment(cmnt with id 1) to match the same id in server. + int svrCmntId=-1; + int used = 0; // how many new comments used + int avail = newCmnts.size(); + int lastId = -1; + for (int i = 0; i < edCmnts.size(); i++) { + Object ec = edCmnts.get(i); + int thisId = ec.getNumber(); + if (thisId > lastId + 1) { + int needed = thisId - lastId-1; + lastId = thisId; + if (used < avail) { + int start = used; + int end = Math.min(avail, used + needed); + for (int j = used; j < end; j++) { + Comment cnw=newCmnts.get(j); + api.addPageComment(wikiName, spaceName, pageName, cnw); + svrCmntId++; + for(Comment c:newCmnts){ + if(c.getReplyTo()==cnw.getId()){ + c.setReplyTo(svrCmntId); + } + } + } + used += needed; + } + api.addObject(wikiName, spaceName, pageName, ec); + svrCmntId++; + } else { + lastId=thisId; + api.addObject(wikiName, spaceName, pageName, ec); + svrCmntId++; + } + } + + if(used newCmnts=pad.getNewComments(); - List edCmnts=pad.getEditedComments(); - - - return null; // TODO RET CREATED DOC. NEED TO ADD CUSTOMIZATION CODE WETHER TO RET OR NOT. } } catch (RestException e) { - Log.d(tag, "couldn't create page" + e.getCode()); + Log.d(TAG, "couldn't create page" + e.getCode()); e.printStackTrace(); throw new RaoException(e); } - } - + @Override public boolean exists(Document doc) throws RestConnectionException, RaoException { @@ -184,11 +271,11 @@ public boolean exists(Document doc) throws RestConnectionException, RaoException String pageName = doc.getPageName(); boolean exists; try { - exists=api.existsPage(wikiName, spaceName, pageName); + exists = api.existsPage(wikiName, spaceName, pageName); return exists; } catch (RestException e) { throw new RaoException(e); - } + } } @Override @@ -257,8 +344,4 @@ public void delete(Document resrc) throws RestConnectionException, RaoException delete(resrc.getDocumentReference()); } - - - - } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java index b82ae9c..f7d5d34 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java @@ -9,187 +9,201 @@ public class Comment extends Resource { - List links; - int id =-1; //-1 to mean null - String author; - Date date; - String text; - int replyTo=-1; //-1 to mean null - String highlight; - - Document ownerDoc; - List replies; - // object associated to this comment. - XComment xobj; - - public Comment() - { - replies=new ArrayList(); - } - - public Comment(String text){ - this(); - this.text=text; - } - - /** - * - * This method also adds the reply comment to the parent comment's owning document if it is owned by a document. - * @return true if added. false if already contained the comment. - */ - public boolean addReplyComment(Comment rply){ - if(!replies.contains(rply)){ - replies.add(rply); - if(ownerDoc!=null){ - rply.replyTo=this.id;//setting id is done by document. If this cmnt is owned by a doc then it is - ownerDoc.addComment(rply); - } - return true; - }else{ - return false; - } - } - - public List getReplies() - { - return replies; - } - - public void setReplies(List replies) - { - this.replies = replies; - } - - public List getLinks() - { - return links; - } - - public void addLink(Link link) - { - links.add(link); - } - - public void removeLink(int index) - { - links.remove(index); - } - - public void clearLinks() - { - links.clear(); - } - - public int getId() - { - return id; - } - - public void setId(int id) - { - if(ownerDoc!=null){ - throw new IllegalStateException("You cannot alter the id of a comment after it is owned by a document"); - } - this.id = id; - } - - public String getAuthor() - { - return author; - } - - public void setAuthor(String author) - { - this.author = author; - } - - public Date getDate() - { - return date; - } - - public void setDate(Date date) - { - this.date = date; - } - - public String getText() - { - return text; - } - - public void setText(String text) - { - this.text = text; - } - - public int getReplyTo() - { - return replyTo; - } - - public void setReplyTo(int replyTo) - { - this.replyTo = replyTo; - } - - public String getHighlight() - { - return highlight; - } - - public void setHighlight(String highlight) - { - this.highlight = highlight; - } - - //package - - Document getDocument(){ - return ownerDoc; - } - void setOwner(Document ownerDoc){ - this.ownerDoc=ownerDoc; - } - - - - - //private - - private XComment getXObject() - { - if (xobj == null) { - xobj = new XComment(); - - // ! xobj.setId(""+id);// dont set.Not the same. - xobj.setNumber(id); - xobj.setAuthor(author); - xobj.setDate(date); - xobj.setComment(text); - xobj.setReplyto(replyTo); - - } - return xobj; - } - - - - private void setXObject(XComment xobj) - { - this.xobj = xobj; - } - - @Override - public boolean equals(Object o) - { - if (!(o instanceof XComment)) { - return false; - } else { - Comment c = (Comment) o; - return c.getId() == this.id && c.text==this.text; - } - - } + List links; + int id = -1; // -1 to mean null + String author; + Date date; + String text; + int replyTo = -1; // -1 to mean null + String highlight; + + Document ownerDoc; + List replies; + // object associated to this comment. + XComment xobj; + + public Comment() + { + replies = new ArrayList(); + } + + public Comment(String text) + { + this(); + this.text = text; + } + + /** + * + * This method also adds the reply comment to the parent comment's owning + * document if it is owned by a document. + * + * @return true if added. false if already contained the comment. + */ + public boolean addReplyComment(Comment rply) + { + if (!replies.contains(rply)) { + replies.add(rply); + if (ownerDoc != null) { + ownerDoc.addComment(rply); + } + rply.replyTo = this.id; + return true; + } else { + return false; + } + } + + /** + * when the id of this comment is changed refresh the change to replyTo + * fields of direct reply comments. + */ + private void refreshChildrenReplyToID() + { + for (Comment rply : this.getReplies()) { + rply.setReplyTo(this.getId()); + } + } + + public List getReplies() + { + return replies; + } + + public void setReplies(List replies) + { + this.replies = replies; + } + + public List getLinks() + { + return links; + } + + public void addLink(Link link) + { + links.add(link); + } + + public void removeLink(int index) + { + links.remove(index); + } + + public void clearLinks() + { + links.clear(); + } + + public int getId() + { + return id; + } + + public void setId(int id) + { + if (ownerDoc != null) { + throw new IllegalStateException("You cannot alter the id of a comment after it is owned by a document"); + } + this.id = id; + refreshChildrenReplyToID(); + } + + public String getAuthor() + { + return author; + } + + public void setAuthor(String author) + { + this.author = author; + } + + public Date getDate() + { + return date; + } + + public void setDate(Date date) + { + this.date = date; + } + + public String getText() + { + return text; + } + + public void setText(String text) + { + this.text = text; + } + + public int getReplyTo() + { + return replyTo; + } + + public void setReplyTo(int replyTo) + { + this.replyTo = replyTo; + } + + public String getHighlight() + { + return highlight; + } + + public void setHighlight(String highlight) + { + this.highlight = highlight; + } + + // package + + Document getDocument() + { + return ownerDoc; + } + + void setOwner(Document ownerDoc) + { + this.ownerDoc = ownerDoc; + } + + // private + + private XComment getXObject() + { + if (xobj == null) { + xobj = new XComment(); + + // ! xobj.setId(""+id);// dont set.Not the same. + xobj.setNumber(id); + xobj.setAuthor(author); + xobj.setDate(date); + xobj.setComment(text); + xobj.setReplyto(replyTo); + + } + return xobj; + } + + private void setXObject(XComment xobj) + { + this.xobj = xobj; + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof XComment)) { + return false; + } else { + Comment c = (Comment) o; + return c.getId() == this.id && c.text == this.text; + } + + } } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java index 388e58a..65fd5ae 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java @@ -17,480 +17,517 @@ import android.util.Log; /** - * @author xwiki gsoc 2012 A document that supports only SimpleObjects. Simple Objects are shallow objects that can have - * only XProperties for property fields. + * @author xwiki gsoc 2012 A document that supports only SimpleObjects. Simple + * Objects are shallow objects that can have only XProperties for + * property fields. */ public class Document extends DocumentBase { - // things in a retreived document. - private DocumentBase parent; - - private List children; - - private Map objects; // key= ClassName/number - - private Map comments; // key = int index in the list - - private Map attatchments;// key = resource id. ex: xwiki:Blog.BlogPost1@mypic -->key is: mypic - - private List tags; // search by key not needed - - // resources that get newly added. - // no keys. These are to be posted to server.Server will define the keys after these resources are posted. - private List newObjects; - private List newAttachments; - private List newComments; - private List newTags; // just a ref to tags. We always have to send the whole set in Rest. - - - // resources to update - - private Map editedObjects; // key= ClassName/number - private List editedAttachments;// key = resource id i.e . ex: xwiki:Blog.BlogPost1@mypic => mypic - // space.png - private List editedComments; - - // resources to delete - private List deletedObjects; // value= of the deleted obj. ClassName/number - private List deletedAttachments; - private List deletedCommetns; - private List deletedTags; - - public Document(String wikiName, String spaceName, String pageName) - { - super(wikiName, spaceName, pageName); - - objects = new Hashtable(); - newObjects = new ArrayList(); - editedObjects = new Hashtable(); - deletedObjects = new ArrayList(); - - comments = new HashMap(); - newComments=new ArrayList(); - editedComments=new ArrayList(); - deletedCommetns=new ArrayList(); - - attatchments=new Hashtable(); - newAttachments=new ArrayList(); - editedAttachments=new ArrayList(); - deletedAttachments=new ArrayList(); - - tags=new ArrayList(); - newTags=new ArrayList(); - deletedTags=new ArrayList(); - } - - /** - * When retrieving the object through get it will return the reference to the object in the list. Warning! For the - * current implementation, alterations done to the object will not get affected in the server unless the edited - * object is reset explicitly through setObject(String key, XSimpleObject object). - * - * @param key - * @return - */ - public XSimpleObject getObject(String key) - { - // TODO: When retreived by a RAL layer obj::- use isAltered method in Resource. use this to automatically - // identify altered objects - // and add them to editedObjects Map at the "ral.transformation" package. - XSimpleObject obj = objects.get(key); - if(obj!=null){ - obj.setEdited(true); - } - return obj; - } - - public XSimpleObject getObject(String className, int number) - { - String key=className+"/"+number; - XSimpleObject obj = objects.get(key); - if(obj!=null){ - obj.setEdited(true); - } - return obj; - } - - - /** - * Update a existing object in the doc. The update is done if the Object.isAltered returns true. This property is - * set by defalut, when the object is retrieved using getObject(key) - * - * @param key - * @param object - */ - @Deprecated - public void setObject(String key, XSimpleObject object) - { - String keyprefix=object.getClassName(); - boolean valid=true; - valid=key.startsWith(keyprefix); - if(valid){ - String[] args=key.split("[/]"); - String clsName=args[0]; - String number=args[1]; - valid=clsName.equals(object.getClassName());// &&number.matches("[\\d]+") ; - object.setNumber(new Integer(number)); - } - if(!valid){ - throw new IllegalArgumentException("invalid form of key.\n" + - " Key should be of the form /. " + - " \nIdeally you shold retreive these objects from server before editing."); - } - - if (object.isEdited()) {//may remove this line. Since set is done because XObj is edited. - editedObjects.put(key, object); - } - objects.put(key, object); - } - /** - * - * @param object - * @return key to refer this obj. - */ - public String setObject(XSimpleObject object) - { - if(object.getNumber()==-1){ - throw new IllegalArgumentException("object's number must be set"); - } - if(object.getClassName().equals("")){ - throw new IllegalArgumentException("object's class name must not be empty"); - } - //end validation - - String key=object.getClassName()+"/"+object.getNumber(); - - if (object.isEdited()) {//may remove this line. Since set is done because XObj is edited. - editedObjects.put(key, object); - } - objects.put(key, object); - return key; - } - - private int _addNum = 0; - - /** - * @param obj - * @return the auto generated key for this object. key is /new/ - */ - public String addObject(XSimpleObject obj) - { - String key = obj.getClassName() + "/new/" + _addNum++; - obj.setNew(true); - objects.put(key, obj); - newObjects.add(obj); - return key; - } - - public void deleteObject(String key) - { - XSimpleObject obj = objects.get(key); - if (obj.isNew()) { - newObjects.remove(obj); - } else { - deletedObjects.add(key); - } - if (obj.isEdited()) { - editedObjects.remove(key); - } - objects.remove(key); - - } - - - public Comment getComment(int id){ - return comments.get(id); - } - /** - * - * @param cmnt - * @return id of the new comment. - */ - public int addComment(Comment cmnt){ - if(!newComments.contains(cmnt)&&!comments.containsKey(cmnt.getId())){ - newComments.add(cmnt); - int id=-newComments.size()-10; - comments.put(id,cmnt); - cmnt.setId(id); - cmnt.setOwner(this); - return id; - }else{ - return cmnt.getId(); - } - } - - /** - * - * @param cmnt - * @param cascade if true adds all the reply comments as well to the document. - * @return int[0]=parent comments id, int[1] number of comments added - */ - public int[] addComment(Comment prntCmnt, boolean cascade){ - int pid=addComment(prntCmnt); - int[] rslts=new int[2]; - rslts[0]=pid; - rslts[1]=1; - if(cascade){ - for(Comment rply:prntCmnt.getReplies()){ - int[] recRslt=addComment(rply,true); - rslts[1]+=recRslt[1]; - } - } - return rslts; - } - - @Deprecated //TODO remove soon - public void setComment(int id, Comment cmnt){ - if(id<0){ - throw new IllegalArgumentException("comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); - } - comments.put(id, cmnt); - if(!editedComments.contains(cmnt)){ - editedComments.add(cmnt); - } - if(cmnt.getDocument()!=null){ - if(this!=cmnt.getDocument())throw new IllegalStateException("comment is already owned by another doc"); - }else{ - cmnt.setId(id); - cmnt.setOwner(this); - } - - } - - public void setComment(Comment cmnt){ - int id=cmnt.getId(); - if(id<0){ - throw new IllegalArgumentException("comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); - } - comments.put(id, cmnt); - if(!editedComments.contains(cmnt)){ - editedComments.add(cmnt); - } - if(cmnt.getDocument()!=null){ - if(this!=cmnt.getDocument())throw new IllegalStateException("comment is already owned by another doc"); - }else{ - cmnt.setId(id); - cmnt.setOwner(this); - } - - } - - - public void deleteComment(int id){ - comments.remove(id); - Comment cmnt=new Comment(); - cmnt.setId(id); - if(id<0){ - int i=newComments.indexOf(cmnt); - if(i>=0){ - newComments.remove(i); - } - }else{ - int j=editedComments.indexOf(cmnt); - if(j>=0){ - editedComments.remove(j); - } - } - - deletedCommetns.add(id); - } - - public List getTags(){ - return tags; - } - - public void addTag(Tag tag){ - tags.add(tag); - newTags=tags; - } - - public void clearTags(){ - for(Tag t:tags){ - deletedTags.add(t.getName()); - } - tags.clear(); - } - - public Attachment getAttachment(String name){ - Attachment a=attatchments.get(name); - a.setEdited(true); - return attatchments.get(name); - } - - public String addAttachment(Attachment a){ - if(a.isNew()==true){ - newAttachments.add(a); - } - attatchments.put(a.getName(), a); - return a.getName(); - } - - public void setAttachment(String name,Attachment a){ - if(a.getName()==null){ - a.setName(name); - } - - if(a.isEdited()==true){ - int i=editedAttachments.indexOf(a); - if(i>-1){ - editedAttachments.add(i,a); - }else{ - editedAttachments.add(a); - } - attatchments.put(name, a); - } - - } - /** - * - * @param name - * @return true. If the attachment existed locally in the list and was marked for deletion. - * false. Attachement is not in the local list. But the model has marked the attachment for - * deletion on the server. - * - */ - public boolean deleteAttachment(String name){ - Attachment a=attatchments.remove(name); - if(!deletedAttachments.contains(name)){ - deletedAttachments.add(a.getName()); - } - if(a==null){ - Log.w(this.getClass().getSimpleName(), "marking an unknown attachment to be deleted"); - return false; - }else { - return true; - } - - } - - - - public Map getAllObjects() - { - return objects; - } - - public DocumentBase getParentDocument() - { - return parent; - } - - public List getChildrenDocuments() - { - return children; - } - - public Map getAllComments() - { - return comments; - } - - public Map getAllAttatchments() - { - return attatchments; - } - - public List getAllTags() - { - return tags; - } - - public List getAllNewObjects() - { - return newObjects; - } - - - public List getAllNewComments() + // things in a retreived document. + private DocumentBase parent; + + private List children; + + private Map objects; // key= ClassName/number + + private Map comments; // key = int index in the list + + private Map attatchments;// key = resource id. ex: + // xwiki:Blog.BlogPost1@mypic + // -->key is: mypic + + private List tags; // search by key not needed + + // resources that get newly added. + // no keys. These are to be posted to server.Server will define the keys + // after these resources are posted. + private List newObjects; + private List newAttachments; + private List newComments; + private List newTags; // just a ref to tags. We always have to send the + // whole set in Rest. + + // resources to update + + private Map editedObjects; // key= ClassName/number + private List editedAttachments;// key = resource id i.e . + // ex: + // xwiki:Blog.BlogPost1@mypic => + // mypic + // space.png + private List editedComments; + + // resources to delete + private List deletedObjects; // value= of the deleted obj. + // ClassName/number + private List deletedAttachments; + private List deletedCommetns; + private List deletedTags; + + public Document(String wikiName, String spaceName, String pageName) + { + super(wikiName, spaceName, pageName); + + objects = new Hashtable(); + newObjects = new ArrayList(); + editedObjects = new Hashtable(); + deletedObjects = new ArrayList(); + + comments = new HashMap(); + newComments = new ArrayList(); + editedComments = new ArrayList(); + deletedCommetns = new ArrayList(); + + attatchments = new Hashtable(); + newAttachments = new ArrayList(); + editedAttachments = new ArrayList(); + deletedAttachments = new ArrayList(); + + tags = new ArrayList(); + newTags = new ArrayList(); + deletedTags = new ArrayList(); + } + + /** + * When retrieving the object through get it will return the reference to + * the object in the list. Warning! For the current implementation, + * alterations done to the object will not get affected in the server unless + * the edited object is reset explicitly through setObject(String key, + * XSimpleObject object). + * + * @param key + * @return + */ + public XSimpleObject getObject(String key) + { + // TODO: When retreived by a RAL layer obj::- use isAltered method in + // Resource. use this to automatically + // identify altered objects + // and add them to editedObjects Map at the "ral.transformation" + // package. + XSimpleObject obj = objects.get(key); + if (obj != null) { + obj.setEdited(true); + } + return obj; + } + + public XSimpleObject getObject(String className, int number) + { + String key = className + "/" + number; + XSimpleObject obj = objects.get(key); + if (obj != null) { + obj.setEdited(true); + } + return obj; + } + + /** + * Update a existing object in the doc. The update is done if the + * Object.isAltered returns true. This property is set by defalut, when the + * object is retrieved using getObject(key) + * + * @param key + * @param object + */ + @Deprecated + public void setObject(String key, XSimpleObject object) + { + String keyprefix = object.getClassName(); + boolean valid = true; + valid = key.startsWith(keyprefix); + if (valid) { + String[] args = key.split("[/]"); + String clsName = args[0]; + String number = args[1]; + valid = clsName.equals(object.getClassName());// &&number.matches("[\\d]+") + // ; + object.setNumber(new Integer(number)); + } + if (!valid) { + throw new IllegalArgumentException("invalid form of key.\n" + + " Key should be of the form /. " + + " \nIdeally you shold retreive these objects from server before editing."); + } + + if (object.isEdited()) {// may remove this line. Since set is done + // because XObj is edited. + editedObjects.put(key, object); + } + objects.put(key, object); + } + + /** + * + * @param object + * @return key to refer this obj. + */ + public String setObject(XSimpleObject object) + { + if (object.getNumber() == -1) { + throw new IllegalArgumentException("object's number must be set"); + } + if (object.getClassName().equals("")) { + throw new IllegalArgumentException("object's class name must not be empty"); + } + // end validation + + String key = object.getClassName() + "/" + object.getNumber(); + + if (object.isEdited()) {// may remove this line. Since set is done + // because XObj is edited. + editedObjects.put(key, object); + } + objects.put(key, object); + return key; + } + + private int _addNum = 0; + + /** + * @param obj + * @return the auto generated key for this object. key is + * /new/ + */ + public String addObject(XSimpleObject obj) + { + String key = obj.getClassName() + "/new/" + _addNum++; + obj.setNew(true); + objects.put(key, obj); + newObjects.add(obj); + return key; + } + + public void deleteObject(String key) + { + XSimpleObject obj = objects.get(key); + if (obj.isNew()) { + newObjects.remove(obj); + } else { + deletedObjects.add(key); + } + if (obj.isEdited()) { + editedObjects.remove(key); + } + objects.remove(key); + + } + + public Comment getComment(int id) + { + return comments.get(id); + } + + /** + * + * @param cmnt + * @return id of the new comment. + */ + public int addComment(Comment cmnt) + { + if (!newComments.contains(cmnt) && !comments.containsKey(cmnt.getId())) { + newComments.add(cmnt); + int id = -newComments.size() - 10; + comments.put(id, cmnt); + cmnt.setId(id); + cmnt.setOwner(this); + return id; + } else { + return cmnt.getId(); + } + } + + /** + * + * @param cmnt + * @param cascade + * if true adds all the reply comments as well to the document. + * @return int[0]=parent comments id, int[1] number of comments added + */ + public int[] addComment(Comment prntCmnt, boolean cascade) + { + int pid = addComment(prntCmnt); + int[] rslts = new int[2]; + rslts[0] = pid; + rslts[1] = 1; + if (cascade) { + for (Comment rply : prntCmnt.getReplies()) { + int[] recRslt = addComment(rply, true); + rslts[1] += recRslt[1]; + } + } + return rslts; + } + + + + @Deprecated + // TODO remove soon + public void setComment(int id, Comment cmnt) + { + if (id < 0) { + throw new IllegalArgumentException( + "comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); + } + cmnt.setId(id); + comments.put(id, cmnt); + if (!editedComments.contains(cmnt)) { + editedComments.add(cmnt); + } + if (cmnt.getDocument() != null) { + if (this != cmnt.getDocument()) + throw new IllegalStateException("comment is already owned by another doc"); + } else { + cmnt.setId(id); + cmnt.setOwner(this); + } + + } + + public void setComment(Comment cmnt) + { + int id = cmnt.getId(); + if (id < 0) { + throw new IllegalArgumentException( + "comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); + } + comments.put(id, cmnt); + if (!editedComments.contains(cmnt)) { + editedComments.add(cmnt); + } + if (cmnt.getDocument() != null) { + if (this != cmnt.getDocument()) + throw new IllegalStateException("comment is already owned by another doc"); + } else { + cmnt.setId(id); + cmnt.setOwner(this); + } + + } + + public void deleteComment(int id) + { + comments.remove(id); + Comment cmnt = new Comment(); + cmnt.setId(id); + if (id < 0) { + int i = newComments.indexOf(cmnt); + if (i >= 0) { + newComments.remove(i); + } + } else { + int j = editedComments.indexOf(cmnt); + if (j >= 0) { + editedComments.remove(j); + } + } + + deletedCommetns.add(id); + } + + public List getTags() + { + return tags; + } + + public void addTag(Tag tag) + { + tags.add(tag); + newTags = tags; + } + + public void clearTags() + { + for (Tag t : tags) { + deletedTags.add(t.getName()); + } + tags.clear(); + } + + public Attachment getAttachment(String name) + { + Attachment a = attatchments.get(name); + a.setEdited(true); + return attatchments.get(name); + } + + public String addAttachment(Attachment a) + { + if (a.isNew() == true) { + newAttachments.add(a); + } + attatchments.put(a.getName(), a); + return a.getName(); + } + + public void setAttachment(String name, Attachment a) + { + if (a.getName() == null) { + a.setName(name); + } + + if (a.isEdited() == true) { + int i = editedAttachments.indexOf(a); + if (i > -1) { + editedAttachments.add(i, a); + } else { + editedAttachments.add(a); + } + attatchments.put(name, a); + } + + } + + /** + * + * @param name + * @return true. If the attachment existed locally in the list and was + * marked for deletion. false. Attachement is not in the local list. + * But the model has marked the attachment for deletion on the + * server. + * + */ + public boolean deleteAttachment(String name) + { + Attachment a = attatchments.remove(name); + if (!deletedAttachments.contains(name)) { + deletedAttachments.add(a.getName()); + } + if (a == null) { + Log.w(this.getClass().getSimpleName(), "marking an unknown attachment to be deleted"); + return false; + } else { + return true; + } + + } + + public Map getAllObjects() + { + return objects; + } + + public DocumentBase getParentDocument() + { + return parent; + } + + public List getChildrenDocuments() + { + return children; + } + + public Map getAllComments() + { + return comments; + } + + public Map getAllAttatchments() + { + return attatchments; + } + + public List getAllTags() + { + return tags; + } + + public List getAllNewObjects() + { + return newObjects; + } + + public List getAllNewComments() { return newComments; } - - - public List getAllNewAttachments() - { - return newAttachments; - } - - public List getAllNewTags() + + public List getAllNewAttachments() + { + return newAttachments; + } + + public List getAllNewTags() { return newTags; } - - public Map getAllEditedObjects() - { - return editedObjects; - } + public Map getAllEditedObjects() + { + return editedObjects; + } - public List getAllEditedComments() + public List getAllEditedComments() { return editedComments; } - - public List getAllEditedAttachments() - { - return editedAttachments; - } - - - - public List listObjectDeletions() - { - return deletedObjects; - } - - public Set getDeletedObjects(){ - Set s=new HashSet(); - s.addAll(deletedObjects); - return s; - } - - public List listCommentDeletions() - { - return deletedCommetns; - } - - public Set getDeletedCommentSet(){ - Set s=new HashSet(); - s.addAll(deletedCommetns); - return s; - } - - - public List listAttachmentDeletions(){ - return deletedAttachments; - } - - public Set getDeletedAttachments(){ - Set s=new HashSet(); - s.addAll(deletedObjects); - return s; - } - - public List listTagDeletions(){ - return deletedTags; + + public List getAllEditedAttachments() + { + return editedAttachments; + } + + public List listObjectDeletions() + { + return deletedObjects; + } + + public Set getDeletedObjects() + { + Set s = new HashSet(); + s.addAll(deletedObjects); + return s; + } + + public List listCommentDeletions() + { + return deletedCommetns; + } + + public Set getDeletedCommentSet() + { + Set s = new HashSet(); + s.addAll(deletedCommetns); + return s; + } + + public List listAttachmentDeletions() + { + return deletedAttachments; + } + + public Set getDeletedAttachments() + { + Set s = new HashSet(); + s.addAll(deletedObjects); + return s; + } + + public List listTagDeletions() + { + return deletedTags; } - public void setParent(DocumentBase parent) - { - if (parentFullName == null) { - parentFullName = parent.fullName; - } - if (parentId == null) { + { + if (parentFullName == null) { + parentFullName = parent.fullName; + } + if (parentId == null) { - } - this.parent = parent; - } + } + this.parent = parent; + } - public void setChildren(List children) - { - this.children = children; - } + public void setChildren(List children) + { + this.children = children; + } } /** - * NOTE: TODO: extract interface Document.l Always use XWikiApplicationContext to create new. + * NOTE: TODO: extract interface Document.l Always use XWikiApplicationContext + * to create new. **/ diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDateProperty.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDateProperty.java index 0d5d34a..2480b2e 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDateProperty.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDateProperty.java @@ -43,7 +43,12 @@ public String toString() SimpleDateFormat sdf = new SimpleDateFormat(fmt); return sdf.format(value); } - return value.toGMTString(); + if(value!=null){ + return value.toGMTString(); + }else{ + return null; + } + } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDoubleProperty.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDoubleProperty.java index 0dd1ce2..f41ae0d 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDoubleProperty.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XDoubleProperty.java @@ -27,5 +27,11 @@ public void setValueFromString(String val) { this.val=new Double(val); } + + @Override + public String toString() + { + return val+""; + } } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XFloatProperty.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XFloatProperty.java index 0b18d75..1607895 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XFloatProperty.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XFloatProperty.java @@ -28,5 +28,11 @@ public void setValueFromString(String val) { this.val=new Float(val); } + + @Override + public String toString() + { + return val+""; + } } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XIntegerProperty.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XIntegerProperty.java index bfe75da..fa7f483 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XIntegerProperty.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XIntegerProperty.java @@ -2,29 +2,35 @@ public class XIntegerProperty extends XNumberProperty { - private Integer val; - - public XIntegerProperty() - { - fields.put("numberType","integer"); - } + private Integer val; - @Override - public void setValue(Integer val) - { - this.val=val; - } + public XIntegerProperty() + { + fields.put("numberType", "integer"); + } + + @Override + public void setValue(Integer val) + { + this.val = val; + } + + @Override + public Integer getValue() + { + return val; + } + + @Override + public void setValueFromString(String val) + { + this.val = new Integer(val); + } + + @Override + public String toString() + { + return val+""; + } - @Override - public Integer getValue() - { - return val; - } - - @Override - public void setValueFromString(String val) - { - this.val=new Integer(val); - } - } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XLongProperty.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XLongProperty.java index d85c032..8efce70 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XLongProperty.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XLongProperty.java @@ -2,29 +2,34 @@ public class XLongProperty extends XNumberProperty { - private Long val; + private Long val; - public XLongProperty() - { - fields.put("numberType", "long"); - } + public XLongProperty() + { + fields.put("numberType", "long"); + } - @Override - public void setValue(Long val) - { - this.val = val; - } + @Override + public void setValue(Long val) + { + this.val = val; + } - @Override - public Long getValue() - { - return val; - } - - @Override - public void setValueFromString(String val) - { - this.val=new Long(val); - } + @Override + public Long getValue() + { + return val; + } + @Override + public void setValueFromString(String val) + { + this.val = new Long(val); + } + + @Override + public String toString() + { + return val + ""; + } } diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java b/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java index f83e477..a8d8ad2 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java @@ -278,7 +278,7 @@ public int checkLogin(String username, String password, String Url) throws RestC String Uri; int responseCode = 0; - Uri = "http://" + Url + "/xwiki/xmlrpc/"; + Uri = "http://" + Url + "/xwiki/rest/"; try { requestUri = new URI(Uri); diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java index ffea118..25d9ec6 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java @@ -577,7 +577,7 @@ public InputStream getPageAttachment(String wikiName, String spaceName, String p * java.lang.String, java.lang.String, java.lang.String) */ - @Override + @Override public String putPageAttachment(String wikiName, String spaceName, String pageName, String filePath, String attachmentName) throws RestConnectionException, RestException { @@ -592,6 +592,8 @@ public String putPageAttachment(String wikiName, String spaceName, String pageNa } return attachmentresources.putPageAttachment(filePath, attachmentName); } + + /* * (non-Javadoc) diff --git a/xwiki-android-test-core/project.properties b/xwiki-android-test-core/project.properties index 0d7f4ae..01b98dd 100644 --- a/xwiki-android-test-core/project.properties +++ b/xwiki-android-test-core/project.properties @@ -12,5 +12,4 @@ # Project target. target=android-7 -android.library.reference.1=..\\xwiki-android-rest -android.library.reference.2=../xwiki-android-core +android.library.reference.1=../xwiki-android-rest diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java index 93a3b01..2cf7019 100644 --- a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java +++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java @@ -38,233 +38,270 @@ */ public class TestDocumentRaoCreate extends AndroidTestCase { - private static final String TAG = TestDocumentRaoCreate.class.getSimpleName(); + private static final String TAG = TestDocumentRaoCreate.class.getSimpleName(); // test org.xwiki.android.test.fixture.teardown.env parameters. - String serverUrl, username, password, wikiName, spaceName, pageName, attachmentName; - static int count=1; - - // tested apis - RESTfulManager rm; - DocumentRao rao; - - // api used for output verification - XWikiAPI api; - - // test inputs - Document doc; - // special inputs set in tests - XBlogPost xb1, xb2, xb3; - XSimpleObject so1, so2; // a general so. - Comment c1, c2, c3; - Tag t1, t2; - Attachment a1; - File af1; - - public TestDocumentRaoCreate() - { - username = Env.USERNAME; - password = Env.PASSWORD; - serverUrl = Env.URL; - - wikiName = Env.WIKI_NAME; - spaceName = Env.SPACE_NAME; - pageName = Env.TEMP_PAGE_NAME; - attachmentName=Env.ATTACHMENT_NAME; - } - - @Override - protected void setUp() throws Exception - { - super.setUp(); - rm = new XmlRESTFulManager(serverUrl, username, password); - api = rm.getConnection().getBaseAPI(); - rao = rm.newDocumentRao(); - doc = new Document(wikiName, spaceName, pageName); - doc.setTitle(pageName); - - // setup preconditions on serverside - if(count<6)api.deletePage(wikiName, spaceName, pageName); - if(count==1){ - Application sys=XWikiApplicationContext.getInstance(); - FileOutputStream fos = sys.openFileOutput(attachmentName, Context.MODE_WORLD_READABLE); - PrintWriter writer=new PrintWriter(fos); - writer.println("this is a text attachment."); - writer.flush(); - writer.close(); - af1=sys.getFileStreamPath(attachmentName); - } - Log.d(TAG,"setup test method:"+ count ); - - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - count++; - // rm.close(); - } - - /** - * a minimal test - */ - public void testCreate01() throws Throwable - { - boolean success = true; - - try { - rao.create(doc); - success = api.existsPage(wikiName, spaceName, pageName); - } catch (RaoException e) { - success = false; - } catch (RestException e) { - success = false; - } - assertTrue(success); - } - - /** - * test with xobjects. Use add method. - */ - public void testCreate02() throws Throwable - { - boolean success = false; - xb1 = new XBlogPost(); - xb1.setContent("test post"); - doc.addObject(xb1); - try { - rao.create(doc); - } catch (RaoException e) { - success = false; - } - try { - success = api.existsPage(wikiName, spaceName, pageName); - } catch (RestException e) { - success = false; - } - assertTrue(success); - } - - /** - * test add/set general XSimpleObject. - * - * @throws Throwable - */ - public void testCreate03() throws Throwable - { - boolean success; - so1 = new XSimpleObject("Blog.BlogClass") - { - }; - so2 = new XSimpleObject("Blog.BlogCategoryClass") - { - }; - so2.setNumber(1); - doc.addObject(so1); - doc.setObject(so2); - - try { - rao.create(doc); - } catch (RaoException e) { - success = false; - } - - // verify - try { - success = api.existsPage(wikiName, spaceName, pageName); - if (success) { - boolean crite1 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); - boolean crite2 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); - success = crite1 & crite2; - } - } catch (RestException e) { - success = false; - } - } - - /** - * checks wether the objects get added in the correct sequence - * - * @throws Throwable - */ - public void testCreate04() throws Throwable - { - boolean success = false; - xb1 = new XBlogPost(); - xb2 = new XBlogPost(); - xb3 = new XBlogPost(); - - xb1.setContent("0"); - xb2.setContent("1"); - xb3.setContent("2"); - - xb1.setNumber(0); - // dont set num on xb2 - xb3.setNumber(2); - - doc.setObject(xb1); - doc.addObject(xb2); - doc.setObject(xb3); - - rao.create(doc); - - try { - success = api.existsPage(wikiName, spaceName, pageName); - if (success) { - boolean crite1 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 0); - boolean crite2 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 1); - boolean crite3 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 2); - success = crite1 & crite2 & crite3; - } - if (success) { - Property xb2PropRet = - api.getObjectProperty(wikiName, spaceName, pageName, xb2.getClassName(), "1", "content"); - success = xb2PropRet.getValue().equals("1"); - } - - } catch (RestException e) { - success = false; - } - assertTrue(success); - } - - public void testCreate05WithCmnts() throws Throwable - { - - c1 = new Comment("hi"); - c2 = new Comment("reply to hi"); - c1.addReplyComment(c2); - doc.addComment(c1, true); - - try { - rao.create(doc); - } catch (RaoException e) { - throw new AssertionFailedError("xmlrpc exception code=" + e.getCode()); - } - try { - boolean success = api.existsPage(wikiName, spaceName, pageName); - assertTrue(success); - if (success) { - Comments cmnts = api.getPageComments(wikiName, spaceName, pageName); - List cl = cmnts.comments; - assertEquals(2, cl.size()); - int replyto = cl.get(1).replyTo; - assertEquals(0, replyto); - } - } catch (RestException e) { - throw new AssertionFailedError("xmlrpc exception code=" + e.getCode()); - } - } - -// public void testCreate06WithAttachment() throws Throwable -// { -// -// Attachment a=new Attachment(attachmentName, af1); -// doc.addAttachment(a); -// rao.create(doc); -// assertNotNull(api.getPageAttachment(wikiName, spaceName, pageName, attachmentName)); -// -// -// -// } + String serverUrl, username, password, wikiName, spaceName, pageName, attachmentName; + static int count = 1; + + // tested apis + RESTfulManager rm; + DocumentRao rao; + + // api used for output verification + XWikiAPI api; + + // test inputs + Document doc; + // special inputs set in tests + XBlogPost xb1, xb2, xb3; + XSimpleObject so1, so2; // a general so. + Comment c1, c2, c3, c4; + Tag t1, t2; + Attachment a1; + File af1; + + public TestDocumentRaoCreate() + { + username = Env.USERNAME; + password = Env.PASSWORD; + serverUrl = Env.URL; + + wikiName = Env.WIKI_NAME; + spaceName = Env.SPACE_NAME; + pageName = Env.TEMP_PAGE_NAME; + attachmentName = Env.ATTACHMENT_NAME; + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + rm = new XmlRESTFulManager(serverUrl, username, password); + api = rm.getConnection().getBaseAPI(); + rao = rm.newDocumentRao(); + doc = new Document(wikiName, spaceName, pageName); + doc.setTitle(pageName); + + // setup preconditions on serverside + if (count < 7) + api.deletePage(wikiName, spaceName, pageName); + if (count == 1) { + Application sys = XWikiApplicationContext.getInstance(); + FileOutputStream fos = sys.openFileOutput(attachmentName, Context.MODE_WORLD_READABLE); + PrintWriter writer = new PrintWriter(fos); + writer.println("this is a text attachment."); + writer.flush(); + writer.close(); + af1 = sys.getFileStreamPath(attachmentName); + } + Log.d(TAG, "setup test method:" + count); + + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + count++; + // rm.close(); + } + + /** + * a minimal test + */ + public void testCreate01() throws Throwable + { + boolean success = true; + + try { + rao.create(doc); + success = api.existsPage(wikiName, spaceName, pageName); + } catch (RaoException e) { + success = false; + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + /** + * test with xobjects. Use add method. + */ + public void testCreate02() throws Throwable + { + boolean success = false; + xb1 = new XBlogPost(); + xb1.setContent("test post"); + doc.addObject(xb1); + try { + rao.create(doc); + } catch (RaoException e) { + success = false; + } + try { + success = api.existsPage(wikiName, spaceName, pageName); + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + /** + * test add/set general XSimpleObject. + * + * @throws Throwable + */ + public void testCreate03() throws Throwable + { + boolean success; + so1 = new XSimpleObject("Blog.BlogClass") + { + }; + so2 = new XSimpleObject("Blog.BlogCategoryClass") + { + }; + so2.setNumber(1); + doc.addObject(so1); + doc.setObject(so2); + + try { + rao.create(doc); + } catch (RaoException e) { + success = false; + } + + // verify + try { + success = api.existsPage(wikiName, spaceName, pageName); + if (success) { + boolean crite1 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); + boolean crite2 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); + success = crite1 & crite2; + } + } catch (RestException e) { + success = false; + } + } + + /** + * checks wether the objects get added in the correct sequence + * + * @throws Throwable + */ + public void testCreate04() throws Throwable + { + boolean success = false; + xb1 = new XBlogPost(); + xb2 = new XBlogPost(); + xb3 = new XBlogPost(); + + xb1.setContent("0"); + xb2.setContent("1"); + xb3.setContent("2"); + + xb1.setNumber(0); + // dont set num on xb2 + xb3.setNumber(2); + + doc.setObject(xb1); + doc.addObject(xb2); + doc.setObject(xb3); + + rao.create(doc); + + try { + success = api.existsPage(wikiName, spaceName, pageName); + if (success) { + boolean crite1 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 0); + boolean crite2 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 1); + boolean crite3 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 2); + success = crite1 & crite2 & crite3; + } + if (success) { + Property xb2PropRet = api.getObjectProperty(wikiName, spaceName, pageName, xb2.getClassName(), "1", + "content"); + success = xb2PropRet.getValue().equals("1"); + } + + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + public void testCreate_05_WithCmnts() throws Throwable + { + + c1 = new Comment("hi"); + c2 = new Comment("reply to hi"); + c1.addReplyComment(c2); + doc.addComment(c1, true); + + try { + rao.create(doc); + } catch (RaoException e) { + throw new AssertionFailedError("xmlrpc exception code=" + e.getCode()); + } + try { + boolean success = api.existsPage(wikiName, spaceName, pageName); + assertTrue(success); + if (success) { + Comments cmnts = api.getPageComments(wikiName, spaceName, pageName); + List cl = cmnts.comments; + assertEquals(2, cl.size()); + int replyto = cl.get(1).replyTo; + assertEquals(0, replyto); + } + } catch (RestException e) { + throw new AssertionFailedError("xmlrpc exception code=" + e.getCode()); + } + } + + public void testCreate_06_WithCmnts_SequenceCheck() throws Throwable + { + + c1 = new Comment("0"); + c2 = new Comment("1"); + c3 = new Comment("2"); + c3.setId(2); + c4 = new Comment("3"); + c4.setId(3); + + c1.addReplyComment(c2); + c3.addReplyComment(c4); + + doc.addComment(c1, true); + doc.setComment(c3); + doc.setComment(c4); + + rao.create(doc); + + boolean success = api.existsPage(wikiName, spaceName, pageName); + assertTrue(success); + if (success) { + Comments cmnts = api.getPageComments(wikiName, spaceName, pageName); + List clst = cmnts.comments; + assertEquals(4, clst.size()); + int replyto = clst.get(1).replyTo; + assertEquals(0, replyto); + replyto=clst.get(3).replyTo; + assertEquals(2, replyto); + + assertEquals("3", clst.get(3).text); + } + + } + + // public void testCreate_07_WithAttachment() throws Throwable + // { + // + // Attachment a=new Attachment(attachmentName, af1); + // doc.addAttachment(a); + // rao.create(doc); + // assertNotNull(api.getPageAttachment(wikiName, spaceName, pageName, + // attachmentName)); + // + // + // + // } }