]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / technical / ProjectSettingsServiceImpl.java
index b537b10f8db4e2c7de6b525265afbde1a2e0bf11..14e6e66d58e7a01d791636fe656a70450573b36e 100644 (file)
@@ -10,13 +10,14 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.Vector;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -48,56 +49,56 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
        /**
         * The logger for the service.
         */
-       protected final static Logger logger = Logger
+       protected final static Logger LOG = Logger
                        .getLogger(ProjectSettingsServiceImpl.class);
 
        // Non persistent configuration information
        /**
         * Repository settings.
         */
-       private final Properties reprop = new Properties();
+       private transient final Properties _reprop = new Properties();
        /**
         * Pattern of study references.
         */
-       private String pattern;
+       private transient String _pattern;
        /**
         * Scheme of file names stored into the repository.
         */
-       private FileNaming naming;
+       private transient FileNaming _naming;
        /**
         * Pattern of the presentation of version numbers.
         */
-       private String versioning;
+       private transient String _versioning;
        /**
         * Ordered list of (transient) study steps.
         */
-       private final Vector<ProjectSettingsService.Step> steps = new Vector<ProjectSettingsService.Step>();
+       private transient final List<ProjectSettingsService.Step> _steps = new ArrayList<ProjectSettingsService.Step>();
        /**
         * Configuration document validation cycles.
         */
-       private Vector<ProjectSettingsValidationCycle> concycles;
+       private transient List<ProjectSettingsValidationCycle> _concycles;
 
        // Temporary attributes initialized from the configuration file for populating the database with object types
        /**
         * Document type names and uses mapping.
         */
-       private LinkedHashMap<String, String> mapuse;
+       private transient Map<String, String> _mapuse;
        /**
         * Simulation Context type names.
         */
-       private Vector<String> context;
+       private transient List<String> _context;
        /**
         * Knowledge Element type names.
         */
-       private Vector<String> kname;
+       private transient List<String> _kname;
        /**
         * Document flows.
         */
-       private Vector<NamedNodeMap> flows;
+       private transient List<NamedNodeMap> _flows;
        /**
         * Study classifications.
         */
-       private Vector<NamedNodeMap> sclass;
+       private transient List<NamedNodeMap> _sclass;
 
        // Other resources
        /**
@@ -128,18 +129,18 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                /**
                 * Cycle (document) type name.
                 */
-               private final String name;
+               private final String _name;
                /**
                 * Array of cycle actors positions in the organization. TODO: Must be replaced by Roles.
                 */
-               private final Actor[] actor;
+               private final Actor[] _actor;
 
                /**
                 * Default constructor.
                 */
                private ProjectSettingsValidationCycle() {
-                       this.name = "built-in";
-                       this.actor = new Actor[] { null, null, null };
+                       this._name = "built-in";
+                       this._actor = new Actor[] { null, null, null };
                }
 
                /**
@@ -152,8 +153,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                 */
                private ProjectSettingsValidationCycle(final String name,
                                final Actor[] actor) {
-                       this.name = name;
-                       this.actor = actor;
+                       this._name = name;
+                       this._actor = actor;
                }
 
                /**
@@ -162,7 +163,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                 * @return the document type name
                 */
                public String getName() {
-                       return name;
+                       return _name;
                }
 
                /**
@@ -172,7 +173,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                 * @see org.splat.dal.bo.som.ValidationCycle.Actor
                 */
                public Actor[] getActorTypes() {
-                       return actor;
+                       return _actor;
                }
        }
 
@@ -192,7 +193,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        public void configure(final String filename) throws IOException,
                        SQLException {
-               if (!steps.isEmpty()) {
+               if (!_steps.isEmpty()) {
                        return; // Project already configured
                }
 
@@ -201,11 +202,11 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                if (config.exists()) {
                        loadCustomization(config);
                } else {
-                       logger.fatal("Could not find the database configuration file \""
+                       LOG.fatal("Could not find the database configuration file \""
                                        + config.getAbsolutePath() + "\"");
                        throw new FileNotFoundException();
                }
-               base.configure(reprop);
+               base.configure(_reprop);
                if (!base.isInitialized()) {
                        base.initialize();
                        initialize(); // Populates the database with all necessary stuff
@@ -218,7 +219,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return the list of steps from project settings
         */
        public List<ProjectSettingsService.Step> getAllSteps() {
-               return steps;
+               return _steps;
        }
 
        /**
@@ -228,7 +229,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return the validation cycles of the workflow
         */
        public List<ProjectSettingsValidationCycle> getAllValidationCycles() {
-               return concycles;
+               return _concycles;
        }
 
        /**
@@ -238,7 +239,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @see org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming
         */
        public FileNaming getFileNamingScheme() {
-               return naming;
+               return _naming;
        }
 
        /**
@@ -247,7 +248,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return the reference pattern
         */
        public String getReferencePattern() {
-               return pattern;
+               return _pattern;
        }
 
        /**
@@ -256,7 +257,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return the version numbers presentation pattern
         */
        public String getRevisionPattern() {
-               return versioning;
+               return _versioning;
        }
 
        /**
@@ -267,13 +268,15 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * @return the step
         */
        public ProjectSettingsService.Step getStep(final int number) {
-               for (int i = 0; i < steps.size(); i++) {
-                       ProjectSettingsService.Step step = steps.get(i);
-                       if (step.number == number) {
-                               return step;
+               ProjectSettingsService.Step res = null;
+               for (int i = 0; i < _steps.size(); i++) {
+                       ProjectSettingsService.Step step = _steps.get(i);
+                       if (step.getNumber() == number) {
+                               res = step;
+                               break;
                        }
                }
-               return null;
+               return res;
        }
 
        /**
@@ -285,10 +288,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        public List<ProjectSettingsService.Step> getStepsOf(
                        final Class<? extends ProjectElement> level) {
-               Vector<ProjectSettingsService.Step> result = new Vector<ProjectSettingsService.Step>();
+               List<ProjectSettingsService.Step> result = new ArrayList<ProjectSettingsService.Step>();
 
-               for (int i = 0; i < steps.size(); i++) {
-                       ProjectSettingsService.Step step = steps.get(i);
+               for (int i = 0; i < _steps.size(); i++) {
+                       ProjectSettingsService.Step step = _steps.get(i);
                        if (step.appliesTo(level)) {
                                result.add(step);
                        }
@@ -334,29 +337,29 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        if (!disk.endsWith("/")) {
                                disk = disk + "/";
                        }
-                       logger.info("Database root set to " + disk);
-                       reprop.setProperty("repository", disk);
+                       LOG.info("Database root set to " + disk);
+                       _reprop.setProperty("repository", disk);
 
                        // Formats tag initializing the reference pattern and date attributes
                        child = children.get("formats");
                        datag = XDOM.getNamedChildNodes(child);
 
                        NamedNodeMap natr = datag.get("references").getAttributes();
-                       pattern = natr.getNamedItem("study").getNodeValue();
+                       _pattern = natr.getNamedItem("study").getNodeValue();
 
                        natr = datag.get("files").getAttributes();
-                       naming = FileNaming.valueOf(natr.getNamedItem("name")
+                       _naming = FileNaming.valueOf(natr.getNamedItem("name")
                                        .getNodeValue());
 
                        natr = datag.get("versions").getAttributes();
-                       versioning = natr.getNamedItem("pattern").getNodeValue();
+                       _versioning = natr.getNamedItem("pattern").getNodeValue();
 
                        // Activities tag initializing the steps and rex attributes
                        child = children.get("activities");
                        NodeList nlist = child.getChildNodes();
-                       Vector<NamedNodeMap> flist = new Vector<NamedNodeMap>();
-                       Vector<String> resultype = new Vector<String>();
-                       Vector<NamedNodeMap> clist = new Vector<NamedNodeMap>();
+                       List<NamedNodeMap> flist = new ArrayList<NamedNodeMap>();
+                       List<String> resultype = new ArrayList<String>();
+                       List<NamedNodeMap> clist = new ArrayList<NamedNodeMap>();
 
                        int snum = 1; // Base number of steps
                        for (int i = 0; i < nlist.getLength(); i++) {
@@ -385,20 +388,20 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                                }
 
                                                child = tags.get("classification");
-                                               if (child != null) {
-                                                       clist.add(child.getAttributes());
-                                               } else {
+                                               if (child == null) {
                                                        clist.add(null);
+                                               } else {
+                                                       clist.add(child.getAttributes());
                                                }
 
                                                if (natr.getNamedItem("contents").getNodeValue()
                                                                .equals("knowledge")) {
                                                        // TODO In a given scenario, only one step must contain knowledges
-                                                       step.contents.add(KnowledgeElement.class);
+                                                       step._contents.add(KnowledgeElement.class);
                                                } else {
-                                                       step.contents.add(Document.class);
+                                                       step._contents.add(Document.class);
                                                }
-                                               steps.add(step);
+                                               _steps.add(step);
                                                snum += 1;
                                        }
                                } else {
@@ -421,25 +424,26 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        }
 
                                        child = tags.get("classification"); // Optional information
-                                       if (child != null) {
-                                               clist.add(child.getAttributes());
-                                       } else {
+                                       if (child == null) {
                                                clist.add(null);
+                                       } else {
+                                               clist.add(child.getAttributes());
                                        }
 
                                        if (natr.getNamedItem("contents").getNodeValue().equals(
                                                        "knowledge")) {
                                                // TODO Error: knowledges must be attached to scenarios
+                                               LOG.error("Error: knowledges must be attached to scenarios.");
                                        } else {
-                                               step.contents.add(Document.class);
+                                               step._contents.add(Document.class);
                                        }
-                                       steps.add(step);
+                                       _steps.add(step);
                                        snum += 1;
                                }
                        }
                        // Validations tag
                        child = children.get("validations");
-                       concycles = new Vector<ProjectSettingsValidationCycle>();
+                       _concycles = new ArrayList<ProjectSettingsValidationCycle>();
                        datag = XDOM.getNamedChildNodes(child);
 
                        String[] step = { "review", "approval", "acceptance" };
@@ -459,9 +463,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        }
                                        actor[j] = Actor.valueOf(child.getNodeValue());
                                }
-                               concycles.add(new ProjectSettingsValidationCycle(name, actor));
+                               _concycles.add(new ProjectSettingsValidationCycle(name, actor));
                        }
-                       concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
+                       _concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
 
                        if (getDatabase().getCheckedDB().isInitialized()) {
                                return; // No need to load object type definitions as they are already stored
@@ -471,9 +475,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        child = children.get("documents");
                        nlist = child.getChildNodes();
 
-                       flows = flist; // Kept for later use in document type definition
-                       sclass = clist; // Kept for later use in simulation context type definition
-                       mapuse = new LinkedHashMap<String, String>();
+                       _flows = flist; // Kept for later use in document type definition
+                       _sclass = clist; // Kept for later use in simulation context type definition
+                       _mapuse = new LinkedHashMap<String, String>();
                        for (int i = 0; i < nlist.getLength(); i++) {
                                child = nlist.item(i);
                                if (!child.getNodeName().equals("article")) {
@@ -487,38 +491,38 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                if (child != null) {
                                        uses = child.getNodeValue();
                                }
-                               mapuse.put(type, uses); // Must be added to the map even if no (null) uses
+                               _mapuse.put(type, uses); // Must be added to the map even if no (null) uses
                        }
                        // Simulation Contexts tag
                        child = children.get("contexts");
                        nlist = child.getChildNodes();
 
-                       context = new Vector<String>();
+                       _context = new ArrayList<String>();
                        for (int i = 0; i < nlist.getLength(); i++) {
                                child = nlist.item(i);
                                if (!child.getNodeName().equals("article")) {
                                        continue;
                                }
 
-                               context.add(child.getAttributes().getNamedItem("type")
+                               _context.add(child.getAttributes().getNamedItem("type")
                                                .getNodeValue());
                        }
                        // Knowledge Elements tag
                        child = children.get("knowledges");
                        nlist = child.getChildNodes();
 
-                       kname = new Vector<String>();
+                       _kname = new ArrayList<String>();
                        for (int i = 0; i < nlist.getLength(); i++) {
                                child = nlist.item(i);
                                if (!child.getNodeName().equals("article")) {
                                        continue;
                                }
 
-                               kname.add(child.getAttributes().getNamedItem("type")
+                               _kname.add(child.getAttributes().getNamedItem("type")
                                                .getNodeValue());
                        }
                } catch (Exception error) {
-                       logger.info("Error in customization", error);
+                       LOG.info("Error in customization", error);
                }
        }
 
@@ -527,28 +531,28 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        private void createDocumentTypes() {
                DocumentType.Properties tprop = new DocumentType.Properties();
-               HashMap<String, Vector<ProjectSettingsService.Step>> mapsteps = new HashMap<String, Vector<ProjectSettingsService.Step>>();
-               HashMap<String, ProjectSettingsService.Step> mapresult = new HashMap<String, ProjectSettingsService.Step>();
-               HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+               Map<String, List<ProjectSettingsService.Step>> mapsteps = new HashMap<String, List<ProjectSettingsService.Step>>();
+               Map<String, ProjectSettingsService.Step> mapresult = new HashMap<String, ProjectSettingsService.Step>();
+               Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
 
-               Vector<ProjectSettingsService.Step> slist = null; // List of Steps to which each document type is valid
+               List<ProjectSettingsService.Step> slist = null; // List of Steps to which each document type is valid
                int snum = 0; // Step number
                String type = null;
                String uses = null;
-               for (Iterator<NamedNodeMap> i = flows.iterator(); i.hasNext(); snum++) {
+               for (Iterator<NamedNodeMap> i = _flows.iterator(); i.hasNext(); snum++) {
                        NamedNodeMap flow = i.next();
-                       ProjectSettingsService.Step step = steps.get(snum);
+                       ProjectSettingsService.Step step = _steps.get(snum);
                        String[] contents = flow.getNamedItem("contents").getNodeValue()
                                        .split(",");
                        for (int j = 0; j < contents.length; j++) {
                                type = contents[j];
-                               if (!mapuse.containsKey(type)) {
-                                       logger.warn("Undefined \"" + type + "\" document type.");
+                               if (!_mapuse.containsKey(type)) {
+                                       LOG.warn("Undefined \"" + type + "\" document type.");
                                        continue;
                                }
                                slist = mapsteps.get(type);
                                if (slist == null) {
-                                       slist = new Vector<ProjectSettingsService.Step>();
+                                       slist = new ArrayList<ProjectSettingsService.Step>();
                                }
                                slist.add(step);
                                mapsteps.put(type, slist);
@@ -560,12 +564,12 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                }
                try {
                        DocumentType tdoc = null;
-                       Set<String> tset = mapuse.keySet();
+                       Set<String> tset = _mapuse.keySet();
                        ProjectSettingsService.Step step;
                        for (Iterator<String> i = tset.iterator(); i.hasNext();) {
                                type = i.next();
                                slist = mapsteps.get(type);
-                               uses = mapuse.get(type);
+                               uses = _mapuse.get(type);
                                step = mapresult.get(type);
 
                                tprop.clear();
@@ -575,7 +579,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                if (uses != null) {
                                        tdoc = maptype.get(uses);
                                        if (tdoc == null) {
-                                               logger
+                                               LOG
                                                                .warn("Undefined \"" + uses
                                                                                + "\" document type.");
                                        } else {
@@ -592,7 +596,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                maptype.put(type, tdoc);
                        }
                } catch (Exception error) {
-                       logger.warn("Error creating document types, reason:", error); // Should not happen
+                       LOG.warn("Error creating document types, reason:", error); // Should not happen
                }
        }
 
@@ -604,14 +608,14 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        KnowledgeElementType ktype = getKnowledgeElementTypeService()
                                        .createType("usecase"); // Internal reserved knowledge element type
                        getKnowledgeElementTypeService().reserve(ktype);
-                       for (Iterator<String> i = kname.iterator(); i.hasNext();) {
+                       for (Iterator<String> i = _kname.iterator(); i.hasNext();) {
                                String type = i.next();
 
                                ktype = getKnowledgeElementTypeService().createType(type); // Knowledge Elements Types defined in the configuration
                                getKnowledgeElementTypeService().approve(ktype);
                        }
                } catch (Exception error) {
-                       logger.warn("Error creating knowledge types, reason:", error); // Should not happen
+                       LOG.warn("Error creating knowledge types, reason:", error); // Should not happen
                }
        }
 
@@ -619,9 +623,9 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * Create in the database simulation contexts types defined in the custom configuration.
         */
        private void createSimulationContextTypes() {
-               HashMap<String, ProjectSettingsService.Step> mapstep = new HashMap<String, ProjectSettingsService.Step>();
+               Map<String, ProjectSettingsService.Step> mapstep = new HashMap<String, ProjectSettingsService.Step>();
                int snum = 0;
-               for (Iterator<NamedNodeMap> i = sclass.iterator(); i.hasNext(); snum++) {
+               for (Iterator<NamedNodeMap> i = _sclass.iterator(); i.hasNext(); snum++) {
                        NamedNodeMap clatr = i.next();
                        if (clatr == null) {
                                continue;
@@ -630,15 +634,15 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        String[] clist = clatr.getNamedItem("context").getNodeValue()
                                        .split(",");
                        for (int j = 0; j < clist.length; j++) {
-                               mapstep.put(clist[j], steps.get(snum));
+                               mapstep.put(clist[j], _steps.get(snum));
                        }
                }
                try {
                        SimulationContextType tctex = null;
-                       for (Iterator<String> i = context.iterator(); i.hasNext();) {
+                       for (Iterator<String> i = _context.iterator(); i.hasNext();) {
                                String type = i.next();
                                if (!mapstep.containsKey(type)) {
-                                       logger
+                                       LOG
                                                        .warn("Could not find \""
                                                                        + type
                                                                        + "\" classification. Simulation Context type ignored.");
@@ -649,7 +653,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                getSimulationContextTypeService().approve(tctex);
                        }
                } catch (Exception error) {
-                       logger.warn("Error creating context types, reason:", error); // Should not happen
+                       LOG.warn("Error creating context types, reason:", error); // Should not happen
                }
        }