Search in sources :

Example 11 with Invitation

use of org.alfresco.service.cmr.invitation.Invitation 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 12 with Invitation

use of org.alfresco.service.cmr.invitation.Invitation in project alfresco-remote-api by Alfresco.

the class InvitationDelete method checkAndCancelTheInvitation.

protected void checkAndCancelTheInvitation(final String invId, String siteShortName) {
    Invitation invitation = null;
    try {
        invitation = invitationService.getInvitation(invId);
    } catch (org.alfresco.service.cmr.invitation.InvitationExceptionNotFound ienf) {
        throwInvitationNotFoundException(invId, siteShortName);
    }
    if (invitation == null) {
        throwInvitationNotFoundException(invId, siteShortName);
    }
    // check that this invitation really belongs to the specified siteShortName
    if (invitation != null && invitation.getResourceName() != null && !siteShortName.equals(invitation.getResourceName())) {
        throw new WebScriptException(Status.STATUS_FORBIDDEN, "Unable to cancel workflow");
    }
    invitationService.cancel(invId);
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Invitation(org.alfresco.service.cmr.invitation.Invitation)

Example 13 with Invitation

use of org.alfresco.service.cmr.invitation.Invitation in project alfresco-remote-api by Alfresco.

the class InviteResponse method execute.

private Map<String, Object> execute(WebScriptRequest req, Status status) {
    // initialise model to pass on for template to render
    Map<String, Object> model = new HashMap<String, Object>();
    String inviteId = req.getServiceMatch().getTemplateVars().get("inviteId");
    String inviteTicket = req.getServiceMatch().getTemplateVars().get("inviteTicket");
    // Check that the task is still open.
    // if(inviteStart)
    // process response
    String action = req.getServiceMatch().getTemplateVars().get("action");
    if (action.equals("accept")) {
        try {
            Invitation invitation = invitationService.accept(inviteId, inviteTicket);
            // add model properties for template to render
            model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT);
            model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, invitation.getResourceName());
        } catch (InvitationExceptionForbidden fe) {
            throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString());
        } catch (InvitationExceptionUserError fe) {
            throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString());
        }
    } else if (action.equals("reject")) {
        try {
            Invitation invitation = invitationService.reject(inviteId, "Rejected");
            // add model properties for template to render
            model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT);
            model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, invitation.getResourceName());
        } catch (InvitationExceptionForbidden fe) {
            throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString());
        } catch (InvitationExceptionUserError fe) {
            throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString());
        }
    } else {
        /* handle unrecognised method */
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "action " + action + " is not supported by this webscript.");
    }
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Invitation(org.alfresco.service.cmr.invitation.Invitation) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) InvitationExceptionUserError(org.alfresco.service.cmr.invitation.InvitationExceptionUserError)

Example 14 with Invitation

use of org.alfresco.service.cmr.invitation.Invitation in project alfresco-remote-api by Alfresco.

the class RepoService method rejectSiteInvitation.

public Invitation rejectSiteInvitation(String personId, String siteId) {
    Invitation ret = null;
    List<Invitation> invitations = invitationService.listPendingInvitationsForInvitee(personId);
    for (Invitation invitation : invitations) {
        if (invitation.getResourceName().equals(siteId)) {
            ret = invitationService.reject(invitation.getInviteId(), "I reject you");
        }
    }
    return ret;
}
Also used : Invitation(org.alfresco.service.cmr.invitation.Invitation)

Example 15 with Invitation

use of org.alfresco.service.cmr.invitation.Invitation in project alfresco-remote-api by Alfresco.

the class RepoService method approveSiteInvitation.

public Invitation approveSiteInvitation(String personId, String siteId) {
    Invitation ret = null;
    List<Invitation> invitations = invitationService.listPendingInvitationsForInvitee(personId);
    for (Invitation invitation : invitations) {
        if (invitation.getResourceName().equals(siteId)) {
            ret = invitationService.approve(invitation.getInviteId(), "I accept you");
        }
    }
    return ret;
}
Also used : Invitation(org.alfresco.service.cmr.invitation.Invitation)

Aggregations

Invitation (org.alfresco.service.cmr.invitation.Invitation)16 ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)6 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)5 InvitationSearchCriteriaImpl (org.alfresco.repo.invitation.InvitationSearchCriteriaImpl)4 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 InvitationExceptionForbidden (org.alfresco.service.cmr.invitation.InvitationExceptionForbidden)3 List (java.util.List)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)2 NominatedInvitation (org.alfresco.service.cmr.invitation.NominatedInvitation)2 ParseException (java.text.ParseException)1 WorkflowModelNominatedInvitation (org.alfresco.repo.invitation.WorkflowModelNominatedInvitation)1