From: rkv Date: Mon, 3 Dec 2012 06:07:26 +0000 (+0000) Subject: Document name is generated now for new documents during checkin. Unit test is updated... X-Git-Tag: Root_Delivery1_2012_12_06~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6aa0788ecdb5449f2cc19256750aeb77f3df3dd5;p=tools%2Fsiman.git Document name is generated now for new documents during checkin. Unit test is updated. During checkout applet calls to the server for checkout before launching an executable module. For that the new checkoutAction is created and the new checkout method is added to ScenarioService. Log messages configuration is fixed. Close study bug is fixed (in french locale the URL of the link was invalid). --- diff --git a/Workspace/Siman-Common/src/conf/log-messages.properties b/Workspace/Siman-Common/src/conf/log-messages.properties index 3f69b0f..8669c7b 100644 --- a/Workspace/Siman-Common/src/conf/log-messages.properties +++ b/Workspace/Siman-Common/src/conf/log-messages.properties @@ -1,14 +1,18 @@ #Lock service exception values -LCK-000001=Lock reference already exists for user {2}. +LCK-000001=Lock reference already exists for user {0}. 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}. -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 +LCK-000003=Lock reference protected and can be only deleted or updated by user {0}. +LCK-000004=Lock reference is timeout and could have been modified by user {0}. +STD-000001=Unable to re-index the study #{0}, reason: {1} +SCN-000001=Scenario doesn't contain the step number #{0} +SCN-000002=Scenario doesn't contain the document #{0} +SCN-000003=The existing file {0} has been deleted when check-in the scenario #{0} +SCN-000004=Can not delete the existing destination file to move file from {0} to {1} when check-in the scenario #{2} +SCN-000005=Can not move file from {0} to {1} when check-in the scenario #{2} +SCN-000006=Scenario #{0} is not found +SCN-000007=The user {0} does not participate in the scenario #{1} +SCN-000008=The scenario #{0} is already checked out by the user {1} +USR-000001=User {0} is not found in the database +KNT-000001=Knowledge element type "{0}" already exists +SCT-000001=Simulation context type "{0}" already exists +DCT-000001=Document type "{0}" 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 3f69b0f..8669c7b 100644 --- a/Workspace/Siman-Common/src/conf/log-messages_en.properties +++ b/Workspace/Siman-Common/src/conf/log-messages_en.properties @@ -1,14 +1,18 @@ #Lock service exception values -LCK-000001=Lock reference already exists for user {2}. +LCK-000001=Lock reference already exists for user {0}. 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}. -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 +LCK-000003=Lock reference protected and can be only deleted or updated by user {0}. +LCK-000004=Lock reference is timeout and could have been modified by user {0}. +STD-000001=Unable to re-index the study #{0}, reason: {1} +SCN-000001=Scenario doesn't contain the step number #{0} +SCN-000002=Scenario doesn't contain the document #{0} +SCN-000003=The existing file {0} has been deleted when check-in the scenario #{0} +SCN-000004=Can not delete the existing destination file to move file from {0} to {1} when check-in the scenario #{2} +SCN-000005=Can not move file from {0} to {1} when check-in the scenario #{2} +SCN-000006=Scenario #{0} is not found +SCN-000007=The user {0} does not participate in the scenario #{1} +SCN-000008=The scenario #{0} is already checked out by the user {1} +USR-000001=User {0} is not found in the database +KNT-000001=Knowledge element type "{0}" already exists +SCT-000001=Simulation context type "{0}" already exists +DCT-000001=Document type "{0}" 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 e7b4366..ce03ca8 100644 --- a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java +++ b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java @@ -18,7 +18,7 @@ package org.splat.common.properties; public enum MessageKeyEnum { /** - * Lock reference already exists for user {2}. + * Lock reference already exists for user {0}. */ LCK_000001("LCK-000001"), /** @@ -26,47 +26,63 @@ public enum MessageKeyEnum { */ LCK_000002("LCK-000002"), /** - * Lock reference protected and can be only deleted or updated by user {2}. + * Lock reference protected and can be only deleted or updated by user {0}. */ LCK_000003("LCK-000003"), /** - * Lock reference is timeout and could have been modified by user {2}. + * Lock reference is timeout and could have been modified by user {0}. */ LCK_000004("LCK-000004"), /** - * Unable to re-index the study #{1}, reason: {2}. + * Unable to re-index the study #{0}, reason: {1}. */ STD_000001("STD-000001"), /** - * Scenario doesn't contain the step number #{1}. + * Scenario doesn't contain the step number #{0}. */ SCN_000001("SCN-000001"), /** - * Scenario doesn't contain the document #{1}. + * Scenario doesn't contain the document #{0}. */ SCN_000002("SCN-000002"), /** - * The existing file {1} has been deleted when check-in the scenario #{2}. + * The existing file {0} has been deleted when check-in the scenario #{1}. */ SCN_000003("SCN-000003"), /** - * Can not delete the existing destination file to move file from {1} to {2} when check-in the scenario #{3}. + * Can not delete the existing destination file to move file from {0} to {1} when check-in the scenario #{2}. */ SCN_000004("SCN-000004"), /** - * Can not move file from {1} to {2} when check-in the scenario #{3}. + * Can not move file from {0} to {1} when check-in the scenario #{2}. */ SCN_000005("SCN-000005"), /** - * Simulation context type "{1}" already exists. + * SCN-000006=Scenario #{0} is not found. + */ + SCN_000006("SCN-000006"), + /** + * SCN-000007=The user {0} does not participate in the scenario #{1}. + */ + SCN_000007("SCN-000007"), + /** + * SCN-000008=The scenario #{0} is already checked out by the user {1}. + */ + SCN_000008("SCN-000008"), + /** + * USR-000001=User {0} is not found in the database. + */ + USR_000001("USR-000001"), + /** + * Simulation context type "{0}" already exists. */ KNT_000001("KNT-000001"), /** - * Knowledge element type "{1}" already exists. + * Knowledge element type "{0}" already exists. */ SCT_000001("SCT-000001"), /** - * Document type "{1}" already exists. + * Document type "{0}" already exists. */ DCT_000001("DCT-000001"); diff --git a/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java b/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java index 690574e..5ba5f37 100644 --- a/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java +++ b/Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java @@ -11,6 +11,7 @@ package org.splat.i18n; import java.util.Locale; +import org.springframework.context.NoSuchMessageException; import org.springframework.context.support.ResourceBundleMessageSource; /** @@ -68,7 +69,13 @@ public final class I18nUtils { * @return Translated message */ public static String getMessageLocaleDefault(final String code, final Object... context) { - return getMessage(Locale.getDefault(), code, context); + String res = ""; + try { + res = getMessage(Locale.getDefault(), code, context); + } catch (NoSuchMessageException nsme) { + res = getMessage(new Locale(""), code, context); + } + return res; } diff --git a/Workspace/Siman-Common/src/org/splat/kernel/NotApplicableException.java b/Workspace/Siman-Common/src/org/splat/kernel/NotApplicableException.java index 26b8116..6848e36 100644 --- a/Workspace/Siman-Common/src/org/splat/kernel/NotApplicableException.java +++ b/Workspace/Siman-Common/src/org/splat/kernel/NotApplicableException.java @@ -22,4 +22,12 @@ public class NotApplicableException extends BusinessException { public NotApplicableException (final String message) { super(message); } + + /** + * @param messageKey + * @param context + */ + public NotApplicableException(final String messageKey, final Object... context) { + super(messageKey, context); + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java index de0ed29..9087b19 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioService.java @@ -154,6 +154,21 @@ public interface ScenarioService { */ boolean checkout(Scenario aScenario, User user); + /** + * Mark the given scenario as checked out by the given user. + * + * @param scenarioId + * the scenario id + * @param username + * the username of the user performing the check out + * @throws InvalidPropertyException + * if the user or the scenario is not found in the database + * @throws NotApplicableException + * if the given user can not check out the scenario + */ + public void checkout(final long scenarioId, final String username) + throws InvalidPropertyException, NotApplicableException; + /** * Copy contents from other scenario up to its given step into the given scenario. * diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 0303a5f..98949f1 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -357,8 +357,9 @@ public class ScenarioServiceImpl implements ScenarioService { + " is added to the scenario #" + aScenario.getIndex()); } } catch (IOException error) { - LOG.error("Unable to index the knowedge element '" - + kelm.getIndex() + "', reason:", error); + LOG.error( + "Unable to index the knowedge element '" + kelm.getIndex() + + "', reason:", error); kelm = null; } @@ -379,8 +380,9 @@ public class ScenarioServiceImpl implements ScenarioService { getScenarioDAO().update(aScenario); // Update of relational base isOk = true; } catch (Exception error) { - LOG.error("Unable to re-index the knowledge element '" - + aScenario.getIndex() + "', reason:", error); + LOG.error( + "Unable to re-index the knowledge element '" + + aScenario.getIndex() + "', reason:", error); } return isOk; } @@ -568,8 +570,6 @@ public class ScenarioServiceImpl implements ScenarioService { java.io.File upfile = new java.io.File(file.getPath()); String fileFormat = upfile.getName().substring( upfile.getName().lastIndexOf('.') + 1); - String docname = upfile.getName().substring(0, - upfile.getName().lastIndexOf('.')); // Create a new document or a new version of the document dprop.setAuthor(aUser).setDate(aDate); @@ -584,8 +584,8 @@ public class ScenarioServiceImpl implements ScenarioService { MessageKeyEnum.SCN_000002.toString(), doc.getId()); } if (pub.value() == null) { - throw new MismatchException(MessageKeyEnum.SCN_000002 - .toString(), doc.getId()); + throw new MismatchException( + MessageKeyEnum.SCN_000002.toString(), doc.getId()); } newPub = getStepService().versionDocument(step, pub, dprop); // Remeber the link from the old document to the new document version @@ -602,8 +602,18 @@ public class ScenarioServiceImpl implements ScenarioService { } else { dprop.setType(resType); } - dprop.setDescription("Checked in").setName(docname).setFormat( - fileFormat); + // New document title generation as _N + String docname = dprop.getType().getName(); + int i = 1; + for (Publication scenPub : step.getOwner().getDocums()) { + if (scenPub.value().getTitle().startsWith(docname)) { + i++; + } + } + docname += "_" + i; // The generated new document title + + dprop.setDescription("Checked in").setName(docname) + .setFormat(fileFormat); newPub = getStepService().createDocument(step, dprop); // Remeber the new document @@ -618,8 +628,8 @@ public class ScenarioServiceImpl implements ScenarioService { } if (updir.exists()) { if (updir.delete()) { - LOG.info(MessageKeyEnum.SCN_000003.toString(), updir - .getAbsoluteFile(), step.getOwner().getIndex()); + LOG.info(MessageKeyEnum.SCN_000003.toString(), + updir.getAbsoluteFile(), step.getOwner().getIndex()); } else { throw new IOException( "Can't delete the existing destination file to move file from " @@ -661,8 +671,8 @@ public class ScenarioServiceImpl implements ScenarioService { } while ((step == null) && (i < steps.length)); if (step == null) { - throw new InvalidPropertyException(MessageKeyEnum.SCN_000001 - .toString(), stepDTO.getNumber()); + throw new InvalidPropertyException( + MessageKeyEnum.SCN_000001.toString(), stepDTO.getNumber()); } return step; } @@ -689,11 +699,56 @@ public class ScenarioServiceImpl implements ScenarioService { if (res) { aScenario.setUser(user); aScenario.setLastModificationDate(Calendar.getInstance().getTime()); - getScenarioDAO().update(aScenario); + // RKV: getScenarioDAO().update(aScenario); } return res; } + /** + * Mark the given scenario as checked out by the given user. + * + * @param scenarioId + * the scenario id + * @param username + * the username of the user performing the check out + * @throws InvalidPropertyException + * if the user or the scenario is not found in the database + * @throws NotApplicableException + * if the given user can not check out the scenario + */ + @Transactional + public void checkout(final long scenarioId, final String username) + throws InvalidPropertyException, NotApplicableException { + User aUser = getUserService().selectUser(username); + if (aUser == null) { + // User not found + throw new InvalidPropertyException( + MessageKeyEnum.USR_000001.toString(), username); + } + Scenario aScenario = getScenarioDAO().get(scenarioId); + if (aScenario == null) { + // Scenario not found + throw new InvalidPropertyException( + MessageKeyEnum.SCN_000006.toString(), scenarioId); + } + boolean res = getStudyService().isStaffedBy(aScenario.getOwnerStudy(), + aUser); + if (res) { + if (aScenario.isCheckedout() + && (!aScenario.getUser().getUsername().equals(username))) { + throw new NotApplicableException( + MessageKeyEnum.SCN_000008.toString(), scenarioId, + aScenario.getUser().getUsername()); + } + aScenario.setUser(aUser); + aScenario.setLastModificationDate(Calendar.getInstance().getTime()); + } else { + // User doesn't participate in the scenario + throw new NotApplicableException( + MessageKeyEnum.SCN_000007.toString(), username, scenarioId); + } + } + /** * {@inheritDoc} * @@ -799,9 +854,9 @@ public class ScenarioServiceImpl implements ScenarioService { Restrictions.like("role", "%sysadmin%")).get(0); User admin = getUserDAO().getFilteredList( Restrictions.eq("role", adminRole), Order.asc("rid")).get(0); // First sysadmin in the database - - kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue( - scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of + + kprop.setType(ucase).setTitle(aStudy.getTitle()) + .setValue(scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of // knowledges addKnowledgeElement(scenario, kprop); return scenario; diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index b858a29..5a391b7 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -23,6 +23,7 @@ import java.util.Set; import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.Document; +import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElementType; import org.splat.dal.bo.som.Publication; @@ -32,7 +33,6 @@ import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; -import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.ScenarioDAO; import org.splat.kernel.InvalidPropertyException; @@ -51,13 +51,14 @@ import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.FileDTO; import org.splat.service.dto.StepDTO; import org.splat.service.technical.ProjectSettingsService; -import org.splat.service.technical.RepositoryService; import org.splat.service.technical.ProjectSettingsService.Step; +import org.splat.service.technical.RepositoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.orm.hibernate3.HibernateTemplate; import org.testng.Assert; import org.testng.annotations.Test; +import org.testng.reporters.Files; import test.splat.common.BaseTest; @@ -116,7 +117,7 @@ public class TestScenarioService extends BaseTest { @Autowired @Qualifier("simulationContextService") private transient SimulationContextService _simulationContextService; - + /** * The ProjectSettingsService. Later injected by Spring. */ @@ -176,7 +177,7 @@ public class TestScenarioService extends BaseTest { SQLException { LOG.debug(">>>>> BEGIN testGetScenarioInfo()"); startNestedTransaction(); - + long scenarioId = createScenario(); // Call DAO's create method for a good transient knowledge element. List steps = _scenarioService.getScenarioInfo(scenarioId); @@ -219,9 +220,8 @@ public class TestScenarioService extends BaseTest { Assert.assertEquals(doc.getTitle(), docName); Assert.assertNotNull(doc.getFiles(), "Document files list must not be null."); - Assert - .assertTrue(doc.getFiles().size() > 1, - "Document must have more then 1 attached file."); + Assert.assertTrue(doc.getFiles().size() > 1, + "Document must have more then 1 attached file."); for (FileDTO file : doc.getFiles()) { Assert.assertNotNull(file.getPath(), @@ -256,10 +256,9 @@ public class TestScenarioService extends BaseTest { } else { // Outdated Assert.assertEquals(file.getState(), 'O', "File state must be outdated ('O')."); - Assert - .assertEquals(file.getProcessing(), - "file-download", - "Outdated document should not be imported but downloaded."); + Assert.assertEquals(file.getProcessing(), + "file-download", + "Outdated document should not be imported but downloaded."); } } } @@ -272,8 +271,7 @@ public class TestScenarioService extends BaseTest { try { steps = _scenarioService.getScenarioInfo(-1L); // getHibernateTemplate().flush(); - Assert - .fail("Getting an object with not existing id must be failed."); + Assert.fail("Getting an object with not existing id must be failed."); } catch (Exception e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); @@ -294,6 +292,7 @@ public class TestScenarioService extends BaseTest { *
  • uses relations are copied correctly
  • *
  • files are moved correctly
  • *
  • new documents are created for new data
  • + *
  • new documents have correctly generated names
  • *
  • uses relations are created correctly
  • *
  • files are moved correctly
  • * @@ -337,7 +336,7 @@ public class TestScenarioService extends BaseTest { SQLException, MismatchException, NotApplicableException { LOG.debug(">>>>> BEGIN testCheckin()"); startNestedTransaction(); - + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again _projectSettings.configure(ClassLoader .getSystemResource("test/som.xml").getPath()); @@ -389,7 +388,8 @@ public class TestScenarioService extends BaseTest { } } } - Assert.assertTrue(found, + Assert.assertTrue( + found, "New version of the existing checked in document \"" + docDTO.getTitle() + "\" (id=" + docDTO.getId() @@ -445,11 +445,18 @@ public class TestScenarioService extends BaseTest { Publication newPub = null; for (Publication pub : aScen.getDocums()) { if (pub.value().getPreviousVersion() == null) { - found = (docDTO.getTitle().equals(pub.value() - .getTitle())); + found = (pub.value().getTitle().startsWith(pub + .value().getType().getName())); if (found) { // Found next published version of the checked in document - newPub = pub; - break; + String fcontent = Files.readFile(pub + .getSourceFile().asFile()); + found = fcontent.contains(docDTO.getTitle()); + if (found) { + LOG.debug("Found new document with generated title: " + + pub.value().getTitle()); + newPub = pub; + break; + } } } } @@ -457,6 +464,14 @@ public class TestScenarioService extends BaseTest { "New document is not created for checked in document \"" + docDTO.getTitle() + "\"."); // Check that uses relations are created correctly + Assert.assertTrue( + newPub.value() + .getTitle() + .startsWith( + newPub.value().getType().getName() + + "_"), + "Document title newPub.value().getTitle() must start with " + + newPub.value().getType().getName() + "_"); // 1. Find the document type used by this document type Set usedTypes = newPub.value().getType() @@ -484,13 +499,12 @@ public class TestScenarioService extends BaseTest { // Call checkin method for a not existing id. try { _scenarioService.checkin(-1, userId, stepsToCheckin); - Assert - .fail("Check in for scenario with not existing id must be failed."); + Assert.fail("Check in for scenario with not existing id must be failed."); } catch (Exception e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } - + rollbackNestedTransaction(); LOG.debug(">>>>> END testCheckin()"); } @@ -592,8 +606,8 @@ public class TestScenarioService extends BaseTest { } // Prepare new data stepToCheckin.addDoc(0, "newdoc" + stepFrom.getNumber()).addFile( - createDownloadedFile(userId, "newdoc" - + stepFrom.getNumber(), "brep")); + createDownloadedFile(userId, + "newdoc" + stepFrom.getNumber(), "brep")); } return stepToCheckin; } @@ -633,7 +647,8 @@ public class TestScenarioService extends BaseTest { // Prepare download directory File tmpDir = _repositoryService.getDownloadDirectory(userId); if (!tmpDir.exists()) { - Assert.assertTrue(tmpDir.mkdir(), + Assert.assertTrue( + tmpDir.mkdir(), "Can't create temporary directory: " + tmpDir.getAbsolutePath()); } @@ -678,21 +693,23 @@ public class TestScenarioService extends BaseTest { User.Properties uprop = new User.Properties(); uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser") .setFirstName("TST_FirstName").setDisplayName("TST_test.user") - .addRole("TST_user").setMailAddress( - "noreply@salome-platform.org"); + .addRole("TST_user") + .setMailAddress("noreply@salome-platform.org"); uprop.disableCheck(); User anAuthor = new User(uprop); ht.saveOrUpdate(anAuthor); // Create a test study - Study.Properties stprops = new Study.Properties().setReference( - "TST_SID_01").setTitle("TST_Study").setManager(anAuthor); + Study.Properties stprops = new Study.Properties() + .setReference("TST_SID_01").setTitle("TST_Study") + .setManager(anAuthor); Study aStudy = new Study(stprops); ht.saveOrUpdate(aStudy); // Create a test scenario - Scenario.Properties sprops = new Scenario.Properties().setTitle( - "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy); + Scenario.Properties sprops = new Scenario.Properties() + .setTitle("TST_Scenario").setManager(anAuthor) + .setOwnerStudy(aStudy); Scenario aScenario = new Scenario(sprops); aStudy.getScenariiList().add(aScenario); ht.saveOrUpdate(anAuthor); @@ -750,8 +767,9 @@ public class TestScenarioService extends BaseTest { Assert.assertTrue(ht.find("from Document").size() > 0, "No documents in the database."); - Assert.assertNotNull(ht.find("from Publication where owner=" - + aScenario.getIndex()), "No publications in the database."); + Assert.assertNotNull( + ht.find("from Publication where owner=" + aScenario.getIndex()), + "No publications in the database."); Assert.assertTrue( ht.find("from Publication where owner=" + aScenario.getIndex()) .size() > 0, "No publications in the database."); @@ -777,9 +795,7 @@ public class TestScenarioService extends BaseTest { "More then one document must be in the database"); // Check created uses relations - Assert - .assertTrue(usedMap.size() > 0, - "Uses relations must be created."); + Assert.assertTrue(usedMap.size() > 0, "Uses relations must be created."); boolean foundAny = false; for (Long usingId : usedMap.keySet()) { for (Publication pub : aScen.getDocums()) { @@ -855,7 +871,6 @@ public class TestScenarioService extends BaseTest { return pub; } - /** * Test check-in scenario operation to be performed after SALOME session.
    * Description :
    @@ -911,38 +926,42 @@ public class TestScenarioService extends BaseTest { SQLException, MismatchException, NotApplicableException { LOG.debug(">>>>> BEGIN testCreateStudy()"); startNestedTransaction(); - + Database.getInstance().reset(); _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again _projectSettings.configure(ClassLoader .getSystemResource("test/som.xml").getPath()); - + // Create a test user User.Properties uprop = new User.Properties(); uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser") .setFirstName("TST_FirstName").setDisplayName("TST_test.user") - .addRole("TST_user").setMailAddress( - "noreply@salome-platform.org"); + .addRole("TST_user") + .setMailAddress("noreply@salome-platform.org"); uprop.disableCheck(); User anAuthor = new User(uprop); - + getHibernateTemplate().saveOrUpdate(anAuthor); - KnowledgeElementType ucase = _knowledgeElementTypeService.selectType("usecase"); - Assert.assertNotNull(ucase, "Knowledge type 'usecase' must be created in the database."); - SimulationContextType prodtype = _simulationContextService.selectType("product"); - Assert.assertNotNull(prodtype, "Simulation context type 'product' must be created in the database."); - + KnowledgeElementType ucase = _knowledgeElementTypeService + .selectType("usecase"); + Assert.assertNotNull(ucase, + "Knowledge type 'usecase' must be created in the database."); + SimulationContextType prodtype = _simulationContextService + .selectType("product"); + Assert.assertNotNull(prodtype, + "Simulation context type 'product' must be created in the database."); + // Create admin uprop.clear(); uprop.setUsername("TST_Admin").setName("TST_SimanUnitTestsAdmin") - .setFirstName("TST_AdminFirstName").setDisplayName("TST_test.admin") - .addRole("TST_user,sysadmin").setMailAddress( - "noreply@salome-platform.org"); + .setFirstName("TST_AdminFirstName") + .setDisplayName("TST_test.admin").addRole("TST_user,sysadmin") + .setMailAddress("noreply@salome-platform.org"); uprop.disableCheck(); - + getHibernateTemplate().saveOrUpdate(new User(uprop)); getHibernateTemplate().flush(); - + Study.Properties sprop = new Study.Properties(); sprop.setTitle("Test study creation").setManager(anAuthor); Scenario.Properties oprop = new Scenario.Properties(); @@ -952,9 +971,9 @@ public class TestScenarioService extends BaseTest { SimulationContext.Properties cprop = new SimulationContext.Properties(); // Input of new project context cprop.setType(_simulationContextService.selectType("product")) - .setValue("Test Simulation Context: Product"); + .setValue("Test Simulation Context: Product"); Study study = _scenarioService.createStudy(sprop, oprop, cprop); - + rollbackNestedTransaction(); LOG.debug(">>>>> END testCreateStudy()"); } diff --git a/Workspace/Siman-Common/src/test/spring/ut-applicationContext.xml b/Workspace/Siman-Common/src/test/spring/ut-applicationContext.xml index 221c133..1a59c70 100644 --- a/Workspace/Siman-Common/src/test/spring/ut-applicationContext.xml +++ b/Workspace/Siman-Common/src/test/spring/ut-applicationContext.xml @@ -27,8 +27,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> class="org.springframework.context.support.ResourceBundleMessageSource"> - application - log-messages + som + conf/log-messages diff --git a/Workspace/Siman/WebContent/jap/splat-launcher.jar b/Workspace/Siman/WebContent/jap/splat-launcher.jar index a95e95c..afb3cbf 100644 Binary files a/Workspace/Siman/WebContent/jap/splat-launcher.jar and b/Workspace/Siman/WebContent/jap/splat-launcher.jar differ diff --git a/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar b/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar index d0b4873..bfb5394 100644 Binary files a/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar and b/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar differ diff --git a/Workspace/Siman/WebContent/study/jsonCheckoutRes.jsp b/Workspace/Siman/WebContent/study/jsonCheckoutRes.jsp new file mode 100644 index 0000000..b266101 --- /dev/null +++ b/Workspace/Siman/WebContent/study/jsonCheckoutRes.jsp @@ -0,0 +1,5 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="s" uri="/struts-tags"%> +<%@ page import="org.splat.launcher.ToolbarApplet"%> +{<%=ToolbarApplet.CHECKOUT_RES%> ""} \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/launcher/ConfigurationException.java b/Workspace/Siman/src/org/splat/launcher/ConfigurationException.java new file mode 100644 index 0000000..b9623fc --- /dev/null +++ b/Workspace/Siman/src/org/splat/launcher/ConfigurationException.java @@ -0,0 +1,35 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 02.12.2012 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.launcher; + +/** + * Exception thrown when configuration problem appears during an executable module launching. + * + * @author Roman Kozlov (RKV) + */ +public class ConfigurationException extends Exception { + + /** + * Constructs a configuration exception with its reason description. + * + * @param message + * error message + */ + public ConfigurationException(final String message) { + super(message); + } + + /** + * Serialization version id. + */ + private static final long serialVersionUID = -8886811002435115163L; + +} diff --git a/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java b/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java index 3a7c590..0de0756 100644 --- a/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java +++ b/Workspace/Siman/src/org/splat/launcher/ToolbarApplet.java @@ -5,11 +5,16 @@ import java.awt.ComponentOrientation; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; import java.io.ObjectInputStream; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.net.URLEncoder; /** * Applet providing a set of buttons. Each button is defined by three parameters:
    @@ -27,6 +32,11 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener */ private static final long serialVersionUID = 3243053622061086715L; + /** + * The response key string: '"canCheckout" :'. + */ + public static final String CHECKOUT_RES = "\"canCheckout\" :"; + // ============================================================================================================================== // Overridden functions // ============================================================================================================================== @@ -106,50 +116,8 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener // Opening an application on the local machine - if (module.equals("runSalome")) { - // Run SALOME - // To get the SALOME_HOME environment variable - String SALOME_HOME = System.getenv("SALOME_ROOT_DIR"); - // If SALOME_ROOT_DIR does not exist the SALOME_HOME equals to null. - if (SALOME_HOME == null) { - // TODO: Use logger to be more user friendly - getAppletContext() - .showDocument( - new URL( - getCodeBase().toString() - + "error.jsp?message=launch&value=" - + "SALOME_ROOT_DIR environment variable is not defined."), - "_blank"); - throw new Exception( - "SALOME_ROOT_DIR nevironment variable is not defined."); - } else if (!SALOME_HOME.endsWith(File.separator)) { - SALOME_HOME += File.separator; - } - String pathToScript = SALOME_HOME + "runSalome"; - - File script = new File(pathToScript); - if (!script.exists()) { - script = new File(pathToScript + ".bat"); - if (!script.exists()) { - script = new File(pathToScript + ".cmd"); - } - } - - if (script.exists()) { - // Execute the runSalome script. - // filename here indeed a string containing parameters for runSalome. - Runtime.getRuntime().exec( - new String[] { script.getAbsolutePath(), filename }); - } else { - // TODO: Use logger to be more user friendly - getAppletContext().showDocument( - new URL(getCodeBase().toString() - + "error.jsp?message=launch&value=" - + "SALOME module is not found: " - + script.getAbsolutePath()), "_blank"); - throw new FileNotFoundException( - "SALOME module is not found: " + script.getAbsolutePath()); - } + if ("runSalome".equals(module)) { + salomeCheckout(filename); } else if (module.endsWith(".exe") || module.endsWith(".EXE")) { @@ -205,4 +173,100 @@ public class ToolbarApplet extends java.applet.Applet implements ActionListener error.printStackTrace(); // RKV: NOPMD: TODO: try to use logger } } + + /** + * Checkout a scenario and start Salome with it. + * + * @param params + * Salome parameters + * @throws IOException + * if URL connection opening/reading is failed + * @throws ConfigurationException + * if SALOME_ROOT_DIR environment variable is not defined or Salome launcher script is not found + */ + private void salomeCheckout(final String params) + throws ConfigurationException, IOException { + // Run SALOME + // To get the SALOME_HOME environment variable + String SALOME_HOME = System.getenv("SALOME_ROOT_DIR"); + // If SALOME_ROOT_DIR does not exist the SALOME_HOME equals to null. + if (SALOME_HOME == null) { + // TODO: Use logger to be more user friendly + showError("SALOME_ROOT_DIR environment variable is not defined."); + throw new ConfigurationException( + "SALOME_ROOT_DIR nevironment variable is not defined."); + } else if (!SALOME_HOME.endsWith(File.separator)) { + SALOME_HOME += File.separator; + } + String pathToScript = SALOME_HOME + "runSalome"; + + File script = new File(pathToScript); + if (!script.exists()) { + script = new File(pathToScript + ".bat"); + if (!script.exists()) { + script = new File(pathToScript + ".cmd"); + } + } + + if (script.exists()) { + + // Checkout the scenario + URL checkoutUrl = new URL(getCodeBase().toString() + + "checkout.action?" + + params.replaceAll("siman-", "").replaceAll("--", "-") + .replaceAll("-", "&").replaceAll("\\s", "")); + + BufferedReader buffer = new BufferedReader(new InputStreamReader( + checkoutUrl.openStream())); + boolean isOk = false; + String response = buffer.readLine(); + while ((response != null)) { + if (response.contains(CHECKOUT_RES)) { + isOk = response.contains(CHECKOUT_RES + " \"true\""); + break; + } + response = buffer.readLine(); + } + buffer.close(); + + if (isOk) { + // Execute the runSalome script. + // filename here indeed a string containing parameters for runSalome. + Runtime.getRuntime().exec( + new String[] { script.getAbsolutePath(), params }); + } else { + // Checkout of the scenario is failed at the beginning. + if (response != null) { + response = response + .substring( + response.indexOf(CHECKOUT_RES) + + CHECKOUT_RES.length()) + .replace('}', ' ').replace('"', ' '); + } + showError(response); + } + } else { + // TODO: Use logger to be more user friendly + showError("SALOME module is not found: " + script.getAbsolutePath()); + throw new ConfigurationException("SALOME module is not found: " + + script.getAbsolutePath()); + } + } + + /** + * Show error message in the new window. + * + * @param message + * the error message + * @throws MalformedURLException + * if built URL is incorrect + * @throws UnsupportedEncodingException + * if UTF-8 encoding is not supported + */ + private void showError(final String message) throws MalformedURLException, + UnsupportedEncodingException { + getAppletContext().showDocument( + new URL(getCodeBase().toString() + "../error.jsp?error=" + + URLEncoder.encode(message, "UTF-8")), "_blank"); + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/CheckoutAction.java b/Workspace/Siman/src/org/splat/simer/CheckoutAction.java new file mode 100644 index 0000000..ed95b20 --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/CheckoutAction.java @@ -0,0 +1,149 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 02.12.2012 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.simer; + +import org.splat.exception.BusinessException; +import org.splat.log.AppLogger; +import org.splat.service.ScenarioService; + +import com.opensymphony.xwork2.ActionSupport; + +/** + * Action to checkout a scenario. + * + * @author Roman Kozlov (RKV) + */ +public class CheckoutAction extends ActionSupport { + + /** + * Serialization version id. + */ + private static final long serialVersionUID = 6140789360802711199L; + + /** + * Action logger. + */ + protected static final AppLogger LOG = AppLogger + .getLogger(CheckoutAction.class); + + /** + * Result message. If the scenario is successfully checked out then result is "true", otherwise it contains the error message. + */ + private String _result; + /** + * Scenario id action parameter. Defines the scenario to check out. + */ + private long _scenario; + /** + * User login name action parameter. Defines the user who performs check out. + */ + private String _user; + /** + * Injected scenario service. + */ + private ScenarioService _scenarioService; + + /** + * Mark the currently selected scenario as checked out. If the scenario is successfully checked out then result is "true", otherwise it + * contains the error message. + * + * @return SUCCESS + */ + public String doCheckout() { + try { + getScenarioService().checkout(getScenario(), getUser()); + setResult("true"); + } catch (BusinessException e) { + setResult(e.getMessage()); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Can checkout scenario #" + getScenario() + + " by the user " + getUser() + ": " + getResult()); + } + return SUCCESS; + } + + /** + * Get the scenarioService. + * + * @return the scenarioService + */ + public ScenarioService getScenarioService() { + return _scenarioService; + } + + /** + * Set the scenarioService. + * + * @param scenarioService + * the scenarioService to set + */ + public void setScenarioService(final ScenarioService scenarioService) { + _scenarioService = scenarioService; + } + + /** + * Result message. If the scenario is successfully checked out then result is "true", otherwise it contains the error message. + * + * @return the result + */ + public String getResult() { + return _result; + } + + /** + * Set the result. + * + * @param result + * the result to set + */ + public void setResult(final String result) { + _result = result; + } + + /** + * Get the scenario. + * + * @return the scenario + */ + public long getScenario() { + return _scenario; + } + + /** + * Set the scenario. + * + * @param scenario + * the scenario to set + */ + public void setScenario(final long scenario) { + _scenario = scenario; + } + + /** + * Get the user. + * + * @return the user + */ + public String getUser() { + return _user; + } + + /** + * Set the user. + * + * @param user + * the user to set + */ + public void setUser(final String user) { + _user = user; + } +} diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 256f84c..82dcc0e 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -97,8 +97,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { public OpenStudy open(final User user, final Study study) { ResourceBundle custom = ResourceBundle.getBundle("som", getApplicationSettings().getCurrentLocale()); - SimpleDateFormat datstring = new SimpleDateFormat(custom - .getString("date.format")); + SimpleDateFormat datstring = new SimpleDateFormat( + custom.getString("date.format")); Revision.Format verstring = new Revision.Format(getProjectSettings() .getRevisionPattern()); @@ -204,9 +204,10 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { } public String getType() { - return ResourceBundle.getBundle("labels", - getApplicationSettings().getCurrentLocale()).getString( - "label.study"); + /* + * RKV: return ResourceBundle.getBundle("labels", getApplicationSettings().getCurrentLocale()).getString( "label.study"); + */ + return "study"; } public String getVersion() { @@ -256,8 +257,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { // Transfer to the document of all known properties ResourceBundle locale = ResourceBundle.getBundle("som", getApplicationSettings().getCurrentLocale()); - SimpleDateFormat get = new SimpleDateFormat(locale - .getString("date.format")); + SimpleDateFormat get = new SimpleDateFormat( + locale.getString("date.format")); Writer tool = Toolbox.getWriter(credoc); List slist = getInvolvedSteps(); for (Iterator i = slist.iterator(); i.hasNext();) { @@ -266,14 +267,15 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { for (Iterator j = clist.iterator(); j .hasNext();) { SimulationContext context = j.next(); - tool.updateProperty(context.getType().getName(), context - .getValue()); + tool.updateProperty(context.getType().getName(), + context.getValue()); } } tool.updateProperty("reference", medoc.getReference()); tool.updateProperty("study", _mystudy.getTitle()); - tool.updateProperty("step", locale.getString( - "folder.step." + step.getNumber()).replaceAll("''", "'")); + tool.updateProperty("step", + locale.getString("folder.step." + step.getNumber()) + .replaceAll("''", "'")); tool.updateProperty("author", author.getUsername().toUpperCase()); tool.updateProperty("date", get.format(medoc.getCreationDate())); tool.updateProperty("history", locale.getString("label.creation") @@ -343,8 +345,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { } protected void add(final KnowledgeElement kelm) { - KnowledgeElementFacade facade = new KnowledgeElementFacade(BeanHelper - .copyBean(kelm, KnowledgeElementDTO.class), + KnowledgeElementFacade facade = new KnowledgeElementFacade( + BeanHelper.copyBean(kelm, KnowledgeElementDTO.class), getApplicationSettings()); // RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2); // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2) diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 70c4bb4..6867411 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -1,7 +1,6 @@ - + - application - log-messages + conf/log-messages - + @@ -56,13 +53,12 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - + @@ -70,17 +66,14 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - + - - + + @@ -94,8 +87,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> parent="openObject" scope="session"> - + @@ -109,23 +102,24 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - - + + - + + + + + @@ -134,17 +128,15 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - + @@ -153,46 +145,37 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> scope="prototype" parent="displayStudyStepAction"> - - + + - + - - + + - + - - - + + + - + @@ -200,45 +183,37 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> scope="prototype" parent="baseAction"> - + - + - + - + - + - - + + - + - - + + - + - + - + - + - - + - + - - + - + diff --git a/Workspace/Siman/src/struts.xml b/Workspace/Siman/src/struts.xml index 9a2da59..ea10f3f 100644 --- a/Workspace/Siman/src/struts.xml +++ b/Workspace/Siman/src/struts.xml @@ -72,6 +72,10 @@ page.error.study + + /study/jsonCheckoutRes.jsp + +