mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
fix/MNT-18001_ignore_version_label_in_metadata (#28)
MNT-18001: Presence of versionLabel in metadata file throws error in bulk importer - remove versionLabel property from the list of properties loaded from metadata files - add tests for bulkimport file with versionLabel present in metadata files
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
@@ -33,8 +33,11 @@ import java.io.Serializable;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.bulkimport.MetadataLoader;
|
import org.alfresco.repo.bulkimport.MetadataLoader;
|
||||||
import org.alfresco.repo.bulkimport.impl.FileUtils;
|
import org.alfresco.repo.bulkimport.impl.FileUtils;
|
||||||
@@ -97,6 +100,15 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad
|
|||||||
{
|
{
|
||||||
private final static Log log = LogFactory.getLog(XmlPropertiesFileMetadataLoader.class);
|
private final static Log log = LogFactory.getLog(XmlPropertiesFileMetadataLoader.class);
|
||||||
private final static String METADATA_FILE_EXTENSION = "properties.xml";
|
private final static String METADATA_FILE_EXTENSION = "properties.xml";
|
||||||
|
// MNT-18001
|
||||||
|
// list of properties to be ignored from the metadata files
|
||||||
|
private final Set<String> protectedProperties = new HashSet<>();
|
||||||
|
|
||||||
|
public void setProtectedProperties(List<String> protectedProperties)
|
||||||
|
{
|
||||||
|
this.protectedProperties.clear();
|
||||||
|
this.protectedProperties.addAll(protectedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
public XmlPropertiesFileMetadataLoader(final ServiceRegistry serviceRegistry)
|
public XmlPropertiesFileMetadataLoader(final ServiceRegistry serviceRegistry)
|
||||||
{
|
{
|
||||||
@@ -121,6 +133,9 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad
|
|||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile)));
|
props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile)));
|
||||||
result = new HashMap<String,Serializable>((Map)props);
|
result = new HashMap<String,Serializable>((Map)props);
|
||||||
|
|
||||||
|
// MNT-18001
|
||||||
|
removeProtectedProperties(result);
|
||||||
}
|
}
|
||||||
catch (final IOException ioe)
|
catch (final IOException ioe)
|
||||||
{
|
{
|
||||||
@@ -130,4 +145,13 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes protected properties from the map supplied
|
||||||
|
*
|
||||||
|
* @param props Map with the properties from metadata file
|
||||||
|
*/
|
||||||
|
private void removeProtectedProperties(Map<String,Serializable> props)
|
||||||
|
{
|
||||||
|
props.keySet().removeAll(protectedProperties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,11 @@
|
|||||||
class="org.alfresco.repo.bulkimport.metadataloaders.XmlPropertiesFileMetadataLoader"
|
class="org.alfresco.repo.bulkimport.metadataloaders.XmlPropertiesFileMetadataLoader"
|
||||||
lazy-init="true">
|
lazy-init="true">
|
||||||
<constructor-arg index="0" ref="ServiceRegistry" />
|
<constructor-arg index="0" ref="ServiceRegistry" />
|
||||||
|
<property name="protectedProperties">
|
||||||
|
<list>
|
||||||
|
<value>cm:versionLabel</value>
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="bfsiContentDataFactory" class="org.alfresco.repo.bulkimport.impl.FilesystemContentDataFactory">
|
<bean id="bfsiContentDataFactory" class="org.alfresco.repo.bulkimport.impl.FilesystemContentDataFactory">
|
||||||
|
@@ -699,6 +699,39 @@ public class BulkImportTest extends AbstractBulkImportTests
|
|||||||
Files.deleteIfExists(dest);
|
Files.deleteIfExists(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MNT-18001: Presence of versionLabel in metadata file throws error in bulk importer
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testImportFilesWithVersionLabel() throws Throwable
|
||||||
|
{
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
// Get metadata file with versionLabel property
|
||||||
|
NodeRef folderNode = topLevelFolder.getNodeRef();
|
||||||
|
NodeImporter nodeImporter = streamingNodeImporterFactory.getNodeImporter(ResourceUtils.getFile("classpath:bulkimport6"));
|
||||||
|
|
||||||
|
// Set parameters for bulk import: Target space, Disable rule processing, Replace existing files, Batch size:1, Number of threads:1
|
||||||
|
BulkImportParameters bulkImportParameters = new BulkImportParameters();
|
||||||
|
bulkImportParameters.setTarget(folderNode);
|
||||||
|
bulkImportParameters.setDisableRulesService(true);
|
||||||
|
bulkImportParameters.setExistingFileMode(BulkImportParameters.ExistingFileMode.REPLACE);
|
||||||
|
bulkImportParameters.setBatchSize(1);
|
||||||
|
bulkImportParameters.setNumThreads(1);
|
||||||
|
|
||||||
|
bulkImporter.bulkImport(bulkImportParameters, nodeImporter);
|
||||||
|
|
||||||
|
List<FileInfo> files = getFiles(folderNode, null);
|
||||||
|
assertNotNull(files);
|
||||||
|
FileInfo file = files.get(0);
|
||||||
|
assertNotNull(file);
|
||||||
|
|
||||||
|
VersionHistory history = versionService.getVersionHistory(file.getNodeRef());
|
||||||
|
assertEquals(1, bulkImporter.getStatus().getNumberOfContentNodesCreated());
|
||||||
|
assertEquals("Imported file should have 3 versions:", 3, history.getAllVersions().size());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplifies calling {@ResourceUtils.getFile} so that a {@link RuntimeException}
|
* Simplifies calling {@ResourceUtils.getFile} so that a {@link RuntimeException}
|
||||||
* is thrown rather than a checked {@link FileNotFoundException} exception.
|
* is thrown rather than a checked {@link FileNotFoundException} exception.
|
||||||
|
BIN
src/test/resources/bulkimport6/doc.xlsx
Normal file
BIN
src/test/resources/bulkimport6/doc.xlsx
Normal file
Binary file not shown.
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties>
|
||||||
|
<entry key="type">cm:content</entry>
|
||||||
|
<entry key="aspects">cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author</entry>
|
||||||
|
<entry key="cm:creator">admin</entry>
|
||||||
|
<entry key="cm:autoVersion">true</entry>
|
||||||
|
<entry key="cm:title"></entry>
|
||||||
|
<entry key="cm:modifier">admin</entry>
|
||||||
|
<entry key="cm:versionType">MAJOR</entry>
|
||||||
|
<entry key="cm:created">2017-02-24T01:17:47.670-05:00</entry>
|
||||||
|
<entry key="cm:versionLabel">23.0</entry>
|
||||||
|
<entry key="cm:autoVersionOnUpdateProps">false</entry>
|
||||||
|
<entry key="sys:store-protocol">workspace</entry>
|
||||||
|
<entry key="sys:store-identifier">SpacesStore</entry>
|
||||||
|
<entry key="cm:description"></entry>
|
||||||
|
<entry key="cm:name">doc.xlsx</entry>
|
||||||
|
<entry key="cm:author">admin</entry>
|
||||||
|
<entry key="cm:initialVersion">true</entry>
|
||||||
|
<entry key="sys:locale">en_GB</entry>
|
||||||
|
<entry key="cm:modified">2017-02-24T01:25:19.626-05:00</entry>
|
||||||
|
</properties>
|
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties>
|
||||||
|
<entry key="type">cm:content</entry>
|
||||||
|
<entry key="aspects">cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author</entry>
|
||||||
|
<entry key="cm:creator">admin</entry>
|
||||||
|
<entry key="cm:autoVersion">true</entry>
|
||||||
|
<entry key="cm:title"></entry>
|
||||||
|
<entry key="cm:modifier">admin</entry>
|
||||||
|
<entry key="cm:versionType">MAJOR</entry>
|
||||||
|
<entry key="cm:created">2017-02-24T01:17:47.670-05:00</entry>
|
||||||
|
<entry key="cm:versionLabel">23.1</entry>
|
||||||
|
<entry key="cm:autoVersionOnUpdateProps">false</entry>
|
||||||
|
<entry key="sys:store-protocol">workspace</entry>
|
||||||
|
<entry key="sys:store-identifier">SpacesStore</entry>
|
||||||
|
<entry key="cm:description"></entry>
|
||||||
|
<entry key="cm:name">doc.xlsx</entry>
|
||||||
|
<entry key="cm:author">admin</entry>
|
||||||
|
<entry key="cm:initialVersion">true</entry>
|
||||||
|
<entry key="sys:locale">en_GB</entry>
|
||||||
|
<entry key="cm:modified">2017-02-24T01:17:48.858-05:00</entry>
|
||||||
|
</properties>
|
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties>
|
||||||
|
<entry key="type">cm:content</entry>
|
||||||
|
<entry key="aspects">cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author</entry>
|
||||||
|
<entry key="cm:creator">admin</entry>
|
||||||
|
<entry key="cm:autoVersion">true</entry>
|
||||||
|
<entry key="cm:title"></entry>
|
||||||
|
<entry key="cm:modifier">admin</entry>
|
||||||
|
<entry key="cm:versionType">MAJOR</entry>
|
||||||
|
<entry key="cm:created">2017-02-24T01:17:47.670-05:00</entry>
|
||||||
|
<entry key="cm:versionLabel">23.2</entry>
|
||||||
|
<entry key="cm:autoVersionOnUpdateProps">false</entry>
|
||||||
|
<entry key="sys:store-protocol">workspace</entry>
|
||||||
|
<entry key="sys:store-identifier">SpacesStore</entry>
|
||||||
|
<entry key="cm:description"></entry>
|
||||||
|
<entry key="cm:name">doc.xlsx</entry>
|
||||||
|
<entry key="cm:author">admin</entry>
|
||||||
|
<entry key="cm:initialVersion">true</entry>
|
||||||
|
<entry key="sys:locale">en_GB</entry>
|
||||||
|
<entry key="cm:modified">2017-02-24T01:22:37.661-05:00</entry>
|
||||||
|
</properties>
|
BIN
src/test/resources/bulkimport6/doc.xlsx.v1
Normal file
BIN
src/test/resources/bulkimport6/doc.xlsx.v1
Normal file
Binary file not shown.
BIN
src/test/resources/bulkimport6/doc.xlsx.v2
Normal file
BIN
src/test/resources/bulkimport6/doc.xlsx.v2
Normal file
Binary file not shown.
Reference in New Issue
Block a user