use of org.alfresco.sync.events.types.ActivityEvent 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.events.types.ActivityEvent in project alfresco-repository by Alfresco.
the class ActivityPostServiceImpl method postActivity.
private void postActivity(final String activityType, String siteId, String appTool, String activityData, ActivityPostEntity.STATUS status, String userId, final Client client, final FileInfo contentNodeInfo) {
NodeRef nodeRef = null;
try {
// optional - default to empty string
if (siteId == null) {
siteId = "";
} else if (siteId.length() > ActivityPostDAO.MAX_LEN_SITE_ID) {
throw new IllegalArgumentException("Invalid siteId - exceeds " + ActivityPostDAO.MAX_LEN_SITE_ID + " chars: " + siteId);
}
// optional - default to empty string
if (appTool == null) {
appTool = "";
} else if (appTool.length() > ActivityPostDAO.MAX_LEN_APP_TOOL_ID) {
throw new IllegalArgumentException("Invalid app tool - exceeds " + ActivityPostDAO.MAX_LEN_APP_TOOL_ID + " chars: " + appTool);
}
// required
ParameterCheck.mandatoryString("activityType", activityType);
if (activityType.length() > ActivityPostDAO.MAX_LEN_ACTIVITY_TYPE) {
throw new IllegalArgumentException("Invalid activity type - exceeds " + ActivityPostDAO.MAX_LEN_ACTIVITY_TYPE + " chars: " + activityType);
}
if (ignoredActivityTypes != null && ignoredActivityTypes.contains(activityType)) {
// do not log the activity for ignored activity types.
logger.debug("Ignoring activity type for posting: " + activityType);
return;
}
// optional - default to empty string
if (activityData == null) {
activityData = "";
}
try {
if (activityData.length() > 0) {
JSONObject jo = new JSONObject(new JSONTokener(activityData));
if (AuthenticationUtil.isMtEnabled()) {
// MT share - add tenantDomain
jo.put(PostLookup.JSON_TENANT_DOMAIN, tenantService.getCurrentUserDomain());
activityData = jo.toString();
}
nodeRef = checkNodeRef(jo);
// ALF-10362 - belts-and-braces (note: Share sets "title" from cm:name)
if (jo.has(PostLookup.JSON_TITLE)) {
String title = jo.getString(PostLookup.JSON_TITLE);
if (title.length() > ActivityPostDAO.MAX_LEN_NAME) {
jo.put(PostLookup.JSON_TITLE, title.substring(0, 255));
activityData = jo.toString();
}
}
}
} catch (JSONException e) {
// throw new IllegalArgumentException("Invalid activity data - not valid JSON: " + e);
// According to test data in org/alfresco/repo/activities/script/test_activityService.js
// invalid JSON should be OK.
}
if (activityData.length() > ActivityPostDAO.MAX_LEN_ACTIVITY_DATA) {
throw new IllegalArgumentException("Invalid activity data - exceeds " + ActivityPostDAO.MAX_LEN_ACTIVITY_DATA + " chars: " + activityData);
}
// required
ParameterCheck.mandatoryString("userId", userId);
if (userId.length() > ActivityPostDAO.MAX_LEN_USER_ID) {
throw new IllegalArgumentException("Invalid user - exceeds " + ActivityPostDAO.MAX_LEN_USER_ID + " chars: " + userId);
}
} catch (IllegalArgumentException e) {
// log error and throw exception
logger.error(e);
throw new IllegalArgumentException("Failed to post activity: " + e, e);
}
try {
final Date postDate = new Date();
final ActivityPostEntity activityPost = new ActivityPostEntity();
final String network = tenantService.getName(siteId);
final String site = siteId;
final NodeRef finalNodeRef = nodeRef;
// MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities"
if (!userNamesAreCaseSensitive) {
userId = userId.toLowerCase();
}
activityPost.setUserId(userId);
activityPost.setSiteNetwork(network);
activityPost.setAppTool(appTool);
activityPost.setActivityData(activityData);
activityPost.setActivityType(activityType);
activityPost.setPostDate(postDate);
activityPost.setStatus(status.toString());
activityPost.setLastModified(postDate);
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
String filename = null, nodeType = null, mime = null, encoding = null;
long size = 0l;
String nodeId = finalNodeRef != null ? finalNodeRef.getId() : null;
FileInfo fileInfo = contentNodeInfo;
// Use content info
if (fileInfo != null) {
if (logger.isDebugEnabled()) {
logger.debug("Enhancing the Activity Event with fileInfo provided for node " + nodeId);
}
if (nodeId == null) {
nodeId = fileInfo.getNodeRef().getId();
}
filename = fileInfo.getName();
nodeType = fileInfo.getType().toString();
if (!fileInfo.isFolder()) {
// It's a file so get more info
ContentData contentData = fileInfo.getContentData();
if (contentData != null) {
mime = contentData.getMimetype();
size = contentData.getSize();
encoding = contentData.getEncoding();
}
}
}
return new ActivityEvent(activityType, transactionId, networkId, user, nodeId, site, nodeType, client, activityPost.getActivityData(), filename, mime, size, encoding);
}
});
// hash the userid to generate a job task node
int nodeCount = estGridSize;
int userHashCode = userId.hashCode();
int nodeHash = (userHashCode % nodeCount) + 1;
activityPost.setJobTaskNode(nodeHash);
try {
long postId = postDAO.insertPost(activityPost);
if (logger.isDebugEnabled()) {
activityPost.setId(postId);
logger.debug("Posted: " + activityPost);
}
} catch (SQLException e) {
throw new AlfrescoRuntimeException("Failed to post activity: " + e, e);
} catch (Throwable t) {
throw new AlfrescoRuntimeException("Failed to post activity: " + t, t);
}
} catch (AlfrescoRuntimeException e) {
// log error, subsume exception (for post activity)
logger.error(e);
}
}
use of org.alfresco.sync.events.types.ActivityEvent in project alfresco-repository by Alfresco.
the class FavouritesServiceImpl method removeFavouriteNode.
private boolean removeFavouriteNode(String userName, Type type, NodeRef nodeRef) {
boolean exists = false;
Map<PersonFavouriteKey, PersonFavourite> personFavourites = getFavouriteNodes(userName, type);
PersonFavouriteKey personFavouriteKey = new PersonFavouriteKey(userName, null, type, nodeRef);
PersonFavourite personFavourite = personFavourites.remove(personFavouriteKey);
exists = personFavourite != null;
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.removed", transactionId, networkId, user, finalRef, null, nodeType == null ? null : nodeType.toString(), Client.asType(ClientType.script), null, null, null, 0l, null);
}
});
OnRemoveFavouritePolicy policy = onRemoveFavouriteDelegate.get(nodeRef, nodeClass);
policy.onRemoveFavourite(userName, nodeRef);
return exists;
}
use of org.alfresco.sync.events.types.ActivityEvent in project alfresco-repository by Alfresco.
the class QuickShareServiceImpl method shareContent.
@Override
public QuickShareDTO shareContent(NodeRef nodeRef, Date expiryDate) throws QuickShareDisabledException, InvalidNodeRefException {
checkEnabled();
// Check the node is the correct type
final QName typeQName = nodeService.getType(nodeRef);
if (isSharable(typeQName) == false) {
throw new InvalidNodeRefException(nodeRef);
}
final String sharedId;
// If it is retura dto built from the existing properties.
if (!nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) {
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID();
// => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray());
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
// Disable audit to preserve modifier and modified date
// see MNT-11960
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try {
// consumer/contributor should be able to add "shared" aspect (MNT-10366)
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
public Void doWork() {
nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props);
return null;
}
});
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
final NodeRef tenantNodeRef = tenantService.getName(nodeRef);
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>() {
public Void doWork() throws Exception {
attributeService.setAttribute(tenantNodeRef, ATTR_KEY_SHAREDIDS_ROOT, sharedId);
return null;
}
});
final StringBuffer sb = new StringBuffer();
sb.append("{").append("\"sharedId\":\"").append(sharedId).append("\"").append("}");
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
return new ActivityEvent("quickshare", transactionId, networkId, user, nodeRef.getId(), null, typeQName.toString(), Client.asType(ClientType.webclient), sb.toString(), null, null, 0l, null);
}
});
if (logger.isInfoEnabled()) {
logger.info("QuickShare - shared content: " + sharedId + " [" + nodeRef + "]");
}
} else {
sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (logger.isDebugEnabled()) {
logger.debug("QuickShare - content already shared: " + sharedId + " [" + nodeRef + "]");
}
}
if (expiryDate != null) {
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
// Create and save the expiry action
saveSharedLinkExpiryAction(sharedId, expiryDate);
// if we get here, it means the expiry date is validated and the action
// is created and saved, so now set the expiryDate property.
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try {
nodeService.setProperty(nodeRef, QuickShareModel.PROP_QSHARE_EXPIRY_DATE, expiryDate);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
return null;
});
}
return new QuickShareDTO(sharedId, expiryDate);
}
Aggregations