Dear experts,
I need you advise.
Objective :
Create a complex document (using compund type) and generate the api-manual with it.
HIPPO CMS can do the following:
- Create the complex data structure via the CMS interface (compound type and document type)
- Generate the java files via Bean Writer
- Generate generic API even for this compund type.
BUT HIPPO CMS cannot generate the api-manual for such complex type.
This is how I did it.
-
Create a component type call Orang (Person in Malay) and in it nama (name) in cms
-
Create a document type call OrangDT which content only 1 Orang type in cms
-
Create a document instance of OrangDT can call it cubaorang (tryPeople in Malay) in cms
-
Generate all the Java files with Bean Writer in essential
-
Generate the generic api and also manual api.in essential so that I can get to use this URL
(http://localhost:8080/site/api-manual/OrangDT/) -
In the cms/console you should see something like this YAML format,
(/content/documents/xxxxxx/cubaorang) -
In the orangDTResource.java (created by beanwriter) I added the following
@GET
@Path("/test")
public String test(@Context HttpServletRequest request)throws Exception{
Session session = null;
StringBuilder result = new StringBuilder();
try {
HippoRepository repository = HippoRepositoryFactory.getHippoRepository("vm://");
session = repository.login("admin","admin".toCharArray());
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery("SELECT * FROM xxxxxx:OrangDT WHERE hippostd:stateSummary='live' AND hippostd:state='published'",Query.SQL);
QueryResult qResult = query.execute();
NodeIterator ns = qResult.getNodes(); // get the nodes
while (ns.hasNext()) {
Node n = ns.nextNode(); // get each node
// get the properties
PropertyIterator it = n.getProperties(); // get the properties
while (it.hasNext()) {
Property property = it.nextProperty(); // get each property
String key = p.getName().trim();
String value = "";
if(p.isMultiple()) {
Value[] valueArr = p.getValues();
int i = 0;
for (i=0;i < valueArr.length;i++) {
value += valueArr[i].getString();
}
}else {
p.getValue().getString().trim();
}
result.append (key + ":" + value);
}
}
} catch (Exception e) {e.printStackTrace();
} finally {session.logout();}
return result.toString();
}
Using this logic I was able to generate extract the properties and convert the result into anything I wish for example another JSON or XML or etc…
But I do not think this is the best way.
Is there a way I can take the Node and convert into an OrangDT object so I can extract the Orang object… (for example change from line 12 to have something like this?)
while (ns.hasNext()) {
Node n = ns.nextNode(); // get each node
OrangDT test = (OrangDT) n;
Orang temp = test.getOrang();
}
Cheers
Sola Lee