Search in sources :

Example 1 with EventPreparator

use of org.alfresco.sync.repo.events.EventPreparator in project alfresco-repository by Alfresco.

the class CMISConnector method publishReadEvent.

/**
 * Notifies listeners that a read has taken place.
 *
 * @param nodeRef NodeRef
 * @param name String
 * @param mimeType String
 * @param contentSize long
 * @param encoding String
 * @param range String
 */
protected void publishReadEvent(final NodeRef nodeRef, final String name, final String mimeType, final long contentSize, final String encoding, final String range) {
    final QName nodeType = nodeRef == null ? null : nodeService.getType(nodeRef);
    eventPublisher.publishEvent(new EventPreparator() {

        @Override
        public Event prepareEvent(String user, String networkId, String transactionId) {
            if (StringUtils.hasText(range)) {
                return new ContentReadRangeEvent(user, networkId, transactionId, nodeRef.getId(), null, nodeType.toString(), Client.asType(ClientType.cmis), name, mimeType, contentSize, encoding, range);
            } else {
                return new ContentEventImpl(ContentEvent.DOWNLOAD, user, networkId, transactionId, nodeRef.getId(), null, nodeType.toString(), Client.asType(ClientType.cmis), name, mimeType, contentSize, encoding);
            }
        }
    });
}
Also used : EventPreparator(org.alfresco.sync.repo.events.EventPreparator) ContentReadRangeEvent(org.alfresco.sync.events.types.ContentReadRangeEvent) QName(org.alfresco.service.namespace.QName) Event(org.alfresco.sync.events.types.Event) ApplicationEvent(org.springframework.context.ApplicationEvent) ApplicationContextEvent(org.springframework.context.event.ApplicationContextEvent) ContentReadRangeEvent(org.alfresco.sync.events.types.ContentReadRangeEvent) ContentEvent(org.alfresco.sync.events.types.ContentEvent) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) ContentEventImpl(org.alfresco.sync.events.types.ContentEventImpl)

Example 2 with EventPreparator

use of org.alfresco.sync.repo.events.EventPreparator 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 3 with EventPreparator

use of org.alfresco.sync.repo.events.EventPreparator 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)

Example 4 with EventPreparator

use of org.alfresco.sync.repo.events.EventPreparator in project alfresco-repository by Alfresco.

the class FavouritesServiceImpl method addFavouriteDocumentOrFolder.

private PersonFavourite addFavouriteDocumentOrFolder(String userName, Type type, NodeRef nodeRef) {
    Map<PersonFavouriteKey, PersonFavourite> personFavourites = getFavouriteNodes(userName, type);
    PersonFavourite personFavourite = getPersonFavourite(userName, type, nodeRef);
    if (personFavourite == null) {
        Date createdAt = new Date();
        final String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        personFavourite = new PersonFavourite(userName, nodeRef, type, name, createdAt);
        personFavourites.put(personFavourite.getKey(), personFavourite);
        updateFavouriteNodes(userName, type, personFavourites);
        QName nodeClass = nodeService.getType(nodeRef);
        final String finalRef = nodeRef.getId();
        final QName nodeType = nodeClass;
        eventPublisher.publishEvent(new EventPreparator() {

            @Override
            public Event prepareEvent(String user, String networkId, String transactionId) {
                return new ActivityEvent("favorite.added", transactionId, networkId, user, finalRef, null, nodeType == null ? null : nodeType.toString(), Client.asType(ClientType.script), null, name, null, 0l, null);
            }
        });
        OnAddFavouritePolicy policy = onAddFavouriteDelegate.get(nodeRef, nodeClass);
        policy.onAddFavourite(userName, nodeRef);
    }
    return personFavourite;
}
Also used : EventPreparator(org.alfresco.sync.repo.events.EventPreparator) ActivityEvent(org.alfresco.sync.events.types.ActivityEvent) QName(org.alfresco.service.namespace.QName) Event(org.alfresco.sync.events.types.Event) ActivityEvent(org.alfresco.sync.events.types.ActivityEvent) PersonFavouriteKey(org.alfresco.repo.favourites.PersonFavourite.PersonFavouriteKey) Date(java.util.Date)

Example 5 with EventPreparator

use of org.alfresco.sync.repo.events.EventPreparator in project alfresco-repository by Alfresco.

the class PersonServiceImpl method publishEvent.

/**
 * Publish new user event
 *
 * @param eventType String
 * @param properties Map<QName, Serializable>
 */
private void publishEvent(String eventType, Map<QName, Serializable> properties) {
    if (properties == null)
        return;
    final String managedUsername = (String) properties.get(ContentModel.PROP_USERNAME);
    final String managedFirstname = (String) properties.get(ContentModel.PROP_FIRSTNAME);
    final String managedLastname = (String) properties.get(ContentModel.PROP_LASTNAME);
    final String eventTType = eventType;
    eventPublisher.publishEvent(new EventPreparator() {

        @Override
        public Event prepareEvent(String user, String networkId, String transactionId) {
            return new UserManagementEvent(eventTType, transactionId, networkId, new Date().getTime(), user, managedUsername, managedFirstname, managedLastname);
        }
    });
}
Also used : EventPreparator(org.alfresco.sync.repo.events.EventPreparator) Event(org.alfresco.sync.events.types.Event) UserManagementEvent(org.alfresco.sync.events.types.UserManagementEvent) Date(java.util.Date) UserManagementEvent(org.alfresco.sync.events.types.UserManagementEvent)

Aggregations

Event (org.alfresco.sync.events.types.Event)9 EventPreparator (org.alfresco.sync.repo.events.EventPreparator)9 Date (java.util.Date)6 QName (org.alfresco.service.namespace.QName)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 ActivityEvent (org.alfresco.sync.events.types.ActivityEvent)4 Serializable (java.io.Serializable)3 ApplicationEvent (org.springframework.context.ApplicationEvent)3 HashMap (java.util.HashMap)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 PersonFavouriteKey (org.alfresco.repo.favourites.PersonFavourite.PersonFavouriteKey)2 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)2 FilterTypeString (org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)2 SiteManagementEvent (org.alfresco.sync.events.types.SiteManagementEvent)2 JSONException (org.json.JSONException)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1