Search in sources :

Example 6 with RelationshipResourceNotFoundException

use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method getSiteMembershipRequest.

public SiteMembershipRequest getSiteMembershipRequest(String inviteeId, final String siteId) {
    inviteeId = people.validatePerson(inviteeId);
    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 RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
        // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
        String normalizedSiteId = siteInfo.getShortName();
        Invitation invitation = getSiteInvitation(inviteeId, normalizedSiteId);
        if (invitation == null) {
            // no such invitation
            throw new RelationshipResourceNotFoundException(inviteeId, normalizedSiteId);
        }
        if (invitation instanceof ModeratedInvitation) {
            ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
            SiteMembershipRequest siteInvite = getSiteMembershipRequest(moderatedInvitation);
            return siteInvite;
        } else {
            throw new InvalidArgumentException("Expected moderated invitation");
        }
    } else {
        // non-moderated sites cannot appear in a site membership request, so throw an exception
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) 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 7 with RelationshipResourceNotFoundException

use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method updateSiteMembershipRequest.

@Override
public SiteMembershipRequest updateSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
    SiteMembershipRequest updatedSiteInvite = null;
    inviteeId = people.validatePerson(inviteeId, true);
    String siteId = siteInvite.getId();
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    String message = siteInvite.getMessage();
    if (message == null) {
        // the invitation service ignores null messages so convert to an empty message.
        message = "";
    }
    try {
        ModeratedInvitation updatedInvitation = invitationService.updateModeratedInvitation(inviteeId, siteId, message);
        if (updatedInvitation == null) {
            throw new RelationshipResourceNotFoundException(inviteeId, siteId);
        }
        updatedSiteInvite = getSiteMembershipRequest(updatedInvitation);
    } catch (InvitationExceptionNotFound e) {
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    if (updatedSiteInvite == null) {
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    return updatedSiteInvite;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionNotFound(org.alfresco.service.cmr.invitation.InvitationExceptionNotFound) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest)

Example 8 with RelationshipResourceNotFoundException

use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSiteMember.

public SiteMember getSiteMember(String personId, String siteId) {
    SiteMember siteMember = null;
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        logger.debug("Site does not exist: " + siteId);
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    siteId = siteInfo.getShortName();
    logger.debug("Getting member role for " + siteId + " person " + personId);
    String role = siteService.getMembersRole(siteId, personId);
    if (role != null) {
        siteMember = new SiteMember(personId, role);
    } else {
        logger.debug("Getting member role but role is null");
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    return siteMember;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 9 with RelationshipResourceNotFoundException

use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method removeSiteMember.

public void removeSiteMember(String personId, String siteId) {
    personId = people.validatePerson(personId);
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    boolean isMember = siteService.isMember(siteId, personId);
    if (!isMember) {
        throw new InvalidArgumentException();
    }
    String role = siteService.getMembersRole(siteId, personId);
    if (role != null) {
        if (role.equals(SiteModel.SITE_MANAGER)) {
            int numAuthorities = siteService.countAuthoritiesWithRole(siteId, SiteModel.SITE_MANAGER);
            if (numAuthorities <= 1) {
                throw new InvalidArgumentException("Can't remove last manager of site " + siteId);
            }
            siteService.removeMembership(siteId, personId);
        } else {
            siteService.removeMembership(siteId, personId);
        }
    } else {
        throw new AlfrescoRuntimeException("Unable to determine role of site member");
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 10 with RelationshipResourceNotFoundException

use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSiteContainer.

public SiteContainer getSiteContainer(String siteId, String containerId) {
    // check site and container node validity
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    NodeRef containerNodeRef = siteService.getContainer(siteId, containerId);
    if (containerNodeRef == null) {
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    }
    // check that the containerId is actually a container for the specified site
    SiteInfo testSiteInfo = siteService.getSite(containerNodeRef);
    if (testSiteInfo == null) {
        throw new RelationshipResourceNotFoundException(siteId, containerId);
    } else {
        if (!testSiteInfo.getShortName().equals(siteId)) {
            throw new RelationshipResourceNotFoundException(siteId, containerId);
        }
    }
    String folderId = (String) nodeService.getProperty(containerNodeRef, SiteModel.PROP_COMPONENT_ID);
    SiteContainer siteContainer = new SiteContainer(folderId, containerNodeRef);
    return siteContainer;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Aggregations

RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)17 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)14 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)6 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)5 Invitation (org.alfresco.service.cmr.invitation.Invitation)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)3 PersonFavourite (org.alfresco.repo.favourites.PersonFavourite)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 Favourite (org.alfresco.rest.api.model.Favourite)2 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)2 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)2 InvitationExceptionForbidden (org.alfresco.service.cmr.invitation.InvitationExceptionForbidden)2 Serializable (java.io.Serializable)1 FormNotFoundException (org.alfresco.repo.forms.FormNotFoundException)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1