--- /dev/null
+<!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>
<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>
// -------------------------
return last + " " + first;
}
+ /**
+ * Get the role.
+ * @return the role
+ */
+ public Role getRole() {
+ return role;
+ }
}
\ No newline at end of file
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;
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.
*/
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.
*
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;
/**
* Injected study service.
*/
private StudyService _studyService;
+ /**
+ * Injected project element service.
+ */
+ private ProjectElementService _projectElementService;
/**
* {@inheritDoc}
/**
* 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) {
*
* @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;
}
/**
* Get the studyService.
+ *
* @return the studyService
*/
public StudyService getStudyService() {
/**
* 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;
+ }
}
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;
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
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;
/**
* @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;
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+
+}
+
<property name="indexService" ref="indexService" />
<property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
<property name="studyService" ref="studyService" />
+ <property name="projectElementService"
+ ref="projectElementService" />
</bean>
<bean id="knowledgeElementTypeService"
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+}
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;
// _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
getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
}
- /**s
+ /**
* Initialization the Context for Menu Bar and Tool Bar.
*
* @param titleProperty - The title of the open study/knowledge.
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 {
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
}
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);
}
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;
// 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
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(" \"").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(" \"")
+ .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;
// ==============================================================================================================================
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();) {
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
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.
*/