03-04-2009 05:41 AM
03-04-2009 11:40 AM
private NodeRef randomUser(String pUsername, String pLastname,
String pInitiales) {
if (StringUtils.isEmpty( pUsername ))
{
pUsername = RandomStringUtils.randomAlphanumeric( (RandomUtils
.nextInt() % (USERNAME_MAX_LENGTH - USERNAME_MIN_LENGTH))
+ USERNAME_MIN_LENGTH );
}
if (StringUtils.isEmpty( pInitiales ))
{
pInitiales = RandomStringUtils.randomAlphanumeric( (RandomUtils
.nextInt() % (INITIALES_MAX_LENGTH - INITIALES_MIN_LENGTH))
+ INITIALES_MIN_LENGTH );
}
if (StringUtils.isEmpty( pLastname ))
{
pLastname = RandomStringUtils.randomAlphanumeric( (RandomUtils
.nextInt() % (LASTNAME_MAX_LENGTH - LASTNAME_MIN_LENGTH))
+ LASTNAME_MIN_LENGTH );
}
// creation du user de type cm:person
HashMap<QName, Serializable> lPersonMap = new HashMap<QName, Serializable>();
lPersonMap.put( ContentModel.PROP_USERNAME, pUsername );
lPersonMap.put( ContentModel.PROP_LASTNAME, pLastname );
NodeRef lPersonRef = personService.createPerson( lPersonMap );
// on copie le homefolder et on change le nom du dossier
NodeRef lHomeSpaceRef = (NodeRef) nodeService.getProperty( lPersonRef,
ContentModel.PROP_HOMEFOLDER );
Map<QName, Serializable> lHomeSpacePropMap = nodeService
.getProperties( lHomeSpaceRef );
lHomeSpacePropMap.put( ContentModel.PROP_NAME, pInitiales );
// creation conforme à la "NewUserWizard.finish()'
String qname = QName.createValidLocalName( pInitiales );
ChildAssociationRef assocRef = nodeService.createNode( nodeService
.getPrimaryParent( lHomeSpaceRef ).getParentRef(),
ContentModel.ASSOC_CONTAINS, QName.createQName(
NamespaceService.SYSTEM_MODEL_1_0_URI, qname ),
ContentModel.TYPE_FOLDER );
nodeService.setProperties( assocRef.getChildRef(), lHomeSpacePropMap );
nodeService.setProperty( lPersonRef, ContentModel.PROP_HOMEFOLDER,
assocRef.getChildRef() );
// on delete le homespaceRef original car plus besoin
nodeService.deleteNode( lHomeSpaceRef );
return lPersonRef;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.