Search in sources :

Example 1 with NominatedInvitation

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

the class Invites method executeImpl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco
     * .web.scripts.WebScriptRequest,
     * org.alfresco.web.scripts.WebScriptResponse)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    // initialise model to pass on for template to render
    Map<String, Object> model = new HashMap<String, Object>();
    // Get parameter names
    String[] paramNames = req.getParameterNames();
    // handle no parameters given on URL
    if ((paramNames == null) || (paramNames.length == 0)) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "No parameters have been provided on URL");
    }
    // get URL request parameters, checking if at least one has been provided
    // check if 'inviterUserName' parameter provided
    String inviterUserName = req.getParameter(PARAM_INVITER_USER_NAME);
    boolean inviterUserNameProvided = (inviterUserName != null) && (inviterUserName.length() != 0);
    // check if 'inviteeUserName' parameter provided
    String inviteeUserName = req.getParameter(PARAM_INVITEE_USER_NAME);
    boolean inviteeUserNameProvided = (inviteeUserName != null) && (inviteeUserName.length() != 0);
    // check if 'siteShortName' parameter provided
    String siteShortName = req.getParameter(PARAM_SITE_SHORT_NAME);
    boolean siteShortNameProvided = (siteShortName != null) && (siteShortName.length() != 0);
    // check if 'inviteId' parameter provided
    String inviteId = req.getParameter(PARAM_INVITE_ID);
    boolean inviteIdProvided = (inviteId != null) && (inviteId.length() != 0);
    // 'inviteId' URL request parameters has not been provided
    if (!(inviterUserNameProvided || inviteeUserNameProvided || siteShortNameProvided || inviteIdProvided)) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "At least one of the following URL request parameters must be provided in URL " + "'inviterUserName', 'inviteeUserName', 'siteShortName' or 'inviteId'");
    }
    // InviteInfo List to place onto model
    List<InviteInfo> inviteInfoList = new ArrayList<InviteInfo>();
    // query properties
    if (inviteIdProvided) {
        NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
        Map<String, SiteInfo> siteInfoCache = new HashMap<String, SiteInfo>(2);
        inviteInfoList.add(toInviteInfo(siteInfoCache, invitation));
    } else // 'inviteId' has not been provided, so create the query properties from
    // the invite URL request
    // parameters
    // - because this web script class will terminate with a web script
    // exception if none of the required
    // request parameters are provided, at least one of these query
    // properties will be set
    // at this point
    {
        InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl();
        criteria.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
        criteria.setResourceType(Invitation.ResourceType.WEB_SITE);
        if (inviterUserNameProvided) {
            criteria.setInviter(inviterUserName);
        }
        if (inviteeUserNameProvided) {
            criteria.setInvitee(inviteeUserName);
        }
        if (siteShortNameProvided) {
            criteria.setResourceName(siteShortName);
        }
        // MNT-9905 Pending Invites created by one site manager aren't visible to other site managers
        String currentUser = AuthenticationUtil.getRunAsUser();
        List<Invitation> invitations;
        if (siteShortNameProvided == true && (SiteModel.SITE_MANAGER).equals(siteService.getMembersRole(siteShortName, currentUser)) && inviterUserNameProvided == false && inviteeUserNameProvided == false) {
            final InvitationSearchCriteriaImpl crit = criteria;
            RunAsWork<List<Invitation>> runAsSystem = new RunAsWork<List<Invitation>>() {

                @Override
                public List<Invitation> doWork() throws Exception {
                    return invitationService.searchInvitation(crit);
                }
            };
            invitations = AuthenticationUtil.runAs(runAsSystem, AuthenticationUtil.getSystemUserName());
        } else {
            invitations = invitationService.searchInvitation(criteria);
        }
        // Put InviteInfo objects (containing workflow path properties
        // wf:inviterUserName, wf:inviteeUserName, wf:siteShortName,
        // and invite id property (from workflow instance id))
        // onto model for each invite workflow task returned by the query
        Map<String, SiteInfo> siteInfoCache = new HashMap<String, SiteInfo>(invitations.size() * 2);
        for (Invitation invitation : invitations) {
            inviteInfoList.add(toInviteInfo(siteInfoCache, (NominatedInvitation) invitation));
        }
    }
    // put the list of invite infos onto model to be passed onto template
    // for rendering
    model.put(MODEL_KEY_NAME_INVITES, inviteInfoList);
    return model;
}
Also used : InviteInfo(org.alfresco.repo.invitation.site.InviteInfo) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) HashMap(java.util.HashMap) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) ArrayList(java.util.ArrayList) NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) InvitationSearchCriteriaImpl(org.alfresco.repo.invitation.InvitationSearchCriteriaImpl) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with NominatedInvitation

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

the class InviteByTicket 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>();
    // get inviteId and inviteTicket
    String inviteId = req.getServiceMatch().getTemplateVars().get("inviteId");
    String inviteTicket = req.getServiceMatch().getTemplateVars().get("inviteTicket");
    try {
        Invitation invitation = invitationService.getInvitation(inviteId);
        if (invitation instanceof NominatedInvitation) {
            NominatedInvitation theInvitation = (NominatedInvitation) invitation;
            String ticket = theInvitation.getTicket();
            if (ticket == null || (!ticket.equals(inviteTicket))) {
                throw new WebScriptException(Status.STATUS_NOT_FOUND, "Ticket mismatch");
            }
            // return the invite info
            model.put("invite", toInviteInfo(theInvitation));
            return model;
        } else {
            // Not a nominated invitation
            throw new WebScriptException(Status.STATUS_FORBIDDEN, "Not a nominated invitation");
        }
    } catch (InvitationExceptionNotFound nfe) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "No invite found for given id");
    }
}
Also used : NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) WorkflowModelNominatedInvitation(org.alfresco.repo.invitation.WorkflowModelNominatedInvitation) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) NominatedInvitation(org.alfresco.service.cmr.invitation.NominatedInvitation) WorkflowModelNominatedInvitation(org.alfresco.repo.invitation.WorkflowModelNominatedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) InvitationExceptionNotFound(org.alfresco.service.cmr.invitation.InvitationExceptionNotFound)

Aggregations

HashMap (java.util.HashMap)2 Invitation (org.alfresco.service.cmr.invitation.Invitation)2 NominatedInvitation (org.alfresco.service.cmr.invitation.NominatedInvitation)2 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InvitationSearchCriteriaImpl (org.alfresco.repo.invitation.InvitationSearchCriteriaImpl)1 WorkflowModelNominatedInvitation (org.alfresco.repo.invitation.WorkflowModelNominatedInvitation)1 InviteInfo (org.alfresco.repo.invitation.site.InviteInfo)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 InvitationExceptionNotFound (org.alfresco.service.cmr.invitation.InvitationExceptionNotFound)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1