Update an User with Phone,Address and Contact
User updateUser = UserLocalServiceUtil.getUser(Long
.parseLong(userId));
Long companyId = updateUser.getCompanyId();
List<Address> updateAddress = (List<Address>) AddressLocalServiceUtil
.getAddresses(updateUser.getCompanyId(),
Contact.class.getName(),
updateUser.getContactId());
UserAdditionalInfo userAdditionalInfo = UserAdditionalInfoLocalServiceUtil
.getUserAdditionalInfo(Long.parseLong(userId));
List<Phone> phoneList = PhoneLocalServiceUtil.getPhones(
companyId, Contact.class.getName(),
updateUser.getContactId());
List<ListType> phoneTypes = ListTypeServiceUtil
.getListTypes(Contact.class.getName()
+ ListTypeConstants.PHONE);
int officePhoneTypeId = 0;
int mobilePhoneTypeId = 0;
int homePhoneTypeId = 0;
int faxTypeId = 0;
for (ListType phoneType : phoneTypes) {
String phoneTypeName = phoneType.getName();
if (UserConstants.OFFICE_PHONE_TYPE.equals(phoneTypeName)) {
officePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.MOBILE_PHONE_TYPE.equals(phoneTypeName)) {
mobilePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.HOME_PHONE_TYPE.equals(phoneTypeName)) {
homePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.PERSONAL_FAX_TYPE.equals(phoneTypeName)) {
faxTypeId = phoneType.getListTypeId();
}
}
String officeNumber = StringPool.BLANK;
String mobileNumber = StringPool.BLANK;
String homeNumber = StringPool.BLANK;
String faxNumber = StringPool.BLANK;
for (Phone phone : phoneList) {
if ((updateUser.getUserId() == phone.getUserId())
&& (officePhoneTypeId == phone.getTypeId())) {
officeNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (mobilePhoneTypeId == phone.getTypeId())) {
mobileNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (homePhoneTypeId == phone.getTypeId())) {
homeNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (faxTypeId == phone.getTypeId())) {
faxNumber = phone.getNumber();
}
}
if (!updateAddress.isEmpty() && updateAddress.size() != 0) {
Contact updateContact = ContactLocalServiceUtil
.getContact(updateUser.getContactId());
UserRegistrationDTO userRegistration = requestedUserData(
companyId, userAdditionalInfo.getRoleId(),
updateUser.getEmailAddress(),
updateUser.getFirstName(),
updateUser.getMiddleName(),
updateUser.getLastName(), updateAddress.get(0)
.getStreet1(), updateAddress.get(0)
.getStreet2(), updateAddress.get(0)
.getStreet3(), updateAddress.get(0)
.getCity(), userAdditionalInfo.getState(),
updateAddress.get(0).getZip(), updateAddress.get(0)
.getCountryId(), officeNumber,
mobileNumber, homeNumber, faxNumber,
userAdditionalInfo.getLinkedIn(),
updateContact.getFacebookSn(),
updateContact.getTwitterSn(),
userAdditionalInfo.getAnnualIncome(),
userAdditionalInfo.getCurrencyCode(),
userAdditionalInfo.getDomainExpertise(),
userAdditionalInfo.getExperience(),
userAdditionalInfo.getQualification(),
userAdditionalInfo.isSubscribeNewsAlerts());
actionRequest.setAttribute(UserConstants.USER_REGISTRATION,
userRegistration);
}
User updateUser = UserLocalServiceUtil.getUser(Long
.parseLong(userId));
Long companyId = updateUser.getCompanyId();
List<Address> updateAddress = (List<Address>) AddressLocalServiceUtil
.getAddresses(updateUser.getCompanyId(),
Contact.class.getName(),
updateUser.getContactId());
UserAdditionalInfo userAdditionalInfo = UserAdditionalInfoLocalServiceUtil
.getUserAdditionalInfo(Long.parseLong(userId));
List<Phone> phoneList = PhoneLocalServiceUtil.getPhones(
companyId, Contact.class.getName(),
updateUser.getContactId());
List<ListType> phoneTypes = ListTypeServiceUtil
.getListTypes(Contact.class.getName()
+ ListTypeConstants.PHONE);
int officePhoneTypeId = 0;
int mobilePhoneTypeId = 0;
int homePhoneTypeId = 0;
int faxTypeId = 0;
for (ListType phoneType : phoneTypes) {
String phoneTypeName = phoneType.getName();
if (UserConstants.OFFICE_PHONE_TYPE.equals(phoneTypeName)) {
officePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.MOBILE_PHONE_TYPE.equals(phoneTypeName)) {
mobilePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.HOME_PHONE_TYPE.equals(phoneTypeName)) {
homePhoneTypeId = phoneType.getListTypeId();
}
if (UserConstants.PERSONAL_FAX_TYPE.equals(phoneTypeName)) {
faxTypeId = phoneType.getListTypeId();
}
}
String officeNumber = StringPool.BLANK;
String mobileNumber = StringPool.BLANK;
String homeNumber = StringPool.BLANK;
String faxNumber = StringPool.BLANK;
for (Phone phone : phoneList) {
if ((updateUser.getUserId() == phone.getUserId())
&& (officePhoneTypeId == phone.getTypeId())) {
officeNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (mobilePhoneTypeId == phone.getTypeId())) {
mobileNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (homePhoneTypeId == phone.getTypeId())) {
homeNumber = phone.getNumber();
}
if ((updateUser.getUserId() == phone.getUserId())
&& (faxTypeId == phone.getTypeId())) {
faxNumber = phone.getNumber();
}
}
if (!updateAddress.isEmpty() && updateAddress.size() != 0) {
Contact updateContact = ContactLocalServiceUtil
.getContact(updateUser.getContactId());
UserRegistrationDTO userRegistration = requestedUserData(
companyId, userAdditionalInfo.getRoleId(),
updateUser.getEmailAddress(),
updateUser.getFirstName(),
updateUser.getMiddleName(),
updateUser.getLastName(), updateAddress.get(0)
.getStreet1(), updateAddress.get(0)
.getStreet2(), updateAddress.get(0)
.getStreet3(), updateAddress.get(0)
.getCity(), userAdditionalInfo.getState(),
updateAddress.get(0).getZip(), updateAddress.get(0)
.getCountryId(), officeNumber,
mobileNumber, homeNumber, faxNumber,
userAdditionalInfo.getLinkedIn(),
updateContact.getFacebookSn(),
updateContact.getTwitterSn(),
userAdditionalInfo.getAnnualIncome(),
userAdditionalInfo.getCurrencyCode(),
userAdditionalInfo.getDomainExpertise(),
userAdditionalInfo.getExperience(),
userAdditionalInfo.getQualification(),
userAdditionalInfo.isSubscribeNewsAlerts());
actionRequest.setAttribute(UserConstants.USER_REGISTRATION,
userRegistration);
}
sir I want to retrieve the data from table which is by default present in liferay lportal database, please help me in this regard. I search a lot but fail to get any help.
ReplyDeletethanks
asifaftab