Search in sources :

Example 1 with Person

use of org.alfresco.rest.api.model.Person in project alfresco-remote-api by Alfresco.

the class PeopleImpl method getPersonWithProperties.

private Person getPersonWithProperties(String personId, List<String> include) {
    Person person = null;
    NodeRef personNode = personService.getPerson(personId, false);
    if (personNode != null) {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(personNode);
        processPersonProperties(personId, nodeProps);
        // TODO this needs to be run as admin but should we do this here?
        final String pId = personId;
        Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork<Boolean>() {

            public Boolean doWork() throws Exception {
                return authenticationService.getAuthenticationEnabled(pId);
            }
        });
        person = new Person(personNode, nodeProps, enabled);
        // Remove the temporary property used to help inline the person description content property.
        // It may be accessed from the person object (person.getDescription()).
        nodeProps.remove(Person.PROP_PERSON_DESCRIPTION);
        // Expose properties
        if (include.contains(PARAM_INCLUDE_PROPERTIES)) {
            // Note that custProps may be null.
            Map<String, Object> custProps = nodes.mapFromNodeProperties(nodeProps, new ArrayList<>(), new HashMap<>(), EXCLUDED_NS, EXCLUDED_PROPS);
            person.setProperties(custProps);
        }
        if (include.contains(PARAM_INCLUDE_ASPECTNAMES)) {
            // Expose aspect names
            Set<QName> aspects = nodeService.getAspects(personNode);
            person.setAspectNames(nodes.mapFromNodeAspects(aspects, EXCLUDED_NS, EXCLUDED_ASPECTS));
        }
        if (include.contains(PARAM_INCLUDE_CAPABILITIES)) {
            // Expose capabilities
            Map<String, Boolean> capabilities = new HashMap<>(3);
            capabilities.put("isAdmin", isAdminAuthority(personId));
            capabilities.put("isGuest", isGuestAuthority(personId));
            capabilities.put("isMutable", isMutableAuthority(personId));
            person.setCapabilities(capabilities);
        }
        // get avatar information
        if (hasAvatar(personNode)) {
            try {
                NodeRef avatar = getAvatar(personId);
                person.setAvatarId(avatar);
            } catch (EntityNotFoundException e) {
            // shouldn't happen, but ok
            }
        }
    } else {
        throw new EntityNotFoundException(personId);
    }
    return person;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) ResetPasswordWorkflowInvalidUserException(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowInvalidUserException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) ResetPasswordWorkflowException(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Person(org.alfresco.rest.api.model.Person)

Example 2 with Person

use of org.alfresco.rest.api.model.Person in project alfresco-remote-api by Alfresco.

the class PeopleImpl method getPerson.

public Person getPerson(String personId, List<String> include) {
    personId = validatePerson(personId);
    Person person = getPersonWithProperties(personId, include);
    return person;
}
Also used : Person(org.alfresco.rest.api.model.Person)

Example 3 with Person

use of org.alfresco.rest.api.model.Person in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method getSiteMembershipRequest.

private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation, boolean includePersonDetails) {
    SiteMembershipRequest siteMembershipRequest = null;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (resourceType.equals(ResourceType.WEB_SITE)) {
        final String siteId = moderatedInvitation.getResourceName();
        SiteInfo siteInfo = AuthenticationUtil.runAsSystem(new RunAsWork<SiteInfo>() {

            @Override
            public SiteInfo doWork() throws Exception {
                SiteInfo siteInfo = sites.validateSite(siteId);
                return siteInfo;
            }
        });
        if (siteInfo == null) {
            // site does not exist
            throw new EntityNotFoundException(siteId);
        }
        if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
            // return a site membership request only if this is a moderated site
            siteMembershipRequest = new SiteMembershipRequest();
            String title = siteInfo.getTitle();
            siteMembershipRequest.setTitle(title);
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
            siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
            siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
            if (includePersonDetails) {
                Person person = people.getPerson(moderatedInvitation.getInviteeUserName());
                siteMembershipRequest.setPerson(person);
            }
        }
    } else {
        logger.warn("Unexpected resource type " + resourceType + " for site membership request");
    }
    return siteMembershipRequest;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) Person(org.alfresco.rest.api.model.Person) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 4 with Person

use of org.alfresco.rest.api.model.Person in project alfresco-remote-api by Alfresco.

the class PeopleEntityResource method create.

@Override
@WebApiDescription(title = "Create person", description = "Create a person")
@WebApiParam(name = "persons", title = "A single person", description = "A single person, multiple people are not supported.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple = false, required = true)
public List<Person> create(List<Person> persons, Parameters parameters) {
    Person p = persons.get(0);
    validateDerivedFieldsExistence(p);
    List<Person> result = new ArrayList<>(1);
    result.add(people.create(p));
    return result;
}
Also used : ArrayList(java.util.ArrayList) Person(org.alfresco.rest.api.model.Person) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 5 with Person

use of org.alfresco.rest.api.model.Person in project alfresco-remote-api by Alfresco.

the class PeopleImpl method getPerson.

/**
 * Get a full representation of a person.
 *
 * @throws NoSuchPersonException
 *             if personId does not exist
 */
@Override
public Person getPerson(String personId) {
    personId = validatePerson(personId);
    List<String> include = Arrays.asList(PARAM_INCLUDE_ASPECTNAMES, PARAM_INCLUDE_PROPERTIES, PARAM_INCLUDE_CAPABILITIES);
    Person person = getPersonWithProperties(personId, include);
    return person;
}
Also used : Person(org.alfresco.rest.api.model.Person)

Aggregations

Person (org.alfresco.rest.api.model.Person)7 Serializable (java.io.Serializable)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 QName (org.alfresco.service.namespace.QName)2 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 PagingRequest (org.alfresco.query.PagingRequest)1 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)1 ResetPasswordWorkflowException (org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowException)1 ResetPasswordWorkflowInvalidUserException (org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowInvalidUserException)1 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)1 Comment (org.alfresco.rest.api.model.Comment)1 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)1 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)1 WebApiParam (org.alfresco.rest.framework.WebApiParam)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1