From 5c67bdd9738c7bcae9e454e72309a40a764ce2f8 Mon Sep 17 00:00:00 2001 From: sasinda Date: Thu, 23 Aug 2012 21:26:01 +0530 Subject: [PATCH] wrote the how tos --- .../android/rest/ral/RESTfulManager.java | 13 +- .../android/rest/ral/XmlRESTFulManager.java | 8 ++ .../rest/ral/algo/DocUpdateStrategy.java | 54 +++++--- .../xwiki/android/xmodel/entity/Document.java | 7 +- .../android/xmodel/entity/XWikiPage.java | 18 ++- .../android/xmodel/entity/XWikiResource.java | 4 +- .../android/howtos/_00_SampleActivity.java | 2 + .../android/howtos/_01_CreateDocument.java | 13 +- .../howtos/_02_AdvancedObjectEditing.java | 4 +- .../android/howtos/_03_SaveDocument.java | 17 ++- .../android/howtos/_04_SaveDocumentAdv.java | 6 +- .../howtos/_05_ListAndLoadDocuments.java | 9 +- .../org/xwiki/android/howtos/filestore/README | 2 + .../android/howtos/filestore/_00_Save.java | 22 ++++ .../howtos/filestore/_01_ListAndLoad.java | 23 ++++ .../src/org/xwiki/android/howtos/ral/README | 3 + .../xwiki/android/howtos/ral/_00_Create.java | 85 ++++++++++++ .../android/howtos/ral/_10_Retreive.java | 40 ++++++ .../xwiki/android/howtos/ral/_20_Update.java | 73 +++++++++++ .../xwiki/android/howtos/ral/_30_Delete.java | 35 +++++ .../entity/test/DocumentModelStateTest.java | 2 +- .../xwiki/android/tests/TestConstants.java | 124 ++++++++---------- 22 files changed, 448 insertions(+), 116 deletions(-) create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/README create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_00_Save.java create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_01_ListAndLoad.java create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/ral/README create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_00_Create.java create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_10_Retreive.java create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_20_Update.java create mode 100644 xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_30_Delete.java diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java index c7f1424..aa3aeb7 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java @@ -5,12 +5,15 @@ public interface RESTfulManager { + /** + * misnormer. We will be giving the save Rao instance. + * Use getDocumentRao() which is named correctly; + * @return + */ + DocumentRao newDocumentRao(); - - SpaceRao newSpaceRao(); - - WikiRao newWikiRao(); - + DocumentRao getDocumentRao(); + RestClient getRestClient(); @Deprecated diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java index 35ab8cf..ee8c7e5 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java @@ -37,6 +37,12 @@ public DocumentRao newDocumentRao() { return new XmlDocumentRao(serverUrl, username, password); } + + @Override + public DocumentRao getDocumentRao() + { + return new XmlDocumentRao(serverUrl, username, password);//TODO: cache this rao. Dont make new every time. Make thread safe. + } public SpaceRao newSpaceRao() { @@ -64,6 +70,8 @@ public XWikiRestConnector getRestConnector() return new XWikiRestConnector(serverUrl, username, password); } + + diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java index 50e3f0a..928766c 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java @@ -6,6 +6,7 @@ import org.xwiki.android.resources.Comment; import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Page; import org.xwiki.android.resources.Tags; import org.xwiki.android.rest.RestConnectionException; import org.xwiki.android.rest.RestException; @@ -15,6 +16,7 @@ import org.xwiki.android.rest.transformation.DocLaunchPadForXML; import org.xwiki.android.rest.transformation.DocumentDismantler_XML; import org.xwiki.android.rest.transformation.RestModelTransformer; +import org.xwiki.android.rest.transformation.XModelTranslator_XML; import org.xwiki.android.xmodel.entity.Attachment; import org.xwiki.android.xmodel.entity.Document; @@ -46,6 +48,16 @@ public Document update(Document d) throws RestConnectionException, RaoException String pageName = d.getPageName(); DocLaunchPadForXML pad = dismantler.convertDocument(d); +//page + if (d.isEdited()) { + Page p=pad.getPage(); + try { + rpc.addPage(wikiName, spaceName, pageName, p);// add page does the update. + } catch (RestException e1) { + throw new RaoException("Error while updating content of the Page Element"); + } + } + Set> entrySet = pad.getEditedObjects().entrySet(); // edited objs for (Entry e : entrySet) { @@ -58,7 +70,9 @@ public Document update(Document d) throws RestConnectionException, RaoException rpc.updateObject(wikiName, spaceName, pageName, objectClassname, objectNumber, ores); numEdObj++; // after the api op. If exception happens no ++ happens. } catch (RestException e1) { - throw new RaoException("Object may not exist in actual doc. Also see wether you are updating non existing document. Because Update does not check for doc existence.", e1); + throw new RaoException( + "Object may not exist in actual doc. Also see wether you are updating non existing document. Because Update does not check for doc existence.", + e1); // TODO } } @@ -72,28 +86,32 @@ public Document update(Document d) throws RestConnectionException, RaoException numDelObj++; } catch (RestException e1) { // TODO Auto-generated catch block - throw new RaoException("?. By the way, delete op should work even if there is no actual object in the server to delete.",e1); + throw new RaoException( + "?. By the way, delete op should work even if there is no actual object in the server to delete.", + e1); } } // new comments - //TODO: this algo needs improvements if a large num of comments is added. + // TODO: this algo needs improvements if a large num of comments is added. List newComments = pad.getNewComments(); List editedComments = pad.getEditedComments(); - for (Comment comment : newComments) {//TODO: Update op cannot achieve replyto s, unless rest layer is upgraded. + for (Comment comment : newComments) {// TODO: Update op cannot achieve replyto s, unless rest layer is upgraded. try { - Comment c = rpc.commentOperations(wikiName, spaceName, pageName).addPageCommentForResult(comment); - for(Comment rply:newComments){ - if(rply.replyTo!=null && rply.replyTo==comment.replyTo){//cause both cmnts id,replyTo can be null. - rply.setReplyTo(comment.id); - } - } - for(Comment rply:editedComments){ - if(rply.replyTo!=null && rply.replyTo==comment.replyTo){//cause both cmnts id,replyTo can be null. - rply.setReplyTo(comment.id); - } - } - numNwCmnt++; + Comment c = rpc.commentOperations(wikiName, spaceName, pageName).addPageCommentForResult(comment); + for (Comment rply : newComments) { + if (rply.replyTo != null && rply.replyTo == comment.replyTo) {// cause both cmnts id,replyTo can be + // null. + rply.setReplyTo(comment.id); + } + } + for (Comment rply : editedComments) { + if (rply.replyTo != null && rply.replyTo == comment.replyTo) {// cause both cmnts id,replyTo can be + // null. + rply.setReplyTo(comment.id); + } + } + numNwCmnt++; } catch (RestException e1) { // TODO Auto-generated catch block throw new RaoException(e1); @@ -103,9 +121,9 @@ public Document update(Document d) throws RestConnectionException, RaoException // edited comments // need to conver to objs. Direct editing is not currently supported in // xwiki restful api. - RestModelTransformer transformer =new RestModelTransformer(); + RestModelTransformer transformer = new RestModelTransformer(); for (Comment cmnt : pad.getEditedComments()) { - Object cmntObj=transformer.toObject(cmnt); + Object cmntObj = transformer.toObject(cmnt); String objectClassname = cmntObj.getClassName(); int objectNumber = cmntObj.getNumber(); try { 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 b4604ff..e9a512f 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 @@ -211,10 +211,11 @@ public String setObject(XSimpleObject object) */ public String addObject(XSimpleObject obj) { - String key = obj.getClassName() + "/new/" + _addNum++; - obj.setNew(true); + String key = obj.getClassName() + "/new/" + _addNum++; objects.put(key, obj); - newObjects.add(obj); + if(obj.isNew()){ + newObjects.add(obj); + } return key; } 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 4fa91d1..c05d734 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 @@ -30,8 +30,7 @@ public abstract class XWikiPage extends XWikiPageSummary protected String content; - - + /** @@ -244,6 +243,21 @@ public String getContent() public void setContent(String value) { this.content = value; + edited=true; + } + + + + /** + * if set to false update operations will not update the content of this page. + * @param pageEdited + */ + @Override + public void setEdited(boolean pageEdited) + { + this.edited = pageEdited; } + + } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java index f186d87..105a1d4 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java @@ -10,9 +10,9 @@ public class XWikiResource implements Serializable List links; - private boolean isNew=true; + protected boolean isNew=true; - private boolean edited=true; + protected boolean edited=true; public void setNew(boolean val) { diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_00_SampleActivity.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_00_SampleActivity.java index 0ef8acc..6fc29f0 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_00_SampleActivity.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_00_SampleActivity.java @@ -1,5 +1,7 @@ package org.xwiki.android.howtos; +import org.xwiki.android.howtos.R; + import android.app.Activity; import android.os.Bundle; diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_01_CreateDocument.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_01_CreateDocument.java index 69aa686..801b0d4 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_01_CreateDocument.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_01_CreateDocument.java @@ -1,12 +1,13 @@ package org.xwiki.android.howtos; -import org.xwiki.android.blog.xobj.XBlogPost; -import org.xwiki.android.ral.RaoException; +import org.xwiki.android.rest.ral.RaoException; +import org.xwiki.android.svc.xmodel.DocumentRemoteSvcCallbacks; +import org.xwiki.android.svc.xmodel.DocumentRemoteSvcs; +import org.xwiki.android.svc.xmodel.DocumentSvcImpl; +import org.xwiki.android.xmodel.blog.XBlogPost; import org.xwiki.android.xmodel.entity.Document; -import org.xwiki.android.xmodel.entity.Document; -import org.xwiki.android.xmodel.svc.DocumentRemoteSvcCallbacks; -import org.xwiki.android.xmodel.svc.DocumentRemoteSvcs; -import org.xwiki.android.xmodel.svc.DocumentSvcImpl; + + public class _01_CreateDocument diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_02_AdvancedObjectEditing.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_02_AdvancedObjectEditing.java index 0b65e17..9c4097e 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_02_AdvancedObjectEditing.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_02_AdvancedObjectEditing.java @@ -1,6 +1,6 @@ package org.xwiki.android.howtos; -import org.xwiki.android.blog.xobj.XBlogPost; +import org.xwiki.android.xmodel.blog.XBlogPost; import org.xwiki.android.xmodel.entity.Document; import org.xwiki.android.xmodel.xobjects.XBooleanProperty; @@ -20,7 +20,7 @@ public void demo(){ //change an attribute of the property. hiddenP.setPrettyName("Hidden pretty name"); - //Since a reference is passed, you do not have to blgpstObj.setpHidden(hiddenP) to commit the effects. + //Since a reference is passed, you do not have to do a blgpstObj.setpHidden(hiddenP) to commit the effects. } } diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_03_SaveDocument.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_03_SaveDocument.java index 85cb743..6ddecd9 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_03_SaveDocument.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_03_SaveDocument.java @@ -1,8 +1,10 @@ package org.xwiki.android.howtos; +import org.xwiki.android.svc.xmodel.DocumentLocalSvcs; +import org.xwiki.android.svc.xmodel.DocumentSvcImpl; +import org.xwiki.android.xmodel.blog.XBlogPost; +import org.xwiki.android.xmodel.entity.Comment; import org.xwiki.android.xmodel.entity.Document; -import org.xwiki.android.xmodel.svc.DocumentLocalSvcs; -import org.xwiki.android.xmodel.svc.DocumentSvcImpl; public class _03_SaveDocument { @@ -10,14 +12,21 @@ public void demo(){ Document mydoc=new Document("wikiName", "spaceName", "pageName");//create empty document // ... edit mydoc + mydoc.addObject(new XBlogPost()); + mydoc.setContent("edited page content"); + mydoc.addComment(new Comment("hi")); //lets save it! DocumentLocalSvcs docsvcl=new DocumentSvcImpl(); - docsvcl.save(mydoc, "My tag to identify this easily", null);//docsvcl.save(doc, tag, clbk). we pass null for clbk - // since we do not want to know wether the doc was sucessfully + docsvcl.save(mydoc, "My short TAG to identify this easily", null);//docsvcl.save(doc, tag, clbk). we pass null for clbk + // since we do not want to know whether the doc was sucessfully // saved or not. + /* + * The current implementatation supports tagging to identify documents saved in the file store. + * The key for the document is automatically generated as a combination of wiki:space:page:version. + */ } } diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_04_SaveDocumentAdv.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_04_SaveDocumentAdv.java index 57514fa..f0743a3 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_04_SaveDocumentAdv.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_04_SaveDocumentAdv.java @@ -2,10 +2,10 @@ import java.io.File; +import org.xwiki.android.svc.xmodel.DocumentLocalSvcCallbacks; +import org.xwiki.android.svc.xmodel.DocumentLocalSvcs; +import org.xwiki.android.svc.xmodel.DocumentSvcImpl; import org.xwiki.android.xmodel.entity.Document; -import org.xwiki.android.xmodel.svc.DocumentLocalSvcCallbacks; -import org.xwiki.android.xmodel.svc.DocumentLocalSvcs; -import org.xwiki.android.xmodel.svc.DocumentSvcImpl; public class _04_SaveDocumentAdv { diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/_05_ListAndLoadDocuments.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/_05_ListAndLoadDocuments.java index ce5377b..f485e97 100644 --- a/xwiki-android-howtos/src/org/xwiki/android/howtos/_05_ListAndLoadDocuments.java +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/_05_ListAndLoadDocuments.java @@ -3,11 +3,11 @@ import java.util.List; import java.util.Map; -import org.xwiki.android.fileStore.FSDocumentReference; +import org.xwiki.android.data.fileStore.FSDocumentReference; +import org.xwiki.android.svc.xmodel.DocumentLocalSvcCallbacks; +import org.xwiki.android.svc.xmodel.DocumentLocalSvcs; +import org.xwiki.android.svc.xmodel.DocumentSvcImpl; import org.xwiki.android.xmodel.entity.Document; -import org.xwiki.android.xmodel.svc.DocumentLocalSvcCallbacks; -import org.xwiki.android.xmodel.svc.DocumentLocalSvcs; -import org.xwiki.android.xmodel.svc.DocumentSvcImpl; import android.app.Activity; @@ -17,6 +17,7 @@ public class _05_ListAndLoadDocuments extends Activity FSDocumentReference loadMe; DocumentLocalSvcs ds; + @Override protected void onCreate(android.os.Bundle savedInstanceState) { diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/README b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/README new file mode 100644 index 0000000..ad336f8 --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/README @@ -0,0 +1,2 @@ +These how tos explain how to directly use the File Store. +(DocumentSvc in svc.xmodel package provide an asynchronous layer with call backs to call these same methods.) diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_00_Save.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_00_Save.java new file mode 100644 index 0000000..f6a2edc --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_00_Save.java @@ -0,0 +1,22 @@ +package org.xwiki.android.howtos.filestore; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.data.fileStore.DocumentFao; +import org.xwiki.android.data.fileStore.FSDocumentReference; +import org.xwiki.android.data.fileStore.FileStoreManager; +import org.xwiki.android.xmodel.entity.Document; + +public class _00_Save +{ + void save() + { + XWikiApplicationContext ctx = XWikiApplicationContext.getInstance(); + FileStoreManager fm = ctx.getFileStoreManager(); + DocumentFao fao = fm.getDocumentFao(); + + + Document doc=new Document("WikiName", "spaceName", "pageName"); + FSDocumentReference ref = fao.save(doc, "sas"); + } + +} diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_01_ListAndLoad.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_01_ListAndLoad.java new file mode 100644 index 0000000..cbfb174 --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/filestore/_01_ListAndLoad.java @@ -0,0 +1,23 @@ +package org.xwiki.android.howtos.filestore; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.data.fileStore.DocumentFao; +import org.xwiki.android.data.fileStore.FSDocumentReference; +import org.xwiki.android.data.fileStore.FileStoreManager; +import org.xwiki.android.xmodel.entity.Document; + +public class _01_ListAndLoad +{ + void load(){ + XWikiApplicationContext ctx = XWikiApplicationContext.getInstance(); + FileStoreManager fm = ctx.getFileStoreManager(); + DocumentFao fao = fm.getDocumentFao(); + + + + FSDocumentReference ref=fao.listByTag("my File Store tag. ").get(0); //file store supports tagging to search documents. + //listBy... returns a list of references; + Document doc=fao.load(ref);//ok we loaded it. + + } +} diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/README b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/README new file mode 100644 index 0000000..b0b8698 --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/README @@ -0,0 +1,3 @@ +These how tos explain how to directly use the RAL layer. +All the operations here are longrunning blocking operations. +So it is adviced to use the svc.xmodel package's DocumentSvc classes to do these asynchronically. \ No newline at end of file diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_00_Create.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_00_Create.java new file mode 100644 index 0000000..d797368 --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_00_Create.java @@ -0,0 +1,85 @@ +package org.xwiki.android.howtos.ral; + + +import java.io.File; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.ral.DocumentRao; +import org.xwiki.android.rest.ral.RESTfulManager; +import org.xwiki.android.rest.ral.RaoException; +import org.xwiki.android.xmodel.blog.XBlogPost; +import org.xwiki.android.xmodel.entity.Attachment; +import org.xwiki.android.xmodel.entity.Comment; +import org.xwiki.android.xmodel.entity.Document; +import org.xwiki.android.xmodel.entity.Tag; + +import android.app.Activity; + +public class _00_Create extends Activity +{ + + public void create(){ + Document doc=new Document("WikiName", "spaceName", "pageName"); + //make 2 Blog.BlogPostClass objects + XBlogPost blg1=new XBlogPost(); + XBlogPost blg2=new XBlogPost(); + + //lets add them to the doc. + doc.addObject(blg1); + //We need blg2 to exactly take the id Blog.BlogPostClass/0 in the created doc. + blg2.setNumber(0);/* set the number to the one you want. If you put a number like 3 this will obviously get created as + the Blog.BlogPostClass/1 object as there are only 2 BlogPost objects.*/ + // note the naming convention blog.XBlogPost --> Blog.BlogPostClass : we remove the suffix "Class" and add a prefix "X" to the + // corresponding serverside object type when in the android model. + doc.setObject(blg2); + + + + //make a few comments. + Comment c0=new Comment("hi"); + Comment c1=new Comment("reply to hi"); + Comment c2=new Comment("another reply"); + + c1.replyTo(c0); //let c1 comment reply to c0 + c2.replyTo(c1); + boolean cascade=true; + doc.addComment(c0, cascade); //we add c0 and instruct to add c0 s children/replies to the doc as well + + // add a few tags to the doc. + Tag t=new Tag("tag1"); + Tag t2=new Tag("tag2"); + + doc.addTag(t); + doc.addTag(t2); + + //lets add an attachement + + File f=new File("/path to my attachment file"); + Attachment a=new Attachment("Attachment name", f); + + doc.addAttachment(a); + + + //lets create this doc in the server; + XWikiApplicationContext ctx=(XWikiApplicationContext)getApplication(); + + RESTfulManager rm=ctx.newRESTfulManager(); + DocumentRao rao=rm.getDocumentRao(); + + //we then simply call the create method. + + try { + rao.create(doc); + } catch (RestConnectionException e) { + //if IO/connection failure + } catch (RaoException e) { + // thrown when the document is already created on the server. If the space does not exist etc. + } + + + + + } + +} diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_10_Retreive.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_10_Retreive.java new file mode 100644 index 0000000..60a255f --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_10_Retreive.java @@ -0,0 +1,40 @@ +package org.xwiki.android.howtos.ral; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.ral.DocumentRao; +import org.xwiki.android.rest.ral.RESTfulManager; +import org.xwiki.android.rest.ral.RaoException; +import org.xwiki.android.rest.reference.DocumentReference; +import org.xwiki.android.xmodel.entity.Document; + +import android.app.Activity; + +public class _10_Retreive extends Activity +{ + public void retreive() + { + + // init code for getting a rao. + XWikiApplicationContext ctx = (XWikiApplicationContext) getApplication(); + RESTfulManager rm = ctx.newRESTfulManager(); + DocumentRao rao = rm.getDocumentRao(); + + // we then simply call the retreive method. + Document retDoc; + try { + Document doc=new Document("WikiName", "spaceName", "pageName"); + retDoc=rao.retreive(doc); + /* + * following is also valid + */ + DocumentReference docref=new DocumentReference("WikiName", "spaceName", "pageName");//creating a ref is faster than a doc. + retDoc=rao.retreive(docref); + } catch (RestConnectionException e) { + // if IO/connection failure + } catch (RaoException e) { + // thrown when non existing. + } + + } +} diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_20_Update.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_20_Update.java new file mode 100644 index 0000000..d1c563a --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_20_Update.java @@ -0,0 +1,73 @@ +package org.xwiki.android.howtos.ral; + +import java.io.File; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.ral.DocumentRao; +import org.xwiki.android.rest.ral.RESTfulManager; +import org.xwiki.android.rest.ral.RaoException; +import org.xwiki.android.xmodel.blog.XBlogPost; +import org.xwiki.android.xmodel.entity.Attachment; +import org.xwiki.android.xmodel.entity.Comment; +import org.xwiki.android.xmodel.entity.Document; +import org.xwiki.android.xmodel.entity.Tag; + +import android.app.Activity; + +public class _20_Update extends Activity +{ + + public void update(){ + + Document doc=new Document("WikiName", "spaceName", "pageName"); + //make 2 Blog.BlogPostClass objects + XBlogPost blg1=new XBlogPost(); + XBlogPost blg2=new XBlogPost(); + + // add a new object in update op + doc.addObject(blg1); + + blg2.setNumber(0);//edit the Blog.BlogPostClass/0 + doc.setObject(blg2); + + + + //edit comment 0 + Comment c0=new Comment("comments/0 edited"); + c0.setId(0); + doc.setComment(c0); + + //add a new comment + Comment c1=new Comment("new one"); + //c1.setId(7); //oops this will be ignored if you do an addComment + doc.addComment(c1); + + //lets delete another comment + doc.deleteComment(2); //delete comment with id 2. + + //lets replace an attachement + + File f=new File("/path to my attachment file"); + Attachment a=new Attachment("existing @ name", f); + doc.setAttachment(a); + + + //lets update this doc in the server; + XWikiApplicationContext ctx=(XWikiApplicationContext)getApplication(); + RESTfulManager rm=ctx.newRESTfulManager(); + DocumentRao rao=rm.getDocumentRao(); + + //we then simply call the update method. + + try { + rao.update(doc); + } catch (RestConnectionException e) { + //if IO/connection failure + } catch (RaoException e) { + // thrown when the document is already created on the server. If the space does not exist etc. + } + + } + +} diff --git a/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_30_Delete.java b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_30_Delete.java new file mode 100644 index 0000000..56fca7e --- /dev/null +++ b/xwiki-android-howtos/src/org/xwiki/android/howtos/ral/_30_Delete.java @@ -0,0 +1,35 @@ +package org.xwiki.android.howtos.ral; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.ral.DocumentRao; +import org.xwiki.android.rest.ral.RESTfulManager; +import org.xwiki.android.rest.ral.RaoException; +import org.xwiki.android.rest.reference.DocumentReference; +import org.xwiki.android.xmodel.entity.Document; + +import android.app.Activity; + +public class _30_Delete extends Activity +{ + + public void delete() + { + + // init code for getting a rao. + XWikiApplicationContext ctx = (XWikiApplicationContext) getApplication(); + RESTfulManager rm = ctx.newRESTfulManager(); + DocumentRao rao = rm.getDocumentRao(); + + + try { + DocumentReference dref=new DocumentReference("WikiName", "spaceName", "pageName"); + rao.delete(dref); + } catch (RestConnectionException e) { + // if IO/connection failure + } catch (RaoException e) { + // thrown when non existing. + } + + } +} diff --git a/xwiki-android-test-core/src/org/xwiki/android/xmodel/entity/test/DocumentModelStateTest.java b/xwiki-android-test-core/src/org/xwiki/android/xmodel/entity/test/DocumentModelStateTest.java index 7365506..49faf1b 100644 --- a/xwiki-android-test-core/src/org/xwiki/android/xmodel/entity/test/DocumentModelStateTest.java +++ b/xwiki-android-test-core/src/org/xwiki/android/xmodel/entity/test/DocumentModelStateTest.java @@ -29,7 +29,7 @@ public void testAddSetStateManipulation(){ xblgpst1.setEdited(false); doc.setObject(xblgpst1); xblgpst2.setNew(false); - doc.addObject(xblgpst1); + doc.addObject(xblgpst2); c1.setId(0); c1.setEdited(false); diff --git a/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java b/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java index 0e99e07..9e00002 100644 --- a/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java +++ b/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java @@ -1,66 +1,58 @@ -package org.xwiki.android.tests; - -/** - * Environment variables for tests. - * How to setup external text setup. - */ - -public class TestConstants { - - public static final String DEFAULT_EXECUTION_DIRECTORY; //see static block to change default. - public static final int SERVER_INDEX; - public static final String HOST = "10.0.2.2"; // do not put local host as this is run on AVD. It'll call AVDs nic. - public static final int PORT = 8080; //actual port is port+server_index - public static final String SERVER_URL; //SERVER NAME set in static block. - public static final String USERNAME = "Admin"; - public static final String PASSWORD = "admin"; - - //external test fixture. - - public static final String WIKI_NAME = "xwiki"; - - public static final String SPACE_NAME = "Blog"; - - public static final String PAGE_NAME = "test2"; - - public static final String PAGE_VERSION = "1.1"; - - public static final String COMMENT_ID = "0"; - public static final String COMMENT_TEXT = "hi"; - public static final String COMMENT_REPLY_ID = "1"; - public static final int COMMENT_REPLY_REPLY_TO = 0; - public static final String COMMENT_PAGE_HISTORY_VERSION="5.1"; - public static final String COMMENT_REPLY_TEXT = "huy"; - - - public static final String LANGUAGE = "fr"; - public static final String TRANSLATION_VERSION="2.1"; - - public static final String CLASS_NAME = "Blog.BlogPostClass"; - public static final String OBJECT_NUMBER = "0"; - public static final String OBJECT_PROPERTY_NAME = "content"; - public static final String OBJECT_PROPERTY_VALUE = "test blog content"; - - public static final String SEARCH_KEWORD = "test"; - - public static final String TAG_WORD = "testTag"; - - public static final String ATTACHMENT_NAME = "a.png"; - public static final String ATTACHMENT_DEL_NAME = "del.png"; - public static final String ATTACHMENT_PATH = "./"; - public static final String ATTACHMENT_VERSION = "1.1"; - public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1"; - - static { - SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0")); - DEFAULT_EXECUTION_DIRECTORY = System.getProperty("xwikiExecutionDirectory", "C:\\Users\\admin\\Desktop\\xwiki-enterprise-jetty"); - SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX); - if(System.getProperty("xwikiExecutionDirectory"+SERVER_INDEX)==null){ - System.out.println("xwiki execution dir:"+ DEFAULT_EXECUTION_DIRECTORY +" index: "+SERVER_INDEX + " server Url: "+SERVER_URL); - }else{ - System.out.println("xwiki execution dir:"+ System.getProperty("xwikiExecutionDirectory"+SERVER_INDEX) +" index: "+SERVER_INDEX + " server Url: "+SERVER_URL); - } - System.setProperty("xwikiExecutionDirectory", DEFAULT_EXECUTION_DIRECTORY);//set it up to default val above, if not set by pom.else rewrite. - } - -} +package org.xwiki.android.tests; + +public class TestConstants +{ + public static final int SERVER_INDEX; + public static final String HOST = "10.0.2.2"; + public static final int PORT = 8080; // actual port is port+server_index + public static final String SCHEME = "http://"; + public static final String SERVER_URL; // SERVER NAME set in static block. + public static final String USERNAME = "Admin"; + public static final String PASSWORD = "admin"; + + // external test fixture. + + public static final String WIKI_NAME = "xwiki"; + public static final String SPACE_NAME = "Blog"; + public static final String PAGE_NAME = "test2"; + public static final String PAGE_VERSION = "1.1"; + public static final String CREATE_PAGE_NAME = "CreatePage"; // used for create method tests. because page needss to + // be deleted for creation test 01 will create + // CreatePage-1 + public static final String UPDATE_PAGE_NAME = "UpdatePage"; + + public static final String COMMENT_ID = "0"; + public static final String COMMENT_TEXT = "hi"; + public static final String COMMENT_REPLY_ID = "1"; + public static final int COMMENT_REPLY_REPLY_TO = 0; + public static final String COMMENT_PAGE_HISTORY_VERSION = "5.1"; + public static final String COMMENT_REPLY_TEXT = "huy"; + + public static final String LANGUAGE = "fr"; + public static final String TRANSLATION_VERSION = "2.1"; + + public static final String OBJECT_CLASS_NAME_1 = "Blog.BlogPostClass"; + public static final String OBJECT_CLASS_NAME_2 = "Blog.BlogCategoryClass"; + public static final int OBJECT_NUMBER = 0; + public static final String OBJECT_PROPERTY_NAME = "content"; + public static final String OBJECT_PROPERTY_VALUE = "test blog content"; + + public static final String SEARCH_KEWORD = "test"; + + public static final String TAG_WORD = "testTag"; + + public static final String ATTACHMENT_NAME = "a.png"; + public static final String ATTACHMENT_DEL_NAME = "del.png"; + public static final String ATTACHMENT_PATH = "./"; + public static final String ATTACHMENT_VERSION = "1.1"; + public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1"; + + static { + SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0")); + SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX); + if (HOST.contains("localhost")) { + System.err.println("localhost on android means devices interface card!!!"); + } + } + +}