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.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.model.User;
33 import com.liferay.portal.service.ServiceContext;
34 import com.liferay.portal.service.UserLocalServiceUtil;
35
36 import java.util.Calendar;
37 import java.util.Locale;
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 String openId = StringPool.BLANK;
82 Locale locale = Locale.US;
83 String firstName = "Paul";
84 String middleName = StringPool.BLANK;
85 String lastName = "Smith";
86 int prefixId = 0;
87 int suffixId = 0;
88 boolean male = true;
89 int birthdayMonth = Calendar.JANUARY;
90 int birthdayDay = 1;
91 int birthdayYear = 1970;
92 String jobTitle = StringPool.BLANK;
93 long[] groupIds = null;
94 long[] organizationIds = null;
95 long[] roleIds = null;
96 long[] userGroupIds = null;
97 boolean sendEmail = false;
98 ServiceContext serviceContext = new ServiceContext();
99
100 User paulUser = UserLocalServiceUtil.addUser(
101 creatorUserId, companyId, autoPassword, password1, password2,
102 autoScreenName, screenName, emailAddress, openId, locale, firstName,
103 middleName, lastName, prefixId, suffixId, male, birthdayMonth,
104 birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds,
105 roleIds, userGroupIds, sendEmail, serviceContext);
106
107 if (_log.isDebugEnabled()) {
108 _log.debug(
109 paulUser.getFullName() + " was created with user id " +
110 paulUser.getUserId());
111 }
112
113 screenName = "jane";
114 emailAddress = "jane@liferay.com";
115 firstName = "Jane";
116
117 User janeUser = UserLocalServiceUtil.addUser(
118 creatorUserId, companyId, autoPassword, password1, password2,
119 autoScreenName, screenName, emailAddress, openId, locale, firstName,
120 middleName, lastName, prefixId, suffixId, male, birthdayMonth,
121 birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds,
122 roleIds, userGroupIds, sendEmail, serviceContext);
123
124 if (_log.isDebugEnabled()) {
125 _log.debug(
126 janeUser.getFullName() + " was created with user id " +
127 janeUser.getUserId());
128 }
129 }
130
131 private static Log _log =
132 LogFactoryUtil.getLog(SampleAppStartupAction.class);
133
134 }