35
35
import cbit .vcell .geometry .GeometryThumbnailImageFactoryAWT ;
36
36
import cbit .vcell .mathmodel .MathModel ;
37
37
import cbit .vcell .messaging .db .SimulationJobTable ;
38
+ import cbit .vcell .modeldb .BioModelSimContextLinkTable ;
38
39
import cbit .vcell .modeldb .BioModelSimulationLinkTable ;
39
40
import cbit .vcell .modeldb .BioModelTable ;
40
41
import cbit .vcell .modeldb .DBTopLevel ;
44
45
import cbit .vcell .modeldb .MathModelTable ;
45
46
import cbit .vcell .modeldb .PublicationModelLinkTable ;
46
47
import cbit .vcell .modeldb .ServerDocumentManager ;
48
+ import cbit .vcell .modeldb .TFTestCaseTable ;
49
+ import cbit .vcell .modeldb .TFTestSuiteTable ;
47
50
import cbit .vcell .modeldb .UserTable ;
48
51
import cbit .vcell .modeldb .VersionTable ;
49
52
import cbit .vcell .simdata .Cachetable ;
64
67
public class IonItems {
65
68
//See vcell-node1:/opt/build/frm/cbit_vcell_tools_IonItems.info
66
69
private static final String PUBLISHEDMODELVCML = "publishedmodelvcml" ;
70
+ private static final String TESTSUITEMODELVCML = "testsuitemodelvcml" ;
67
71
private static final String PUBLICMODELWITHSIMS = "publicmodelwithsims" ;
68
72
private static final String PUBLISHEDMODELVCMLDIFF = "publishedmodelvcmldiff" ;
69
73
@@ -119,6 +123,9 @@ public static void main(String[] args) {
119
123
}else if (command .toLowerCase ().equals (PUBLISHEDMODELVCMLDIFF )) {
120
124
File dirWithSavedVCML = new File (args [1 ]);
121
125
readVCMLWithSimsRemoved (con , dirWithSavedVCML );
126
+ }else if (command .toLowerCase ().equals (TESTSUITEMODELVCML )) {
127
+ File dirToSaveVCML = new File (args [1 ]);
128
+ saveVCMLTestSuite (dirToSaveVCML ,0 ,0 );
122
129
}
123
130
124
131
} catch (Exception e ) {
@@ -140,10 +147,120 @@ public static void main(String[] args) {
140
147
141
148
}
142
149
150
+ private static void saveVCMLTestSuite (File dirToSaveVCML ,long startSimKey ,long endSimKey ) throws Exception {
151
+ // select distinct vc_biomodelsimcontext.biomodelref modelkey
152
+ // from vc_tftestsuite,vc_tftestcase,vc_biomodelsimcontext
153
+ // where vc_tftestsuite.tsversion='88_alpha_from_87_alpha'
154
+ // and vc_tftestcase.testsuiteref=vc_tftestsuite.id
155
+ // and vc_tftestcase.bmappref is not null
156
+ // and vc_tftestcase.bmappref=vc_biomodelsimcontext.id
157
+ // union
158
+ // select distinct vc_mathmodel.id modelkey
159
+ // from vc_tftestsuite,vc_tftestcase,vc_mathmodel
160
+ // where vc_tftestsuite.tsversion='88_alpha_from_87_alpha'
161
+ // and vc_tftestcase.testsuiteref=vc_tftestsuite.id
162
+ // and vc_tftestcase.mathmodelref is not null
163
+ // and vc_tftestcase.mathmodelref=vc_mathmodel.id;
164
+ String modelKeyStr = "modelkey" ;
165
+ String userKeyStr = "userkey" ;
166
+ String useridStr = "userid" ;
167
+ String modelUserKeyStr = modelKeyStr +"," +UserTable .table .id .getQualifiedColName ()+" " +userKeyStr +"," +UserTable .table .userid .getQualifiedColName ()+" " +useridStr ;
168
+ String testSuitTestCaseLink =
169
+ TFTestSuiteTable .table .tsVersion .getQualifiedColName ()+"=" +"'88_alpha_from_87_alpha'" +
170
+ " AND " +TFTestCaseTable .table .testSuiteRef .getQualifiedColName ()+"=" +TFTestSuiteTable .table .id .getQualifiedColName ();
171
+ String testSuitAndUserStr = TFTestSuiteTable .table .getTableName ()+"," +TFTestCaseTable .table .getTableName ()+"," +UserTable .table .getTableName ();
172
+ String bioModelTypeStr = "biomodel" ;
173
+ String mathModelTypeStr = "mathmodel" ;
174
+ String modelTypeKeyStr = "modeltype" ;
175
+ String sql =
176
+ "SELECT distinct " +"'" +bioModelTypeStr +"' " +modelTypeKeyStr +"," +BioModelTable .table .id .getQualifiedColName ()+" " +modelUserKeyStr +
177
+ " FROM " +testSuitAndUserStr +"," +BioModelSimContextLinkTable .table .getTableName ()+"," +BioModelTable .table .getTableName ()+
178
+ " WHERE " +testSuitTestCaseLink +" AND " +TFTestCaseTable .table .bmAppRef .getQualifiedColName ()+" IS NOT NULL" +
179
+ " AND " +TFTestCaseTable .table .bmAppRef .getQualifiedColName ()+"=" +BioModelSimContextLinkTable .table .id .getQualifiedColName ()+
180
+ " AND " +BioModelSimContextLinkTable .table .bioModelRef .getQualifiedColName ()+"=" +BioModelTable .table .id .getQualifiedColName ()+
181
+ " AND " +BioModelTable .table .ownerRef .getQualifiedColName ()+"=" +UserTable .table .id .getQualifiedColName ()+
182
+ " UNION " +
183
+ "SELECT distinct " +"'" +mathModelTypeStr +"' " +modelTypeKeyStr +"," +MathModelTable .table .id .getQualifiedColName ()+" " +modelUserKeyStr +
184
+ " FROM " +testSuitAndUserStr +"," +MathModelTable .table .getTableName ()+
185
+ " WHERE " +testSuitTestCaseLink +" AND " +TFTestCaseTable .table .mathModelRef .getQualifiedColName ()+" IS NOT NULL" +
186
+ " AND " +TFTestCaseTable .table .mathModelRef .getQualifiedColName ()+"=" +MathModelTable .table .id .getQualifiedColName ()+
187
+ " AND " +MathModelTable .table .ownerRef .getQualifiedColName ()+"=" +UserTable .table .id .getQualifiedColName ();
188
+
189
+ Statement stmt = null ;
190
+ try {
191
+ stmt = con .createStatement ();
192
+ //ArrayList<VCDocument> successDocs = new ArrayList<VCDocument>();
193
+ DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl (connFac ,null );
194
+ ArrayList <Object []> modeKeyAndUser = new ArrayList <Object []>();
195
+
196
+ ResultSet rset = stmt .executeQuery (sql );
197
+ while (rset .next ()) {
198
+ BigDecimal modelKeyBigDecimal = rset .getBigDecimal (modelKeyStr );
199
+ KeyValue modelKey = new KeyValue (modelKeyBigDecimal );
200
+ String modelType = rset .getString (modelTypeKeyStr );
201
+ if (startSimKey == 0 || (modelKeyBigDecimal .longValue () >= startSimKey && modelKeyBigDecimal .longValue () <= endSimKey )) {
202
+ User user = new User (rset .getString (useridStr ), new KeyValue (rset .getBigDecimal (userKeyStr )));
203
+ modeKeyAndUser .add (new Object [] {(modelType .equals (bioModelTypeStr )?VCDocumentType .BIOMODEL_DOC :VCDocumentType .MATHMODEL_DOC ),modelKey ,user });
204
+ }
205
+ }
206
+ rset .close ();
207
+ stmt .close ();
208
+
209
+ VCDocument vcDoc = null ;
210
+ for (int ii =0 ;ii <modeKeyAndUser .size ();ii ++) {
211
+ try {
212
+ VCDocumentType vcDocType = (VCDocumentType )modeKeyAndUser .get (ii )[0 ];
213
+ KeyValue modelKey = (KeyValue )modeKeyAndUser .get (ii )[1 ];
214
+ User user = (User )modeKeyAndUser .get (ii )[2 ];
215
+ //-----NOTE: (privacy, versionflag) may not match between xml and database (because privacy and versionflag can be set without saving model)
216
+ //some models regenerated from xml will not have same privacy and versionflag matched in query from database (the database values are correct, ignore the xml values)
217
+ BigString modelXML = (vcDocType == VCDocumentType .BIOMODEL_DOC ?databaseServerImpl .getBioModelXML (user , modelKey ):databaseServerImpl .getMathModelXML (user , modelKey ));
218
+ vcDoc = null ;
219
+ if (vcDocType == VCDocumentType .BIOMODEL_DOC ) {
220
+ BioModel bm = cbit .vcell .xml .XmlHelper .XMLToBioModel (new XMLSource (modelXML .toString ()));
221
+ bm .refreshDependencies ();
222
+ vcDoc = bm ;
223
+ }else {
224
+ MathModel mm = cbit .vcell .xml .XmlHelper .XMLToMathModel (new XMLSource (modelXML .toString ()));
225
+ mm .refreshDependencies ();
226
+ vcDoc = mm ;
227
+ }
228
+ //if(true) {
229
+ // System.out.println(modelKey+" "+user+" "+vcDoc);
230
+ // continue;
231
+ //}
232
+
233
+ String docXml = null ;
234
+ if (vcDoc .getDocumentType () == VCDocument .VCDocumentType .BIOMODEL_DOC ) {
235
+ docXml = XmlHelper .bioModelToXML (((BioModel )vcDoc ));
236
+ }else {
237
+ docXml = XmlHelper .mathModelToXML (((MathModel )vcDoc ));
238
+ }
239
+ PrintWriter pw = new PrintWriter (new File (dirToSaveVCML ,vcDoc .getVersion ().getVersionKey ().toString ()+".xml" ));
240
+ pw .write (docXml );
241
+ pw .close ();
242
+ // }
243
+ } catch (Exception e ) {
244
+ System .out .println ("----------GENERALERROR " +vcDoc .getVersion ().getVersionKey ());
245
+ e .printStackTrace ();
246
+ if (vcDoc != null ) {
247
+ PrintWriter pw = new PrintWriter (new File (dirToSaveVCML ,vcDoc .getVersion ().getVersionKey ().toString ()+"_exception.xml" ));
248
+ pw .write ("" );
249
+ pw .close ();
250
+ }
251
+ }
252
+ }
253
+ } finally {
254
+ if (stmt != null ){try {stmt .close ();}catch (Exception e ){e .printStackTrace ();}}
255
+ }
256
+
257
+ }
258
+
143
259
public static void usage () {
144
260
System .out .println ("cbit.vcell.tools.IonItems jdbc:oracle:thin:@VCELL_DB_HOST:1521:VCEL_DB_NAME vcellUsersRootDir " +PUBLICMODELWITHSIMS +" {true,false print more info}}" );
145
261
System .out .println ("cbit.vcell.tools.IonItems jdbc:oracle:thin:@VCELL_DB_HOST:1521:VCEL_DB_NAME vcellUsersRootDir " +PUBLISHEDMODELVCML +" dirToSaveVCML, startSimKey endSimKey" );
146
262
System .out .println ("cbit.vcell.tools.IonItems jdbc:oracle:thin:@VCELL_DB_HOST:1521:VCEL_DB_NAME dirWithSavedVCML " +PUBLISHEDMODELVCMLDIFF );
263
+ System .out .println ("cbit.vcell.tools.IonItems jdbc:oracle:thin:@VCELL_DB_HOST:1521:VCEL_DB_NAME dirToSaveVCML " +TESTSUITEMODELVCML );
147
264
System .exit (1 );
148
265
}
149
266
0 commit comments