use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SiteMembershipRequestsImpl method getSiteMembershipRequest.
private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation, boolean includePersonDetails) {
SiteMembershipRequest siteMembershipRequest = null;
ResourceType resourceType = moderatedInvitation.getResourceType();
if (resourceType.equals(ResourceType.WEB_SITE)) {
final String siteId = moderatedInvitation.getResourceName();
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 EntityNotFoundException(siteId);
}
if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
// return a site membership request only if this is a moderated site
siteMembershipRequest = new SiteMembershipRequest();
String title = siteInfo.getTitle();
siteMembershipRequest.setTitle(title);
siteMembershipRequest.setId(siteId);
siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
if (includePersonDetails) {
Person person = people.getPerson(moderatedInvitation.getInviteeUserName());
siteMembershipRequest.setPerson(person);
}
}
} else {
logger.warn("Unexpected resource type " + resourceType + " for site membership request");
}
return siteMembershipRequest;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteMembers.
public CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteId, Parameters parameters) {
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
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();
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final List<Pair<SiteService.SortFields, Boolean>> sort = new ArrayList<Pair<SiteService.SortFields, Boolean>>();
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.LastName, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.FirstName, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Role, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Username, Boolean.TRUE));
PagingResults<SiteMembership> pagedResults = siteService.listMembersPaged(siteId, true, sort, pagingRequest);
List<SiteMembership> siteMembers = pagedResults.getPage();
List<SiteMember> ret = new ArrayList<SiteMember>(siteMembers.size());
for (SiteMembership siteMembership : siteMembers) {
SiteMember siteMember = new SiteMember(siteMembership.getPersonId(), siteMembership.getRole());
ret.add(siteMember);
}
return CollectionWithPagingInfo.asPaged(paging, ret, pagedResults.hasMoreItems(), null);
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method updateSiteMember.
public SiteMember updateSiteMember(String siteId, SiteMember siteMember) {
String siteMemberId = siteMember.getPersonId();
if (siteMemberId == null) {
throw new InvalidArgumentException("Member id is null");
}
siteMemberId = people.validatePerson(siteMemberId);
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
siteId = siteInfo.getShortName();
String siteRole = siteMember.getRole();
if (siteRole == null) {
throw new InvalidArgumentException("Must provide a role");
}
/* MNT-10551 : fix */
if (!siteService.isMember(siteId, siteMember.getPersonId())) {
throw new InvalidArgumentException("User is not a member of the site");
}
try {
siteService.setMembership(siteId, siteMember.getPersonId(), siteRole);
} catch (UnknownAuthorityException e) {
throw new InvalidArgumentException("Unknown role '" + siteRole + "'");
}
return siteMember;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method addSiteMember.
public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
String personId = people.validatePerson(siteMember.getPersonId());
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
logger.debug("addSiteMember: site does not exist " + siteId + " person " + personId);
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();
String role = siteMember.getRole();
if (role == null) {
logger.debug("addSiteMember: Must provide a role " + siteMember);
throw new InvalidArgumentException("Must provide a role");
}
if (siteService.isMember(siteId, personId)) {
logger.debug("addSiteMember: " + personId + " is already a member of site " + siteId);
throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
}
if (!siteService.canAddMember(siteId, personId, role)) {
logger.debug("addSiteMember: PermissionDeniedException " + siteId + " person " + personId + " role " + role);
throw new PermissionDeniedException();
}
try {
siteService.setMembership(siteId, personId, role);
} catch (UnknownAuthorityException e) {
logger.debug("addSiteMember: UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
throw new InvalidArgumentException("Unknown role '" + role + "'");
}
return siteMember;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method deleteSite.
public void deleteSite(String siteId, Parameters parameters) {
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
siteId = siteInfo.getShortName();
NodeRef siteNodeRef = siteInfo.getNodeRef();
// belt-and-braces - double-check before purge/delete (rather than rollback)
if (permissionService.hasPermission(siteNodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
throw new AccessDeniedException("Cannot delete site: " + siteId);
}
// default false (if not provided)
boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));
if (permanentDelete == true) {
// Set as temporary to delete node instead of archiving.
nodeService.addAspect(siteNodeRef, ContentModel.ASPECT_TEMPORARY, null);
// bypassing trashcan means that purge behaviour will not fire, so explicitly force cleanup here
siteServiceImpl.beforePurgeNode(siteNodeRef);
}
siteService.deleteSite(siteId);
}
Aggregations