2/06/2014

How to put your document library folder under workflow control programmatically

If you want to create document library folders (dlfolder) programmatically, you can do this very easy by calling
DLFolderLocalServiceUtil.addFolder(userId, groupId, groupId, false, 0, "Folder title", "Folder description",false, new ServiceContext());
That´s just one line of code and you´re done. But what if you want to put your folder under workflow control? Liferay offers the possibility to connect assets in your folders to specific workflows. So as soon as you upload a basic document for example, the workflow will be started.  You can do that manually when you select your folder and click on "Edit":



Wouldn´t it be nice it that could be done programmatically ? Liferay source code comes to the rescue ! This is how they do it. First, set the file entry types override:
dlFolder.setOverrideFileEntryTypes(true);
dlFolder = DLFolderLocalServiceUtil.updateDLFolder(dlFolder);
Then you need to query the DLFileEntryType table for the FileEntryType you want to set up a workflow for. Next, you need to set the DlFileEntries for the folder:
long[] fileEntryTypeIds = new long[] { basicDocumentType.getFileEntryTypeId() };
DLFileEntryTypeLocalServiceUtil.setDLFolderDLFileEntryTypes(dlFolder.getFolderId(), fileEntryTypeIds);
Next is a query to get the process definitions you want your folder and the fileEntryType to connect with:
List<WorkflowDefinition> activeWorkflowDefinitions = WorkflowDefinitionManagerUtil.getActiveWorkflowDefinitions(companyId, "Your Process Name", 0, 100, null);
And last but not least you need to add a workflow definition link:
WorkflowDefinitionLinkLocalServiceUtil.addWorkflowDefinitionLink(userId, companyId, groupId, 
DLFolderConstants.getClassName(), dlFolder.getFolderId(), basicDocumentType.getFileEntryTypeId(),  name, version);


If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/03/2014

How to show a JSP full-screen in liferay

Just answered this question to a developer on stackoverflow, so I just wanted to share it in my blog. If you want to access a JSP in full-screen mode, without showing anything of the liferay portal the JSP is deployed in, you can do the following:


Create a portlet and inside the portlet, create a servlet. This has the nice advantage that you can access your JSP by a URL like http://localhost:8080/your-portlet/your-servlet. Just think about a nice name and you will come up with a dozen business cases. Anyway ... inside your servlet you can now do a forward to your JSP and this JSp will then be displayed in full-screen. Please note that now you don´t have access to the liferay request context - no themeDisplay for example.



Creating the forward in your Servlet is pretty simple. Just add the following:

String forwardJSP = "/your-jsp.jsp";
RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(forwardJSP);
requestDispatcher.forward(request,response);

If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.