]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
DTO is introduced for knowledge elements. BeanHelper is modified so that setters...
authorrkv <rkv@opencascade.com>
Thu, 1 Nov 2012 07:15:20 +0000 (07:15 +0000)
committerrkv <rkv@opencascade.com>
Thu, 1 Nov 2012 07:15:20 +0000 (07:15 +0000)
21 files changed:
Workspace/Siman-Common/ testng_util.xml [new file with mode: 0644]
Workspace/Siman-Common/src/log4j.xml
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.java
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementService.java
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementDTO.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementTypeDTO.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/dto/RoleDTO.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/dto/UserDTO.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java
Workspace/Siman-Common/src/org/splat/util/BeanHelper.java
Workspace/Siman-Common/src/org/splat/util/DTOTransformer.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/util/DTOTransformerFactory.java [new file with mode: 0644]
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/test/splat/util/TestDTOTransformer.java [new file with mode: 0644]
Workspace/Siman/src/org/splat/simer/Action.java
Workspace/Siman/src/org/splat/simer/DisplayKnowledgeAction.java
Workspace/Siman/src/org/splat/simer/OpenKnowledge.java
Workspace/Siman/src/org/splat/simer/OpenObject.java

diff --git a/Workspace/Siman-Common/ testng_util.xml b/Workspace/Siman-Common/ testng_util.xml
new file mode 100644 (file)
index 0000000..9c58f73
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanUtilTests" verbose="1">
+       <test name="all">
+               <method-selectors>
+                       <method-selector>
+                               <script language="beanshell">
+                                       <![CDATA[
+                groups.containsKey("util") && method.getName().toUpperCase().startsWith("TEST")             
+              ]]>
+                               </script>
+                       </method-selector>
+               </method-selectors>
+        <groups>
+        </groups>
+               <packages>
+                       <package name="test.*" />
+               </packages>
+       </test>
+</suite>
index c73cdd5e2cbf6c8feb06ceb6745fa276600fcdad..f31a8af879f631fecc27e4a921085e3a39137d0e 100644 (file)
         <level value="DEBUG" />
     </logger>
   
+    <logger name="org.splat.util">
+        <level value="DEBUG" />
+    </logger>
+  
+    <logger name="net.sf.beanlib.spi">
+        <level value="DEBUG" />
+    </logger>
+  
     <logger name="log4j.logger.org.hibernate">
         <level value="DEBUG" />
     </logger>
index 41443f075a467a1a00884e7f12edc725620ac6f6..41dad3bc452dde7583e8994d83755194baa56fa3 100644 (file)
@@ -234,4 +234,11 @@ public class User extends Persistent implements Principal, Name {
 //  -------------------------
       return last + " " + first;
     }
+       /**
+        * Get the role.
+        * @return the role
+        */
+       public Role getRole() {
+               return role;
+       }
 }
\ No newline at end of file
index 0bfa2e56696899c25a7cff6a5783e52e6b5673e4..6f4a9a8c7d3739bc750d6e67cd1e2446b50e997e 100644 (file)
@@ -11,11 +11,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.Vector;
 
-import org.hibernate.Session;
-
 import org.splat.dal.bo.kernel.Persistent;
 import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
index 2ccef0cec1b943b9d5ada308c5df537eac52bc96..a2f0f021c8e3cd6d0e4eb8aaa8d91d672001c24e 100644 (file)
@@ -15,6 +15,7 @@ import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.kernel.InvalidPropertyException;
+import org.splat.service.dto.KnowledgeElementDTO;
 
 /**
  * Knowledge element service interface.
@@ -72,6 +73,15 @@ public interface KnowledgeElementService {
         */
        public KnowledgeElement selectKnowledgeElement(long index);
 
+       /**
+        * Get a knowledge element DTO by id.
+        * 
+        * @param index
+        *            the knowledge element id
+        * @return the found knowledge element as DTO
+        */
+       public KnowledgeElementDTO getKnowledgeElement(long index);
+
        /**
         * Update the description of the knowledge element.
         * 
index 76f86676cc9a76b825c59958e222f2d53af28e2c..c01cd6858eb99cae7553620e50f04055e115c7b5 100644 (file)
@@ -9,12 +9,19 @@
 
 package org.splat.service;
 
+import java.util.Collection;
+import java.util.Vector;
+
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.dao.som.KnowledgeElementDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.log.AppLogger;
+import org.splat.service.dto.KnowledgeElementDTO;
 import org.splat.service.technical.IndexService;
+import org.splat.som.Step;
+import org.splat.util.BeanHelper;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -42,6 +49,10 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
         * Injected study service.
         */
        private StudyService _studyService;
+       /**
+        * Injected project element service.
+        */
+       private ProjectElementService _projectElementService;
 
        /**
         * {@inheritDoc}
@@ -72,7 +83,9 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
 
        /**
         * Update knowledge element in the database and in the lucene index.
-        * @param knowledgeElement the knowledge element to update
+        * 
+        * @param knowledgeElement
+        *            the knowledge element to update
         * @return true if updating succeeded
         */
        protected boolean update(KnowledgeElement knowledgeElement) {
@@ -120,10 +133,56 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
         * 
         * @see org.splat.service.KnowledgeElementService#selectKnowledgeElement(long)
         */
-       @Transactional(readOnly=true)
+       @Transactional(readOnly = true)
        public KnowledgeElement selectKnowledgeElement(long index) {
                KnowledgeElement result = getKnowledgeElementDAO().get(index);
-               getStudyService().loadWorkflow(result.getOwnerScenario().getOwnerStudy());
+               getStudyService().loadWorkflow(
+                               result.getOwnerScenario().getOwnerStudy());
+               return result;
+       }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#getKnowledgeElement(long)
+        */
+       @Transactional(readOnly = true)
+       public KnowledgeElementDTO getKnowledgeElement(long index) {
+               KnowledgeElement kelm = getKnowledgeElementDAO().get(index);
+               getStudyService().loadWorkflow(kelm.getOwnerScenario().getOwnerStudy());
+               KnowledgeElementDTO result = BeanHelper.copyBean(kelm,
+                               KnowledgeElementDTO.class);
+               result.setScenarioTitle(kelm.getOwnerScenario().getTitle());
+               result.setStudyTitle(kelm.getOwnerScenario().getOwnerStudy().getTitle());
+               result.getInvolving().addAll(getAllSteps(kelm.getOwnerScenario()));
+               return result;
+       }
+
+       /**
+        * Get all steps of the scenario.
+        * @param scenar the scenario
+        * @return collection of steps
+        */
+       private Collection<? extends Step> getAllSteps(Scenario scenar) {
+               Vector<Step> result = new Vector<Step>();
+               Step[] step = getProjectElementService().getSteps(scenar);
+
+               int base = step[0].getNumber();
+               int last = step[step.length - 1].getNumber();
+               for (int i = 0; i < step.length; i++) {
+                       result.add(step[i]);
+               }
+               step = getProjectElementService().getSteps(scenar.getOwnerStudy());
+               for (int i = step.length - 1; i > -1; i--) {
+                       if (step[i].getNumber() >= base)
+                               continue;
+                       result.add(0, step[i]);
+               }
+               for (int i = 0; i < step.length; i++) {
+                       if (step[i].getNumber() <= last)
+                               continue;
+                       result.add(step[i]);
+               }
                return result;
        }
 
@@ -193,6 +252,7 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
 
        /**
         * Get the studyService.
+        * 
         * @return the studyService
         */
        public StudyService getStudyService() {
@@ -201,9 +261,27 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
 
        /**
         * Set the studyService.
-        * @param studyService the studyService to set
+        * 
+        * @param studyService
+        *            the studyService to set
         */
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
        }
+
+       /**
+        * Get the projectElementService.
+        * @return the projectElementService
+        */
+       public ProjectElementService getProjectElementService() {
+               return _projectElementService;
+       }
+
+       /**
+        * Set the projectElementService.
+        * @param projectElementService the projectElementService to set
+        */
+       public void setProjectElementService(ProjectElementService projectElementService) {
+               _projectElementService = projectElementService;
+       }
 }
index 7e7537617365fe1214b3ee0239384dba073269fc..b8a35358a7c28cae24ea90f6fbbed4003ab7bd09 100644 (file)
@@ -14,7 +14,6 @@ import java.util.List;
 
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.ProjectElementDAO;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.som.Step;
diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementDTO.java
new file mode 100644 (file)
index 0000000..e354bd9
--- /dev/null
@@ -0,0 +1,171 @@
+package org.splat.service.dto;
+/**
+ * 
+ * @author    Daniel Brunier-Coulin
+ * @copyright OPEN CASCADE 2012
+ */
+
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Vector;
+
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.som.Step;
+
+
+public class KnowledgeElementDTO {
+
+       private long                     rid;
+       private KnowledgeElementTypeDTO  type;     // User extendable types
+    private ProgressState            state;
+    private String                   title;
+    private String                   value;
+    private UserDTO                  author;
+    private Date                     date;
+    private List<Step>               involving = new Vector<Step>();
+       private String                   studyTitle;
+       private String                   scenarioTitle;
+
+//  ==============================================================================================================================
+//  Public member functions
+//  ==============================================================================================================================
+
+    /**
+     * @param given
+     * @return
+     */
+    public boolean equals (KnowledgeElementDTO given) {
+      if (!this.getType().equals(given.getType())) return false;
+      if (this.getValue().equals(given.getValue())) return true;
+      return false;      
+    }
+
+    public UserDTO getAuthor () {
+      return author;
+    }
+
+    public Date getDate () {
+      return date;
+    }
+
+    public ProgressState getProgressState () {
+      return state;
+    }
+
+    public String getTitle () {
+      return title;
+    }
+
+    public String getReference () {
+      DecimalFormat toString = new DecimalFormat("00000");   // Supports 99 999 knowledge elements
+      return "KE" + toString.format(this.getIndex());
+    }
+
+    public KnowledgeElementTypeDTO getType () {
+      return type;
+    }
+
+    public String getValue () {
+      return value;
+    }
+
+       /**
+        * Set a status of 
+        * @param aState knowledge element progress state to set
+        */
+       public void setProgressState(ProgressState aState) {
+               state = aState;
+       }
+       /**
+        * Set a title of the knowledge.
+        * @param aTitle a title to set
+        */
+       public void setTitle(String aTitle) {
+               title = aTitle;
+       }
+       /**
+        * Set the value.
+        * @param value the value to set
+        */
+       public void setValue(String value) {
+               this.value = value;
+       }
+       /**
+        * Get list of involving steps.
+        * @return list of steps
+        */
+       public List<Step> getInvolving() {
+               return involving;
+       }
+       /**
+        * Get title of the parent study.
+        * @return study title
+        */
+       public String getStudyTitle() {
+               return studyTitle;
+       }
+       /**
+        * Get title of the parent scenario.
+        * @return scenario title
+        */
+       public String getScenarioTitle() {
+               return scenarioTitle;
+       }
+
+       /**
+        * Get the rid.
+        * @return the rid
+        */
+       public long getIndex() {
+               return rid;
+       }
+
+       /**
+        * Set the rid.
+        * @param rid the rid to set
+        */
+       public void setIndex(long rid) {
+               this.rid = rid;
+       }
+
+       /**
+        * Set the studyTitle.
+        * @param studyTitle the studyTitle to set
+        */
+       public void setStudyTitle(String studyTitle) {
+               this.studyTitle = studyTitle;
+       }
+
+       /**
+        * Set the scenarioTitle.
+        * @param scenarioTitle the scenarioTitle to set
+        */
+       public void setScenarioTitle(String scenarioTitle) {
+               this.scenarioTitle = scenarioTitle;
+       }
+
+       /**
+        * Set the type.
+        * @param type the type to set
+        */
+       public void setType(KnowledgeElementTypeDTO type) {
+               this.type = type;
+       }
+
+       /**
+        * Set the author.
+        * @param author the author to set
+        */
+       public void setAuthor(UserDTO author) {
+               this.author = author;
+       }
+
+       /**
+        * Set the date.
+        * @param date the date to set
+        */
+       public void setDate(Date date) {
+               this.date = date;
+       }
+}
\ No newline at end of file
diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementTypeDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeElementTypeDTO.java
new file mode 100644 (file)
index 0000000..48cec3b
--- /dev/null
@@ -0,0 +1,82 @@
+package org.splat.service.dto;
+
+/**
+ * Knowledge type DTO.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class KnowledgeElementTypeDTO {
+
+       /**
+        * Type name.
+        */
+       private String name;
+       /**
+        * Persistent id of the type.
+        */
+       private long rid;
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see java.lang.Object#equals(java.lang.Object)
+        */
+       public boolean equals(Object entity) {
+               if (entity == null)
+                       return false;
+               if (entity instanceof String) {
+                       return this.name.equals((String) entity); // Names are unique
+               } else if (entity instanceof KnowledgeElementTypeDTO) {
+                       KnowledgeElementTypeDTO object = (KnowledgeElementTypeDTO) entity;
+                       long he = object.getIndex();
+                       long me = this.getIndex();
+                       if (me * he != 0) {
+                               return (he == me);
+                       } else {
+                               return this.getName().equals(object.getName());
+                       }
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * Get the name of the knowledge type.
+        * 
+        * @return the type name
+        */
+       public String getName() {
+               return name;
+       }
+
+       /**
+        * Get the rid.
+        * 
+        * @return the rid
+        */
+       public long getIndex() {
+               return rid;
+       }
+
+       /**
+        * Set the rid.
+        * 
+        * @param rid
+        *            the rid to set
+        */
+       public void setIndex(long rid) {
+               this.rid = rid;
+       }
+
+       /**
+        * Set the name.
+        * @param name the name to set
+        */
+       public void setName(String name) {
+               this.name = name;
+       }
+}
\ No newline at end of file
diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/RoleDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/RoleDTO.java
new file mode 100644 (file)
index 0000000..5f9966c
--- /dev/null
@@ -0,0 +1,66 @@
+package org.splat.service.dto;
+
+import java.util.Vector;
+
+/**
+ * Role DTO.
+ * 
+ * @see UserDTO
+ */
+public class RoleDTO {
+
+       private String username;
+       private String role;
+
+       // ==============================================================================================================================
+       // Constructors
+       // ==============================================================================================================================
+
+       // Database fetch constructor
+       protected RoleDTO() {
+       }
+
+       // Initialization constructor
+       protected RoleDTO(String username, String role) {
+               this.username = username;
+               this.role = role;
+       }
+
+       // ==============================================================================================================================
+       // Protected member functions
+       // ==============================================================================================================================
+
+       protected void addRole(String role) {
+               this.role = this.role + "," + role;
+       }
+
+       protected RoleDTO[] toArray() {
+               String[] name = role.split(",");
+               Vector<RoleDTO> role = new Vector<RoleDTO>();
+
+               for (int i = 0; i < name.length; i++)
+                       role.add(new RoleDTO(username, name[i]));
+               return role.toArray(new RoleDTO[name.length]);
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+       // In functions below, the role is supposed having previously been extracted as an array.
+
+       public String getName() {
+               return role;
+       }
+
+       public void setName(final String name) {
+               role = name;
+       }
+
+       public boolean is(String name) {
+               return this.role.equals(name);
+       }
+
+       public boolean isSame(RoleDTO other) {
+               return this.role.equals(other.role);
+       }
+}
\ No newline at end of file
diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/UserDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/UserDTO.java
new file mode 100644 (file)
index 0000000..3d2b4c9
--- /dev/null
@@ -0,0 +1,157 @@
+package org.splat.service.dto;
+
+import java.security.Principal;
+import org.splat.kernel.Name;
+
+/**
+ * User DTO.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class UserDTO implements Principal, Name {
+
+       private String password; // Property without getter function
+       private String username; // Unique in the user directory
+       private String first;
+       private String last;
+       private String display; // Optional
+       private RoleDTO role = new RoleDTO(); // Roles as list (as stored into the database)
+       private String email;
+       private String organid;
+
+       /**
+        * Persistent id of the type.
+        */
+       private long rid;
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public boolean equals(Object item) {
+               if (item == null)
+                       return false;
+               if (item instanceof String) {
+                       return this.username.equals((String) item); // Usernames are unique
+               } else if (item instanceof UserDTO) {
+                       UserDTO given = (UserDTO) item;
+                       return (given.username.equals(this.username)); // Usernames are unique
+               } else {
+                       return false;
+               }
+       }
+
+       public String getDisplayName() {
+               if (display == null)
+                       return last + " " + first;
+               else
+                       return display;
+       }
+
+       public String getFirstName() {
+               return first;
+       }
+
+       public void setFirstName(final String name) {
+               first = name;
+       }
+
+       public String getMailAddress() {
+               return email;
+       }
+
+       public void setMailAddress(final String addr) {
+               email = addr;
+       }
+
+       public String getName() {
+               return last;
+       }
+       
+       public void setName(final String name) {
+               last = name;
+       }
+
+       public String getOrganizationName() {
+               return organid;
+       }
+
+       public void setOrganizationName(String name) {
+               organid = name;
+       }
+
+       public String getRoleNames() {
+               return role.getName();
+       }
+
+       public RoleDTO[] getRoles() {
+               return role.toArray();
+       }
+
+       public String getUsername() {
+               return username;
+       }
+
+       public String toString() {
+               return last + " " + first;
+       }
+
+       /**
+        * Get the rid.
+        * 
+        * @return the rid
+        */
+       public long getIndex() {
+               return rid;
+       }
+
+       /**
+        * Set the rid.
+        * 
+        * @param rid
+        *            the rid to set
+        */
+       public void setIndex(long rid) {
+               this.rid = rid;
+       }
+
+       /**
+        * Get the password.
+        * @return the password
+        */
+       public String getPassword() {
+               return password;
+       }
+
+       /**
+        * Set the password.
+        * @param password the password to set
+        */
+       public void setPassword(String password) {
+               this.password = password;
+       }
+
+       /**
+        * Set the username.
+        * @param username the username to set
+        */
+       public void setUsername(String username) {
+               this.username = username;
+       }
+
+       /**
+        * Get the role.
+        * @return the role
+        */
+       public RoleDTO getRole() {
+               return role;
+       }
+
+       /**
+        * Set the role.
+        * @param role the role to set
+        */
+       public void setRole(RoleDTO role) {
+               this.role = role;
+       }
+}
\ No newline at end of file
index c9919c6d56dec343e973d7b20db7c2af4f704ed7..d979f0f126c502e4123c9e4d1ede287cc5d309e1 100644 (file)
@@ -16,7 +16,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.splat.dal.bo.som.ProjectElement;
-import org.splat.service.technical.ProjectSettingsService.Step;
 import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
 
 /**
index 167d41701ea497b8d1b2a3ecddce42a8dc5359d3..4e318662bb7b905da54270c22c9828857c0ab1cc 100644 (file)
@@ -7,46 +7,53 @@
  * @version        $Revision$
  *****************************************************************************/
 
-package org.splat.util; 
+package org.splat.util;
 
 import net.sf.beanlib.provider.BeanTransformer;
 import net.sf.beanlib.provider.replicator.BeanReplicator;
-import net.sf.beanlib.spi.BeanTransformerSpi;
-
 
 /**
- * Helper class for beans.
- * This class supplies :
- *             - methods to copy bean to an other bean
+ * Helper class for beans. This class supplies : - methods to copy bean to an other bean
+ * 
  * @author Maria KRUCHININA
- *
+ * 
  */
 public final class BeanHelper {
-       
+
        /**
         * private constructor to make it abstract.
         */
-       private BeanHelper(){
+       private BeanHelper() {
                super();
        }
-       
+
        /**
         * copy a bean to a bean.
-        * @param <T> the original type
-        * @param <D> the target type
-        * @param from the original bean
-        * @param clazz the destination class
+        * 
+        * @param <T>
+        *            the original type
+        * @param <D>
+        *            the target type
+        * @param from
+        *            the original bean
+        * @param clazz
+        *            the destination class
         * @return an instance of the destination class
         */
-       public static <T,D>D copyBean(final T from,final Class <D> clazz) {
+       public static <T, D> D copyBean(final T from, final Class<D> clazz) {
                D result;
-               
-               if(from == null) {
+
+               if (from == null) {
                        result = null;
                } else {
-                       BeanTransformerSpi transformer = new BeanTransformer(new TimestampTransformerFactory());
-                       BeanReplicator bp = new BeanReplicator(transformer);
-
+                       BeanTransformer bt = new BeanTransformer(
+                                       new TimestampTransformerFactory(),
+                                       new DTOTransformerFactory());
+                       // Don't check parameter types of getters and setters. 
+                       // Find them just by property name.
+                       bt.initDetailedPropertyFilter(null);
+                       
+                       BeanReplicator bp = new BeanReplicator(bt);
                        result = bp.replicateBean(from, clazz);
                }
                return result;
diff --git a/Workspace/Siman-Common/src/org/splat/util/DTOTransformer.java b/Workspace/Siman-Common/src/org/splat/util/DTOTransformer.java
new file mode 100644 (file)
index 0000000..9af8ea4
--- /dev/null
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   05.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.util;
+
+import java.util.Map;
+
+import org.splat.log.AppLogger;
+
+import net.sf.beanlib.PropertyInfo;
+import net.sf.beanlib.spi.BeanTransformerSpi;
+import net.sf.beanlib.spi.CustomBeanTransformerSpi;
+
+/**
+ * DTO transformer used by BeanHelper.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class DTOTransformer implements CustomBeanTransformerSpi {
+
+       /**
+        * The logger for the service.
+        */
+       public final static AppLogger logger = AppLogger
+                       .getLogger(DTOTransformer.class);
+
+       /**
+        * the bean transformer.
+        */
+       private final BeanTransformerSpi _beanTransformer;
+
+       /**
+        * Constructor.
+        * 
+        * @param beanTransformer
+        *            the bean transformer
+        */
+       public DTOTransformer(final BeanTransformerSpi beanTransformer) {
+               _beanTransformer = beanTransformer;
+       }
+
+       /**
+        * 
+        * {@inheritDoc}
+        * 
+        * @see net.sf.beanlib.spi.CustomBeanTransformerSpi#isTransformable(java.lang.Object, java.lang.Class, net.sf.beanlib.PropertyInfo)
+        */
+       public <T> boolean isTransformable(final Object from,
+                       final Class<T> toClass, final net.sf.beanlib.PropertyInfo info) {
+               boolean ok = false;
+               if (from != null) {
+                       String fromName = from.getClass().getSimpleName();
+                       String toName = toClass.getSimpleName();
+                       if (logger.isDebugEnabled()) {
+                               logger.debug("From: " + fromName + "; To: " + toName);
+                               ok = (fromName.equals(toName + "DTO") || toName.equals(fromName
+                                               + "DTO"));
+                       }
+               } else {
+                       if (logger.isDebugEnabled()) {
+                               logger.debug("From: null; To: " + toClass.getSimpleName());
+                       }
+               }
+               if (logger.isDebugEnabled()) {
+                       logger.debug("Can transform from " + info.getFromBean() + "."
+                                       + info.getPropertyName() + " to " + info.getToBean() + "."
+                                       + info.getPropertyName() + ": " + ok);
+               }
+               return ok;
+       }
+
+       /**
+        * 
+        * {@inheritDoc}
+        * 
+        * @see net.sf.beanlib.spi.Transformable#transform(java.lang.Object, java.lang.Class, net.sf.beanlib.PropertyInfo)
+        */
+       public <T> T transform(final Object in, final Class<T> toClass,
+                       final PropertyInfo info) {
+               if (logger.isDebugEnabled()) {
+                       logger.debug("Transform " + in.getClass().getSimpleName() + ": "
+                                       + in.toString() + " to " + toClass.getSimpleName());
+               }
+               Map<Object, Object> cloneMap = _beanTransformer.getClonedMap();
+               Object clone = cloneMap.get(in);
+
+               if (clone != null) {
+                       return (T) clone;
+               }
+
+               if (logger.isDebugEnabled()) {
+                       logger.debug("Copy bean from " + info.getFromBean() + "."
+                                       + info.getPropertyName() + " to " + info.getToBean() + "."
+                                       + info.getPropertyName());
+               }
+               clone = BeanHelper.copyBean(in, toClass);
+               cloneMap.put(in, clone);
+
+               return (T) clone;
+       }
+}
diff --git a/Workspace/Siman-Common/src/org/splat/util/DTOTransformerFactory.java b/Workspace/Siman-Common/src/org/splat/util/DTOTransformerFactory.java
new file mode 100644 (file)
index 0000000..76d75ab
--- /dev/null
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   05.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.util; 
+
+import net.sf.beanlib.spi.BeanTransformerSpi;
+import net.sf.beanlib.spi.CustomBeanTransformerSpi;
+
+/**
+ * Factory for creation DTO transformer(s).
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class DTOTransformerFactory implements CustomBeanTransformerSpi.Factory {
+       
+    /** 
+     * {@inheritDoc}
+     * @see net.sf.beanlib.spi.CustomBeanTransformerSpi$Factory#newCustomBeanTransformer(net.sf.beanlib.spi.BeanTransformerSpi)
+     */
+    public CustomBeanTransformerSpi  newCustomBeanTransformer(BeanTransformerSpi beanTransformer) {
+        return new DTOTransformer(beanTransformer);
+    }
+
+}
+
index 0e5800485172cb2eb144f09f90519bcfb045e185..9dbba557af037b90c6df2d3feee052d5e38acf82 100644 (file)
@@ -48,6 +48,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="indexService" ref="indexService" />
                <property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
                <property name="studyService" ref="studyService" />
+        <property name="projectElementService"
+            ref="projectElementService" />
        </bean>
 
        <bean id="knowledgeElementTypeService"
diff --git a/Workspace/Siman-Common/src/test/splat/util/TestDTOTransformer.java b/Workspace/Siman-Common/src/test/splat/util/TestDTOTransformer.java
new file mode 100644 (file)
index 0000000..8976f39
--- /dev/null
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   12 Oct 2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+package test.splat.util;
+
+import java.util.Date;
+
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
+import org.splat.log.AppLogger;
+import org.splat.service.dto.KnowledgeElementDTO;
+import org.splat.util.BeanHelper;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import test.splat.common.BaseTest;
+
+/**
+ * Test class for DTOTransformer. <BR/> DTOTransformer is intended to be used by BeanHelper for transforming DTO to appropriate BO and vice
+ * versa.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ * 
+ */
+@Test(groups = { "util" })
+public class TestDTOTransformer extends BaseTest {
+
+       /**
+        * Logger for the class.
+        */
+       private static final AppLogger LOG = AppLogger
+                       .getLogger(TestDTOTransformer.class);
+
+       /**
+        * Test transforming a knowledge element to a DTO.<BR>
+        * <B>Description :</B> <BR>
+        * <i>Create a knowledge element BO and transform it to a DTO.</i><BR>
+        * 
+        * <B>Outcome results:</B><BR>
+        * <i>
+        * <ul>
+        * <li>DTO should be filled correctly including date, knoledge type and author properties<BR>
+        * </li>
+        * </ul>
+        * </i>
+        * 
+        * @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
+        * 
+        */
+       @Test
+       public void testBOtoDTO() throws InvalidPropertyException,
+                       MissedPropertyException, MultiplyDefinedException {
+               LOG.debug(">>>>> BEGIN testBOtoDTO()");
+
+               KnowledgeElement aKelm = getKnowledgeElement();
+               KnowledgeElementDTO aDTO = BeanHelper.copyBean(aKelm,
+                               KnowledgeElementDTO.class);
+               Assert.assertEquals(aDTO.getTitle(),
+                               aKelm.getTitle(), "Titles are not equal.");
+               Assert.assertEquals(aDTO.getValue(),
+                               aKelm.getValue(), "Values are not equal.");
+               Assert
+                               .assertNotNull(aDTO.getAuthor(),
+                                               "Author property is not copied.");
+               Assert
+               .assertNotNull(aDTO.getAuthor().getRole(),
+                               "Author.role property is not copied.");
+               Assert.assertEquals(aDTO.getAuthor().getName(),
+                               aKelm.getAuthor().getName(), "Author names are not equal.");
+               Assert.assertNotNull(aDTO.getProgressState(),
+               "ProgressState property is not copied.");
+               Assert.assertEquals(aDTO.getProgressState(),
+                               aKelm.getProgressState(), "Progress states are not equal.");
+               Assert.assertNotNull(aDTO.getType(), "Type property is not copied.");
+               Assert.assertEquals(aDTO.getType().getName(),
+                               aKelm.getType().getName(), "Type names are not equal.");
+               Assert.assertEquals(aDTO.getAuthor().getRoleNames(),
+                               aKelm.getAuthor().getRoleNames(), "Author role names are not equal.");
+               LOG.debug(">>>>> END testBOtoDTO()");
+       }
+
+       /**
+        * Create a transient KnowledgeElement for tests.
+        * 
+        * @return a transient KnowledgeElement
+        * @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
+        */
+       private KnowledgeElement getKnowledgeElement()
+                       throws InvalidPropertyException, MissedPropertyException,
+                       MultiplyDefinedException {
+               // Create a test knowledge type
+
+               KnowledgeElement.Properties kprops = new KnowledgeElement.Properties();
+               KnowledgeElementType aKType = new KnowledgeElementType("TST_kelmtype");
+               // 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);
+               // Create a test study
+               Study.Properties stprops = new Study.Properties().setReference(
+                               "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
+               Study aStudy = new Study(stprops);
+               // Create a test scenario
+               Scenario.Properties sprops = new Scenario.Properties().setTitle(
+                               "TST_Study").setManager(anAuthor).setOwnerStudy(aStudy);
+               Scenario aScenario = new Scenario(sprops);
+               aStudy.getScenariiList().add(aScenario);
+
+               Date aDate = new Date();
+
+               // Prepare a knowledge element transient object
+               kprops
+                               .setTitle("Test knowledge element")
+                               .setAuthor(anAuthor)
+                               .setOwnerScenario(aScenario)
+                               .setType(aKType)
+                               .setDate(aDate)
+                               .setValue(
+                                               "This is the test knowledge element.\nIt is created by the unit test.");
+
+               return new KnowledgeElement(kprops);
+       }
+}
index 7b56bc4c3d9e579374c1d201bd4169892606929d..71e8bb1822d4226f687c00d9105ed562e626a5a0 100644 (file)
@@ -13,6 +13,7 @@ import org.apache.struts2.interceptor.ServletRequestAware;
 import org.apache.struts2.interceptor.SessionAware;
 import org.apache.log4j.Logger;
 import org.splat.dal.bo.kernel.User;
+import org.splat.service.dto.KnowledgeElementDTO;
 import org.splat.som.ApplicationRights;
 import org.splat.som.StudyRights;
 import org.splat.dal.bo.som.KnowledgeElement;
@@ -171,7 +172,7 @@ public class Action extends ActionSupport implements ServletRequestAware, Sessio
 //     _openStudy = (OpenStudy)session.get("study.open");
           return _openStudy;                       // May be null
         }
-    protected OpenKnowledge open (KnowledgeElement kelm) {
+    protected OpenKnowledge open (KnowledgeElementDTO kelm) {
       OpenKnowledge open = _openKnowledge.open(kelm);
 
       closeKnowledge();   // Just in case
@@ -255,7 +256,7 @@ public class Action extends ActionSupport implements ServletRequestAware, Sessio
         getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
     }
     
-    /**s
+    /**
      * Initialization the Context for Menu Bar and Tool Bar.
      * 
      * @param titleProperty - The title of the open study/knowledge.
index 2495f13922482ee79a06622eb9594629d582a840..339742c4407a163c58434736d060dece32624574 100644 (file)
@@ -4,6 +4,7 @@ import java.util.List;
 
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.service.KnowledgeElementService;
+import org.splat.service.dto.KnowledgeElementDTO;
 import org.splat.som.Step;
 
 public class DisplayKnowledgeAction extends DisplayBaseAction {
@@ -60,14 +61,14 @@ public class DisplayKnowledgeAction extends DisplayBaseAction {
 
        public String doOpen() {
                myknelm = getOpenKnowledge();
-               if (myindex != null)
+               if (myindex != null) {
                        try { // Opening a knowledge from the search result
                                int index = Integer.valueOf(myindex);
                                if (myknelm != null && myknelm.getIndex() == index) { // - The selected knowledge is currently open
                                        selection = myknelm.getSelection(); // Current selection
                                } else { // - The selected knowledge is new
-                                       KnowledgeElement kelm = getKnowledgeElementService()
-                                                       .selectKnowledgeElement(index);
+                                       KnowledgeElementDTO kelm = getKnowledgeElementService()
+                                                       .getKnowledgeElement(index);
                                        myknelm = open(kelm);
                                        selection = myknelm.getSelection(); // Default selection
                                }
@@ -75,9 +76,9 @@ public class DisplayKnowledgeAction extends DisplayBaseAction {
                                logger.error("Reason:", error);
                                return ERROR;
                        }
-               else if (selection != null) { // Re-opening (refreshing) the currently open knowledge
-                       KnowledgeElement kelm = getKnowledgeElementService()
-                                       .selectKnowledgeElement(myknelm.getIndex());
+               else if (selection != null) { // Re-opening (refreshing) the currently open knowledge
+                       KnowledgeElementDTO kelm = getKnowledgeElementService()
+                                       .getKnowledgeElement(myknelm.getIndex());
                        myknelm = open(kelm); // Closes the previously open knowledge
                        myknelm.setSelection(selection);
                }
index aa647707b1699a8e67ce634970bc363bf953cd89..63e7fff7e632f2cc4591989adc7a08c6c4429c3d 100644 (file)
@@ -5,23 +5,38 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
-import java.util.Vector;
 
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
-import org.splat.service.ProjectElementService;
-import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.dto.KnowledgeElementDTO;
 import org.splat.som.Step;
 import org.splat.wapp.SimpleMenu;
 
+/**
+ * Open knowledge details for presentation.
+ */
 public class OpenKnowledge extends OpenObject {
 
-       private KnowledgeElement myknelm;
+       /**
+        * The open knowledge element DTO.
+        */
+       private KnowledgeElementDTO myknelm = new KnowledgeElementDTO();
+       /**
+        * Creation date.
+        */
        private String credate;
+
+       /**
+        * Knowledge element left menu.
+        */
        public class Menu extends SimpleMenu {
-               // ------------------------------------
+               /**
+                * Build menu from the list of study steps.
+                * 
+                * @param context
+                *            the list of steps
+                */
                public Menu(List<Step> context) {
                        super("steps", "study");
                        int i = 0;
@@ -47,22 +62,30 @@ public class OpenKnowledge extends OpenObject {
        // Constructor
        // ==============================================================================================================================
 
-       public OpenKnowledge open (KnowledgeElement knelm) {
-               // ---------------------------------------------
+       /**
+        * Set the given knowledge as currently open.
+        * 
+        * @param knelm
+        *            the knowledge element DTO
+        * @return the open knowledge presentation
+        */
+       public OpenKnowledge open(KnowledgeElementDTO knelm) {
                ResourceBundle label = ResourceBundle.getBundle("labels",
                                getApplicationSettings().getCurrentLocale());
                ResourceBundle custom = ResourceBundle.getBundle("som",
                                getApplicationSettings().getCurrentLocale());
-               SimpleDateFormat convert = new SimpleDateFormat(
-                               custom.getString("date.format"));
+               SimpleDateFormat convert = new SimpleDateFormat(custom
+                               .getString("date.format"));
                StringBuffer value = new StringBuffer(knelm.getValue());
-               Scenario scene = knelm.getOwnerScenario();
+               String sceneTitle = knelm.getScenarioTitle();
+               String studyTitle = knelm.getStudyTitle();
 
                myknelm = knelm;
 
                // Preparation of the display
                credate = convert.format(myknelm.getDate());
-               involving = getAllSteps(knelm.getOwnerScenario());
+               // involving = getAllSteps(knelm.getOwnerScenario());
+               involving = knelm.getInvolving();
                context = new ArrayList<SimulationContextFacade>();
                menu = new Menu(getInvolvedSteps());
                selection = menu.getSelection(); // The default selection is set in the menu definition
@@ -73,15 +96,17 @@ public class OpenKnowledge extends OpenObject {
                                ustep = next;
                        for (Iterator<SimulationContext> j = next
                                        .getAllSimulationContexts().iterator(); j.hasNext();) {
-                               context.add(new SimulationContextFacade(j.next(), getProjectSettings().getAllSteps()));
+                               context.add(new SimulationContextFacade(j.next(),
+                                               getProjectSettings().getAllSteps()));
                        }
                }
-               value.append("<p>").append("<b>")
-                               .append(label.getString("label.source")).append(":</b>")
-                               .append("<br>").append(label.getString("label.study"))
-                               .append("&nbsp\"").append(scene.getOwnerStudy().getTitle())
-                               .append("\",").append("<br>").append(scene.getTitle())
-                               .append(".").append("</p>");
+               value.append("<p>").append("<b>").append(
+                               label.getString("label.source")).append(":</b>").append("<br>")
+                               .append(label.getString("label.study")).append("&nbsp\"")
+                               .append(studyTitle/* scene.getOwnerStudy().getTitle() */)
+                               .append("\",").append("<br>")
+                               .append(sceneTitle/* scene.getTitle() */).append(".").append(
+                                               "</p>");
                description = value.toString();
                setupContents(); // Initializes documents and knowledge at ustep
                return this;
@@ -92,54 +117,44 @@ public class OpenKnowledge extends OpenObject {
        // ==============================================================================================================================
 
        public String getAuthorName() {
-               // -----------------------------
                return myknelm.getAuthor().toString();
        }
 
        public String getDate() {
-               // ------------------------
                return credate;
        }
 
        public Long getIndex() {
-               // -------------------------
                return myknelm.getIndex();
        }
 
        public Menu getMenu() {
-               // ----------------------
                return (Menu) menu;
        }
 
        public ProgressState getProgressState() {
-               // ---------------------------------------
                return myknelm.getProgressState();
        }
 
        public String getReference() {
-               // ----------------------------
                return myknelm.getReference();
        }
 
-       public KnowledgeElement getKnowledgeObject() {
-               // ---------------------------------------------
+       public KnowledgeElementDTO getKnowledgeObject() {
                return myknelm;
        }
 
        public String getTitle() {
-               // ------------------------
                return myknelm.getTitle();
        }
 
        public String getType() {
-               // ------------------------
                return ResourceBundle.getBundle("som",
                                getApplicationSettings().getCurrentLocale()).getString(
                                "type.knowledge." + myknelm.getType().getName());
        }
 
        public void setSelection(String step) {
-               // --------------------------------------
                selection = step;
                int index = Integer.valueOf(selection);
                for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
@@ -150,33 +165,4 @@ public class OpenKnowledge extends OpenObject {
                menu.selects(selection);
                setupContents(); // The contents may have changed even if the selection is the same
        }
-
-       // ==============================================================================================================================
-       // Private services
-       // ==============================================================================================================================
-
-       private List<Step> getAllSteps(Scenario scenar) {
-               // ------------------------------------------------
-               Vector<Step> result = new Vector<Step>();
-               Step[] step = getProjectElementService().getSteps(scenar);
-
-               int base = step[0].getNumber();
-               int last = step[step.length - 1].getNumber();
-               for (int i = 0; i < step.length; i++) {
-                       result.add(step[i]);
-               }
-               step = getProjectElementService().getSteps(scenar.getOwnerStudy());
-               for (int i = step.length - 1; i > -1; i--) {
-                       if (step[i].getNumber() >= base)
-                               continue;
-                       result.add(0, step[i]);
-               }
-               for (int i = 0; i < step.length; i++) {
-                       if (step[i].getNumber() <= last)
-                               continue;
-                       result.add(step[i]);
-               }
-               return result;
-       }
-
 }
\ No newline at end of file
index 8231fa5016f0580780ff0ea0482b21a798d444a2..a4a9bdd8620849413df519b4b6d977f6402f4ee3 100644 (file)
@@ -28,17 +28,44 @@ public abstract class OpenObject implements Proxy {
        protected static HashMap<Long, DocumentFacade> docpres = null;
        protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
 
-       protected User cuser = null; // Connected user
-       protected String selection = null; // Menu selected by the user
-       protected Step ustep = null; // Corresponding selected step
-       protected String description = null; // Object description (rich text)
+       /**
+        * Connected user.
+        */
+       protected User cuser = null;
+       /**
+        * Menu selected by the user.
+        */
+       protected String selection = null;
+       /**
+        * Corresponding selected step.
+        */
+       protected Step ustep = null;
+       /**
+        * Object description (rich text).
+        */
+       protected String description = null;
        protected List<Step> involving = new ArrayList<Step>();
+       /**
+        * Simulation Context display representations.
+        */
        protected List<SimulationContextFacade> context = new ArrayList<SimulationContextFacade>(); // Simulation Context display representations
-       protected List<DocumentFacade> contents = null; // Document display representations
-       protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
+       /**
+        * Document display representations.
+        */
+       protected List<DocumentFacade> contents = null;
+       /**
+        * Knowledge Element display representations structured by knowledge types.
+        */
+       protected List<KnowledgeIterator> knowledge = null;
 
-       protected Menu menu = null; // Left pane menu of this object
-       protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
+       /**
+        * Left pane menu of this object.
+        */
+       protected Menu menu = null;
+       /**
+        * Pop-up menu of this object, if the user has write access.
+        */
+       protected PopupMenu popup = null;
        /**
         * Injected project settings service.
         */