protected Date getTomorrowDate(long timeInMillis) { CalendarFactory calendarFactory = CalendarFactoryUtil.getCalendarFactory(); Calendar tomorrowCalendar = calendarFactory.getCalendar(timeInMillis); tomorrowCalendar.add(Calendar.DATE, 1); tomorrowCalendar.set(Calendar.HOUR_OF_DAY, 0); tomorrowCalendar.set(Calendar.MINUTE, 0); tomorrowCalendar.set(Calendar.SECOND, 0); return tomorrowCalendar.getTime(); }
public User addUser(ServiceContext serviceContext, String screenName,String password,String repassword, Date birthdate,String fullName,String email) throws PortalException, SystemException{ //boolean autoPassword String[] tg = fullName.split(" "); String firstName = tg[0]; String middleName = ""; String lastName = ""; if (tg.length > 1){ firstName = tg[tg.length-1]; lastName = tg[0]; } if (tg.length > 2){ middleName = tg[1]; for (int i = 2; i < tg.length -1;i++){ middleName += " " + tg[i]; } } Calendar birthday = CalendarFactoryUtil.getCalendar(); birthday.setTime(birthdate); long creatorUserId = 0; boolean autoPassword = false; //String password1 = "password"; //String password2 = password1; boolean autoScreenName = false; //String screenName = "tck"; String emailAddress = email; long facebookId = 0; String openId = StringPool.BLANK; Locale locale = LocaleUtil.getDefault(); int prefixId = 0; int suffixId = 0; boolean male = true; int birthdayMonth = birthday.get(Calendar.MONTH); int birthdayDay = birthday.get(Calendar.DAY_OF_MONTH); int birthdayYear = birthday.get(Calendar.YEAR); String jobTitle = StringPool.BLANK; long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; boolean sendEmail = false; //Locale locale = LocaleUtil.US; // creatorUserId, companyId, autoPassword, password1, password2, // autoScreenName, screenName, emailAddress, facebookId, openId, // locale, firstName, middleName, lastName, prefixId, suffixId, // male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, // groupIds, organizationIds, roleIds, userGroupIds, sendEmail, // serviceContext); User user = UserLocalServiceUtil.addUser(creatorUserId, serviceContext.getCompanyId(), autoPassword, password, repassword, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); return user; }
private User addUser(final ActionRequest request, String screenName, String password, String repassword, Date birthdate, String fullName, String email, int gender) throws PortalException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) request .getAttribute(WebKeys.THEME_DISPLAY); long creatorUserId = themeDisplay.getUserId(); // default liferay user long companyId = themeDisplay.getCompanyId(); // default company boolean autoPassword = true; String password1 = ""; String password2 = ""; boolean autoScreenName = true; String emailAddress = email; long facebookId = 0; String openId = ""; Locale locale = themeDisplay.getLocale(); String[] tg = fullName.split(" "); String firstName = tg[0]; String middleName = ""; String lastName = ""; if (tg.length > 1) { firstName = tg[tg.length - 1]; lastName = tg[0]; } if (tg.length > 2) { middleName = tg[1]; for (int i = 2; i < tg.length - 1; i++) { middleName += " " + tg[i]; } } int prefixId = 0; int suffixId = 0; boolean male = gender == 1; Calendar birthday = CalendarFactoryUtil.getCalendar(); birthday.setTime(birthdate); int birthdayMonth = birthday.get(Calendar.MONTH); int birthdayDay = birthday.get(Calendar.DAY_OF_MONTH); int birthdayYear = birthday.get(Calendar.YEAR); String jobTitle = ""; long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; boolean sendEmail = false; ServiceContext serviceContext = ServiceContextFactory .getInstance(request); try { User user = UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); return user; } catch(Exception e){ System.out.println(e.getMessage()); return null; } }
protected User updateUser(User user, Userinfo userinfo) throws Exception { String emailAddress = userinfo.getEmail(); String firstName = userinfo.getGivenName(); String lastName = userinfo.getFamilyName(); boolean male = Validator.equals(userinfo.getGender(), "male"); if (emailAddress.equals(user.getEmailAddress()) && firstName.equals(user.getFirstName()) && lastName.equals(user.getLastName()) && (male == user.isMale())) { return user; } Contact contact = user.getContact(); Calendar birthdayCal = CalendarFactoryUtil.getCalendar(); birthdayCal.setTime(contact.getBirthday()); int birthdayMonth = birthdayCal.get(Calendar.MONTH); int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH); int birthdayYear = birthdayCal.get(Calendar.YEAR); long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; List<UserGroupRole> userGroupRoles = null; long[] userGroupIds = null; ServiceContext serviceContext = new ServiceContext(); if (!StringUtil.equalsIgnoreCase( emailAddress, user.getEmailAddress())) { UserLocalServiceUtil.updateEmailAddress( user.getUserId(), StringPool.BLANK, emailAddress, emailAddress); } UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true); return UserLocalServiceUtil.updateUser( user.getUserId(), StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, false, user.getReminderQueryQuestion(), user.getReminderQueryAnswer(), user.getScreenName(), emailAddress, 0, user.getOpenId(), user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(), user.getComments(), firstName, user.getMiddleName(), lastName, contact.getPrefixId(), contact.getSuffixId(), male, birthdayMonth, birthdayDay, birthdayYear, contact.getSmsSn(), contact.getAimSn(), contact.getFacebookSn(), contact.getIcqSn(), contact.getJabberSn(), contact.getMsnSn(), contact.getMySpaceSn(), contact.getSkypeSn(), contact.getTwitterSn(), contact.getYmSn(), contact.getJobTitle(), groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds, serviceContext); }
protected Date getStartDate(long timeInMillis, long hoursToSubstract) { CalendarFactory calendarFactory = CalendarFactoryUtil.getCalendarFactory(); long start = timeInMillis - (hoursToSubstract * 60 * 60 * 1000); Calendar startCalendar = calendarFactory.getCalendar(start); return startCalendar.getTime(); }