use of org.alfresco.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class SitesImpl method createSite.
/**
* Create default/fixed preset (Share) site - with DocLib container/component
*
* @param site
* @return
*/
public Site createSite(Site site, Parameters parameters) {
// note: if site id is null then will be generated from the site title
site = validateSite(site);
SiteInfo siteInfo = null;
try {
siteInfo = createSite(site);
} catch (SiteServiceException sse) {
if (sse.getMsgId().equals("site_service.unable_to_create")) {
throw new ConstraintViolatedException(sse.getMessage());
} else {
throw sse;
}
}
String siteId = siteInfo.getShortName();
NodeRef siteNodeRef = siteInfo.getNodeRef();
// default false (if not provided)
boolean skipShareSurfConfig = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_SURF_CONFIGURATION));
if (skipShareSurfConfig == false) {
// import default/fixed preset Share surf config
importSite(siteId, siteNodeRef);
}
// pre-create doclib
siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
// default false (if not provided)
boolean skipAddToFavorites = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_ADDTOFAVORITES));
if (skipAddToFavorites == false) {
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
// ignore result
favouritesService.addFavourite(personId, siteNodeRef);
}
return getSite(siteInfo, true);
}
use of org.alfresco.service.cmr.site.SiteInfo 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.service.cmr.site.SiteInfo 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);
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteContainers.
public PagingResults<SiteContainer> getSiteContainers(String siteId, Paging paging) {
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging));
List<FileInfo> containerFileInfos = pagingResults.getPage();
final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size());
for (FileInfo containerFileInfo : containerFileInfos) {
NodeRef nodeRef = containerFileInfo.getNodeRef();
String containerId = (String) nodeService.getProperty(nodeRef, SiteModel.PROP_COMPONENT_ID);
SiteContainer siteContainer = new SiteContainer(containerId, nodeRef);
siteContainers.add(siteContainer);
}
return new PagingResults<SiteContainer>() {
@Override
public List<SiteContainer> getPage() {
return siteContainers;
}
@Override
public boolean hasMoreItems() {
return pagingResults.hasMoreItems();
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
return pagingResults.getTotalResultCount();
}
@Override
public String getQueryExecutionId() {
return null;
}
};
}
Aggregations