]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Fixes for checkin and user creation.
authorrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 13:27:38 +0000 (13:27 +0000)
committerrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 13:27:38 +0000 (13:27 +0000)
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/conf/log-messages_en.properties
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java
Workspace/Siman-Common/testng_checkin.xml [new file with mode: 0644]

index dfee6a49a8e1b49dbc959bd0c055c6faa2920ac9..3f69b0feea780ecd2182d3c777b83423b0453581 100644 (file)
@@ -6,6 +6,9 @@ LCK-000004=Lock reference is timeout and could have been modified by user {2}.
 STD-000001=Unable to re-index the study #{1}, reason: {2}
 SCN-000001=Scenario doesn't contain the step number #{1}
 SCN-000002=Scenario doesn't contain the document #{1}
+SCN-000003=The existing file {1} has been deleted when check-in the scenario #{2}
+SCN-000004=Can not delete the existing destination file to move file from {1} to {2} when check-in the scenario #{3}
+SCN-000005=Can not move file from {1} to {2} when check-in the scenario #{3}
 KNT-000001=Knowledge element type "{1}" already exists
 SCT-000001=Simulation context type "{1}" already exists
 DCT-000001=Document type "{1}" already exists
index dfee6a49a8e1b49dbc959bd0c055c6faa2920ac9..3f69b0feea780ecd2182d3c777b83423b0453581 100644 (file)
@@ -6,6 +6,9 @@ LCK-000004=Lock reference is timeout and could have been modified by user {2}.
 STD-000001=Unable to re-index the study #{1}, reason: {2}
 SCN-000001=Scenario doesn't contain the step number #{1}
 SCN-000002=Scenario doesn't contain the document #{1}
+SCN-000003=The existing file {1} has been deleted when check-in the scenario #{2}
+SCN-000004=Can not delete the existing destination file to move file from {1} to {2} when check-in the scenario #{3}
+SCN-000005=Can not move file from {1} to {2} when check-in the scenario #{3}
 KNT-000001=Knowledge element type "{1}" already exists
 SCT-000001=Simulation context type "{1}" already exists
 DCT-000001=Document type "{1}" already exists
index 0d4b54aaaa726c1f1776b730441852e23e63634e..e7b4366c0d2ad0fce110bce36c2002bc0fd97a8a 100644 (file)
@@ -45,6 +45,18 @@ public enum MessageKeyEnum {
         * Scenario doesn't contain the document #{1}.
         */
        SCN_000002("SCN-000002"),
+       /**
+        * The existing file {1} has been deleted when check-in the scenario #{2}.
+        */
+       SCN_000003("SCN-000003"),
+       /**
+        * Can not delete the existing destination file to move file from {1} to {2} when check-in the scenario #{3}.
+        */
+       SCN_000004("SCN-000004"),
+       /**
+        * Can not move file from {1} to {2} when check-in the scenario #{3}.
+        */
+       SCN_000005("SCN-000005"),
        /**
         * Simulation context type "{1}" already exists.
         */
index 03372095f9e647b0884b15b234e6630b8efa8d7e..470504c5bb47980e111905be5098b3065afd5442 100644 (file)
@@ -18,7 +18,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
 import org.splat.common.properties.MessageKeyEnum;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
@@ -44,6 +43,7 @@ import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.NotApplicableException;
+import org.splat.log.AppLogger;
 import org.splat.service.dto.DocumentDTO;
 import org.splat.service.dto.FileDTO;
 import org.splat.service.dto.StepDTO;
@@ -61,9 +61,9 @@ import org.springframework.transaction.annotation.Transactional;
 public class ScenarioServiceImpl implements ScenarioService {
 
        /**
-        * Logger for this class.
+        * The logger for the service.
         */
-       protected final static Logger LOG = Logger
+       public final static AppLogger LOG = AppLogger
                        .getLogger(ScenarioServiceImpl.class);
 
        /**
@@ -480,15 +480,30 @@ public class ScenarioServiceImpl implements ScenarioService {
 
                                        // Attach the file to the created document
                                        updir = newPub.getSourceFile().asFile();
-                                       if (LOG.isInfoEnabled()) {
-                                               LOG.info("Moving \"" + upfile.getName() + "\" to \""
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Moving \"" + upfile.getName() + "\" to \""
                                                                + updir.getPath() + "\".");
                                        }
+                                       if (updir.exists()) {
+                                               if (updir.delete()) {
+                                                       LOG.info(MessageKeyEnum.SCN_000003.toString(),
+                                                                       updir.getAbsoluteFile(), scenId);
+                                               } else {
+                                                       throw new IOException(
+                                                                       "Can't delete the existing destination file to move file from "
+                                                                                       + file.getPath() + " to "
+                                                                                       + updir.getAbsolutePath());
+                                               }
+                                       }
                                        if (upfile.renameTo(updir)) {
                                                // Save the new publication in the scenario.
                                                // The old publication is removed from the scenario here.
                                                getPublicationService().saveAs(newPub,
                                                                ProgressState.inWORK); // May throw FileNotFound if rename was not done
+                                       } else {
+                                               throw new IOException("Can't move file from "
+                                                               + file.getPath() + " to "
+                                                               + updir.getAbsolutePath());
                                        }
                                }
                        }
@@ -499,7 +514,7 @@ public class ScenarioServiceImpl implements ScenarioService {
                // For each new version copy uses relations from the previous version.
                for (Publication newVer : newVers) {
                        // For each Uses relation of the previous version
-                       Document prevDoc = newVer.value().getPreviousVersion();//prevVersion.get(newVer);
+                       Document prevDoc = newVer.value().getPreviousVersion();// prevVersion.get(newVer);
                        if (LOG.isDebugEnabled()) {
                                LOG.debug("Previous version for publication #"
                                                + newVer.getIndex() + " is found: " + prevDoc);
index 862f30e50709d00718ac42ebc01d4784fe9e7ead..5b7848ff3e7d6883c57f5de92e27f5ef99b87138 100644 (file)
@@ -68,6 +68,12 @@ public class UserServiceImpl implements UserService {
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException, RuntimeException {
                User nuser = new User(uprop);
+               // Do merge to synchronize Role object with the current hibernate session
+               // and to avoid th exception:
+               // org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the
+               // session: [org.splat.dal.bo.kernel.Role#simer]
+               getUserDAO().merge(nuser);
+               
                getUserDAO().create(nuser);
                return nuser;
        }
@@ -113,11 +119,11 @@ public class UserServiceImpl implements UserService {
                                if (members.contains(uname)) {
                                        continue; // This user already exists
                                }
-                               uprop.setUsername(uname)
-                                               .setFirstName(row.get("first").getTextContent())
-                                               .setName(row.get("last").getTextContent())
-                                               .setMailAddress(row.get("mail").getTextContent())
-                                               .addRole(row.get("role").getTextContent()); // Add all roles at a time
+                               uprop.setUsername(uname).setFirstName(
+                                               row.get("first").getTextContent()).setName(
+                                               row.get("last").getTextContent()).setMailAddress(
+                                               row.get("mail").getTextContent()).addRole(
+                                               row.get("role").getTextContent()); // Add all roles at a time
 
                                // Optional properties
                                org.w3c.dom.Node node = row.get("password");
@@ -141,13 +147,13 @@ public class UserServiceImpl implements UserService {
                        return imported;
                } catch (IOException error) {
                        LOG.debug(error.getMessage(), error);
-                       throw new XMLException("XML users file not found"); //RKV: NOPMD: Original message is printed
+                       throw new XMLException("XML users file not found"); // RKV: NOPMD: Original message is printed
                } catch (ParserConfigurationException e) {
                        LOG.debug(e.getMessage(), e);
-                       throw new XMLException("XML Organization parser not accessible"); //RKV: NOPMD: Original message is printed
+                       throw new XMLException("XML Organization parser not accessible"); // RKV: NOPMD: Original message is printed
                } catch (Exception e) {
                        LOG.debug(e.getMessage(), e);
-                       throw new XMLException("XML users file not valid"); //RKV: NOPMD: Original message is printed
+                       throw new XMLException("XML users file not valid"); // RKV: NOPMD: Original message is printed
                }
        }
 
@@ -206,13 +212,11 @@ public class UserServiceImpl implements UserService {
                // but this requires a getPassword in User.Properties nested class.
                Criterion aCondition = Restrictions.eq("username", username);
                if (password == null) {
-                       aCondition = Restrictions.and(aCondition,
-                                       Restrictions.isNull("password"));
+                       aCondition = Restrictions.and(aCondition, Restrictions
+                                       .isNull("password"));
                } else {
-                       aCondition = Restrictions.and(
-                                       aCondition,
-                                       Restrictions.eq("password",
-                                                       String.valueOf(password.hashCode())));
+                       aCondition = Restrictions.and(aCondition, Restrictions.eq(
+                                       "password", String.valueOf(password.hashCode())));
                }
                return getUserDAO().findByCriteria(aCondition);
        }
@@ -224,21 +228,21 @@ public class UserServiceImpl implements UserService {
 
        @SuppressWarnings("unchecked")
        public List<User> selectUsersWhere(final User.Properties... uprop) {
-//             StringBuffer query = new StringBuffer("FROM User");
-//             String separator = " where (";
-//             String value;
-//
-//             for (int i = 0; i < uprop.length; i++) {
-//
-//                     value = uprop[i].getOrganizationName();
-//                     if (value != null) {
-//                             query = query.append(separator).append(" organid='")
-//                                             .append(value).append("'");
-//                             // separator = " and";
-//                     }
-//                     separator = ") or (";
-//             }
-//             query.append(")");
+               // StringBuffer query = new StringBuffer("FROM User");
+               // String separator = " where (";
+               // String value;
+               //
+               // for (int i = 0; i < uprop.length; i++) {
+               //
+               // value = uprop[i].getOrganizationName();
+               // if (value != null) {
+               // query = query.append(separator).append(" organid='")
+               // .append(value).append("'");
+               // // separator = " and";
+               // }
+               // separator = ") or (";
+               // }
+               // query.append(")");
                Criterion aCondition = null;
                String value;
                for (int i = 0; i < uprop.length; i++) {
@@ -247,7 +251,8 @@ public class UserServiceImpl implements UserService {
                                if (aCondition == null) {
                                        aCondition = Restrictions.eq("organid", value);
                                } else {
-                                       aCondition = Restrictions.or(aCondition, Restrictions.eq("organid", value));
+                                       aCondition = Restrictions.or(aCondition, Restrictions.eq(
+                                                       "organid", value));
                                }
                        }
                }
index 6830946e56aed99223542cea343f079c3310e779..adc8a361f74f9e2369270ff6291bcd26354c9cd9 100644 (file)
@@ -37,6 +37,7 @@ import org.splat.manox.XDOM;
 import org.splat.service.DocumentTypeService;
 import org.splat.service.KnowledgeElementTypeService;
 import org.splat.service.SimulationContextTypeService;
+import org.springframework.transaction.annotation.Transactional;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -225,6 +226,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @throws SQLException
         *             if there is a database population problem
         */
+       @Transactional
        public void configure(final String filename) throws IOException,
                        SQLException {
                if (!_steps.isEmpty()) {
index ed044b3ae8f8fc1d0cb1d9c0d932e0569bf869e7..4be263288c0a933929309c49a8504beb429789e0 100644 (file)
@@ -303,7 +303,7 @@ public class TestScenarioService extends BaseTest {
         * @throws MismatchException
         *             if checkin failed
         */
-       @Test
+       @Test(groups = {"checkin", "sevice", "functional", "business"})
        public void testCheckin() throws InvalidPropertyException,
                        MissedPropertyException, MultiplyDefinedException, IOException,
                        SQLException, MismatchException, NotApplicableException {
@@ -343,7 +343,7 @@ public class TestScenarioService extends BaseTest {
                // Check that new document versions are created for checked in documents
                for (StepDTO step : stepsToCheckin) {
                        for (DocumentDTO docDTO : step.getDocs()) {
-                               if (docDTO.getId() != 0) {
+                               if ((docDTO.getId() != 0) && (docDTO.getId() != null)) {
                                        boolean found = false;
                                        Document prevDoc = null;
                                        Publication newPub = null;
@@ -358,7 +358,7 @@ public class TestScenarioService extends BaseTest {
                                                }
                                        }
                                        Assert.assertTrue(found,
-                                                       "New version of existing checked in document \""
+                                                       "New version of the existing checked in document \""
                                                                        + docDTO.getTitle() + "\" (id="
                                                                        + docDTO.getId()
                                                                        + ") is not found in the scenario.");
@@ -552,7 +552,7 @@ public class TestScenarioService extends BaseTest {
                                                "noreply@salome-platform.org");
                uprop.disableCheck();
                User anAuthor = new User(uprop);
-               ht.save(anAuthor);
+               ht.saveOrUpdate(anAuthor);
 
                // Create a test study
                Study.Properties stprops = new Study.Properties().setReference(
diff --git a/Workspace/Siman-Common/testng_checkin.xml b/Workspace/Siman-Common/testng_checkin.xml
new file mode 100644 (file)
index 0000000..ea77d9e
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanCommonTests" verbose="1">
+       <test name="all">
+               <method-selectors>
+                       <method-selector>
+                               <script language="beanshell">
+                                       <![CDATA[
+                (groups.containsKey("checkin")) && method.getName().toUpperCase().startsWith("TEST")             
+              ]]>
+                               </script>
+                       </method-selector>
+               </method-selectors>
+        <groups>
+            <!-- 
+                <define name="all">
+                <include name="business"/>
+                <include name="functional"/>
+                <include name="service"/>
+                </define>
+                <define name="new">
+                <include name="newservice"/>
+                </define>
+                <run>
+                <include name="all"/>
+                <exclude name="old"/>
+                </run>
+            -->
+
+        </groups>
+               <packages>
+                       <package name="test.*" />
+               </packages>
+       </test>
+</suite>