Foren

getUserEntries in AnnouncementsEntry returns no records

thumbnail
Pete Helgren, geändert vor 9 Jahren.

getUserEntries in AnnouncementsEntry returns no records

Regular Member Beiträge: 225 Beitrittsdatum: 07.04.11 Neueste Beiträge
I have the following code that I used to implement a feature where I can get a list of the announcements for a user and then iterate through them to see if they have acknowledged seeing the announcement:

.....................
int entryCount = AnnouncementsEntryLocalServiceUtil.getAnnouncementsEntriesCount();
int total = AnnouncementsEntryLocalServiceUtil.getUserEntriesCount(userId);

announcementsList = AnnouncementsEntryLocalServiceUtil.getUserEntries(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
// iterate, etc
......................

There are 4 announcements total that have been entered in the portlet. TWO of those announcements can be seen when I log in as a user who should see two announcements so I know that the portlet is working OK. The problem is that getUserEntriesCount and getUserEntries returns zero entries when I use debug , even though I can see entries when I log in as the user. entryCount correctly returns the number of entries total.

So the question is: What have I missed? As far as I can tell in debug the userID I have retrieved like this:

userId = PortalUtil.getUserId(request)

IS correct. Did I misunderstand what the getUserEntries* methods should do (entries waiting for the user VS entries entered BY the user)?

Using LR 6.0.6
thumbnail
Pete Helgren, geändert vor 9 Jahren.

RE: getUserEntries in AnnouncementsEntry returns no records

Regular Member Beiträge: 225 Beitrittsdatum: 07.04.11 Neueste Beiträge
To answer my own question here: the AnnouncementsEntryLocalServiceUtil.getUserEntries method gives me the list of announcements ENTERED by the userId, not the announcements that are FOR the userId.

So I need to know how do I build the list of announcements FOR a particular user? When you land on the portlet, it will show you the list of your announcements. How do I get that list???
thumbnail
Jeffrey Handa, geändert vor 9 Jahren.

RE: getUserEntries in AnnouncementsEntry returns no records

Liferay Master Beiträge: 541 Beitrittsdatum: 01.12.08 Neueste Beiträge
Hi Pete,

Take a look at the how the current Announcements portlet works. In particular, take a look at view_entries.jspf and entry_iterator.jspf. They make use of the getAnnouncementScopes method of the AnnouncementsUtil.
thumbnail
Pete Helgren, geändert vor 9 Jahren.

RE: getUserEntries in AnnouncementsEntry returns no records

Regular Member Beiträge: 225 Beitrittsdatum: 07.04.11 Neueste Beiträge
Hmmm...I must have missed something because this code in a Post Login Action class throws a no class def error:

long userId = 0;
userId = PortalUtil.getUserId(request);
List<AnnouncementsEntry> announcementsList = new ArrayList<AnnouncementsEntry>();

// Let's start by seeing of this user needs to check some announcements
try {
// need a list of scopes
LinkedHashMap<Long, long[]> lhm = AnnouncementsUtil.getAnnouncementScopes(userId);

>>>>>Kablam!

java.lang.NoClassDefFoundError: com/liferay/portlet/announcements/util/AnnouncementsUtil
at org.bsfinternational.portal.action.LoginActionPost.run(LoginActionPost.java:42)
at com.liferay.portal.kernel.events.InvokerAction.run(InvokerAction.java:41)
at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:81)

The purpose of the code is to see if the user has any announcements to view and then redirect them to that page...But the no class def error gives me the sense that I need to have this run within the announcement portlet itself, which isn't going to work since I am calling the code post-login.

Or, maybe I am just missing the point ( I am not much of a JSF/JSP guy....)
thumbnail
Pete Helgren, geändert vor 9 Jahren.

RE: getUserEntries in AnnouncementsEntry returns no records (Antwort)

Regular Member Beiträge: 225 Beitrittsdatum: 07.04.11 Neueste Beiträge
I ended up creating a copy of this class in a package local to the hook and it works fine (based on a post I found here:
https://www.liferay.com/community/forums/-/message_boards/view_message/11317330)

Not sure why that was necessary but it fixed my issue.