diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index 1b0a116117276f9a8a7033d3a354dba47c7dada7..4dbcb551fd68c70348f0f0709fef826ac9c58a17 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -1262,14 +1262,8 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt updateEntityType(sessionToken, EntityKind.DATA_SET, entityType); } - private void updateEntityType(String sessionToken, EntityKind entityKind, EntityType entityType) + private void setValidationScript(EntityTypePE entityTypePE, EntityType entityType) { - checkSession(sessionToken); - IEntityTypeDAO entityTypeDAO = - getDAOFactory().getEntityTypeDAO(DtoConverters.convertEntityKind(entityKind)); - EntityTypePE entityTypePE = entityTypeDAO.tryToFindEntityTypeByCode(entityType.getCode()); - - entityTypePE.setDescription(entityType.getDescription()); if (entityType.getValidationScript() == null || entityType.getValidationScript().getName() == null || entityType.getValidationScript().getName().equals("")) @@ -1277,13 +1271,26 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt entityTypePE.setValidationScript(null); } else { - ScriptPE script = getDAOFactory().getScriptDAO() - .tryFindByName(entityType.getValidationScript().getName()); + ScriptPE script = + getDAOFactory().getScriptDAO().tryFindByName( + entityType.getValidationScript().getName()); if (script != null) { entityTypePE.setValidationScript(script); } } + } + + private void updateEntityType(String sessionToken, EntityKind entityKind, EntityType entityType) + { + checkSession(sessionToken); + IEntityTypeDAO entityTypeDAO = + getDAOFactory().getEntityTypeDAO(DtoConverters.convertEntityKind(entityKind)); + EntityTypePE entityTypePE = entityTypeDAO.tryToFindEntityTypeByCode(entityType.getCode()); + + entityTypePE.setDescription(entityType.getDescription()); + + setValidationScript(entityTypePE, entityType); updateSpecificEntityTypeProperties(entityKind, entityTypePE, entityType); entityTypeDAO.createOrUpdateEntityType(entityTypePE); @@ -1305,20 +1312,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt sampleTypePE .setGeneratedFromHierarchyDepth(sampleType.getGeneratedFromHierarchyDepth()); - if (sampleType.getValidationScript() == null - || sampleType.getValidationScript().getName() == null - || sampleType.getValidationScript().getName().equals("")) - { - sampleTypePE.setValidationScript(null); - } else - { - ScriptPE script = getDAOFactory().getScriptDAO() - .tryFindByName(sampleType.getValidationScript().getName()); - if (script != null) - { - sampleTypePE.setValidationScript(script); - } - } + setValidationScript(entityTypePE, entityType); } else if (entityKind == EntityKind.DATA_SET) { @@ -1330,20 +1324,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt EntityTypeBO.assertValidDataSetTypeMainPattern(mainDataSetPattern); dataSetTypePE.setMainDataSetPattern(mainDataSetPattern); - if (dataSetType.getValidationScript() == null - || dataSetType.getValidationScript().getName() == null - || dataSetType.getValidationScript().getName().equals("")) - { - dataSetTypePE.setValidationScript(null); - } else - { - ScriptPE script = getDAOFactory().getScriptDAO() - .tryFindByName(dataSetType.getValidationScript().getName()); - if (script != null) - { - dataSetTypePE.setValidationScript(script); - } - } + setValidationScript(entityTypePE, entityType); } }