From 4a8f60cdf5136f3a03c97e2ee31bb9cc9a82abca Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Tue, 11 Feb 2014 19:30:15 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 57094: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 56579: Merged V4.1-BUG-FIX (4.1.7) to V4.2-BUG-FIX (4.2.1) 56546: MNT-9471: Merged DEV to V4.1-BUG-FIX (4.1.7) 56525: MNT-9471: Better Bulk Import management in case of bad files and folders - During Bulk Import ignore files and folders with illegal names git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61723 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bulk-import-context.xml | 1 + .../impl/DirectoryAnalyserImpl.java | 63 ++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/config/alfresco/bulk-import-context.xml b/config/alfresco/bulk-import-context.xml index eac63ba616..285d0a50e7 100644 --- a/config/alfresco/bulk-import-context.xml +++ b/config/alfresco/bulk-import-context.xml @@ -46,6 +46,7 @@ + diff --git a/source/java/org/alfresco/repo/bulkimport/impl/DirectoryAnalyserImpl.java b/source/java/org/alfresco/repo/bulkimport/impl/DirectoryAnalyserImpl.java index afaee4748a..2b53113eef 100644 --- a/source/java/org/alfresco/repo/bulkimport/impl/DirectoryAnalyserImpl.java +++ b/source/java/org/alfresco/repo/bulkimport/impl/DirectoryAnalyserImpl.java @@ -33,14 +33,23 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.bulkimport.AnalysedDirectory; import org.alfresco.repo.bulkimport.DirectoryAnalyser; import org.alfresco.repo.bulkimport.ImportFilter; import org.alfresco.repo.bulkimport.ImportableItem; import org.alfresco.repo.bulkimport.ImportableItem.FileType; import org.alfresco.repo.bulkimport.MetadataLoader; +import org.alfresco.service.cmr.dictionary.Constraint; +import org.alfresco.service.cmr.dictionary.ConstraintDefinition; +import org.alfresco.service.cmr.dictionary.ConstraintException; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.PropertyCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.InitializingBean; /** * This class provides the implementation for directory analysis, the process by @@ -49,7 +58,7 @@ import org.apache.commons.logging.LogFactory; * @since 4.0 * */ -public class DirectoryAnalyserImpl implements DirectoryAnalyser +public class DirectoryAnalyserImpl implements DirectoryAnalyser, InitializingBean { private final static Log log = LogFactory.getLog(DirectoryAnalyserImpl.class); @@ -58,18 +67,52 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser private MetadataLoader metadataLoader; private BulkImportStatusImpl importStatus; private List importFilters; + private DictionaryService dictionaryService; + private Constraint filenameConstraint; - public DirectoryAnalyserImpl(MetadataLoader metadataLoader, BulkImportStatusImpl importStatus, List importFilters) + public DirectoryAnalyserImpl(MetadataLoader metadataLoader, BulkImportStatusImpl importStatus, List importFilters, + DictionaryService dictionaryService) { this.metadataLoader = metadataLoader; this.importStatus = importStatus; this.importFilters = importFilters; + this.dictionaryService = dictionaryService; } public DirectoryAnalyserImpl() { } + public DictionaryService getDictionaryService() + { + return dictionaryService; + } + + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryService = dictionaryService; + } + + /** + * Loads filename constraint from dictionary + */ + public void afterPropertiesSet() throws Exception + { + PropertyCheck.mandatory(this, "dictionaryService", dictionaryService); + + QName qNameConstraint = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "filename"); + ConstraintDefinition constraintDef = dictionaryService.getConstraint(qNameConstraint); + if (constraintDef == null) + { + throw new AlfrescoRuntimeException("Constraint definition does not exist: " + qNameConstraint); + } + filenameConstraint = constraintDef.getConstraint(); + if (filenameConstraint == null) + { + throw new AlfrescoRuntimeException("Constraint does not exist: " + qNameConstraint); + } + } + public void setMetadataLoader(MetadataLoader metadataLoader) { this.metadataLoader = metadataLoader; @@ -143,6 +186,22 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser if (file.canRead()) { + try + { + filenameConstraint.evaluate(file.getName()); + } + catch (ConstraintException e) + { + if (log.isWarnEnabled()) + { + log.warn("Skipping file with invalid name: '" + FileUtils.getFileName(file) + "'."); + } + // mark file with invalid name as unreadable + importStatus.incrementNumberOfUnreadableEntries(); + + continue; + } + if (isVersionFile(file)) { addVersionFile(directory, result, file);