]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Show and Edit description functionalities are implemented
authormka <mka@opencascade.com>
Fri, 15 Feb 2013 13:11:01 +0000 (13:11 +0000)
committermka <mka@opencascade.com>
Fri, 15 Feb 2013 13:11:01 +0000 (13:11 +0000)
18 files changed:
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/conf/log-messages_en.properties
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml
Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.hbm.xml
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/test/splat/service/TestStepService.java
Workspace/Siman-Common/src/test/splat/service/TestStudyService.java
Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java [new file with mode: 0644]
Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml
Workspace/Siman/WebContent/jsp/descriptionPane.jsp [new file with mode: 0644]
Workspace/Siman/WebContent/jsp/readDescription.jsp
Workspace/Siman/WebContent/study/displayStudyStep.jsp
Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Workspace/Siman/src/struts.xml

index fed0f42968195518bab26ab7105b790b0d5bf451..f947e086840ea67bcd321e78cb53dd1f49462ed6 100644 (file)
@@ -18,4 +18,4 @@ SCT-000001=Simulation context type "{0}" already exists
 DCT-000001=Document type "{0}" already exists
 DCT-000002=Can not delete the document "{0}" because it is used by other documents.
 DCT-000003=Can not save a document in {0} state. Check the validation cycle.
-PARAM-000001=Parameter {0} is invalid with value: {1}
+PRM-000001=Parameter {0} is invalid with value: {1}
index fed0f42968195518bab26ab7105b790b0d5bf451..f1b20c6f913739ea1e5bd53d1ba8c1807d700e5b 100644 (file)
@@ -18,4 +18,4 @@ SCT-000001=Simulation context type "{0}" already exists
 DCT-000001=Document type "{0}" already exists
 DCT-000002=Can not delete the document "{0}" because it is used by other documents.
 DCT-000003=Can not save a document in {0} state. Check the validation cycle.
-PARAM-000001=Parameter {0} is invalid with value: {1}
+PRM-000001=Parameter {0} is invalid with value: {1}
\ No newline at end of file
index 27be5b2fbd0931724e3cf40eae73b4d911cfe675..eaea30f00eb18a27eed06f51bad61669debc2656 100644 (file)
@@ -94,9 +94,9 @@ public enum MessageKeyEnum {
         */
        DCT_000003("DCT-000003"),
                /**
-        * Parameter {1} is invalid with value: {2}.
+        * Parameter {0} is invalid with value: {1}.
         */
-       PARAM_000001("PARAM-000001");
+       PRM_000001("PRM-000001");
        /**
        * Value.
        */
index 2072446520dc057ceaeae3b76902491aef5da8fe..6c21eaf77e896feeec3c6fdd06d1980430fb2993 100644 (file)
@@ -26,7 +26,7 @@
        <union-subclass name="org.splat.dal.bo.som.StepCommentAttribute"
                extends="org.splat.dal.bo.kernel.TextAttribute" table="step_comment">
                
-               <many-to-one name="user" column="user" not-null="true" />       
+               <many-to-one name="user" column="author" not-null="true" />     
            <property name="date" column="date" not-null="true" />
            <property name="step" column="step" not-null="true" />
         <property name="title" column="title" not-null="true" type="text"/>
index 27f2d9caca2dd1cfc17d255d585568793b1bd7ef..be38e6a5bd0ca976f22c7f36c8c22f61da4248ea 100644 (file)
@@ -19,7 +19,7 @@
   <union-subclass name="org.splat.dal.bo.som.Study" extends="org.splat.dal.bo.som.ProjectElement" table="study" lazy="false">
   
       <!-- String sid                  -->
-      <property name="sid"         column="sid"     access="field" not-null="true" />    
+      <property name="sid"         column="reference"     access="field" not-null="true" />    
   
       <!-- int    docount              -->
       <property name="docount"     column="docount" access="field" not-null="true" />    
index 47d096253daee1715ae9d9f0569a6616c5527634..af8ffcb90112268733c14743203b04d3f23f9c81 100644 (file)
@@ -604,9 +604,11 @@ public class StepServiceImpl implements StepService {
        }
 
        /**
+        * {@inheritDoc}
         * @see org.splat.service.StepService#getStepComments(org.splat.som.Step)
         */
        @Override
+       @Transactional(readOnly = true)
        public List<StepCommentDTO> getStepComments(final Step step) throws InvalidParameterException {
                ProjectElement owner = _projectElementDAO.get(step.getOwner().getRid());
                if(owner == null) {
index 13dc7dfde866f89b77e126e4f746156b8904602e..19fa71f8817076a8c84a8378fd47578bdbc1db2c 100644 (file)
@@ -18,6 +18,7 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Study.Properties;
 import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
@@ -264,7 +265,6 @@ public interface StudyService {
         * Mark study as reference.
         * 
         * @param aStudy - the Study
-        * @return true if operation is success
         */
        void markStudyAsReference(Study aStudy);
        
@@ -273,7 +273,24 @@ public interface StudyService {
         * This operation is inverse one to Mark as reference.
         * 
         * @param aStudy - the Study
-        * @return true if operation is success
         */
        void removeStudyAsReference(Study aStudy);
+       
+       /**
+        * Get the description attribute related to the study
+        *              (there supposed to be the only one such attribute in the database).
+        * @param studyId the study id
+        * @return the description attribute value (null if does not exist)
+        * @throws InvalidParameterException if a study with such id does not exist in the database.
+        */
+       String getDescription(Long studyId) throws InvalidParameterException;
+       
+       /**
+        * Set the description attribute related to the study.
+        * @param studyId the study id
+        * @param descriptionText the description text
+        * @throws InvalidParameterException if some parameters are invalid.
+        */
+       void setDescription(Long studyId, String descriptionText) throws InvalidParameterException;
+
 }
index 122892593aaffa36f41b229841537a9a7e82681d..b1f03057030d5f53d2242b8900963cb3dfc8ed35 100644 (file)
@@ -34,16 +34,20 @@ 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.Study;
+import org.splat.dal.bo.som.Study.Properties;
 import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.ValidationCycle.Actor;
 import org.splat.dal.bo.som.ValidationCycleRelation;
 import org.splat.dal.bo.som.ValidationStep;
 import org.splat.dal.bo.som.Visibility;
-import org.splat.dal.bo.som.Study.Properties;
-import org.splat.dal.bo.som.ValidationCycle.Actor;
+import org.splat.dal.dao.som.DescriptionAttributeDAO;
+import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.dal.dao.som.IDBuilderDAO;
+import org.splat.dal.dao.som.PublicationDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.dal.dao.som.StudyDAO;
 import org.splat.dal.dao.som.ValidationCycleDAO;
+import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
@@ -51,6 +55,7 @@ import org.splat.log.AppLogger;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsServiceImpl;
+import org.splat.service.technical.RepositoryService;
 import org.splat.som.Revision;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -117,6 +122,26 @@ public class StudyServiceImpl implements StudyService {
         * Injected user service.
         */
        private UserService _userService;
+       
+       /**
+        * Injected publication DAO.
+        */
+       private PublicationDAO _publicationDAO;
+
+       /**
+        * Injected repository service.
+        */
+       private RepositoryService _repositoryService;
+
+       /**
+        * Injected document DAO.
+        */
+       private DocumentDAO _documentDAO;
+
+       /**
+        * Injected description attribute DAO.
+        */
+       private DescriptionAttributeDAO _descriptionAttributeDAO;
 
        /**
         * {@inheritDoc}
@@ -1027,6 +1052,42 @@ public class StudyServiceImpl implements StudyService {
                aStudy.setProgressState(ProgressState.APPROVED);
                getStudyDAO().merge(aStudy);
        }
+       
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StudyService#getDescription(java.lang.Long)
+        */
+       @Override
+       @Transactional(readOnly = true)
+       public String getDescription(final Long studyId) throws InvalidParameterException {
+               if(studyId == null) {
+                       throw new InvalidParameterException("studyId", "null");
+               }
+               Study study = _studyDAO.get(studyId);
+               if(study == null) {
+                       throw new InvalidParameterException("studyId", studyId.toString());
+               }
+               return study.getDescription();
+       }
+       
+       
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String)
+        */
+       @Override
+       @Transactional
+       public void setDescription(final Long studyId, final String descriptionText) 
+                       throws InvalidParameterException {
+               if(studyId == null) {
+                       throw new InvalidParameterException("studyId", "null");
+               }
+               Study study = _studyDAO.get(studyId);
+               if(study == null) {
+                       throw new InvalidParameterException("studyId", studyId.toString());
+               }
+               study.setAttribute(new DescriptionAttribute(study, descriptionText));
+       }
 
        /**
         * Get project settings.
@@ -1221,4 +1282,70 @@ public class StudyServiceImpl implements StudyService {
        public void setUserService(final UserService userService) {
                _userService = userService;
        }
+
+       /**
+        * Get the publicationDAO.
+        * @return the publicationDAO
+        */
+       public PublicationDAO getPublicationDAO() {
+               return _publicationDAO;
+       }
+
+       /**
+        * Set the publicationDAO.
+        * @param publicationDAO the publicationDAO to set
+        */
+       public void setPublicationDAO(final PublicationDAO publicationDAO) {
+               _publicationDAO = publicationDAO;
+       }
+
+       /**
+        * Get the repositoryService.
+        * @return the repositoryService
+        */
+       public RepositoryService getRepositoryService() {
+               return _repositoryService;
+       }
+
+       /**
+        * Set the repositoryService.
+        * @param repositoryService the repositoryService to set
+        */
+       public void setRepositoryService(final RepositoryService repositoryService) {
+               _repositoryService = repositoryService;
+       }
+
+       /**
+        * Get the documentDAO.
+        * @return the documentDAO
+        */
+       public DocumentDAO getDocumentDAO() {
+               return _documentDAO;
+       }
+
+       /**
+        * Set the documentDAO.
+        * @param documentDAO the documentDAO to set
+        */
+       public void setDocumentDAO(final DocumentDAO documentDAO) {
+               _documentDAO = documentDAO;
+       }
+
+       /**
+        * Get the descriptionAttributeDAO.
+        * @return the descriptionAttributeDAO
+        */
+       public DescriptionAttributeDAO getDescriptionAttributeDAO() {
+               return _descriptionAttributeDAO;
+       }
+
+       /**
+        * Set the descriptionAttributeDAO.
+        * @param descriptionAttributeDAO the descriptionAttributeDAO to set
+        */
+       public void setDescriptionAttributeDAO(
+                       final DescriptionAttributeDAO descriptionAttributeDAO) {
+               _descriptionAttributeDAO = descriptionAttributeDAO;
+       }
+
 }
index 199904679f1133c903cba8925bf05cfe0cb99581..2a1874f523ce3910f8de89735708b438f4bd36a1 100644 (file)
@@ -153,6 +153,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="validationCycleDAO" ref="validationCycleDAO" />
                <property name="documentTypeService" ref="documentTypeService" />
                <property name="userService" ref="userService" />
+               <property name="descriptionAttributeDAO" ref="descriptionAttributeDAO" />
        </bean>
 
        <bean id="userRights" abstract="true" scope="session">
index 92329d53107573a10bd9b2240b55b6beaab533c0..f0e0bf86557f7ed471e841cab9c94782349dd020 100644 (file)
@@ -23,16 +23,13 @@ import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.File;
-import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.ProjectElement;
 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.StepCommentAttribute;
 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.bo.som.Visibility;
 import org.splat.dal.dao.kernel.UserDAO;
 import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.FileDAO;
@@ -60,6 +57,7 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import test.splat.common.BaseTest;
+import test.splat.util.TestEntitiesGenerator;
 
 /**
  * Test class for StepService.
@@ -665,6 +663,7 @@ public class TestStepService extends BaseTest {
 
                return pub;
        }
+       
        /**
         * Test of addition of a new step comment.
         *
@@ -673,9 +672,9 @@ public class TestStepService extends BaseTest {
        @Test
        public void testAddStepComment() throws BusinessException{
 
-               User goodUser = getTestUser("goodUser");
+               User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
                _userDAO.create(goodUser);
-               Study goodStudy = getTestStudy(goodUser);
+               Study goodStudy = TestEntitiesGenerator.getTestStudy(goodUser);
                _studyDAO.create(goodStudy);
                getHibernateTemplate().flush();
                StepCommentDTO goodStepCommentDTO = createStepCommentDTO(goodUser, goodStudy);
@@ -693,7 +692,7 @@ public class TestStepService extends BaseTest {
                //valid DTO, non-existing user
                {
                        //get a non-existing id
-                       User badUser = getTestUser("badUser");
+                       User badUser = TestEntitiesGenerator.getTestUser("badUser");
                        _userDAO.create(badUser);
                        getHibernateTemplate().evict(badUser);//so createStepCommentDTO will invoke an
                                        //actual query to the base, not cache in order to check if the user already exists
@@ -712,7 +711,7 @@ public class TestStepService extends BaseTest {
 
                //valid DTO, non-existing project element
                {
-                       Study badStudy = getTestStudy(goodUser);
+                       Study badStudy = TestEntitiesGenerator.getTestStudy(goodUser);
                        _studyDAO.create(badStudy);
                        getHibernateTemplate().evict(badStudy);//so createStepCommentDTO will invoke an
                        //actual query to the base, not cache in order to check if the study already exists
@@ -751,9 +750,9 @@ public class TestStepService extends BaseTest {
        @Test
        public void testGetStepComments() throws BusinessException {
 
-               User user = getTestUser("goodUser");
+               User user = TestEntitiesGenerator.getTestUser("goodUser");
                _userDAO.create(user);
-               Study study = getTestStudy(user);
+               Study study = TestEntitiesGenerator.getTestStudy(user);
                
                //Before we create the study in the database:
                org.splat.som.Step step = new org.splat.som.Step(_projectSettings.getStep(1), study);
@@ -801,49 +800,6 @@ public class TestStepService extends BaseTest {
                                new Integer(0), new Date(), user.getRid(), user.getName(), "Good comment title");
        }
 
-       /**
-        * Create a transient user.
-        *
-        * @param userName the userName
-        * @return a transient StepCommentDTO
-        * @throws BusinessException if something's wrong
-        */
-       private User getTestUser(final String userName) throws BusinessException {
-
-               User.Properties uprop = new User.Properties();
-               uprop.setUsername(userName)
-                               .setName("TST_Username")
-                               .setFirstName("TST_FirstName")
-                               .setDisplayName("TST_test.user")
-                               .setMailAddress("noreply@salome-platform.org")
-                               .addRole("TST-User");
-               uprop.disableCheck();
-               User user = new User(uprop);
-               return user;
-       }
-
-       /**
-        * Create a transient study.
-        *
-        * @param user the user that will be placed in 'manager' and 'actor' properties
-        * @return the test study
-        * @throws BusinessException if something's wrong
-        */
-       private Study getTestStudy(final User user) throws BusinessException{
-               Study.Properties studyProps = new Study.Properties();
-               studyProps.setActor(user)
-                               .setManager(user)
-                               .setTitle("a test study")
-                               .setDescription("description")
-                               .setDate(new Date())
-                               .setReference("test reference")
-                               .setSimulationContexts(new ArrayList<SimulationContext>())
-                               .setState(ProgressState.inWORK)
-                               .setVisibility(Visibility.PUBLIC);
-               Study study = new Study(studyProps);
-               return study;
-       }
-
        /**
         * Create StepCommentDTO with all the fields filled in from StepCommentAttribute.
         * @param comment the comment
index 915f54b0fe4fb4b9c6bb164d08bb4ba9d3f5e423..565cfea898d864d4a405973c71e991936a42e60a 100644 (file)
@@ -17,15 +17,19 @@ import java.util.List;
 import java.util.Map;
 
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.DescriptionAttribute;
 import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.Study;
-import org.splat.dal.bo.som.Document.Properties;
+import org.splat.dal.dao.kernel.UserDAO;
 import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.StudyDAO;
+import org.splat.exception.BusinessException;
+import org.splat.exception.InvalidParameterException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
@@ -43,6 +47,7 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import test.splat.common.BaseTest;
+import test.splat.util.TestEntitiesGenerator;
 
 /**
  * Test class for StudyService.
@@ -99,6 +104,13 @@ public class TestStudyService extends BaseTest {
        @Autowired
        @Qualifier("studyService")
        private transient StudyService _studyService;
+       
+       /**
+        * The UserDAO. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("userDAO")
+       private transient UserDAO _userDAO;
 
        /**
         * Create a persistent scenario for tests.
@@ -397,4 +409,107 @@ public class TestStudyService extends BaseTest {
                rollbackNestedTransaction();
                LOG.debug(">>>>> END testGenerateLocalIndex()");
        }
+       
+       /**
+        * Test of retrieval of a study description.
+        *
+        * @throws BusinessException if there is something wrong likely unrelated to the tested method
+        */
+       @Test
+       public void testGetDescription() throws BusinessException {
+               LOG.debug(">>>>> BEGIN testGetDescription()");
+               startNestedTransaction();
+               
+               User user = TestEntitiesGenerator.getTestUser("GoodUser");
+               _userDAO.create(user);
+               Study study = TestEntitiesGenerator.getTestStudy(user);
+               _studyDAO.create(study);
+               _studyDAO.flush();
+               Long studyId = Long.valueOf(study.getIndex());
+               
+               //Empty description:
+               Assert.assertNull(_studyService.getDescription(studyId), 
+                               "returned value for study without description must be null");
+               
+               //Not empty description:
+               study.setAttribute(new DescriptionAttribute(study, "description"));
+               _studyDAO.update(study);
+               _studyDAO.flush();
+               Assert.assertEquals("description", _studyService.getDescription(studyId));
+               
+               //null id
+               try {
+                       _studyService.getDescription(null);
+                       Assert.fail("retrieval with null study id must fail");
+               } catch(InvalidParameterException e){
+                       LOG.debug("Expected exception is thrown: "
+                               + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+               
+               //Non-existing id
+               Study tmpStudy = TestEntitiesGenerator.getTestStudy(user);
+               _studyDAO.create(tmpStudy);
+               Long nonExistingId = tmpStudy.getIndex();
+               _studyDAO.delete(tmpStudy);
+               try {
+                       _studyService.getDescription(nonExistingId);
+                       Assert.fail("retrieval with non-existing study id must fail");
+               } catch(InvalidParameterException e){
+                       LOG.debug("Expected exception is thrown: "
+                               + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+
+               rollbackNestedTransaction();
+               LOG.debug(">>>>> END testGetDescription()");
+       }
+       
+       /**
+        * Test of setting of a study description.
+        *
+        * @throws BusinessException if there is something wrong likely unrelated to the tested method
+        */
+       @Test
+       public void testSetDescription() throws BusinessException {
+               LOG.debug(">>>>> BEGIN testSetDescription()");
+               startNestedTransaction();
+               
+               User user = TestEntitiesGenerator.getTestUser("GoodUser");
+               _userDAO.create(user);
+               Study study = TestEntitiesGenerator.getTestStudy(user);
+               _studyDAO.create(study);
+               _studyDAO.flush();
+               Long studyId = Long.valueOf(study.getIndex());
+               
+               //Setting description for study without any
+               _studyService.setDescription(studyId, "description");
+
+               //Resetting description
+               _studyService.setDescription(studyId, "replaced description");
+               
+               //null id
+               try {
+                       _studyService.setDescription(null, "description");
+                       Assert.fail("setting with null study id must fail");
+               } catch(InvalidParameterException e){
+                       LOG.debug("Expected exception is thrown: "
+                               + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+               
+               //Non-existing id
+               Study tmpStudy = TestEntitiesGenerator.getTestStudy(user);
+               _studyDAO.create(tmpStudy);
+               Long nonExistingId = tmpStudy.getIndex();
+               _studyDAO.delete(tmpStudy);
+               
+               try {
+                       _studyService.setDescription(nonExistingId, "description");
+                       Assert.fail("retrieval with non-existing study id must fail");
+               } catch(InvalidParameterException e){
+                       LOG.debug("Expected exception is thrown: "
+                               + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+
+               rollbackNestedTransaction();
+               LOG.debug(">>>>> END testSetDescription()");
+       }
 }
diff --git a/Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java b/Workspace/Siman-Common/src/test/splat/util/TestEntitiesGenerator.java
new file mode 100644 (file)
index 0000000..d43b932
--- /dev/null
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   Feb 12, 2013
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package test.splat.util; 
+
+import java.util.ArrayList;
+import java.util.Date;
+
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Visibility;
+import org.splat.exception.BusinessException;
+
+/**
+ * Utility class for creating test entities.
+ */
+public class TestEntitiesGenerator {
+       
+       /**
+        * Create a transient user.
+        *
+        * @param userName the userName
+        * @return a transient StepCommentDTO
+        * @throws BusinessException if something's wrong
+        */
+       public static User getTestUser(final String userName) throws BusinessException {
+
+               User.Properties uprop = new User.Properties();
+               uprop.setUsername(userName)
+                               .setName("TST_Username")
+                               .setFirstName("TST_FirstName")
+                               .setDisplayName("TST_test.user")
+                               .setMailAddress("noreply@salome-platform.org")
+                               .addRole("TST-User");
+               uprop.disableCheck();
+               User user = new User(uprop);
+               return user;
+       }
+
+       /**
+        * Create a transient study.
+        *
+        * @param user the user that will be placed in 'manager' and 'actor' properties
+        * @return the test study
+        * @throws BusinessException if something's wrong
+        */
+       public static Study getTestStudy(final User user) throws BusinessException{
+               Study.Properties studyProps = new Study.Properties();
+               studyProps.setActor(user)
+                               .setManager(user)
+                               .setTitle("a test study")
+                               //.setDescription("description")
+                               .setDate(new Date())
+                               .setReference("test reference")
+                               .setSimulationContexts(new ArrayList<SimulationContext>())
+                               .setState(ProgressState.inWORK)
+                               .setVisibility(Visibility.PUBLIC);
+               Study study = new Study(studyProps);
+               return study;
+       }
+}
index 319ce104b4b26eab13ea71c7865a8bd896e7eaf5..435051c54479a3f4f7ffc7cfe6cac0bdca211c1f 100644 (file)
     <put-attribute name="display_comments_pane"   value="zone.stepcomments"/>
 </definition>
 
+<definition name="zone.description"  template="/jsp/readDescription.jsp"/>
+
+<definition name="page.description" template="/jsp/descriptionPane.jsp">
+    <put-attribute name="display_description_pane" value="zone.description" />
+</definition>
+
 <definition name="zone.displaystudy" template="/study/displayStudyStep.jsp">
     <put-attribute name="step_comments_pane" value="page.stepcomments" />
+    <put-attribute name="description_pane" value="page.description" />
 </definition>
 
 <definition name="page.displaystudy" extends="baseLayout">
diff --git a/Workspace/Siman/WebContent/jsp/descriptionPane.jsp b/Workspace/Siman/WebContent/jsp/descriptionPane.jsp
new file mode 100644 (file)
index 0000000..a14d1f0
--- /dev/null
@@ -0,0 +1,70 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+    pageEncoding="ISO-8859-1"%>
+<%@ taglib prefix="s" uri="/struts-tags"%>
+<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
+
+<div id="display_description_div">
+    <tiles:insertAttribute name="display_description_pane" ignore="true" />
+</div>
+
+<s:if test="%{writeAccess == 'true' && stepEnabled == 'true'}">
+    <script type="text/javascript">
+        $(document).ready(function(){        
+            $("#description_form").ajaxForm({
+                target: '#display_description_div'
+            });
+        
+            // Bind the add button
+            $("#set_description_button").click(function() {
+              document.getElementById("display_description_div").style.display = 'none';
+              document.getElementById("set_description_button_div").style.display = 'none';
+              document.getElementById("description_editor_div").style.display = 'block';
+              document.getElementById("descriptionValue").contentDocument.body.innerHTML = 
+                    document.getElementById("display_description_div").innerHTML;
+            });
+            
+            function hideDescriptionEditor() {
+              document.getElementById("display_description_div").style.display = 'block';
+              document.getElementById("set_description_button_div").style.display = 'block';
+              document.getElementById("description_editor_div").style.display = 'none';
+              document.getElementById('descriptionValue').contentDocument.body.innerHTML = '';
+            }
+            
+            // Bind the cancel button
+            $("#cancel_set_description_button").click(hideDescriptionEditor);
+            
+            // Bind the submit event
+            $('#description_form').on('submit', hideDescriptionEditor);
+        });
+    </script>
+    
+    <div id="set_description_button_div">
+      <table width="100%" cellpadding="0" cellspacing="0" border="0" class="attribute">
+        <tr>
+          <td width="20" height="20" align="center">
+            <img id="set_description_button" src="<s:url value="/skin/icon.add.png"/>" onMouseOver=this.src="<s:url value="/skin/icon.addhot.png"/>"
+                onMouseOut=this.src="<s:url value="/skin/icon.add.png"/>" title="<s:text name="tooltip.adddescription"/>"/>
+           </td>
+          <td>&nbsp;</td>
+        </tr>
+      </table>  
+    </div>
+    
+    <div id="description_editor_div" style="display: none;">
+    <form name="description_form" id="description_form" action="set-description" method="post">
+      <table width="100%" cellpadding="0" cellspacing="0" border="0" class="attribute">
+        <tr valign="top">
+          <td width="20" height="20" align="center">
+            <img id="cancel_set_description_button" src="<s:url value="/skin/icon.undo.png"/>"
+                title="<s:text name="tooltip.cancel"/>" />
+          </td>
+          <td>
+            <script language='JavaScript'>
+                displayTextEditor('descriptionValue', '', 300, 150);
+            </script>   
+          </td>
+        </tr>
+      </table> 
+    </form>
+    </div>
+</s:if>
\ No newline at end of file
index 48f3d984d01f22b6974b09388bbb65bbcd53aeda..14c32db387ed6d9a8118310cefdd378810674c39 100644 (file)
@@ -1,27 +1,4 @@
 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
-    pageEncoding="ISO-8859-1"
-%>
-<%@ taglib prefix="s" uri="/struts-tags"
-%>
-<%@ page import="org.splat.simer.AbstractOpenObject"%>
-<%
-//  On the contrary of Struts tags, the Java implementation allows the HTML contents of knowledge values to be displayed
-    String      entitype    = request.getParameter("entity");   // Study or Knowledge element
-    AbstractOpenObject  object      = (AbstractOpenObject)session.getAttribute(entitype + ".open");
-    String      description = object.getDisplayedDescription();
-%>
-<table cellpadding=0 cellspacing=0 border=0 class=text>
-<%  if (description != null) {
-%><tr>
-    <td><%=description%></td>
-  </tr>
-<%  }
-%><tr height=2><td></td></tr>
-  <tr height=18>
-    <s:if test="%{writeAccess == 'true' && stepEnabled == 'true'}">
-      <td>
-        <img src="<s:url value="/skin/icon.add.png"/>" border="none" title="<s:text name="tooltip.adddescription"/>" />
-      </td>
-    </s:if>
-  </tr>
-</table>
\ No newline at end of file
+    pageEncoding="ISO-8859-1"%>
+<%@ taglib prefix="s" uri="/struts-tags"%>
+<s:property value="descriptionValue" escapeHtml="false"/>
\ No newline at end of file
index 7803b465857912eddf7867019ec56edba2606b69..6cc1f8f9ff1008128e3d2fe3d2f0accbb5b46635 100644 (file)
           <td width=38%>     <!-- Must conform to the width of above tab-description -->
             <div id="top-spacer"></div>
             <div id=article-body class=text>
-              <jsp:include page="/jsp/readDescription.jsp">
-                <jsp:param name="entity" value="study" />
-              </jsp:include>
+              <tiles:insertAttribute name="description_pane" ignore="true" />         
             </div>
           </td>
           <td width=1></td>    <!-- Trick for aligning the vertical separator with the tab -->
index f8523e137db8092e6a34c1d151f2caecf356ff73..4474f20d8088a6256cae95b1bd22c978edd1b8f9 100644 (file)
@@ -45,6 +45,11 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
         * Injected Step Service.
         */
        private StepService _stepService;
+       
+       /**
+        * Study description.
+        */
+       private String _descriptionValue;
 
        // ==============================================================================================================================
        // Action methods
@@ -102,6 +107,7 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
                        setMenu();
                }
                loadComments();
+               loadDescription();
                return res;
        }
 
@@ -198,6 +204,34 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
                }
        }
        
+       /**
+        * Loads description (if already loaded - reloads).
+        */
+       public void loadDescription() {
+               try {
+                       _descriptionValue = _studyService.getDescription(_openStudy.getIndex());
+               } catch(InvalidParameterException exception) {
+                       _descriptionValue = null;
+                       LOG.debug("Error while trying to add description: " + exception.getMessage());
+               }
+       }
+       
+       /**
+        * Sets study description.
+        * @return SUCCESS if succeeded, INPUT otherwise.
+        */
+       public String doSetDescription() {
+               String res = INPUT;
+               try {
+                       _studyService.setDescription(_openStudy.getIndex(), _descriptionValue);
+                       res = SUCCESS;
+               } catch(InvalidParameterException exception) {
+                       LOG.debug("Error while trying to add description: " + exception.getMessage());
+               }
+               loadDescription();
+               return res;
+       }
+       
        // ==============================================================================================================================
        // Getters
        // ==============================================================================================================================
@@ -300,4 +334,20 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
        public void setStepService(final StepService stepService) {
                _stepService = stepService;
        }
+       
+       /**
+        * Get the descriptionValue.
+        * @return the descriptionValue
+        */
+       public String getDescriptionValue() {
+               return _descriptionValue;
+       }
+
+       /**
+        * Set the descriptionValue.
+        * @param descriptionValue the descriptionValue to set
+        */
+       public void setDescriptionValue(final String descriptionValue) {
+               _descriptionValue = descriptionValue;
+       }
 }
\ No newline at end of file
index 4dadb4c340a31bac0183411ffa434c72065593a9..b8226791c267601a361bc223b71a036f44f52093 100644 (file)
                                page.editscenarioproperties
                        </result>
                </action>
+               <action name="set-description"
+            class="displayStudyStepAction" method="setDescription">
+            <result name="success" type="tiles">
+                zone.description
+            </result>
+        </action>      
 
                <!-- Edition of scenario
                -->