use of java.beans.PropertyVetoException 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 java.beans.PropertyVetoException in project vcell by virtualcell.
the class ModelDbDriver method getModel.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.Model
* @param rset java.sql.ResultSet
*/
private Model getModel(QueryHashtable dbc, ResultSet rset, Connection con, User user) throws SQLException, DataAccessException {
// User owner = new User(ownerName, ownerRef);
try {
Model model = modelTable.getModel(rset, con);
// model.setOwner(owner);
KeyValue modelKey = model.getVersion().getVersionKey();
//
// set structures for this model
//
StructureTopology structureTopology = model.getStructureTopology();
Structure[] structures = reactStepDB.getStructuresFromModel(dbc, con, modelKey);
if (structures != null && structures.length > 0) {
model.setStructures(structures);
}
HashMap<KeyValue, StructureKeys> structureKeysMap = reactStepDB.getStructureParentMapByModel(dbc, con, modelKey);
ReactStepDbDriver.populateStructureAndElectricalTopology(model, structureKeysMap);
//
// set species for this model
//
SpeciesContext[] speciesContexts = getSpeciesContextFromModel(dbc, con, user, modelKey, structureTopology);
if (speciesContexts != null) {
Vector<Species> speciesList = new Vector<Species>();
for (int i = 0; i < speciesContexts.length; i++) {
if (!speciesList.contains(speciesContexts[i].getSpecies())) {
speciesList.addElement(speciesContexts[i].getSpecies());
}
}
Species[] speciesArray = new Species[speciesList.size()];
speciesList.copyInto(speciesArray);
model.setSpecies(speciesArray);
}
//
if (speciesContexts != null) {
model.setSpeciesContexts(speciesContexts);
}
//
// Add global parameters to the model
//
GlobalModelParameterTable.table.setModelParameters(con, model);
//
// add reactionSteps for this model
//
ReactionStep[] reactSteps = reactStepDB.getReactionStepsFromModel(dbc, con, model, modelKey);
if (reactSteps != null) {
model.setReactionSteps(reactSteps);
for (int i = 0; i < reactSteps.length; i++) {
try {
//
// fix any improperly defined reactionSteps (which have parameters that should be catalysts)
// name space of kinetic parameters should be unique with respect to SpeciesContexts (so if they overlap, should be a catalyst).
//
Kinetics.KineticsParameter[] params = reactSteps[i].getKinetics().getKineticsParameters();
for (int j = 0; j < params.length; j++) {
SpeciesContext speciesContext = model.getSpeciesContext(params[j].getName());
if (speciesContext != null) {
reactSteps[i].addCatalyst(speciesContext);
if (lg.isWarnEnabled())
lg.warn("ModelDbDriver.getModel(), Parameter '" + params[j].getName() + "' in Reaction " + reactSteps[i].getName() + " in Model(" + model.getKey() + ") conflicts with SpeciesContext, added as a catalyst");
}
}
} catch (Throwable e) {
lg.error(e.getMessage(), e);
}
try {
reactSteps[i].rebindAllToModel(model);
} catch (cbit.vcell.parser.ExpressionBindingException e) {
throw new DataAccessException("bindingException: " + e.getMessage());
} catch (cbit.vcell.parser.ExpressionException e) {
throw new DataAccessException(e.getMessage());
} catch (PropertyVetoException e) {
throw new DataAccessException("PropertyVetoException: " + e.getMessage());
} catch (cbit.vcell.model.ModelException e) {
throw new DataAccessException(e.getMessage());
}
}
}
//
// add diagrams for this model
//
Diagram[] diagrams = getDiagramsFromModel(dbc, con, modelKey, structureTopology, dbSyntax);
model.setDiagrams(diagrams);
//
// add rbm
//
ModelTable.readRbmElement(con, model, dbSyntax);
if (!model.getRbmModelContainer().isEmpty()) {
for (SpeciesContext sc : model.getSpeciesContexts()) {
sc.parseSpeciesPatternString(model);
}
}
return model;
} catch (PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
use of java.beans.PropertyVetoException 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 java.beans.PropertyVetoException in project vcell by virtualcell.
the class ReactStepDbDriver method getReactionParticipant.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.ReactionParticipant
* @param rset java.sql.ResultSet
* @exception java.sql.SQLException The exception description.
*/
private ReactionParticipant getReactionParticipant(QueryHashtable dbc, Connection con, ResultSet rset, ReactionStep rs) throws SQLException, DataAccessException {
//
// try to get ReactionParticipant from object cache
//
KeyValue rpKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.id.toString()));
ReactionParticipant rp = (ReactionParticipant) dbc.get(rpKey);
if (rp != null) {
return rp;
}
//
// get foreign keys
//
KeyValue speciesContextKey = new KeyValue(rset.getBigDecimal(ReactPartTable.table.scRef.toString()));
//
// get ReactionParticipant
//
rp = reactPartTable.getReactionParticipant(rpKey, rset);
//
// get referenced Objects (Species and Structure)
//
SpeciesContext speciesContext = modelDB.getSpeciesContext(dbc, con, speciesContextKey);
try {
rp.setSpeciesContext(speciesContext);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new DataAccessException("PropertyVetoException: " + e.getMessage());
}
rp.setReactionStep(rs);
// ========== Since there is no flux carrier in fluxReaction, this is not required?? ===========
// if (rp instanceof Flux && rs instanceof FluxReaction) {
// try {
// ((FluxReaction) rs).setFluxCarrier(speciesContext.getSpecies(), null);
// }catch (ModelException e){
// e.printStackTrace(System.out);
// throw new DataAccessException("ModelException: "+e.getMessage());
// }catch (PropertyVetoException e){
// e.printStackTrace(System.out);
// throw new DataAccessException("PropertyVetoException: "+e.getMessage());
// }
// }
//
// stick ReactionParticipant in object cache
//
dbc.put(rpKey, rp);
return rp;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class GeomDbDriver method insertGeometry.
/**
* This method was created in VisualAge.
*/
private void insertGeometry(InsertHashtable hash, QueryHashtable dbc, Connection con, User user, Geometry geom, KeyValue updatedImageKey, Version newVersion, boolean bVersionChildren) throws ImageException, SQLException, DataAccessException, RecordChangedException {
// log.print("GeomDbDriver.insertGeometry(" + geom + ")");
// everybody needs to be in synch 'cause children may be manipulated...
geom.refreshDependencies();
KeyValue extentKey = null;
GeometrySpec geometrySpec = geom.getGeometrySpec();
if (geometrySpec.getImage() != null) {
// //try {
// imageVersionKey = hash.getDatabaseKey(geometrySpec.getImage());
// if (imageVersionKey==null){
// if(geometrySpec.getImage().getVersion()!=null && geometrySpec.getImage().getVersion().getVersionKey() != null){
// imageVersionKey = updateVersionable(hash, con, user, geometrySpec.getImage(), bVersionChildren);
// }else{
// String imageName = geometrySpec.getImage().getName(); // + "_image";
// while (isNameUsed(con,VersionableType.VCImage,user,imageName)){
// imageName = cbit.util.TokenMangler.getNextRandomToken(imageName);
// }
// imageVersionKey = insertVersionable(hash, con, user, geometrySpec.getImage(),imageName ,bVersionChildren);
// }
// try{
// geometrySpec.setImage(getVCImage(con,user,imageVersionKey));
// }catch(PropertyVetoException e){
// e.printStackTrace();
// throw new DataAccessException(e.getMessage());
// }
// }
// //} catch (RecordChangedException rce) {
// // throw rce;
// //}
extentKey = getExtentRefKeyFromImage(con, updatedImageKey);
}
//
if (extentKey == null) {
extentKey = keyFactory.getNewKey(con);
insertExtentSQL(con, extentKey, geometrySpec.getExtent().getX(), geometrySpec.getExtent().getY(), geometrySpec.getExtent().getZ());
}
//
insertGeometrySQL(con, geom, updatedImageKey, extentKey, newVersion, user);
hash.put(geom, newVersion.getVersionKey());
if (updatedImageKey != null && !updatedImageKey.equals(geom.getGeometrySpec().getImage().getKey())) {
VCImage resavedImage = getVCImage(dbc, con, user, updatedImageKey, true);
try {
geom.getGeometrySpec().setImage(resavedImage);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage());
}
}
insertSubVolumesSQL(hash, con, geom, newVersion.getVersionKey());
insertSurfaceClassesSQL(hash, con, geom, newVersion.getVersionKey());
if (geom.getDimension() > 0) {
insertGeometrySurfaceDescriptionSQL(hash, con, geom, newVersion.getVersionKey());
insertFilamentsSQL(con, geom, newVersion.getVersionKey());
}
}
Aggregations