0

Can I start the workflow for a file uploaded in document and library of liferay?

Here is my code:

DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);

fileEntry = DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId() ,file.getName(),"" ,title,"test", null, dlFolder.getDefaultFileEntryTypeId(), null, file, null, file.getUsableSpace(), serviceContext);

//*************************************NOW***************************

  • How can I start the workflow for the file which has been uploaded?
  • The started workflow, will it be the same workflow for all files in the test folder?
Prakash K
  • 11,669
  • 6
  • 51
  • 109
Mok
  • 35
  • 4

2 Answers2

0

Your question is not quite clear.

If you are talking about whether Liferay's workflow will get applied when you upload documents programatically? Then answer would be yes provided you have selected workflow definition for document library portlet.

You will find workflow task in the control panel under My workflow Tasks.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
Sharana
  • 749
  • 3
  • 8
  • yes the question is this. Can I know how do? (to code) please. – Mok Jul 17 '12 at 15:12
  • I have just selected workflow definition for document library portlet, but will not start when I add a file programmatically using this code, adds it to the folder as a draft, not as pending. – Mok Jul 19 '12 at 07:58
  • if i am not wrong u created a custom portlet of file upload..and u want to start workflow as soon as file is uploaded – Laxman Rana Jul 25 '12 at 08:30
0

Assuming that you have a custom portlet and the folder into which you're trying to upload a document has workflow,

DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);

FileInputStream is = new FileInputStream(file);
DLFileEntry fileEntry = DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId() ,
                            file.getName(),MimeTypesUtil.getContentType(file) ,title,"test", StringPool.BLANK, 
                            dlFolder.getDefaultFileEntryTypeId(), null, file, is,
                            file.length(), serviceContext);
DLFileEntryLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(), file.getName(), MimeTypesUtil.getContentType(file), 
        title(), "test", StringPool.BLANK, Boolean.FALSE, dlFileEntry.getFileEntryTypeId(), null, file, is,
        file.length(), serviceContext)

You should call updateFilEntry method after addFileEntry. It actually does two things,

  1. It changes the state of the document from Draft
  2. It invokes workflow

Hope this helps.

Harsha Kasturi
  • 233
  • 2
  • 13