Search in sources :

Example 26 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException 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 27 with EntityNotFoundException

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

the class SitesImpl method getSiteMembers.

public CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteId, Parameters parameters) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        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();
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    final List<Pair<SiteService.SortFields, Boolean>> sort = new ArrayList<Pair<SiteService.SortFields, Boolean>>();
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.LastName, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.FirstName, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Role, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Username, Boolean.TRUE));
    PagingResults<SiteMembership> pagedResults = siteService.listMembersPaged(siteId, true, sort, pagingRequest);
    List<SiteMembership> siteMembers = pagedResults.getPage();
    List<SiteMember> ret = new ArrayList<SiteMember>(siteMembers.size());
    for (SiteMembership siteMembership : siteMembers) {
        SiteMember siteMember = new SiteMember(siteMembership.getPersonId(), siteMembership.getRole());
        ret.add(siteMember);
    }
    return CollectionWithPagingInfo.asPaged(paging, ret, pagedResults.hasMoreItems(), null);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) PagingRequest(org.alfresco.query.PagingRequest) SiteMembership(org.alfresco.repo.site.SiteMembership) SiteService(org.alfresco.service.cmr.site.SiteService) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 28 with EntityNotFoundException

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

the class SitesImpl method updateSiteMember.

public SiteMember updateSiteMember(String siteId, SiteMember siteMember) {
    String siteMemberId = siteMember.getPersonId();
    if (siteMemberId == null) {
        throw new InvalidArgumentException("Member id is null");
    }
    siteMemberId = people.validatePerson(siteMemberId);
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    siteId = siteInfo.getShortName();
    String siteRole = siteMember.getRole();
    if (siteRole == null) {
        throw new InvalidArgumentException("Must provide a role");
    }
    /* MNT-10551 : fix */
    if (!siteService.isMember(siteId, siteMember.getPersonId())) {
        throw new InvalidArgumentException("User is not a member of the site");
    }
    try {
        siteService.setMembership(siteId, siteMember.getPersonId(), siteRole);
    } catch (UnknownAuthorityException e) {
        throw new InvalidArgumentException("Unknown role '" + siteRole + "'");
    }
    return siteMember;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 29 with EntityNotFoundException

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

the class SitesImpl method addSiteMember.

public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
    String personId = people.validatePerson(siteMember.getPersonId());
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        logger.debug("addSiteMember:  site does not exist " + siteId + " person " + personId);
        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();
    String role = siteMember.getRole();
    if (role == null) {
        logger.debug("addSiteMember:  Must provide a role " + siteMember);
        throw new InvalidArgumentException("Must provide a role");
    }
    if (siteService.isMember(siteId, personId)) {
        logger.debug("addSiteMember:  " + personId + " is already a member of site " + siteId);
        throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
    }
    if (!siteService.canAddMember(siteId, personId, role)) {
        logger.debug("addSiteMember:  PermissionDeniedException " + siteId + " person " + personId + " role " + role);
        throw new PermissionDeniedException();
    }
    try {
        siteService.setMembership(siteId, personId, role);
    } catch (UnknownAuthorityException e) {
        logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
        throw new InvalidArgumentException("Unknown role '" + role + "'");
    }
    return siteMember;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 30 with EntityNotFoundException

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

the class SitesImpl method deleteSite.

public void deleteSite(String siteId, Parameters parameters) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    siteId = siteInfo.getShortName();
    NodeRef siteNodeRef = siteInfo.getNodeRef();
    // belt-and-braces - double-check before purge/delete (rather than rollback)
    if (permissionService.hasPermission(siteNodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
        throw new AccessDeniedException("Cannot delete site: " + siteId);
    }
    // default false (if not provided)
    boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));
    if (permanentDelete == true) {
        // Set as temporary to delete node instead of archiving.
        nodeService.addAspect(siteNodeRef, ContentModel.ASPECT_TEMPORARY, null);
        // bypassing trashcan means that purge behaviour will not fire, so explicitly force cleanup here
        siteServiceImpl.beforePurgeNode(siteNodeRef);
    }
    siteService.deleteSite(siteId);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Aggregations

EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)66 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)24 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 QName (org.alfresco.service.namespace.QName)15 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 HashMap (java.util.HashMap)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 ArrayList (java.util.ArrayList)9 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)8 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)7 Serializable (java.io.Serializable)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4