Skip to content

Instantly share code, notes, and snippets.

@CorneAussems
Created March 21, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CorneAussems/c6daec7a42e40cd0d0a0e569f9357e8a to your computer and use it in GitHub Desktop.
Save CorneAussems/c6daec7a42e40cd0d0a0e569f9357e8a to your computer and use it in GitHub Desktop.
Liferay DXP JournalFolderTree with file download groovy
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portlet.journal.service.*;
import com.liferay.journal.service.impl.*;
import com.liferay.journal.service.*;
import com.liferay.portal.kernel.service.*;
import com.liferay.portal.kernel.dao.orm.*;
final def SCRIPT_ID = "MYSCRIPT1"
outputFile = new File("""${System.getProperty("liferay.home")}/scripting/out-${SCRIPT_ID}.txt""")
outputFile.getParentFile().mkdirs()
def trace(message) {
//out.println(message)
outputFile << "${message}\n"
}
def getChildFolders(groupId, parentFolderId) {
def journalFolders = JournalFolderLocalServiceUtil.getFolders(groupId, parentFolderId);
if(journalFolders.size() > 0){
trace("<UL>");
for( x=0; x<journalFolders.size();x++){
trace("<li>"+journalFolders[x].getName()+"</li>");
getChildFolders(groupId, journalFolders[x].getFolderId());
}
trace("</UL>");
}
}
try {
trace("START");
long companyId = PortalUtil.getDefaultCompanyId();
long groupId = 20143; //HeyHema
def group = GroupLocalServiceUtil.getGroup(companyId,"Guest");
trace("groupId:"+group.getGroupId());
def groupFolders = JournalFolderLocalServiceUtil.getFolders(group.getGroupId());
trace("<UL>");
//for( i=0; i<groupFolders.size();i++){
for( i=0; i<1;i++){
trace("<li>"+groupFolders[i].getName()+"</li>");
getChildFolders(groupId, groupFolders[i].getFolderId() );
}
trace("</UL>");
trace("END");
}catch (e) {
out.println("Error = " + e.getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment