1
22
23 package com.liferay.portal.events;
24
25 import com.liferay.portal.NoSuchUserException;
26 import com.liferay.portal.kernel.events.ActionException;
27 import com.liferay.portal.kernel.events.SimpleAction;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.model.User;
31 import com.liferay.portal.service.UserLocalServiceUtil;
32
33 import java.util.Calendar;
34 import java.util.Locale;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39
50 public class SampleAppStartupAction extends SimpleAction {
51
52 public void run(String[] ids) throws ActionException {
53 try {
54 long companyId = GetterUtil.getLong(ids[0]);
55
56 doRun(companyId);
57 }
58 catch (Exception e) {
59 throw new ActionException(e);
60 }
61 }
62
63 protected void doRun(long companyId) throws Exception {
64 try {
65 UserLocalServiceUtil.getUserByScreenName(companyId, "paul");
66
67
69 return;
70 }
71 catch (NoSuchUserException nsue) {
72 }
73
74 long creatorUserId = 0;
75 boolean autoPassword = false;
76 String password1 = "test";
77 String password2 = password1;
78 boolean autoScreenName = false;
79 String screenName = "paul";
80 String emailAddress = "paul@liferay.com";
81 Locale locale = Locale.US;
82 String firstName = "Paul";
83 String middleName = StringPool.BLANK;
84 String lastName = "Smith";
85 int prefixId = 0;
86 int suffixId = 0;
87 boolean male = true;
88 int birthdayMonth = Calendar.JANUARY;
89 int birthdayDay = 1;
90 int birthdayYear = 1970;
91 String jobTitle = StringPool.BLANK;
92 long[] organizationIds = new long[0];
93 boolean sendEmail = false;
94
95 User paulUser = UserLocalServiceUtil.addUser(
96 creatorUserId, companyId, autoPassword, password1, password2,
97 autoScreenName, screenName, emailAddress, locale, firstName,
98 middleName, lastName, prefixId, suffixId, male, birthdayMonth,
99 birthdayDay, birthdayYear, jobTitle, organizationIds, sendEmail);
100
101 if (_log.isDebugEnabled()) {
102 _log.debug(
103 paulUser.getFullName() + " was created with user id " +
104 paulUser.getUserId());
105 }
106
107 screenName = "jane";
108 emailAddress = "jane@liferay.com";
109 firstName = "Jane";
110
111 User janeUser = UserLocalServiceUtil.addUser(
112 creatorUserId, companyId, autoPassword, password1, password2,
113 autoScreenName, screenName, emailAddress, locale, firstName,
114 middleName, lastName, prefixId, suffixId, male, birthdayMonth,
115 birthdayDay, birthdayYear, jobTitle, organizationIds, sendEmail);
116
117 if (_log.isDebugEnabled()) {
118 _log.debug(
119 janeUser.getFullName() + " was created with user id " +
120 janeUser.getUserId());
121 }
122 }
123
124 private static Log _log = LogFactory.getLog(SampleAppStartupAction.class);
125
126 }