Skip to content
Snippets Groups Projects
Commit 25221c02 authored by juanf's avatar juanf
Browse files

SSDM-2904 : Support creation of datasets with auto-generated codes (Working prototype)

SVN: 35336
parent 1570004a
No related branches found
No related tags found
No related merge requests found
......@@ -95,22 +95,10 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
@Autowired
private IVerifyDataSetExecutor verifyDataSetExecutor;
@Override
protected void checkData(IOperationContext context, DataSetCreation creation)
{
if (creation.getTypeId() == null)
{
throw new UserFailureException("Type id cannot be null.");
}
if (creation.getExperimentId() == null && creation.getSampleId() == null)
{
throw new UserFailureException("Experiment id and sample id cannot be both null.");
}
}
@Override
protected List<DataPE> createEntities(IOperationContext context, Collection<DataSetCreation> creations)
{
// Get Types
Collection<IEntityTypeId> typeIds = new HashSet<IEntityTypeId>();
for (DataSetCreation creation : creations)
......@@ -119,6 +107,13 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
}
Map<IEntityTypeId, EntityTypePE> types = mapEntityTypeByIdExecutor.map(context, EntityKind.DATA_SET, typeIds);
// Validate DataSet creations
for (DataSetCreation creation : creations)
{
checkData(context, creation, types.get(creation.getTypeId()));
}
IPermIdDAO codeGenerator = daoFactory.getPermIdDAO();
List<DataPE> dataSets = new LinkedList<DataPE>();
......@@ -126,14 +121,8 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
{
DataSetTypePE type = (DataSetTypePE) types.get(creation.getTypeId());
if (type == null)
{
throw new ObjectNotFoundException(creation.getTypeId());
} else if(StringUtils.isEmpty(creation.getCode()) && false == creation.isAutoGeneratedCode()) {
throw new UserFailureException("Code cannot be empty for a non auto generated code.");
} else if(false == StringUtils.isEmpty(creation.getCode()) && creation.isAutoGeneratedCode()) {
throw new UserFailureException("Code should be empty when auto generated code is selected.");
} else if(creation.getCode() == null) {
//Create code if is not present
if(StringUtils.isEmpty(creation.getCode())) {
creation.setCode(codeGenerator.createPermId());
}
......@@ -166,6 +155,31 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC
return dataSets;
}
private void checkData(IOperationContext context, DataSetCreation creation, EntityTypePE type)
{
if (type == null)
{
throw new ObjectNotFoundException(creation.getTypeId());
} else if(StringUtils.isEmpty(creation.getCode()) && false == creation.isAutoGeneratedCode()) {
throw new UserFailureException("Code cannot be empty for a non auto generated code.");
} else if(false == StringUtils.isEmpty(creation.getCode()) && creation.isAutoGeneratedCode()) {
throw new UserFailureException("Code should be empty when auto generated code is selected.");
}
}
@Override
protected void checkData(IOperationContext context, DataSetCreation creation)
{
if (creation.getTypeId() == null)
{
throw new UserFailureException("Type id cannot be null.");
}
if (creation.getExperimentId() == null && creation.getSampleId() == null)
{
throw new UserFailureException("Experiment id and sample id cannot be both null.");
}
}
@Override
protected DataSetPermId createPermId(IOperationContext context, DataPE entity)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment