From: rkv Date: Fri, 30 Nov 2012 13:22:42 +0000 (+0000) Subject: Hibernate config changed to generate db in release mode also. User creation is fixed... X-Git-Tag: Root_Delivery1_2012_12_06~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=86a08afc3583db279ce4a0411e445b919a84f630;p=tools%2Fsiman.git Hibernate config changed to generate db in release mode also. User creation is fixed. Study creation is fixed. --- diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml index ffa5d73..3273b27 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml @@ -19,7 +19,7 @@ + update="false" unique="true" cascade="merge,save-update" access="field" /> diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 70714a6..0303a5f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -19,8 +19,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; import org.splat.common.properties.MessageKeyEnum; import org.splat.dal.bo.kernel.Relation; +import org.splat.dal.bo.kernel.Role; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ConvertsRelation; import org.splat.dal.bo.som.Document; @@ -35,6 +38,7 @@ import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; +import org.splat.dal.dao.kernel.RoleDAO; import org.splat.dal.dao.kernel.UserDAO; import org.splat.dal.dao.som.KnowledgeElementDAO; import org.splat.dal.dao.som.KnowledgeElementTypeDAO; @@ -117,6 +121,11 @@ public class ScenarioServiceImpl implements ScenarioService { */ private UserDAO _userDAO; + /** + * Injected role DAO. + */ + private RoleDAO _roleDAO; + /** * Injected knowledge element type DAO. */ @@ -784,7 +793,13 @@ public class ScenarioServiceImpl implements ScenarioService { KnowledgeElementType ucase = getKnowledgeElementTypeService() .selectType("usecase"); KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); - User admin = getUserService().selectUser(1); // First user created when creating the database + // TODO: Get appropriate user by its role: UserService.getAdmin(); + // User admin = getUserService().selectUser(1); // First user created when creating the database + Role adminRole = getRoleDAO().getFilteredList( + Restrictions.like("role", "%sysadmin%")).get(0); + User admin = getUserDAO().getFilteredList( + Restrictions.eq("role", adminRole), Order.asc("rid")).get(0); // First sysadmin in the database + kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue( scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of // knowledges @@ -1059,4 +1074,23 @@ public class ScenarioServiceImpl implements ScenarioService { _documentTypeService = documentTypeService; } + /** + * Get the roleDAO. + * + * @return the roleDAO + */ + public RoleDAO getRoleDAO() { + return _roleDAO; + } + + /** + * Set the roleDAO. + * + * @param roleDAO + * the roleDAO to set + */ + public void setRoleDAO(final RoleDAO roleDAO) { + _roleDAO = roleDAO; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java index 94ba43a..9541c3d 100644 --- a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java @@ -72,7 +72,7 @@ public class UserServiceImpl implements UserService { // and to avoid the exception: // org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the // session: [org.splat.dal.bo.kernel.Role#simer] - getUserDAO().merge(nuser); + nuser = getUserDAO().merge(nuser); getUserDAO().saveOrUpdate(nuser); //getUserDAO().create(nuser); diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java index adc8a36..08feeae 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -336,7 +336,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } /** - * Check if a file of the given format should be imported during check-in of a document of the given type. + * Check if a file of the given format should be imported during check-out of a document of the given type. * * @param type * document type @@ -345,6 +345,15 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * @return true if file should be imported */ public boolean doImport(final String type, final String format) { + if (LOG.isDebugEnabled()) { + LOG.debug("Do import for (" + + type + + ", " + + format + + "): " + + (_mapimport.containsKey(type) && _mapimport.get(type) + .contains(format))); + } return (_mapimport.containsKey(type) && _mapimport.get(type).contains( format)); } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 1329347..9ac1007 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -87,7 +87,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + * Description :
@@ -454,6 +472,7 @@ public class TestProjectSettingsService extends BaseTest { startNestedTransaction(); // /////////////////////////////////////////////////// // ////// Load good workflow customization + getHibernateTemplate().clear(); _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again try { _projectSettings.configure(ClassLoader.getSystemResource( @@ -464,6 +483,10 @@ public class TestProjectSettingsService extends BaseTest { List steps = _projectSettings.getStepsOf(Scenario.class); Assert.assertTrue(steps.size() > 0, "No steps are created."); + KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase"); + Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database."); + SimulationContextType prodtype = _simulationContextService.selectType("product"); + Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database."); // ///////////////////////////////////////////////////////// // ////// Test reconfiguration attempt @@ -477,6 +500,10 @@ public class TestProjectSettingsService extends BaseTest { } steps = _projectSettings.getStepsOf(Scenario.class); Assert.assertTrue(steps.size() > 0, "No steps are created."); + ucase = _knowledgeElementTypeService.selectType("usecase"); + Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database."); + prodtype = _simulationContextService.selectType("product"); + Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database."); try { /* @@ -500,4 +527,71 @@ public class TestProjectSettingsService extends BaseTest { rollbackNestedTransaction(); LOG.debug(">>>>> END testConfigure()"); } + + /** + * Test of repeated database configuration method (dynamic reconfiguration).
+ * The problem - duplication of the simer user admin role. Description :
+ * Load customization twice and check the result.
+ * Action :
+ * 1. call the method twice for som.xml
+ * Test data :
+ * test/som.xml
+ * + * Outcome results:
+ * + *
    + *
  • step must be configured
    + *
  • + *
+ *
+ * + * @throws IOException + * if configuration loading is failed + * @throws SQLException + * if configuration loading is failed + */ + @Test + public void testDatabaseInitialize() throws IOException, SQLException { + LOG.debug(">>>>> BEGIN testDatabaseInitialize()"); + startNestedTransaction(); + // /////////////////////////////////////////////////// + // ////// Load good workflow customization + getHibernateTemplate().bulkUpdate("delete from Role"); + getHibernateTemplate().flush(); + Database.getInstance().reset(); + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again + try { + _projectSettings.configure(ClassLoader.getSystemResource( + "test/som.xml").getPath()); + } catch (FileNotFoundException e) { + Assert.fail("Can't find configuration file: ", e); + } + try { + /* + * The next call to flush() must not throw the following exception: org.springframework.dao.DuplicateKeyException: a different + * object with the same identifier value was already associated with the session: [org.splat.dal.bo.kernel.Role#simer]; nested + * exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated + * with the session: [org.splat.dal.bo.kernel.Role#simer] at + * org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:662) at + * org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at + * org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at + * org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at + * org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881) + */ + Database.getInstance().initialize(); + getHibernateTemplate().flush(); + } catch (DuplicateKeyException dke) { + Assert.fail( + "User creation failed during the database reconfiguration: " + + dke.getMessage(), dke); + } + + KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase"); + Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database."); + SimulationContextType prodtype = _simulationContextService.selectType("product"); + Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database."); + + rollbackNestedTransaction(); + LOG.debug(">>>>> END testDatabaseInitialize()"); + } } diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index d064e2f..b858a29 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -24,8 +24,11 @@ import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; +import org.splat.dal.bo.som.KnowledgeElementType; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; +import org.splat.dal.bo.som.SimulationContext; +import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; @@ -39,8 +42,10 @@ import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; import org.splat.log.AppLogger; import org.splat.service.DocumentTypeService; +import org.splat.service.KnowledgeElementTypeService; import org.splat.service.PublicationService; import org.splat.service.ScenarioService; +import org.splat.service.SimulationContextService; import org.splat.service.StepService; import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.FileDTO; @@ -105,6 +110,13 @@ public class TestScenarioService extends BaseTest { @Qualifier("stepService") private transient StepService _stepService; + /** + * The SimulationContextService. Later injected by Spring. + */ + @Autowired + @Qualifier("simulationContextService") + private transient SimulationContextService _simulationContextService; + /** * The ProjectSettingsService. Later injected by Spring. */ @@ -119,6 +131,13 @@ public class TestScenarioService extends BaseTest { @Qualifier("documentTypeService") private transient DocumentTypeService _documentTypeService; + /** + * The KnowledgeElementTypeService. Later injected by Spring. + */ + @Autowired + @Qualifier("knowledgeElementTypeService") + private transient KnowledgeElementTypeService _knowledgeElementTypeService; + /** * Test of getting a scenario content for building siman-salome.conf.
* Description :
@@ -835,4 +854,108 @@ public class TestScenarioService extends BaseTest { return pub; } + + + /** + * Test check-in scenario operation to be performed after SALOME session.
+ * Description :
+ * Create a scenario and try to check-in it with some simulated SALOME results data.
+ * After check-in verify following points: + *
    + *
  • scenario is no more marked as checked out
  • + *
  • new document versions are created for checked in documents
  • + *
  • presentation of the previous version is removed
  • + *
  • uses relations are copied correctly
  • + *
  • files are moved correctly
  • + *
  • new documents are created for new data
  • + *
  • uses relations are created correctly
  • + *
  • files are moved correctly
  • + *
+ *

+ * Action :
+ * 1. call the method for an existing scenario id.
+ * 2. call the method for a not existing scenario id.
+ * Test data :
+ * no input parameters
+ * no input parameters
+ * + * Outcome results:
+ * + *
    + *
  • New version of existing documents must be created and new documents must be imported for documents with zero id. Correct + * relations must be created.
    + *
  • + *
  • Exception is thrown
    + *
  • + *
+ *
+ * + * @throws InvalidPropertyException + * if an invalid property is used when creating objects + * @throws MultiplyDefinedException + * when trying to create an object with already existing id + * @throws MissedPropertyException + * if a mandatory property is not defined for an object to be created + * @throws IOException + * if scenario creation is failed + * @throws SQLException + * if scenario creation is failed + * @throws NotApplicableException + * if checkin failed + * @throws MismatchException + * if checkin failed + */ + @Test(groups = { "study", "sevice", "functional", "business" }) + public void testCreateStudy() throws InvalidPropertyException, + MissedPropertyException, MultiplyDefinedException, IOException, + SQLException, MismatchException, NotApplicableException { + LOG.debug(">>>>> BEGIN testCreateStudy()"); + startNestedTransaction(); + + Database.getInstance().reset(); + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again + _projectSettings.configure(ClassLoader + .getSystemResource("test/som.xml").getPath()); + + // Create a test user + User.Properties uprop = new User.Properties(); + uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser") + .setFirstName("TST_FirstName").setDisplayName("TST_test.user") + .addRole("TST_user").setMailAddress( + "noreply@salome-platform.org"); + uprop.disableCheck(); + User anAuthor = new User(uprop); + + getHibernateTemplate().saveOrUpdate(anAuthor); + KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase"); + Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database."); + SimulationContextType prodtype = _simulationContextService.selectType("product"); + Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database."); + + // Create admin + uprop.clear(); + uprop.setUsername("TST_Admin").setName("TST_SimanUnitTestsAdmin") + .setFirstName("TST_AdminFirstName").setDisplayName("TST_test.admin") + .addRole("TST_user,sysadmin").setMailAddress( + "noreply@salome-platform.org"); + uprop.disableCheck(); + + getHibernateTemplate().saveOrUpdate(new User(uprop)); + getHibernateTemplate().flush(); + + Study.Properties sprop = new Study.Properties(); + sprop.setTitle("Test study creation").setManager(anAuthor); + Scenario.Properties oprop = new Scenario.Properties(); + oprop.setTitle("Test scenario for the created study"); + + // Addition of the entered project context + SimulationContext.Properties cprop = new SimulationContext.Properties(); + // Input of new project context + cprop.setType(_simulationContextService.selectType("product")) + .setValue("Test Simulation Context: Product"); + Study study = _scenarioService.createStudy(sprop, oprop, cprop); + + rollbackNestedTransaction(); + LOG.debug(">>>>> END testCreateStudy()"); + } } diff --git a/Workspace/Siman-Common/testng_study.xml b/Workspace/Siman-Common/testng_study.xml new file mode 100644 index 0000000..f35d3e3 --- /dev/null +++ b/Workspace/Siman-Common/testng_study.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + diff --git a/Workspace/Siman/conf/release.properties b/Workspace/Siman/conf/release.properties index 4cb9919..c61d1bf 100644 --- a/Workspace/Siman/conf/release.properties +++ b/Workspace/Siman/conf/release.properties @@ -5,7 +5,8 @@ connection.password=admin connection.driver_class=com.p6spy.engine.spy.P6SpyDriver # Hibernate config -hibernate.hbm2ddl.auto=validate +#hibernate.hbm2ddl.auto=validate +hibernate.hbm2ddl.auto=update hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.current_session_context_class=thread