How can I enable user account at the time of creation using JAVA Webscript?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

How can I enable user account at the time of creation using JAVA Webscript?

Hi All,

I want to create users from the csv file which will be available on alfresco repository. I created a JAVA Webscript for that but I am not able to set its account enabled through java. Like in javascript 

var testUser = people.createPerson("spm", "Joe", "User", "joe.user@alfresco.com", "spm", true, true);

the second last argument refers to the setAccountEnabled param but in java we need to create Map instead of passing the value in params like 

Map userMap = new HashMap();
userMap.put(ContentModel.PROP_USERNAME, user.getUserName());
userMap.put(ContentModel.PROP_FIRSTNAME, user.getFirstName());
userMap.put(ContentModel.PROP_LASTNAME, user.getLastName());
userMap.put(ContentModel.PROP_EMAIL, user.getEmailAddress());
userMap.put(ContentModel.PROP_PASSWORD, user.getPassword());

So here I am not able to find the QName for the setAcountEnabled property and because of that users are created in alfresco but I am not able to login through their id.

Is there any possible way to do that?

Thanks and Regards,

Neha

1 Reply
Highlighted
Professional

Re: How can I enable user account at the time of creation using JAVA Webscript?

I don't see anything in the JavaDoc or the source that would indicate that setting the enabled flag to true is required. I suspect it defaults to that.

In addition to creating the person object, are you also making a call to the authentication service? Take a look at: https://docs.alfresco.com/5.2/references/dev-services-person.html

Also, did you know that the Share admin console includes a CSV import? If you can find that implementation in the source it might have some helpful tidbits.

By the way, you can always create a QName if you know the namespace and the property name. If you knew the property you wanted is "enabled" and the namespace is Alfresco's User namespace, you could create the QName like:

QName PROP_ENABLED = QName.createQName("http://www.alfresco.org/model/user/1.0", "enabled");

But, if that's the property you are looking for, you don't have to create the QName yourself--it is already defined on the org.alfresco.model.ContentModel interface. Just import it.