use of org.alfresco.repo.jscript.ScriptNode in project alfresco-remote-api by Alfresco.
the class ScriptCommentService method createCommentsFolder.
public ScriptNode createCommentsFolder(ScriptNode node) {
final NodeRef nodeRef = node.getNodeRef();
if (permissionService.hasPermission(nodeRef, PermissionService.ADD_CHILDREN) == AccessStatus.DENIED) {
throw new AccessDeniedException("User '" + AuthenticationUtil.getFullyAuthenticatedUser() + "' doesn't have permission to create discussion on node '" + nodeRef + "'");
}
// Run as system user to allow Contributor create discussions
NodeRef commentsFolder = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() {
public NodeRef doWork() throws Exception {
NodeRef commentsFolder = null;
// ALF-5240: turn off auditing round the discussion node creation to prevent
// the source document from being modified by the first user leaving a comment
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try {
nodeService.addAspect(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussable"), null);
nodeService.addAspect(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "commentsRollup"), null);
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(nodeRef, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion"), RegexQNamePattern.MATCH_ALL);
if (assocs.size() != 0) {
NodeRef forumFolder = assocs.get(0).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME);
commentsFolder = nodeService.createNode(forumFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, COMMENTS_TOPIC_NAME), QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "topic"), props).getChildRef();
}
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
return commentsFolder;
}
}, AuthenticationUtil.getSystemUserName());
return new ScriptNode(commentsFolder, serviceRegistry, getScope());
}
use of org.alfresco.repo.jscript.ScriptNode in project alfresco-remote-api by Alfresco.
the class QuickShareThumbnailContentGet method executeImpl.
@Override
protected void executeImpl(NodeRef nodeRef, Map<String, String> templateVars, WebScriptRequest req, WebScriptResponse res, Map<String, Object> model) throws IOException {
String thumbnailName = templateVars.get("thumbnailname");
if (thumbnailName == null) {
logger.error("Thumbnail name was not provided: " + nodeRef);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + nodeRef);
}
// the latest thumbnail image.
if (model == null) {
model = new HashMap<String, Object>(1);
}
if (req.getParameter("lastModified") != null) {
// note: must be String not boolean
model.put("allowBrowserToCache", "true");
} else {
// note: must be String not boolean
model.put("allowBrowserToCache", "false");
}
NodeRef thumbnailNodeRef = thumbnailService.getThumbnailByName(nodeRef, ContentModel.PROP_CONTENT, thumbnailName);
if (thumbnailNodeRef == null) {
// Get the queue/force create setting
boolean qc = false;
boolean fc = false;
String c = req.getParameter("c");
if (c != null) {
if (c.equals("queue")) {
qc = true;
} else if (c.equals("force")) {
fc = true;
}
}
// Get the place holder flag
boolean ph = false;
String phString = req.getParameter("ph");
if (phString != null) {
ph = new Boolean(phString);
}
// note: required for ValueConverter (collection)
Scriptable scope = new BaseScopableProcessorExtension().getScope();
ScriptNode node = new ScriptNode(nodeRef, serviceRegistry, scope);
// Queue the creation of the thumbnail if appropriate
if (fc) {
ScriptNode thumbnailNode = node.createThumbnail(thumbnailName, false);
if (thumbnailNode != null) {
thumbnailNodeRef = thumbnailNode.getNodeRef();
}
} else {
if (qc) {
node.createThumbnail(thumbnailName, true);
}
}
if (thumbnailNodeRef == null) {
if (ph == true) {
// Try and get the place holder resource. We use a method in the thumbnail service
// that by default gives us a resource based on the content's mime type.
String phPath = null;
ContentData contentData = (ContentData) this.serviceRegistry.getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
if (contentData != null) {
phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath(thumbnailName, contentData.getMimetype());
}
if (phPath == null) {
// 404 since no thumbnail was found
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Thumbnail was not found and no place holder resource set for '" + thumbnailName + "'");
} else {
// Set the resouce path in the model ready for the content stream to send back to the client
model.put("contentPath", phPath);
}
} else {
// 404 since no thumbnail was found
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Thumbnail was not found");
}
}
}
super.executeImpl(thumbnailNodeRef, templateVars, req, res, model);
if (logger.isDebugEnabled()) {
logger.debug("QuickShare - retrieved thumbnail content: " + thumbnailNodeRef + " [" + nodeRef + "," + thumbnailName + "]");
}
}
Aggregations