Build fix and overhaul of (unused I think) createPerson method

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13990 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2009-04-17 09:56:13 +00:00
parent c38219e7b3
commit 04236a3706

View File

@@ -24,6 +24,7 @@
*/ */
package org.alfresco.repo.jscript; package org.alfresco.repo.jscript;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@@ -67,6 +68,7 @@ public final class People extends BaseScopableProcessorExtension
private UserNameGenerator usernameGenerator; private UserNameGenerator usernameGenerator;
private PasswordGenerator passwordGenerator; private PasswordGenerator passwordGenerator;
private StoreRef storeRef; private StoreRef storeRef;
private int numRetries = 10;
/** /**
@@ -167,6 +169,10 @@ public final class People extends BaseScopableProcessorExtension
/** /**
* Create a Person with a generated user name * Create a Person with a generated user name
* *
* @param firstName firstName
* @param lastName lastName
* @param emailAddress emailAddress
*
* @param createUserAccount * @param createUserAccount
* set to 'true' to create a user account for the person with the * set to 'true' to create a user account for the person with the
* generated user name and a generated password * generated user name and a generated password
@@ -176,41 +182,48 @@ public final class People extends BaseScopableProcessorExtension
* @return the person node (type cm:person) created or null if the person * @return the person node (type cm:person) created or null if the person
* could not be created * could not be created
*/ */
public ScriptNode createPerson(boolean createUserAccount, boolean setAccountEnabled) public ScriptNode createPerson(String firstName, String lastName, String emailAddress, boolean createUserAccount, boolean setAccountEnabled)
{ {
ParameterCheck.mandatory("firstName", firstName);
ParameterCheck.mandatory("lastName", lastName);
ParameterCheck.mandatory("createUserAccount", createUserAccount); ParameterCheck.mandatory("createUserAccount", createUserAccount);
ParameterCheck.mandatory("setAccountEnabled", setAccountEnabled); ParameterCheck.mandatory("setAccountEnabled", setAccountEnabled);
ScriptNode person = null; ScriptNode person = null;
// generate user name // generate user name
String userName = usernameGenerator.generateUserName(); for(int i=0; i < numRetries; i++)
// create person if user name does not already exist
if (!personService.personExists(userName))
{ {
person = createPerson(userName); String userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i);
// create person if user name does not already exist
if (!personService.personExists(userName))
{
person = createPerson(userName, firstName, lastName, emailAddress);
if (createUserAccount) if (createUserAccount)
{ {
// generate password // generate password
char[] password = passwordGenerator.generatePassword().toCharArray(); char[] password = passwordGenerator.generatePassword().toCharArray();
// create account for person with generated userName and // create account for person with generated userName and
// password // password
mutableAuthenticationDao.createUser(userName, password); mutableAuthenticationDao.createUser(userName, password);
mutableAuthenticationDao.setEnabled(userName, setAccountEnabled); mutableAuthenticationDao.setEnabled(userName, setAccountEnabled);
// TODO glen johnson at alfresco dot com - // TODO glen johnson at alfresco dot com -
// find a more secure way of making generated password // find a more secure way of making generated password
// available. I need to make it available for the invite // available. I need to make it available for the invite
// workflow/service // workflow/service
person.getProperties().put("generatedPassword", new String(password)); person.getProperties().put("generatedPassword", new String(password));
person.save(); person.save();
} }
return person;
}
} }
return person; return null;
} }
/** /**
@@ -275,6 +288,36 @@ public final class People extends BaseScopableProcessorExtension
return person; return person;
} }
/**
* Create a Person with the given user name, firstName, lastName and emailAddress
*
* @param userName the user name of the person to create
* @return the person node (type cm:person) created or null if the user name already exists
*/
public ScriptNode createPerson(String userName, String firstName, String lastName, String emailAddress)
{
ParameterCheck.mandatoryString("userName", userName);
ParameterCheck.mandatoryString("firstName", firstName);
ParameterCheck.mandatoryString("lastName", lastName);
ParameterCheck.mandatoryString("emailAddress", emailAddress);
ScriptNode person = null;
PropertyMap properties = new PropertyMap();
properties.put(ContentModel.PROP_USERNAME, userName);
properties.put(ContentModel.PROP_FIRSTNAME, firstName);
properties.put(ContentModel.PROP_LASTNAME, lastName);
properties.put(ContentModel.PROP_EMAIL, emailAddress);
if (!personService.personExists(userName))
{
NodeRef personRef = personService.createPerson(properties);
person = new ScriptNode(personRef, services, getScope());
}
return person;
}
/** /**
* Get the collection of people stored in the repository. * Get the collection of people stored in the repository.
* An optional filter query may be provided by which to filter the people collection. * An optional filter query may be provided by which to filter the people collection.