Search in sources :

Example 1 with SiteManagementEvent

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) JSONException(org.json.JSONException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) EventPreparator(org.alfresco.sync.repo.events.EventPreparator) Event(org.alfresco.sync.events.types.Event) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) ApplicationEvent(org.springframework.context.ApplicationEvent)

Example 2 with SiteManagementEvent

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);
        }
    });
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) EventPreparator(org.alfresco.sync.repo.events.EventPreparator) FileInfo(org.alfresco.service.cmr.model.FileInfo) Event(org.alfresco.sync.events.types.Event) SiteManagementEvent(org.alfresco.sync.events.types.SiteManagementEvent) ApplicationEvent(org.springframework.context.ApplicationEvent) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility)

Aggregations

Serializable (java.io.Serializable)2 Date (java.util.Date)2 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)2 FilterTypeString (org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 QName (org.alfresco.service.namespace.QName)2 Event (org.alfresco.sync.events.types.Event)2 SiteManagementEvent (org.alfresco.sync.events.types.SiteManagementEvent)2 EventPreparator (org.alfresco.sync.repo.events.EventPreparator)2 ApplicationEvent (org.springframework.context.ApplicationEvent)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 LuceneQueryParserException (org.alfresco.repo.search.impl.lucene.LuceneQueryParserException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1