Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hugo Palma
Announcements default delivery
January 6, 2010 6:01 AM
Answer

Hugo Palma

Rank: New Member

Posts: 20

Join Date: September 13, 2007

Recent Posts

Hi,
it seems that by default when a user is created the delivery option for receiving announcements by email isn't active.

I would like to configuration Liferay so that by default all users get announcements by email.
Any ideas on how i can do this ?

Thanks.
Lisa Simpson
RE: Announcements default delivery
January 21, 2010 3:42 PM
Answer

Lisa Simpson

Rank: Liferay Legend

Posts: 2034

Join Date: March 5, 2009

Recent Posts

See if there is an option you can set in the portal-ext.properties
Christian Merkel
RE: Announcements default delivery
February 3, 2010 2:19 AM
Answer

Christian Merkel

Rank: Regular Member

Posts: 111

Join Date: December 14, 2009

Recent Posts

i got the same question.
i just checked all portal-ext properties, but can't find any value to set this behavior.

we got now many existing accounts in portal, but non of this has activate the email notification for announcements....

i want to force the email notification for a special type (e.g. general). is this posible??

thx emoticon
Marco Peters
RE: Announcements default delivery
May 4, 2010 2:23 AM
Answer

Marco Peters

Rank: New Member

Posts: 4

Join Date: May 4, 2010

Recent Posts

We do have the same problem and obviously the same questions.

Any ideas are very welcome.

Thanks in advance
Marco
www.brockmann-consult.de/beam
Marco Peters
RE: Announcements default delivery
May 6, 2010 12:34 PM
Answer

Marco Peters

Rank: New Member

Posts: 4

Join Date: May 4, 2010

Recent Posts

To answer the question myself: Hooks are the best way to achieve this.
You can add a ModelListener to Liferay and then you get informed when a new user is created.
With the Plugins SDK it's very simple to achieve.
All you have to do is (also consider tutorials about hooks and how to build them):

1. Create the file liferay-hooks.xml indocroot/WEB_INF
1<hook>
2  <model-listener>
3    <model-listener-class>my.class.path.UserListener</model-listener-class>
4    <model-name>com.liferay.portal.model.User</model-name>
5</model-listener>
6</hook>

2. Create the class UserListener.java in docroot/WEB-INF/src/my/class/path
 1public class UserListener extends BaseModelListener<User> {
 2
 3    @Override
 4    public void onAfterCreate(User user) throws ModelListenerException {
 5        super.onAfterCreate(user);
 6
 7        final long userId = user.getUserId();
 8        AnnouncementsDeliveryLocalService adls = AnnouncementsDeliveryLocalServiceUtil.getService();
 9
10        try {
11            adls.updateDelivery(userId, "general", true, false, true);
12            adls.updateDelivery(userId, "news", true, false, true);
13            adls.updateDelivery(userId, "test", false, false, true);
14        } catch (PortalException e) {
15            throw new ModelListenerException("Could not update announcement delivery.", e);
16        } catch (SystemException e) {
17            throw new ModelListenerException("Could not update announcement delivery.", e);
18        }
19    }
20}


best wishes
Marco
Nicola Grigoletti
RE: Announcements default delivery
August 26, 2010 5:59 AM
Answer

Nicola Grigoletti

Rank: New Member

Posts: 16

Join Date: April 19, 2007

Recent Posts

Hi Marco

I've the same problem so I tried your code... All runs fine, I've no errors and when I debug this hook I find all data as I set, but (yes, there is a problem emoticon) when I check on db or on Liferay Control Panel I find default data (false, false, true).

I'm using LR 5.2.3... any idea?

Tks a lot
Nicola
Marco Peters
RE: Announcements default delivery
August 27, 2010 4:46 AM
Answer

Marco Peters

Rank: New Member

Posts: 2

Join Date: August 26, 2010

Recent Posts

Hi Nicola

I have to reply to you using a different account (can't log in to my actual account).

We also use LR 5.2.3. With a MySQL database in background.
Both, the database and the profile page, reflected the changes we have made.
So unfortunately I can't give you any hint.

We haven't followed this approach to the end, because it is not allowed to set such email notification check-boxes by default to true (at least in Germany). The user has to agree.

best wishes
Marco
James Denmark
RE: Announcements default delivery
July 15, 2011 2:24 PM
Answer

James Denmark

Rank: Junior Member

Posts: 27

Join Date: November 19, 2008

Recent Posts

Nicola Grigoletti:
Hi Marco

I've the same problem so I tried your code... All runs fine, I've no errors and when I debug this hook I find all data as I set, but (yes, there is a problem emoticon) when I check on db or on Liferay Control Panel I find default data (false, false, true).

I'm using LR 5.2.3... any idea?

Tks a lot
Nicola


I am having the same issue as Nicola. The modelListener on user fires when new users are created and everything would seem to be fine but the deliveries are not being persisted to the DB. I am wondering if this is something of a timing issue as it appears as if the announcements defaults are also being set by a modelListener and these updates may collide. I tried adding a threadwait to my listener but that didn't make any difference. I saw another post where the user was successful at doing this when the listener was fired at login instead which would be consistent with my collision theory (although it makes no sense to me why hibernate wouldn't handle this for us). Before I move my listener to the login chain and assuming the acceptedTermsOfUse field is still false at that point can someone shine some light on how this gets set now.

The question I have is can anyone explain exactly how the current default values are being created? If it is a listener, then what is it listening for?

Jim.
Michael Bravo
RE: Announcements default delivery
September 28, 2012 5:31 AM
Answer

Michael Bravo

Rank: New Member

Posts: 20

Join Date: April 26, 2012

Recent Posts

I was able to get this working by using a slightly altered method of doing this....

I found an updated version of what Marco posted above, here, at the link below:

http://www.emforge.net/web/akakunin/blogs/-/blogs/model-listener-in-liferay-6

This link above gives an altered approach to creating the hook to use a ModelListener to get the job done. Here are the steps that I used by just creating a baic class with a couple of static methods:

1. Create a hook project in eclipse. Call it something like liferay-announcement-listener. The eclipse project should add 'hook' at the end of it, I think, depending on what eclipse plugin you are using. That is, if you are using an eclipse plugin. I hope you are. That makes things easier, for sure.
2. Create a package where you are going to place our new class. Something like, com.listener.example
3. Create a Class called UserListener (Even though in this example it's not a real Listner). You can create a Listener class and overide the methods in the BaseModelListener class, but you don't have to I found.
4. Create a file called portal.propuerties and place it in the same package folder as your new class. They tell you to place it in the /src directory, but when I did this it through a funky error. I placed it in both locations for this job, and it worked after I placed it in the same package folder as the class.
5. In the portal.properties file enter the following:
value.object.listener.com.liferay.portal.model.User=com.listener.example.UserListener
6. In <project>/docroot/WEB-INF/liferay-hook.xml enter the following:
<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>

<portal-properties>portal.properties</portal-properties>

</hook>

Ok .. We're done with that part.

7. Now for the class that will do the work. It's a basic class with two static methods, one that is a static initialization block that will be read at runtime to grab the users in the system and then update each one at a time, and another that does the work of calling the AnnouncementDeliveryLocalService to do the update. Here is what it looks like:

package com.listener.example;

import java.util.List;

import com.liferay.portal.ModelListenerException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.BaseModelListener;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.announcements.service.AnnouncementsDeliveryLocalService;
import com.liferay.portlet.announcements.service.AnnouncementsDeliveryLocalServiceUtil;

public class UserListener{

static{
try {
int users = UserLocalServiceUtil.getUsersCount();
List userList = UserLocalServiceUtil.getUsers(0, users);
for (int i = 0; i < userList.size(); i++) {
User u = (User)userList.get(i);
System.out.println(u.getScreenName());
UserListener.beginUpdate(u);
}
System.out.println(users);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public UserListener(){
}
public static void beginUpdate(User user) throws ModelListenerException{

final long userId = user.getUserId();
AnnouncementsDeliveryLocalService adls = AnnouncementsDeliveryLocalServiceUtil.getService();

try {
System.out.println("Updating announcement delivery");
adls.updateDelivery(userId, "general", true, false, true);
adls.updateDelivery(userId, "news", true, false, true);
adls.updateDelivery(userId, "test", false, false, true);
} catch (PortalException e) {
throw new ModelListenerException("Could not update announcement delivery.", e);
} catch (SystemException e) {
throw new ModelListenerException("Could not update announcement delivery.", e);
}
}


}

8. Finally, build the project. in eclipse if you run ant on the build file that the wizard made for you the output should look something like this.

Buildfile: C:\liferay-plugins-sdk-6.1.20\hooks\liferay-announcement-listener-hook\build.xml
compile:
merge:
Copying 5 files to C:\liferay-plugins-sdk-6.1.20\hooks\liferay-announcement-listener-hook\docroot\WEB-INF\lib
compile-java:
merge:
war:
Deleting: C:\liferay-plugins-sdk-6.1.20\dist\liferay-announcement-listener-hook-6.1.20.1.war
clean-portal-dependencies:
Building zip: C:\liferay-plugins-sdk-6.1.20\dist\liferay-announcement-listener-hook-6.1.20.1.war
deploy:
Copying 1 file to C:\liferay_6.1.0\liferay-portal-6.1.0-ce-ga1\deploy
BUILD SUCCESSFUL
Total time: 1 second

9. Upload the war file to the <liferay instance>/deploy directory.
10. I like to tail the <liferay instance>/tomcat/logs/catalina.out at this point to check the deploy is running .. It ought to be, and you should see that it's deploying, then .. You should start seeing the System.out.println's .. if you kept them in there .. That will telll you that the method was called and that the updates are occuring.
11. Now you should be able to go to the portal and check on any user and see that the Announcements checkboxes are selected. Again, this will update users in the portal.

Hope this helps somebody ..