From 5ed58202d65987155dc24d21404ba00ea9b397df Mon Sep 17 00:00:00 2001 From: rkv Date: Sun, 18 Nov 2012 15:29:35 +0000 Subject: [PATCH] Loading of mappings of document types to lists of file formats is implemented. ProjectSetting.doImport method is added. --- .../technical/ProjectSettingsService.java | 11 + .../technical/ProjectSettingsServiceImpl.java | 72 +++++- .../src/test/som-without-mappings.xml | 218 ++++++++++++++++++ Workspace/Siman-Common/src/test/som.xml | 17 +- .../service/TestProjectSettingsService.java | 136 +++++++++++ .../splat/service/TestScenarioService.java | 1 - Workspace/Siman/WebContent/conf/som.xml | 16 +- 7 files changed, 445 insertions(+), 26 deletions(-) create mode 100644 Workspace/Siman-Common/src/test/som-without-mappings.xml create mode 100644 Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java index bdb7273..576fd67 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java @@ -247,4 +247,15 @@ public interface ProjectSettingsService { */ List getStepsOf( Class level); + + /** + * Check if a file of the given format should be imported during check-in of a document of the given type. + * + * @param type + * document type + * @param format + * file format + * @return true if file should be imported + */ + public boolean doImport(final String type, final String format); } 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 66790ae..49f84de 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -78,6 +78,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * Configuration document validation cycles. */ private transient List _concycles; + /** + * Document type mappings to file formats which should be imported into SALOME during check-out. + */ + private transient Map> _mapimport; // Temporary attributes initialized from the configuration file for populating the database with object types /** @@ -300,6 +304,20 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { return result; } + /** + * Check if a file of the given format should be imported during check-in of a document of the given type. + * + * @param type + * document type + * @param format + * file format + * @return true if file should be imported + */ + public boolean doImport(final String type, final String format) { + return (_mapimport.containsKey(type) && _mapimport.get(type).contains( + format)); + } + /** * Initialize the database: create all necessary default staff defined in the configuration file. */ @@ -379,6 +397,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { // Validations tag _concycles = loadValidationCycles(children, resultype); + _mapimport = loadFormatMappings(children); + if (!getDatabase().getCheckedDB().isInitialized()) { // Load object type definitions // Documents tag @@ -411,6 +431,47 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { } } + /** + * Load mappings of document types to lists of importable file formats. + * + * @param children + * XML nodes + * @return map of document type names to lists of file formats + */ + private Map> loadFormatMappings( + final Map children) { + Map> res = new HashMap>(); + Element maps = (Element) children.get("mappings"); + Element doc, imp; + String type, format; + List formats; + NodeList docs, imports; + if (maps != null) { + // Read document types + docs = maps.getElementsByTagName("document"); + for (int i = 0; i < docs.getLength(); i++) { + doc = (Element) docs.item(i); + type = doc.getAttribute("type"); + if (!type.isEmpty()) { + // Read file formats for the document type + imports = doc.getElementsByTagName("import"); + formats = new ArrayList(); + for (int j = 0; j < imports.getLength(); j++) { + imp = (Element) imports.item(j); + format = imp.getAttribute("format"); + if (!format.isEmpty()) { + formats.add(format); + } + } + if (!formats.isEmpty()) { + res.put(type, formats); + } + } + } + } + return res; + } + /** * Load a step from the given XML node. Return the next step's number. * @@ -434,8 +495,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { final List resultype) { int res = snum; if ("step".equals(node.getNodeName())) { - - String name = ((Element)node).getAttribute("name"); + + String name = ((Element) node).getAttribute("name"); HashMap tags = XDOM.getNamedChildNodes(node); NamedNodeMap natr = tags.get("storage").getAttributes(); @@ -594,7 +655,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { if (slist != null) { uses = _mapuse.get(type); step = mapresult.get(type); - + tprop.clear(); tprop.setName(type).setStep( slist.toArray(new ProjectSettingsService.Step[slist @@ -602,7 +663,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { if (uses != null) { tdoc = maptype.get(uses); if (tdoc == null) { - LOG.warn("Undefined \"" + uses + "\" document type."); + LOG.warn("Undefined \"" + uses + + "\" document type."); } else { tprop.setUses(tdoc); } @@ -610,7 +672,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { if (step != null) { tprop.setResult(step); } - + tprop.disableCheck(); tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types getDocumentTypeService().approve(tdoc); diff --git a/Workspace/Siman-Common/src/test/som-without-mappings.xml b/Workspace/Siman-Common/src/test/som-without-mappings.xml new file mode 100644 index 0000000..0aeae57 --- /dev/null +++ b/Workspace/Siman-Common/src/test/som-without-mappings.xml @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + +
+
+
+
+
+
+ + +
+
+ + + +
+
+
+
+ + +
+ + +
+
+
+ + + + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/test/som.xml b/Workspace/Siman-Common/src/test/som.xml index 0aeae57..1e36c05 100644 --- a/Workspace/Siman-Common/src/test/som.xml +++ b/Workspace/Siman-Common/src/test/som.xml @@ -194,25 +194,22 @@ - - - - + - - - + - - + - + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java new file mode 100644 index 0000000..f5f27f0 --- /dev/null +++ b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java @@ -0,0 +1,136 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 12 Oct 2012 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ +package test.splat.service; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; + +import org.splat.dal.bo.som.Scenario; +import org.splat.log.AppLogger; +import org.splat.service.DocumentTypeService; +import org.splat.service.technical.ProjectSettingsService; +import org.splat.service.technical.ProjectSettingsService.Step; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.testng.Assert; +import org.testng.annotations.Test; + +import test.splat.common.BaseTest; + +/** + * Test class for KnowledgeElementDAO. + * + * @author Roman Kozlov (RKV) + * + */ +public class TestProjectSettingsService extends BaseTest { + + /** + * Logger for the class. + */ + private static final AppLogger LOG = AppLogger + .getLogger(TestProjectSettingsService.class); + + /** + * The ProjectSettingsService. Later injected by Spring. + */ + @Autowired + @Qualifier("projectSettings") + private transient ProjectSettingsService _projectSettings; + + /** + * The DocumentTypeService. Later injected by Spring. + */ + @Autowired + @Qualifier("documentTypeService") + private transient DocumentTypeService _documentTypeService; + + /** + * Test of loading document mappings to file formats from customization XML file.
+ * Description :
+ * Load customization and check the result.
+ * Action :
+ * 1. call the method for som.xml
+ * 2. call the method for a xml without mappings.
+ * 3. call the method for a not existing file.
+ * Test data :
+ * no input parameters
+ * no input parameters
+ * no input parameters
+ * + * Outcome results:
+ * + *
    + *
  • doImport() must return true for mapped formats
    + *
  • + *
  • doImport() must always return false
    + *
  • + *
  • Exception is thrown
    + *
  • + *
+ *
+ * + * @throws IOException + * if configuration loading is failed + * @throws SQLException + * if configuration loading is failed + */ + @Test + public void testLoadMappings() throws IOException, SQLException { + LOG.debug(">>>>> BEGIN testGetScenarioInfo()"); + // ////// Load good workflow customization + /* + * geometry: brep model: med loads: c3m results: med + */ + try { + _projectSettings.configure(ClassLoader.getSystemResource( + "test/som.xml").getPath()); + } catch (FileNotFoundException e) { + Assert.fail("Can't find configuration file: ", e); + } + List steps = _projectSettings.getStepsOf(Scenario.class); + Assert.assertTrue(steps.size() > 0, "No steps are created."); + Assert.assertTrue(_projectSettings.doImport("geometry", "brep")); + Assert.assertTrue(_projectSettings.doImport("model", "med")); + Assert.assertTrue(_projectSettings.doImport("loads", "c3m")); + Assert.assertTrue(_projectSettings.doImport("results", "med")); + + // ////// Load workflow customization with empty mappings + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again + try { + _projectSettings.configure(ClassLoader.getSystemResource( + "test/som-without-mappings.xml").getPath()); + } catch (FileNotFoundException e) { + Assert.fail("Can't find configuration file: ", e); + } + steps = _projectSettings.getStepsOf(Scenario.class); + Assert.assertTrue(steps.size() > 0, "No steps are created."); + Assert.assertFalse(_projectSettings.doImport("geometry", "brep")); + Assert.assertFalse(_projectSettings.doImport("model", "med")); + Assert.assertFalse(_projectSettings.doImport("loads", "c3m")); + Assert.assertFalse(_projectSettings.doImport("results", "med")); + + // ////// Load workflow customization from not existing file + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again + try { + _projectSettings.configure(ClassLoader.getSystemResource("/") + .getPath() + + "test/xxx.xml"); + Assert + .fail("Customization loading must fail for not existing configuration file."); + } catch (FileNotFoundException e) { + LOG.debug("Configuration file must not be found.", e); + } + + LOG.debug(">>>>> END testGetScenarioInfo()"); + } + +} diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index 1f0e41d..a0557c6 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -49,7 +49,6 @@ import test.splat.common.BaseTest; * @author Roman Kozlov (RKV) * */ -@Test(sequential = true, groups = { "service", "functional", "business" }) public class TestScenarioService extends BaseTest { /** diff --git a/Workspace/Siman/WebContent/conf/som.xml b/Workspace/Siman/WebContent/conf/som.xml index 0aeae57..a8cb18e 100644 --- a/Workspace/Siman/WebContent/conf/som.xml +++ b/Workspace/Siman/WebContent/conf/som.xml @@ -194,25 +194,21 @@ - - - - + - - - + - - + - + \ No newline at end of file -- 2.39.2