Search in sources :

Example 11 with RelationshipResourceNotFoundException

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

the class FavouritesImpl method removeFavourite.

@Override
public void removeFavourite(String personId, String id) {
    personId = people.validatePerson(personId, true);
    NodeRef nodeRef = nodes.validateNode(id);
    boolean exists = false;
    Type type = favouritesService.getType(nodeRef);
    if (type.equals(Type.SITE)) {
        SiteInfo siteInfo = siteService.getSite(nodeRef);
        if (siteInfo == null) {
            // shouldn't happen because the type implies it's a site
            throw new AlfrescoRuntimeException("Unable to find site with nodeRef " + nodeRef);
        }
        exists = favouritesService.removeFavourite(personId, siteInfo.getNodeRef());
    } else if (type.equals(Type.FILE)) {
        exists = favouritesService.removeFavourite(personId, nodeRef);
    } else if (type.equals(Type.FOLDER)) {
        exists = favouritesService.removeFavourite(personId, nodeRef);
    }
    if (!exists) {
        throw new RelationshipResourceNotFoundException(personId, id);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 12 with RelationshipResourceNotFoundException

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

the class PreferencesImpl method getPreference.

public Preference getPreference(String personId, String preferenceName) {
    personId = people.validatePerson(personId);
    Serializable preferenceValue = preferenceService.getPreference(personId, preferenceName);
    if (preferenceValue != null) {
        return new Preference(preferenceName, preferenceValue);
    } else {
        throw new RelationshipResourceNotFoundException(personId, preferenceName);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) Serializable(java.io.Serializable) Preference(org.alfresco.rest.api.model.Preference)

Example 13 with RelationshipResourceNotFoundException

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

the class SiteMembershipRequestsImpl method rejectSiteMembershipRequest.

@Override
public void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection) {
    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);
    }
    String reason = null;
    if (siteMembershipRejection != null && !(siteMembershipRejection.getComment() == null || siteMembershipRejection.getComment().isEmpty())) {
        reason = siteMembershipRejection.getComment();
    }
    try {
        invitationService.reject(invitation.getInviteId(), reason);
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
}
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) 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)

Example 14 with RelationshipResourceNotFoundException

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

the class SitesImpl method getMemberOfSite.

/**
 * people/<personId>/sites/<siteId>
 *
 * @param siteId String
 * @param personId String
 * @return MemberOfSite
 */
public MemberOfSite getMemberOfSite(String personId, String siteId) {
    MemberOfSite siteMember = null;
    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();
    String roleStr = siteService.getMembersRole(siteInfo.getShortName(), personId);
    if (roleStr != null) {
        Site site = new Site(siteInfo, roleStr);
        siteMember = new MemberOfSite(site.getId(), siteInfo.getNodeRef(), roleStr);
    } else {
        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 15 with RelationshipResourceNotFoundException

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

the class SitesImpl method getFavouriteSite.

public FavouriteSite getFavouriteSite(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();
    NodeRef nodeRef = siteInfo.getNodeRef();
    if (favouritesService.isFavourite(personId, nodeRef)) {
        String role = getSiteRole(siteId, personId);
        return new FavouriteSite(siteInfo, role);
    } else {
        throw new RelationshipResourceNotFoundException(personId, siteId);
    }
}
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