Creating a Person - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Creating a person uses the createPerson method of the PeopleApi.

For more information about this ReST API endpoint, see Create a Person.

For a description of the common parameters, such as fields, see Common Parameters.

import org.alfresco.core.handler.PeopleApi;
import org.alfresco.core.model.PersonBodyCreate;
import org.alfresco.core.model.PersonEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
public class CreatePersonCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(CreatePersonCmd.class);

    @Autowired
    PeopleApi peopleApi;

    public void execute(String username, String pwd, String firstname, String lastname, String email) throws IOException {
        List<String> fields = null;

        PersonBodyCreate personBodyCreate = new PersonBodyCreate();
        personBodyCreate.setId(username);
        personBodyCreate.setPassword(pwd);
        personBodyCreate.setFirstName(firstname);
        personBodyCreate.setLastName(lastname);
        personBodyCreate.setEmail(email);
        PersonEntry person = peopleApi.createPerson(personBodyCreate, fields).getBody();
        LOGGER.info("Created person  {}", person);
    }
}

Executing this code will add a user passed in username, pwd, first name, last name and email:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar create-person martin 1234 Martin Bergljung martin@example.com

2021-05-05 15:49:25.198  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.928 seconds (JVM running for 4.427)
2021-05-05 15:49:25.200  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: create-person
2021-05-05 15:49:25.201  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: martin
2021-05-05 15:49:25.201  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[2]: 1234
2021-05-05 15:49:25.201  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[3]: Martin
2021-05-05 15:49:25.201  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[4]: Bergljung
2021-05-05 15:49:25.201  INFO 22389 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[5]: martin@example.com
2021-05-05 15:49:25.830  INFO 22389 --- [           main] o.a.tutorial.restapi.CreatePersonCmd     : Created person  class PersonEntry {
    entry: class Person {
        id: martin
        firstName: Martin
        lastName: Bergljung
        displayName: Martin Bergljung
        description: null
        avatarId: null
        email: martin@example.com
        skypeId: null
        googleId: null
        instantMessageId: null
        jobTitle: null
        location: null
        company: class Company {
            organization: null
            address1: null
            address2: null
            address3: null
            postcode: null
            telephone: null
            fax: null
            email: null
        }
        mobile: null
        telephone: null
        statusUpdatedAt: null
        userStatus: null
        enabled: true
        emailNotificationsEnabled: true
        aspectNames: null
        properties: null
        capabilities: class Capabilities {
            isAdmin: false
            isGuest: false
            isMutable: true
        }
    }
}