diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java index 4007fa9..50b0617 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java @@ -354,8 +354,20 @@ public DocumentBuilder withAttachment(Attachment attachment) d.setAttachment(a); return this; } - - // public DocumentBuilder_XML withLinks(List links) + +// @Override +// public DocumentBuilder withHistory(Attachments attachments) +// { +// for (Attachment ares : attachments.getAttachments()) { +// withAttachment(ares); +// } +// return this; +// } + + // + // These methods are too fine grain to be worth it. + // + //public DocumentBuilder_XML withLinks(List links) // { // return this; // } @@ -462,6 +474,7 @@ public DocumentBuilder withAttachment(Attachment attachment) // return this; // } // + /* * (non-Javadoc) * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#build() diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTranslator.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTranslator.java new file mode 100644 index 0000000..30f1822 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTranslator.java @@ -0,0 +1,11 @@ +package org.xwiki.android.rest.transformation; + +/** + * + * Translates RestModle to XModel.(other model) + * + */ +public class RestModelTranslator +{ + +} diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java index 7143e99..2a9c0b3 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java @@ -26,6 +26,11 @@ import org.xwiki.android.xmodel.xobjects.XProperty; import org.xwiki.android.xmodel.xobjects.XSimpleObject; +/** + * + * Translates XModel to rest Model (other model). + * + */ public class XModelTranslator_XML { public Page toPage(XWikiPage doc) diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java index a4d633e..4fa91d1 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java @@ -1,9 +1,7 @@ package org.xwiki.android.xmodel.entity; import java.util.Date; -import java.util.List; import org.xwiki.android.rest.reference.DocumentReference; -import org.xwiki.android.rest.reference.Link; /** * Contains the properties of a Page +Additional methods for Document. @@ -11,40 +9,9 @@ * @author xwiki dev: not saved to DB. Only the DocumentReference is saved. */ -public abstract class XWikiPage extends XWikiResource +public abstract class XWikiPage extends XWikiPageSummary { - // Resource fields - // - protected List links; - - protected String id;// id field in the resource representation. Mobile apps normally use ReSTful URL to - // identify a resource.Not this. - - protected String fullName; - - protected String wikiName;// wiki in page element - - protected String spaceName;// space in page element - - protected String name; // name in page element (same) - - protected String title; - - protected String parentFullName;// parent in resoruce repr. - - protected String parentId; - - protected String xwikiRelativeUrl; - - protected String xwikiAbsoluteUrl; - - protected List translations; - - protected String defalutTranslation; - - protected String syntax; - protected String language; protected String version; @@ -63,8 +30,8 @@ public abstract class XWikiPage extends XWikiResource protected String content; - // other fields - protected DocumentReference docRef; + + /** @@ -86,7 +53,7 @@ public XWikiPage(String wikiName, String spaceName, String pageName) */ public DocumentReference getDocumentReference() { - docRef = new DocumentReference(wikiName, spaceName, name); + DocumentReference docRef = new DocumentReference(wikiName, spaceName, name); docRef.setVersion(version); docRef.setLanguage(language); return docRef; @@ -111,258 +78,6 @@ public DocumentReference getDocumentReference() - /** - * Gets the value of the id property. - * - * @return possible object is {@link String } - */ - public String getId() - { - return id; - } - - - - /** - * Sets the value of the id property. - * - * @param value allowed object is {@link String } - */ - public void setId(String value) - { - this.id = value; - } - - /** - * Gets the value of the fullName property. * - * - * @return possible object is {@link String } - */ - public String getFullName() - { - return fullName; - } - - /** - * Sets the value of the fullName property. * - * - * @param value allowed object is {@link String } - */ - public void setFullName(String value) - { - this.fullName = value; - } - - /** - * Gets the value of the wiki property. - * - * @return possible object is {@link String } - */ - public String getWikiName() - { - return wikiName; - } - - /** - * Sets the value of the wiki property. - * - * @param value allowed object is {@link String } - */ - public void setWikiName(String value) - { - this.wikiName = value; - } - - /** - * Gets the value of the space property. - * - * @return possible object is {@link String } - */ - public String getSpaceName() - { - return spaceName; - } - - /** - * Sets the value of the space property. - * - * @param value allowed object is {@link String } - */ - public void setSpaceName(String value) - { - this.spaceName = value; - } - - // TODO:Consider refactor rename back to getName() ? confuse with name,fullName ? - /** - * get Page Name. - * @return the value of the name property in the Rest model "Page" element.. - */ - public String getPageName() - { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value allowed object is {@link String } - */ - public void setPageName(String name) - { - this.name = name; - } - - /** - * Gets the value of the title property. - * - * @return possible object is {@link String } - */ - public String getTitle() - { - return title; - } - - /** - * Sets the value of the title property. - * - * @param value allowed object is {@link String } - */ - public void setTitle(String value) - { - this.title = value; - } - - /** - * Gets the value of the parent property. - * - * @return possible object is {@link String } - */ - public String getParentFullName() - { - return parentFullName; - } - - /** - * Sets the value of the parent property. - * - * @param value allowed object is {@link String } - */ - public void setParentFullName(String parent) - { - this.parentFullName = parent; - } - - /** - * Gets the value of the parentId property. - * - * @return possible object is {@link String } - */ - public String getParentId() - { - return parentId; - } - - /** - * Sets the value of the parentId property. - * - * @param value allowed object is {@link String } - */ - public void setParentId(String value) - { - this.parentId = value; - } - - /** - * Gets the value of the xwikiRelativeUrl property. - * - * @return possible object is {@link String } - */ - public String getXwikiRelativeUrl() - { - return xwikiRelativeUrl; - } - - /** - * Sets the value of the xwikiRelativeUrl property. - * - * @param value allowed object is {@link String } - */ - public void setXwikiRelativeUrl(String value) - { - this.xwikiRelativeUrl = value; - } - - /** - * Gets the value of the xwikiAbsoluteUrl property. - * - * @return possible object is {@link String } - */ - public String getXwikiAbsoluteUrl() - { - return xwikiAbsoluteUrl; - } - - /** - * Sets the value of the xwikiAbsoluteUrl property. - * - * @param value allowed object is {@link String } - */ - public void setXwikiAbsoluteUrl(String value) - { - this.xwikiAbsoluteUrl = value; - } - - /** - * Gets the value of the translations property. - * - * @return possible object is {@link Translations } - */ - public List getTranslations() - { - return translations; - } - - /** - * Sets the value of the translations property. - * - * @param value allowed object is {@link Translations } - */ - public void setTranslations(List translations) - { - this.translations = translations; - } - - public String getDefalutTranslation() - { - return defalutTranslation; - } - - public void setDefalutTranslation(String defalutTranslation) - { - this.defalutTranslation = defalutTranslation; - } - - /** - * Gets the value of the syntax property. - * - * @return possible object is {@link String } - */ - public String getSyntax() - { - return syntax; - } - - /** - * Sets the value of the syntax property. - * - * @param value allowed object is {@link String } - */ - public void setSyntax(String value) - { - this.syntax = value; - } - public String getLanguage() { return language; diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPageSummary.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPageSummary.java new file mode 100644 index 0000000..3b7ac29 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPageSummary.java @@ -0,0 +1,290 @@ +package org.xwiki.android.xmodel.entity; + +import java.util.List; + +import org.xwiki.android.rest.reference.DocumentReference; +import org.xwiki.android.rest.reference.Link; + +public class XWikiPageSummary extends XWikiResource +{ + + protected List links; + protected String id; + protected String fullName; + protected String wikiName; + protected String spaceName; + protected String name; + protected String title; + protected String parentFullName; + protected String parentId; + protected String xwikiRelativeUrl; + protected String xwikiAbsoluteUrl; + protected List translations; + protected String defalutTranslation; + protected String syntax; + + public XWikiPageSummary() + { + super(); + } + + /** + * + * @return ref filled with wiki,space,name coordinates + */ + public DocumentReference getDocumentReference() + { + DocumentReference docRef = new DocumentReference(wikiName, spaceName, name); + return docRef; + } + + /** + * Gets the value of the id property. + * + * @return possible object is {@link String } + */ + public String getId() + { + return id; + } + + /** + * Sets the value of the id property. + * + * @param value allowed object is {@link String } + */ + public void setId(String value) + { + this.id = value; + } + + /** + * Gets the value of the fullName property. * + * + * @return possible object is {@link String } + */ + public String getFullName() + { + return fullName; + } + + /** + * Sets the value of the fullName property. * + * + * @param value allowed object is {@link String } + */ + public void setFullName(String value) + { + this.fullName = value; + } + + /** + * Gets the value of the wiki property. + * + * @return possible object is {@link String } + */ + public String getWikiName() + { + return wikiName; + } + + /** + * Sets the value of the wiki property. + * + * @param value allowed object is {@link String } + */ + public void setWikiName(String value) + { + this.wikiName = value; + } + + /** + * Gets the value of the space property. + * + * @return possible object is {@link String } + */ + public String getSpaceName() + { + return spaceName; + } + + /** + * Sets the value of the space property. + * + * @param value allowed object is {@link String } + */ + public void setSpaceName(String value) + { + this.spaceName = value; + } + + /** + * get Page Name. + * @return the value of the name property in the Rest model "Page" element.. + */ + public String getPageName() + { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value allowed object is {@link String } + */ + public void setPageName(String name) + { + this.name = name; + } + + /** + * Gets the value of the title property. + * + * @return possible object is {@link String } + */ + public String getTitle() + { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value allowed object is {@link String } + */ + public void setTitle(String value) + { + this.title = value; + } + + /** + * Gets the value of the parent property. + * + * @return possible object is {@link String } + */ + public String getParentFullName() + { + return parentFullName; + } + + /** + * Sets the value of the parent property. + * + * @param value allowed object is {@link String } + */ + public void setParentFullName(String parent) + { + this.parentFullName = parent; + } + + /** + * Gets the value of the parentId property. + * + * @return possible object is {@link String } + */ + public String getParentId() + { + return parentId; + } + + /** + * Sets the value of the parentId property. + * + * @param value allowed object is {@link String } + */ + public void setParentId(String value) + { + this.parentId = value; + } + + /** + * Gets the value of the xwikiRelativeUrl property. + * + * @return possible object is {@link String } + */ + public String getXwikiRelativeUrl() + { + return xwikiRelativeUrl; + } + + /** + * Sets the value of the xwikiRelativeUrl property. + * + * @param value allowed object is {@link String } + */ + public void setXwikiRelativeUrl(String value) + { + this.xwikiRelativeUrl = value; + } + + /** + * Gets the value of the xwikiAbsoluteUrl property. + * + * @return possible object is {@link String } + */ + public String getXwikiAbsoluteUrl() + { + return xwikiAbsoluteUrl; + } + + /** + * Sets the value of the xwikiAbsoluteUrl property. + * + * @param value allowed object is {@link String } + */ + public void setXwikiAbsoluteUrl(String value) + { + this.xwikiAbsoluteUrl = value; + } + + /** + * Gets the value of the translations property. + * + * @return possible object is {@link Translations } + */ + public List getTranslations() + { + return translations; + } + + /** + * Sets the value of the translations property. + * + * @param value allowed object is {@link Translations } + */ + public void setTranslations(List translations) + { + this.translations = translations; + } + + public String getDefalutTranslation() + { + return defalutTranslation; + } + + public void setDefalutTranslation(String defalutTranslation) + { + this.defalutTranslation = defalutTranslation; + } + + /** + * Gets the value of the syntax property. + * + * @return possible object is {@link String } + */ + public String getSyntax() + { + return syntax; + } + + /** + * Sets the value of the syntax property. + * + * @param value allowed object is {@link String } + */ + public void setSyntax(String value) + { + this.syntax = value; + } + +} 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 7dafb6a..4895612 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java @@ -313,7 +313,8 @@ public T putForResource(String uri, Resource res, Class */ HttpResponse post(String uri, String content) throws RestConnectionException, RestException { - + initialize(); + setCredentials(); HttpPost request = new HttpPost(); try { @@ -360,7 +361,8 @@ HttpResponse post(String uri, String content) throws RestConnectionException, Re */ public HttpResponse put(String uri, String content) throws RestConnectionException, RestException { - + initialize(); + setCredentials(); HttpPut request = new HttpPut(); try { @@ -433,7 +435,7 @@ public int checkLogin(String username, String password, String Url) throws RestC int responseCode = 0; Uri = "http://" + Url + "/xwiki/rest/"; - + try { requestUri = new URI(Uri); diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java index 2d93ee4..92eec3a 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java @@ -1076,7 +1076,7 @@ public PageResources pageOperations(String wikiName, String spaceName) public ObjectResources objectOperations(String wikiName, String spaceName, String pageName) { - ObjectResources ops= new ObjectResources(spaceName, wikiName, spaceName, pageName); + ObjectResources ops= new ObjectResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { ops.setAuthenticaion(username, password); } @@ -1085,7 +1085,7 @@ public ObjectResources objectOperations(String wikiName, String spaceName, Strin public CommentResources commentOperations(String wikiName, String spaceName, String pageName) { - CommentResources ops= new CommentResources(spaceName, wikiName, spaceName, pageName); + CommentResources ops= new CommentResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { ops.setAuthenticaion(username, password); } @@ -1094,7 +1094,7 @@ public CommentResources commentOperations(String wikiName, String spaceName, Str public TagResources tagOperations(String wikiName, String spaceName, String pageName) { - TagResources ops= new TagResources(spaceName, wikiName, spaceName, pageName); + TagResources ops= new TagResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { ops.setAuthenticaion(username, password); } @@ -1103,7 +1103,7 @@ public TagResources tagOperations(String wikiName, String spaceName, String page public AttachmentResources attachmentOperations(String wikiName, String spaceName, String pageName) { - AttachmentResources ops= new AttachmentResources(spaceName, wikiName, spaceName, pageName); + AttachmentResources ops= new AttachmentResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { ops.setAuthenticaion(username, password); } @@ -1112,7 +1112,7 @@ public AttachmentResources attachmentOperations(String wikiName, String spaceNam public HistoryResources historyOperations(String wikiName, String spaceName, String pageName) { - HistoryResources ops= new HistoryResources(spaceName, wikiName, spaceName, pageName); + HistoryResources ops= new HistoryResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { ops.setAuthenticaion(username, password); } 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 fa8a127..f1830ac 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 @@ -88,7 +88,7 @@ public void setUp() throws Exception // setup preconditions on serverside //TODO: change as you add more methods and you need to keep the tempTestPage undeleted after a test. api.deletePage(wikiName, spaceName, pageName); - if (count == 8) {//make attachment file + if (count == 9) {//make attachment file Application sys = XWikiApplicationContext.getInstance(); FileOutputStream fos = sys.openFileOutput(attachmentName, Context.MODE_WORLD_READABLE); PrintWriter writer = new PrintWriter(fos); @@ -342,6 +342,7 @@ public void testCreate_07_WithCmnts_SequenceCheck2() throws Throwable public void testCreate_08_WithCmnts_wieredReplyTos() throws Throwable { + boolean success=false; c1 = new Comment("0"); c2 = new Comment("1"); c3 = new Comment("2"); @@ -349,28 +350,23 @@ public void testCreate_08_WithCmnts_wieredReplyTos() throws Throwable c4 = new Comment("3"); c4.setId(3); + try{ + c2.addReplyComment(c1); c4.addReplyComment(c3); doc.addComment(c1, true); doc.setComment(c3); doc.setComment(c4); + }catch(IllegalStateException e){ + success=true; + } rao.create(doc); - boolean success = api.existsPage(wikiName, spaceName, pageName); + success = api.existsPage(wikiName, spaceName, pageName);// any way the page should get created. You could not add the last 2 comments because you replied to a comment that is added after this. assertTrue(success); - if (success) { - Comments cmnts = api.getPageComments(wikiName, spaceName, pageName); - List clst = cmnts.comments; - assertEquals(4, clst.size()); - int replyto = clst.get(2).replyTo; - assertEquals(1, replyto); - replyto=clst.get(3).replyTo; - assertEquals(0, replyto); - - assertEquals("6", clst.get(3).text); - } + } diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java index a20aee3..edbe8f4 100644 --- a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java +++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java @@ -5,6 +5,7 @@ import org.xwiki.android.core.test.properties.TestConstants; import org.xwiki.android.resources.Attribute; +import org.xwiki.android.resources.Comments; import org.xwiki.android.resources.Objects; import org.xwiki.android.resources.Page; import org.xwiki.android.resources.Object; @@ -60,11 +61,13 @@ protected void setUp() throws Exception doc.setTitle(pageName); // setup external fixture + //add page Page page = new Page(); page.setName(pageName); page.setSpace(spaceName); page.setWiki(wikiName); api.addPage(wikiName, spaceName, pageName, page); + //add object blogpost 0 Object o = new Object(); o.setClassName("Blog.BlogPostClass"); Property content = new Property(); @@ -81,6 +84,10 @@ protected void setUp() throws Exception published.setValue("1"); o.withProperties(content, category, published); api.addObject(wikiName, spaceName, pageName, o); + //add comment + org.xwiki.android.resources.Comment comment=new org.xwiki.android.resources.Comment(); + comment.setText("0"); + api.addPageComment(wikiName, spaceName, pageName, comment); } @@ -133,8 +140,37 @@ public void testUpdate_02_withComments() throws Throwable assertTrue(numCmntsAfter == numCmntsBefore+1); } - public void testUpdate_03_withComments(){ + public void testUpdate_03_withComments() throws Throwable{ + //get state of external fixture page. + int numCmntsBefore=0; + List comments = api.getPageComments(wikiName, spaceName, pageName).comments; + if(comments!=null){ + numCmntsBefore=comments.size(); + } + + //tested logic + Comment cmnt = new Comment("hi comment"); + String rtBfr="hi reply"; + Comment cmnt2= new Comment(rtBfr); + cmnt2.replyTo(cmnt); + + doc.addComment(cmnt,true); //add the prnt cmnt with cascade to replies. + + rao.update(doc); + + //verify + Comments comments2 = api.getPageComments(wikiName, spaceName, pageName); + int numCmntsAfter =api.getPageComments(wikiName, spaceName, pageName).comments.size(); + assertTrue(numCmntsAfter == numCmntsBefore+2); // make sure 2 new were added. + + List lst = comments2.getComments(); + org.xwiki.android.resources.Comment rply=lst.get(lst.size()-1);//it should get added last + int replyTo=rply.replyTo; + String rtAftr=rply.text; + + + assertEquals(rtBfr, rtAftr); } }