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