use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.
the class SiteMembershipRequestsImpl method getSiteMembershipRequest.
public SiteMembershipRequest getSiteMembershipRequest(String inviteeId, final String siteId) {
inviteeId = people.validatePerson(inviteeId);
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 RelationshipResourceNotFoundException(inviteeId, siteId);
}
if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
String normalizedSiteId = siteInfo.getShortName();
Invitation invitation = getSiteInvitation(inviteeId, normalizedSiteId);
if (invitation == null) {
// no such invitation
throw new RelationshipResourceNotFoundException(inviteeId, normalizedSiteId);
}
if (invitation instanceof ModeratedInvitation) {
ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
SiteMembershipRequest siteInvite = getSiteMembershipRequest(moderatedInvitation);
return siteInvite;
} else {
throw new InvalidArgumentException("Expected moderated invitation");
}
} else {
// non-moderated sites cannot appear in a site membership request, so throw an exception
throw new RelationshipResourceNotFoundException(inviteeId, siteId);
}
}
use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.
the class SiteMembershipRequestsImpl method updateSiteMembershipRequest.
@Override
public SiteMembershipRequest updateSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
SiteMembershipRequest updatedSiteInvite = null;
inviteeId = people.validatePerson(inviteeId, true);
String siteId = siteInvite.getId();
SiteInfo siteInfo = sites.validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new RelationshipResourceNotFoundException(inviteeId, 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 message = siteInvite.getMessage();
if (message == null) {
// the invitation service ignores null messages so convert to an empty message.
message = "";
}
try {
ModeratedInvitation updatedInvitation = invitationService.updateModeratedInvitation(inviteeId, siteId, message);
if (updatedInvitation == null) {
throw new RelationshipResourceNotFoundException(inviteeId, siteId);
}
updatedSiteInvite = getSiteMembershipRequest(updatedInvitation);
} catch (InvitationExceptionNotFound e) {
throw new RelationshipResourceNotFoundException(inviteeId, siteId);
}
if (updatedSiteInvite == null) {
throw new RelationshipResourceNotFoundException(inviteeId, siteId);
}
return updatedSiteInvite;
}
use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteMember.
public SiteMember getSiteMember(String personId, String siteId) {
SiteMember siteMember = null;
personId = people.validatePerson(personId);
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
logger.debug("Site does not exist: " + siteId);
throw new RelationshipResourceNotFoundException(personId, siteId);
}
siteId = siteInfo.getShortName();
logger.debug("Getting member role for " + siteId + " person " + personId);
String role = siteService.getMembersRole(siteId, personId);
if (role != null) {
siteMember = new SiteMember(personId, role);
} else {
logger.debug("Getting member role but role is null");
throw new RelationshipResourceNotFoundException(personId, siteId);
}
return siteMember;
}
use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method removeSiteMember.
public void removeSiteMember(String personId, String siteId) {
personId = people.validatePerson(personId);
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new RelationshipResourceNotFoundException(personId, 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();
boolean isMember = siteService.isMember(siteId, personId);
if (!isMember) {
throw new InvalidArgumentException();
}
String role = siteService.getMembersRole(siteId, personId);
if (role != null) {
if (role.equals(SiteModel.SITE_MANAGER)) {
int numAuthorities = siteService.countAuthoritiesWithRole(siteId, SiteModel.SITE_MANAGER);
if (numAuthorities <= 1) {
throw new InvalidArgumentException("Can't remove last manager of site " + siteId);
}
siteService.removeMembership(siteId, personId);
} else {
siteService.removeMembership(siteId, personId);
}
} else {
throw new AlfrescoRuntimeException("Unable to determine role of site member");
}
}
use of org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteContainer.
public SiteContainer getSiteContainer(String siteId, String containerId) {
// check site and container node validity
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new RelationshipResourceNotFoundException(siteId, containerId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
NodeRef containerNodeRef = siteService.getContainer(siteId, containerId);
if (containerNodeRef == null) {
throw new RelationshipResourceNotFoundException(siteId, containerId);
}
// check that the containerId is actually a container for the specified site
SiteInfo testSiteInfo = siteService.getSite(containerNodeRef);
if (testSiteInfo == null) {
throw new RelationshipResourceNotFoundException(siteId, containerId);
} else {
if (!testSiteInfo.getShortName().equals(siteId)) {
throw new RelationshipResourceNotFoundException(siteId, containerId);
}
}
String folderId = (String) nodeService.getProperty(containerNodeRef, SiteModel.PROP_COMPONENT_ID);
SiteContainer siteContainer = new SiteContainer(folderId, containerNodeRef);
return siteContainer;
}
Aggregations