private Document createDocumentWithoutChecks(Folder parent, String name) { // prepare properties Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.NAME, name); properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId()); // prepare empty content ContentStream contentStream = new ContentStreamImpl(name, BigInteger.ZERO, "text/plain", new ByteArrayInputStream(new byte[0])); // create the document return parent.createDocument(properties, contentStream, null, null, null, null, SELECT_ALL_NO_CACHE_OC); } }
private void uploadJsonFile(String baseFileName, String jsonSource, Folder workflowDefinitionFolder) { LOGGER.info("Upload json source..."); String jsonSrcFileName = baseFileName + ".json"; ContentStream jsonSrcContentStream = new ContentStreamImpl(jsonSrcFileName, null, "application/json", new ByteArrayInputStream(jsonSource.getBytes())); Document jsonDocument = getDocumentFromFolder(workflowDefinitionFolder.getPath(), jsonSrcFileName); if (jsonDocument == null) { HashMap<String, Object> jsonSrcProperties = new HashMap<String, Object>(); jsonSrcProperties.put(PropertyIds.NAME, jsonSrcFileName); jsonSrcProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); workflowDefinitionFolder.createDocument(jsonSrcProperties, jsonSrcContentStream, VersioningState.MAJOR); } else { jsonDocument.setContentStream(jsonSrcContentStream, true); } }
public static void main(String args[]) { String serverUrl = args[0]; String username = args[1]; String password = args[2]; Session session = getSession(serverUrl, username, password); Folder root = session.getRootFolder(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_ DOCUMENT.value()); String name = "New Document (" + System.currentTimeMillis() + ").txt"; properties.put(PropertyIds.NAME, name); List<Ace> addAces = new LinkedList<Ace>(); List<Ace> removeAces = new LinkedList<Ace>(); List<Policy> policies = new LinkedList<Policy>(); String content = "The quick brown fox jumps over the lazy dog."; ContentStream contentStream = new ContentStreamImpl("text.txt", BigInteger.valueOf(content.length()), "text/plain", new ByteArrayInputStream(content. getBytes())); Document newDocument = root.createDocument(properties, contentStream, VersioningState.MAJOR, policies, addAces, removeAces, session.getDefaultContext()); System.out.println(newDocument.getId());}
Document newDoc = root.createDocument(properties, contentStream, VersioningState.MAJOR); input.close();
protected void uploadStringToDocument(String string, String folderPath, String documentName, String mimetype) { Session cmisSession = getCmisSession(); Folder folder = (Folder) cmisSession.getObjectByPath(folderPath); ContentStream contentStream = new ContentStreamImpl(documentName, null, mimetype, new ByteArrayInputStream(string.getBytes())); Document document = getDocumentFromFolder(folder.getPath(), documentName); if (document == null) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name", documentName); properties.put("cmis:objectTypeId", "cmis:document"); folder.createDocument(properties, contentStream, VersioningState.MAJOR); } else { document.setContentStream(contentStream, true); } }
protected void uploadTaskModel(StringBuilder taskModelsString, String baseFileName) { Session session = getCmisSession(); Folder modelFolder = (Folder) session.getObjectByPath(DATA_DICTIONARY_FOLDER); String taskModelFileName = baseFileName + "-task-model.xml"; // Finally, wrap all taskdefinitions is right XML -> this is the FULL // model file, including generic start-task String taskModelId = UUID.randomUUID().toString(); String taskModelXML = MessageFormat.format(getTaskModelTemplate(), taskModelId, taskModelsString.toString()); LOGGER.info("Deploying task model XML:"); prettyLogXml(taskModelXML); ByteArrayInputStream inputStream = new ByteArrayInputStream(taskModelXML.getBytes()); ContentStream contentStream = new ContentStreamImpl(taskModelFileName, null, "application/xml", inputStream); // Verify whether it is an update or a new workflow Document taskModelDocument = getDocumentFromFolder(DATA_DICTIONARY_FOLDER, taskModelFileName); if (taskModelDocument == null) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name", taskModelFileName); properties.put("cmis:objectTypeId", "D:cm:dictionaryModel"); properties.put("cm:modelActive", true); LOGGER.info("Task model file : " + taskModelFileName); modelFolder.createDocument(properties,contentStream, VersioningState.MAJOR); } else { LOGGER.info("Updating content of " + taskModelFileName); taskModelDocument.setContentStream(contentStream, true); } }
ContentStream contentStream = getSession().getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream); Document doc = folder.createDocument( properties, contentStream,
properties.put("cm:description", kickstartWorkflow.getName()); processDocument = workflowDefinitionFolder.createDocument(properties, processContentStream, VersioningState.MAJOR);
private void uploadDiagramFile(KickstartWorkflow kickstartWorkflow, String baseFileName, Folder workflowDefinitionFolder) { LOGGER.info("Generating process image..."); ProcessDiagramGenerator diagramGenerator = new ProcessDiagramGenerator(kickstartWorkflow, marshallingService); InputStream diagramInputStream = diagramGenerator.execute(); // Diagram is deployed next to the process xml if (workflowDefinitionFolder == null) { throw new RuntimeException("Cannot find workflow definition folder '" + WORKFLOW_DEFINITION_FOLDER + "'"); } String diagramFileName = baseFileName + ".png"; ContentStream diagramContentStream = new ContentStreamImpl(diagramFileName, null, "image/png", diagramInputStream); Document diagramDocument = getDocumentFromFolder(workflowDefinitionFolder.getPath(), diagramFileName); if (diagramDocument == null) { HashMap<String, Object> diagramProperties = new HashMap<String, Object>(); diagramProperties.put(PropertyIds.NAME, diagramFileName); diagramProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); workflowDefinitionFolder.createDocument(diagramProperties, diagramContentStream, VersioningState.MAJOR); } else { diagramDocument.setContentStream(diagramContentStream, true); } }
return parentFolder.createDocument(properties, contentStream, versioningState); } finally { IOUtils.closeQuietly(contentStream);
return parentFolder.createDocument(properties, contentStream, versioningState); } finally { IOUtils.closeQuietly(contentStream);
return parentFolder.createDocument(properties, contentStream, versioningState); } finally { IOUtils.closeQuietly(contentStream);
return parentFolder.createDocument(properties, contentStream, versioningState); } finally { IOUtils.closeQuietly(contentStream);
public void setProcessImage(String processDefinitionId, InputStream processImageStream) { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(WORKFLOW_DEFINITION_FOLDER); String fileName = processDefinitionIdToProcessImage(processDefinitionId); ContentStream contentStream = new ContentStreamImpl(fileName, null, "image/png", processImageStream); Document imageDocument = getDocumentFromFolder(workflowDefinitionFolder.getPath(), fileName); if (imageDocument == null) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name", fileName); properties.put("cmis:objectTypeId", "cmis:document"); workflowDefinitionFolder.createDocument(properties, contentStream, VersioningState.MAJOR); } else { imageDocument.setContentStream(contentStream, true); } }
@Override public void createDocument(DocumentSummary doc) { Session session = getSession(); if (session != null) { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); properties.put(PropertyIds.NAME, doc.getName()); InputStream stream = new ByteArrayInputStream(doc.getContent()); ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(doc.getContent().length), MimeTypes.getMIMEType(doc.getName()), stream); Document createdDoc = ((Folder) session.getObjectByPath(doc.getPath())).createDocument( properties, contentStream, VersioningState.NONE); doc.setId(createdDoc.getId()); } else { throw new IllegalStateException("Could not get CMIS session"); } }
private static Document createDocument(Folder target, String newDocName, Session session) { Map<String, String> props = new HashMap<String, String>(); props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); props.put(PropertyIds.NAME, newDocName); String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation."; byte[] buf = null; try { buf = content.getBytes("ISO-8859-1"); // set the encoding here for the content stream } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ByteArrayInputStream input = new ByteArrayInputStream(buf); ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length, "text/plain; charset=UTF-8", input); // additionally set the charset here // NOTE that we intentionally specified the wrong charset here (as UTF-8) // because Alfresco does automatic charset detection, so we will ignore this explicit request return target.createDocument(props, contentStream, VersioningState.MAJOR); } }
BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes)); testFolder.createDocument(properties, contentStream, null);
return ObjectId.toString(ObjectId.Type.OBJECT, parent.createFolder(params).getId()); case CMIS_DOCUMENT: return ObjectId.toString(ObjectId.Type.OBJECT, parent.createDocument(params, null, VersioningState.NONE).getId()); default: return null;
public void testDownloadEvent() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); String docname = "mydoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, docname); } // content byte[] byteContent = "Hello from Download testing class".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream); Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); ContentStream content = doc1.getContentStream(); assertNotNull(content); //range request content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4)); assertNotNull(content); }
public void DISABLED_testBasicFileOps() { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); // create folder Map<String,String> folderProps = new HashMap<String, String>(); { folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate()); } Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext()); Map<String, String> fileProps = new HashMap<String, String>(); { fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt"); } ContentStreamImpl fileContent = new ContentStreamImpl(); { ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt")); writer.putContent("Ipsum and so on"); ContentReader reader = writer.getReader(); fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN); fileContent.setStream(reader.getContentInputStream()); } folder.createDocument(fileProps, fileContent, VersioningState.MAJOR); }