further changes for Xper adaptation
[cdmlib-apps.git] / XperCdmIntegration / src / test / java / eu / etaxonomy / cdm / io / xper / TestAdapterCdmXper.java
1 package eu.etaxonomy.cdm.io.xper;
2
3 import java.io.File;
4 import java.util.List;
5 import java.util.UUID;
6
7 import org.apache.log4j.Logger;
8
9 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
10 import eu.etaxonomy.cdm.app.common.CdmDestinations;
11 import eu.etaxonomy.cdm.database.DbSchemaValidation;
12 import eu.etaxonomy.cdm.database.ICdmDataSource;
13 import eu.etaxonomy.cdm.model.description.WorkingSet;
14 import fr_jussieu_snv_lis.XPApp;
15 import fr_jussieu_snv_lis.Xper;
16 import fr_jussieu_snv_lis.utils.Utils;
17
18 public class TestAdapterCdmXper {
19 private static final Logger logger = Logger.getLogger(TestAdapterCdmXper.class);
20
21 CdmXperAdapter adapterCdmXper;
22
23 /**
24 *
25 */
26 private boolean startApplications() {
27 DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
28 ICdmDataSource datasource = CdmDestinations.cdm_test_local_xper();
29 System.out.println("cdm start");
30 CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation);
31 System.out.println("cdm started :::");
32
33 List<WorkingSet> workingSets = appCtr.getWorkingSetService().list(null, 1, 0, null, null);
34 if (workingSets.isEmpty()){
35 logger.warn("There is no working set");
36 return false;
37 }else{
38 UUID uuidWorkingSet = workingSets.iterator().next().getUuid();
39 adapterCdmXper = new CdmXperAdapter(appCtr, uuidWorkingSet);
40 }
41
42
43
44 Thread t = new Thread() {
45 public void run() {
46 new Xper(adapterCdmXper);
47 }
48 };
49 System.out.println("xper2 start");
50 t.start();
51 while(!XPApp.xperReady){
52 //TODO wait
53 }
54 System.out.println("xper2 started :::");
55 return true;
56 }
57
58 public void xperloadDataFromCdm(){
59 System.out.println("start load data");
60 // display a loading gif
61 Utils.displayLoadingGif(true);
62
63
64 // create a new empty base and load data from CDM
65 if(XPApp.cdmAdapter != null){
66 // create a new base
67 XPApp.getMainframe().newBase("baseTest");
68 // specify that the current base is not new (needed to be able to add images)
69 XPApp.isNewBase = false;
70 // delete the variable create by default and update the frame
71 XPApp.getCurrentBase().deleteVariable(XPApp.getCurrentBase().getVariableAt(0));
72 XPApp.getMainframe().displayNbVariable();
73 XPApp.getMainframe().getControler().displayJifVarTree();
74
75 if (XPApp.getCurrentBase() != null) {
76 // adaptaterCdmXper.createWorkingSet();
77 adapterCdmXper.load();
78
79 XPApp.getMainframe().displayNbVariable();
80 XPApp.getMainframe().getControler().displayJifVarTree();
81 }
82 }
83 // undisplay a loading gif
84 Utils.displayLoadingGif(false);
85 System.out.println("data loaded :::");
86 }
87
88 /**
89 *
90 */
91 private void createThumbnailDirectory() {
92 // create a _thumbnail directory to store thumbnails
93 new File(System.getProperty("user.dir") + Utils.sep + "images" + Utils.sep + "_thumbnails").mkdirs();
94 }
95
96 /**
97 *
98 */
99 private void generateThumbnails() {
100 System.out.println("start generate thumbnails");
101 // generate all thumbnails (a loading gif is automatically displayed
102 XPApp.generateThumbnailsFromURLImage(XPApp.getCurrentBase().getAllResources());
103 System.out.println("stop generate thumbnails");
104 }
105
106
107 private void startPartialCdm() {
108 System.out.println("start load data");
109 // display a loading gif
110 // Utils.displayLoadingGif(true);
111
112
113 // create a new empty base and load data from CDM
114 if(XPApp.cdmAdapter != null){
115 // create a new base
116 // XPApp.getMainframe().newBase("baseTest");
117 // specify that the current base is not new (needed to be able to add images), not really needed
118 XPApp.isNewBase = false;
119
120 XPApp.getMainframe().displayNbVariable();
121 XPApp.getMainframe().getControler().displayJifVarTree();
122
123 // if (XPApp.getCurrentBase() != null) {
124 //// adaptaterCdmXper.createWorkingSet();
125 // adapterCdmXper.load();
126 //
127 // XPApp.getMainframe().displayNbVariable();
128 // XPApp.getMainframe().getControler().displayJifVarTree();
129 // }
130 }
131 // undisplay a loading gif
132 Utils.displayLoadingGif(false);
133 System.out.println("data loaded :::");
134
135
136 }
137
138 /**
139 * @param args
140 */
141 public static void main(String[] args) {
142 System.out.println("start test");
143 //start CDM and Xper
144 TestAdapterCdmXper testAdapter = new TestAdapterCdmXper();
145 boolean success = testAdapter.startApplications();
146 if (success){
147 testAdapter.createThumbnailDirectory();
148 if (args.length >= 1 && "-p".equals(args[0]) ){
149 testAdapter.startPartialCdm();
150 }else{
151 // load the data from CDM
152 testAdapter.xperloadDataFromCdm();
153 // use the current directory as working directory for Xper2
154 XPApp.getCurrentBase().setPathName(System.getProperty("user.dir") + Utils.sep);
155
156 testAdapter.generateThumbnails();
157 }
158 }else{
159 System.exit(-1);
160 }
161
162
163 }
164
165
166
167
168 }