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