Java Code Examples for org.alfresco.service.cmr.repository.ContentWriter#setMimetype()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentWriter#setMimetype() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Check that a valid writer into the content store can be retrieved and used. */ public void testSimpleNonTempWriter() throws Exception { ContentWriter writer = contentService.getWriter(null, null, false); assertNotNull("Writer should not be null", writer); assertNotNull("Content URL should not be null", writer.getContentUrl()); // write some content writer.putContent(SOME_CONTENT); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // get the reader ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNotNull("Reader should not be null", reader); assertNotNull("Content URL should not be null", reader.getContentUrl()); assertEquals("Content Encoding was not set", "UTF-16", reader.getEncoding()); assertEquals("Content Locale was not set", Locale.CHINESE, reader.getLocale()); }
Example 2
Source File: ThumbnailServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private NodeRef createCorruptedContent(NodeRef parentFolder) throws IOException { // The below pdf file has been truncated such that it is identifiable as a PDF but otherwise corrupt. File corruptPdfFile = AbstractContentTransformerTest.loadNamedQuickTestFile("quickCorrupt.pdf"); assertNotNull("Failed to load required test file.", corruptPdfFile); Map<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(ContentModel.PROP_NAME, "corrupt.pdf"); NodeRef node = this.secureNodeService.createNode(parentFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "quickCorrupt.pdf"), ContentModel.TYPE_CONTENT, props).getChildRef(); secureNodeService.setProperty(node, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_PDF, 0L, null)); ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_PDF); writer.setEncoding("UTF-8"); writer.putContent(corruptPdfFile); return node; }
Example 3
Source File: EMLTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a valid eml with an attachment to text; attachment should be ignored */ public void testRFC822WithAttachmentToText() throws Exception { File emlSourceFile = loadQuickTestFile("attachment.eml"); File txtTargetFile = TempFileProvider.createTempFile("test3", ".txt"); ContentReader reader = new FileContentReader(emlSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_RFC822); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); String contentStr = reader2.getContentString(); assertTrue(contentStr.contains(QUICK_EML_WITH_ATTACHMENT_CONTENT)); assertTrue(!contentStr.contains(QUICK_EML_ATTACHMENT_CONTENT)); }
Example 4
Source File: MessageServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void addMessageResource(NodeRef rootNodeRef, String name, InputStream resourceStream) throws Exception { Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); contentProps.put(ContentModel.PROP_NAME, name); ChildAssociationRef association = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), ContentModel.TYPE_CONTENT, contentProps); NodeRef content = association.getChildRef(); ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); writer.putContent(resourceStream); resourceStream.close(); }
Example 5
Source File: GetChildrenCannedQueryTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private NodeRef createContent(NodeRef parentNodeRef, QName childAssocType, String fileName, QName contentType) throws IOException { Map<QName,Serializable> properties = new HashMap<QName,Serializable>(); properties.put(ContentModel.PROP_NAME, fileName); properties.put(ContentModel.PROP_TITLE, fileName+" my title"); properties.put(ContentModel.PROP_DESCRIPTION, fileName+" my description"); NodeRef nodeRef = nodeService.getChildByName(parentNodeRef, childAssocType, fileName); if (nodeRef != null) { nodeService.deleteNode(nodeRef); } nodeRef = nodeService.createNode(parentNodeRef, childAssocType, QName.createQName(fileName), contentType, properties).getChildRef(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(mimetypeService.guessMimetype(fileName)); writer.putContent("my text content"); return nodeRef; }
Example 6
Source File: MailContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test transforming a chinese non-unicode msg file to * text */ public void testNonUnicodeChineseMsgToText() throws Exception { File msgSourceFile = loadQuickTestFile("chinese.msg"); File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt"); ContentReader reader = new FileContentReader(msgSourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG); ContentWriter writer = new FileContentWriter(txtTargetFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); transformer.transform(reader, writer); ContentReader reader2 = new FileContentReader(txtTargetFile); reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // Check the quick text String text = reader2.getContentString(); assertTrue(text.contains(QUICK_CONTENT)); // Now check the non quick parts came out ok assertTrue(text.contains("(\u5f35\u6bd3\u502b)")); assertTrue(text.contains("\u683c\u5f0f\u6e2c\u8a66 )")); }
Example 7
Source File: UserUsageTrackingComponentTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NodeRef addTextContent(NodeRef spaceRef, String fileName, String textData) { Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); contentProps.put(ContentModel.PROP_NAME, fileName); ChildAssociationRef association = nodeService.createNode(spaceRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName), ContentModel.TYPE_CONTENT, contentProps); NodeRef content = association.getChildRef(); // add titled aspect (for Web Client display) Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(); titledProps.put(ContentModel.PROP_TITLE, fileName); titledProps.put(ContentModel.PROP_DESCRIPTION, fileName); this.nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps); ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); writer.putContent(textData); return content; }
Example 8
Source File: CommentsPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * add the comment from json to given nodeRef * * @param nodeRef * @param json * @return */ private NodeRef addComment(NodeRef nodeRef, JSONObject json) { // fetch the parent to add the node to NodeRef commentsFolder = getOrCreateCommentsFolder(nodeRef); // get a unique name String name = getUniqueChildName("comment"); // create the comment NodeRef commentNodeRef = nodeService.createNode(commentsFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(name)), ForumModel.TYPE_POST).getChildRef(); // fetch the title required to create a comment String title = getOrNull(json, JSON_KEY_TITLE); HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f); props.put(ContentModel.PROP_TITLE, title != null ? title : ""); nodeService.addProperties(commentNodeRef, props); ContentWriter writer = contentService.getWriter(commentNodeRef, ContentModel.PROP_CONTENT, true); // fetch the content of a comment String contentString = getOrNull(json, JSON_KEY_CONTENT); writer.setMimetype(MimetypeMap.MIMETYPE_HTML); writer.putContent(contentString); return commentNodeRef; }
Example 9
Source File: XSLTFunctionsTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ private FileInfo createXmlFile(NodeRef folder) { String name = GUID.generate(); FileInfo testXmlFile = fileFolderService.create(folder, name + ".xml", ContentModel.TYPE_CONTENT); ContentWriter writer = contentService.getWriter(testXmlFile.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype("text/xml"); writer.setEncoding("UTF-8"); writer.putContent(sampleXML); return testXmlFile; }
Example 10
Source File: XSLTRenderingEngineTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private FileInfo createXmlFile(NodeRef folder, String filename, String content) { FileInfo testXmlFile = fileFolderService.create(folder, filename, ContentModel.TYPE_CONTENT); ContentWriter writer = contentService.getWriter(testXmlFile.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype("text/xml"); writer.setEncoding("UTF-8"); writer.putContent(content); return testXmlFile; }
Example 11
Source File: AbstractEmailMessageHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Write content to the node from InputStream. * * @param nodeRef Target node. * @param content Content stream. * @param mimetype MIME content type. * @param encoding Encoding. Can be null for text based content, n which case the best guess. */ protected void writeContent(NodeRef nodeRef, InputStream content, String mimetype, String encoding) { InputStream bis = new BufferedInputStream(content, 4092); // Only guess the encoding if it has not been supplied if (encoding == null) { if (mimetypeService.isText(mimetype)) { ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder(); encoding = charsetFinder.getCharset(bis, mimetype).name(); } else { encoding = "UTF-8"; } } if (log.isDebugEnabled()) { log.debug("Write content (MimeType=\"" + mimetype + "\", Encoding=\"" + encoding + "\""); } ContentService contentService = getContentService(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(mimetype); writer.setEncoding(encoding); writer.putContent(bis); }
Example 12
Source File: UserUsageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void updateTextContent(NodeRef contentRef, String textData) { ContentWriter writer = contentService.getWriter(contentRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); writer.putContent(textData); }
Example 13
Source File: StringExtractingContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generate a large file and then transform it using the text extractor. * We are not creating super-large file (1GB) in order to test the transform * as it takes too long to create the file in the first place. Rather, * this test can be used during profiling to ensure that memory is not * being consumed. */ public void testLargeFileStreaming() throws Exception { File sourceFile = TempFileProvider.createTempFile(getName(), ".txt"); int chars = 1000000; // a million characters should do the trick Random random = new Random(); Writer charWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(sourceFile))); for (int i = 0; i < chars; i++) { char next = (char)(random.nextDouble() * 93D + 32D); charWriter.write(next); } charWriter.close(); // get a reader and a writer ContentReader reader = new FileContentReader(sourceFile); reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); File outputFile = TempFileProvider.createTempFile(getName(), ".txt"); ContentWriter writer = new FileContentWriter(outputFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); // transform transformer.transform(reader, writer); // delete files sourceFile.delete(); outputFile.delete(); }
Example 14
Source File: XSLTProcessorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private FileInfo createXmlFile(NodeRef folder, String content) { String name = GUID.generate(); FileInfo testXmlFile = fileFolderService.create(folder, name + ".xml", ContentModel.TYPE_CONTENT); ContentWriter writer = contentService.getWriter(testXmlFile.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype("text/xml"); writer.setEncoding("UTF-8"); writer.putContent(content); return testXmlFile; }
Example 15
Source File: DownloadRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName, String content) { NodeRef nodeRef = createNode(parentNode, nodeCmName, nodeType, ownerUserName); // If there is any content, add it. if (content != null) { ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); writer.putContent(content); } return nodeRef; }
Example 16
Source File: StringExtractingContentTransformerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Writes some content using the mimetype and encoding specified. * * @param mimetype String * @param encoding String * @return Returns a reader onto the newly written content */ private ContentReader writeContent(String mimetype, String encoding) { ContentWriter writer = new FileContentWriter(getTempFile()); writer.setMimetype(mimetype); writer.setEncoding(encoding); // put content writer.putContent(SOME_CONTENT); // return a reader onto the new content return writer.getReader(); }
Example 17
Source File: CommentServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public NodeRef createComment(final NodeRef discussableNode, String title, String comment, boolean suppressRollups) { if(comment == null) { throw new IllegalArgumentException("Must provide a non-null comment"); } // There is no CommentService, so we have to create the node structure by hand. // This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API. if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE)) { nodeService.addAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE, null); } if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups) { nodeService.addAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP, null); } // Forum node is created automatically by DiscussableAspect behaviour. NodeRef forumNode = nodeService.getChildAssocs(discussableNode, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef(); final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, FORUM_TO_TOPIC_ASSOC_QNAME); NodeRef topicNode = null; if (existingTopics.isEmpty()) { Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f); props.put(ContentModel.PROP_NAME, COMMENTS_TOPIC_NAME); topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, FORUM_TO_TOPIC_ASSOC_QNAME, ForumModel.TYPE_TOPIC, props).getChildRef(); } else { topicNode = existingTopics.get(0).getChildRef(); } NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS, ForumModel.TYPE_POST).getChildRef(); nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null)); nodeService.setProperty(postNode, ContentModel.PROP_TITLE, title); ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_HTML); writer.setEncoding("UTF-8"); writer.putContent(comment); // determine the siteId and activity data of the comment NodeRef String siteId = getSiteId(discussableNode); JSONObject activityData = getActivityData(siteId, discussableNode); postActivity(siteId, ActivityType.COMMENT_CREATED, activityData); return postNode; }
Example 18
Source File: RuleServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Commit @Test public void testCyclicAsyncRules() throws Exception { NodeRef nodeRef = createNewNode(this.rootNodeRef); // Create the first rule Map<String, Serializable> conditionProps = new HashMap<String, Serializable>(); conditionProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*.jpg"); Map<String, Serializable> actionProps = new HashMap<String, Serializable>(); actionProps.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_GIF); actionProps.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, nodeRef); actionProps.put(ImageTransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN); actionProps.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN); Rule rule = new Rule(); rule.setRuleType(this.ruleType.getName()); rule.setTitle("Convert from *.jpg to *.gif"); rule.setExecuteAsynchronously(true); Action action = this.actionService.createAction(ImageTransformActionExecuter.NAME); action.setParameterValues(actionProps); ActionCondition actionCondition = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME); actionCondition.setParameterValues(conditionProps); action.addActionCondition(actionCondition); rule.setAction(action); // Create the next rule Map<String, Serializable> conditionProps2 = new HashMap<String, Serializable>(); conditionProps2.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*.gif"); Map<String, Serializable> actionProps2 = new HashMap<String, Serializable>(); actionProps2.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG); actionProps2.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, nodeRef); actionProps2.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN); Rule rule2 = new Rule(); rule2.setRuleType(this.ruleType.getName()); rule2.setTitle("Convert from *.gif to *.jpg"); rule2.setExecuteAsynchronously(true); Action action2 = this.actionService.createAction(ImageTransformActionExecuter.NAME); action2.setParameterValues(actionProps2); ActionCondition actionCondition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME); actionCondition2.setParameterValues(conditionProps2); action2.addActionCondition(actionCondition2); rule2.setAction(action2); // Save the rules this.ruleService.saveRule(nodeRef, rule); this.ruleService.saveRule(nodeRef, rule); // Now create new content NodeRef contentNode = this.nodeService.createNode(nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_CONTENT).getChildRef(); this.nodeService.setProperty(contentNode, ContentModel.PROP_NAME, "myFile.jpg"); File file = AbstractContentTransformerTest.loadQuickTestFile("jpg"); ContentWriter writer = this.contentService.getWriter(contentNode, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); writer.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG); writer.putContent(file); //final NodeRef finalNodeRef = nodeRef; // Check to see what has happened // ActionServiceImplTest.postAsyncActionTest( // this.transactionService, // 10000, // 10, // new AsyncTest() // { // public boolean executeTest() // { // List<ChildAssociationRef> assocs = RuleServiceImplTest.this.nodeService.getChildAssocs(finalNodeRef); // for (ChildAssociationRef ref : assocs) // { // NodeRef child = ref.getChildRef(); // System.out.println("Child name: " + RuleServiceImplTest.this.nodeService.getProperty(child, ContentModel.PROP_NAME)); // } // // return true; // }; // }); }
Example 19
Source File: AlfrescoCmisServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String createDocument( String repositoryId, final Properties properties, String folderId, final ContentStream contentStream, VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) { checkRepositoryId(repositoryId); // get the parent folder node ref final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder"); // get name and type final String name = connector.getNameProperty(properties, null); final String objectTypeId = connector.getObjectTypeIdProperty(properties); final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_DOCUMENT); connector.checkChildObjectType(parentInfo, type.getTypeId()); DocumentTypeDefinition docType = (DocumentTypeDefinition) type.getTypeDefinition(false); if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null)) { throw new CmisConstraintException("This document type does not support content!"); } if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null)) { throw new CmisConstraintException("This document type does requires content!"); } if (!docType.isVersionable() && (versioningState != VersioningState.NONE)) { throw new CmisConstraintException("This document type is not versionable!"); } versioningState = getDocumentDefaultVersioningState(versioningState, type); FileInfo fileInfo = connector.getFileFolderService().create( parentInfo.getNodeRef(), name, type.getAlfrescoClass()); NodeRef nodeRef = fileInfo.getNodeRef(); connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID }); connector.applyPolicies(nodeRef, type, policies); connector.applyACL(nodeRef, type, addAces, removeAces); // handle content if (contentStream != null) { // write content String mimeType = parseMimeType(contentStream); String encoding = getEncoding(contentStream.getStream(), mimeType); ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef); writer.setMimetype(mimeType); writer.setEncoding(encoding); writer.putContent(contentStream.getStream()); } connector.extractMetadata(nodeRef); // generate "doclib" thumbnail asynchronously connector.createThumbnails(nodeRef, Collections.singleton("doclib")); connector.applyVersioningState(nodeRef, versioningState); String objectId = connector.createObjectId(nodeRef); connector.getActivityPoster().postFileFolderAdded(nodeRef); return objectId; }
Example 20
Source File: ContentMetadataExtracterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Ensure that missing raw values result in node properties being removed * when running with {@link ContentMetadataExtracter#setCarryAspectProperties(boolean)} * set to <tt>false</tt>. */ @Test public void testNullExtractedValues_ALF1823() { MetadataExtracterRegistry registry = (MetadataExtracterRegistry) applicationContext.getBean("metadataExtracterRegistry"); TestNullPropMetadataExtracter extractor = new TestNullPropMetadataExtracter(); extractor.setRegistry(registry); extractor.register(); // Now set the title and description nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "TITLE"); nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "DESCRIPTION"); // Now add some content with a binary mimetype ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); cw.setMimetype(MimetypeMap.MIMETYPE_BINARY); cw.putContent("Content for " + getName()); ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null); executer.execute(action, this.nodeRef); // cm:titled properties should be present Serializable title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE); Serializable descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION); assertNotNull("cm:title property is null", title); assertNotNull("cm:description property is null", descr); try { // Now change the setting to remove unset aspect properties executer.setCarryAspectProperties(false); // Extract again executer.execute(action, this.nodeRef); // cm:titled properties should *NOT* be present title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE); descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION); assertNull("cm:title property is not null", title); assertNull("cm:description property is not null", descr); } finally { executer.setCarryAspectProperties(true); } }