use of org.alfresco.service.cmr.repository.ContentWriter in project alfresco-remote-api by Alfresco.
the class TestCMIS method testCreationDate.
/**
* MNT-12680
* The creation date of version should be the same as creation date of the original node
* @throws Exception
*/
@Test
public void testCreationDate() throws Exception {
// create a site
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
final TestSite site = network1.createSite(siteInfo);
final NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc.txt", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
return resNode;
}
}, person1Id, network1.getId());
// create a document
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
AlfrescoFolder docLibrary = (AlfrescoFolder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
Map<String, String> properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("some content");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document autoVersionedDoc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
String objectId = autoVersionedDoc.getId();
String bareObjectId = stripCMISSuffix(objectId);
// create versions
for (int i = 0; i < 3; i++) {
Document doc1 = (Document) cmisSession.getObject(bareObjectId);
ObjectId pwcId = doc1.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
ContentStreamImpl contentStream = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(GUID.generate());
ContentReader reader = writer.getReader();
contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentStream.setStream(reader.getContentInputStream());
}
pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
}
GregorianCalendar cDateFirst = cmisSession.getAllVersions(bareObjectId).get(0).getCreationDate();
GregorianCalendar cDateSecond = cmisSession.getAllVersions(bareObjectId).get(2).getCreationDate();
if (cDateFirst.before(cDateSecond) || cDateFirst.after(cDateSecond)) {
fail("The creation date of version should be the same as creation date of the original node");
}
}
use of org.alfresco.service.cmr.repository.ContentWriter in project alfresco-remote-api by Alfresco.
the class TestPeople method createAvatarDirect.
private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile) {
// create new avatar node
nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(personRef, ContentModel.ASSOC_PREFERENCE_IMAGE, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"), ContentModel.TYPE_CONTENT);
final NodeRef avatarRef = assoc.getChildRef();
// JSF client compatibility?
nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
// upload the avatar content
ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
writer.guessMimetype(avatarFile.getName());
writer.putContent(avatarFile);
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
renditions.createRendition(avatarRef, avatarR, false, null);
return avatarRef;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project alfresco-remote-api by Alfresco.
the class RepoService method createDocument.
public NodeRef createDocument(final NodeRef parentNodeRef, final String name, final String title, final String description, final String content) {
NodeRef nodeRef = fileFolderService.create(parentNodeRef, name, ContentModel.TYPE_CONTENT).getNodeRef();
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(content);
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, title);
nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, description);
return nodeRef;
}
use of org.alfresco.service.cmr.repository.ContentWriter in project alfresco-remote-api by Alfresco.
the class RepoStore method createDocument.
/* (non-Javadoc)
* @see org.alfresco.web.scripts.Store#createDocument(java.lang.String, java.lang.String)
*/
public void createDocument(String documentPath, String content) throws IOException {
String[] pathElements = documentPath.split("/");
String[] folderElements = new String[pathElements.length - 1];
System.arraycopy(pathElements, 0, folderElements, 0, pathElements.length - 1);
List<String> folderElementsList = Arrays.asList(folderElements);
// create folder
FileInfo pathInfo;
if (folderElementsList.size() == 0) {
pathInfo = fileService.getFileInfo(getBaseNodeRef());
} else {
pathInfo = FileFolderServiceImpl.makeFolders(fileService, getBaseNodeRef(), folderElementsList, ContentModel.TYPE_FOLDER);
}
// create file
String fileName = pathElements[pathElements.length - 1];
if (fileService.searchSimple(pathInfo.getNodeRef(), fileName) != null) {
throw new IOException("Document " + documentPath + " already exists");
}
FileInfo fileInfo = fileService.create(pathInfo.getNodeRef(), fileName, ContentModel.TYPE_CONTENT);
ContentWriter writer = fileService.getWriter(fileInfo.getNodeRef());
writer.putContent(content);
}
use of org.alfresco.service.cmr.repository.ContentWriter in project alfresco-remote-api by Alfresco.
the class ThumbnailServiceTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
this.contentService = (ContentService) getServer().getApplicationContext().getBean("ContentService");
this.repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
try {
this.transactionService = (TransactionServiceImpl) getServer().getApplicationContext().getBean("transactionComponent");
} catch (ClassCastException e) {
throw new AlfrescoRuntimeException("The ThumbnailServiceTest needs direct access to the TransactionServiceImpl");
}
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
this.testRoot = this.repositoryHelper.getCompanyHome();
// Get test content
InputStream pdfStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf");
assertNotNull(pdfStream);
InputStream jpgStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_image.jpg");
assertNotNull(jpgStream);
String guid = GUID.generate();
// Create new nodes and set test content
FileInfo fileInfoPdf = this.fileFolderService.create(this.testRoot, "test_doc" + guid + ".pdf", ContentModel.TYPE_CONTENT);
this.pdfNode = fileInfoPdf.getNodeRef();
ContentWriter contentWriter = this.contentService.getWriter(fileInfoPdf.getNodeRef(), ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_PDF);
contentWriter.putContent(pdfStream);
FileInfo fileInfoJpg = this.fileFolderService.create(this.testRoot, "test_image" + guid + ".jpg", ContentModel.TYPE_CONTENT);
this.jpgNode = fileInfoJpg.getNodeRef();
contentWriter = this.contentService.getWriter(fileInfoJpg.getNodeRef(), ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG);
contentWriter.putContent(jpgStream);
}
Aggregations