use of org.alfresco.repo.invitation.site.InviteInfo 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.repo.invitation.site.InviteInfo in project alfresco-remote-api by Alfresco.
the class Invites method toInviteInfo.
private InviteInfo toInviteInfo(Map<String, SiteInfo> siteInfoCache, final NominatedInvitation invitation) {
// get the site info
String resourceName = invitation.getResourceName();
SiteInfo siteInfo = siteInfoCache.get(resourceName);
if (siteInfo == null) {
siteInfo = siteService.getSite(resourceName);
siteInfoCache.put(resourceName, siteInfo);
}
String invitationStatus = InviteInfo.INVITATION_STATUS_PENDING;
TemplateNode inviterPerson = getPersonIfAllowed(invitation.getInviterUserName());
// fetch the person node for the invitee
TemplateNode inviteePerson = getPersonIfAllowed(invitation.getInviteeUserName());
InviteInfo ret = new InviteInfo(invitationStatus, invitation.getInviterUserName(), inviterPerson, invitation.getInviteeUserName(), inviteePerson, invitation.getRoleName(), invitation.getResourceName(), siteInfo, invitation.getSentInviteDate(), invitation.getInviteId());
return ret;
}
use of org.alfresco.repo.invitation.site.InviteInfo in project alfresco-remote-api by Alfresco.
the class InviteByTicket method toInviteInfo.
private InviteInfo toInviteInfo(NominatedInvitation invitation) {
final PersonService personService = serviceRegistry.getPersonService();
// get the site info
SiteInfo siteInfo = siteService.getSite(invitation.getResourceName());
String invitationStatus = getInvitationStatus(invitation);
NodeRef inviterRef = personService.getPerson(invitation.getInviterUserName());
TemplateNode inviterPerson = null;
if (inviterRef != null) {
inviterPerson = new TemplateNode(inviterRef, serviceRegistry, null);
}
// fetch the person node for the invitee
NodeRef inviteeRef = personService.getPerson(invitation.getInviteeUserName());
TemplateNode inviteePerson = null;
if (inviteeRef != null) {
inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null);
}
InviteInfo ret = new InviteInfo(invitationStatus, invitation.getInviterUserName(), inviterPerson, invitation.getInviteeUserName(), inviteePerson, invitation.getRoleName(), invitation.getResourceName(), siteInfo, invitation.getSentInviteDate(), invitation.getInviteId());
return ret;
}
Aggregations