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;
}
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");
}
}
Aggregations