Java Code Examples for org.alfresco.service.cmr.repository.ContentWriter#getContentData()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentWriter#getContentData() .
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: DeletionMetricsRunner.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void createContent() { final StoreRef storeRef = nodeService.createStore("test", "timings-" + GUID.generate()); RetryingTransactionCallback<ContentData> testCallback = new RetryingTransactionCallback<ContentData>() { public ContentData execute() throws Throwable { ContentData contentData = null; for (int i = 0; i < numOrphans; i++) { // Create some content NodeRef rootNodeRef = nodeService.getRootNode(storeRef); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13); properties.put(ContentModel.PROP_NAME, (Serializable)"test.txt"); NodeRef contentNodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT, properties).getChildRef(); ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.putContent("INITIAL CONTENT"); contentData = writer.getContentData(); // Delete the first node, bypassing archive nodeService.addAspect(contentNodeRef, ContentModel.ASPECT_TEMPORARY, null); nodeService.deleteNode(contentNodeRef); } // Done return contentData; } }; transactionService.getRetryingTransactionHelper().doInTransaction(testCallback); }
Example 2
Source File: RoutingContentServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Checks what happens when the physical content disappears */ public void testMissingContent() throws Exception { // whitelist the test as it has to manipulate content property directly ContentPropertyRestrictionInterceptor contentPropertyRestrictionInterceptor = (ContentPropertyRestrictionInterceptor) ctx.getBean("contentPropertyRestrictionInterceptor"); contentPropertyRestrictionInterceptor.setGlobalContentPropertyRestrictionWhiteList(this.getClass().getName()); try { File tempFile = TempFileProvider.createTempFile(getName(), ".txt"); ContentWriter writer = new FileContentWriter(tempFile); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); writer.putContent("What about the others? Buckwheats!"); // check assertTrue("File does not exist", tempFile.exists()); assertTrue("File not written to", tempFile.length() > 0); // update the node with this new info ContentData contentData = writer.getContentData(); nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, contentData); // delete the content tempFile.delete(); assertFalse("File not deleted", tempFile.exists()); // now attempt to get the reader for the node ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertFalse("Reader should indicate that content is missing", reader.exists()); // check the indexing doesn't spank everthing txn.commit(); txn = null; // cleanup txn = getUserTransaction(); txn.begin(); nodeService.deleteNode(contentNodeRef); txn.commit(); txn = null; } finally { contentPropertyRestrictionInterceptor.setGlobalContentPropertyRestrictionWhiteList(""); } }