@Test public void testNoteCreationWithProperties() throws OperationException { Blob textBlob = Blobs.createBlob("foo", "text/plain", null, "foo.txt"); try (OperationContext ctx = new OperationContext(session)) { ctx.put("currentDocument", "/"); ctx.setInput(textBlob); Map<String, Serializable> params = new HashMap<>(); Properties properties = new Properties(); properties.put("dc:source", "bar"); params.put("properties", properties); DocumentModel doc = (DocumentModel) service.run(ctx, FileManagerImportWithProperties.ID, params); assertNotNull(doc); assertFalse(doc.isDirty()); assertNotNull(doc.getId()); assertEquals("Note", doc.getType()); assertEquals("foo.txt", doc.getTitle()); assertEquals("foo", doc.getPropertyValue("note:note")); assertEquals("bar", doc.getPropertyValue("dc:source")); assertEquals("0.1", doc.getVersionLabel()); } }
@OperationMethod public DocumentModel run(Blob blob) throws OperationException, IOException { DocumentModel currentDocument = getCurrentDocument(); String path = currentDocument.getPathAsString(); FileImporterContext fileCreationContext = FileImporterContext.builder(session, blob, path) .overwrite(overwrite) .mimeTypeCheck(mimeTypeCheck) .persistDocument(false) .build(); DocumentModel doc = fileManager.createOrUpdateDocument(fileCreationContext); DocumentHelper.setProperties(session, doc, properties); if (doc.isDirty()) { doc = doc.getId() == null ? session.createDocument(doc) : session.saveDocument(doc); } return doc; }
FileManagerImportWithProperties { @OperationMethod public DocumentModel run(Blob blob) throws OperationException, IOException { DocumentModel currentDocument = getCurrentDocument(); String path = currentDocument.getPathAsString(); FileImporterContext fileCreationContext = FileImporterContext.builder(session, blob, path) .overwrite(overwrite) .mimeTypeCheck(mimeTypeCheck) .persistDocument(false) .build(); DocumentModel doc = fileManager.createOrUpdateDocument(fileCreationContext); DocumentHelper.setProperties(session, doc, properties); if (doc.isDirty()) { doc = doc.getId() == null ? session.createDocument(doc) : session.saveDocument(doc); } return doc; } }
FileManagerImportWithProperties { @OperationMethod public DocumentModel run(Blob blob) throws OperationException, IOException { DocumentModel currentDocument = getCurrentDocument(); String path = currentDocument.getPathAsString(); FileImporterContext fileCreationContext = FileImporterContext.builder(session, blob, path) .overwrite(overwrite) .mimeTypeCheck(mimeTypeCheck) .persistDocument(false) .build(); DocumentModel doc = fileManager.createOrUpdateDocument(fileCreationContext); DocumentHelper.setProperties(session, doc, properties); if (doc.isDirty()) { doc = doc.getId() == null ? session.createDocument(doc) : session.saveDocument(doc); } return doc; }  }
FileManagerImportWithProperties { @OperationMethod public DocumentModel run(Blob blob) throws OperationException, IOException { DocumentModel currentDocument = getCurrentDocument(); String path = currentDocument.getPathAsString(); FileImporterContext fileCreationContext = FileImporterContext.builder(session, blob, path) .overwrite(overwrite) .mimeTypeCheck(mimeTypeCheck) .persistDocument(false) .build(); DocumentModel doc = fileManager.createOrUpdateDocument(fileCreationContext); DocumentHelper.setProperties(session, doc, properties); if (doc.isDirty()) { doc = doc.getId() == null ? session.createDocument(doc) : session.saveDocument(doc); } return doc; }  @OperationMethod DocumentModel run(Blob blob); @OperationMethod DocumentModelList run(BlobList blobs); }
FileManagerImportWithProperties { @OperationMethod public DocumentModel run(Blob blob) throws OperationException, IOException { DocumentModel currentDocument = getCurrentDocument(); String path = currentDocument.getPathAsString(); FileImporterContext fileCreationContext = FileImporterContext.builder(session, blob, path) .overwrite(overwrite) .mimeTypeCheck(mimeTypeCheck) .persistDocument(false) .build(); DocumentModel doc = fileManager.createOrUpdateDocument(fileCreationContext); DocumentHelper.setProperties(session, doc, properties); if (doc.isDirty()) { doc = doc.getId() == null ? session.createDocument(doc) : session.saveDocument(doc); } return doc; }  @OperationMethod DocumentModel run(Blob blob); @OperationMethod DocumentModelList run(BlobList blobs); static final String ID; }