use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method updateExistingFile.
private Node updateExistingFile(NodeRef parentNodeRef, NodeRef nodeRef, String fileName, BasicContentInfo contentInfo, InputStream stream, Parameters parameters, Boolean versionMajor, String versionComment) {
boolean isVersioned = versionService.isVersioned(nodeRef);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try {
writeContent(nodeRef, fileName, stream, true);
if ((isVersioned) || (versionMajor != null) || (versionComment != null)) {
VersionType versionType = null;
if (versionMajor != null) {
versionType = (versionMajor ? VersionType.MAJOR : VersionType.MINOR);
} else {
// note: it is possible to have versionable aspect but no versions (=> no version label)
if ((!isVersioned) || (nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL) == null)) {
versionType = VersionType.MAJOR;
} else {
versionType = VersionType.MINOR;
}
}
createVersion(nodeRef, isVersioned, versionType, versionComment);
}
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
postActivity(Activity_Type.UPDATED, activityInfo, false);
extractMetadata(nodeRef);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters);
}
use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method createNodeImpl.
private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props, QName assocTypeQName) {
NodeRef newNode = null;
if (props == null) {
props = new HashMap<>(1);
}
props.put(ContentModel.PROP_NAME, nodeName);
validatePropValues(props);
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
try {
newNode = nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, nodeTypeQName, props).getChildRef();
} catch (DuplicateChildNodeNameException dcne) {
// duplicate - name clash
throw new ConstraintViolatedException(dcne.getMessage());
}
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
postActivity(Activity_Type.ADDED, activityInfo, false);
return newNode;
}
use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method getActivityInfo.
// note: see also org.alfresco.opencmis.ActivityPosterImpl
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef) {
// runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not)
SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>() {
@Override
public SiteInfo doWork() throws Exception {
return siteService.getSite(nodeRef);
}
}, AuthenticationUtil.getSystemUserName());
String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
if (siteId != null && !siteId.equals("")) {
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
if (fileInfo != null) {
boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);
if (fileInfo.isFolder() || isContent) {
return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Non-site activity, so ignored " + nodeRef);
}
}
return null;
}
use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method getContent.
@Override
public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity) {
if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) {
throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
}
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
String name = (String) nodeProps.get(ContentModel.PROP_NAME);
org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
String mimeType = null;
if (cd != null) {
mimeType = cd.getMimetype();
ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale());
}
// By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach
boolean attach = true;
String attachment = parameters.getParameter("attachment");
if (attachment != null) {
Boolean a = Boolean.valueOf(attachment);
if (!a) {
if (nonAttachContentTypes.contains(mimeType)) {
attach = false;
} else {
logger.warn("Ignored attachment=false for " + nodeRef.getId() + " since " + mimeType + " is not in the whitelist for non-attach content types");
}
}
}
String attachFileName = (attach ? name : null);
if (recordActivity) {
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
postActivity(Activity_Type.DOWNLOADED, activityInfo, true);
}
return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName);
}
use of org.alfresco.service.cmr.activities.ActivityInfo in project alfresco-remote-api by Alfresco.
the class NodesImpl method deleteNode.
@Override
public void deleteNode(String nodeId, Parameters parameters) {
NodeRef nodeRef = validateOrLookupNode(nodeId, null);
if (isSpecialNode(nodeRef, getNodeType(nodeRef))) {
throw new PermissionDeniedException("Cannot delete: " + nodeId);
}
// default false (if not provided)
boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));
if (permanentDelete == true) {
boolean isAdmin = authorityService.hasAdminAuthority();
if (!isAdmin) {
String owner = ownableService.getOwner(nodeRef);
if (!AuthenticationUtil.getRunAsUser().equals(owner)) {
// non-owner/non-admin cannot permanently delete (even if they have delete permission)
throw new PermissionDeniedException("Non-owner/non-admin cannot permanently delete: " + nodeId);
}
}
// Set as temporary to delete node instead of archiving.
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
}
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
postActivity(Activity_Type.DELETED, activityInfo, true);
fileFolderService.delete(nodeRef);
}
Aggregations