Recently I come across one of the requirement where client wanted to export detail about all the contents which are stored in Alfresco. I had though of following options of to implement it.
Create a Javabased webscript which will use the Alfresco foundation APIs to do the job.
The other option was to create Javascript based webscript which will use Alfresco javascript APIs to do the job.
I have decided to go with second option reasons were as follow.
- It was one time export, so need not to worry about features like security and reliability, maintainability and all those things.
- Alfresco javascript has all required api which will be enough to carry out activity.
- It is always faster to created javascript based webscript as we can quickly do the development without need to restart the server and It was production instance so data items inside.I need to make sure I do it with minimum downtime.
All above points you could probably used as deciding factor between javascript and java based wescript. When to go with javascript and when to go for java.
Here is the script which I have created as a part of export process.
var filename=space.name+".csv"; var CSVFile=companyhome.createFile(filename); var mainnode=space; var str; var header="FileName,FileID,FolderPath"+'\r\n'; iteratenode(mainnode.children) CSVFile.content=header+str; CSVFile.save(); function iteratenode(childarray){ for each (m in childarray) { if(m.isDocument){ var nodepath=m.displayPath.replace("/Company Home/",""); str+=m.name+","+m.id+","+nodepath +'\r\n'; }else if(m.isContainer){ iteratenode(m.children); } } }
This is not the optimized version of script there is scope for improvement in terms of logic for iteration.
Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!
Hi,
Why don’t you use recursivity right from the begining ?
On line 6, use iteratenode(mainnode.children);
This will simplify your script by avoiding code duplication.
Regards.
Yeah I had changed it later on, I did not got time to update it. Just updated it.
FYI, if you run this somewhere where str ends up being more than 10M, the script will become extremely slow as each string operation will have to re-allocate memory and that takes a heck of a long time in rhino.
Yeah Bindu, Thanks for pointing that out.
As I have specified in this article, this was really a one time job for me and I do not wanted to waste time in creating java based utility which could have handled that scenario.
I have taken divide and conquer approach here where I had various parent folders under root folder. So, I had run this scrip on those folders individually and every time I had created new file. This way I was able avoid that situation.