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. 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 = WorkflowDefinitionManagerUti l.getActiveWorkflowDefinitions(companyId,  "Your Process Name" 0 100 null );
you need to add a workflow definition link:
 
WorkflowDefinitionLinkLocalServiceUtil.addWorkflowDefinitionLink(userId, companyId, groupId, 
DLFolderConstants.getClassName(), dlFolder.getFolderId(), basicDocumentType.getFileEntryTypeId(),  name, version);
 
 
4
Blogs
Dear Tauseef,

Thanks for sharing. Really useful. Appreciate if you can explain in which context you've made use of this feature / API's of Liferay in the real world scenario.

Ahamed Hasan
Author, Liferay Cookbook
We had requirement where very end user can upload his document and media files in his folder. This folder needs to be approved by the admin. After approval this folder becomes visible to the community members so we achieved using this
Hi Tauseef!

Are you sure that the DLFolder*Util is the right client?
I know that you have to user DLApp as a client wrapper on the D&M library..
Have you tryed to login as a "normal" user -ie not an Administrator- and trying to access the document you have uploaded?
In my tests the portlet D&M Library was broken and I couldn't see the document thumbnail & metadata...
Hi buddy

check this same blog in this URL it is published on feb 6

http://liferay-blogging.blogspot.in/2014/02/how-to-put-your-document-library-folder.html