From: rkv Date: Fri, 23 Nov 2012 13:27:38 +0000 (+0000) Subject: Fixes for checkin and user creation. X-Git-Tag: Root_Delivery1_2012_12_06~47 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=61a41c23149e40774365a74a9ea6fe824f60104c;p=tools%2Fsiman.git Fixes for checkin and user creation. --- diff --git a/Workspace/Siman-Common/src/conf/log-messages.properties b/Workspace/Siman-Common/src/conf/log-messages.properties index dfee6a4..3f69b0f 100644 --- a/Workspace/Siman-Common/src/conf/log-messages.properties +++ b/Workspace/Siman-Common/src/conf/log-messages.properties @@ -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 diff --git a/Workspace/Siman-Common/src/conf/log-messages_en.properties b/Workspace/Siman-Common/src/conf/log-messages_en.properties index dfee6a4..3f69b0f 100644 --- a/Workspace/Siman-Common/src/conf/log-messages_en.properties +++ b/Workspace/Siman-Common/src/conf/log-messages_en.properties @@ -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 diff --git a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java index 0d4b54a..e7b4366 100644 --- a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java +++ b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java @@ -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. */ diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 0337209..470504c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -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); diff --git a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java index 862f30e..5b7848f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java @@ -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 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)); } } } diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java index 6830946..adc8a36 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -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()) { diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index ed044b3..4be2632 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -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 index 0000000..ea77d9e --- /dev/null +++ b/Workspace/Siman-Common/testng_checkin.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + +