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);
}
}
});
}
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;
}
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);
}
});
}
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;
}
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);
}
});
}
Aggregations