Getting Person Metadata - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Getting metadata for a person involves a number of API calls:

  • PeopleApi.getPerson
  • PeopleApi.getAvatarImage
  • PreferencesApi.listPreferences
  • PreferencesApi.getPreference

For more information about this ReST API endpoint, see Get Person Metadata.

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

import org.alfresco.core.handler.PeopleApi;
import org.alfresco.core.handler.PreferencesApi;
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 GetPersonMetadataCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(GetPersonMetadataCmd.class);

    @Autowired
    PeopleApi peopleApi;

    @Autowired
    PreferencesApi preferencesApi;

    public void execute(String personId) throws IOException {
        Integer skipCount = 0;
        Integer maxItems = 100;
        List<String> fields = null;

        PersonEntry person = peopleApi.getPerson(personId, fields).getBody();
        LOGGER.info("Got person metadata {}", person);
        PreferencePaging preferencePaging = preferencesApi.listPreferences(personId, skipCount, maxItems, fields).getBody();
        LOGGER.info("Got person preferences:");
        for (PreferenceEntry preferenceEntry: preferencePaging.getList().getEntries()) {
            LOGGER.info("  preference: {}", preferenceEntry.getEntry());
        }
    }
}

Executing this code will list the metadata for the user including any preferences. In the following example we list metadata for the out-of-the-box user abeecher:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar get-person-metadata abeecher

2021-05-05 16:06:50.550  INFO 22610 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.396 seconds (JVM running for 3.893)
2021-05-05 16:06:50.552  INFO 22610 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: get-person-metadata
2021-05-05 16:06:50.553  INFO 22610 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: abeecher
2021-05-05 16:06:50.787  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       : Got person metadata class PersonEntry {
    entry: class Person {
        id: abeecher
        firstName: Alice
        lastName: Beecher
        displayName: Alice Beecher
        description: Alice is a demo user for the sample Alfresco Team site.
        avatarId: 198500fc-1e99-4f5f-8926-248cea433366
        email: abeecher@example.com
        skypeId: abeecher
        googleId: null
        instantMessageId: null
        jobTitle: Graphic Designer
        location: Tilbury, UK
        company: class Company {
            organization: Moresby, Garland and Wedge
            address1: 200 Butterwick Street
            address2: Tilbury
            address3: UK
            postcode: ALF1 SAM1
            telephone: null
            fax: null
            email: null
        }
        mobile: 0112211001100
        telephone: 0112211001100
        statusUpdatedAt: 2011-02-15T20:20:13.432Z
        userStatus: Helping to design the look and feel of the new web site
        enabled: false
        emailNotificationsEnabled: true
        aspectNames: null
        properties: null
        capabilities: class Capabilities {
            isAdmin: false
            isGuest: false
            isMutable: true
        }
    }
}
2021-05-05 16:06:50.849  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       : Got person preferences:
2021-05-05 16:06:50.849  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.documentList.showFolders
    value: true
}
2021-05-05 16:06:50.849  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.documentList.simpleView
    value: false
}
2021-05-05 16:06:50.849  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.documentList.sortField
    value: cm:name
}
2021-05-05 16:06:50.849  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.documents.favourites
    value: workspace://SpacesStore/7c7bca1d-b65d-4444-9378-805b459fb74d,workspace://SpacesStore/b2f21ddd-0b0e-449f-bea9-a0be73e7d67b,workspace://SpacesStore/2cf35860-6705-42c3-b123-c4d6b39997b4,workspace://SpacesStore/7d90c94c-fcf7-4f79-9273-bd1352bbb612,workspace://SpacesStore/05dedd34-9d9d-48d9-9af6-c81b555541c9
}
2021-05-05 16:06:50.850  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.sites.favourites.test
    value: true
}
2021-05-05 16:06:50.850  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.sites.recent._0
    value: swsdp
}
2021-05-05 16:06:50.850  INFO 22610 --- [           main] o.a.t.restapi.GetPersonMetadataCmd       :   preference: class Preference {
    id: org.alfresco.share.twisters.collapsed
    value: DocumentPermissions,DocumentWorkflows,DocumentLinks,DocumentActions
}