diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/CreateSampleExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/CreateSampleExecutor.java index 06e2140153b257d4ada3b6398d0b557ec283ff45..668a8536f17eb5344cccd1b89dd9544dd8f3ee27 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/CreateSampleExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/CreateSampleExecutor.java @@ -36,6 +36,7 @@ import ch.ethz.sis.openbis.generic.as.api.v3.dto.sample.create.SampleCreation; import ch.ethz.sis.openbis.generic.as.api.v3.dto.sample.id.SampleIdentifier; import ch.ethz.sis.openbis.generic.as.api.v3.dto.sample.id.SamplePermId; import ch.ethz.sis.openbis.generic.as.api.v3.dto.tag.id.ITagId; +import ch.ethz.sis.openbis.generic.as.api.v3.exceptions.ObjectNotFoundException; import ch.ethz.sis.openbis.generic.as.api.v3.exceptions.UnauthorizedObjectAccessException; import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; import ch.ethz.sis.openbis.generic.server.api.v3.executor.attachment.ICreateAttachmentExecutor; @@ -141,7 +142,11 @@ public class CreateSampleExecutor extends AbstractCreateEntityExecutor<SampleCre private void checkData(IOperationContext context, SampleCreation creation, SampleTypePE type) { - if(false == StringUtils.isEmpty(creation.getCode()) && (type.isAutoGeneratedCode() || creation.isAutoGeneratedCode())) { + if(creation.getTypeId() == null) { + throw new UserFailureException("Type id cannot be null."); + } else if(type == null) { + throw new ObjectNotFoundException(creation.getTypeId()); + } else if (false == StringUtils.isEmpty(creation.getCode()) && (type.isAutoGeneratedCode() || creation.isAutoGeneratedCode())) { throw new UserFailureException("Code should be empty when auto generated code is selected."); } else if(StringUtils.isEmpty(creation.getCode()) && false == type.isAutoGeneratedCode() && false == creation.isAutoGeneratedCode()) { throw new UserFailureException("Code cannot be empty for a non auto generated code.");