--- /dev/null
+#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
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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();
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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:
+ }
+
+
+}
/*****************************************************************************
* 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;
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);
/*****************************************************************************
* 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 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;
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;
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;
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(
--- /dev/null
+/*****************************************************************************
+ * 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);
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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
+ }*/
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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);
+ }
+
+}
+
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> -->
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 {
// -------------------------
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>
<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">