import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.log4j.Logger;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.service.DocumentTypeService;
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SimulationContextTypeService;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+/**
+ * SIMAN configuration data service.
+ */
public class ProjectSettingsServiceImpl implements ProjectSettingsService {
/**
.getLogger(ProjectSettingsServiceImpl.class);
// Non persistent configuration information
- private Properties reprop; // Repository settings
- private String pattern; // Pattern of study references
- private FileNaming naming; // Scheme of file names stored into the repository
- private String versioning; // Pattern of the presentation of version numbers
- private Vector<ProjectSettingsService.Step> steps; // Ordered list of (transient) study steps
- private Vector<ProjectSettingsValidationCycle> concycles; // Configuration document validation cycles
+ /**
+ * Repository settings.
+ */
+ private final Properties reprop = new Properties();
+ /**
+ * Pattern of study references.
+ */
+ private String pattern;
+ /**
+ * Scheme of file names stored into the repository.
+ */
+ private FileNaming naming;
+ /**
+ * Pattern of the presentation of version numbers.
+ */
+ private String versioning;
+ /**
+ * Ordered list of (transient) study steps.
+ */
+ private final Vector<ProjectSettingsService.Step> steps = new Vector<ProjectSettingsService.Step>();
+ /**
+ * Configuration document validation cycles.
+ */
+ private Vector<ProjectSettingsValidationCycle> concycles;
// Temporary attributes initialized from the configuration file for populating the database with object types
- private LinkedHashMap<String, String> mapuse; // Document type names and uses mapping
- private Vector<String> context; // Simulation Context type names
- private Vector<String> kname; // Knowledge Element type names
- private Vector<NamedNodeMap> flows; // Document flows
- private Vector<NamedNodeMap> sclass; // Study classifications
+ /**
+ * Document type names and uses mapping.
+ */
+ private LinkedHashMap<String, String> mapuse;
+ /**
+ * Simulation Context type names.
+ */
+ private Vector<String> context;
+ /**
+ * Knowledge Element type names.
+ */
+ private Vector<String> kname;
+ /**
+ * Document flows.
+ */
+ private Vector<NamedNodeMap> flows;
+ /**
+ * Study classifications.
+ */
+ private Vector<NamedNodeMap> sclass;
// Other resources
- private static ProjectSettingsServiceImpl my = null; // Singleton instance
+ /**
+ * Database service to check its version, etc.
+ */
private Database _database;
/**
* Injected simulation context type service.
title, encoded, asis
}
+ /**
+ * Validation cycle defined in the XML configuration.
+ */
public static class ProjectSettingsValidationCycle {
- // -----------------------------------
- private String name;
- private Actor[] actor;
-
+ /**
+ * Cycle (document) type name.
+ */
+ private final String name;
+ /**
+ * Array of cycle actors positions in the organization. TODO: Must be replaced by Roles.
+ */
+ private final Actor[] actor;
+
+ /**
+ * Default constructor.
+ */
private ProjectSettingsValidationCycle() {
this.name = "built-in";
this.actor = new Actor[] { null, null, null };
}
- private ProjectSettingsValidationCycle(String name, Actor[] actor) {
+ /**
+ * Create a validation cycle definition for the given document type name and actors positions.
+ *
+ * @param name
+ * the document type name
+ * @param actor
+ * the array of actors positions
+ */
+ private ProjectSettingsValidationCycle(final String name,
+ final Actor[] actor) {
this.name = name;
this.actor = actor;
}
+ /**
+ * The processed document type name.
+ *
+ * @return the document type name
+ */
public String getName() {
return name;
}
+ /**
+ * Get an array of cycle actors positions.
+ *
+ * @return the array of actors positions
+ * @see org.splat.dal.bo.som.ValidationCycle.Actor
+ */
public Actor[] getActorTypes() {
return actor;
}
}
- // ==============================================================================================================================
- // Construction
- // ==============================================================================================================================
- protected ProjectSettingsServiceImpl() {
- // ----------------------------
- reprop = new Properties();
- steps = new Vector<ProjectSettingsService.Step>();
- my = this;
- }
-
// ==============================================================================================================================
// Public functions
// ==============================================================================================================================
- public void configure(String filename) throws IOException, SQLException {
- // ---------------------------------------
- if (!steps.isEmpty())
+ /**
+ * Load workflow configuration from the given file. <br/> Create necessary default staff in the database if it is not initialized yet.
+ *
+ * @param filename
+ * the workflow configuration file
+ * @throws IOException
+ * if there is a file reading or index creation problem
+ * @throws SQLException
+ * if there is a database population problem
+ */
+ public void configure(final String filename) throws IOException,
+ SQLException {
+ if (!steps.isEmpty()) {
return; // Project already configured
+ }
Database base = getDatabase().getCheckedDB();
File config = new File(filename);
}
}
+ /**
+ * Get ordered list of (transient) study steps.
+ *
+ * @return the list of steps from project settings
+ */
public List<ProjectSettingsService.Step> getAllSteps() {
- // ---------------------------------------
return steps;
}
*
* @return the validation cycles of the workflow
*/
- public static List<ProjectSettingsValidationCycle> getAllValidationCycles() {
- // -------------------------------------------------------------
- return my.concycles;
+ public List<ProjectSettingsValidationCycle> getAllValidationCycles() {
+ return concycles;
}
+ /**
+ * Get file naming scheme setting.
+ *
+ * @return file naming scheme
+ * @see org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming
+ */
public FileNaming getFileNamingScheme() {
- // -----------------------------------------------
return naming;
}
- public static ProjectSettingsValidationCycle getNewValidationCycle() {
- // ------------------------------------------------------
- return new ProjectSettingsValidationCycle();
- }
-
+ /**
+ * Get a pattern of study references.
+ *
+ * @return the reference pattern
+ */
public String getReferencePattern() {
return pattern;
}
+ /**
+ * Get a pattern of the presentation of version numbers.
+ *
+ * @return the version numbers presentation pattern
+ */
public String getRevisionPattern() {
- // ------------------------------------------
return versioning;
}
- public static ProjectSettingsService.Step getStep(int number) {
- // ---------------------------------------
- for (int i = 0; i < my.steps.size(); i++) {
- ProjectSettingsService.Step step = my.steps.get(i);
- if (step.number == number)
+ /**
+ * Get a study step by its sequential number.
+ *
+ * @param number
+ * the step number
+ * @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;
+ }
}
return null;
}
+ /**
+ * Get steps of the given project element (study or scenario).
+ *
+ * @param level
+ * the project element (study or scenario)
+ * @return the list of steps
+ */
public List<ProjectSettingsService.Step> getStepsOf(
- Class<? extends ProjectElement> level) {
- // ---------------------------------------------------------------------------
+ final Class<? extends ProjectElement> level) {
Vector<ProjectSettingsService.Step> result = new Vector<ProjectSettingsService.Step>();
for (int i = 0; i < steps.size(); i++) {
ProjectSettingsService.Step step = steps.get(i);
- if (step.appliesTo(level))
+ if (step.appliesTo(level)) {
result.add(step);
+ }
}
return result;
}
- // ==============================================================================================================================
- // Protected member function
- // ==============================================================================================================================
-
- public void initialize() {
- // ----------------------------
+ /**
+ * Initialize the database: create all necessary default staff defined in the configuration file.
+ */
+ protected void initialize() {
createDocumentTypes();
createSimulationContextTypes();
createKnowledgeElementTypes();
// Private member function
// ==============================================================================================================================
- private void loadCustomization(File config) {
- // --------------------------------------------
+ /**
+ * Read the configuration file and fill transient project settings fields.
+ *
+ * @param config
+ * the configuration XML file
+ */
+ private void loadCustomization(final File config) {
try {
DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
.newInstance();
String disk = datag.get("repository").getAttributes().getNamedItem(
"disk").getNodeValue();
- if (!disk.endsWith("/"))
+ if (!disk.endsWith("/")) {
disk = disk + "/";
+ }
logger.info("Database root set to " + disk);
reprop.setProperty("repository", disk);
NodeList slist = child.getChildNodes();
for (int j = 0; j < slist.getLength(); j++) {
child = slist.item(j);
- if (!child.getNodeName().equals("step"))
+ if (!child.getNodeName().equals("step")) {
continue;
+ }
HashMap<String, Node> tags = XDOM
.getNamedChildNodes(child);
natr = tags.get("flow").getAttributes();
flist.add(natr);
child = natr.getNamedItem("result");
- if (child != null)
+ if (child != null) {
resultype.add(child.getNodeValue());
+ }
child = tags.get("classification");
- if (child != null)
+ if (child != null) {
clist.add(child.getAttributes());
- else
+ } else {
clist.add(null);
+ }
if (natr.getNamedItem("contents").getNodeValue()
.equals("knowledge")) {
snum += 1;
}
} else {
- if (!child.getNodeName().equals("step"))
+ if (!child.getNodeName().equals("step")) {
continue;
+ }
HashMap<String, Node> tags = XDOM.getNamedChildNodes(child);
natr = tags.get("storage").getAttributes(); // Mandatory information
natr = tags.get("flow").getAttributes();
flist.add(natr);
child = natr.getNamedItem("result");
- if (child != null)
+ if (child != null) {
resultype.add(child.getNodeValue());
+ }
child = tags.get("classification"); // Optional information
- if (child != null)
+ if (child != null) {
clist.add(child.getAttributes());
- else
+ } else {
clist.add(null);
+ }
if (natr.getNamedItem("contents").getNodeValue().equals(
"knowledge")) {
Actor[] actor = { null, null, null };
String name = i.next();
child = datag.get(name);
- if (child == null)
+ if (child == null) {
continue; // Document type not subject of any validation
+ }
natr = child.getAttributes();
for (int j = 0; j < step.length; j++) {
child = natr.getNamedItem(step[j]);
- if (child == null)
+ if (child == null) {
continue; // Validation step not required
+ }
actor[j] = Actor.valueOf(child.getNodeValue());
}
concycles.add(new ProjectSettingsValidationCycle(name, actor));
}
concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
- if (getDatabase().getCheckedDB().isInitialized())
+ if (getDatabase().getCheckedDB().isInitialized()) {
return; // No need to load object type definitions as they are already stored
+ }
// Documents tag
child = children.get("documents");
mapuse = new LinkedHashMap<String, String>();
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("article"))
+ if (!child.getNodeName().equals("article")) {
continue;
+ }
natr = child.getAttributes();
String type = natr.getNamedItem("type").getNodeValue();
String uses = null;
child = natr.getNamedItem("uses");
- if (child != null)
+ if (child != null) {
uses = child.getNodeValue();
+ }
mapuse.put(type, uses); // Must be added to the map even if no (null) uses
}
// Simulation Contexts tag
context = new Vector<String>();
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("article"))
+ if (!child.getNodeName().equals("article")) {
continue;
+ }
context.add(child.getAttributes().getNamedItem("type")
.getNodeValue());
kname = new Vector<String>();
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("article"))
+ if (!child.getNodeName().equals("article")) {
continue;
+ }
kname.add(child.getAttributes().getNamedItem("type")
.getNodeValue());
}
}
+ /**
+ * Create in the database document types defined in the custom configuration.
+ */
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>();
continue;
}
slist = mapsteps.get(type);
- if (slist == null)
+ if (slist == null) {
slist = new Vector<ProjectSettingsService.Step>();
+ }
slist.add(step);
mapsteps.put(type, slist);
}
Node result = flow.getNamedItem("result");
- if (result != null)
+ if (result != null) {
mapresult.put(result.getNodeValue(), step);
+ }
}
try {
DocumentType tdoc = null;
.size()]));
if (uses != null) {
tdoc = maptype.get(uses);
- if (tdoc == null)
+ if (tdoc == null) {
logger
.warn("Undefined \"" + uses
+ "\" document type.");
- else
+ } else {
tprop.setUses(tdoc);
+ }
}
- if (step != null)
+ if (step != null) {
tprop.setResult(step);
+ }
tprop.disableCheck();
tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
}
}
+ /**
+ * Create in the database knowledge types defined in the custom configuration.
+ */
private void createKnowledgeElementTypes() {
- // -------------------------------------------
try {
KnowledgeElementType ktype = getKnowledgeElementTypeService()
.createType("usecase"); // Internal reserved knowledge element type
}
}
+ /**
+ * 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>();
int snum = 0;
for (Iterator<NamedNodeMap> i = sclass.iterator(); i.hasNext(); snum++) {
NamedNodeMap clatr = i.next();
- if (clatr == null)
+ if (clatr == null) {
continue;
+ }
String[] clist = clatr.getNamedItem("context").getNodeValue()
.split(",");
* @param database
* the database to set
*/
- public void setDatabase(Database database) {
+ public void setDatabase(final Database database) {
_database = database;
}
* the simulationContextTypeService to set
*/
public void setSimulationContextTypeService(
- SimulationContextTypeService simulationContextTypeService) {
+ final SimulationContextTypeService simulationContextTypeService) {
_simulationContextTypeService = simulationContextTypeService;
}
* the knowledgeElementTypeService to set
*/
public void setKnowledgeElementTypeService(
- KnowledgeElementTypeService knowledgeElementTypeService) {
+ final KnowledgeElementTypeService knowledgeElementTypeService) {
_knowledgeElementTypeService = knowledgeElementTypeService;
}
/**
* Get the documentTypeService.
+ *
* @return the documentTypeService
*/
public DocumentTypeService getDocumentTypeService() {
/**
* Set the documentTypeService.
- * @param documentTypeService the documentTypeService to set
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
*/
- public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ public void setDocumentTypeService(
+ final DocumentTypeService documentTypeService) {
_documentTypeService = documentTypeService;
}
}
\ No newline at end of file