Skip to content

Commit

Permalink
wrote the how tos
Browse files Browse the repository at this point in the history
  • Loading branch information
sasinda committed Aug 23, 2012
1 parent 4799dbe commit 5c67bdd
Show file tree
Hide file tree
Showing 22 changed files with 448 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -64,6 +70,8 @@ public XWikiRestConnector getRestConnector()
return new XWikiRestConnector(serverUrl, username, password);
}






Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Entry<String, Object>> entrySet = pad.getEditedObjects().entrySet();
// edited objs
for (Entry<String, Object> e : entrySet) {
Expand All @@ -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
}
}
Expand All @@ -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<Comment> newComments = pad.getNewComments();
List<Comment> 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);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public abstract class XWikiPage extends XWikiPageSummary

protected String content;






/**
Expand Down Expand Up @@ -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;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class XWikiResource implements Serializable

List<Link> links;

private boolean isNew=true;
protected boolean isNew=true;

private boolean edited=true;
protected boolean edited=true;

public void setNew(boolean val)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.xwiki.android.howtos;

import org.xwiki.android.howtos.R;

import android.app.Activity;
import android.os.Bundle;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.

}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
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
{
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.
*/

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,6 +17,7 @@ public class _05_ListAndLoadDocuments extends Activity
FSDocumentReference loadMe;
DocumentLocalSvcs ds;

@Override
protected void onCreate(android.os.Bundle savedInstanceState)
{

Expand Down
Original file line number Diff line number Diff line change
@@ -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.)
Original file line number Diff line number Diff line change
@@ -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");
}

}
Original file line number Diff line number Diff line change
@@ -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.

}
}
3 changes: 3 additions & 0 deletions xwiki-android-howtos/src/org/xwiki/android/howtos/ral/README
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 5c67bdd

Please sign in to comment.