diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java index ac26dc4a7bf15576330e04d48b049f4d0c0164e0..4d12959e56a12651f26dec52ad4073ba44ec258a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/BasicConstant.java @@ -23,6 +23,9 @@ package ch.systemsx.cisd.openbis.generic.shared.basic; */ public class BasicConstant { + /** default encoding used for strings - UTF-8 */ + public static final String UTF_ENCODING = "UTF-8"; + /** Maximum length of a file name for uploading data sets to CIFEX. */ public static final int MAX_LENGTH_OF_FILE_NAME = 250; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/parser/SampleUploadSectionsParser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/parser/SampleUploadSectionsParser.java index 47c649d5a6ecdd149c88acb7e969d05ebbcd9bc7..39828304027871c992a024d53e4d3e19da4da0e0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/parser/SampleUploadSectionsParser.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/parser/SampleUploadSectionsParser.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.generic.shared.parser; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -32,6 +33,7 @@ import ch.systemsx.cisd.common.parser.IParserObjectFactory; import ch.systemsx.cisd.common.parser.IParserObjectFactoryFactory; import ch.systemsx.cisd.common.parser.IPropertyMapper; import ch.systemsx.cisd.common.parser.ParserException; +import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BatchOperationKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BatchRegistrationResult; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; @@ -93,26 +95,33 @@ public class SampleUploadSectionsParser { final List<NewSamplesWithTypes> newSamples = new ArrayList<NewSamplesWithTypes>(); boolean isAutoGenerateCodes = (sampleCodeGeneratorOrNull != null); - final List<BatchRegistrationResult> results = - loadSamplesFromFiles(files, sampleType, isAutoGenerateCodes, newSamples, - allowExperiments, operationKind); - if (defaultGroupIdentifier != null) + try { - switch (operationKind) + final List<BatchRegistrationResult> results = + loadSamplesFromFiles(files, sampleType, isAutoGenerateCodes, newSamples, + allowExperiments, operationKind); + + if (defaultGroupIdentifier != null) { - case REGISTRATION: - if (isAutoGenerateCodes) - { - generateIdentifiers(defaultGroupIdentifier, sampleCodeGeneratorOrNull, - isAutoGenerateCodes, newSamples); - } - break; - case UPDATE: - fillIdentifiers(defaultGroupIdentifier, newSamples); - break; + switch (operationKind) + { + case REGISTRATION: + if (isAutoGenerateCodes) + { + generateIdentifiers(defaultGroupIdentifier, sampleCodeGeneratorOrNull, + isAutoGenerateCodes, newSamples); + } + break; + case UPDATE: + fillIdentifiers(defaultGroupIdentifier, newSamples); + break; + } } + return new BatchSamplesOperation(newSamples, results, parseCodes(newSamples)); + } catch (UnsupportedEncodingException ex) + { + throw new UserFailureException(ex.getMessage()); } - return new BatchSamplesOperation(newSamples, results, parseCodes(newSamples)); } private static String[] parseCodes(final List<NewSamplesWithTypes> newSamples) @@ -245,6 +254,7 @@ public class SampleUploadSectionsParser Collection<NamedInputStream> uploadedFiles, SampleType sampleType, boolean isAutoGenerateCodes, final List<NewSamplesWithTypes> newSamples, boolean allowExperiments, BatchOperationKind operationKind) + throws UnsupportedEncodingException { final List<BatchRegistrationResult> results = new ArrayList<BatchRegistrationResult>(uploadedFiles.size()); @@ -256,8 +266,8 @@ public class SampleUploadSectionsParser sampleSections.addAll(extractSections(multipartFile.getInputStream())); } else { - sampleSections.add(new FileSection(new String(multipartFile.getBytes()), sampleType - .getCode())); + sampleSections.add(new FileSection(new String(multipartFile.getBytes(), + BasicConstant.UTF_ENCODING), sampleType.getCode())); } int sampleCounter = 0; for (FileSection fs : sampleSections)