cancel
Showing results for 
Search instead for 
Did you mean: 

[solved] NewUserWizard does not rely on PersonService...

zomurn
Champ in-the-making
Champ in-the-making
I constated something strange : NewUserWizard is much more complex that PersonService.createPerson.
Particularly, NewUserWizard (executed from admin console) create a node with Path :

PATH:"/app:company_home/app:user_homes/sys:KXJWX/*"

where "KXJWX" is the homeSpaceName.

where as createPerson create a node with Path :

PATH:"/app:company_home/app:user_homes/cm:KXJWX/*"

Furthermore, createPerson considers the username+HomeSpaceName equals to the specified username if any (through parameters), where as NewUserWizard distinguish them.
It is strange that presentation layer do such complex task …
JUnit code, to create random users, might be more complex than I though…
1 REPLY 1

zomurn
Champ in-the-making
Champ in-the-making
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;
   }

Above, a randomUser method.
I needed to swap the HomeFolderRef so to be conformed to NewUserWizard webclient.

NB : pInitiales is the homeSpaceName