Salome HOME
e0e7083a9f7a1201203ff705fc4af8e96f4bab84
[tools/siman.git] / Workspace / Siman-Common / src / test / Test.java
1 package test;
2
3 import java.io.File;
4 import java.text.SimpleDateFormat;
5 import java.util.Date;
6 import java.util.Iterator;
7 import java.util.List;
8 import java.util.Vector;
9
10 import org.splat.som.*;
11 import org.splat.kernel.Do;
12 import org.splat.kernel.UserDirectory;
13 import org.splat.kernel.User;
14 import org.splat.kernel.Role;
15 import org.splat.manox.Reader;
16 import org.splat.manox.Toolbox;
17 import org.splat.manox.Writer;
18
19 import org.hibernate.Session;
20 import org.hibernate.Transaction;
21 import org.apache.log4j.Logger;
22
23
24 public class Test {
25         
26     final static Logger logger = Logger.getLogger(Test.class);
27
28 //  ==============================================================================================================================
29 //  Main
30 //  ==============================================================================================================================
31
32         public static void main(String[] args) {
33 //  --------------------------------------
34       Session     session = Database.getSession();       // Single session for multiple operations
35       Transaction transax = session.beginTransaction();   
36                   
37           ProjectSettings project = ProjectSettings.getMe();
38           String          path    = System.getProperty("user.dir");
39       try {
40             project.configure(path + "/src/som.xml");
41           }
42           catch (Exception error) {
43                 logger.fatal("Could not initialize the database, reason:", error);
44                 return;
45           }
46           int nargs = args.length;
47           if (nargs > 0) switch (Integer.valueOf(args[0])) {
48
49             case 1:
50         if (!importation_of_users()) return;
51         break;
52
53             case 2:
54         if (!create_narveos_study()) return;
55         break;
56
57             case 3:
58         if (!create_tripoli_study()) return;
59         break;
60
61             case 4:
62         if (!select_user_by_username()) return;
63         break;
64
65             case 5:
66         if (!select_study_by_state()) return;
67         break;
68
69             case 6:
70         if (!select_study_by_title()) return;
71         break;
72
73             case 7:
74         if (!select_study_by_reference()) return;
75         break;
76
77             case 8:
78         if (!select_study_by_context()) return;
79         break;
80
81             case 9:
82         if (!select_document_by_reference()) return;
83         break;
84
85             case 10:
86         if (!select_knowledge_by_context()) return;
87         break;
88
89             case 11:
90             if (!browse_knowledge()) return;
91             break;
92
93             case 12:
94             if (!read_wordxml_properties()) return;
95             break;
96
97             case 13:
98             if (!read_worddoc_properties()) return;
99           }
100       transax.commit();
101     }
102         
103         private static boolean importation_of_users () {
104 //  ----------------------------------------------
105       try {
106                 UserDirectory.importUsers(new File("C:/Users/Daniel/Projets/Internes/SaLoMe/Workspace/org.splat/src/users.xml"));
107         
108 //        Print of imported users         
109             List<User> result = UserDirectory.selectAllUsers();
110             for (Iterator<User> i=result.iterator(); i.hasNext();) {
111           User   auser = i.next();
112           Role[] role  = auser.getRoles();
113               String echo  = "Role(s) of user " + auser.getIndex() + " (" + auser.toString()  + "): " + role[0].getName();
114               for (int j=1; j<role.length; j++) echo = echo + ", " + role[j].getName();
115               logger.info(echo);
116             }
117             return true;
118       }
119       catch (Exception error) {
120         logger.info("Reason:", error);
121         return false;
122       }
123         }
124
125         private static boolean create_narveos_study () {
126 //  ----------------------------------------------
127       try {
128
129         User.Properties uprop = new User.Properties();
130         List<User>      ulist = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Euriware"));
131         User jb = ulist.get(0);                                    // Manager of the study
132         User pd = ulist.get(1);                                    // Author of specifications
133         User hl = UserDirectory.selectUser("hl");                  // Geometry expert
134         User sd = UserDirectory.selectUser("sdd");                 // Customer
135
136
137 //    Creation of the Study object
138         SimpleDateFormat on    = new SimpleDateFormat("dd/MM/yyyy");
139         SimpleDateFormat at    = new SimpleDateFormat("dd/MM/yyyy HH:mm");
140         Study.Properties sprop = new Study.Properties();
141
142         Date  someday = on.parse("25/01/2010");
143         Study mystudy = Database.createStudy(sprop.setTitle("Caractérisation du béton SERCOTER").setDate(someday).setManager(jb)
144                                                           .setDescription("Cette étude est livrée avec l'application comme exemple pour tester les fonctions de recherche et de navigation."));
145
146
147 //    Addition of the default scenario
148         Scenario.Properties oprop = new Scenario.Properties();
149         Scenario myscenar = mystudy.addScenario(oprop.setTitle("Scénario 1").setDate(someday));
150
151
152 //    Definition of the project team
153         mystudy.addContributor(pd);
154
155
156 //    Addition of documents
157         Step[]              ownstep  = mystudy.getSteps();
158         Step[]              nexstep  = myscenar.getSteps();
159         Document.Properties dprop;
160         DocumentType        request  = Document.selectType("requirements");
161         DocumentType        spec     = Document.selectType("specification");
162         DocumentType        geom     = Document.selectType("geometry");
163         DocumentType        note     = Document.selectType("memorandum");
164         DocumentType        delivery = Document.selectType("report");   // Final report of the study
165
166 //    Set of document validation cycles
167         mystudy.setValidationCycle(geom, new ValidationCycle.Properties().setActor(ValidationStep.REVIEW, hl)
168                                                                                  .setActor(ValidationStep.APPROVAL, jb));
169 //      (1) Customer requirements
170         dprop = new Document.Properties();
171         Publication  cdc      = ownstep[0].createDocument(dprop.setName("Proposition technique")
172                                                             .setExternReference("GCVP-P/09-1629/V1")
173                                                             .setDate(on.parse("08/02/2010"))
174                                                             .setType(request)
175                                                             .setFormat("pdf")
176                                                             .setAuthor(sd));
177         logger.info("Uploading file \"" + cdc.getSourceFile().getName() + "\" into " + cdc.value().getSaveDirectory().getPath());
178         cdc.saveAs(ProgressState.EXTERN);
179
180 //      (2)(3) General specifications based on (using) Customer requirements
181         dprop.clear();
182         Publication  specgen  = ownstep[0].createDocument(dprop.setName("Spécifications générales")
183                                                             .setDate(on.parse("05/03/2010"))
184                                                             .setType(spec)
185                                                             .setFormat("xml")
186                                                             .setAuthor(pd));
187         logger.info("Uploading file \"" + specgen.getSourceFile().getName() + "\" into " + specgen.value().getSaveDirectory().getPath());
188         specgen.saveAs(ProgressState.inWORK);         // Version 0.1
189         specgen.addDependency(cdc);
190         
191         dprop.clear();
192         specgen = ownstep[0].versionDocument(specgen, dprop.setDate(on.parse("12/03/2010"))
193                                                                 .setDescription("Ajout de la description du scénario de calcul"));        
194         specgen.saveAs(ProgressState.inWORK);         // Version 0.2
195         specgen.addDependency(cdc);
196
197 //      (4) Assembly geometry based on (using) General specifications
198         dprop.clear();
199         Publication  sercoter = nexstep[1].createDocument(dprop.setName("Assemblage SERCOTER")
200                                                             .setDate(on.parse("26/03/2010"))
201                                                             .setType(geom)
202                                                             .setFormat("sldasm")
203                                                             .setAuthor(jb));
204         logger.info("Uploading file \"" + sercoter.getSourceFile().getName() + "\" into " + sercoter.value().getSaveDirectory().getPath());
205         sercoter.saveAs(ProgressState.inWORK);
206         sercoter.addDependency(specgen);
207
208 //      (5) Technical note based on (using) General specifications and Assembly geometry
209         dprop.clear();
210         Publication  report = nexstep[1].createDocument(dprop.setName("Modifications et simplifications retenues")
211                                                             .setDate(on.parse("26/03/2010"))
212                                                             .setType(note)
213                                                             .setFormat("doc")
214                                                             .setAuthor(jb));
215         logger.info("Uploading file \"" + report.getSourceFile().getName()   + "\" into " + report.value().getSaveDirectory().getPath());
216         report.saveAs(ProgressState.inWORK);
217         report.addDependency(specgen);
218         report.addDependency(sercoter);
219         report.promote(on.parse("26/03/2010"));
220
221 //      (6) New version of General specifications
222         dprop.clear();
223         specgen = ownstep[0].versionDocument(specgen, dprop.setDate(on.parse("24/03/2010"))
224                                                         .setDescription("Prise en compte des retours internes"));        
225         specgen.saveAs(ProgressState.inDRAFT);                // Version 0.3
226         specgen.addDependency(cdc);
227
228         specgen.review(at.parse("26/03/2010 10:15"));         // Promotion to version 1.0
229         specgen.attach("pdf");
230         specgen.approve(at.parse("26/03/2010 16:30")).setComment("Le document peut être envoyé au client.");
231         logger.info("Uploading file \"" + specgen.value().getTitle() + ".pdf\" into " + specgen.value().getSaveDirectory().getPath());
232
233 //      (7)
234         Publication    result = ownstep[1].createDocument(dprop.setName("Comparaison des résultats")
235                                                             .setDate(on.parse("16/04/2010"))
236                                                             .setType(delivery)
237                                                             .setFormat("xml")
238                                                             .setAuthor(jb));
239         logger.info("Uploading file \"" + result.getSourceFile().getName() + "\" into " + result.value().getSaveDirectory().getPath());
240         result.saveAs(ProgressState.inDRAFT);                 // Promotes the study to In-Draft
241         result.review (at.parse("19/04/2010 10:15"));         // Promotes the study to In-Check
242
243
244 //    Assignment of simulation contexts
245         SimulationContext.Properties cprop     = new SimulationContext.Properties();        
246         SimulationContextType        customer  = SimulationContext.selectType("customer");
247         SimulationContextType        product   = SimulationContext.selectType("product");
248         SimulationContextType        phase     = SimulationContext.selectType("phase");
249         SimulationContextType        need      = SimulationContext.selectType("need");
250         SimulationContextType        subject   = SimulationContext.selectType("purpose");
251         SimulationContextType        physics   = SimulationContext.selectType("physic");
252         SimulationContextType        object    = SimulationContext.selectType("object");
253         SimulationContextType        part      = SimulationContext.selectType("part");
254         SimulationContextType        model     = SimulationContext.selectType("model");
255         SimulationContextType        element   = SimulationContext.selectType("element");
256         SimulationContextType        shape     = SimulationContext.selectType("shape");
257         SimulationContextType        platform  = SimulationContext.selectType("platform");
258         SimulationContextType        module    = SimulationContext.selectType("module");
259         SimulationContextType        component = SimulationContext.selectType("component");
260
261         List<SimulationContext> ihave = mystudy.getFirstStep().getSimulationContext(customer);
262         if (ihave.size() > 0)   ihave.get(0).approve();     // Generated from specifications
263         else {
264           SimulationContext  imported = Database.selectSimulationContext(customer, "CEA Cadarache");
265           if (imported == null) {
266             mystudy.addProjectContext(cprop.setType(customer).setValue("CEA Cadarache").setState(ProgressState.APPROVED));
267           } else {
268             mystudy.addProjectContext(imported);            // Previously generated
269           }
270         }
271         ihave = mystudy.getFirstStep().getSimulationContext(product);
272         if (ihave.size() > 0) ihave.get(0).approve();       // Generated from specifications
273         else {
274           SimulationContext  imported = Database.selectSimulationContext(product, "Réacteur RAPSODIE");
275           if (imported == null) {
276             mystudy.addProjectContext(cprop.setType(product).setValue("Réacteur RAPSODIE").setState(ProgressState.APPROVED));
277           } else {
278             mystudy.addProjectContext(imported);            // Previously generated
279           }
280         }
281         mystudy.addProjectContext(cprop.setType(phase).setValue("Démantèlement").setState(ProgressState.APPROVED));        
282         mystudy.addProjectContext(cprop.setType(need).setValue("Caractérisation du béton SERCOTER").setState(ProgressState.APPROVED));        
283         mystudy.addProjectContext(cprop.setType(subject).setValue("Valider les résultats d'une précédente étude").setState(ProgressState.APPROVED));
284         mystudy.addProjectContext(cprop.setType(physics).setValue("Transport de particules").setState(ProgressState.APPROVED));
285         nexstep[1].addSimulationContext(cprop.setType(object).setValue("Réacteur nucléaire").setState(ProgressState.APPROVED));
286         nexstep[1].addSimulationContext(cprop.setType(part).setValue("Ensemble Bloc réacteur et Enceinte en béton").setState(ProgressState.APPROVED));
287 //      nexstep[2].addSimulationContext(cprop.setType(model).setValue("CSG"));
288         nexstep[2].addSimulationContext(cprop.setType(model).setValue("Éléments finis").setState(ProgressState.APPROVED));
289         nexstep[2].addSimulationContext(cprop.setType(element).setValue("Surfacique").setState(ProgressState.APPROVED));
290         nexstep[2].addSimulationContext(cprop.setType(shape).setValue("Triangles").setState(ProgressState.APPROVED));
291         nexstep[4].addSimulationContext(cprop.setType(platform).setValue("NARVEOS V3").setState(ProgressState.APPROVED));
292         nexstep[4].addSimulationContext(cprop.setType(module).setValue("NARMER V2").setState(ProgressState.APPROVED));
293         nexstep[4].addSimulationContext(cprop.setType(component).setValue("VIRTOOLS V5").setState(ProgressState.APPROVED));
294
295 //    Assignment of a knowledge
296         KnowledgeElement.Properties kprop      = new KnowledgeElement.Properties();
297         KnowledgeElementType        practice   = KnowledgeElement.selectType("bestpractice");
298         KnowledgeElementType        limit      = KnowledgeElement.selectType("limitation");
299         KnowledgeElementType        improvment = KnowledgeElement.selectType("improvement");
300         kprop.setType(limit)
301              .setTitle("Format du modèle géométrique")
302              .setValue("Seul le format 3DXML V5 ou antérieur est supporté.")
303 //           .setState(ProgressState.APPROVED)
304              .setAuthor(jb);
305         myscenar.addKnowledgeElement(kprop);
306         kprop.setType(practice)
307                  .setTitle("Compréhension de l'environnement")
308                  .setValue("Avoir une compréhension globale du débit de dose en commençant par effectuer une cartographie.")
309                  .setState(ProgressState.APPROVED)
310                  .setAuthor(jb);
311             myscenar.addKnowledgeElement(kprop);
312         kprop.setType(practice)
313                  .setTitle("Calage du modèle radiologique")
314                  .setValue("A partir de sources à 1 Bq/m<sup>3</sup>, faire évoluer une source à la fois et vérifier l'impact sur les points de calcul pour connaitre l'influence relative des sources.")
315                  .setState(ProgressState.APPROVED)
316                  .setAuthor(jb);
317             myscenar.addKnowledgeElement(kprop);
318         kprop.setType(practice)
319                  .setTitle("Calage du modèle radiologique")
320                  .setValue("Toujours faire le premier calcul sans built-up.")
321                  .setState(ProgressState.APPROVED)
322                  .setAuthor(jb);
323             myscenar.addKnowledgeElement(kprop);
324         kprop.setType(limit)
325                  .setTitle("Effets diffusés indirects")
326                  .setValue("L'outil ne tenant pas compte des effets diffusés indirects, faire attention à la géométrie autour des points de calcul.")
327                  .setState(ProgressState.APPROVED)
328                  .setAuthor(jb);
329             myscenar.addKnowledgeElement(kprop);
330         kprop.setType(improvment)
331                  .setTitle("Gestion des écrans")
332                  .setValue("Mieux gérer les multi-écrans à géométrie cylindrique.")
333                  .setState(ProgressState.inCHECK)     // Just for testing the approve() function below
334                  .setAuthor(jb);
335             KnowledgeElement kelm = myscenar.addKnowledgeElement(kprop);
336
337         kelm.approve();
338
339         mystudy.moveToPublic();
340
341             logger.info("Study \"" + mystudy.getTitle() + "\" successfully created.");
342             return true;
343       }
344       catch (Exception error) {
345         logger.info("Reason:", error);
346         return false;
347       }
348         }
349         
350         private static boolean create_tripoli_study () {
351 //  ----------------------------------------------
352       User plt = UserDirectory.selectUser("sdd");
353       try {
354 //    Creation of the Study object
355         SimpleDateFormat todate = new SimpleDateFormat("dd/MM/yyyy");
356         Study.Properties sprop  = new Study.Properties();
357
358         Date  at      = todate.parse("03/05/2011");
359         Study mystudy = Database.createStudy(sprop.setTitle("Validation des voies de production de la plate-forme Radioprotection").setDate(at).setManager(plt));
360
361 //    Addition of scenarios
362         Scenario.Properties oprop = new Scenario.Properties();
363         Scenario myscenar = mystudy.addScenario(oprop.setTitle("Scénario Tripoli").setDate(at));
364                             mystudy.addScenario(oprop.setTitle("Scénario MCNP").setDate(at));
365
366 //    Addition of documents
367         Step[]              ownstep  = mystudy.getSteps();
368         Step[]              nexstep  = myscenar.getSteps();
369         
370         DocumentType        request  = Document.selectType("requirements");
371         DocumentType        spec     = Document.selectType("specification");
372         DocumentType        geom     = Document.selectType("geometry");
373         DocumentType        mesh     = Document.selectType("model");
374         DocumentType        note     = Document.selectType("memorandum");
375         DocumentType        delivery = Document.selectType("report");   // Final report of the study
376         Document.Properties dprop;
377
378         dprop = new Document.Properties();
379         Publication  cdc  = ownstep[0].createDocument(dprop.setName("Cahier des charges")
380                                                      .setDate(todate.parse("03/05/2011"))
381                                                      .setType(request)
382                                                      .setFormat("pdf")
383                                                      .setAuthor(plt));
384         logger.info("Uploading file \"" + cdc.getSourceFile().getName() + "\" into " + cdc.value().getSaveDirectory().getPath());
385         cdc.saveAs(ProgressState.EXTERN);
386         
387         dprop = new Document.Properties();
388         Publication  sgen = ownstep[0].createDocument(dprop.setName("Spécifications générales")
389                                                      .setDate(todate.parse("03/05/2010"))
390                                                      .setType(spec)
391                                                      .setFormat("xml")
392                                                      .setAuthor(plt));
393         logger.info("Uploading file \"" + sgen.getSourceFile().getName() + "\" into " + sgen.value().getSaveDirectory().getPath());
394         sgen.saveAs(ProgressState.inDRAFT);         // Version 0.1
395         sgen.addDependency(cdc);
396
397         dprop = new Document.Properties();
398         Publication  pcc = nexstep[1].createDocument(dprop.setName("Assemblage PCC")
399                                                        .setDate(todate.parse("03/05/2011"))
400                                                        .setType(geom)
401                                                        .setFormat("ProE")
402                                                        .setAuthor(plt));
403         Publication  doc = nexstep[1].createDocument(dprop.setName("Description de l'assemblage")
404                                                        .setDate(todate.parse("03/05/2011"))
405                                                        .setType(note)
406                                                        .setFormat("doc")
407                                                        .setAuthor(plt));
408         logger.info("Uploading file \"" + pcc.getSourceFile().getName() + "\" into " + pcc.value().getSaveDirectory().getPath());
409         logger.info("Uploading file \"" + doc.getSourceFile().getName() + "\" into " + doc.value().getSaveDirectory().getPath());
410         pcc.saveAs(ProgressState.inDRAFT);
411         doc.saveAs(ProgressState.inCHECK);
412
413         pcc.review(todate.parse("08/05/2011"));
414         pcc.addDependency(sgen);
415         doc.addDependency(sgen);
416         doc.addDependency(pcc);
417         
418         pcc.attach("gdml");
419         logger.info("Uploading file \"" + pcc.value().getTitle() + ".gdml\" into " + pcc.value().getSaveDirectory().getPath());
420
421         dprop = new Document.Properties();
422         Publication  csg = nexstep[2].createDocument(dprop.setName("PCC")
423                                                        .setDate(todate.parse("03/05/2011"))
424                                                        .setType(mesh)
425                                                        .setFormat("hdf")
426                                                        .setAuthor(plt));
427         logger.info("Uploading file \"" + csg.getSourceFile().getName() + "\" into " + csg.value().getSaveDirectory().getPath());
428         csg.saveAs(ProgressState.inDRAFT);
429
430         csg.addDependency(pcc);
431         
432         csg.attach("gdml", "sans void space");
433         csg.attach("tri",  "avec void space");
434         csg.attach("pdf");
435         logger.info("Uploading file \"" + csg.value().getTitle() + ".tri\" into " + csg.value().getSaveDirectory().getPath());
436
437         Publication    result = ownstep[1].createDocument(dprop.setName("Comparaison des résultats")
438                                                        .setDate(todate.parse("17/05/2011"))
439                                                        .setType(delivery)
440                                                        .setFormat("xml")
441                                                        .setAuthor(plt));
442         logger.info("Uploading file \"" + result.getSourceFile().getName() + "\" into " + result.value().getSaveDirectory().getPath());
443         result.saveAs(ProgressState.inWORK);        // Version 0.1
444         result.promote(todate.parse("18/05/2011"));                           // Promotes also the study
445
446 //    Assignment of simulation contexts
447         SimulationContext.Properties cprop     = new SimulationContext.Properties();        
448         SimulationContextType        customer  = SimulationContext.selectType("customer");
449         SimulationContextType        product   = SimulationContext.selectType("product");
450         SimulationContextType        phase     = SimulationContext.selectType("phase");
451         SimulationContextType        need      = SimulationContext.selectType("need");
452         SimulationContextType        subject   = SimulationContext.selectType("purpose");
453         SimulationContextType        physics   = SimulationContext.selectType("physic");
454         SimulationContextType        object    = SimulationContext.selectType("object");
455         SimulationContextType        part      = SimulationContext.selectType("part");
456         SimulationContextType        model     = SimulationContext.selectType("model");
457         SimulationContextType        element   = SimulationContext.selectType("element");
458         SimulationContextType        shape     = SimulationContext.selectType("shape");
459         SimulationContextType        platform  = SimulationContext.selectType("platform");
460         SimulationContextType        module    = SimulationContext.selectType("module");
461
462         List<SimulationContext> ihave = mystudy.getFirstStep().getSimulationContext(customer);
463         if (ihave.size() > 0)   ihave.get(0).approve();     // Generated from specifications
464         else {
465           SimulationContext imported = Database.selectSimulationContext(customer, "Fonction transverse sûreté");
466           if (imported == null) {
467             mystudy.addProjectContext(cprop.setType(customer).setValue("Fonction transverse sûreté").setState(ProgressState.APPROVED));
468           } else {
469             mystudy.addProjectContext(imported);     // Not generated from specifications
470           }
471         }
472         ihave = mystudy.getFirstStep().getSimulationContext(product);
473         if (ihave.size() > 0)   ihave.get(0).approve();     // Generated from specifications
474         else {
475           SimulationContext imported = Database.selectSimulationContext(product, "Laser Mégajoule");
476           if (imported == null) {
477             mystudy.addProjectContext(cprop.setType(product).setValue("Laser Mégajoule").setState(ProgressState.APPROVED));        
478           } else {
479             mystudy.addProjectContext(imported);     // Not generated from specifications
480           }
481         }
482         mystudy.addProjectContext(cprop.setType(phase).setValue("Dossier de Validation DSGA/SSPP").setState(ProgressState.APPROVED));        
483         mystudy.addProjectContext(cprop.setType(need).setValue("Validation du calcul TRIPOLI4.5 via le PlugIn Pro/E").setState(ProgressState.APPROVED));        
484         mystudy.addProjectContext(cprop.setType(subject).setValue("Cartographie neutronique").setState(ProgressState.APPROVED));
485         mystudy.addProjectContext(Database.selectSimulationContext(physics, "Transport de particules"));
486         nexstep[1].addSimulationContext(cprop.setType(object).setValue("Bâtiment LMJ").setState(ProgressState.APPROVED));
487         nexstep[1].addSimulationContext(cprop.setType(part).setValue("Bât. Nord, Sud, Hall d'expériences, Hall lasers").setState(ProgressState.APPROVED));
488         nexstep[2].addSimulationContext(cprop.setType(model).setValue("CSG").setState(ProgressState.APPROVED));
489         nexstep[2].addSimulationContext(cprop.setType(element).setValue("Monte Carlo ").setState(ProgressState.APPROVED));
490         nexstep[2].addSimulationContext(cprop.setType(shape).setValue("Combinatoire volumique").setState(ProgressState.APPROVED));
491         nexstep[4].addSimulationContext(cprop.setType(platform).setValue("SALOME-TRIPOLI V2.04").setState(ProgressState.APPROVED));
492         nexstep[4].addSimulationContext(cprop.setType(module).setValue("TRIPOLI4.5").setState(ProgressState.APPROVED));
493
494 //      Assignment of a knowledge
495         KnowledgeElement.Properties kprop      = new KnowledgeElement.Properties();
496         KnowledgeElementType        practice   = KnowledgeElement.selectType("bestpractice");
497         KnowledgeElementType        limit      = KnowledgeElement.selectType("limitation");
498         KnowledgeElementType        improvment = KnowledgeElement.selectType("improvement");
499         kprop.setType(practice)
500              .setTitle("Compréhension des modèles CAO")
501              .setValue("Convertir le modèle CAO par élément (part) et constituer les assemblages sous GDML en vérifiant à chaque étape qu'il n'existe pas d'intersection entre les éléments.")
502              .setState(ProgressState.APPROVED)
503              .setAuthor(plt);
504         myscenar.addKnowledgeElement(kprop);
505         kprop.setType(practice)
506              .setTitle("Génération du volume complémentaire")
507              .setValue("Appliquer la génération du volume complémentaire au modèle GDML global de l'installation en sauvegardant le découpage de l'espace complémentaire en tant que volume.")
508              .setState(ProgressState.APPROVED)
509              .setAuthor(plt);
510         myscenar.addKnowledgeElement(kprop);
511         kprop.setType(limit)
512              .setTitle("Découpage du volume complémentaire")
513              .setValue("Inutile de découper le complémentaire pour le code TRIPOLI4.5. Les performances calculs ne sont pas meilleures.")
514              .setState(ProgressState.APPROVED)
515              .setAuthor(plt);
516         myscenar.addKnowledgeElement(kprop);
517         kprop.setType(limit)
518              .setTitle("Option de pondération")
519              .setValue("impossible de visualiser sous le viewer OCC les grilles de pondération dans la géométrie (temps d'affichage prohibitif).")
520              .setState(ProgressState.APPROVED)
521              .setAuthor(plt);
522         myscenar.addKnowledgeElement(kprop);
523         kprop.setType(improvment)
524              .setTitle("Grille de pondération TRIPOLI4.5")
525              .setValue("Faire évoluer le viewer Ray tracing pour qu'il puisse afficher les grilles de pondération et de maillage.")
526              .setState(ProgressState.APPROVED)
527              .setAuthor(plt);
528         myscenar.addKnowledgeElement(kprop);
529
530         mystudy.moveToPublic();
531
532             logger.info("Study \"" + mystudy.getTitle() + "\" successfully created.");
533             return true;
534       }
535       catch (Exception error) {
536         logger.info("Reason:", error);
537         return false;
538       }
539         }
540
541     private static boolean select_user_by_username () {
542 //  -------------------------------------------------
543       String jbt  = "jbt";
544       try {
545         User   user = UserDirectory.selectUser(jbt);
546         if (user == null) {
547           logger.info("User " + jbt + " not found.");
548         } else {
549           logger.info("User " + jbt + " found:");
550           logger.info("* " + user.getDisplayName() + ", role \"" + user.getRoleNames() + "\"");
551         }
552         return true;
553       }
554       catch (Exception e) {
555         return false;
556       }
557     }
558
559     private static boolean select_study_by_state () {
560 //  -----------------------------------------------
561       String dbc  = "jbt";
562       User   user = UserDirectory.selectUser(dbc);
563       try {
564         Study.Properties  criter1 = new Study.Properties().setState(ProgressState.inPROGRESS);
565         Study.Properties  criter2 = new Study.Properties().setState(ProgressState.inWORK).setManager(user);
566         List<Proxy>       result  = Database.selectStudiesWhere(criter1, criter2);
567         if (result.size() == 0) {
568           logger.info("No study found.");
569         } else {
570           logger.info("Study(ies) found:");
571           for (int i=0; i<result.size(); i++) {
572             logger.info("* \"" + result.get(i).getTitle() + "\"");
573           }
574         }
575         return true;
576       }
577       catch (Exception e) {
578         return false;
579       }
580     }
581
582     private static boolean select_study_by_title () {
583 //  -----------------------------------------------
584       String words = "sercoter";
585       try {
586         Study.Properties  criteria = new Study.Properties();
587         List<Proxy>       result   = Database.selectStudiesWhere(criteria.setTitle(words));
588         if (result.size() == 0) {
589           logger.info("No study found with a title including \"" + words + "\".");
590         } else {
591           logger.info("Study(ies) found:");
592           for (int i=0; i<result.size(); i++) {
593             logger.info("* \"" + result.get(i).getTitle() + "\"");
594           }
595         }
596         return true;
597       }
598       catch (Exception e) {
599         return false;
600       }
601     }
602
603     private static boolean select_study_by_reference () {
604 //  ---------------------------------------------------
605       String refid = "PLM110001";      
606       try {
607         Study  study = Database.selectStudy(refid);
608         if (study == null) {
609           logger.info("Study " + refid + " not found.");
610           return false;
611         } else {
612           logger.info("Study " + refid + ": " + study.getTitle() + ".");
613           display_study(study);
614           return true;
615         }
616       }
617       catch (Exception e) {
618         return false;
619       }
620     }
621     
622     private static boolean select_study_by_context () {
623 //  -------------------------------------------------
624       SimulationContext.Properties cprop   = new SimulationContext.Properties();
625       SimulationContextType        ctype   = SimulationContext.selectType("Produit");
626       List<SimulationContext>      context = Database.selectSimulationContextsWhere(cprop.setType(ctype));
627       for (Iterator<SimulationContext> i=context.iterator(); i.hasNext();) {
628         SimulationContext reactor = i.next();
629         if (reactor.getValue().equals("Réacteur RAPSODIE")) {
630
631           context = new Vector<SimulationContext>();
632           context.add(reactor);
633                 
634           Study.Properties sprop = new Study.Properties();
635           List<Proxy> result = Database.selectStudiesWhere(sprop.setSimulationContexts(context)
636                                                                             .setState(ProgressState.inPROGRESS));
637           if (result.size() == 0) {
638             logger.info("Study on Réacteur RAPSODIE not found.");
639             return false;
640           } else {
641             logger.info("Study on Réacteur RAPSODIE: " + result.get(0).getTitle() + ".");
642             return true;
643           }
644         }
645       }
646       return false;
647     }
648
649     private static boolean select_document_by_reference () {
650 //  ------------------------------------------------------
651       String  refid = "PLM100001.02";     
652       String  verid = "2.0.0";
653       try {
654         Document result = Database.selectDocument(refid, verid);
655         String   title  = result.getTitle();
656         String   refdoc = result.getReference();
657         logger.info("Document " + refdoc + ": " + title + ".");
658         return true;
659       }
660       catch (Exception e) {
661         return false;
662       }
663     }
664
665     private static boolean select_knowledge_by_context () {
666 //  -------------------------------------------------
667       SimulationContext.Properties cprop   = new SimulationContext.Properties();
668       SimulationContextType        ctype   = SimulationContext.selectType("Produit");
669       List<SimulationContext>      context = Database.selectSimulationContextsWhere(cprop.setType(ctype));
670       for (Iterator<SimulationContext> i=context.iterator(); i.hasNext();) {
671         SimulationContext reactor = i.next();
672         if (reactor.getValue().equals("Réacteur RAPSODIE")) {
673
674           context = new Vector<SimulationContext>();
675           context.add(reactor);
676
677           KnowledgeElementType        ktype = KnowledgeElement.selectType("Bonne pratique");
678           KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
679           List<Proxy> result = Database.selectKnowledgeElementsWhere(sprop.setSimulationContexts(context)
680                                                                                       .setType(ktype));
681           if (result.size() == 0) {
682             logger.info("Study on Réacteur RAPSODIE not found.");
683             return false;
684           } else {
685             logger.info("Study on Réacteur RAPSODIE: " + result.get(0).getTitle() + ".");
686             return true;
687           }
688         }
689       }
690       return false;
691     }
692
693     private static boolean display_study (Study study) {
694 //  --------------------------------------------------
695       try {
696         Step[]            mystep = study.getSteps();
697         Scenario[]        branch = study.getScenarii();
698         List<Publication> list;
699
700         for (int j=0; j<mystep.length; j++) {
701           Step   step = mystep[j];
702           list = step.getAllDocuments();
703           if (list.size() == 0) continue;
704           logger.info("Step 0." + j + ":");
705           for (Iterator<Publication> k=list.iterator(); k.hasNext();) {
706             Publication       doc     = k.next();
707             String            output  = "* " + doc.value().getTitle();
708             List<Publication> exports = doc.getRelations(ConvertsRelation.class);
709             if (exports.size() > 0) {
710               output = output + " et export(s)";
711               for (Iterator<Publication> m=exports.iterator(); m.hasNext(); ) {
712                 output = output + " " + m.next().getSourceFile().getName();
713               }
714             }
715             logger.info(output);
716           }
717         }
718         for (int i=0; i<branch.length; i++) {
719           Scenario scene  = branch[i];
720                    mystep = scene.getSteps();
721           for (int j=0; j<mystep.length; j++) {
722             Step   step = mystep[j];
723             list = step.getAllDocuments();
724             if (list.size() == 0) continue;
725             logger.info("Step " + (i+1) + "." + j + ":");
726             for (Iterator<Publication> k=list.iterator(); k.hasNext();) {
727               Publication       doc     = k.next();
728               String            output  = "* " + doc.value().getTitle();
729               List<Publication> exports = doc.getRelations(ConvertsRelation.class);
730               if (exports.size() > 0) {
731                 output = output + " et export(s)";
732                 for (Iterator<Publication> m=exports.iterator(); m.hasNext(); ) {
733                   output = output + " " + m.next().getSourceFile().getName();
734                 }
735               }
736               logger.info(output);
737             }
738           }
739         }
740         return true;
741       }
742       catch (Exception e) {
743         return false;
744       }
745     }
746
747     private static boolean browse_knowledge () {
748 //  ------------------------------------------
749       try {
750         Study                       study  = Database.selectStudy(1);
751         Scenario[]                  branch = study.getScenarii();
752             List<KnowledgeElementType>  types  = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
753
754         for (int i=0; i<branch.length; i++) {
755           Scenario                   scene = branch[i];
756           List<KnowledgeElement>     kelms = scene.getAllKnowledgeElements();
757           Iterator<KnowledgeElement> more  = kelms.iterator();
758           KnowledgeElement           next  = null;
759           if (more.hasNext())        next  = more.next();
760
761           for (Iterator<KnowledgeElementType> j=types.iterator(); j.hasNext();) {
762             KnowledgeElementType  type = j.next();
763             logger.info(type.getName() + ":");
764             while (next != null && next.getType().equals(type)) {
765               logger.info("* " + next.getTitle() + ": " + next.getValue());
766             }
767           }
768         }
769         return true;
770       }
771       catch (Exception e) {
772         return false;
773       }
774     }
775
776     private static boolean read_wordxml_properties () {
777 //  -------------------------------------------------
778       File   template = new File("D:/Atelier/Eclipse/salome/org.splat/src/template.xml");
779       File   copy     = new File("D:/Atelier/Eclipse/salome/org.splat/src/example.xml");
780       try {
781         if (copy.exists()) copy.delete();
782         Do.copy(template, copy);
783         Writer credoc = Toolbox.getWriter(copy);
784         if (credoc != null) {
785
786 //        Setting of properties
787           credoc.updateProperty("customer", "CEA Cadarache");
788           credoc.updateProperty("title", "Spécifications générales");
789           credoc.save();
790
791 //        Displaying properties
792           Reader         example = Toolbox.getReader(copy);
793           Revision.Format convert = new Revision.Format("V%M.%m");
794           String         value;
795           logger.info("Properties of \"" + copy.getName() + "\" document:");
796
797           value = example.extractProperty("title");
798           logger.info("* Title    = " + value);
799           value = example.extractProperty("version");
800           Revision verdoc = convert.parse(value);
801           logger.info("* Version  = " + verdoc.toString());
802           value = example.extractProperty("customer");
803           logger.info("* Customer = " + value);
804           value = example.extractText();
805           logger.info("* Text     = " + value);
806         }
807         return false;
808       }
809       catch (Exception e) {
810         return false;
811       }
812     }
813
814     private static boolean read_worddoc_properties () {
815 //  -------------------------------------------------
816       File  file = new File("D:/Atelier/Eclipse/salome/org.splat/src/example.docx");
817       try {
818         if (!file.exists()) return false;
819
820         Reader example = Toolbox.getReader(file);
821         logger.info("Properties of \"" + file.getName() + "\" document:");
822         String value;
823
824         value = example.extractProperty("customer");
825         logger.info("* Customer = " + value);
826         value = example.extractProperty("title");
827         logger.info("* Title    = " + value);
828         value = example.extractText();
829         logger.info("* Text     = " + value);
830         return false;
831       }
832       catch (Exception e) {
833         return false;
834       }
835     }
836 }