Search in sources :

Example 1 with RelationshipResourceNotFoundException

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

the class FavouritesImpl method getFavourite.

@Override
public Favourite getFavourite(String personId, String favouriteId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateNode(favouriteId);
    personId = people.validatePerson(personId, true);
    PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
    if (personFavourite != null) {
        Favourite favourite = getFavourite(personFavourite, parameters);
        return favourite;
    } else {
        throw new RelationshipResourceNotFoundException(personId, favouriteId);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 2 with RelationshipResourceNotFoundException

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

the class FavouritesImpl method addFavourite.

@Override
public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters) {
    Favourite ret = null;
    personId = people.validatePerson(personId, true);
    Target target = favourite.getTarget();
    if (target == null) {
        throw new InvalidArgumentException("target is missing");
    } else if (target instanceof SiteTarget) {
        SiteTarget siteTarget = (SiteTarget) target;
        String guid = siteTarget.getSite().getGuid();
        SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
        NodeRef siteNodeRef = siteInfo.getNodeRef();
        String siteId = siteInfo.getShortName();
        try {
            PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
            ret = getFavourite(personFavourite, parameters);
        } catch (SiteDoesNotExistException e) {
            throw new RelationshipResourceNotFoundException(personId, siteId);
        }
    } else if (target instanceof DocumentTarget) {
        DocumentTarget documentTarget = (DocumentTarget) target;
        NodeRef nodeRef = documentTarget.getFile().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null)) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    } else if (target instanceof FolderTarget) {
        FolderTarget folderTarget = (FolderTarget) target;
        NodeRef nodeRef = folderTarget.getFolder().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE))) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    }
    return ret;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteTarget(org.alfresco.rest.api.model.SiteTarget) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) Target(org.alfresco.rest.api.model.Target) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) SiteDoesNotExistException(org.alfresco.repo.site.SiteDoesNotExistException) SiteTarget(org.alfresco.rest.api.model.SiteTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 3 with RelationshipResourceNotFoundException

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

the class SiteMembershipRequestsImpl method approveSiteMembershipRequest.

@Override
public void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval) {
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        throw new EntityNotFoundException(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();
    // Validate invitation.
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
        // note: security, no indication that this has a different visibility
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    try {
        invitationService.approve(invitation.getInviteId(), "");
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
    // approval role differs from default one.
    if (siteMembershipApproval != null && !(siteMembershipApproval.getRole() == null || siteMembershipApproval.getRole().isEmpty())) {
        String role = siteMembershipApproval.getRole();
        // Check if role chosen by moderator differs from the invite role.
        if (!moderatedInvitation.getRoleName().equals(role)) {
            String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            // Update invitation with new role.
            try {
                addSiteMembership(invitation.getInviteeUserName(), siteId, role, currentUserId);
            } catch (UnknownAuthorityException e) {
                logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + invitation.getInviteId() + " role " + role);
                throw new InvalidArgumentException("Unknown role '" + role + "'");
            }
        }
    }
}
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) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 4 with RelationshipResourceNotFoundException

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

the class SiteMembershipRequestsImpl method cancelSiteMembershipRequest.

@Override
public void cancelSiteMembershipRequest(String inviteeId, String siteId) {
    inviteeId = people.validatePerson(inviteeId);
    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();
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation == null) {
        // no such invitation
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    invitationService.cancel(invitation.getInviteId());
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation)

Example 5 with RelationshipResourceNotFoundException

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

the class SiteMembershipRequestsImpl method createSiteMembershipRequest.

@Override
public SiteMembershipRequest createSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
    SiteMembershipRequest request = null;
    inviteeId = people.validatePerson(inviteeId, true);
    // Note that the order of error checking is important. The server first needs to check for the status 404
    // conditions before checking for status 400 conditions. Otherwise the server is open to a probing attack.
    String siteId = siteInvite.getId();
    final 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();
    final SiteVisibility siteVisibility = siteInfo.getVisibility();
    if (siteVisibility.equals(SiteVisibility.PRIVATE)) {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    // Is the invitee already a member of the site?
    boolean isMember = siteService.isMember(siteId, inviteeId);
    if (isMember) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already a member of site " + siteId);
    }
    // Is there an outstanding site invite request for the (invitee, site)?
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation != null) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already invited to site " + siteId);
    }
    final String inviteeRole = DEFAULT_ROLE;
    String message = siteInvite.getMessage();
    if (message == null) {
        // the invitation service ignores null messages so convert to an empty message.
        message = "";
    }
    if (siteVisibility.equals(SiteVisibility.MODERATED)) {
        request = inviteToModeratedSite(message, inviteeId, siteId, inviteeRole);
    } else if (siteVisibility.equals(SiteVisibility.PUBLIC)) {
        request = inviteToPublicSite(siteInfo, message, inviteeId, inviteeRole);
    } else {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    return request;
}
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) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility)

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