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:
Alan Davis
2016-08-04 15:53:11 +00:00
parent d59b9e3b1d
commit 268e8eb9e1
16 changed files with 446 additions and 295 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
* #%L
* Alfresco Repository
* %%
@@ -15,14 +15,14 @@
* (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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
* 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.bulkimport.impl;
import static org.junit.Assert.assertEquals;
@@ -30,10 +30,18 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
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.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import javax.transaction.NotSupportedException;
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.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -607,5 +614,73 @@ public class BulkImportTest extends AbstractBulkImportTests
assertEquals("This is version 1 of fileWithVersions.txt.", contentReader.getContentString());
}
/**
* 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();
}
}
}