Skip to content

Commit

Permalink
NXP-21025 NXP-18555: Remove deprecated filename property from file an…
Browse files Browse the repository at this point in the history
…d files schemas
  • Loading branch information
kevinleturc authored and nuxeojenkins committed Dec 26, 2016
1 parent 11e89d2 commit c39b384
Show file tree
Hide file tree
Showing 67 changed files with 171 additions and 348 deletions.
@@ -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.
Expand All @@ -15,7 +15,6 @@
*
* Contributors:
* Nuxeo - initial API and implementation
*
*/
package org.nuxeo.ecm.core.api.blobholder;

Expand Down Expand Up @@ -51,11 +50,11 @@ public class BlobHolderAdapterComponent extends DefaultComponent implements Blob

public static final String EXTERNALBLOB_ADAPTER_EP = "ExternalBlobAdapter";

protected final Map<String, BlobHolderFactory> factories = new HashMap<String, BlobHolderFactory>();
protected final Map<String, BlobHolderFactory> factories = new HashMap<>();

protected Map<String, BlobHolderFactory> factoriesByFacets = new HashMap<String, BlobHolderFactory>();
protected Map<String, BlobHolderFactory> factoriesByFacets = new HashMap<>();

protected static final Map<String, ExternalBlobAdapter> externalBlobAdapters = new HashMap<String, ExternalBlobAdapter>();
protected static final Map<String, ExternalBlobAdapter> externalBlobAdapters = new HashMap<>();

@Override
public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
Expand Down Expand Up @@ -94,7 +93,8 @@ public void unregisterContribution(Object contribution, String extensionPoint, C
/* for test */

public static Set<String> getFactoryNames() {
return ((BlobHolderAdapterComponent) Framework.getLocalService(BlobHolderAdapterService.class)).factories.keySet();
return ((BlobHolderAdapterComponent) Framework.getLocalService(
BlobHolderAdapterService.class)).factories.keySet();
}

/* Service Interface */
Expand Down Expand Up @@ -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 {
Expand Down
@@ -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.
Expand All @@ -15,9 +15,7 @@
*
* Contributors:
* Nuxeo - initial API and implementation
*
*/

package org.nuxeo.ecm.core.api.blobholder;

import java.io.Serializable;
Expand All @@ -41,21 +39,11 @@ public class DocumentBlobHolder extends AbstractBlobHolder {

protected final String xPath;

protected String xPathFilename;

protected List<Blob> 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
Expand All @@ -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
Expand Down
Expand Up @@ -119,10 +119,8 @@ public void testGetBlobsPropertiesBlobList() throws Exception {
DocumentModel doc = new DocumentModelImpl("/", "doc", "BlobInListDocument");
Map<String, Object> map1 = new HashMap<>();
map1.put("file", createBlob("test1.pdf"));
map1.put("filename", "test1.pdf");
Map<String, Object> map2 = new HashMap<>();
map2.put("file", createBlob("test2.pdf"));
map2.put("filename", "test2.pdf");
doc.setPropertyValue("bil:files", (Serializable) Arrays.asList(map1, map2));
List<Property> blobs;

Expand Down
Expand Up @@ -23,12 +23,7 @@

<xs:complexType name="file">
<xs:sequence>
<!-- old definition -->
<xs:element name="file" type="nxs:content"/>
<xs:element name="filename" type="xs:string"/>
<!-- future definition -->
<!--<xs:element name="file" type="nxs:file" minOccurs="0"
maxOccurs="unbounded" />-->
</xs:sequence>
</xs:complexType>

Expand Down
Expand Up @@ -5,7 +5,6 @@

<xs:include schemaLocation="core-types.xsd" />

<xs:element name="filename" type="xs:string" />
<xs:element name="content" type="nxs:externalcontent" />

</xs:schema>
Expand Up @@ -5,7 +5,6 @@

<xs:include schemaLocation="core-types.xsd" />

<xs:element name="filename" type="xs:string" />
<xs:element name="content" type="nxs:content" />

</xs:schema>
Expand Up @@ -325,10 +325,9 @@ public void testResolveBlobFromDownloadUrl() throws IOException {
String blobFilename = "synopsis.txt";
blob.setFilename(blobFilename);

Map<String, Object> fileMap = new HashMap<String, Object>();
Map<String, Object> fileMap = new HashMap<>();
fileMap.put("file", blob);
fileMap.put("filename", blob.getFilename());
List<Map<String, Object>> docFiles = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> docFiles = new ArrayList<>();
docFiles.add(fileMap);

doc.setProperty("files", "files", docFiles);
Expand Down
Expand Up @@ -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);
Expand All @@ -83,7 +82,7 @@ protected final DocumentModel createTestDoc(CoreSession session) {
doc.setPropertyValue("cs:origin", "Internal");

// segmentVariable
Map<String, Serializable> segment = new HashMap<String, Serializable>();
Map<String, Serializable> segment = new HashMap<>();
segment.put("name", "MySegment");
segment.put("target", "SomeTarget");
segment.put("variableType", "rawVariable");
Expand Down
Expand Up @@ -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);

Expand Down
Expand Up @@ -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);
Expand Down
Binary file modified nuxeo-core/nuxeo-core-io/src/test/resources/archive.zip
Binary file not shown.
Binary file modified nuxeo-core/nuxeo-core-io/src/test/resources/export.zip
Binary file not shown.
Binary file modified nuxeo-core/nuxeo-core-io/src/test/resources/modified_archive.zip
Binary file not shown.
Binary file not shown.
Expand Up @@ -8,7 +8,6 @@

<xs:include schemaLocation="core-types.xsd"/>

<xs:element name="filename" type="xs:string"/>
<xs:element name="content" type="nxs:content"/>

</xs:schema>
Expand Down
Expand Up @@ -104,14 +104,9 @@ private interface TriConsumer<T, U, V> {
void accept(T t, U u, V v);
}

protected final BiFunction<Document, String, Object> DocumentGetValue = (Document doc, String xpath) -> {
return doc.getValue(xpath);
};
protected final BiFunction<Document, String, Object> DocumentGetValue = Document::getValue;

protected final TriConsumer<Document, String, Object> DocumentSetValue = (Document doc, String xpath,
Object value) -> {
doc.setValue(xpath, value);
};
protected final TriConsumer<Document, String, Object> DocumentSetValue = Document::setValue;

@Test
public void testGetValueErrors() throws Exception {
Expand Down Expand Up @@ -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<String, Object> c1 = (xpath, value) -> DocumentSetValue.accept(doc1, xpath, value);
checkSet(c1, "tp:complexList", Long.valueOf(0),
Expand Down Expand Up @@ -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<String, Object> vignette2 = new HashMap<>();
vignette2.put("width", size1);
vignette2.put("content", blob);

// get recursive list item
@SuppressWarnings("unchecked")
Map<String, Object> v0 = (Map<String, Object>) 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<String, Object> ev1 = new HashMap<>();
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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<String, CompositeType> facets = getSchemaManagerFacets();
Expand Down

0 comments on commit c39b384

Please sign in to comment.