use of org.alfresco.sync.events.types.SiteManagementEvent in project alfresco-repository by Alfresco.
the class SiteServiceImpl method createSite.
public SiteInfo createSite(final String sitePreset, String passedShortName, final String title, final String description, final SiteVisibility visibility, final QName siteType) {
// Check that the provided site type is a subtype of TYPE_SITE
if (SiteModel.TYPE_SITE.equals(siteType) == false && dictionaryService.isSubClass(siteType, TYPE_SITE) == false) {
throw new SiteServiceException(MSG_INVALID_SITE_TYPE, new Object[] { siteType });
}
// Remove spaces from shortName
final String shortName = passedShortName.replaceAll(" ", "");
// Check to see if we already have a site of this name
NodeRef existingSite = getSiteNodeRef(shortName, false);
if (existingSite != null || authorityService.authorityExists(getSiteGroup(shortName, true))) {
// Throw an exception since we have a duplicate site name
throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[] { shortName });
}
// Check that the site name isn't too long
// Authorities are limited to 100 characters by the PermissionService
int longestPermissionLength = 0;
for (String permission : permissionService.getSettablePermissions(siteType)) {
if (permission.length() > longestPermissionLength)
longestPermissionLength = permission.length();
}
int maximumPermisionGroupLength = 99 - longestPermissionLength;
if (getSiteGroup(shortName, true).length() > maximumPermisionGroupLength) {
throw new SiteServiceException(MSG_SITE_SHORT_NAME_TOO_LONG, new Object[] { shortName, maximumPermisionGroupLength - getSiteGroup("", true).length() });
}
// Get the site parent node reference
final NodeRef siteParent = getSiteParent(shortName);
if (siteParent == null) {
throw new SiteServiceException("No root sites folder exists");
}
// Create the site node
final PropertyMap properties = new PropertyMap(4);
properties.put(ContentModel.PROP_NAME, shortName);
properties.put(SiteModel.PROP_SITE_PRESET, sitePreset);
properties.put(SiteModel.PROP_SITE_VISIBILITY, visibility.toString());
properties.put(ContentModel.PROP_TITLE, title);
properties.put(ContentModel.PROP_DESCRIPTION, description);
final NodeRef siteNodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
behaviourFilter.disableBehaviour(siteParent, ContentModel.ASPECT_AUDITABLE);
try {
return nodeService.createNode(siteParent, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, shortName), siteType, properties).getChildRef();
} finally {
behaviourFilter.enableBehaviour(siteParent, ContentModel.ASPECT_AUDITABLE);
}
}
}, AuthenticationUtil.getSystemUserName());
// Make the new site a tag scope
this.taggingService.addTagScope(siteNodeRef);
// Clear the sites inherited permissions
this.permissionService.setInheritParentPermissions(siteNodeRef, false);
// Create the relevant groups and assign permissions
setupSitePermissions(siteNodeRef, shortName, visibility, null);
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
return new SiteManagementEvent("site.create", transactionId, networkId, new Date().getTime(), user, shortName, title, description, visibility.toString(), sitePreset);
}
});
// Return created site information
Map<QName, Serializable> customProperties = getSiteCustomProperties(siteNodeRef);
SiteInfo siteInfo = new SiteInfoImpl(sitePreset, shortName, title, description, visibility, customProperties, siteNodeRef);
return siteInfo;
}
use of org.alfresco.sync.events.types.SiteManagementEvent in project alfresco-repository by Alfresco.
the class SiteServiceImpl method updateSite.
/**
* @see org.alfresco.service.cmr.site.SiteService#updateSite(org.alfresco.service.cmr.site.SiteInfo)
*/
public void updateSite(SiteInfo siteInfo) {
final String shortName = siteInfo.getShortName();
final String title = siteInfo.getTitle();
final String description = siteInfo.getDescription();
NodeRef siteNodeRef = getSiteNodeRef(shortName);
if (siteNodeRef == null) {
throw new SiteServiceException(MSG_CAN_NOT_UPDATE, new Object[] { siteInfo.getShortName() });
}
// Get the sites properties
Map<QName, Serializable> properties = this.directNodeService.getProperties(siteNodeRef);
// Update the properties of the site
// Note: the site preset and short name should never be updated!
properties.put(ContentModel.PROP_TITLE, title);
properties.put(ContentModel.PROP_DESCRIPTION, description);
// Update the permissions based on the visibility
SiteVisibility currentVisibility = getSiteVisibility(siteNodeRef);
SiteVisibility updatedVisibility = siteInfo.getVisibility();
if (currentVisibility.equals(updatedVisibility) == false) {
// visibility has changed
logger.debug("site:" + shortName + " visibility has changed from: " + currentVisibility + "to: " + updatedVisibility);
// Grab the Public Site Group and validate
final String sitePublicGroup = sysAdminParams.getSitePublicGroup();
boolean publicGroupExists = authorityService.authorityExists(sitePublicGroup);
if (!PermissionService.ALL_AUTHORITIES.equals(sitePublicGroup) && !publicGroupExists) {
// If the group specified in the settings does not exist, we cannot update the site.
throw new SiteServiceException(MSG_VISIBILITY_GROUP_MISSING, new Object[] { sitePublicGroup });
}
// Remove current visibility permissions
if (SiteVisibility.PUBLIC.equals(currentVisibility) == true || SiteVisibility.MODERATED.equals(currentVisibility) == true) {
// Remove the old Consumer permissions
// (Always remove both EVERYONE and the Publci Site Group, just to be safe)
this.permissionService.deletePermission(siteNodeRef, sitePublicGroup, SITE_CONSUMER);
if (sitePublicGroup.equals(PermissionService.ALL_AUTHORITIES)) {
this.permissionService.deletePermission(siteNodeRef, PermissionService.ALL_AUTHORITIES, SITE_CONSUMER);
}
}
// (Leaving the old extra permissions on containers is fine)
if (SiteVisibility.MODERATED.equals(currentVisibility) == true || SiteVisibility.PRIVATE.equals(currentVisibility) == true) {
List<FileInfo> folders = fileFolderService.listFolders(siteNodeRef);
for (FileInfo folder : folders) {
NodeRef containerNodeRef = folder.getNodeRef();
this.permissionService.setInheritParentPermissions(containerNodeRef, true);
}
}
// Note - these need to be kept in sync manually with those in #setupSitePermissions
if (SiteVisibility.PUBLIC.equals(updatedVisibility) == true) {
this.permissionService.setPermission(siteNodeRef, sitePublicGroup, SITE_CONSUMER, true);
} else if (SiteVisibility.MODERATED.equals(updatedVisibility) == true) {
this.permissionService.setPermission(siteNodeRef, sitePublicGroup, SITE_CONSUMER, true);
// Set the moderated permissions on all the containers the site already has
List<FileInfo> folders = fileFolderService.listFolders(siteNodeRef);
for (FileInfo folder : folders) {
NodeRef containerNodeRef = folder.getNodeRef();
setModeratedPermissions(shortName, containerNodeRef);
}
} else if (SiteVisibility.PRIVATE.equals(updatedVisibility)) {
// Set the private permissions on all the containers the site already has
List<FileInfo> folders = fileFolderService.listFolders(siteNodeRef);
for (FileInfo folder : folders) {
NodeRef containerNodeRef = folder.getNodeRef();
setPrivatePermissions(shortName, containerNodeRef);
}
}
// Update the site node reference with the updated visibility value
properties.put(SiteModel.PROP_SITE_VISIBILITY, siteInfo.getVisibility().toString());
}
// Set the updated properties back onto the site node reference
this.nodeService.setProperties(siteNodeRef, properties);
final SiteVisibility visibility = siteInfo.getVisibility();
final String sitePreset = siteInfo.getSitePreset();
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
return new SiteManagementEvent("site.update", transactionId, networkId, new Date().getTime(), user, shortName, title, description, visibility.toString(), sitePreset);
}
});
}
Aggregations