diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetService.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetService.java index 8bd0b279faae8c11c174584a31200a3f803cb62c..757582998b6e15116b6c1b57d3e6e847c95213dc 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetService.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetService.java @@ -274,26 +274,12 @@ public class PutDataSetService implements IPutDataSetService doInitialization(); } - if (StringUtils.isBlank(sessionToken)) - { - throw new UserFailureException("Session token cannot be null or empty"); - } - if (sessionToken.contains("/")) - { - throw new UserFailureException("Session token must not contain '/'"); - } + validateSessionToken(sessionToken); + validateUploadId(uploadId); if (newDataSet == null) { throw new UserFailureException("New data set cannot be null"); } - if (StringUtils.isBlank(uploadId)) - { - throw new UserFailureException("Upload id cannot be null or empty"); - } - if (uploadId.contains("/")) - { - throw new UserFailureException("Upload id must not contain '/'"); - } ServiceProvider.getOpenBISService().checkSession(sessionToken); @@ -346,14 +332,8 @@ public class PutDataSetService implements IPutDataSetService try { - if (StringUtils.isBlank(sessionToken)) - { - throw new UserFailureException("Session token cannot be null or empty"); - } - if (sessionToken.contains("/")) - { - throw new UserFailureException("Session token must not contain '/'"); - } + validateSessionToken(sessionToken); + validateUploadId(uploadId); if (StringUtils.isBlank(filePath)) { throw new UserFailureException("File path cannot be null or empty"); @@ -370,14 +350,6 @@ public class PutDataSetService implements IPutDataSetService { throw new UserFailureException("Data set type cannot be null or empty"); } - if (StringUtils.isBlank(uploadId)) - { - throw new UserFailureException("Upload id cannot be null or empty"); - } - if (uploadId.contains("/")) - { - throw new UserFailureException("Upload id must not contain '/'"); - } if (inputStream == null) { throw new UserFailureException("Input stream cannot be null"); @@ -613,14 +585,7 @@ public class PutDataSetService implements IPutDataSetService doInitialization(); } - if (StringUtils.isBlank(sessionToken)) - { - throw new IllegalArgumentException("Session token cannot be null or empty"); - } - if (sessionToken.contains("/")) - { - throw new UserFailureException("Session token must not contain '/'"); - } + validateSessionToken(sessionToken); Collection<TopLevelDataSetRegistratorGlobalState> states = getThreadGlobalStates(); @@ -646,6 +611,28 @@ public class PutDataSetService implements IPutDataSetService } } + private void validateSessionToken(String sessionToken) + { + validate(sessionToken, "Session token"); + } + + private void validateUploadId(String uploadId) + { + validate(uploadId, "Upload id"); + } + + private void validate(String uploadId, String name) + { + if (StringUtils.isBlank(uploadId)) + { + throw new UserFailureException(name + " cannot be null or empty"); + } + if (uploadId.contains("/")) + { + throw new UserFailureException(name + " must not contain '/'"); + } + } + } /**