use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class MathVerifier method testMathGeneration.
public MathGenerationResults testMathGeneration(KeyValue simContextKey) throws SQLException, ObjectNotFoundException, DataAccessException, XmlParseException, MappingException, MathException, MatrixException, ExpressionException, ModelException, PropertyVetoException {
User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new org.vcell.util.document.KeyValue(PropertyLoader.ADMINISTRATOR_ID));
if (lg.isTraceEnabled())
lg.trace("Testing SimContext with key '" + simContextKey + "'");
// get biomodel refs
java.sql.Connection con = null;
java.sql.Statement stmt = null;
con = conFactory.getConnection(new Object());
cbit.vcell.modeldb.BioModelSimContextLinkTable bmscTable = cbit.vcell.modeldb.BioModelSimContextLinkTable.table;
cbit.vcell.modeldb.BioModelTable bmTable = cbit.vcell.modeldb.BioModelTable.table;
cbit.vcell.modeldb.UserTable userTable = cbit.vcell.modeldb.UserTable.table;
String sql = "SELECT " + bmscTable.bioModelRef.getQualifiedColName() + "," + bmTable.ownerRef.getQualifiedColName() + "," + userTable.userid.getQualifiedColName() + " FROM " + bmscTable.getTableName() + "," + bmTable.getTableName() + "," + userTable.getTableName() + " WHERE " + bmscTable.simContextRef.getQualifiedColName() + " = " + simContextKey + " AND " + bmTable.id.getQualifiedColName() + " = " + bmscTable.bioModelRef.getQualifiedColName() + " AND " + bmTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
ArrayList<KeyValue> bioModelKeys = new ArrayList<KeyValue>();
stmt = con.createStatement();
User owner = null;
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue key = new KeyValue(rset.getBigDecimal(bmscTable.bioModelRef.getUnqualifiedColName()));
bioModelKeys.add(key);
KeyValue ownerRef = new KeyValue(rset.getBigDecimal(bmTable.ownerRef.getUnqualifiedColName()));
String userid = rset.getString(userTable.userid.getUnqualifiedColName());
owner = new User(userid, ownerRef);
}
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
// use the first biomodel...
if (bioModelKeys.size() == 0) {
throw new RuntimeException("zombie simContext ... no biomodels");
}
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(owner, bioModelKeys.get(0));
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(owner, bioModelInfo.getVersion().getVersionKey());
BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
bioModelFromDB.refreshDependencies();
bioModelNewMath.refreshDependencies();
//
// get all Simulations for this model
//
Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
//
// ---> only for the SimContext we started with...
// recompute mathDescription, and verify it is equivalent
// then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
//
SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
SimulationContext simContextFromDB = null;
SimulationContext simContextNewMath = null;
for (int k = 0; k < simContextsFromDB.length; k++) {
// find it...
if (simContextsFromDB[k].getKey().equals(simContextKey)) {
simContextFromDB = simContextsFromDB[k];
simContextNewMath = simContextsNewMath[k];
break;
}
}
if (simContextFromDB == null) {
throw new RuntimeException("BioModel referred to by this SimContext does not contain this SimContext");
} else {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
try {
if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
//
// updated mathDescription loaded into copy of bioModel, then test for equivalence.
//
cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
MathDescription mathDesc_latest = mathMapping.getMathDescription();
MathMapping_4_8 mathMapping_4_8 = new MathMapping_4_8(simContextNewMath);
MathDescription mathDesc_4_8 = mathMapping_4_8.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):\n");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>\n");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(mathDesc_latest);
MathCompareResults mathCompareResults_latest = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_latest);
MathCompareResults mathCompareResults_4_8 = null;
try {
mathCompareResults_4_8 = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, mathDesc_4_8);
} catch (Exception e) {
e.printStackTrace(System.out);
mathCompareResults_4_8 = new MathCompareResults(Decision.MathDifferent_FAILURE_UNKNOWN, e.getMessage());
}
return new MathGenerationResults(bioModelFromDB, simContextFromDB, origMathDesc, mathDesc_latest, mathCompareResults_latest, mathDesc_4_8, mathCompareResults_4_8);
}
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class ModelTable method readRbmElement.
public static void readRbmElement(Connection con, Model model, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
Statement stmt = null;
try {
stmt = con.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM " + ModelTable.table.getTableName() + " WHERE " + ModelTable.table.id.getUnqualifiedColName() + " = " + model.getVersion().getVersionKey().toString());
if (rset.next()) {
String rbmXMLStr = DbDriver.varchar2_CLOB_get(rset, ModelTable.table.rbmSmall, ModelTable.table.rbmLarge, dbSyntax);
rset.close();
if (rbmXMLStr != null) {
Element rbmElement = XmlUtil.stringToXML(rbmXMLStr, null).getRootElement();
XmlReader reader = new XmlReader(false);
try {
reader.getRbmModelContainer(rbmElement, model);
} catch (ModelException | PropertyVetoException | XmlParseException e) {
throw new DataAccessException(e.getMessage(), e);
}
}
}
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class ServerDocumentManager method getBioModelXML.
/**
* Insert the method's description here.
* Creation date: (3/29/2004 4:04:16 PM)
* @return java.lang.String
* @param vType cbit.sql.VersionableType
* @param vKey cbit.sql.KeyValue
*/
public String getBioModelXML(QueryHashtable dbc, User user, KeyValue bioModelKey, boolean bRegenerateXML) throws DataAccessException {
String bioModelXML = null;
try {
bioModelXML = dbServer.getDBTopLevel().getBioModelXML(user, bioModelKey, true);
if (bioModelXML != null) {
if (bRegenerateXML) {
try {
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML));
return cbit.vcell.xml.XmlHelper.bioModelToXML(bioModel);
} catch (XmlParseException e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage(), e);
}
} else {
return bioModelXML;
}
}
} catch (java.sql.SQLException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
} catch (ObjectNotFoundException e) {
//
// not stored as XML currently, retrieve traditional way.
//
}
try {
bioModelXML = getBioModelUnresolved(dbc, user, bioModelKey);
dbServer.insertVersionableXML(user, VersionableType.BioModelMetaData, bioModelKey, bioModelXML);
return bioModelXML;
} catch (java.sql.SQLException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
} catch (cbit.vcell.xml.XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class SimContextTable method readAppComponents.
/**
* readAppComponents : reads the additional simContext components like bioevents/application related flags (for stochastic, at the moment), if present, and sets them on simContext.
* @param con
* @param simContext
* @return
* @throws SQLException
* @throws DataAccessException
* @throws PropertyVetoException
*/
public void readAppComponents(Connection con, SimulationContext simContext, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
try {
Element appComponentsElement = getAppComponentsElement(con, simContext.getVersion().getVersionKey(), dbSyntax);
if (appComponentsElement != null) {
Element appRelatedFlags = appComponentsElement.getChild(XMLTags.ApplicationSpecificFlagsTag);
if (appRelatedFlags != null) {
// for now, only reading the 'randomizeInitCondition' attribute, since 'isStoch' and 'isUsingconcentration' are read in by other means; so not messing with those fields of simContext.
boolean bRandomizeInitCondition = false;
if ((appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
bRandomizeInitCondition = true;
}
simContext.setRandomizeInitConditions(bRandomizeInitCondition);
}
if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag).equals("true"))) {
simContext.setInsufficientIterations(true);
} else {
simContext.setInsufficientIterations(false);
}
if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag).equals("true"))) {
simContext.setInsufficientMaxMolecules(true);
} else {
simContext.setInsufficientMaxMolecules(false);
}
XmlReader xmlReader = new XmlReader(false);
NetworkConstraints nc = null;
Element ncElement = appComponentsElement.getChild(XMLTags.RbmNetworkConstraintsTag);
if (ncElement != null) {
// one network constraint element
nc = xmlReader.getAppNetworkConstraints(ncElement, simContext.getModel());
}
simContext.setNetworkConstraints(nc);
// get spatial objects
Element spatialObjectsElement = appComponentsElement.getChild(XMLTags.SpatialObjectsTag);
if (spatialObjectsElement != null) {
SpatialObject[] spatialObjects = xmlReader.getSpatialObjects(simContext, spatialObjectsElement);
simContext.setSpatialObjects(spatialObjects);
}
// get application parameters
Element appParamsElement = appComponentsElement.getChild(XMLTags.ApplicationParametersTag);
if (appParamsElement != null) {
SimulationContextParameter[] appParams = xmlReader.getSimulationContextParams(appParamsElement, simContext);
simContext.setSimulationContextParameters(appParams);
}
// get bioEvents
Element bioEventsElement = appComponentsElement.getChild(XMLTags.BioEventsTag);
if (bioEventsElement != null) {
BioEvent[] bioEvents = xmlReader.getBioEvents(simContext, bioEventsElement);
simContext.setBioEvents(bioEvents);
}
// get spatial processes
Element spatialProcessesElement = appComponentsElement.getChild(XMLTags.SpatialProcessesTag);
if (spatialProcessesElement != null) {
SpatialProcess[] spatialProcesses = xmlReader.getSpatialProcesses(simContext, spatialProcessesElement);
simContext.setSpatialProcesses(spatialProcesses);
}
// get microscope measurements
Element element = appComponentsElement.getChild(XMLTags.MicroscopeMeasurement);
if (element != null) {
xmlReader.getMicroscopeMeasurement(element, simContext);
}
// get rate rules
Element rateRulesElement = appComponentsElement.getChild(XMLTags.RateRulesTag);
if (rateRulesElement != null) {
RateRule[] rateRules = xmlReader.getRateRules(simContext, rateRulesElement);
simContext.setRateRules(rateRules);
}
// get reaction rule specs
Element reactionRuleSpecsElement = appComponentsElement.getChild(XMLTags.ReactionRuleSpecsTag);
if (reactionRuleSpecsElement != null) {
ReactionRuleSpec[] reactionRuleSpecs = xmlReader.getReactionRuleSpecs(simContext, reactionRuleSpecsElement);
simContext.getReactionContext().setReactionRuleSpecs(reactionRuleSpecs);
}
}
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException("Error retrieving bioevents : " + e.getMessage());
}
}
use of cbit.vcell.xml.XmlParseException in project vcell by virtualcell.
the class VCDatabaseScanner method scanMathModels.
public void scanMathModels(VCDatabaseVisitor databaseVisitor, PrintStream logFilePrintStream, User[] users, KeyValue singleMathmodelKey, HashSet<KeyValue> includeHash, HashSet<KeyValue> excludeHash, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
BadMathVisitor badMathVisitor = null;
if (databaseVisitor instanceof BadMathVisitor) {
badMathVisitor = (BadMathVisitor) databaseVisitor;
}
final boolean isBadMathVisitor = badMathVisitor != null;
if (users == null) {
users = getAllUsers();
}
try {
// start visiting models and writing log
logFilePrintStream.println("Start scanning mathmodels ......");
logFilePrintStream.println("\n");
for (int i = 0; i < users.length; i++) {
User user = users[i];
MathModelInfo[] mathInfos = dbServerImpl.getMathModelInfos(user, false);
for (int j = 0; j < mathInfos.length; j++) {
if (singleMathmodelKey != null && !mathInfos[j].getVersion().getVersionKey().compareEqual(singleMathmodelKey)) {
System.out.println("skipping geometry, not the single one that we wanted");
continue;
}
if (excludeHash != null && excludeHash.contains(mathInfos[j].getVersion().getVersionKey())) {
System.out.println("skipping geometry with key '" + mathInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (includeHash != null && !includeHash.contains(mathInfos[j].getVersion().getVersionKey())) {
System.out.println("not including geometry with key '" + mathInfos[j].getVersion().getVersionKey() + "'");
continue;
}
if (!databaseVisitor.filterMathModel(mathInfos[j])) {
continue;
}
KeyValue vk = null;
try {
vk = mathInfos[j].getVersion().getVersionKey();
BigString mathModelXML = dbServerImpl.getMathModelXML(user, mathInfos[j].getVersion().getVersionKey());
MathModel mathModel = cbit.vcell.xml.XmlHelper.XMLToMathModel(new XMLSource(mathModelXML.toString()));
mathModel.refreshDependencies();
databaseVisitor.visitMathModel(mathModel, logFilePrintStream);
} catch (Exception e2) {
if (isBadMathVisitor) {
badMathVisitor.unableToLoad(vk, e2);
}
lg.error(e2.getMessage(), e2);
if (bAbortOnDataAccessException) {
throw e2;
}
}
}
}
logFilePrintStream.close();
} catch (Exception e) {
System.err.println("error writing to log file.");
}
}
Aggregations