use of org.alfresco.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo 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