diff --git a/src/main/java/org/alfresco/repo/bulkimport/metadataloaders/XmlPropertiesFileMetadataLoader.java b/src/main/java/org/alfresco/repo/bulkimport/metadataloaders/XmlPropertiesFileMetadataLoader.java index 5028d9adf0..571a455d24 100644 --- a/src/main/java/org/alfresco/repo/bulkimport/metadataloaders/XmlPropertiesFileMetadataLoader.java +++ b/src/main/java/org/alfresco/repo/bulkimport/metadataloaders/XmlPropertiesFileMetadataLoader.java @@ -1,20 +1,20 @@ /* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.Path; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.alfresco.repo.bulkimport.MetadataLoader; 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 String METADATA_FILE_EXTENSION = "properties.xml"; + // MNT-18001 + // list of properties to be ignored from the metadata files + private final Set protectedProperties = new HashSet<>(); + + public void setProtectedProperties(List protectedProperties) + { + this.protectedProperties.clear(); + this.protectedProperties.addAll(protectedProperties); + } public XmlPropertiesFileMetadataLoader(final ServiceRegistry serviceRegistry) { @@ -121,6 +133,9 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad Properties props = new Properties(); props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile))); result = new HashMap((Map)props); + + // MNT-18001 + removeProtectedProperties(result); } catch (final IOException ioe) { @@ -130,4 +145,13 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad return(result); } + /** + * Removes protected properties from the map supplied + * + * @param props Map with the properties from metadata file + */ + private void removeProtectedProperties(Map props) + { + props.keySet().removeAll(protectedProperties); + } } diff --git a/src/main/resources/alfresco/bulk-import-context.xml b/src/main/resources/alfresco/bulk-import-context.xml index aeb4d9a376..2bfad037d5 100644 --- a/src/main/resources/alfresco/bulk-import-context.xml +++ b/src/main/resources/alfresco/bulk-import-context.xml @@ -28,6 +28,11 @@ class="org.alfresco.repo.bulkimport.metadataloaders.XmlPropertiesFileMetadataLoader" lazy-init="true"> + + + cm:versionLabel + + diff --git a/src/test/java/org/alfresco/repo/bulkimport/impl/BulkImportTest.java b/src/test/java/org/alfresco/repo/bulkimport/impl/BulkImportTest.java index 4893d74613..f3bfde84bd 100644 --- a/src/test/java/org/alfresco/repo/bulkimport/impl/BulkImportTest.java +++ b/src/test/java/org/alfresco/repo/bulkimport/impl/BulkImportTest.java @@ -699,6 +699,39 @@ public class BulkImportTest extends AbstractBulkImportTests 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 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} * is thrown rather than a checked {@link FileNotFoundException} exception. diff --git a/src/test/resources/bulkimport6/doc.xlsx b/src/test/resources/bulkimport6/doc.xlsx new file mode 100644 index 0000000000..a7f65f1b45 Binary files /dev/null and b/src/test/resources/bulkimport6/doc.xlsx differ diff --git a/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml new file mode 100644 index 0000000000..ad62ceaa5c --- /dev/null +++ b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml @@ -0,0 +1,22 @@ + + + + cm:content + cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author + admin + true + + admin + MAJOR + 2017-02-24T01:17:47.670-05:00 + 23.0 + false + workspace + SpacesStore + + doc.xlsx + admin + true + en_GB + 2017-02-24T01:25:19.626-05:00 + \ No newline at end of file diff --git a/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v1 b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v1 new file mode 100644 index 0000000000..221ef36343 --- /dev/null +++ b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v1 @@ -0,0 +1,22 @@ + + + + cm:content + cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author + admin + true + + admin + MAJOR + 2017-02-24T01:17:47.670-05:00 + 23.1 + false + workspace + SpacesStore + + doc.xlsx + admin + true + en_GB + 2017-02-24T01:17:48.858-05:00 + \ No newline at end of file diff --git a/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v2 b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v2 new file mode 100644 index 0000000000..179b76f85a --- /dev/null +++ b/src/test/resources/bulkimport6/doc.xlsx.metadata.properties.xml.v2 @@ -0,0 +1,22 @@ + + + + cm:content + cm:versionable,cm:titled,cm:auditable,sys:referenceable,sys:localized,cm:author + admin + true + + admin + MAJOR + 2017-02-24T01:17:47.670-05:00 + 23.2 + false + workspace + SpacesStore + + doc.xlsx + admin + true + en_GB + 2017-02-24T01:22:37.661-05:00 + \ No newline at end of file diff --git a/src/test/resources/bulkimport6/doc.xlsx.v1 b/src/test/resources/bulkimport6/doc.xlsx.v1 new file mode 100644 index 0000000000..bb931bc132 Binary files /dev/null and b/src/test/resources/bulkimport6/doc.xlsx.v1 differ diff --git a/src/test/resources/bulkimport6/doc.xlsx.v2 b/src/test/resources/bulkimport6/doc.xlsx.v2 new file mode 100644 index 0000000000..7d21622ec7 Binary files /dev/null and b/src/test/resources/bulkimport6/doc.xlsx.v2 differ