]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
refactoring
authormka <mka@opencascade.com>
Fri, 12 Oct 2012 06:34:36 +0000 (06:34 +0000)
committermka <mka@opencascade.com>
Fri, 12 Oct 2012 06:34:36 +0000 (06:34 +0000)
24 files changed:
Workspace/Siman-Common/lib/beanlib-5.0.1beta.jar [new file with mode: 0644]
Workspace/Siman-Common/lib/commons-logging-1.1.1.jar [new file with mode: 0644]
Workspace/Siman-Common/src/conf/log-messages.properties [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/AbstractException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/LockAlreadyExistsException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/LockNotExistsException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/LockOutdatedException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/LockProtectedException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/log/AppLogger.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/LockService.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/LockServiceImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/UtilService.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/UtilServiceImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/util/BeanHelper.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/util/TimestampTransformer.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/util/TimestampTransformerFactory.java [new file with mode: 0644]
Workspace/Siman-Common/src/spring/globalContext.xml
Workspace/Siman/src/org/splat/simer/NewStudyAction.java
Workspace/Siman/src/spring/applicationContext.xml
Workspace/Siman/src/struts.xml

diff --git a/Workspace/Siman-Common/lib/beanlib-5.0.1beta.jar b/Workspace/Siman-Common/lib/beanlib-5.0.1beta.jar
new file mode 100644 (file)
index 0000000..f26062d
Binary files /dev/null and b/Workspace/Siman-Common/lib/beanlib-5.0.1beta.jar differ
diff --git a/Workspace/Siman-Common/lib/commons-logging-1.1.1.jar b/Workspace/Siman-Common/lib/commons-logging-1.1.1.jar
new file mode 100644 (file)
index 0000000..8758a96
Binary files /dev/null and b/Workspace/Siman-Common/lib/commons-logging-1.1.1.jar differ
diff --git a/Workspace/Siman-Common/src/conf/log-messages.properties b/Workspace/Siman-Common/src/conf/log-messages.properties
new file mode 100644 (file)
index 0000000..974cf9e
--- /dev/null
@@ -0,0 +1,5 @@
+#Lock service exception values
+LCK-000001=Lock reference already exists for user {2}.
+LCK-000002=Lock reference does not exists.
+LCK-000003=Lock reference protected and can be only deleted or updated by user {2}.
+LCK-000004=Lock reference is timeout and could have been modified by user {2}.
\ No newline at end of file
diff --git a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
new file mode 100644 (file)
index 0000000..6c1950b
--- /dev/null
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   03.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.common.properties; 
+
+/**
+ * Enumeration of all exception's code.
+ * Values are in the src/conf/log-messages.properties file.
+ * @author Maria KRUCHININA
+ *
+ */
+public enum MessageKeyEnum {
+       
+       /**
+        * Lock reference already exists for user {2}.
+        */
+       LCK_000001("LCK-000001"),
+       /**
+        * Lock reference does not exists.
+        */
+       LCK_000002("LCK-000002"),
+       /**
+        * Lock reference protected and can be only deleted or updated by user {2}.
+        */
+       LCK_000003("LCK-000003"),
+       /**
+        * Lock reference is timeout and could have been modified by user {2}.
+        */
+       LCK_000004("LCK-000004");
+       
+       /**
+       * Value.
+       */
+       private final String _value;
+               
+       /**
+       * The enum contructor with param(s).
+       * @param value The value
+       */
+       MessageKeyEnum(final String value) {
+               this._value = value;
+       }
+        
+       /** 
+       * {@inheritDoc}
+       * @see java.lang.Enum#toString()
+       */
+       @Override
+       public String toString() {
+               return this._value;
+       }
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/exception/AbstractException.java b/Workspace/Siman-Common/src/org/splat/exception/AbstractException.java
new file mode 100644 (file)
index 0000000..0f8ae1e
--- /dev/null
@@ -0,0 +1,166 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.exception; 
+
+import org.splat.i18n.I18nUtils;
+
+/**
+ * Superclass for all SIMAN application exceptions.
+ * @author Maria KRUCHININA
+ *
+ */
+public class AbstractException extends Exception {
+
+       /**
+        * serial id.
+        */
+       private static final long serialVersionUID = -96254753042743175L;
+
+       /**
+        * message key to write to user interface.
+        */
+       private String _messageKey = null;
+
+       /**
+        * message key to write to user interface.
+        */
+       private Object[] _context = new Object[0];
+
+       /**
+        * default constructor.
+        */
+       public AbstractException() {
+               super();
+       }
+
+       /**
+        * constructor with one parameter :the original throwable.
+        * 
+        * @param throwable
+        *            the original throwable
+        * @see java.lang.Exception#Exception(Throwable)
+        */
+       public AbstractException(final Throwable throwable) {
+               super(throwable);
+       }
+
+       /**
+        * constructor with two parameters : - the message - a throwable.
+        * 
+        * @param message
+        *            the error message
+        * @param throwable
+        *            the original throwable
+        * @see java.lang.Exception#Exception(String, Throwable)
+        */
+       public AbstractException(final String message, final Throwable throwable) {
+               super(I18nUtils.getMessageLocaleDefault(message), throwable);
+               this._messageKey = message;
+       }
+
+       /**
+        * Build a ServiceException with message, user message key, and throwable.
+        * CAUTION: this only works with 1 log-messages.properties 
+        * 
+        * @param messageKey
+        *            the User Interface Message Key
+        * @param throwable
+        *            the original exception
+        * @param context
+        *            the execution context
+        */
+       public AbstractException(final String messageKey,
+                       final Throwable throwable, final Object... context) {
+               // read the CAUTION above
+               super(I18nUtils.getMessageLocaleDefault(messageKey, context), throwable);
+               this._messageKey = messageKey;
+               this._context = context.clone();
+
+       }
+
+       /**
+        * Build a ServiceException with message, user message key and context.
+        * CAUTION: this only works with 1 log-messages.properties 
+        * 
+        * @param messageKey
+        *            the User Interface Message Key
+        * @param context
+        *            the execution context
+        */
+       public AbstractException(final String messageKey, final Object... context) {
+               // read the CAUTION above
+               super(I18nUtils.getMessageLocaleDefault(messageKey, context));
+               this._messageKey = messageKey;
+               this._context = context.clone();
+       }
+
+       /**
+        * get the exception message key.
+        * 
+        * @return the messageKey
+        */
+       public String getMessageKey() {
+               return _messageKey;
+       }
+
+       /**
+        * set the exception message key.
+        * 
+        * @param key
+        *            the messageKey to set
+        */
+       public void setMessageKey(final String key) {
+               _messageKey = key;
+       }
+
+       /**
+        * get the context.
+        * 
+        * @return the context
+        */
+       public Object[] getContext() {
+               return _context.clone();
+       }
+
+       /**
+        * Converts the object context array into a string array.
+        * @return a string array
+        */
+       public String[] getContextAsStringArray() {
+               String[] result = null;
+               
+               if (null != _context) {
+                       result = 
+                               new String[_context.length];
+                       int i = 0;
+                       for (Object o : _context) {
+                               if (null == o) {
+                                       result[i] = null;
+                               } else {
+                                       result[i] = o.toString();
+                               }
+                               i++;
+                       }
+               } 
+               
+               return result;
+       }
+
+       /**
+        * set the context.
+        * 
+        * @param context
+        *            the context to set
+        */
+       public void setContext(final Object[] context) {
+               this._context = context.clone();
+       }
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/exception/LockAlreadyExistsException.java b/Workspace/Siman-Common/src/org/splat/exception/LockAlreadyExistsException.java
new file mode 100644 (file)
index 0000000..b87884a
--- /dev/null
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+package org.splat.exception; 
+
+import org.splat.common.properties.MessageKeyEnum;
+
+/**
+ *
+ * Exception thrown when a lock already exists for another one.
+ * @author Maria KRUCHININA
+ *
+ */
+public class LockAlreadyExistsException extends AbstractException {
+       
+       /**
+        * loginName of a user who has already locked an object.
+        */
+       private String _loginName;
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+
+       /**
+        * Create a LockAlreadyExistsException.
+        * 
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param pLogin The plogin of the user identified by the user ID
+        */
+       public LockAlreadyExistsException(final String tableUid, final String rowUid, final String pLogin) {
+               super(MessageKeyEnum.LCK_000001.toString(), tableUid, rowUid, pLogin);
+               _loginName = pLogin;
+       }
+
+       /**
+        * Create a LockAlreadyExistsException.
+        * 
+        * @param throwable the cause
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param pLogin The plogin of the user identified by the user ID
+        */
+       public LockAlreadyExistsException(final Throwable throwable, final String tableUid, final String rowUid, final String pLogin) {
+               super(MessageKeyEnum.LCK_000001.toString(),throwable, tableUid, rowUid, pLogin);
+               _loginName = pLogin;
+       }
+
+       /**
+        * Create a LockAlreadyExistsException.
+        * 
+        * @param throwable
+        *            the original LockAlreadyExistsException
+        * @param msgKey
+        *            the message key
+        * @param objName
+        *            the object name
+        */
+       public LockAlreadyExistsException(
+                       final LockAlreadyExistsException throwable, final String msgKey,
+                       final String objName) {
+               super(msgKey, throwable, objName, throwable.getLoginName());
+               _loginName = throwable.getLoginName();
+       }
+
+
+       /**
+        * Get the loginName of a user who has already locked an object.
+        * @return the loginName
+        */
+       public final String getLoginName() {
+               return _loginName;
+       }
+
+       /**
+        * Set the loginName of a user who has already locked an object.
+        * @param loginName the loginName to set
+        */
+       public final void setLoginName(final String loginName) {
+               _loginName = loginName;
+       }
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/exception/LockNotExistsException.java b/Workspace/Siman-Common/src/org/splat/exception/LockNotExistsException.java
new file mode 100644 (file)
index 0000000..0084884
--- /dev/null
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   03.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision:
+ *****************************************************************************/
+
+package org.splat.exception; 
+
+import org.splat.common.properties.MessageKeyEnum;
+
+/**
+ * Exception thrown when lock does not exist.
+ * @author Maria KRUCHININA
+ *
+ */
+public class LockNotExistsException extends AbstractException {
+       
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+
+       /**
+        * Create a LockNotExistsException.
+        * 
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        */
+       public LockNotExistsException(final String tableUid, final String rowUid) {
+               super(MessageKeyEnum.LCK_000002.toString(), tableUid, rowUid);
+       }
+
+       /**
+        * Create a LockNotExistsException.
+        * 
+        * @param throwable the cause
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        */
+       public LockNotExistsException(final Throwable throwable, final String tableUid, final String rowUid) {
+               super(MessageKeyEnum.LCK_000002.toString(),throwable, tableUid, rowUid);
+       }
+
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/exception/LockOutdatedException.java b/Workspace/Siman-Common/src/org/splat/exception/LockOutdatedException.java
new file mode 100644 (file)
index 0000000..1d73311
--- /dev/null
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   03.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision:
+ *****************************************************************************/
+
+package org.splat.exception; 
+
+import org.splat.common.properties.MessageKeyEnum;
+
+/**
+ * Exception thrown when lock on object is timeout and can't be updated because
+ * object is outdated (obsolete).
+ * 
+ * @author Maria KRUCHININA
+ *
+ */
+public class LockOutdatedException extends AbstractException {
+
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+
+       /**
+        * Create a LockOutdatedException.
+        * 
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param userUid the user ID
+        */
+       public LockOutdatedException(final String tableUid, final String rowUid, final String userUid) {
+               super(MessageKeyEnum.LCK_000004.toString(), tableUid, rowUid, userUid);
+       }
+
+       /**
+        * Create a LockOutdatedException.
+        * 
+        * @param throwable the cause
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param userUid the user ID
+        */
+       public LockOutdatedException(final Throwable throwable, final String tableUid, final String rowUid, final String userUid) {
+               super(MessageKeyEnum.LCK_000004.toString(),throwable, tableUid, rowUid, userUid);
+       }
+}
diff --git a/Workspace/Siman-Common/src/org/splat/exception/LockProtectedException.java b/Workspace/Siman-Common/src/org/splat/exception/LockProtectedException.java
new file mode 100644 (file)
index 0000000..54bf663
--- /dev/null
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   03.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision:
+ *****************************************************************************/
+
+package org.splat.exception; 
+
+import org.splat.common.properties.MessageKeyEnum;
+
+/**
+ * Exception thrown when a lock has another one and can't be deleted, created 
+ * or updated.
+ * @author Maria KRUCHININA
+ *
+ */
+public class LockProtectedException extends AbstractException {
+
+       /**
+        * Version id for serialization.
+        */
+       private static final long serialVersionUID = -4596111071538834057L;
+
+       /**
+        * Create a LockProtectedException.
+        * 
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param userUid the user ID
+        */
+       public LockProtectedException(final String tableUid, final String rowUid, final String userUid) {
+               super(MessageKeyEnum.LCK_000003.toString(), tableUid, rowUid, userUid);
+       }
+
+       /**
+        * Create a LockProtectedException.
+        * 
+        * @param throwable the cause
+        * @param tableUid the table name uid 
+        * @param rowUid the row uid 
+        * @param userUid the user ID
+        */
+       public LockProtectedException(final Throwable throwable, final String tableUid, final String rowUid, final String userUid) {
+               super(MessageKeyEnum.LCK_000003.toString(),throwable, tableUid, rowUid, userUid);
+       }
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java b/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java
new file mode 100644 (file)
index 0000000..5f3b06e
--- /dev/null
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.i18n; 
+
+import java.util.Locale;
+import org.springframework.context.support.ResourceBundleMessageSource;
+
+/**
+ * Resource bundle utility methods.
+ * 
+ * @author Maria KRUCHININA
+ *
+ */
+public final class I18nUtils {
+
+       /**
+        * Contains the list of resources bundle. 
+        */
+       private static ResourceBundleMessageSource _resourceBundleMessageSource;
+       
+       /**
+        * .
+        * @param locale Locale
+        * @param code key
+        * @return message i18n
+        */
+       public static String getMessage(final Locale locale, final String code) {
+               return getMessage(locale, code, new Object[0]);
+       }
+       
+       /**
+        * .
+        * @param locale Locale
+        * @param code key
+        * @param context args
+        * @return message i18n
+        */
+       public static String getMessage(final Locale locale, final String code, final Object... context) {
+               return _resourceBundleMessageSource.getMessage(code, context, locale);
+       }
+       
+       
+       /**
+        * Return the translated message of a code with the language.
+        * @param language lowercase two-letter ISO-639 code
+        * @param code code
+        * @param context parameters
+        * @return Translated message
+        */
+       public static String getMessage(final String language, final String code, final Object... context) {
+               Locale locale = new Locale(language);
+               return getMessage(locale, code, context);
+       }       
+       
+       
+       /**
+        * Return the translated message of a code with the locale default.
+        * @param code code
+        * @param context parameters
+        * @return Translated message
+        */
+       public static String getMessageLocaleDefault(final String code, final Object... context) {
+               return getMessage(Locale.getDefault(), code, context);
+       }       
+       
+       
+       /**
+        * Get the resourceBundleMessageSource.
+        * @return the resourceBundleMessageSource
+        */
+       protected ResourceBundleMessageSource getResourceBundleMessageSource() {
+               return _resourceBundleMessageSource;
+       }
+       /**
+        * Set the resourceBundleMessageSource.
+        * @param resourceBundleMessageSource the resourceBundleMessageSource to set
+        */
+       public void setResourceBundleMessageSource(
+                       final ResourceBundleMessageSource resourceBundleMessageSource) {
+               _resourceBundleMessageSource = resourceBundleMessageSource;
+       }       
+       
+}
diff --git a/Workspace/Siman-Common/src/org/splat/log/AppLogger.java b/Workspace/Siman-Common/src/org/splat/log/AppLogger.java
new file mode 100644 (file)
index 0000000..7463e6f
--- /dev/null
@@ -0,0 +1,275 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   02.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.log; 
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.splat.i18n.I18nUtils;
+
+/**
+ * 
+ * Application Logger.
+ * This class supply methods to log app messages
+ * @author Maria KRUCHININA
+ *
+ */
+
+public class AppLogger {
+
+       // logger common logging
+       /** The logger. */
+       protected transient Log _logger = null;
+
+       /**
+        * Constructor with a class param.
+        * 
+        * @param categorie criteria to choose the logger to use
+        * 
+        * @return the logger
+        */
+       public static AppLogger getLogger(final Class<?> categorie) {
+               return new AppLogger(LogFactory.getLog(categorie));
+       }
+
+       /**
+        * Constructor with a String param.
+        * 
+        * @param categorie the categorie
+        * 
+        * @return the logger
+        */
+       public static AppLogger getLogger(final String categorie) {
+               return new AppLogger(LogFactory.getLog(categorie));
+       }
+
+       /**
+        * protected parameter.
+        * 
+        * @param logger the logger
+        */
+       protected AppLogger(final Log logger) {
+               _logger = logger;
+       }
+
+       // Fatal
+
+       /**
+        * Log a fatal message.
+        * 
+        * @param code the message code/key
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void fatal(final String code, final Object... context) {
+               _logger.fatal(formatMessage(code, context));
+       }
+
+       /**
+        * Log a fatal message.
+        * 
+        * @param code the message code/key
+        * @param exception the exception which originated the message
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void fatal(final String code, final Exception exception, final Object... context) {
+               _logger.fatal(formatMessage(code, context), exception);
+       }
+
+       /**
+        * Log a fatal message.
+        * 
+        * @param msg the message
+        * @param exc the exc
+        */
+       public void fatalMsg(final String msg, final Exception exc) {
+               _logger.fatal(msg, exc);
+       }
+
+       /**
+        * Log a fatal message.
+        * 
+        * @param msg the message
+        */
+       public void fatalMsg(final String msg) {
+               _logger.fatal(msg);
+       }
+
+       // Error
+
+       /**
+        * Log an error message.
+        * 
+        * @param code the message code/key
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void error(final String code, final Object... context) {
+               _logger.error(formatMessage(code, context));
+       }
+
+       /**
+        * Log an error message.
+        * 
+        * @param code the message code/key
+        * @param exception the exception which originated the message
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void error(final String code, final Exception exception, final Object... context) {
+               _logger.error(formatMessage(code, context), exception);
+       }
+
+       /**
+        * Log an error message.
+        * 
+        * @param msg the message
+        */
+       public void errorMsg(final String msg) {
+               _logger.error(msg);
+       }
+
+       /**
+        * Log an error message.
+        * 
+        * @param msg the message
+        * @param exception the exception
+        */
+       public void errorMsg(final String msg, final Exception exception) {
+               _logger.error(msg, exception);
+       }
+
+       // Warn
+
+       /**
+        * Log a warning message.
+        * 
+        * @param code the message code/key
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void warn(final String code, final Object... context) {
+               _logger.warn(formatMessage(code, context));
+       }
+
+       /**
+        * Log a warning message.
+        * 
+        * @param code the message code/key
+        * @param exception the exception which originated the message
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void warn(final String code, final Exception exception, final Object... context) {
+               _logger.warn(formatMessage(code, context), exception);
+       }
+
+       /**
+        * Log an error message.
+        * 
+        * @param msg the message
+        */
+       public void warnMsg(final String msg) {
+               _logger.warn(msg);
+       }
+
+       /**
+        * Log an error message.
+        * 
+        * @param msg the message
+        * @param exception the exception
+        */
+       public void warnMsg(final String msg, final Exception exception) {
+               _logger.warn(msg, exception);
+       }
+
+       
+       // Info
+
+       /**
+        * Log an info message.
+        * 
+        * @param code the message code/key
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void info(final String code, final Object... context) {
+               _logger.info(formatMessage(code, context));
+       }
+
+       /**
+        * Log an info message.
+        * 
+        * @param code the message code/key
+        * @param exception the exception which originated the message
+        * @param context the message context (used to complete {0..n} elements)
+        */
+       public void info(final String code, final Exception exception, final Object... context) {
+               _logger.info(formatMessage(code, context), exception);
+       }
+
+       // Debug
+
+       /**
+        * Allows to check if DEBUG logging level is enabled.
+        * 
+        * @return <b>true</b> if DEBUG logging level is enabled and <b>false</b> otherwise 
+        */
+       public boolean isDebugEnabled() {
+               return _logger.isDebugEnabled();
+       }
+
+       /**
+        * Log a debug message.
+        * 
+        * @param exception the exception which originated the message
+        * @param message the message
+        */
+       public void debug(final String message, final Exception exception) {
+               _logger.debug(message, exception);
+       }
+
+       /**
+        * Log a debug message.
+        * 
+        * @param message the message
+        */
+       public void debug(final String message) {
+               _logger.debug(message);
+       }
+
+       /**
+        * Log a debug message.
+        * 
+        * @param context the message context (used to complete {0..n} elements)
+        * @param messageFormat the message format
+        */
+       public void debug(final String messageFormat, final Object... context) {
+               _logger.debug(String.format(messageFormat, context));
+       }
+
+       // Utils methods
+       /**
+        * format the message from the code and context.
+        * 
+        * @param code the message code/key
+        * @param context the message context (used to complete {0..n} elements)
+        * 
+        * @return the formated message
+        */
+       public String formatMessage(final String code, final Object... context) {
+               String translatedMessage;
+               String tempCode = code;
+               try {
+                       translatedMessage = I18nUtils.getMessageLocaleDefault(code, context);
+               } catch (Exception e) {
+                       translatedMessage = "Translation error for code: ?" + code + "?";
+                       _logger.error(translatedMessage, e);
+
+                       if (tempCode == null) {
+                               tempCode = "null";
+                       }
+               }
+               return new StringBuffer(tempCode).append(": ").append(translatedMessage).toString();
+       }
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/LockService.java b/Workspace/Siman-Common/src/org/splat/service/LockService.java
new file mode 100644 (file)
index 0000000..dc5f695
--- /dev/null
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.service; 
+
+import org.splat.exception.LockAlreadyExistsException;
+import org.splat.exception.LockNotExistsException;
+import org.splat.exception.LockOutdatedException;
+import org.splat.exception.LockProtectedException;
+
+/**
+ * Service interface class for lock management.
+ * @author mka
+ *
+ */
+public interface LockService {
+
+       /**
+        * Lock a data row or update lock on a data row for one user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockAlreadyExistsException when a lock already exists for row uid and another user id
+        */
+       void lock(final String rowUid, final String tableUid, final String userUid) throws LockAlreadyExistsException;
+       
+       /**
+        * Unlock a data row for one user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockNotExistsException when lock does not exist
+        * @throws LockProtectedException lock exists for another user
+        */
+       void unlock(final String rowUid, final String tableUid, final String userUid) throws LockNotExistsException, LockProtectedException;
+
+       /**
+        * Unlock all datas rox for one user.
+        * @param userUid User uid
+        */
+       void unlockAll(final String userUid);
+       
+       /**
+        * Check lock on a data row in a table for a user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockNotExistsException when lock does not exist
+        * @throws LockProtectedException lock exists for another user
+        * @throws LockOutdatedException when lock on object is in timeout but the
+        * owner of lock is another user
+        */
+       void check(final String rowUid, final String tableUid, final String userUid) throws LockNotExistsException, LockProtectedException, LockOutdatedException;
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/LockServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/LockServiceImpl.java
new file mode 100644 (file)
index 0000000..f4561a4
--- /dev/null
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   02.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.service; 
+
+import org.splat.exception.LockAlreadyExistsException;
+import org.splat.exception.LockNotExistsException;
+import org.splat.exception.LockOutdatedException;
+import org.splat.exception.LockProtectedException;
+import org.splat.log.AppLogger;
+
+/**
+ * @author Maria KRUCHININA
+ *
+ */
+public class LockServiceImpl implements LockService {
+       
+       /**
+        * logger.
+        */
+       private final static AppLogger LOG = AppLogger.getLogger(LockService.class);
+
+       /**
+        * Lock timeout period in milliseconds. A 24 hours by default.
+        */
+       private long _timeoutPeriod = 86400000L;
+
+       /**
+        * Lock a data row or update lock on a data row for one user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockAlreadyExistsException when a lock already exists for row uid and another user id
+        */
+       public void lock(final String rowUid, final String tableUid, final String userUid) throws LockAlreadyExistsException {
+               //TODO:
+       }
+       
+       /**
+        * Unlock a data row for one user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockNotExistsException when lock does not exist
+        * @throws LockProtectedException lock exists for another user
+        */
+       public void unlock(final String rowUid, final String tableUid, final String userUid) throws LockNotExistsException, LockProtectedException {
+               //TODO:
+       }
+
+       /** 
+        * Unlock all datas rox for one user.
+        * @param userUid User uid
+        */
+       @Override
+       public void unlockAll(String userUid) {
+               // TODO Auto-generated method stub
+
+       }
+       
+       /**
+        * Check lock on a data row in a table for a user.
+        * @param rowUid Row uid
+        * @param tableUid Table uid
+        * @param userUid User uid
+        * @throws LockNotExistsException when lock does not exist
+        * @throws LockProtectedException lock exists for another user
+        * @throws LockOutdatedException when lock on object is in timeout but the
+        * owner of lock is another user
+        */
+       public void check(final String rowUid, final String tableUid, final String userUid) throws LockNotExistsException, LockProtectedException, LockOutdatedException {
+               //TODO:
+       }
+       
+
+}
index d697bb41a75de5ff4eb6fc9b5d8bef9273b3b879..ad509b380bfc92edf588313aaeb86248d0580b83 100644 (file)
@@ -1,14 +1,15 @@
 /*****************************************************************************
  * Company         EURIWARE
  * Application     SIMAN
- * File            $Id$ 
- * Creation date   06.10.2012
- * @author         $Author$
- * @version        $Revision$
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
  *****************************************************************************/
 
 package org.splat.service;
 
+import java.util.List;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Publication;
@@ -22,11 +23,19 @@ import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 
 /**
- * @author RKV
- * 
+ * This class defines all methods for creation, modification the study.
+ * @author Maria KRUCHININA
+ *
  */
 public interface StudyService {
-
+       
+       /**
+        * Get the simulation context list for displaying drop-down list values populating
+        * on the "Create new study" screen.
+        * @return List of the simulation contexts.
+        */
+       List<SimulationContext> getSimulationContextList();
+       
        public int generateLocalIndex(Study aStudy);
 
        public Study selectStudy(int index);
index d0b9a56c0f5a9369f9cfeb5f7470544522f4c39d..ce6f0b16ba90fb4d8a2b6b7e228abd7086c019ac 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * Company         EURIWARE
  * Application     SIMAN
- * File            $Id$ 
- * Creation date   06.10.2012
- * @author         $Author$
- * @version        $Revision$
+ * File            Id: 
+ * Creation date   02.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
  *****************************************************************************/
 
 package org.splat.service;
@@ -17,6 +17,7 @@ import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.hibernate.Session;
+import org.hibernate.Transaction;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ActorRelation;
@@ -31,6 +32,7 @@ import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.ValidationCycleRelation;
@@ -46,11 +48,15 @@ import org.splat.service.technical.ProjectSettingsService;
 import org.splat.som.Revision;
 
 /**
- * @author RKV
- * 
+ * This class defines all methods for creation, modification the study.
+ * @author Maria KRUCHININA
+ *
  */
 public class StudyServiceImpl implements StudyService {
 
+       /**
+        * logger for the service.
+        */
        public final static Logger logger = Logger.getLogger(org.splat.service.StudyServiceImpl.class);
 
        private IndexService _indexService;
@@ -62,7 +68,27 @@ public class StudyServiceImpl implements StudyService {
        private ProjectSettingsService _projectSettingsService;
 
        private ProjectElementService _projectElementService;
-
+       
+       /**
+        * Get the simulation context list for displaying drop-down list values populating
+        * on the "Create new study" screen.
+        * {@inheritDoc}
+        * @see org.splat.service.StudyService#getSimulationContextList()
+        */
+       public List<SimulationContext> getSimulationContextList() {
+               //TODO: remove the commit transaction ...
+               Session      connex  = Database.getSession();
+               Transaction  transax = connex.beginTransaction();
+               
+               SimulationContext.Properties cprop   = new SimulationContext.Properties();
+           SimulationContextType        product = SimulationContext.selectType("product");
+           List<SimulationContext> resList = Database.selectSimulationContextsWhere(cprop.setType(product));
+           
+           transax.commit();
+                 
+           return resList;
+       }
+       
        public Study selectStudy(int index) {
                // -------------------------------------------
                StringBuffer query = new StringBuffer("from Study where rid='").append(
diff --git a/Workspace/Siman-Common/src/org/splat/service/UtilService.java b/Workspace/Siman-Common/src/org/splat/service/UtilService.java
new file mode 100644 (file)
index 0000000..a00f13d
--- /dev/null
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   08.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.service; 
+
+
+
+/**
+ * @author Maria KRUCHININA
+ *
+ */
+public interface UtilService {
+       /**
+        * Get the connected user.
+        * @return User - the user.
+        */
+       //User getConnectedUser(final Map<String, Object>  session);
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/UtilServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/UtilServiceImpl.java
new file mode 100644 (file)
index 0000000..a4562d6
--- /dev/null
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   08.10.2012
+ * @author         Author: Maria KRUCHININA
+ * @version        Revision: 
+ *****************************************************************************/
+
+package org.splat.service; 
+
+import java.util.Map;
+
+import org.splat.log.AppLogger;
+import org.splat.som.ApplicationRights;
+
+/**
+ * @author Maria KRUCHININA
+ *
+ */
+public class UtilServiceImpl implements UtilService {
+       
+       /**
+        * logger for the service.
+        */
+       private static final AppLogger LOG = AppLogger.getLogger(UtilServiceImpl.class);
+
+       /**
+        * Get the connected user.
+        * {@inheritDoc}
+        * @see org.splat.service.UtilService#getConnectedUser(java.util.Map)
+        */
+       /*public  User getConnectedUser (final Map<String, Object>  session) {
+           ApplicationRights  rights = (ApplicationRights)session.get("user.rights");
+           return rights.getUser();                                           // May be null
+       }*/
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/util/BeanHelper.java b/Workspace/Siman-Common/src/org/splat/util/BeanHelper.java
new file mode 100644 (file)
index 0000000..bc565a0
--- /dev/null
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   05.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+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
+ * @author Maria KRUCHININA
+ *
+ */
+public final class BeanHelper {
+       
+       /**
+        * private constructor to make it abstract.
+        */
+       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
+        * @return an instance of the destination class
+        */
+       public static <T,D>D copyBean(final T from,final Class <D> clazz) {
+               D result;
+               
+               if(from == null) {
+                       result = null;
+               } else {
+                       BeanTransformerSpi transformer = new BeanTransformer(new TimestampTransformerFactory());
+                       BeanReplicator bp = new BeanReplicator(transformer);
+
+                       result = bp.replicateBean(from, clazz);
+               }
+               return result;
+       }
+
+}
diff --git a/Workspace/Siman-Common/src/org/splat/util/TimestampTransformer.java b/Workspace/Siman-Common/src/org/splat/util/TimestampTransformer.java
new file mode 100644 (file)
index 0000000..00cdf22
--- /dev/null
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   05.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.util; 
+
+import java.sql.Timestamp;
+import java.util.Map;
+
+import net.sf.beanlib.PropertyInfo;
+import net.sf.beanlib.spi.BeanTransformerSpi;
+import net.sf.beanlib.spi.CustomBeanTransformerSpi;
+
+/**
+ * the timsetamp transformer used by BeanHelper.
+ * @author Maria KRUCHININA
+ *
+ */
+public class TimestampTransformer implements CustomBeanTransformerSpi{
+
+       /**
+        * the bean transformer.
+        */
+       private final BeanTransformerSpi _beanTransformer;
+       
+       /**
+        * Constructor.
+        * @param beanTransformer the bean transformer
+        */
+       public TimestampTransformer(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)
+       {
+               return ((from instanceof Timestamp) && (toClass == Timestamp.class));
+       }
+
+       /**
+        * 
+        * {@inheritDoc}
+        * @see net.sf.beanlib.spi.Transformable#transform(java.lang.Object, java.lang.Class, net.sf.beanlib.PropertyInfo)
+        */
+       @SuppressWarnings("unchecked")
+       public <T> T transform(final Object in, final Class<T> toClass, final PropertyInfo info)
+       {
+               Map<Object,Object> cloneMap = _beanTransformer.getClonedMap();
+               Object clone = cloneMap.get(in);
+
+               if (clone != null)
+               {
+                       return (T)clone;
+               }
+               
+               Timestamp date = (Timestamp)in;
+               clone = new Timestamp(date.getTime());
+               
+               ((Timestamp)clone).setNanos(date.getNanos());
+               cloneMap.put(in, clone);
+               
+               return (T)clone;
+       }
+}
diff --git a/Workspace/Siman-Common/src/org/splat/util/TimestampTransformerFactory.java b/Workspace/Siman-Common/src/org/splat/util/TimestampTransformerFactory.java
new file mode 100644 (file)
index 0000000..ef9f2c8
--- /dev/null
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * 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;
+
+/**
+ * @author Maria KRUCHININA
+ *
+ */
+public class TimestampTransformerFactory implements CustomBeanTransformerSpi.Factory {
+       
+    public CustomBeanTransformerSpi  newCustomBeanTransformer(BeanTransformerSpi beanTransformer) {
+        return new TimestampTransformer(beanTransformer);
+    }
+
+}
+
index a2487f77d3e567b6fe9c03d758870fdb76aa0822..bc9b67ae74e53cb5ba99f3e06ce8a73f0aaf326d 100644 (file)
@@ -14,6 +14,15 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
+       <bean id="baseMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
+               <property name="basenames">
+                       <list>
+                               <value>application</value>
+                               <value>log-messages</value>
+                       </list>
+               </property>
+       </bean>
+
        <!--    <bean id="simanDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                <property name="jndiName" value="jdbc/ibatis"/>
                </bean> -->
index 22f4a0bd53fef9e478e1634d6e991ab38254ca1f..7d81c008366924739d9815eb1c1b8f47757c0ead 100644 (file)
@@ -22,29 +22,28 @@ public class NewStudyAction extends Action {
        private static int number = 0;
        private static final long serialVersionUID = 693943641800113782L;
 
+       
+       /**
+        * The Study service.
+        */
        private StudyService _studyService;
 
        // ==============================================================================================================================
        // Action methods
        // ==============================================================================================================================
 
-       public String doInitialize() {
-               // -----------------------------
-               Session connex = Database.getSession();
-               Transaction transax = connex.beginTransaction();
-
-               SimulationContext.Properties cprop = new SimulationContext.Properties();
-               SimulationContextType product = SimulationContext.selectType("product");
-               ResourceBundle locale = ResourceBundle.getBundle("labels",
-                               ApplicationSettings.getCurrentLocale());
-
-               contelm = Database
-                               .selectSimulationContextsWhere(cprop.setType(product));
-               title = locale.getString("label.study") + " "
-                               + String.valueOf(number + 1);
-               transax.commit();
-               return SUCCESS;
-       }
+       //Fill the values of the drop-down list. 
+    public String doInitialize () {            
+       
+      //get the list of the simulation contexts of the study
+      contelm = _studyService.getSimulationContextList();
+       
+      //set the default name of the new study
+      ResourceBundle locale  = ResourceBundle.getBundle("labels", ApplicationSettings.getCurrentLocale());
+      title = locale.getString("label.study") + " " + String.valueOf(number + 1);
+               
+      return SUCCESS;
+    }
 
        public String doCreate() throws Exception {
                // -------------------------
index 6ca12a4f3b94bdebc29482d3e8e4d5bd27f6f74c..efe62eb1539456e35f7fa15bff423dd34176458c 100644 (file)
@@ -6,8 +6,28 @@
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/aop  
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
-
-       <bean id="applicationSettings"
+           
+           
+       <!-- configuration i18n -->
+       <bean id="i18nUtils"
+               class="org.splat.i18n.I18nUtils">
+               <property name="resourceBundleMessageSource"
+                       ref="messageSource" />
+       </bean>
+
+       <bean id="messageSource"
+               class="org.springframework.context.support.ResourceBundleMessageSource">
+               <property name="basenames">
+                       <list>
+                               <value>application</value>
+                               <value>log-messages</value>
+                       </list>
+               </property>
+       </bean>
+    <!-- ref 'baseMessageSource' into Siman-common\src\spring\globalContext.xml -->
+       <!-- property name="parentMessageSource" ref="baseMessageSource"/-->
+       
+               <bean id="applicationSettings"
                class="org.splat.simer.ApplicationSettings">
                <property name="projectSettings" ref="projectSettings" />
        </bean>
index 65f7873257f33127f5c323274d8569d82708be0c..629874f315baf30a33f174004d90e442e9144a57 100644 (file)
@@ -8,7 +8,7 @@
        <constant name="struts.objectFactory" value="spring" />
     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
     <constant name="struts.devMode" value="true" />
-    <constant name="struts.custom.i18n.resources" value="labels,som" />
+    <constant name="struts.custom.i18n.resources" value="log-messages,labels,som" />
     <constant name="struts.i18n.encoding" value="ISO-8859-1" />
 
     <package name="simer-default" namespace="/" extends="struts-default">