diff --git a/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/BlobHolderAdapterComponent.java b/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/BlobHolderAdapterComponent.java index 1f3a47f1f310..5aa883c17407 100644 --- a/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/BlobHolderAdapterComponent.java +++ b/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/BlobHolderAdapterComponent.java @@ -1,5 +1,5 @@ /* - * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. + * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ * * Contributors: * Nuxeo - initial API and implementation - * */ package org.nuxeo.ecm.core.api.blobholder; @@ -51,11 +50,11 @@ public class BlobHolderAdapterComponent extends DefaultComponent implements Blob public static final String EXTERNALBLOB_ADAPTER_EP = "ExternalBlobAdapter"; - protected final Map factories = new HashMap(); + protected final Map factories = new HashMap<>(); - protected Map factoriesByFacets = new HashMap(); + protected Map factoriesByFacets = new HashMap<>(); - protected static final Map externalBlobAdapters = new HashMap(); + protected static final Map externalBlobAdapters = new HashMap<>(); @Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { @@ -94,7 +93,8 @@ public void unregisterContribution(Object contribution, String extensionPoint, C /* for test */ public static Set getFactoryNames() { - return ((BlobHolderAdapterComponent) Framework.getLocalService(BlobHolderAdapterService.class)).factories.keySet(); + return ((BlobHolderAdapterComponent) Framework.getLocalService( + BlobHolderAdapterService.class)).factories.keySet(); } /* Service Interface */ @@ -136,7 +136,7 @@ public BlobHolder getBlobHolderAdapter(DocumentModel doc) { } if (doc.hasSchema("file")) { - return new DocumentBlobHolder(doc, "file:content", "file:filename"); + return new DocumentBlobHolder(doc, "file:content"); } else if (doc.hasSchema("note")) { String mt = null; try { diff --git a/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/DocumentBlobHolder.java b/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/DocumentBlobHolder.java index a5c5c4a51948..d274c95c4754 100644 --- a/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/DocumentBlobHolder.java +++ b/nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/blobholder/DocumentBlobHolder.java @@ -1,5 +1,5 @@ /* - * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. + * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,7 @@ * * Contributors: * Nuxeo - initial API and implementation - * */ - package org.nuxeo.ecm.core.api.blobholder; import java.io.Serializable; @@ -41,21 +39,11 @@ public class DocumentBlobHolder extends AbstractBlobHolder { protected final String xPath; - protected String xPathFilename; - protected List blobList = null; - /** - * Constructor with filename property for compatibility (when filename was not stored on blob object) - */ - public DocumentBlobHolder(DocumentModel doc, String xPath, String xPathFilename) { + public DocumentBlobHolder(DocumentModel doc, String xPath) { this.doc = doc; this.xPath = xPath; - this.xPathFilename = xPathFilename; - } - - public DocumentBlobHolder(DocumentModel doc, String xPath) { - this(doc, xPath, null); } @Override @@ -65,24 +53,12 @@ protected String getBasePath() { @Override public Blob getBlob() { - Blob blob = (Blob) doc.getPropertyValue(xPath); - if (blob != null && xPathFilename != null) { - String filename = blob.getFilename(); - if (filename == null || "".equals(filename)) { - // compatibility when filename was not stored on blob - blob.setFilename((String) doc.getPropertyValue(xPathFilename)); - } - } - return blob; + return(Blob) doc.getPropertyValue(xPath); } @Override public void setBlob(Blob blob) { doc.getProperty(xPath).setValue(blob); - if (xPathFilename != null) { - String filename = blob == null ? null : blob.getFilename(); - doc.setPropertyValue(xPathFilename, filename); - } } @Override diff --git a/nuxeo-core/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/utils/TestBlobsExtractor.java b/nuxeo-core/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/utils/TestBlobsExtractor.java index 44e8ae8f29c8..961089257049 100644 --- a/nuxeo-core/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/utils/TestBlobsExtractor.java +++ b/nuxeo-core/nuxeo-core-api/src/test/java/org/nuxeo/ecm/core/utils/TestBlobsExtractor.java @@ -119,10 +119,8 @@ public void testGetBlobsPropertiesBlobList() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "doc", "BlobInListDocument"); Map map1 = new HashMap<>(); map1.put("file", createBlob("test1.pdf")); - map1.put("filename", "test1.pdf"); Map map2 = new HashMap<>(); map2.put("file", createBlob("test2.pdf")); - map2.put("filename", "test2.pdf"); doc.setPropertyValue("bil:files", (Serializable) Arrays.asList(map1, map2)); List blobs; diff --git a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/blobinlist.xsd b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/blobinlist.xsd index e17401762545..c17dad7fd717 100644 --- a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/blobinlist.xsd +++ b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/blobinlist.xsd @@ -23,12 +23,7 @@ - - - - diff --git a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/externalfile.xsd b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/externalfile.xsd index 7991a866cec9..935f280470a8 100644 --- a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/externalfile.xsd +++ b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/externalfile.xsd @@ -5,7 +5,6 @@ - diff --git a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/file.xsd b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/file.xsd index e5ebf8f9cd12..75eb452f29b2 100644 --- a/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/file.xsd +++ b/nuxeo-core/nuxeo-core-api/src/test/resources/schemas/file.xsd @@ -5,7 +5,6 @@ - diff --git a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/download/TestDownloadService.java b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/download/TestDownloadService.java index d40b851a978b..6bacc2b98639 100644 --- a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/download/TestDownloadService.java +++ b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/download/TestDownloadService.java @@ -325,10 +325,9 @@ public void testResolveBlobFromDownloadUrl() throws IOException { String blobFilename = "synopsis.txt"; blob.setFilename(blobFilename); - Map fileMap = new HashMap(); + Map fileMap = new HashMap<>(); fileMap.put("file", blob); - fileMap.put("filename", blob.getFilename()); - List> docFiles = new ArrayList>(); + List> docFiles = new ArrayList<>(); docFiles.add(fileMap); doc.setProperty("files", "files", docFiles); diff --git a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/ComplexDocRepositoryInit.java b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/ComplexDocRepositoryInit.java index 2b55b6048735..38274136bffd 100644 --- a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/ComplexDocRepositoryInit.java +++ b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/ComplexDocRepositoryInit.java @@ -70,7 +70,6 @@ protected final DocumentModel createTestDoc(CoreSession session) { // ----------------------- // file // ----------------------- - doc.setProperty("file", "filename", "test_file.doc"); Blob blob = Blobs.createBlob("My blob"); blob.setFilename("test_file.doc"); doc.setProperty("file", "content", blob); @@ -83,7 +82,7 @@ protected final DocumentModel createTestDoc(CoreSession session) { doc.setPropertyValue("cs:origin", "Internal"); // segmentVariable - Map segment = new HashMap(); + Map segment = new HashMap<>(); segment.put("name", "MySegment"); segment.put("target", "SomeTarget"); segment.put("variableType", "rawVariable"); diff --git a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TestTypedExportedDocument.java b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TestTypedExportedDocument.java index c715db665522..0c9f3bf21bce 100644 --- a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TestTypedExportedDocument.java +++ b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TestTypedExportedDocument.java @@ -144,10 +144,6 @@ public void testTypedExportedDocument() throws Exception { schemaNode = (Node) xpath.evaluate("//schema[@name='file']", document, XPathConstants.NODE); assertNotNull(schemaNode); - fieldNode = (Node) xpath.evaluate("//file:filename[@type='string']", document, XPathConstants.NODE); - assertNotNull(fieldNode); - assertEquals("test_file.doc", fieldNode.getTextContent()); - fieldNode = (Node) xpath.evaluate("//file:content[@type='content']", document, XPathConstants.NODE); assertNotNull(fieldNode); diff --git a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TypedExportedDocumentRepositoryInit.java b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TypedExportedDocumentRepositoryInit.java index 736c9f2b2917..8c2204073fe8 100644 --- a/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TypedExportedDocumentRepositoryInit.java +++ b/nuxeo-core/nuxeo-core-io/src/test/java/org/nuxeo/ecm/core/io/impl/TypedExportedDocumentRepositoryInit.java @@ -64,7 +64,6 @@ protected final DocumentModel createTestDoc(CoreSession session) { // ----------------------- // file // ----------------------- - doc.setProperty("file", "filename", "test_file.doc"); Blob blob = Blobs.createBlob("My blob"); blob.setFilename("test_file.doc"); doc.setProperty("file", "content", blob); diff --git a/nuxeo-core/nuxeo-core-io/src/test/resources/archive.zip b/nuxeo-core/nuxeo-core-io/src/test/resources/archive.zip index c15063f48b4d..c8a3a3f69c6e 100644 Binary files a/nuxeo-core/nuxeo-core-io/src/test/resources/archive.zip and b/nuxeo-core/nuxeo-core-io/src/test/resources/archive.zip differ diff --git a/nuxeo-core/nuxeo-core-io/src/test/resources/export.zip b/nuxeo-core/nuxeo-core-io/src/test/resources/export.zip index d6e406ebb273..01ca65d696cb 100644 Binary files a/nuxeo-core/nuxeo-core-io/src/test/resources/export.zip and b/nuxeo-core/nuxeo-core-io/src/test/resources/export.zip differ diff --git a/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive.zip b/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive.zip index 03023fb4d05d..abddb398ea64 100644 Binary files a/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive.zip and b/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive.zip differ diff --git a/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive2.zip b/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive2.zip index 8a320d6724d5..0d58434e5b10 100644 Binary files a/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive2.zip and b/nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive2.zip differ diff --git a/nuxeo-core/nuxeo-core-schema/src/test/resources/schema/file.xsd b/nuxeo-core/nuxeo-core-schema/src/test/resources/schema/file.xsd index 8ae613c17029..4d322f7abe94 100644 --- a/nuxeo-core/nuxeo-core-schema/src/test/resources/schema/file.xsd +++ b/nuxeo-core/nuxeo-core-schema/src/test/resources/schema/file.xsd @@ -8,7 +8,6 @@ - diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestDocument.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestDocument.java index 176a1abb6fba..cb24b081cf49 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestDocument.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestDocument.java @@ -104,14 +104,9 @@ private interface TriConsumer { void accept(T t, U u, V v); } - protected final BiFunction DocumentGetValue = (Document doc, String xpath) -> { - return doc.getValue(xpath); - }; + protected final BiFunction DocumentGetValue = Document::getValue; - protected final TriConsumer DocumentSetValue = (Document doc, String xpath, - Object value) -> { - doc.setValue(xpath, value); - }; + protected final TriConsumer DocumentSetValue = Document::setValue; @Test public void testGetValueErrors() throws Exception { @@ -154,7 +149,7 @@ public void testSetValueErrors2() throws Exception { Document root = session.getRootDocument(); Document doc1 = root.addChild("doc", "TestDocument"); Document doc2 = root.addChild("doc", "File"); - doc1.setValue("tp:complexList", Arrays.asList(Collections.emptyMap())); + doc1.setValue("tp:complexList", Collections.singletonList(Collections.emptyMap())); BiConsumer c1 = (xpath, value) -> DocumentSetValue.accept(doc1, xpath, value); checkSet(c1, "tp:complexList", Long.valueOf(0), @@ -250,15 +245,12 @@ public void testComplex() throws Exception { Object b = doc.getValue("cmpf:attachedFile/vignettes/0/content"); assertTrue(b instanceof Blob); assertEquals(content2, ((Blob) b).getString()); - Map vignette2 = new HashMap<>(); - vignette2.put("width", size1); - vignette2.put("content", blob); // get recursive list item @SuppressWarnings("unchecked") Map v0 = (Map) doc.getValue("cmpf:attachedFile/vignettes/0"); assertEquals(size1, v0.get("width")); - b = (Blob) v0.get("content"); + b = v0.get("content"); assertEquals(content2, ((Blob) b).getString()); Object v1 = doc.getValue("cmpf:attachedFile/vignettes/1"); Map ev1 = new HashMap<>(); @@ -295,8 +287,9 @@ public void testComplexFiles() throws Exception { Document root = session.getRootDocument(); Document doc = root.addChild("doc", "File"); - doc.setValue("files", Arrays.asList(Collections.singletonMap("filename", "f1"))); - assertEquals("f1", doc.getValue("files/0/filename")); + Blob blob = Blobs.createBlob("My content"); + doc.setValue("files", Collections.singletonList(Collections.singletonMap("file", blob))); + assertEquals(blob, doc.getValue("files/0/file")); } @Test @@ -308,7 +301,7 @@ public void testBlobList() throws Exception { assertTrue(list instanceof List); assertEquals(0, ((List) list).size()); - doc.setValue("tp:fileList", Arrays.asList(Blobs.createBlob("My content"))); + doc.setValue("tp:fileList", Collections.singletonList(Blobs.createBlob("My content"))); list = doc.getValue("tp:fileList"); assertTrue(list instanceof List); @@ -428,7 +421,7 @@ public void testBlobsVisitorWithOldFacet() throws Exception { Blob blob = Blobs.createBlob("content1", "text/plain"); doc.setValue("cmpf:attachedFile", - Collections.singletonMap("vignettes", Arrays.asList(Collections.singletonMap("content", blob)))); + Collections.singletonMap("vignettes", Collections.singletonList(Collections.singletonMap("content", blob)))); // simulate an obsolete Aged facet present on the document but not in the schema manager Map facets = getSchemaManagerFacets(); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryAPI.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryAPI.java index f2847a61525b..b6e919a4ce40 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryAPI.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryAPI.java @@ -1049,7 +1049,6 @@ public void testGetDocumentDocumentRefStringArray() { session.save(); - childFile.setProperty("file", "filename", "second name"); childFile.setProperty("dublincore", "title", "f1"); childFile.setProperty("dublincore", "description", "desc 1"); @@ -1075,7 +1074,6 @@ public void testGetDocumentDocumentRefStringArray() { assertEquals("f1", returnedDocument.getProperty("dublincore", "title")); assertEquals("desc 1", returnedDocument.getProperty("dublincore", "description")); - assertNull(returnedDocument.getProperty("file", "filename")); returnedDocument = session.getDocument(childFile.getRef()); @@ -1095,7 +1093,6 @@ public void testGetDocumentDocumentRefStringArray() { assertEquals("f1", returnedDocument.getProperty("dublincore", "title")); assertEquals("desc 1", returnedDocument.getProperty("dublincore", "description")); - assertEquals("second name", returnedDocument.getProperty("file", "filename")); } @Test @@ -1431,8 +1428,8 @@ public void TODOtestQuery() { List returnedChildDocs = createChildDocuments(childDocs); - returnedChildDocs.get(1).setProperty("file", "filename", "f1"); - returnedChildDocs.get(2).setProperty("file", "filename", "f2"); + returnedChildDocs.get(1).setProperty("file", "content", Blobs.createBlob("blob1", "text/plain", "UTF-8", "f1")); + returnedChildDocs.get(2).setProperty("file", "content", Blobs.createBlob("blob1", "text/plain", "UTF-8", "f2")); session.saveDocuments(returnedChildDocs.toArray(new DocumentModel[0])); session.save(); @@ -1449,7 +1446,7 @@ public void TODOtestQuery() { // if we select filename, the returned docModel // should have both schemas "file" and "common" - list = session.query("SELECT filename FROM File"); + list = session.query("SELECT content/filename FROM File"); assertEquals(1, list.size()); docModel = list.get(0); schemas = Arrays.asList(docModel.getSchemas()); @@ -1511,10 +1508,9 @@ public void TODOtestQueryAfterEdit() { assertEquals(1, returnedChildDocs.size()); childFile1 = returnedChildDocs.get(0); - childFile1.setProperty("file", "filename", "f1"); // add a blob - Blob blob = Blobs.createBlob("La la la!", "text/html"); + Blob blob = Blobs.createBlob("La la la!", "text/html", "UTF-8", "f1"); childFile1.setProperty("file", "content", blob); session.saveDocument(childFile1); @@ -1776,11 +1772,10 @@ public void testSaveFile() { DocumentModel childFile = new DocumentModelImpl(root.getPathAsString(), name, "File"); childFile.setProperty("dublincore", "title", "f1"); childFile.setProperty("dublincore", "description", "desc 1"); - childFile.setProperty("file", "filename", "filename1"); childFile = createChildDocument(childFile); - Property p = childFile.getProperty("/file:/filename"); + Property p = childFile.getProperty("/dublincore:/description"); // System.out.println(p.getPath()); // TODO NXP-2514: this should be tested across sessions - when it can be done @@ -1790,7 +1785,6 @@ public void testSaveFile() { assertEquals("f1", retrievedFile.getProperty("dublincore", "title")); assertEquals("desc 1", retrievedFile.getProperty("dublincore", "description")); - assertEquals("filename1", retrievedFile.getProperty("file", "filename")); } @Test @@ -1824,9 +1818,9 @@ public void testGetDataModel() { session.save(); - childFile.setProperty("file", "filename", "second name"); childFile.setProperty("dublincore", "title", "f1"); childFile.setProperty("dublincore", "description", "desc 1"); + childFile.setProperty("file", "content", Blobs.createBlob("b1", "text/plain", "UTF-8", "second name")); session.saveDocument(childFile); @@ -1847,7 +1841,7 @@ public void testGetDataModel() { assertNotNull(dm.getMap()); assertNotNull(dm.getSchema()); assertEquals("file", dm.getSchema()); - assertEquals("second name", dm.getData("filename")); + assertEquals("second name", ((Blob) dm.getData("content")).getFilename()); } @Test @@ -2657,7 +2651,6 @@ public void testBlob() throws Exception { long length = blob.getLength(); byte[] content = blob.getByteArray(); - childFile.setProperty("file", "filename", "deprectaed filename"); childFile.setProperty("dublincore", "title", "Blob test"); childFile.setProperty("dublincore", "description", "this is a test"); childFile.setProperty("file", "content", blob); @@ -2872,13 +2865,8 @@ public void testCopyContent() throws Exception { doc.setProperty("dublincore", "title", "t"); doc.setProperty("dublincore", "description", "d"); doc.setProperty("dublincore", "subjects", new String[] { "a", "b" }); - doc.setProperty("file", "filename", "f"); - List files = new ArrayList<>(2); + List files = new ArrayList<>(1); Map f = new HashMap<>(); - f.put("filename", "f1"); - files.add(f); - f = new HashMap<>(); - f.put("filename", "f2"); f.put("file", Blobs.createBlob("myfile", "text/test", "UTF-8")); files.add(f); doc.setProperty("files", "files", files); @@ -2896,14 +2884,11 @@ public void testCopyContent() throws Exception { assertEquals("t", copy.getProperty("dublincore", "title")); assertEquals("d", copy.getProperty("dublincore", "description")); assertEquals(Arrays.asList("a", "b"), Arrays.asList((String[]) copy.getProperty("dublincore", "subjects"))); - assertEquals("f", copy.getProperty("file", "filename")); Object fileso = copy.getProperty("files", "files"); assertNotNull(fileso); List> newfiles = (List>) fileso; - assertEquals(2, newfiles.size()); - assertEquals("f1", newfiles.get(0).get("filename")); - assertEquals("f2", newfiles.get(1).get("filename")); - Blob bb = (Blob) newfiles.get(1).get("file"); + assertEquals(1, newfiles.size()); + Blob bb = (Blob) newfiles.get(0).get("file"); assertNotNull(bb); assertEquals("text/test", bb.getMimeType()); assertEquals("UTF-8", bb.getEncoding()); @@ -3065,11 +3050,8 @@ public void testPropertyXPath() throws Exception { DocumentModel doc = new DocumentModelImpl(parent.getPathAsString(), "theDoc", "File"); doc.setProperty("dublincore", "title", "my title"); + assertEquals("my title", doc.getPropertyValue("title")); assertEquals("my title", doc.getPropertyValue("dc:title")); - - doc.setProperty("file", "filename", "the file name"); - assertEquals("the file name", doc.getPropertyValue("filename")); - assertEquals("the file name", doc.getPropertyValue("file:filename")); } @SuppressWarnings("rawtypes") diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryDirectBlob.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryDirectBlob.java index 5b5d113d9686..b7deceb6f5e5 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryDirectBlob.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryDirectBlob.java @@ -116,9 +116,9 @@ public void testDirectBlob() throws Exception { String filename = "doc.txt"; long length = binary.getFile().length(); Blob blob = new BinaryBlob(binary, digest, filename, "text/plain", "utf-8", digest, length); + blob.setFilename(filename); assertEquals("MD5", blob.getDigestAlgorithm()); assertEquals(digest, blob.getDigest()); - file.setProperty("file", "filename", filename); file.setProperty("file", "content", blob); session.saveDocument(file); session.save(); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextConfig.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextConfig.java index 575f456b51ee..1f0eca45821c 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextConfig.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextConfig.java @@ -121,8 +121,8 @@ protected void createDocs() throws Exception { String content = "Some caf\u00e9 in a restaurant.\nDrink!.\n"; String filename = "testfile.txt"; Blob blob1 = Blobs.createBlob(content); + blob1.setFilename(filename); file1.setPropertyValue("content", (Serializable) blob1); - file1.setPropertyValue("filename", filename); Calendar cal1 = getCalendar(2007, 3, 1, 12, 0, 0); file1.setPropertyValue("dc:created", cal1); file1.setPropertyValue("dc:coverage", "football"); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextQuery.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextQuery.java index 1b0e75adf959..e3e26905a42c 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextQuery.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryFulltextQuery.java @@ -210,7 +210,6 @@ protected void createDocs() throws Exception { Blob blob1 = Blobs.createBlob(content); blob1.setFilename(filename); file1.setPropertyValue("content", (Serializable) blob1); - file1.setPropertyValue("filename", filename); Calendar cal1 = getCalendar(2007, 3, 1, 12, 0, 0); file1.setPropertyValue("dc:created", cal1); file1.setPropertyValue("dc:coverage", "football"); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryProperties.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryProperties.java index d8e90a82fe84..43283a062ee4 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryProperties.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryProperties.java @@ -887,11 +887,12 @@ public void testXPath1() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "doc", "File"); List files = new ArrayList<>(2); Map f = new HashMap<>(); - f.put("filename", "f1"); + Blob blob = Blobs.createBlob("blob1"); + f.put("file", blob); files.add(f); doc.setProperty("files", "files", files); - assertEquals("f1", doc.getPropertyValue("files/0/filename")); - assertEquals("f1", doc.getPropertyValue("files/item[0]/filename")); + assertEquals(blob, doc.getPropertyValue("files/0/file")); + assertEquals(blob, doc.getPropertyValue("files/item[0]/file")); } // other complex list diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQuery.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQuery.java index 65d2b32f6f32..1e5fc4680dcc 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQuery.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQuery.java @@ -228,7 +228,6 @@ protected void createDocs() throws Exception { Blob blob1 = Blobs.createBlob(content); blob1.setFilename(filename); file1.setPropertyValue("content", (Serializable) blob1); - file1.setPropertyValue("filename", filename); Calendar cal1 = getCalendar(2007, 3, 1, 12, 0, 0); file1.setPropertyValue("dc:created", cal1); file1.setPropertyValue("dc:coverage", "football"); @@ -333,7 +332,7 @@ public void testQueryBasic() throws Exception { dml = session.query("SELECT * FROM File WHERE dc:title = 'testfolder1_Title'"); assertEquals(0, dml.size()); - dml = session.query("SELECT * FROM File WHERE filename = 'testfile.txt'"); + dml = session.query("SELECT * FROM File WHERE content/name = 'testfile.txt'"); assertEquals(1, dml.size()); dml = session.query("SELECT * FROM Note WHERE dc:title = 'testfile3_Title'"); @@ -351,10 +350,10 @@ public void testQueryBasic() throws Exception { assertEquals(1, dml.size()); // this needs an actual LEFT OUTER JOIN - dml = session.query("SELECT * FROM Document WHERE filename = 'testfile.txt' OR dc:title = 'testfile3_Title'"); + dml = session.query("SELECT * FROM Document WHERE content/name = 'testfile.txt' OR dc:title = 'testfile3_Title'"); assertEquals(2, dml.size()); - dml = session.query("SELECT * FROM Document WHERE filename = 'testfile.txt' OR dc:contributors = 'bob'"); + dml = session.query("SELECT * FROM Document WHERE content/name = 'testfile.txt' OR dc:contributors = 'bob'"); assertEquals(3, dml.size()); // early detection of conflicting types for VCS @@ -539,11 +538,11 @@ public void testQueryAfterEdit() throws Exception { assertEquals(1, returnedChildDocs.length); childFile1 = returnedChildDocs[0]; - childFile1.setProperty("file", "filename", "f1"); // add a blob String s = "La la la!"; Blob blob = Blobs.createBlob(s, "text/html"); + blob.setFilename("f1"); childFile1.setProperty("file", "content", blob); session.saveDocument(childFile1); @@ -2122,9 +2121,9 @@ public void testQueryIterableWithTransformer() throws Exception { @Test public void testQueryComplexTypeFiles() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "myfile", "File"); - List files = new LinkedList(); - Map f = new HashMap(); - f.put("filename", "f1"); + List files = new LinkedList<>(); + Map f = new HashMap<>(); + f.put("file", Blobs.createBlob("b1", "text/plain", "UTF-8", "f1")); files.add(f); doc.setProperty("files", "files", files); doc = session.createDocument(doc); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQueryNoPathOptim.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQueryNoPathOptim.java index 2fd3038a82bd..38dd374d0b88 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQueryNoPathOptim.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryQueryNoPathOptim.java @@ -155,7 +155,6 @@ protected void createDocs() throws Exception { Blob blob1 = Blobs.createBlob(content); blob1.setFilename(filename); file1.setPropertyValue("content", (Serializable) blob1); - file1.setPropertyValue("filename", filename); Calendar cal1 = getCalendar(2007, 3, 1, 12, 0, 0); file1.setPropertyValue("dc:created", cal1); file1.setPropertyValue("dc:coverage", "football"); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryVersioning.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryVersioning.java index 5d506c195201..a196d704f4e0 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryVersioning.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/TestSQLRepositoryVersioning.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; @@ -41,6 +42,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.nuxeo.common.collections.ScopeType; +import org.nuxeo.ecm.core.api.Blobs; import org.nuxeo.ecm.core.api.CoreInstance; import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; @@ -51,6 +53,7 @@ import org.nuxeo.ecm.core.api.VersionModel; import org.nuxeo.ecm.core.api.VersioningOption; import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; +import org.nuxeo.ecm.core.api.impl.blob.StringBlob; import org.nuxeo.ecm.core.api.security.ACE; import org.nuxeo.ecm.core.api.security.ACL; import org.nuxeo.ecm.core.api.security.ACP; @@ -129,7 +132,7 @@ public void testRemoveSingleDocVersion() throws Exception { checkVersions(file); - file.setPropertyValue("file:filename", "A"); + file.setPropertyValue("file:content", (Serializable) Blobs.createBlob("B", "text/plain", "UTF-8", "A")); file = session.saveDocument(file); file.checkIn(VersioningOption.MINOR, null); file.checkOut(); // to allow deleting last version @@ -210,7 +213,7 @@ public void testRemoveLastDocVersion() throws Exception { private void createTrioVersions(DocumentModel file) throws Exception { // create a first version - file.setProperty("file", "filename", "A"); + file.setProperty("file", "content", new StringBlob("A")); file = session.saveDocument(file); file.checkIn(VersioningOption.MINOR, null); @@ -218,7 +221,7 @@ private void createTrioVersions(DocumentModel file) throws Exception { // create a second version // make it dirty so it will be saved - file.setProperty("file", "filename", "B"); + file.setProperty("file", "content", new StringBlob("B")); maybeSleepToNextSecond(); file = session.saveDocument(file); file.checkIn(VersioningOption.MINOR, null); @@ -226,7 +229,7 @@ private void createTrioVersions(DocumentModel file) throws Exception { checkVersions(file, "0.1", "0.2"); // create a third version - file.setProperty("file", "filename", "C"); + file.setProperty("file", "content", new StringBlob("C")); maybeSleepToNextSecond(); file = session.saveDocument(file); file.checkIn(VersioningOption.MINOR, null); @@ -331,9 +334,8 @@ public void testRestoreToVersion() throws Exception { session.checkOut(docRef); assertTrue(session.isCheckedOut(docRef)); - doc.setProperty("file", "filename", "second name"); - doc.setProperty("dc", "title", "f1"); - doc.setProperty("dc", "description", "desc 1"); + doc.setProperty("dublincore", "title", "f1"); + doc.setProperty("dublincore", "description", "desc 1"); session.saveDocument(doc); session.save(); @@ -344,7 +346,7 @@ public void testRestoreToVersion() throws Exception { DocumentModel newDoc = session.getDocument(docRef); assertNotNull(newDoc); assertNotNull(newDoc.getRef()); - assertEquals("second name", newDoc.getProperty("file", "filename")); + assertEquals("desc 1", newDoc.getProperty("dublincore", "description")); waitForFulltextIndexing(); maybeSleepToNextSecond(); @@ -352,7 +354,7 @@ public void testRestoreToVersion() throws Exception { assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); - assertNull(restoredDoc.getProperty("file", "filename")); + assertNull(restoredDoc.getProperty("dublincore", "description")); waitForFulltextIndexing(); maybeSleepToNextSecond(); @@ -360,8 +362,7 @@ public void testRestoreToVersion() throws Exception { assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); - String pr = (String) restoredDoc.getProperty("file", "filename"); - assertEquals("second name", pr); + assertEquals("desc 1", restoredDoc.getProperty("dublincore", "description")); } @Test @@ -457,9 +458,8 @@ public void testGetDocumentWithVersion() throws Exception { DocumentRef v1Ref = session.checkIn(childFile.getRef(), null, null); session.checkOut(childFile.getRef()); - childFile.setProperty("file", "filename", "second name"); - childFile.setProperty("dc", "title", "f1"); - childFile.setProperty("dc", "description", "desc 1"); + childFile.setProperty("dublincore", "title", "f1"); + childFile.setProperty("dublincore", "description", "desc 1"); session.saveDocument(childFile); session.save(); maybeSleepToNextSecond(); @@ -468,7 +468,7 @@ public void testGetDocumentWithVersion() throws Exception { DocumentModel newDoc = session.getDocument(childFile.getRef()); assertNotNull(newDoc); assertNotNull(newDoc.getRef()); - assertEquals("second name", newDoc.getProperty("file", "filename")); + assertEquals("desc 1", newDoc.getProperty("dublincore", "description")); // restore, no snapshot as already pristine waitForFulltextIndexing(); @@ -477,13 +477,13 @@ public void testGetDocumentWithVersion() throws Exception { assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); - assertNull(restoredDoc.getProperty("file", "filename")); + assertNull(restoredDoc.getProperty("dublincore", "description")); DocumentModel last = session.getLastDocumentVersion(childFile.getRef()); assertNotNull(last); assertNotNull(last.getRef()); assertEquals(v2Ref.reference(), last.getId()); - assertEquals("second name", last.getProperty("file", "filename")); + assertEquals("desc 1", last.getProperty("dublincore", "description")); } // security on versions, see TestLocalAPIWithCustomVersioning diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/api/blobholder/TestDocumentAdapter.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/api/blobholder/TestDocumentAdapter.java index cf173e37a50b..c5634c1e4a50 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/api/blobholder/TestDocumentAdapter.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/api/blobholder/TestDocumentAdapter.java @@ -63,7 +63,6 @@ public void testFileAdapters() throws Exception { blob.setFilename("TestFile.txt"); file.setProperty("dublincore", "title", "TestFile"); file.setProperty("file", "content", blob); - file.setProperty("file", "filename", "TestFile-fn.txt"); file = session.createDocument(file); session.save(); @@ -90,8 +89,6 @@ public void testFileAdapters() throws Exception { assertEquals("other.txt", b.getFilename()); assertEquals("text/html", b.getMimeType()); assertEquals("OtherContent", b.getString()); - // check filename property updated as well - assertEquals("other.txt", file.getPropertyValue("file:filename")); // test set null blob bh.setBlob(null); @@ -99,7 +96,6 @@ public void testFileAdapters() throws Exception { session.save(); b = bh.getBlob(); assertNull(b); - assertNull(file.getPropertyValue("file:filename")); } @Test @@ -164,17 +160,15 @@ public void testMultiFileAdapters() throws Exception { blob.setFilename("TestFile.txt"); file.setProperty("dublincore", "title", "TestDoc"); file.setProperty("file", "content", blob); - file.setProperty("file", "filename", "TestFile-fn.txt"); - List> blobs = new ArrayList>(); + List> blobs = new ArrayList<>(); for (int i = 1; i <= 5; i++) { String name = "TestFile" + i + ".txt"; Blob nblob = Blobs.createBlob("BlobContent" + i); nblob.setFilename(name); - Map filesEntry = new HashMap(); + Map filesEntry = new HashMap<>(); filesEntry.put("file", (Serializable) nblob); - filesEntry.put("filename", name); blobs.add(filesEntry); } file.setPropertyValue("files:files", (Serializable) blobs); diff --git a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/event/test/virusscan/TestDummyVirusScanner.java b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/event/test/virusscan/TestDummyVirusScanner.java index 4b3a67aa860a..10c78707a7f2 100644 --- a/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/event/test/virusscan/TestDummyVirusScanner.java +++ b/nuxeo-core/nuxeo-core-test/src/test/java/org/nuxeo/ecm/core/event/test/virusscan/TestDummyVirusScanner.java @@ -124,12 +124,11 @@ public void testScanner() throws Exception { TransactionHelper.startTransaction(); try { - List> files = new ArrayList>(); + List> files = new ArrayList<>(); for (int i = 0; i < 5; i++) { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("file", (Serializable) getFakeBlob(100, "Test4-" + i + ".txt")); - map.put("filename", "Test4-" + i + ".txt"); files.add(map); } @@ -144,9 +143,8 @@ public void testScanner() throws Exception { List> files = (List>) file4.getPropertyValue("files:files"); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("file", (Serializable) getFakeBlob(100, "Test4-b.txt")); - map.put("filename", "Test4-b.txt"); files.add(map); file4.setPropertyValue("files:files", (Serializable) files); file4 = session.saveDocument(file4); @@ -163,7 +161,7 @@ public void testScanner() throws Exception { // System.out.println(DummyVirusScanner.getProcessedFiles()); - assertEquals(new HashSet(Arrays.asList( // + assertEquals(new HashSet<>(Arrays.asList( // "Test1.txt", // "Test2.txt", // "Test3doFail.txt", // @@ -173,7 +171,7 @@ public void testScanner() throws Exception { "Test4-2.txt", // "Test4-3.txt", // "Test4-4.txt", // - "Test4-b.txt")), new HashSet(scannedFiles)); + "Test4-b.txt")), new HashSet<>(scannedFiles)); file = session.getDocument(file.getRef()); file2 = session.getDocument(file2.getRef()); diff --git a/nuxeo-core/nuxeo-core/src/main/resources/schema/file.xsd b/nuxeo-core/nuxeo-core/src/main/resources/schema/file.xsd index cc5fe4418211..9b009975c6c7 100644 --- a/nuxeo-core/nuxeo-core/src/main/resources/schema/file.xsd +++ b/nuxeo-core/nuxeo-core/src/main/resources/schema/file.xsd @@ -6,7 +6,6 @@ - diff --git a/nuxeo-core/nuxeo-core/src/main/resources/schema/files.xsd b/nuxeo-core/nuxeo-core/src/main/resources/schema/files.xsd index f458fc086971..6ced0bbb9ba4 100644 --- a/nuxeo-core/nuxeo-core/src/main/resources/schema/files.xsd +++ b/nuxeo-core/nuxeo-core/src/main/resources/schema/files.xsd @@ -18,7 +18,6 @@ - diff --git a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/contentbrowser/WorkspaceActionsBean.java b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/contentbrowser/WorkspaceActionsBean.java index 9121ffd55d3c..49c4dbbae206 100644 --- a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/contentbrowser/WorkspaceActionsBean.java +++ b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/contentbrowser/WorkspaceActionsBean.java @@ -280,8 +280,6 @@ public String createWorkspaceOld() { Blob blob = (Blob) tmpWorkspace.getProperty("file", "content"); if (blob != null) { created.setProperty("file", "content", blob); - String fname = (String) tmpWorkspace.getProperty("file", "filename"); - created.setProperty("file", "filename", fname); } created = documentManager.saveDocument(created); diff --git a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/documenttemplates/DocumentTemplatesActionsBean.java b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/documenttemplates/DocumentTemplatesActionsBean.java index 4bc15c464e52..f5f7bff3e0ab 100644 --- a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/documenttemplates/DocumentTemplatesActionsBean.java +++ b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/documenttemplates/DocumentTemplatesActionsBean.java @@ -178,8 +178,6 @@ public String createDocumentFromTemplate(DocumentModel doc) { Blob blob = (Blob) doc.getProperty("file", "content"); if (blob != null) { created.setProperty("file", "content", blob); - String fname = (String) doc.getProperty("file", "filename"); - created.setProperty("file", "filename", fname); } created = documentManager.saveDocument(created); diff --git a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/filemanager/FileManageActionsBean.java b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/filemanager/FileManageActionsBean.java index 5a524af697e9..e6b9eeaa028b 100644 --- a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/filemanager/FileManageActionsBean.java +++ b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/filemanager/FileManageActionsBean.java @@ -563,9 +563,8 @@ public void validateMultipleUploadForDocument(DocumentModel current) throws File for (NxUploadedFile uploadItem : nxuploadFiles) { Blob blob = uploadItem.getBlob(); FileUtils.configureFileBlob(blob); - HashMap fileMap = new HashMap(2); + HashMap fileMap = new HashMap(1); fileMap.put("file", blob); - fileMap.put("filename", blob.getFilename()); if (!files.contains(fileMap)) { files.add(fileMap); } diff --git a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/note/EditorImageActionsBean.java b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/note/EditorImageActionsBean.java index d4aae1f8d430..71501abb7046 100644 --- a/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/note/EditorImageActionsBean.java +++ b/nuxeo-dm/nuxeo-platform-webapp-core/src/main/java/org/nuxeo/ecm/webapp/note/EditorImageActionsBean.java @@ -185,7 +185,6 @@ public String uploadImage() { } catch (IOException e) { throw new NuxeoException(e); } - props.put("filename", blob.getFilename()); props.put("file", blob); ListDiff listDiff = new ListDiff(); listDiff.add(props); diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/main/java/org/nuxeo/ecm/automation/core/util/DocumentHelper.java b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/main/java/org/nuxeo/ecm/automation/core/util/DocumentHelper.java index ec960520bb22..94695c47f2de 100644 --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/main/java/org/nuxeo/ecm/automation/core/util/DocumentHelper.java +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/main/java/org/nuxeo/ecm/automation/core/util/DocumentHelper.java @@ -95,7 +95,7 @@ public static void addBlob(Property p, Blob blob) throws PropertyException { // detect if a list of simple blobs or a list of files (blob // holder) Type ft = ((ListProperty) p).getType().getFieldType(); - if (ft.isComplexType() && ((ComplexType) ft).getFieldsCount() == 2) { + if (ft.isComplexType() && ((ComplexType) ft).getFieldsCount() == 1) { p.addValue(createBlobHolderMap(blob)); } else { p.addValue(blob); @@ -106,9 +106,8 @@ public static void addBlob(Property p, Blob blob) throws PropertyException { } public static HashMap createBlobHolderMap(Blob blob) { - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put("file", (Serializable) blob); - map.put("filename", blob.getFilename()); return map; } diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/BlobOperationsTest.java b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/BlobOperationsTest.java index a3d359c0ddd8..19b77364470f 100644 --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/BlobOperationsTest.java +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/BlobOperationsTest.java @@ -311,9 +311,9 @@ public void testGetAllDocumentBlobsOperation() throws Exception { File tmpFile = Framework.createTempFile("test", ".txt"); FileUtils.writeFile(tmpFile, "Content"); Blob blob = Blobs.createBlob(tmpFile); + blob.setFilename("initial_name.txt"); Framework.trackFile(tmpFile, blob); file.put("file", (Serializable) blob); - file.put("filename", "initial_name.txt"); files.add(file); // Create document DocumentModel docFile = session.createDocumentModel(src.getPathAsString(), "blobWithName", "File"); diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/TestComplexTypesMapping.java b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/TestComplexTypesMapping.java index 9345afc0f36c..1886445bf484 100644 --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/TestComplexTypesMapping.java +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-core/src/test/java/org/nuxeo/ecm/automation/core/test/TestComplexTypesMapping.java @@ -67,14 +67,13 @@ public void initRepo() throws Exception { blob.setFilename("Yo.txt"); doc.setPropertyValue("file:content", (Serializable) blob); - List> blobs = new ArrayList>(); + List> blobs = new ArrayList<>(); for (int i = 0; i < 5; i++) { Blob subblob = Blobs.createBlob("Yo" + i); subblob.setFilename("File" + i + ".txt"); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("file", subblob); - map.put("filename", "File" + i + ".txt"); blobs.add(map); } doc.setPropertyValue("files:files", (Serializable) blobs); @@ -83,15 +82,15 @@ public void initRepo() throws Exception { doc.addFacet("Addresses"); - Map address = new HashMap(); + Map address = new HashMap<>(); address.put("streetNumber", "1bis"); address.put("streetName", "whatever"); address.put("zipCode", 75020); doc.setPropertyValue("addr:addressSingle", (Serializable) address); - List> addresses = new ArrayList>(); + List> addresses = new ArrayList<>(); for (int i = 0; i < 5; i++) { - Map add = new HashMap(); + Map add = new HashMap<>(); add.put("streetNumber", "" + i); add.put("streetName", "whatever"); add.put("zipCode", 75000 + i); diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/core/operations/services/BlobHolderAttach.java b/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/core/operations/services/BlobHolderAttach.java index f59a249194b8..c830241eec11 100644 --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/core/operations/services/BlobHolderAttach.java +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/core/operations/services/BlobHolderAttach.java @@ -93,7 +93,6 @@ public DocumentModel run(BlobList blobs) throws OperationException { for (Blob blob : blobs) { Map map = new HashMap<>(); map.put("file", blob); - map.put("filename", blob.getFilename()); existingBlobs.add(map); } currentDocument.setPropertyValue("files:files", (Serializable) existingBlobs); diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-server/README.txt b/nuxeo-features/nuxeo-automation/nuxeo-automation-server/README.txt index 5c84316cc46b..70f0f2a0b8ba 100644 --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-server/README.txt +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-server/README.txt @@ -273,8 +273,7 @@ Example of a JSON document entry "digest": null, "length": "290096", "data": "files/96bfb9cb-a13d-48a2-9bbd-9341fcf24801?path=%2Fcontent" - }, - "file:filename": null + } } The top level properties "title" and "lastModified" have the same value as the corresponding embedded properties "dc:title" and "dc:modified". @@ -637,8 +636,7 @@ Content-Length: 1121 "digest": null, "length": "290096", "data": "files/96bfb9cb-a13d-48a2-9bbd-9341fcf24801?path=%2Fcontent" - }, - "file:filename": null + } } 4. Download the content of the blob we set at step 2. diff --git a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestElasticSearchQuery.java b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestElasticSearchQuery.java index deb0e76cdd06..af4cd3e3ebdd 100644 --- a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestElasticSearchQuery.java +++ b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestElasticSearchQuery.java @@ -19,6 +19,15 @@ package org.nuxeo.elasticsearch.test; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; + import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.junit.Assert; @@ -44,15 +53,6 @@ import org.nuxeo.runtime.test.runner.LocalDeploy; import org.nuxeo.runtime.transaction.TransactionHelper; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; - /** * Test for native ES queries */ @@ -121,14 +121,13 @@ public void searchWithNestedQuery() throws Exception { startTransaction(); DocumentModel doc = session.createDocumentModel("/", "myFile", "File"); // create doc with a list of blob attachement textfile1.txt length=1,textfile2.txt length=2, ... - List> blobs = new ArrayList>(); + List> blobs = new ArrayList<>(); for (int i = 1; i <= 5; i++) { String name = "testfile" + i + ".txt"; Blob nblob = Blobs.createBlob(new String(new char[i]).replace('\0', 'a')); nblob.setFilename(name); - Map filesEntry = new HashMap(); + Map filesEntry = new HashMap<>(); filesEntry.put("file", (Serializable) nblob); - filesEntry.put("filename", name); blobs.add(filesEntry); } doc.setPropertyValue("files:files", (Serializable) blobs); @@ -185,14 +184,11 @@ public void testSecurity() throws Exception { Assert.assertEquals(1, ret.totalSize()); // no match for unknown user - CoreSession restrictedSession = getRestrictedSession("bob"); - try { + try (CoreSession restrictedSession = getRestrictedSession("bob")) { ret = ess.query(new NxQueryBuilder(restrictedSession).nxql("SELECT * FROM Document")); Assert.assertEquals(0, ret.totalSize()); ret = ess.query(new NxQueryBuilder(restrictedSession).esQuery(qb)); Assert.assertEquals(0, ret.totalSize()); - } finally { - restrictedSession.close(); } } diff --git a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/resources/elasticsearch-test-nested-mapping-contrib.xml b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/resources/elasticsearch-test-nested-mapping-contrib.xml index 7bc262036a61..537e8216206d 100644 --- a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/resources/elasticsearch-test-nested-mapping-contrib.xml +++ b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/resources/elasticsearch-test-nested-mapping-contrib.xml @@ -132,9 +132,6 @@ }, "files:files": { "properties": { - "filename": { - "type": "string" - }, "file": { "type" : "nested", "include_in_parent": true, diff --git a/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/api/adapter/PictureTilesAdapterFactory.java b/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/api/adapter/PictureTilesAdapterFactory.java index da03626ccaac..bb8150277fd4 100644 --- a/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/api/adapter/PictureTilesAdapterFactory.java +++ b/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/main/java/org/nuxeo/ecm/platform/pictures/tiles/api/adapter/PictureTilesAdapterFactory.java @@ -55,9 +55,7 @@ public Object getAdapter(DocumentModel doc, Class itf) { if (blob == null) { return null; } - PictureTilesAdapter adapter = new PictureTilesAdapterImpl(doc, "file:content"); - adapter.setFileName((String) doc.getProperty("file", "filename")); - return adapter; + return new PictureTilesAdapterImpl(doc, "file:content"); } else { return new PictureTilesAdapterImpl(doc); } @@ -87,9 +85,7 @@ private PictureTilesAdapter getPictureTilesAdapterForPicture(DocumentModel doc) private PictureTilesAdapter getPictureTilesAdapter(DocumentModel doc, String blobProperty) { Blob blob = (Blob) doc.getPropertyValue(blobProperty); if (blob != null) { - PictureTilesAdapter adapter = new PictureTilesAdapterImpl(doc, blobProperty); - adapter.setFileName(blob.getFilename()); - return adapter; + return new PictureTilesAdapterImpl(doc, blobProperty); } return null; } diff --git a/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/test/java/org/nuxeo/ecm/platform/pictures/tiles/service/test/TestAdapters.java b/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/test/java/org/nuxeo/ecm/platform/pictures/tiles/service/test/TestAdapters.java index 829fca088218..a991086dbb1f 100644 --- a/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/test/java/org/nuxeo/ecm/platform/pictures/tiles/service/test/TestAdapters.java +++ b/nuxeo-features/nuxeo-platform-imaging-tiling/nuxeo-platform-imaging-tiling/src/test/java/org/nuxeo/ecm/platform/pictures/tiles/service/test/TestAdapters.java @@ -80,7 +80,6 @@ public void testAdapter() throws Exception { File file = FileUtils.getResourceFileFromContext("test.jpg"); Blob image = Blobs.createBlob(file); doc.setProperty("file", "content", image); - doc.setProperty("file", "filename", "test.jpg"); doc = session.createDocument(doc); session.save(); diff --git a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/PictureMigrationHandler.java b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/PictureMigrationHandler.java index dad0333368b7..909352775be7 100644 --- a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/PictureMigrationHandler.java +++ b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/PictureMigrationHandler.java @@ -16,6 +16,7 @@ * Contributors: * Thomas Roger */ + package org.nuxeo.ecm.platform.picture; import static org.apache.commons.logging.LogFactory.getLog; @@ -63,8 +64,6 @@ public class PictureMigrationHandler extends RepositoryInitializationHandler { public static final String FILE_CONTENT_PROPERTY = "file:content"; - public static final String FILE_FILENAME_PROPERTY = "file:filename"; - public static final int BATCH_SIZE = 50; public static final String DISABLE_QUOTA_CHECK_LISTENER = "disableQuotaListener"; @@ -163,7 +162,6 @@ protected boolean migratePicture(CoreSession session, String docId) { filename = StringUtils.defaultString(filename).replaceAll("^Original_", ""); blob.setFilename(filename); picture.setPropertyValue(FILE_CONTENT_PROPERTY, (Serializable) blob); - picture.setPropertyValue(FILE_FILENAME_PROPERTY, filename); multiviewPicture.removeView(ORIGINAL_VIEW_TITLE); if (picture.isVersion()) { picture.putContextData(ALLOW_VERSION_WRITE, Boolean.TRUE); diff --git a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/operation/CreatePicture.java b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/operation/CreatePicture.java index 00d8476519f9..898a0160d580 100644 --- a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/operation/CreatePicture.java +++ b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/operation/CreatePicture.java @@ -128,7 +128,6 @@ public DocumentModel run(DocumentModel doc) throws IOException { log.warn("Unable to read Blob from properties"); } else { picture.setPropertyValue("file:content", (Serializable) blob); - picture.setPropertyValue("file:filename", blob.getFilename()); PictureResourceAdapter adapter = picture.getAdapter(PictureResourceAdapter.class); adapter.fillPictureViews(blob, blob.getFilename(), picture.getTitle(), templates); picture = session.saveDocument(picture); diff --git a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestPictureRenditions.java b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestPictureRenditions.java index 9ee215598cc8..85027bb5e3b6 100644 --- a/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestPictureRenditions.java +++ b/nuxeo-features/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestPictureRenditions.java @@ -33,7 +33,6 @@ import org.junit.runner.RunWith; import org.nuxeo.common.utils.FileUtils; import org.nuxeo.ecm.automation.AutomationService; -import org.nuxeo.ecm.automation.OperationContext; import org.nuxeo.ecm.core.api.Blob; import org.nuxeo.ecm.core.api.Blobs; import org.nuxeo.ecm.core.api.CoreSession; @@ -144,7 +143,6 @@ public void shouldDeclareRenditionDefinitionImageToPDF() { public void shouldMakeRenditionAvailableImageToPDF() throws Exception { Blob source = Blobs.createBlob(FileUtils.getResourceFileFromContext("images/test.jpg")); DocumentModel doc = session.createDocumentModel("/", "picture", "Picture"); - doc.setProperty("file", "filename", source.getFilename()); doc.setProperty("file", "content", source); Rendition imageToPDFRendition = renditionService.getRendition(doc, "imageToPDF"); diff --git a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/action/TransformMessageAction.java b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/action/TransformMessageAction.java index cbebca9343b1..b5cdaa5f6823 100644 --- a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/action/TransformMessageAction.java +++ b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/action/TransformMessageAction.java @@ -234,8 +234,8 @@ private void setFile(String fileName, InputStream inputStream) throws IOExceptio log.debug("* adding attachment: " + fileName); Map map = new HashMap(); Blob fileBlob = Blobs.createBlob(inputStream); + fileBlob.setFilename(fileName); map.put("file", fileBlob); - map.put("filename", fileName); files.add(map); } diff --git a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/adapter/MailMessageBlobHolder.java b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/adapter/MailMessageBlobHolder.java index 6e9f684484db..888353804543 100644 --- a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/adapter/MailMessageBlobHolder.java +++ b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/adapter/MailMessageBlobHolder.java @@ -1,5 +1,5 @@ /* - * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. + * (C) Copyright 2013-2016 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,7 @@ * limitations under the License. * * Contributors: - * Nuxeo - initial API and implementation - * + * Nuxeo - initial API and implementation */ package org.nuxeo.ecm.platform.mail.adapter; @@ -36,18 +35,21 @@ */ public class MailMessageBlobHolder extends DocumentBlobHolder { - protected Pattern isHtmlPattern = Pattern.compile("(.*)<(html|head|body)>(.*)", Pattern.CASE_INSENSITIVE - | Pattern.DOTALL); + protected Pattern isHtmlPattern = Pattern.compile("(.*)<(html|head|body)>(.*)", + Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + + private final String filename; - public MailMessageBlobHolder(DocumentModel doc, String xPath, String xPathFilename) { - super(doc, xPath, xPathFilename); + public MailMessageBlobHolder(DocumentModel doc, String xPath, String filename) { + super(doc, xPath); + this.filename = filename; } @Override public Blob getBlob() { String htmlTextProperty = (String) doc.getPropertyValue(xPath); - Blob blob = null; - if (htmlTextProperty != null && xPathFilename != null && htmlTextProperty.length() != 0) { + Blob blob; + if (htmlTextProperty != null && filename != null && htmlTextProperty.length() != 0) { blob = Blobs.createBlob(htmlTextProperty); Matcher m = isHtmlPattern.matcher(htmlTextProperty); if (m.matches()) { @@ -60,11 +62,9 @@ public Blob getBlob() { } blob = Blobs.createBlob(txt); } - if (blob != null) { - blob.setFilename(xPathFilename); - // set dummy digest to avoid comparison error - blob.setDigest("notInBinaryStore"); - } + blob.setFilename(filename); + // set dummy digest to avoid comparison error + blob.setDigest("notInBinaryStore"); return blob; } } diff --git a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/listener/action/CreateDocumentsAction.java b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/listener/action/CreateDocumentsAction.java index d3f9e12ee77c..0eeb602c3a07 100644 --- a/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/listener/action/CreateDocumentsAction.java +++ b/nuxeo-features/nuxeo-platform-mail/nuxeo-platform-mail-core/src/main/java/org/nuxeo/ecm/platform/mail/listener/action/CreateDocumentsAction.java @@ -108,7 +108,6 @@ public boolean execute(ExecutionContext context) { if (currentFileBlob != null) { Map file = new HashMap<>(); file.put("file", currentFileBlob); - file.put("filename", currentFileBlob.getFilename()); files.add(file); } } diff --git a/nuxeo-features/nuxeo-platform-rendition/nuxeo-platform-rendition-core/src/test/java/org/nuxeo/ecm/platform/rendition/service/TestRenditionService.java b/nuxeo-features/nuxeo-platform-rendition/nuxeo-platform-rendition-core/src/test/java/org/nuxeo/ecm/platform/rendition/service/TestRenditionService.java index 3de1cf2bb101..7c0fc3d78fd4 100644 --- a/nuxeo-features/nuxeo-platform-rendition/nuxeo-platform-rendition-core/src/test/java/org/nuxeo/ecm/platform/rendition/service/TestRenditionService.java +++ b/nuxeo-features/nuxeo-platform-rendition/nuxeo-platform-rendition-core/src/test/java/org/nuxeo/ecm/platform/rendition/service/TestRenditionService.java @@ -669,11 +669,9 @@ public void shouldRemoveFilesBlobsOnARendition() { List> files = new ArrayList<>(); Map file = new HashMap<>(); file.put("file", (Serializable) firstAttachedBlob); - file.put("filename", firstAttachedBlob.getFilename()); files.add(file); file = new HashMap<>(); file.put("file", (Serializable) secondAttachedBlob); - file.put("filename", secondAttachedBlob.getFilename()); files.add(file); fileDocument.setPropertyValue(FILES_FILES_PROPERTY, (Serializable) files); diff --git a/nuxeo-features/preview/nuxeo-preview-core/src/test/java/org/nuxeo/ecm/platform/preview/tests/adapter/TestPreviewAdapter.java b/nuxeo-features/preview/nuxeo-preview-core/src/test/java/org/nuxeo/ecm/platform/preview/tests/adapter/TestPreviewAdapter.java index 38e8bb376328..338181a237f6 100644 --- a/nuxeo-features/preview/nuxeo-preview-core/src/test/java/org/nuxeo/ecm/platform/preview/tests/adapter/TestPreviewAdapter.java +++ b/nuxeo-features/preview/nuxeo-preview-core/src/test/java/org/nuxeo/ecm/platform/preview/tests/adapter/TestPreviewAdapter.java @@ -63,7 +63,6 @@ public void testFileDocument() { Map file = new HashMap<>(); // Attach one file to the list file.put("file", (Serializable) blob); - file.put("filename", "test.txt"); document.setPropertyValue("file:content", (Serializable) blob); assertEquals(true, adapter.hasBlobToPreview()); } @@ -79,7 +78,6 @@ public void testCustomDocumentWithFilesSchema() { Map file = new HashMap<>(); // Attach one file to the list file.put("file", (Serializable) blob); - file.put("filename", "test.txt"); ArrayList> files = new ArrayList<>(); files.add(file); document.setPropertyValue("files:files", files); diff --git a/nuxeo-jsf/nuxeo-platform-actions-jsf/src/test/java/org/nuxeo/ecm/platform/actions/TestActionFilter.java b/nuxeo-jsf/nuxeo-platform-actions-jsf/src/test/java/org/nuxeo/ecm/platform/actions/TestActionFilter.java index f2560ff2a7c9..6902dd37fcfe 100644 --- a/nuxeo-jsf/nuxeo-platform-actions-jsf/src/test/java/org/nuxeo/ecm/platform/actions/TestActionFilter.java +++ b/nuxeo-jsf/nuxeo-platform-actions-jsf/src/test/java/org/nuxeo/ecm/platform/actions/TestActionFilter.java @@ -71,7 +71,7 @@ protected boolean filterAccept(DocumentModel doc, ActionFilter filter) { } private ActionFilter getFilter(String name) { - return as.getFilterRegistry().getFilter(name); + return as.getFilter(name); } @Test diff --git a/nuxeo-jsf/nuxeo-platform-contentview-jsf/src/test/java/org/nuxeo/ecm/platform/contentview/jsf/test/TestContentViewState.java b/nuxeo-jsf/nuxeo-platform-contentview-jsf/src/test/java/org/nuxeo/ecm/platform/contentview/jsf/test/TestContentViewState.java index cac985d607c7..e9a04fcfd8c6 100644 --- a/nuxeo-jsf/nuxeo-platform-contentview-jsf/src/test/java/org/nuxeo/ecm/platform/contentview/jsf/test/TestContentViewState.java +++ b/nuxeo-jsf/nuxeo-platform-contentview-jsf/src/test/java/org/nuxeo/ecm/platform/contentview/jsf/test/TestContentViewState.java @@ -514,7 +514,6 @@ public void testSaveJSONContentViewWithSearchDoc() throws Exception { FileUtils.writeFile(tmpFile, "Content"); Blob blob = Blobs.createBlob(tmpFile); file.put("file", (Serializable) blob); - file.put("filename", "initial_name.txt"); files.add(file); searchDocument.setPropertyValue("files:files", files); diff --git a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/DownloadFileRestlet.java b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/DownloadFileRestlet.java index 4432229e8cc4..9d59806986c1 100644 --- a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/DownloadFileRestlet.java +++ b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/DownloadFileRestlet.java @@ -101,13 +101,9 @@ public void handle(Request req, Response res) { } else { String schemaName = getQueryParamValue(req, SCHEMA, DEFAULT_SCHEMA); String blobFieldName = getQueryParamValue(req, BLOB_FIELD, DEFAULT_BLOB_FIELD); - String filenameFieldName = getQueryParamValue(req, FILENAME_FIELD, DEFAULT_FILENAME_FIELD); - filename = (String) dm.getProperty(schemaName, filenameFieldName); blob = (Blob) dm.getProperty(schemaName, blobFieldName); - xpath = schemaName + ':' + blobFieldName; - } - if (StringUtils.isBlank(filename)) { filename = StringUtils.defaultIfBlank(blob.getFilename(), "file"); + xpath = schemaName + ':' + blobFieldName; } // trigger download diff --git a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/UploadFileRestlet.java b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/UploadFileRestlet.java index 32e9749c2067..7ccbc074ea35 100644 --- a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/UploadFileRestlet.java +++ b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/restAPI/UploadFileRestlet.java @@ -101,21 +101,18 @@ public void handle(Request req, Response res) { try { String blobPropertyName = getQueryParamValue(req, BLOB_PROPERTY_NAME, null); - String filenamePropertyName = getQueryParamValue(req, FILENAME_PROPERTY_NAME, null); - if (blobPropertyName == null || filenamePropertyName == null) { + if (blobPropertyName == null) { // find the names of the fields from the optional request // parameters with fallback to defaults if none is provided String schemaName = getQueryParamValue(req, SCHEMA, DEFAULT_SCHEMA); String blobFieldName = getQueryParamValue(req, BLOB_FIELD, DEFAULT_BLOB_FIELD); - String filenameFieldName = getQueryParamValue(req, FILENAME_FIELD, DEFAULT_FILENAME_FIELD); blobPropertyName = schemaName + ":" + blobFieldName; - filenamePropertyName = schemaName + ":" + filenameFieldName; } InputStream is = req.getEntity().getStream(); - saveFileToDocument(filename, dm, blobPropertyName, filenamePropertyName, is); + saveFileToDocument(filename, dm, blobPropertyName, is); } catch (NuxeoException | IOException e) { handleError(res, e); } @@ -127,9 +124,20 @@ protected CoreSession getDocumentManager() { /** * Save the file into the document. + * + * @deprecated since 9.1 filename is now stored in blob */ + @Deprecated protected void saveFileToDocument(String filename, DocumentModel dm, String blobPropertyName, String filenamePropertyName, InputStream is) throws IOException, PropertyException { + saveFileToDocument(filename, dm, blobPropertyName, is); + } + + /** + * Save the file into the document. + */ + protected void saveFileToDocument(String filename, DocumentModel dm, String blobPropertyName, + InputStream is) throws IOException, PropertyException { // persisting the blob makes it possible to read the binary content // of the request stream several times (mimetype sniffing, digest // computation, core binary storage) @@ -137,7 +145,6 @@ protected void saveFileToDocument(String filename, DocumentModel dm, String blob blob.setFilename(filename); dm.setPropertyValue(blobPropertyName, (Serializable) blob); - dm.setPropertyValue(filenamePropertyName, filename); getDocumentManager().saveDocument(dm); // autoversioning see https://jira.nuxeo.org/browse/NXP-5849 for more diff --git a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/tag/fn/LiveEditConstants.java b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/tag/fn/LiveEditConstants.java index 9c44b2cf0814..5744a216bbb7 100644 --- a/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/tag/fn/LiveEditConstants.java +++ b/nuxeo-jsf/nuxeo-platform-ui-web/src/main/java/org/nuxeo/ecm/platform/ui/web/tag/fn/LiveEditConstants.java @@ -78,6 +78,10 @@ public interface LiveEditConstants { String DEFAULT_DOCTYPE = "File"; // to be deprecated once all filenames are stored in the blob itself + /** + * @deprecated since 9.1 filename is now stored in the blob itself + */ + @Deprecated String DEFAULT_FILENAME_FIELD = "filename"; String DEFAULT_BLOB_FIELD = "content"; diff --git a/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/restAPI/TestUploadFileRestlet.java b/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/restAPI/TestUploadFileRestlet.java index dfaadf9b206a..337102fc820f 100644 --- a/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/restAPI/TestUploadFileRestlet.java +++ b/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/restAPI/TestUploadFileRestlet.java @@ -81,15 +81,14 @@ protected CoreSession getDocumentManager() { }; String expectedFileName = "myfile.txt"; String blobPropertyName = DEFAULT_SCHEMA + ":" + DEFAULT_BLOB_FIELD; - String filenamePropertyName = DEFAULT_SCHEMA + ":" + DEFAULT_FILENAME_FIELD; - restlet.saveFileToDocument(expectedFileName, doc, blobPropertyName, filenamePropertyName, + restlet.saveFileToDocument(expectedFileName, doc, blobPropertyName, new ByteArrayInputStream("Content of the file.".getBytes("UTF-8"))); // check that the upload has been done correctly doc = session.getDocument(doc.getRef()); - assertEquals("The file name is", expectedFileName, doc.getProperty(DEFAULT_SCHEMA, DEFAULT_FILENAME_FIELD)); - assertEquals("The content of the file is", "Content of the file.", - ((Blob) doc.getProperty(DEFAULT_SCHEMA, DEFAULT_BLOB_FIELD)).getString()); + Blob blob = (Blob) doc.getProperty(DEFAULT_SCHEMA, DEFAULT_BLOB_FIELD); + assertEquals("The file name is", expectedFileName, blob.getFilename()); + assertEquals("The content of the file is", "Content of the file.", blob.getString()); // checking that no version has been created List versions = session.getVersions(doc.getRef()); @@ -131,15 +130,14 @@ protected CoreSession getDocumentManager() { }; String expectedFileName = "myfile.txt"; String blobPropertyName = DEFAULT_SCHEMA + ":" + DEFAULT_BLOB_FIELD; - String filenamePropertyName = DEFAULT_SCHEMA + ":" + DEFAULT_FILENAME_FIELD; - restlet.saveFileToDocument(expectedFileName, doc, blobPropertyName, filenamePropertyName, + restlet.saveFileToDocument(expectedFileName, doc, blobPropertyName, new ByteArrayInputStream("Content of the file.".getBytes("UTF-8"))); // check that the upload has been done correctly doc = session.getDocument(doc.getRef()); - assertEquals("The file name is", expectedFileName, doc.getProperty(DEFAULT_SCHEMA, DEFAULT_FILENAME_FIELD)); - assertEquals("The content of the file is", "Content of the file.", - ((Blob) doc.getProperty(DEFAULT_SCHEMA, DEFAULT_BLOB_FIELD)).getString()); + Blob blob = (Blob) doc.getProperty(DEFAULT_SCHEMA, DEFAULT_BLOB_FIELD); + assertEquals("The file name is", expectedFileName, blob.getFilename()); + assertEquals("The content of the file is", "Content of the file.", blob.getString()); // checking that version has been created and incremented List versions = session.getVersions(doc.getRef()); diff --git a/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/util/TestDocumentModelFunctions.java b/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/util/TestDocumentModelFunctions.java index 75fcf077d857..806b011a8362 100644 --- a/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/util/TestDocumentModelFunctions.java +++ b/nuxeo-jsf/nuxeo-platform-ui-web/src/test/java/org/nuxeo/ecm/platform/ui/web/util/TestDocumentModelFunctions.java @@ -50,11 +50,9 @@ public void testDefaultValue() throws Exception { Object blobVal = DocumentModelFunctions.defaultValue("files:files"); assertTrue(blobVal instanceof HashMap); HashMap blobValMap = (HashMap) blobVal; - assertEquals(2, blobValMap.size()); + assertEquals(1, blobValMap.size()); assertTrue(blobValMap.containsKey("file")); assertNull(blobValMap.get("file")); - assertTrue(blobValMap.containsKey("filename")); - assertNull(blobValMap.get("filename")); Object stringListItemVal = DocumentModelFunctions.defaultValue("lds:listOfLists/stringListItem"); assertTrue(stringListItemVal instanceof String); diff --git a/nuxeo-jsf/nuxeo-platform-webapp-base/src/test/java/org/nuxeo/ecm/webapp/clipboard/ZipUtilsTest.java b/nuxeo-jsf/nuxeo-platform-webapp-base/src/test/java/org/nuxeo/ecm/webapp/clipboard/ZipUtilsTest.java index c8b37d3214c6..fcb239b97265 100644 --- a/nuxeo-jsf/nuxeo-platform-webapp-base/src/test/java/org/nuxeo/ecm/webapp/clipboard/ZipUtilsTest.java +++ b/nuxeo-jsf/nuxeo-platform-webapp-base/src/test/java/org/nuxeo/ecm/webapp/clipboard/ZipUtilsTest.java @@ -78,7 +78,6 @@ protected DocumentModel createHeavyFile() { HashMap blob = new HashMap(); blob.put("file", (Serializable) blob2); - blob.put("filename", blob2.getFilename()); ArrayList> blobs = new ArrayList>(); blobs.add(blob); diff --git a/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/data/test2/export.zip b/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/data/test2/export.zip index ad407a4e7aa2..beef6dd48acf 100644 Binary files a/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/data/test2/export.zip and b/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/data/test2/export.zip differ diff --git a/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/schema/file.xsd b/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/schema/file.xsd index fa53e98b082a..d6c9e5fe93ce 100644 --- a/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/schema/file.xsd +++ b/nuxeo-services/nuxeo-platform-content-template-manager/src/test/resources/schema/file.xsd @@ -8,7 +8,6 @@ - diff --git a/nuxeo-services/nuxeo-platform-dublincore/src/test/java/org/nuxeo/ecm/platform/dublincore/TestDublinCoreStorage.java b/nuxeo-services/nuxeo-platform-dublincore/src/test/java/org/nuxeo/ecm/platform/dublincore/TestDublinCoreStorage.java index 081dd64a658f..3be0115f960c 100644 --- a/nuxeo-services/nuxeo-platform-dublincore/src/test/java/org/nuxeo/ecm/platform/dublincore/TestDublinCoreStorage.java +++ b/nuxeo-services/nuxeo-platform-dublincore/src/test/java/org/nuxeo/ecm/platform/dublincore/TestDublinCoreStorage.java @@ -291,7 +291,7 @@ public void testProxySchemasWithComplex() { // read part of a non-initialized complex prop // should not mark it dirty which would cause problems on save - proxy.getPropertyValue("file:filename"); + proxy.getPropertyValue("file:content"); // write a modifiable proxy schema proxy.setPropertyValue("info:info", "proxyinfo"); proxy = session.saveDocument(proxy); diff --git a/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/main/java/org/nuxeo/ecm/platform/filemanager/core/listener/MimetypeIconUpdater.java b/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/main/java/org/nuxeo/ecm/platform/filemanager/core/listener/MimetypeIconUpdater.java index 1da1b3656e5f..f63de2ba661d 100644 --- a/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/main/java/org/nuxeo/ecm/platform/filemanager/core/listener/MimetypeIconUpdater.java +++ b/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/main/java/org/nuxeo/ecm/platform/filemanager/core/listener/MimetypeIconUpdater.java @@ -58,10 +58,6 @@ public class MimetypeIconUpdater implements EventListener { public static final String MAIN_BLOB_SCHEMA = "file"; - @Deprecated - // the filename should now be stored inside the main blob - public static final String MAIN_EXTERNAL_FILENAME_FIELD = "file:filename"; - protected static final String OCTET_STREAM_MT = "application/octet-stream"; public final BlobsExtractor blobExtractor = new BlobsExtractor(); @@ -89,9 +85,6 @@ public void handleEvent(Event event) { return; } - // BBB: handle old filename scheme - updateFilename(doc); - try { // ensure the document main icon is not null setDefaultIcon(doc); @@ -147,24 +140,6 @@ private void updateIconAndSizeFields(DocumentModel doc, MimetypeRegistry mimetyp } } - /** - * Backward compatibility for external filename field: if edited, it might affect the main blob mimetype - */ - public void updateFilename(DocumentModel doc) throws PropertyException { - - if (doc.hasSchema(MAIN_BLOB_FIELD.split(":")[0])) { - Property filenameProperty = doc.getProperty(MAIN_EXTERNAL_FILENAME_FIELD); - if (filenameProperty.isDirty()) { - String filename = filenameProperty.getValue(String.class); - if (doc.getProperty(MAIN_BLOB_FIELD).getValue() != null) { - Blob blob = doc.getProperty(MAIN_BLOB_FIELD).getValue(Blob.class); - blob.setFilename(filename); - doc.setPropertyValue(MAIN_BLOB_FIELD, (Serializable) blob); - } - } - } - } - /** * If the icon field is empty, initialize it to the document type icon */ diff --git a/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/test/resources/schema/blobinlist.xsd b/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/test/resources/schema/blobinlist.xsd index 401d147528bc..c31628f95612 100644 --- a/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/test/resources/schema/blobinlist.xsd +++ b/nuxeo-services/nuxeo-platform-filemanager-core-listener/src/test/resources/schema/blobinlist.xsd @@ -17,14 +17,7 @@ - - - - - + diff --git a/nuxeo-services/nuxeo-platform-filemanager-core/src/test/java/org/nuxeo/ecm/platform/filemanager/TestFileManagerService.java b/nuxeo-services/nuxeo-platform-filemanager-core/src/test/java/org/nuxeo/ecm/platform/filemanager/TestFileManagerService.java index 3614cdea2f52..b86650f6a59b 100644 --- a/nuxeo-services/nuxeo-platform-filemanager-core/src/test/java/org/nuxeo/ecm/platform/filemanager/TestFileManagerService.java +++ b/nuxeo-services/nuxeo-platform-filemanager-core/src/test/java/org/nuxeo/ecm/platform/filemanager/TestFileManagerService.java @@ -107,10 +107,10 @@ public void testDefaultCreateFromBlob() throws Exception { "test-data/hello.doc"); assertNotNull(doc); assertEquals("hello.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello.doc", doc.getProperty("file", "filename")); assertNotNull(doc.getProperty("file", "content")); BinaryBlob blob = (BinaryBlob) doc.getProperty("file", "content"); assertEquals("application/msword", blob.getMimeType()); + assertEquals("hello.doc", blob.getFilename()); // let's make the same test but this time without mime-type checking // because the blob already carries a mime-type that matches the file name @@ -119,10 +119,10 @@ public void testDefaultCreateFromBlob() throws Exception { "test-data/hello2.doc", true); assertNotNull(doc); assertEquals("hello2.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello2.doc", doc.getProperty("file", "filename")); assertNotNull(doc.getProperty("file", "content")); blob = (BinaryBlob) doc.getProperty("file", "content"); assertEquals("application/msword", blob.getMimeType()); + assertEquals("hello2.doc", blob.getFilename()); } @Test @@ -136,20 +136,20 @@ public void testCreateFromBlobWithMimeTypeCheck() throws IOException { "test-data/hello3.doc"); assertNotNull(doc); assertEquals("hello3.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello3.doc", doc.getProperty("file", "filename")); assertNotNull(doc.getProperty("file", "content")); BinaryBlob blob = (BinaryBlob) doc.getProperty("file", "content"); assertEquals("application/msword", blob.getMimeType()); + assertEquals("hello3.doc", blob.getFilename()); input = Blobs.createBlob(file, "application/sometype"); doc = service.createDocumentFromBlob(coreSession, input, workspace.getPathAsString(), true, "test-data/hello3.doc", true); assertNotNull(doc); assertEquals("hello3.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello3.doc", doc.getProperty("file", "filename")); assertNotNull(doc.getProperty("file", "content")); blob = (BinaryBlob) doc.getProperty("file", "content"); assertEquals("application/sometype", blob.getMimeType()); + assertEquals("hello3.doc", blob.getFilename()); } @Test @@ -164,8 +164,9 @@ public void testDefaultCreateTwiceFromSameBlob() throws Exception { assertNotNull(doc); assertEquals("hello.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello.doc", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + Blob blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.doc", blob.getFilename()); List versions = coreSession.getVersions(docRef); assertEquals(0, versions.size()); @@ -178,8 +179,9 @@ public void testDefaultCreateTwiceFromSameBlob() throws Exception { DocumentRef newDocRef = doc.getRef(); assertEquals(docRef, newDocRef); assertEquals("hello.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello.doc", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.doc", blob.getFilename()); versions = coreSession.getVersions(docRef); assertEquals(1, versions.size()); @@ -197,8 +199,9 @@ public void testDefaultUpdateFromBlob() throws Exception { assertNotNull(doc); assertEquals("hello.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello.doc", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + Blob blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.doc", blob.getFilename()); // update it with another file with same name doc = service.updateDocumentFromBlob(coreSession, input, workspace.getPathAsString(), @@ -208,8 +211,9 @@ public void testDefaultUpdateFromBlob() throws Exception { DocumentRef newDocRef = doc.getRef(); assertEquals(docRef, newDocRef); assertEquals("hello.doc", doc.getProperty("dublincore", "title")); - assertEquals("hello.doc", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.doc", blob.getFilename()); } protected static final String SEPARATOR = "\n"; @@ -400,7 +404,6 @@ public void testUpdateFileDocWithPlainTextFile() throws Exception { DocumentModel doc = coreSession.createDocumentModel(workspace.getPathAsString(), "hello.html", "File"); doc.setPropertyValue("dc:title", "hello.html"); doc.setPropertyValue("file:content", (Serializable) input); - doc.setPropertyValue("file:filename", "hello.html"); // create doc doc = coreSession.createDocument(doc); @@ -409,8 +412,9 @@ public void testUpdateFileDocWithPlainTextFile() throws Exception { assertNotNull(doc); assertEquals("hello.html", doc.getProperty("dublincore", "title")); - assertEquals("hello.html", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + Blob blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.html", blob.getFilename()); assertTrue(extractText(doc).contains("RTF")); assertEquals("text/rtf", getMimeType(doc)); @@ -426,8 +430,9 @@ public void testUpdateFileDocWithPlainTextFile() throws Exception { DocumentRef newDocRef = doc.getRef(); assertEquals(docRef, newDocRef); - assertEquals("hello.html", doc.getProperty("file", "filename")); - assertNotNull(doc.getProperty("file", "content")); + blob = (Blob) doc.getProperty("file", "content"); + assertNotNull(blob); + assertEquals("hello.html", blob.getFilename()); assertTrue(extractText(doc).contains("HTML")); assertEquals("text/html", getMimeType(doc)); diff --git a/nuxeo-services/nuxeo-platform-rendering/src/test/java/org/nuxeo/ecm/platform/rendering/test/TestDocumentTemplate.java b/nuxeo-services/nuxeo-platform-rendering/src/test/java/org/nuxeo/ecm/platform/rendering/test/TestDocumentTemplate.java index 42c99616f3f7..c0a46838dfda 100644 --- a/nuxeo-services/nuxeo-platform-rendering/src/test/java/org/nuxeo/ecm/platform/rendering/test/TestDocumentTemplate.java +++ b/nuxeo-services/nuxeo-platform-rendering/src/test/java/org/nuxeo/ecm/platform/rendering/test/TestDocumentTemplate.java @@ -1,5 +1,5 @@ /* - * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. + * (C) Copyright 2013-2016 Nuxeo SA (http://nuxeo.com/) and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,31 +26,8 @@ import java.util.List; import java.util.Map; - import javax.inject.Inject; -/* - * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - * Nuxeo - * - * $Id$ - */ -import junit.framework.Assert; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -68,6 +45,8 @@ import org.nuxeo.runtime.test.runner.Features; import org.nuxeo.runtime.test.runner.FeaturesRunner; +import junit.framework.Assert; + /** * @author Tiry * @since 5.7 @@ -106,7 +85,6 @@ public void setUp() throws Exception { Blob blob = Blobs.createBlob("something", "application/something", null, "file" + i + ".something"); Map blobEntry = new HashMap<>(); blobEntry.put("file", (Serializable) blob); - blobEntry.put("filename", blob.getFilename()); blobs.add(blobEntry); } doc.setPropertyValue("files:files", (Serializable) blobs); diff --git a/nuxeo-services/nuxeo-platform-rendering/src/test/resources/testdata/testlists.ftl b/nuxeo-services/nuxeo-platform-rendering/src/test/resources/testdata/testlists.ftl index f4f09de3fffc..e9dd94e8f8b9 100644 --- a/nuxeo-services/nuxeo-platform-rendering/src/test/resources/testdata/testlists.ftl +++ b/nuxeo-services/nuxeo-platform-rendering/src/test/resources/testdata/testlists.ftl @@ -21,5 +21,5 @@ ${doc.dublincore.issued?datetime} <#list doc.dublincore.subjects as subject>${subject}| <#list doc.files.files as file> -${file.filename} ${file.file.length} +${file.file.filename} ${file.file.length} diff --git a/nuxeo-services/nuxeo-platform-ws/src/main/java/org/nuxeo/ecm/platform/ws/NuxeoRemotingBean.java b/nuxeo-services/nuxeo-platform-ws/src/main/java/org/nuxeo/ecm/platform/ws/NuxeoRemotingBean.java index a609591de585..9c6e8125e799 100644 --- a/nuxeo-services/nuxeo-platform-ws/src/main/java/org/nuxeo/ecm/platform/ws/NuxeoRemotingBean.java +++ b/nuxeo-services/nuxeo-platform-ws/src/main/java/org/nuxeo/ecm/platform/ws/NuxeoRemotingBean.java @@ -545,8 +545,7 @@ public String uploadDocument(@WebParam(name = "sessionId") String sid, document.setProperty("dublincore", "description", dublincoreMap.get("description")); document.setProperty("dublincore", "title", dublincoreMap.get("title")); - String filname = (String) fileMap.get("filename"); - document.setProperty("file", "filename", filname); + String filename = (String) fileMap.get("filename"); final byte[] contentData = Base64.decodeBase64((String) contentMap.get("data")); // String contentType = (String) contentMap.get("mime-type") ; Blob blob = Blobs.createBlob(contentData); @@ -555,9 +554,9 @@ public String uploadDocument(@WebParam(name = "sessionId") String sid, String mimetype; try { - mimetype = mimeService.getMimetypeFromFilenameAndBlobWithDefault(filname, blob, ""); + mimetype = mimeService.getMimetypeFromFilenameAndBlobWithDefault(filename, blob, ""); } catch (MimetypeDetectionException e) { - log.error(String.format("error during mimetype detection for %s: %s", filname, e.getMessage())); + log.error(String.format("error during mimetype detection for %s: %s", filename, e.getMessage())); mimetype = ""; } diff --git a/nuxeo-webengine/nuxeo-webengine-base/src/main/java/org/nuxeo/ecm/core/rest/FileService.java b/nuxeo-webengine/nuxeo-webengine-base/src/main/java/org/nuxeo/ecm/core/rest/FileService.java index f5874029bc34..9afcd94ec17b 100644 --- a/nuxeo-webengine/nuxeo-webengine-base/src/main/java/org/nuxeo/ecm/core/rest/FileService.java +++ b/nuxeo-webengine/nuxeo-webengine-base/src/main/java/org/nuxeo/ecm/core/rest/FileService.java @@ -39,7 +39,6 @@ import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.NuxeoException; -import org.nuxeo.ecm.core.api.PropertyException; import org.nuxeo.ecm.core.api.model.Property; import org.nuxeo.ecm.core.versioning.VersioningService; import org.nuxeo.ecm.platform.web.common.ServletHelper; @@ -86,15 +85,7 @@ public Response doGet(@Context Request request) { String fileName = blob.getFilename(); if (fileName == null) { - p = p.getParent(); - if (p.isComplex()) { // special handling for file and files - // schema - try { - fileName = (String) p.getValue("filename"); - } catch (PropertyException e) { - fileName = "Unknown"; - } - } + fileName = "Unknown"; } String digest = blob.getDigest(); @@ -150,19 +141,12 @@ public Response doPost() { // files schema // separately Map map = new HashMap(); - map.put("filename", blob.getFilename()); map.put("file", (Serializable) blob); p.addValue(map); } else { p.addValue(blob); } } else { - if ("file".equals(p.getSchema().getName())) { // for - // compatibility - // with deprecated - // filename - p.getParent().get("filename").setValue(blob.getFilename()); - } p.setValue(blob); } // make snapshot