Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Luigi Molinaro
start workflow programmatically after uploaded file in the DL
July 20, 2012 4:31 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

1
2DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
3ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
4actionRequest);
5fileEntry = DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId() ,file.getName(),"" ,title,"test", null, dlFolder.getDefaultFileEntryTypeId(), null, file, null, file.getUsableSpace(), serviceContext);


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.
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 20, 2012 4:59 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Luiqi,

To fulfill your requirement, you can use 'WorkflowHandlerRegistryUtil' class and can call one of the 'startWorkflowInstance(...)' method of it to start workflow through your code.

Hope this will helps you.

Let me know if you have any query for the same.
Luigi Molinaro
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 3:10 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

Hi Pinkesh,
thanks, for replay!

1
2DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Uploads");
3              dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), dlFolder.getFolderId(), String.valueOf(themeDisplay.getUserId()));
4              ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
5                      actionRequest);
6             
7              fileEntry = DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId() ,file.getName(),"" ,title,"prooova", null, dlFolder.getDefaultFileEntryTypeId(), null, file, null, file.getUsableSpace(), serviceContext);
8              WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), dlFolder.getGroupId(), themeDisplay.getUserId(), DLFileEntry.class.getName(),fileEntry.getFileEntryId(), fileEntry, serviceContext);


I have try whit this code, but not work!

the document is in Folder, but as draft, not as pending.
in the task of user assigned from workflow not appear null.

in the attachment the error generated.
Attachments: error (15.0k)
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 3:41 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Luigi Molinaro,

Can you please put a debugging or sop statement after each and every code statement, as I've doubt that the error which you attached here is comes on the execution of line fileEntry = DLFileEntryServiceUtil.addFileEntry(...); so it is not going to execute the line for startWorkflowInstance(...).

And I suggest one more thing that, please use DLFileEntryLocalServiceUtil instead of DLFileEntryServiceUtil.

Try it out and let me know if you have any query.
Luigi Molinaro
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 5:05 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

Hi Pinkesh,
 1
 2 DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Uploads");
 3              dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), dlFolder.getFolderId(), String.valueOf(themeDisplay.getUserId()));
 4              ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
 5                      actionRequest);
 6              System.out.println("HERE11111111111");
 7              fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId(), file.getName(), "", title, "prova", null, dlFolder.getDefaultFileEntryTypeId(), null, file, null, file.getTotalSpace(), serviceContext);
 8//              fileEntry = DLFileEntryServiceUtil.addFileEntry(dlFolder.getGroupId(), dlFolder.getRepositoryId(), dlFolder.getFolderId() ,file.getName(),"" ,title,"prooova", null, dlFolder.getDefaultFileEntryTypeId(), null, file, null, file.getUsableSpace(), serviceContext);
 9              System.out.println("HERE");
10              WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), dlFolder.getGroupId(), themeDisplay.getUserId(), DLFileEntry.class.getName(),fileEntry.getFileEntryId(), fileEntry, serviceContext);
11              System.out.println("HERE---------");


emoticon nada de nada!
Attachments: error (15.0k)
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 7:28 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Again can you please try with following code snippet

 1
 2long defaultRepoId = DLFolderConstants.getDataRepositoryId(themeDisplay.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
 3            Folder folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Uploads");
 4            System.out.println("HERE11111111111");
 5            folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, folder.getFolderId(), "Uploads");
 6            
 7            System.out.println("HERE22222222222");
 8   
 9            
10            FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), folder.getRepositoryId(), folder.getFolderId(), file.getName(), MimeTypesUtil.getContentType(file), title, "prooova", StringPool.BLANK, file, new ServiceContext());
11//               
12            System.out.println("HERE");
13            
14            serviceContext =  ServiceContextFactory.getInstance(FileEntry.class.getName(), actionRequest);
15            
16            WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), dlFolder.getGroupId(), themeDisplay.getUserId(), FileEntry.class.getName(),fileEntry.getFileEntryId(), fileEntry, serviceContext);
17            System.out.println("HERE---------");


I hope it helps you.
Luigi Molinaro
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 7:06 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

 1
 2long defaultRepoId = DLFolderConstants.getDataRepositoryId(themeDisplay.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
 3            Folder folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Uploads");
 4            System.out.println("HERE11111111111");
 5             folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, folder.getFolderId(), String.valueOf(themeDisplay.getUserId()));
 6           [u][b] dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, String.valueOf(themeDisplay.getUserId()));    [/b][/u]   
 7            System.out.println("HERE22222222222");
 8   
 9            
10            FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), folder.getRepositoryId(), folder.getFolderId(), file.getName(), MimeTypesUtil.getContentType(file), title, "prooova", StringPool.BLANK, file, new ServiceContext());
11//               
12            System.out.println("HERE");
13            
14            serviceContext =  ServiceContextFactory.getInstance(FileEntry.class.getName(), actionRequest);
15            
16            WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), dlFolder.getGroupId(), themeDisplay.getUserId(), FileEntry.class.getName(),fileEntry.getFileEntryId(), fileEntry, serviceContext);
17            System.out.println("HERE---------");

I had an error, but removing the line above underline, it's work!! emoticon

I also still an error, but no matter ... so it works! emoticon

thanks a lot Pinkesh
Attachments: error (13.3k)
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 7:25 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

Hi Luigi,

By looking into error file you attached here, one thing I've noticed that you haven't deployed any workflow engine in your system and that's why that error comes.
So I suggest, please deploy any suitable workflow engine in your liferay system and then after do such kind of workflow related stuffs.

Hope now you get more clarity on workflow.

Let me know if you have any query.
Luigi Molinaro
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 7:57 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

I I have deployed the kaleo workflow engine, (default).
however works. thanks.
I have other one question for you.
how can i call an static function written in an my class from script the workflow?
For exemple:
 1
 2<state><!-- create -->
 3        <name>created</name>
 4        <metadata>
 5            <![CDATA[{"xy":[38,187]}]]>
 6        </metadata>
 7        <actions>
 8            <action>
 9                <name>provaa</name>
10                <script>
11                    <![CDATA[
12                        [u][b]mok.Utility.staticFunction("moook",workflowContext);[/b][/u]
13                    ]]>
14                </script>
15                <script-language>javascript</script-language>
16                <execution-type>onEntry</execution-type>
17            </action>
18        </actions>
19        <initial>true</initial>
20        <transitions>
21            <transition>
22                <name>review</name>
23                <target>reviewPortal</target>
24                <default>true</default>
25            </transition>
26        </transitions>
27    </state>
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 23, 2012 11:34 PM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

I am not sure but as per my knowledge, directly it is not possible.
To make it possible you have to make the jar of your utility class which contains static method and put it into tomcat/lib/ext folder.

I hope this may helps you.
Luigi Molinaro
RE: start workflow programmatically after uploaded file in the DL
July 24, 2012 2:04 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

I tried different ways, but don't works.
Don't worry, this problem not important.
Thanks very much.
Pinkesh Gandhi
RE: start workflow programmatically after uploaded file in the DL
July 24, 2012 2:50 AM
Answer

Pinkesh Gandhi

Rank: Regular Member

Posts: 100

Join Date: January 26, 2012

Recent Posts

It should work as your class will be loaded globally and it would be available to all web application for use.

Any ways, if you are comfortable with your current solution then ok. emoticon
mohammad azaruddin
RE: start workflow programmatically after uploaded file in the DL
December 31, 2012 1:18 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 451

Join Date: September 17, 2012

Recent Posts

Hi Luigi Molinaro
I was facing same problem.Update File Entry after adding file with same data
try this code
DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(userId,10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fileInfo.getFile()
,null
,fileInfo.getFile().length()
,serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(userId, dlFileEntry.getFileEntryId(), fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, comment, true, dlFileEntry.getFileEntryTypeId(), fieldsMap, fileInfo.getFile(), null, fileInfo.getFile().length(), serviceContext);



Or follow this link -----file upload
Alexis Araya
RE: start workflow programmatically after uploaded file in the DL
June 3, 2014 1:17 PM
Answer

Alexis Araya

Rank: Junior Member

Posts: 29

Join Date: October 8, 2013

Recent Posts

You can show an example?
My portlet generates the income to a document library.
but in trying to build the workflow, not found me


Luigi Molinaro:
 1
 2long defaultRepoId = DLFolderConstants.getDataRepositoryId(themeDisplay.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
 3            Folder folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Uploads");
 4            System.out.println("HERE11111111111");
 5             folder = DLAppLocalServiceUtil.getFolder(defaultRepoId, folder.getFolderId(), String.valueOf(themeDisplay.getUserId()));
 6           [u][b] dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, String.valueOf(themeDisplay.getUserId()));    [/b][/u]   
 7            System.out.println("HERE22222222222");
 8   
 9            
10            FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), folder.getRepositoryId(), folder.getFolderId(), file.getName(), MimeTypesUtil.getContentType(file), title, "prooova", StringPool.BLANK, file, new ServiceContext());
11//               
12            System.out.println("HERE");
13            
14            serviceContext =  ServiceContextFactory.getInstance(FileEntry.class.getName(), actionRequest);
15            
16            WorkflowHandlerRegistryUtil.startWorkflowInstance(themeDisplay.getCompanyId(), dlFolder.getGroupId(), themeDisplay.getUserId(), FileEntry.class.getName(),fileEntry.getFileEntryId(), fileEntry, serviceContext);
17            System.out.println("HERE---------");

I had an error, but removing the line above underline, it's work!! emoticon

I also still an error, but no matter ... so it works! emoticon

thanks a lot Pinkesh