RE: Subscriber Notification when Adding file programatically

Kratiyag Gupta, modified 7 Years ago. New Member Posts: 5 Join Date: 9/19/17 Recent Posts
Hi Liferay Folks,
I'm adding a file in documents and media folder in liferay programatically. I know that all those user who have permission to view and subscribe the folder will get a notification through email once a new document is added but in my case it is not happening.

I'm adding file using following approach:-
DLAppLocalServiceUtil.addFileEntry(
			userId, companyGroup.getGroupId(), folder.getFolderId(), fileName,
			ContentTypes.TEXT_CSV_UTF8, csvContent.getBytes(), serviceContext);

Since I'm adding the file programmatically and the file added successfully but the mail notification is not triggerring
srini vasulu, modified 6 Years ago. Regular Member Posts: 139 Join Date: 2/22/11 Recent Posts
Hi ,
Did you resolved the issue i am also facing same issue.
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Srini, 

Looking at the Liferay source code, I don't see anything in any of the addFileEntry methods that sends out notifications. How are you trying to use it? Are you trying to use this service in a custom portlet?
srini vasulu, modified 6 Years ago. Regular Member Posts: 139 Join Date: 2/22/11 Recent Posts
Andrew JardineHi Srini, 

Looking at the Liferay source code, I don't see anything in any of the addFileEntry methods that sends out notifications. How are you trying to use it? Are you trying to use this service in a custom portlet?


Yes in from custom portlet i am adding file.
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi srini,

I didn't dig for hours into the source, but in the 10 or 15 minutes that I spent looking through a few classes I didn't see the reference. For sure it is there though so if you really want to know how Liferay is doing it, then for sure you will find it in the source. Alternatively you could manage sending the email yourself by leveraging the SubscriptionLocalService and the MailUtil that Liferay provides. 

The SubscriptionLocalService can be used to look up the users who are subscribed to the folder that the file is being added to and then you can use the MailUtil to send the message. 

For the record, and I haven't checked this to be honest but, I think the subscription to folders is only a feature web content folders. As far as I know there is no such feature for the documents and media folders. 

​​​​​​​
Kratiyag Gupta, modified 6 Years ago. New Member Posts: 5 Join Date: 9/19/17 Recent Posts
Well it turn out it is not possible without providing the configuration. The solution I followed, I created a configuration where I provide my QA and Prod URL and whever the mail is triggered it find which environment it is and concatinate the file path with the specific URL. 
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Ok. I think maybe I didn't understand your original problem then. I thought the issue was that the email was not being sent out ... Not that it had the wrong link.

If it's just the link you are looking for, the configuration is not the worst solution, but also not ideal as you now have a dependency on liferay not changing something in the future. You'd be better to use the api to generate the url so that if the logic for a generated url changes, you get the changes automatically.

​​​​​​​Just some food for thought.