use of org.vcell.util.document.User in project vcell by virtualcell.
the class MathVerifier method scanSimContexts.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
public void scanSimContexts(boolean bUpdateDatabase, KeyValue[] simContextKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
// calendar.set(2002,java.util.Calendar.MAY,7+1);
calendar.set(2002, java.util.Calendar.JULY, 1);
final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
// calendar.set(2001,java.util.Calendar.JUNE,13+1);
calendar.set(2002, java.util.Calendar.JANUARY, 1);
final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
for (int i = 0; i < simContextKeys.length; i++) {
if (lg.isTraceEnabled())
lg.trace("Testing SimContext with key '" + simContextKeys[i] + "'");
// 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;
String sql = "SELECT " + bmscTable.bioModelRef.getQualifiedColName() + " FROM " + bmscTable.getTableName() + " WHERE " + bmscTable.simContextRef.getQualifiedColName() + " = " + simContextKeys[i];
java.util.Vector keys = new java.util.Vector();
stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue key = new KeyValue(rset.getBigDecimal(bmscTable.bioModelRef.getUnqualifiedColName()));
keys.addElement(key);
}
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
KeyValue[] bmKeys = (org.vcell.util.document.KeyValue[]) org.vcell.util.BeanUtils.getArray(keys, org.vcell.util.document.KeyValue.class);
try {
// use the first biomodel...
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bmKeys[0]);
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(user, 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(simContextKeys[i])) {
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 {
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
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 newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(newMathDesc);
MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
StringBuffer buffer = new StringBuffer();
buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
} catch (Throwable e) {
// exception in whole BioModel
lg.error(e.getMessage(), e);
// update database, since we know the simcontext...
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = 'BIOMODEL EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'" + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextKeys[i];
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application with key '" + simContextKeys[i] + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application with key '" + simContextKeys[i] + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class MathVerifier method scanBioModels.
/**
* Insert the method's description here.
* Creation date: (2/2/01 3:40:29 PM)
*/
public void scanBioModels(boolean bUpdateDatabase, KeyValue[] bioModelKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
// calendar.set(2002,java.util.Calendar.MAY,7+1);
calendar.set(2002, java.util.Calendar.JULY, 1);
final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
// calendar.set(2001,java.util.Calendar.JUNE,13+1);
calendar.set(2002, java.util.Calendar.JANUARY, 1);
final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
for (int i = 0; i < bioModelKeys.length; i++) {
BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bioModelKeys[i]);
if (lg.isTraceEnabled())
lg.trace("Testing bioModel with key '" + bioModelKeys[i] + "'");
java.sql.Connection con = null;
java.sql.Statement stmt = null;
try {
//
// read in the BioModel from the database
//
BigString bioModelXML = dbServerImpl.getBioModelXML(user, 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();
//
// for each application, 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();
for (int k = 0; k < simContextsFromDB.length; k++) {
SimulationContext simContextFromDB = simContextsFromDB[k];
Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
SimulationContext simContextNewMath = simContextsNewMath[k];
Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
MathCompareResults mathCompareResults = null;
try {
MathDescription origMathDesc = simContextFromDB.getMathDescription();
//
// find out if any simulation belonging to this Application has data
//
boolean bApplicationHasData = false;
for (int l = 0; l < modelSimsFromDB.length; l++) {
SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
if (simulationStatus != null && simulationStatus.getHasData()) {
bApplicationHasData = true;
}
}
//
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 newMathDesc = mathMapping.getMathDescription();
String issueString = null;
org.vcell.util.Issue[] issues = mathMapping.getIssues();
if (issues != null && issues.length > 0) {
StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
for (int l = 0; l < issues.length; l++) {
buffer.append(" <<" + issues[l].toString() + ">>");
}
issueString = buffer.toString();
}
simContextNewMath.setMathDescription(newMathDesc);
MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
StringBuffer buffer = new StringBuffer();
buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
// KeyValue mathKey = origMathDesc.getKey();
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
//
for (int l = 0; l < appSimsFromDB.length; l++) {
try {
boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
if (lg.isTraceEnabled())
lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
//
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e) {
lg.error(e.getMessage(), e);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
} catch (Throwable e) {
// exception in SimContext
lg.error(e.getMessage(), e);
if (bUpdateDatabase) {
con = null;
stmt = null;
try {
con = conFactory.getConnection(new Object());
stmt = con.createStatement();
String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
if (status.length() > 255)
status = status.substring(0, 254) + "'";
String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
if (numRowsChanged != 1) {
System.out.println("failed to update status with exception");
}
con.commit();
if (lg.isTraceEnabled())
lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
} catch (SQLException e2) {
lg.error(e2.getMessage(), e2);
if (lg.isWarnEnabled())
lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
} finally {
if (stmt != null) {
stmt.close();
}
con.close();
}
}
}
}
}
} catch (Throwable e) {
// exception in whole BioModel
lg.error(e.getMessage(), e);
// can't update anything in database, since we don't know what simcontexts are involved
}
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class DbDriver method groupAddUser.
/**
* This method was created in VisualAge.
* @return cbit.sql.Versionable
* @param user cbit.vcell.server.User
* @param versionable cbit.sql.Versionable
*/
public static void groupAddUser(Connection con, KeyFactory keyFactory, User owner, VersionableType vType, KeyValue vKey, String userAddToGroupString, boolean isHiddenFromOwner, DatabaseSyntax dbSyntax) throws SQLException, ObjectNotFoundException, DataAccessException {
User userAddToGroup = getUserFromUserid(con, userAddToGroupString);
if (userAddToGroup == null) {
throw new IllegalArgumentException("User name " + userAddToGroupString + " not found");
}
//
if ((con == null) || (vType == null) || (owner == null) || (vKey == null) || (userAddToGroup == null)) {
throw new IllegalArgumentException("Improper parameters for groupAddUser userAddToGroupString=" + (userAddToGroupString == null ? "NULL" : userAddToGroupString));
}
//
Version currentVersion = permissionInit(con, vType, vKey, owner);
// If userAddToGroup is already in group it is an error
// ----- Also can't add members to GroupAccessAll(Public) (CHANGED!!!) -----
boolean bExists = false;
if (currentVersion.getGroupAccess() instanceof GroupAccessSome) {
bExists = (((GroupAccessSome) currentVersion.getGroupAccess()).isNormalMember(userAddToGroup) && !isHiddenFromOwner) || (((GroupAccessSome) currentVersion.getGroupAccess()).isHiddenMember(userAddToGroup) && isHiddenFromOwner);
}
// }
if (currentVersion.getOwner().compareEqual(userAddToGroup) || bExists) {
throw new DataAccessException(userAddToGroup + " Already a member of group");
}
if (lg.isTraceEnabled())
lg.trace("DbDriver.groupAddUser(user=" + owner + ", type =" + vType + ", key=" + vKey + ")");
VersionTable vTable = VersionTable.getVersionTable(vType);
//
//
BigDecimal newHash = null;
//
if (currentVersion.getGroupAccess() instanceof GroupAccessSome) {
// Calculate the hash of the currentVersion's group plus a new user
GroupAccessSome currentGroup = (GroupAccessSome) currentVersion.getGroupAccess();
newHash = currentGroup.calculateHashWithNewMember(userAddToGroup, isHiddenFromOwner);
} else if (currentVersion.getGroupAccess() instanceof GroupAccessNone || currentVersion.getGroupAccess() instanceof GroupAccessAll) {
// Calculate hash for a new group with only userAddToGroup in it
KeyValue[] kvArr = new KeyValue[1];
boolean[] hiddenArr = new boolean[1];
kvArr[0] = userAddToGroup.getID();
hiddenArr[0] = isHiddenFromOwner;
newHash = GroupAccess.calculateHash(kvArr, hiddenArr);
}
//
BigDecimal updatedGroupID = null;
//
// See if the newly calculated hash is present in the database GroupTable
// indicating a group we can reuse by reference
//
String sql = "SELECT groupid FROM " + GroupTable.table.getTableName() + " WHERE groupMemberHash = " + newHash.toString();
java.sql.Statement stmt = con.createStatement();
try {
java.sql.ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
// There may be more than one, just get the first, all have the same groupid and hash
// Group already exists,Re-Use the groupid, we don't have to make a new group
updatedGroupID = rset.getBigDecimal(GroupTable.table.groupid.toString());
}
} finally {
stmt.close();
}
//
if (updatedGroupID == null) {
// Create new Group id
updatedGroupID = getNewGroupID(con, keyFactory);
int groupMemberCount = 1;
// Get all the members of the currentVersion Group or skip if currentVersion group is GroupAccessNone
// Don't worry about GroupAccessAll, we couldn't have gotten this far
//
// Add new User
//
sql = "INSERT INTO " + GroupTable.table.getTableName() + " VALUES ( " + keyFactory.getNewKey(con).toString() + "," + updatedGroupID + "," + userAddToGroup.getID().toString() + "," + (isHiddenFromOwner ? "1" : "0") + "," + newHash + " )";
updateCleanSQL(con, sql);
if (currentVersion.getGroupAccess() instanceof GroupAccessSome) {
// Add all the old Normal Users
User[] normalUsers = ((GroupAccessSome) currentVersion.getGroupAccess()).getNormalGroupMembers();
for (int i = 0; normalUsers != null && i < normalUsers.length; i += 1) {
String userRef = normalUsers[i].getID().toString();
sql = "INSERT INTO " + GroupTable.table.getTableName() + " VALUES ( " + keyFactory.getNewKey(con).toString() + "," + updatedGroupID + "," + userRef + "," + (false ? "1" : "0") + "," + newHash + " )";
updateCleanSQL(con, sql);
}
// Add all the old Hidden Users
User[] hiddenUsers = ((GroupAccessSome) currentVersion.getGroupAccess()).getHiddenGroupMembers();
for (int i = 0; hiddenUsers != null && i < hiddenUsers.length; i += 1) {
String userRef = hiddenUsers[i].getID().toString();
sql = "INSERT INTO " + GroupTable.table.getTableName() + " VALUES ( " + keyFactory.getNewKey(con).toString() + "," + updatedGroupID + "," + userRef + "," + (true ? "1" : "0") + "," + newHash + " )";
updateCleanSQL(con, sql);
}
}
}
// Update the vTable to point to the new Group
String set = vTable.privacy.getQualifiedColName() + " = " + updatedGroupID;
String cond = vTable.id.getQualifiedColName() + " = " + vKey;
// " AND " + vTable.ownerRef.getQualifiedColName() + " = " + owner.getID();
sql = DatabasePolicySQL.enforceOwnershipUpdate(owner, vTable, set, cond);
// System.out.println(sql);
int numRowsProcessed = updateCleanSQL(con, sql);
if (numRowsProcessed != 1) {
//
// check if update failed
//
Vector<VersionInfo> versionInfoList = getVersionableInfos(con, owner, vType, false, vKey, true, dbSyntax);
if (versionInfoList.size() == 0) {
throw new DataAccessException("Add User " + userAddToGroup + " Permission to access failed, " + vType.getTypeName() + "(" + vKey + ") record not found");
} else {
throw new DataAccessException("Add User " + userAddToGroup + " Permission to access failed " + vType.getTypeName() + "(" + vKey + ")");
}
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class DbDriver method insertVersionableInit.
/**
* This method was created in VisualAge.
* @return cbit.sql.KeyValue
* @param versionable cbit.sql.Versionable
* @param pRef cbit.sql.KeyValue
* @param bCommit boolean
*/
protected Version insertVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, String name, String annot, boolean bVersion) throws SQLException, DataAccessException {
if (hash.getDatabaseKey(versionable) != null) {
throw new DataAccessException(versionable + " already inserted in this transaction");
}
VersionableType vType = VersionTable.versionableTypeFromVersionable(versionable);
if (vType.getIsTopLevel() && isNameUsed(con, vType, user, name)) {
throw new DataAccessException("'" + user.getName() + "' already has a " + vType.getTypeName() + " with name '" + name + "'");
}
User owner = user;
// AccessInfo accessInfo = new AccessInfo(AccessInfo.PRIVATE_CODE);
GroupAccess accessInfo = new GroupAccessNone();
KeyValue versionKey = keyFactory.getNewKey(con);
java.util.Date date = getNewDate(con);
// if(versionable.getVersion().getVersionKey() != null){
// throw new DataAccessException("GeomDbDriver:insertVersionable, VersionKey must be null to insert");
// }
String versionName = name;
// Check for Archive and Publish not needed in insert because versionflag is always forced to Current
VersionFlag versionFlag = null;
// if(bVersion){
// versionFlag = VersionFlag.Archived;
// }else{
versionFlag = VersionFlag.Current;
// }
KeyValue PRefKey = null;
java.math.BigDecimal branchID = getNewBranchID(con);
//
// Insert Software Version
//
insertSoftwareVersion(con, versionKey);
//
return new Version(versionKey, versionName, owner, accessInfo, PRefKey, branchID, date, versionFlag, annot);
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class DbDriver method getUserFromUserid.
/**
* This method was created in VisualAge.
* @return int
* @param user java.lang.String
* @param imageName java.lang.String
*/
private static User getUserFromUserid(Connection con, String userid) throws SQLException {
Statement stmt;
String sql;
ResultSet rset;
sql = "SELECT " + UserTable.table.id.getQualifiedColName() + " FROM " + UserTable.table.getTableName() + " WHERE " + UserTable.table.userid.getQualifiedColName() + " = '" + userid + "'";
stmt = con.createStatement();
User user = null;
try {
rset = stmt.executeQuery(sql);
if (rset.next()) {
KeyValue userKey = new KeyValue(rset.getBigDecimal(UserTable.table.id.toString()));
user = new User(userid, userKey);
}
} finally {
stmt.close();
}
return user;
}
Aggregations