mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.0.N (5.0.4) to 5.1.N (5.1.2)
129110 adavis: Merged 5.0.2 (5.0.2.23) to 5.0.N (5.0.4) 120495 amorarasu: MNT-15367: Unable to bulk import filenames with portuguese characters in a linux environment. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@129114 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,9 +26,7 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.bulkimport;
|
package org.alfresco.repo.bulkimport;
|
||||||
|
|
||||||
import java.io.File;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -42,22 +40,22 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class AnalysedDirectory
|
public class AnalysedDirectory
|
||||||
{
|
{
|
||||||
private List<File> originalListing = null;
|
private List<Path> originalPaths = null;
|
||||||
private Map<File, ImportableItem> importableItems = null;
|
private Map<Path, ImportableItem> importableItems = null;
|
||||||
private Map<File, ImportableItem> importableDirectories = null;
|
private Map<Path, ImportableItem> importableDirectories = null;
|
||||||
|
|
||||||
public AnalysedDirectory(File[] files)
|
public AnalysedDirectory(List<Path> paths)
|
||||||
{
|
{
|
||||||
originalListing = Arrays.asList(files);
|
originalPaths = paths;
|
||||||
// Sort the files/directories so that the *.metadata.properties.xml found later, see ALF-17965 for details.
|
// Sort the files/directories so that the *.metadata.properties.xml found later, see ALF-17965 for details.
|
||||||
Collections.sort(originalListing);
|
Collections.sort(originalPaths);
|
||||||
importableItems = new HashMap<File, ImportableItem>();
|
importableItems = new HashMap<Path, ImportableItem>();
|
||||||
importableDirectories = new HashMap<File, ImportableItem>();
|
importableDirectories = new HashMap<Path, ImportableItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> getOriginalListing()
|
public List<Path> getOriginalPaths()
|
||||||
{
|
{
|
||||||
return originalListing;
|
return originalPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ImportableItem> getImportableItems()
|
public Collection<ImportableItem> getImportableItems()
|
||||||
@@ -83,7 +81,7 @@ public class AnalysedDirectory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportableItem findImportableItem(File contentFile)
|
public ImportableItem findImportableItem(Path contentFile)
|
||||||
{
|
{
|
||||||
ImportableItem result = null;
|
ImportableItem result = null;
|
||||||
result = importableItems.get(contentFile);
|
result = importableItems.get(contentFile);
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.bulkimport;
|
package org.alfresco.repo.bulkimport;
|
||||||
|
|
||||||
import java.io.FileFilter;
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,6 +53,6 @@ public interface DirectoryAnalyser
|
|||||||
* @param directory The directory to analyse (note: <u>must</u> be a directory) <i>(must not be null)</i>.
|
* @param directory The directory to analyse (note: <u>must</u> be a directory) <i>(must not be null)</i>.
|
||||||
* @return An <code>AnalysedDirectory</code> object <i>(will not be null)</i>.
|
* @return An <code>AnalysedDirectory</code> object <i>(will not be null)</i>.
|
||||||
*/
|
*/
|
||||||
public AnalysedDirectory analyseDirectory(ImportableItem directory, FileFilter filter);
|
public AnalysedDirectory analyseDirectory(ImportableItem directory, DirectoryStream.Filter<Path> filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.bulkimport;
|
package org.alfresco.repo.bulkimport;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.LinkOption;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -80,7 +84,7 @@ public final class ImportableItem
|
|||||||
public void clearParent()
|
public void clearParent()
|
||||||
{
|
{
|
||||||
numChildren--;
|
numChildren--;
|
||||||
if(numChildren <= 0)
|
if (numChildren <= 0)
|
||||||
{
|
{
|
||||||
numChildren = 0;
|
numChildren = 0;
|
||||||
parent = null;
|
parent = null;
|
||||||
@@ -89,7 +93,7 @@ public final class ImportableItem
|
|||||||
|
|
||||||
public void setParent(ImportableItem parent)
|
public void setParent(ImportableItem parent)
|
||||||
{
|
{
|
||||||
if(parent == null)
|
if (parent == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Parent cannot be null");
|
throw new IllegalArgumentException("Parent cannot be null");
|
||||||
}
|
}
|
||||||
@@ -106,7 +110,7 @@ public final class ImportableItem
|
|||||||
*/
|
*/
|
||||||
public boolean hasVersionEntries()
|
public boolean hasVersionEntries()
|
||||||
{
|
{
|
||||||
return(versionEntries != null && versionEntries.size() > 0);
|
return (versionEntries != null && versionEntries.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<VersionedContentAndMetadata> getVersionEntries()
|
public Set<VersionedContentAndMetadata> getVersionEntries()
|
||||||
@@ -138,43 +142,47 @@ public final class ImportableItem
|
|||||||
|
|
||||||
public class ContentAndMetadata
|
public class ContentAndMetadata
|
||||||
{
|
{
|
||||||
private File contentFile = null;
|
private Path contentFile = null;
|
||||||
private boolean contentFileExists = false;
|
private boolean contentFileExists = false;
|
||||||
private boolean contentFileIsReadable = false;
|
private boolean contentFileIsReadable = false;
|
||||||
private FileType contentFileType = null;
|
private FileType contentFileType = null;
|
||||||
private long contentFileSize = -1;
|
private long contentFileSize = -1;
|
||||||
private Date contentFileCreated = null;
|
private Date contentFileCreated = null;
|
||||||
private Date contentFileModified = null;
|
private Date contentFileModified = null;
|
||||||
private File metadataFile = null;
|
private Path metadataFile = null;
|
||||||
private long metadataFileSize = -1;
|
private long metadataFileSize = -1;
|
||||||
|
|
||||||
|
|
||||||
public final File getContentFile()
|
public final Path getContentFile()
|
||||||
{
|
{
|
||||||
return(contentFile);
|
return contentFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setContentFile(final File contentFile)
|
public final void setContentFile(final Path contentFile)
|
||||||
{
|
{
|
||||||
this.contentFile = contentFile;
|
this.contentFile = contentFile;
|
||||||
|
|
||||||
if (contentFile != null)
|
if (contentFile != null)
|
||||||
{
|
{
|
||||||
// stat the file, to find out a few key details
|
// stat the file, to find out a few key details
|
||||||
contentFileExists = contentFile.exists();
|
contentFileExists = Files.exists(contentFile, LinkOption.NOFOLLOW_LINKS);
|
||||||
|
|
||||||
if (contentFileExists)
|
if (contentFileExists)
|
||||||
{
|
{
|
||||||
contentFileIsReadable = contentFile.canRead();
|
try
|
||||||
contentFileSize = contentFile.length();
|
{
|
||||||
contentFileModified = new Date(contentFile.lastModified());
|
BasicFileAttributes attrs = Files.readAttributes(contentFile, BasicFileAttributes.class);
|
||||||
contentFileCreated = contentFileModified; //TODO: determine proper file creation time (awaiting JDK 1.7 NIO2 library)
|
|
||||||
|
|
||||||
if (contentFile.isFile())
|
contentFileIsReadable = Files.isReadable(contentFile);
|
||||||
|
contentFileSize = attrs.size();
|
||||||
|
contentFileModified = new Date(attrs.lastModifiedTime().toMillis());
|
||||||
|
contentFileCreated = new Date(attrs.creationTime().toMillis());
|
||||||
|
|
||||||
|
if (Files.isRegularFile(contentFile, LinkOption.NOFOLLOW_LINKS))
|
||||||
{
|
{
|
||||||
contentFileType = FileType.FILE;
|
contentFileType = FileType.FILE;
|
||||||
}
|
}
|
||||||
else if (contentFile.isDirectory())
|
else if (Files.isDirectory(contentFile, LinkOption.NOFOLLOW_LINKS))
|
||||||
{
|
{
|
||||||
contentFileType = FileType.DIRECTORY;
|
contentFileType = FileType.DIRECTORY;
|
||||||
}
|
}
|
||||||
@@ -183,6 +191,10 @@ public final class ImportableItem
|
|||||||
contentFileType = FileType.OTHER;
|
contentFileType = FileType.OTHER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,17 +253,23 @@ public final class ImportableItem
|
|||||||
return(metadataFile != null);
|
return(metadataFile != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final File getMetadataFile()
|
public final Path getMetadataFile()
|
||||||
{
|
{
|
||||||
return(metadataFile);
|
return metadataFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setMetadataFile(final File metadataFile)
|
public final void setMetadataFile(final Path metadataFile)
|
||||||
{
|
{
|
||||||
if (metadataFile != null && metadataFile.exists())
|
if (metadataFile != null && Files.exists(metadataFile))
|
||||||
{
|
{
|
||||||
this.metadataFile = metadataFile;
|
this.metadataFile = metadataFile;
|
||||||
this.metadataFileSize = metadataFile.length();
|
try
|
||||||
|
{
|
||||||
|
this.metadataFileSize = Files.size(metadataFile);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,8 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.bulkimport.impl;
|
package org.alfresco.repo.bulkimport.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
import java.io.FileFilter;
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.alfresco.repo.bulkimport.AnalysedDirectory;
|
import org.alfresco.repo.bulkimport.AnalysedDirectory;
|
||||||
import org.alfresco.repo.bulkimport.DirectoryAnalyser;
|
import org.alfresco.repo.bulkimport.DirectoryAnalyser;
|
||||||
@@ -64,29 +66,29 @@ public abstract class AbstractFilesystemTracker implements FilesystemTracker
|
|||||||
|
|
||||||
protected final AnalysedDirectory getImportableDirectoriesInDirectory(ImportableItem directory, final int count)
|
protected final AnalysedDirectory getImportableDirectoriesInDirectory(ImportableItem directory, final int count)
|
||||||
{
|
{
|
||||||
FileFilter filter = null;
|
DirectoryStream.Filter<Path> filter = null;
|
||||||
|
|
||||||
if(count != -1)
|
if (count != -1)
|
||||||
{
|
{
|
||||||
filter = new FileFilter()
|
filter = new DirectoryStream.Filter<Path>()
|
||||||
{
|
{
|
||||||
private int i = count;
|
private int i = count;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file)
|
public boolean accept(Path entry) throws IOException
|
||||||
{
|
{
|
||||||
return file.isDirectory() && i-- > 0;
|
return Files.isDirectory(entry) && i-- > 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
filter = new FileFilter()
|
filter = new DirectoryStream.Filter<Path>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file)
|
public boolean accept(Path entry) throws IOException
|
||||||
{
|
{
|
||||||
return file.isDirectory();
|
return Files.isDirectory(entry);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.bulkimport.impl;
|
package org.alfresco.repo.bulkimport.impl;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -160,11 +160,11 @@ public abstract class AbstractNodeImporter implements NodeImporter
|
|||||||
importableItem != null &&
|
importableItem != null &&
|
||||||
importableItem.getHeadRevision() != null)
|
importableItem.getHeadRevision() != null)
|
||||||
{
|
{
|
||||||
File metadataFile = importableItem.getHeadRevision().getMetadataFile();
|
Path metadataFile = importableItem.getHeadRevision().getMetadataFile();
|
||||||
|
|
||||||
if (metadataFile != null)
|
if (metadataFile != null)
|
||||||
{
|
{
|
||||||
final String metadataFileName = metadataFile.getName();
|
final String metadataFileName = metadataFile.getFileName().toString();
|
||||||
|
|
||||||
result = metadataFileName.substring(0, metadataFileName.length() -
|
result = metadataFileName.substring(0, metadataFileName.length() -
|
||||||
(MetadataLoader.METADATA_SUFFIX.length() + metadataLoader.getMetadataFileExtension().length()));
|
(MetadataLoader.METADATA_SUFFIX.length() + metadataLoader.getMetadataFileExtension().length()));
|
||||||
@@ -175,7 +175,7 @@ public abstract class AbstractNodeImporter implements NodeImporter
|
|||||||
if (result == null &&
|
if (result == null &&
|
||||||
importableItem != null)
|
importableItem != null)
|
||||||
{
|
{
|
||||||
result = importableItem.getHeadRevision().getContentFile().getName();
|
result = importableItem.getHeadRevision().getContentFile().getFileName().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
@@ -341,12 +341,12 @@ public abstract class AbstractNodeImporter implements NodeImporter
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getFileName(File file)
|
protected String getFileName(Path file)
|
||||||
{
|
{
|
||||||
return FileUtils.getFileName(file);
|
return FileUtils.getFileName(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void importImportableItemMetadata(NodeRef nodeRef, File parentFile, MetadataLoader.Metadata metadata)
|
protected final void importImportableItemMetadata(NodeRef nodeRef, Path parentFile, MetadataLoader.Metadata metadata)
|
||||||
{
|
{
|
||||||
// Attach aspects
|
// Attach aspects
|
||||||
if (metadata.getAspects() != null)
|
if (metadata.getAspects() != null)
|
||||||
@@ -405,9 +405,9 @@ public abstract class AbstractNodeImporter implements NodeImporter
|
|||||||
// Load "standard" metadata from the filesystem
|
// Load "standard" metadata from the filesystem
|
||||||
if (contentAndMetadata != null && contentAndMetadata.contentFileExists())
|
if (contentAndMetadata != null && contentAndMetadata.contentFileExists())
|
||||||
{
|
{
|
||||||
final String filename = contentAndMetadata.getContentFile().getName().trim().replaceFirst(DirectoryAnalyser.VERSION_SUFFIX_REGEX, ""); // Strip off the version suffix (if any)
|
final String filename = contentAndMetadata.getContentFile().getFileName().toString().trim().replaceFirst(DirectoryAnalyser.VERSION_SUFFIX_REGEX, ""); // Strip off the version suffix (if any)
|
||||||
final Date modified = new Date(contentAndMetadata.getContentFile().lastModified());
|
final Date modified = contentAndMetadata.getContentFileModifiedDate();
|
||||||
final Date created = modified; //TODO: determine proper file creation time (awaiting JDK 1.7 NIO2 library)
|
final Date created = contentAndMetadata.getContentFileCreatedDate();
|
||||||
|
|
||||||
result.setType(ImportableItem.FileType.FILE.equals(contentAndMetadata.getContentFileType()) ? ContentModel.TYPE_CONTENT : ContentModel.TYPE_FOLDER);
|
result.setType(ImportableItem.FileType.FILE.equals(contentAndMetadata.getContentFileType()) ? ContentModel.TYPE_CONTENT : ContentModel.TYPE_FOLDER);
|
||||||
result.addProperty(ContentModel.PROP_NAME, filename);
|
result.addProperty(ContentModel.PROP_NAME, filename);
|
||||||
|
@@ -26,9 +26,12 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.bulkimport.impl;
|
package org.alfresco.repo.bulkimport.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.LinkOption;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -37,7 +40,6 @@ import java.util.Map;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.repo.bulkimport.AnalysedDirectory;
|
import org.alfresco.repo.bulkimport.AnalysedDirectory;
|
||||||
import org.alfresco.repo.bulkimport.DirectoryAnalyser;
|
import org.alfresco.repo.bulkimport.DirectoryAnalyser;
|
||||||
import org.alfresco.repo.bulkimport.ImportFilter;
|
import org.alfresco.repo.bulkimport.ImportFilter;
|
||||||
@@ -141,21 +143,12 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.bulkimport.DirectoryAnalyser#analyseDirectory(ImportableItem, FileFilter)
|
* @see org.alfresco.repo.bulkimport.DirectoryAnalyser#analyseDirectory(org.alfresco.repo.bulkimport.ImportableItem, java.nio.file.DirectoryStream.Filter)
|
||||||
*/
|
*/
|
||||||
public AnalysedDirectory analyseDirectory(ImportableItem directory, FileFilter filter)
|
public AnalysedDirectory analyseDirectory(ImportableItem directory, DirectoryStream.Filter<Path> filter)
|
||||||
{
|
{
|
||||||
File directoryFile = directory.getHeadRevision().getContentFile();
|
Path directoryFile = directory.getHeadRevision().getContentFile();
|
||||||
AnalysedDirectory result = null;
|
AnalysedDirectory result = new AnalysedDirectory(listFiles(directoryFile, filter));
|
||||||
|
|
||||||
if(filter == null)
|
|
||||||
{
|
|
||||||
result = new AnalysedDirectory(directoryFile.listFiles());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = new AnalysedDirectory(directoryFile.listFiles(filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (log.isDebugEnabled())
|
if (log.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -163,18 +156,18 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build up the list of ImportableItems from the directory listing
|
// Build up the list of ImportableItems from the directory listing
|
||||||
for (File file : result.getOriginalListing())
|
for (Path file : result.getOriginalPaths())
|
||||||
{
|
{
|
||||||
// MNT-9763 bulkimport fails when there is a very large LastModified timestamp.
|
// MNT-9763 bulkimport fails when there is a very large LastModified timestamp.
|
||||||
String isoDate = null;
|
String isoDate = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
isoDate = ISO8601DateFormat.format(new Date(file.lastModified()));
|
isoDate = ISO8601DateFormat.format(new Date(Files.getLastModifiedTime(file, LinkOption.NOFOLLOW_LINKS).toMillis()));
|
||||||
ISO8601DateFormat.parse(isoDate);
|
ISO8601DateFormat.parse(isoDate);
|
||||||
}
|
}
|
||||||
catch (PlatformRuntimeException e)
|
catch (PlatformRuntimeException | IOException e)
|
||||||
{
|
{
|
||||||
log.warn("Failed to convert date " + isoDate + " to string for " + file.getName(), e);
|
log.warn("Failed to convert date " + isoDate + " to string for " + file.getFileName(), e);
|
||||||
importStatus.incrementNumberOfUnreadableEntries();
|
importStatus.incrementNumberOfUnreadableEntries();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -184,11 +177,11 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
log.trace("Scanning file " + FileUtils.getFileName(file) + "...");
|
log.trace("Scanning file " + FileUtils.getFileName(file) + "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.canRead())
|
if (Files.isReadable(file))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nameChecker.evaluate(file.getName());
|
nameChecker.evaluate(file.getFileName().toString());
|
||||||
}
|
}
|
||||||
catch (ConstraintException e)
|
catch (ConstraintException e)
|
||||||
{
|
{
|
||||||
@@ -270,6 +263,23 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Path> listFiles(Path sourceDirectory, DirectoryStream.Filter<Path> filter)
|
||||||
|
{
|
||||||
|
List<Path> files = new ArrayList<Path>();
|
||||||
|
try (DirectoryStream<Path> paths = (filter != null) ? Files.newDirectoryStream(sourceDirectory, filter) : Files.newDirectoryStream(sourceDirectory))
|
||||||
|
{
|
||||||
|
for (Iterator<Path> it = paths.iterator(); it.hasNext();)
|
||||||
|
{
|
||||||
|
files.add(it.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isMetadataValid(ImportableItem importableItem)
|
private boolean isMetadataValid(ImportableItem importableItem)
|
||||||
{
|
{
|
||||||
if (!importableItem.getHeadRevision().metadataFileExists())
|
if (!importableItem.getHeadRevision().metadataFileExists())
|
||||||
@@ -315,29 +325,30 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isVersionFile(File file)
|
private boolean isVersionFile(Path file)
|
||||||
{
|
{
|
||||||
Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(file.getName());
|
Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(file.getFileName().toString());
|
||||||
|
|
||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isMetadataFile(File file)
|
private boolean isMetadataFile(Path file)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
if (metadataLoader != null)
|
if (metadataLoader != null)
|
||||||
{
|
{
|
||||||
result = file.getName().endsWith(MetadataLoader.METADATA_SUFFIX + metadataLoader.getMetadataFileExtension());
|
String name = file.getFileName().toString();
|
||||||
|
result = name.endsWith(MetadataLoader.METADATA_SUFFIX + metadataLoader.getMetadataFileExtension());
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVersionFile(ImportableItem parent, AnalysedDirectory analysedDirectory, File versionFile)
|
private void addVersionFile(ImportableItem parent, AnalysedDirectory analysedDirectory, Path versionFile)
|
||||||
{
|
{
|
||||||
File parentContentFile = getParentOfVersionFile(versionFile);
|
Path parentContentFile = getParentOfVersionFile(versionFile);
|
||||||
boolean isContentVersion = false;
|
boolean isContentVersion = false;
|
||||||
|
|
||||||
if (isMetadataFile(parentContentFile))
|
if (isMetadataFile(parentContentFile))
|
||||||
@@ -365,9 +376,9 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addMetadataFile(ImportableItem parent, AnalysedDirectory analysedDirectory, File metadataFile)
|
private void addMetadataFile(ImportableItem parent, AnalysedDirectory analysedDirectory, Path metadataFile)
|
||||||
{
|
{
|
||||||
File parentContentfile = getParentOfMetadatafile(metadataFile);
|
Path parentContentfile = getParentOfMetadatafile(metadataFile);
|
||||||
|
|
||||||
ImportableItem importableItem = findOrCreateImportableItem(parent, analysedDirectory, parentContentfile);
|
ImportableItem importableItem = findOrCreateImportableItem(parent, analysedDirectory, parentContentfile);
|
||||||
|
|
||||||
@@ -375,7 +386,7 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean addParentFile(ImportableItem parent, AnalysedDirectory analysedDirectory, File contentFile)
|
private boolean addParentFile(ImportableItem parent, AnalysedDirectory analysedDirectory, Path contentFile)
|
||||||
{
|
{
|
||||||
ImportableItem importableItem = findOrCreateImportableItem(parent, analysedDirectory, contentFile);
|
ImportableItem importableItem = findOrCreateImportableItem(parent, analysedDirectory, contentFile);
|
||||||
|
|
||||||
@@ -384,7 +395,7 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
return(importableItem.getHeadRevision().getContentFileType() == FileType.DIRECTORY);
|
return(importableItem.getHeadRevision().getContentFileType() == FileType.DIRECTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImportableItem findOrCreateImportableItem(ImportableItem parent, AnalysedDirectory analysedDirectory, File contentFile)
|
private ImportableItem findOrCreateImportableItem(ImportableItem parent, AnalysedDirectory analysedDirectory, Path contentFile)
|
||||||
{
|
{
|
||||||
ImportableItem result = findImportableItem(analysedDirectory, contentFile);
|
ImportableItem result = findImportableItem(analysedDirectory, contentFile);
|
||||||
|
|
||||||
@@ -404,7 +415,7 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ImportableItem findImportableItem(AnalysedDirectory analysedDirectory, File contentFile)
|
private ImportableItem findImportableItem(AnalysedDirectory analysedDirectory, Path contentFile)
|
||||||
{
|
{
|
||||||
ImportableItem result = null;
|
ImportableItem result = null;
|
||||||
|
|
||||||
@@ -454,7 +465,7 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int getVersionNumber(File versionFile)
|
private int getVersionNumber(Path versionFile)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
@@ -463,7 +474,7 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
throw new IllegalStateException(FileUtils.getFileName(versionFile) + " is not a version file.");
|
throw new IllegalStateException(FileUtils.getFileName(versionFile) + " is not a version file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(versionFile.getName());
|
Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(versionFile.getFileName().toString());
|
||||||
String versionStr = null;
|
String versionStr = null;
|
||||||
|
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
@@ -481,36 +492,36 @@ public class DirectoryAnalyserImpl implements DirectoryAnalyser
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File getParentOfVersionFile(File versionFile)
|
private Path getParentOfVersionFile(Path versionFile)
|
||||||
{
|
{
|
||||||
File result = null;
|
Path result = null;
|
||||||
|
|
||||||
if (!isVersionFile(versionFile))
|
if (!isVersionFile(versionFile))
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(FileUtils.getFileName(versionFile) + " is not a version file.");
|
throw new IllegalStateException(FileUtils.getFileName(versionFile) + " is not a version file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String parentFilename = versionFile.getName().replaceFirst(VERSION_SUFFIX_REGEX, "");
|
String parentFilename = versionFile.getFileName().toString().replaceFirst(VERSION_SUFFIX_REGEX, "");
|
||||||
|
|
||||||
result = new File(versionFile.getParent(), parentFilename);
|
result = versionFile.getParent().resolve(parentFilename);
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File getParentOfMetadatafile(File metadataFile)
|
private Path getParentOfMetadatafile(Path metadataFile)
|
||||||
{
|
{
|
||||||
File result = null;
|
Path result = null;
|
||||||
|
|
||||||
if (!isMetadataFile(metadataFile))
|
if (!isMetadataFile(metadataFile))
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(FileUtils.getFileName(metadataFile) + " is not a metadata file.");
|
throw new IllegalStateException(FileUtils.getFileName(metadataFile) + " is not a metadata file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = metadataFile.getName();
|
String name = metadataFile.getFileName().toString();
|
||||||
String contentName = name.substring(0, name.length() - (MetadataLoader.METADATA_SUFFIX + metadataLoader.getMetadataFileExtension()).length());
|
String contentName = name.substring(0, name.length() - (MetadataLoader.METADATA_SUFFIX + metadataLoader.getMetadataFileExtension()).length());
|
||||||
|
|
||||||
result = new File(metadataFile.getParent(), contentName);
|
result = metadataFile.getParent().resolve(contentName);
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@ package org.alfresco.repo.bulkimport.impl;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.LinkOption;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -54,4 +56,23 @@ public class FileUtils
|
|||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFileName(final Path path)
|
||||||
|
{
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
if (path != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = path.toRealPath(LinkOption.NOFOLLOW_LINKS).toString();
|
||||||
|
}
|
||||||
|
catch (final IOException ioe)
|
||||||
|
{
|
||||||
|
result = path.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,12 +26,15 @@
|
|||||||
package org.alfresco.repo.bulkimport.impl;
|
package org.alfresco.repo.bulkimport.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.repo.bulkimport.ImportableItem;
|
import org.alfresco.repo.bulkimport.ImportableItem;
|
||||||
import org.alfresco.repo.bulkimport.MetadataLoader;
|
import org.alfresco.repo.bulkimport.MetadataLoader;
|
||||||
import org.alfresco.repo.bulkimport.NodeImporter;
|
import org.alfresco.repo.bulkimport.NodeImporter;
|
||||||
import org.alfresco.repo.bulkimport.impl.BulkImportStatusImpl.NodeState;
|
import org.alfresco.repo.bulkimport.impl.BulkImportStatusImpl.NodeState;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.util.Triple;
|
import org.alfresco.util.Triple;
|
||||||
@@ -85,7 +88,17 @@ public class StreamingNodeImporterFactory extends AbstractNodeImporterFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContentWriter writer = fileFolderService.getWriter(nodeRef);
|
ContentWriter writer = fileFolderService.getWriter(nodeRef);
|
||||||
writer.putContent(contentAndMetadata.getContentFile());
|
try
|
||||||
|
{
|
||||||
|
writer.putContent(Files.newInputStream(contentAndMetadata.getContentFile()));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
throw new ContentIOException("Failed to copy content from file: \n" +
|
||||||
|
" writer: " + writer + "\n" +
|
||||||
|
" file: " + contentAndMetadata.getContentFile(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -62,7 +62,7 @@ public class StripingFilesystemTracker extends AbstractFilesystemTracker
|
|||||||
|
|
||||||
// not really an importable item but the interface requires it to be in this form
|
// not really an importable item but the interface requires it to be in this form
|
||||||
rootFolder = new ImportableItem();
|
rootFolder = new ImportableItem();
|
||||||
rootFolder.getHeadRevision().setContentFile(sourceFolder);
|
rootFolder.getHeadRevision().setContentFile(sourceFolder.toPath());
|
||||||
rootFolder.setNodeRef(target);
|
rootFolder.setNodeRef(target);
|
||||||
|
|
||||||
addDirectoryToProcess(rootFolder, currentLevel);
|
addDirectoryToProcess(rootFolder, currentLevel);
|
||||||
|
@@ -58,7 +58,7 @@ public class FileNameRegexImportFilter implements ImportFilter
|
|||||||
*/
|
*/
|
||||||
public boolean shouldFilter(final ImportableItem importableItem)
|
public boolean shouldFilter(final ImportableItem importableItem)
|
||||||
{
|
{
|
||||||
return(pattern.matcher(importableItem.getHeadRevision().getContentFile().getName()).matches());
|
return pattern.matcher(importableItem.getHeadRevision().getContentFile().getFileName().toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.bulkimport.importfilters;
|
package org.alfresco.repo.bulkimport.importfilters;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.alfresco.repo.bulkimport.ImportFilter;
|
import org.alfresco.repo.bulkimport.ImportFilter;
|
||||||
import org.alfresco.repo.bulkimport.ImportableItem;
|
import org.alfresco.repo.bulkimport.ImportableItem;
|
||||||
|
|
||||||
@@ -49,7 +53,14 @@ public class HiddenFileFilter implements ImportFilter
|
|||||||
|
|
||||||
if (importableItem.getHeadRevision().contentFileExists())
|
if (importableItem.getHeadRevision().contentFileExists())
|
||||||
{
|
{
|
||||||
result = importableItem.getHeadRevision().getContentFile().isHidden();
|
Path file = importableItem.getHeadRevision().getContentFile();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = Files.isHidden(file);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
|
@@ -25,8 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.bulkimport.metadataloaders;
|
package org.alfresco.repo.bulkimport.metadataloaders;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -98,7 +99,7 @@ abstract class AbstractMapBasedMetadataLoader implements MetadataLoader
|
|||||||
* @param metadataFile The file to load the properties from <i>(must not be null)</i>.
|
* @param metadataFile The file to load the properties from <i>(must not be null)</i>.
|
||||||
* @return A new <code>Properties</code> object loaded from that file.
|
* @return A new <code>Properties</code> object loaded from that file.
|
||||||
*/
|
*/
|
||||||
abstract protected Map<String,Serializable> loadMetadataFromFile(final File metadataFile);
|
abstract protected Map<String,Serializable> loadMetadataFromFile(final Path metadataFile);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,9 +107,9 @@ abstract class AbstractMapBasedMetadataLoader implements MetadataLoader
|
|||||||
{
|
{
|
||||||
if (contentAndMetadata.metadataFileExists())
|
if (contentAndMetadata.metadataFileExists())
|
||||||
{
|
{
|
||||||
final File metadataFile = contentAndMetadata.getMetadataFile();
|
final Path metadataFile = contentAndMetadata.getMetadataFile();
|
||||||
|
|
||||||
if (metadataFile.canRead())
|
if (Files.isReadable(metadataFile))
|
||||||
{
|
{
|
||||||
Map<String,Serializable> metadataProperties = loadMetadataFromFile(metadataFile);
|
Map<String,Serializable> metadataProperties = loadMetadataFromFile(metadataFile);
|
||||||
|
|
||||||
|
@@ -26,10 +26,10 @@
|
|||||||
package org.alfresco.repo.bulkimport.metadataloaders;
|
package org.alfresco.repo.bulkimport.metadataloaders;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -110,14 +110,14 @@ extends AbstractMapBasedMetadataLoader
|
|||||||
* @see org.alfresco.repo.bulkimport.metadataloaders.AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
|
* @see org.alfresco.repo.bulkimport.metadataloaders.AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Map<String,Serializable> loadMetadataFromFile(File metadataFile)
|
protected Map<String,Serializable> loadMetadataFromFile(Path metadataFile)
|
||||||
{
|
{
|
||||||
Map<String,Serializable> result = null;
|
Map<String,Serializable> result = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.load(new BufferedInputStream(new FileInputStream(metadataFile)));
|
props.load(new BufferedInputStream(Files.newInputStream(metadataFile)));
|
||||||
result = new HashMap<String,Serializable>((Map)props);
|
result = new HashMap<String,Serializable>((Map)props);
|
||||||
}
|
}
|
||||||
catch (final IOException ioe)
|
catch (final IOException ioe)
|
||||||
|
@@ -28,10 +28,10 @@ package org.alfresco.repo.bulkimport.metadataloaders;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -112,14 +112,14 @@ public final class XmlPropertiesFileMetadataLoader extends AbstractMapBasedMetad
|
|||||||
* @see AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
|
* @see AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Map<String,Serializable> loadMetadataFromFile(File metadataFile)
|
protected Map<String,Serializable> loadMetadataFromFile(Path metadataFile)
|
||||||
{
|
{
|
||||||
Map<String,Serializable> result = null;
|
Map<String,Serializable> result = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.loadFromXML(new BufferedInputStream(new FileInputStream(metadataFile)));
|
props.loadFromXML(new BufferedInputStream(Files.newInputStream(metadataFile)));
|
||||||
result = new HashMap<String,Serializable>((Map)props);
|
result = new HashMap<String,Serializable>((Map)props);
|
||||||
}
|
}
|
||||||
catch (final IOException ioe)
|
catch (final IOException ioe)
|
||||||
|
@@ -30,10 +30,18 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import javax.transaction.NotSupportedException;
|
import javax.transaction.NotSupportedException;
|
||||||
import javax.transaction.SystemException;
|
import javax.transaction.SystemException;
|
||||||
@@ -54,7 +62,6 @@ import org.alfresco.service.cmr.rule.Rule;
|
|||||||
import org.alfresco.service.cmr.rule.RuleType;
|
import org.alfresco.service.cmr.rule.RuleType;
|
||||||
import org.alfresco.service.cmr.version.Version;
|
import org.alfresco.service.cmr.version.Version;
|
||||||
import org.alfresco.service.cmr.version.VersionHistory;
|
import org.alfresco.service.cmr.version.VersionHistory;
|
||||||
import org.alfresco.test_category.BaseSpringTestsCategory;
|
|
||||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@@ -608,4 +615,72 @@ public class BulkImportTest extends AbstractBulkImportTests
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MNT-15367: Unable to bulk import filenames with Portuguese characters in a Linux environment
|
||||||
|
*
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testImportFilesWithSpecialCharacters() throws Throwable
|
||||||
|
{
|
||||||
|
NodeRef folderNode = topLevelFolder.getNodeRef();
|
||||||
|
NodeImporter nodeImporter = null;
|
||||||
|
|
||||||
|
File source = ResourceUtils.getFile("classpath:bulkimport4");
|
||||||
|
|
||||||
|
String fileName = new String("135 CarbonÔÇô13 NMR spectroscopy_DS_NS_final_cau.txt".getBytes("ISO-8859-1"), "UTF-8");
|
||||||
|
Path dest = source.toPath().resolve("encoding");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dest = Files.createDirectory(dest);
|
||||||
|
}
|
||||||
|
catch (FileAlreadyExistsException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Path destFile = dest.resolve(fileName);
|
||||||
|
|
||||||
|
unpack(source.toPath(), destFile);
|
||||||
|
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
nodeImporter = streamingNodeImporterFactory.getNodeImporter(ResourceUtils.getFile("classpath:bulkimport4/encoding"));
|
||||||
|
|
||||||
|
BulkImportParameters bulkImportParameters = new BulkImportParameters();
|
||||||
|
bulkImportParameters.setTarget(folderNode);
|
||||||
|
bulkImportParameters.setReplaceExisting(true);
|
||||||
|
bulkImportParameters.setDisableRulesService(true);
|
||||||
|
bulkImportParameters.setBatchSize(40);
|
||||||
|
bulkImporter.bulkImport(bulkImportParameters, nodeImporter);
|
||||||
|
|
||||||
|
assertEquals("", 1, bulkImporter.getStatus().getNumberOfContentNodesCreated());
|
||||||
|
|
||||||
|
checkFiles(folderNode, null, 0, 1,
|
||||||
|
new ExpectedFile[] { new ExpectedFile(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN)},
|
||||||
|
null);
|
||||||
|
|
||||||
|
Files.deleteIfExists(destFile);
|
||||||
|
Files.deleteIfExists(dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unpack(Path source, Path destFile)
|
||||||
|
{
|
||||||
|
Path archive = source.resolve("testbulk.gz");
|
||||||
|
|
||||||
|
try (GZIPInputStream gzis = new GZIPInputStream(Files.newInputStream(archive));
|
||||||
|
OutputStream out = Files.newOutputStream(destFile, StandardOpenOption.CREATE))
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = gzis.read(buffer)) > 0)
|
||||||
|
{
|
||||||
|
out.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BIN
source/test-resources/bulkimport4/testbulk.gz
Normal file
BIN
source/test-resources/bulkimport4/testbulk.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user