user.setPassword(PublicEncryptionFactory.digestString(password));
user.setPasswordEncrypted(true);
APILocator.getUserAPI().save(user, APILocator.getUserAPI().getSystemUser(), false);
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user,APILocator.getUserAPI().getSystemUser(), false);
String userProxyInode = userProxy.getInode();
userProxy = (UserProxy) InodeFactory.getInode(userProxyInode, UserProxy.class);
userProxy.setInode(userProxyInode);
userProxy.setUserId(user.getUserId());
// getting and saving the user
// additional info
String userAdditionalInfo = "";
for (int j = 1; j <= numberGenericVariables; j++) {
try {
userAdditionalInfo = lineTok[i++];
} catch (Exception e) {
userAdditionalInfo = "";
}
if (!userAdditionalInfo.equalsIgnoreCase("")) {
userProxy.setVar(j, userAdditionalInfo);
}
}
com.dotmarketing.business.APILocator.getUserProxyAPI().saveUserProxy(userProxy,APILocator.getUserAPI().getSystemUser(), false);
userProxyInode = userProxy.getInode();
// adding roles to user
Permission permission = null;
if (readPermissions != null) {
for (int n = 0; n < readPermissions.length; n++) {
permission = new Permission(userProxyInode, readPermissions[n], PERMISSION_READ);
permissionAPI.save(permission, userProxy, systemUser, false);
}
}
if (writePermissions != null) {
for (int n = 0; n < writePermissions.length; n++) {
permission = new Permission(userProxyInode, writePermissions[n], PERMISSION_WRITE);
permissionAPI.save(permission, userProxy, systemUser, false);
}
}
Date today = new Date();
Address address = PublicAddressFactory.getInstance();
address.setUserName(user.getFullName());
address.setCompanyId(companyId);
address.setUserId(user.getUserId());
address.setCreateDate(today);
address.setModifiedDate(today);
address.setPriority(1);
address.setClassName(user.getClass().getName());
address.setClassPK(user.getUserId());
address.setDescription("Primary");
address.setStreet1(street1);
address.setStreet2(street2);
address.setCountry(country);
address.setCity(city);
address.setState(state);
address.setZip(zip);
address.setPhone(phone);
address.setFax(fax);
address.setCell(cell);
PublicAddressFactory.save(address);
// creating tag users
if (UtilMethods.isSet(userForm.getTagName())) {
StringTokenizer tagNameToken = new StringTokenizer(userForm.getTagName(), ",");
if (tagNameToken.hasMoreTokens()) {
for (; tagNameToken.hasMoreTokens();) {
String tagTokenized = tagNameToken.nextToken().trim();
TagFactory.addTag(tagTokenized, user.getUserId(),"");
}
}
}
for (String roleId : roles) {
com.dotmarketing.business.APILocator.getRoleAPI().addRoleToUser(roleId, user);
}
userCreated++;
userTaged++;
arrayUserIds.add(user.getUserId());
} else {
// email duplicated
if (userForm.isUpdateDuplicatedUsers()) {
if (UtilMethods.isSet(firstName))
userDuplicated.setFirstName(firstName);
if (UtilMethods.isSet(middleName))
userDuplicated.setMiddleName(middleName);
if (UtilMethods.isSet(lastName))
userDuplicated.setLastName(lastName);
userDuplicated
.setGreeting("Welcome, " + userDuplicated.getFirstName() + " " + userDuplicated.getLastName() + "!");
if (UtilMethods.isSet(email))
userDuplicated.setEmailAddress(email.trim().toLowerCase());
if (UtilMethods.isSet(birthday))
userDuplicated.setBirthday(birthday);
if (UtilMethods.isSet(password)) {
userDuplicated.setPassword(PublicEncryptionFactory.digestString(password));
userDuplicated.setPasswordEncrypted(true);
}
APILocator.getUserAPI().save(userDuplicated,APILocator.getUserAPI().getSystemUser(),false);
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(userDuplicated,APILocator.getUserAPI().getSystemUser(), false);
// getting and saving the user
// additional info
String userAdditionalInfo = "";
for (int j = 1; j <= numberGenericVariables; j++) {
try {
userAdditionalInfo = lineTok[i++];
} catch (Exception e) {
userAdditionalInfo = "";
}
if (!userAdditionalInfo.equalsIgnoreCase("")) {
userProxy.setVar(j, userAdditionalInfo);
}
}
com.dotmarketing.business.APILocator.getUserProxyAPI().saveUserProxy(userProxy,APILocator.getUserAPI().getSystemUser(), false);
String userProxyInode = userProxy.getInode();
permissionAPI.removePermissions(userProxy);
// adding roles to user
if (readPermissions != null) {
for (int n = 0; n < readPermissions.length; n++) {
permissionAPI.save(new Permission(userProxyInode, readPermissions[n], PERMISSION_READ), userProxy, systemUser, false);
}
}
if (writePermissions != null) {
for (int n = 0; n < writePermissions.length; n++) {
permissionAPI.save(new Permission(userProxyInode, writePermissions[n], PERMISSION_WRITE), userProxy, systemUser, false);
}
}
Address address = null;
List<Address> addresses = PublicAddressFactory.getAddressesByUserId(userDuplicated.getUserId());
for (int pos = 0; pos < addresses.size(); ++pos) {
if ((addresses.get(pos).getDescription() != null) && (addresses.get(pos).getDescription().equals("Primary"))) {
address = addresses.get(pos);
break;
}
}
Date today = new Date();
if (address == null) {
address = PublicAddressFactory.getInstance();
address.setUserName(userDuplicated.getFullName());
address.setCompanyId(companyId);
address.setUserId(userDuplicated.getUserId());
address.setCreateDate(today);
address.setModifiedDate(today);
address.setPriority(1);
address.setClassName(userDuplicated.getClass().getName());
address.setClassPK(userDuplicated.getUserId());
address.setDescription("Primary");
address.setStreet1(street1);
address.setStreet2(street2);
address.setCountry(country);
address.setCity(city);
address.setState(state);
address.setZip(zip);
address.setPhone(phone);
address.setFax(fax);
address.setCell(cell);
} else {
address.setModifiedDate(today);
if (UtilMethods.isSet(street1))
address.setStreet1(street1);
if (UtilMethods.isSet(street2))
address.setStreet2(street2);
if (UtilMethods.isSet(country))
address.setCountry(country);
if (UtilMethods.isSet(city))
address.setCity(city);
if (UtilMethods.isSet(state))
address.setState(state);
if (UtilMethods.isSet(zip))
address.setZip(zip);
if (UtilMethods.isSet(phone))
address.setPhone(phone);
if (UtilMethods.isSet(fax))
address.setFax(fax);
if (UtilMethods.isSet(cell))
address.setCell(cell);
}
PublicAddressFactory.save(address);
for (String roleId : roles) {
com.dotmarketing.business.APILocator.getRoleAPI().addRoleToUser(roleId, userDuplicated);
}
countUserDuplicated++;
} else {
if (!someError) {
returnMessage.append(LanguageUtil.get(com.liferay.portal.util.PortalUtil.getUser(req), "Errors-loading-users-br-br"));
someError = true;
}
returnMessage.append(LanguageUtil.get(com.liferay.portal.util.PortalUtil.getUser(req), "Duplicated-Email")+": " + email + " "+LanguageUtil.get(com.liferay.portal.util.PortalUtil.getUser(req), "user.duplicated.email.line")+" " + lineNumber + "<br>");
}
if (UtilMethods.isSet(userForm.getTagName())) {
StringTokenizer tagNameToken = new StringTokenizer(userForm.getTagName(), ",");
if (tagNameToken.hasMoreTokens()) {
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(userDuplicated,APILocator.getUserAPI().getSystemUser(), false);
for (; tagNameToken.hasMoreTokens();) {
String tagTokenized = tagNameToken.nextToken().trim();
TagFactory.addTagInode(tagTokenized, String.valueOf(userProxy.getUserId()), "");
}
}
}
arrayUserIds.add(userDuplicated.getUserId());