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