Updating metadata for a person involves these two API calls:
- PeopleApi.updatePerson
- PeopleApi.updateAvatarImage
For more information about this ReST API endpoint, see Update 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.*; 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 UpdatePersonMetadataCmd { static final Logger LOGGER = LoggerFactory.getLogger(UpdatePersonMetadataCmd.class); @Autowired PeopleApi peopleApi; public void execute(String personId) throws IOException { List<String> fields = null; PersonBodyUpdate personBodyUpdate = new PersonBodyUpdate(); // Mandatory fields during an update personBodyUpdate.setFirstName("Martin"); personBodyUpdate.setLastName("Bergljung"); personBodyUpdate.setEmail("martin@example.com"); personBodyUpdate.setEmailNotificationsEnabled(true); personBodyUpdate.setOldPassword("1234"); personBodyUpdate.setPassword("1234"); personBodyUpdate.setEnabled(true); // Other fields personBodyUpdate.setJobTitle("Techie"); Company company = new Company(); company.setAddress1("Alfresco way 1"); company.setOrganization("Alfresco Org"); company.setTelephone("12345678"); personBodyUpdate.setCompany(company); PersonEntry person = peopleApi.updatePerson(personId, personBodyUpdate, fields).getBody(); LOGGER.info("Updated person metadata {}", person); } }
Executing this code will update the user martin with some new company information, there are a number of fields that are mandatory that you need to set, so might be best to read them first and then set them:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar update-person-metadata martin 2021-05-06 09:16:41.833 INFO 24158 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.151 seconds (JVM running for 3.596) 2021-05-06 09:16:41.835 INFO 24158 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: update-person-metadata 2021-05-06 09:16:41.837 INFO 24158 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: martin 2021-05-06 09:16:42.111 INFO 24158 --- [ main] o.a.t.restapi.UpdatePersonMetadataCmd : Updated person metadata 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: Techie location: null company: class Company { organization: Alfresco Org address1: Alfresco way 1 address2: null address3: null postcode: null telephone: 12345678 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 } } }