Search in sources :

Example 11 with MappingException

use of cbit.vcell.mapping.MappingException 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
        }
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) MathDescription(cbit.vcell.math.MathDescription) SQLException(java.sql.SQLException) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) MathCompareResults(cbit.vcell.math.MathCompareResults) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource)

Example 12 with MappingException

use of cbit.vcell.mapping.MappingException 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();
                }
            }
        }
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) MathDescription(cbit.vcell.math.MathDescription) SQLException(java.sql.SQLException) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) Vector(java.util.Vector) MathCompareResults(cbit.vcell.math.MathCompareResults) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource)

Example 13 with MappingException

use of cbit.vcell.mapping.MappingException in project vcell by virtualcell.

the class MathVerifier method scan.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 */
public void scan(User[] users, boolean bUpdateDatabase, KeyValue[] bioAndMathModelKeys) 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();
    KeyValue[] sortedBioAndMathModelKeys = null;
    if (bioAndMathModelKeys != null) {
        sortedBioAndMathModelKeys = bioAndMathModelKeys.clone();
        Arrays.sort(sortedBioAndMathModelKeys, keyValueCpmparator);
    }
    for (int i = 0; i < users.length; i++) {
        User user = users[i];
        BioModelInfo[] bioModelInfos0 = dbServerImpl.getBioModelInfos(user, false);
        MathModelInfo[] mathModelInfos0 = dbServerImpl.getMathModelInfos(user, false);
        if (lg.isTraceEnabled())
            lg.trace("Testing user '" + user + "'");
        Vector<VCDocumentInfo> userBioAndMathModelInfoV = new Vector<VCDocumentInfo>();
        userBioAndMathModelInfoV.addAll(Arrays.asList(bioModelInfos0));
        userBioAndMathModelInfoV.addAll(Arrays.asList(mathModelInfos0));
        // 
        for (int j = 0; j < userBioAndMathModelInfoV.size(); j++) {
            // 
            // if certain Bio or Math models are requested, then filter all else out
            // 
            VCDocumentInfo documentInfo = userBioAndMathModelInfoV.elementAt(j);
            KeyValue versionKey = documentInfo.getVersion().getVersionKey();
            if (sortedBioAndMathModelKeys != null) {
                int srch = Arrays.binarySearch(sortedBioAndMathModelKeys, versionKey, keyValueCpmparator);
                if (srch < 0) {
                    continue;
                }
            }
            if (!(documentInfo instanceof BioModelInfo)) {
                continue;
            }
            // 
            if (skipHash.contains(versionKey)) {
                System.out.println("skipping " + (documentInfo instanceof BioModelInfo ? "BioModel" : "MathModel") + " with key '" + versionKey + "'");
                continue;
            }
            try {
                // 
                // read in the BioModel and MathModel from the database
                // 
                VCDocument vcDocumentFromDBCache = null;
                BigString vcDocumentXMLFromDBCache = null;
                try {
                    long startTime = System.currentTimeMillis();
                    if (documentInfo instanceof BioModelInfo) {
                        vcDocumentXMLFromDBCache = new BigString(dbServerImpl.getServerDocumentManager().getBioModelXML(new QueryHashtable(), user, versionKey, false));
                        vcDocumentFromDBCache = XmlHelper.XMLToBioModel(new XMLSource(vcDocumentXMLFromDBCache.toString()));
                    } else {
                        vcDocumentXMLFromDBCache = new BigString(dbServerImpl.getServerDocumentManager().getMathModelXML(new QueryHashtable(), user, versionKey, false));
                        vcDocumentFromDBCache = XmlHelper.XMLToMathModel(new XMLSource(vcDocumentXMLFromDBCache.toString()));
                    }
                    if (bUpdateDatabase && testFlag.equals(MathVerifier.MV_LOAD_XML)) {
                        updateLoadModelsStatTable_LoadTest(System.currentTimeMillis() - startTime, versionKey, null);
                    }
                } catch (Exception e) {
                    lg.error(e.getMessage(), e);
                    if (bUpdateDatabase && testFlag.equals(MathVerifier.MV_LOAD_XML)) {
                        updateLoadModelsStatTable_LoadTest(0, versionKey, e);
                    }
                }
                if (testFlag.equals(MathVerifier.MV_LOAD_XML)) {
                    // 
                    if (vcDocumentXMLFromDBCache != null) {
                        testDocumentLoad(bUpdateDatabase, user, documentInfo, vcDocumentFromDBCache);
                    }
                } else if (testFlag.equals(MathVerifier.MV_DEFAULT)) {
                    // 
                    if (vcDocumentFromDBCache instanceof BioModel) {
                        BioModel bioModel = (BioModel) vcDocumentFromDBCache;
                        checkMathForBioModel(vcDocumentXMLFromDBCache, bioModel, user, bUpdateDatabase);
                    }
                }
            } 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
            }
        }
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCDocument(org.vcell.util.document.VCDocument) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) BigString(org.vcell.util.BigString) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) BioModel(cbit.vcell.biomodel.BioModel) Vector(java.util.Vector) XMLSource(cbit.vcell.xml.XMLSource)

Example 14 with MappingException

use of cbit.vcell.mapping.MappingException in project vcell by virtualcell.

the class SimulationContextDbDriver method assignAnalysisTasksSQL.

/**
 * This method was created in VisualAge.
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
private void assignAnalysisTasksSQL(Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    AnalysisTaskXMLTable analysisTaskTable = AnalysisTaskXMLTable.table;
    sql = " SELECT " + analysisTaskTable.analysisTaskXML.toString() + " FROM " + analysisTaskTable.getTableName() + " WHERE " + analysisTaskTable.simContextRef + " = " + simContextKey + " ORDER BY " + // order-by to maintain order ... not really necessary
    analysisTaskTable.insertDate;
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            String analysisXML = (String) getLOB(rset, analysisTaskTable.analysisTaskXML, dbSyntax);
            org.jdom.Element rootElement = XmlUtil.stringToXML(analysisXML, null).getRootElement();
            cbit.vcell.modelopt.ParameterEstimationTask parameterEstimationTask = cbit.vcell.modelopt.ParameterEstimationTaskXMLPersistence.getParameterEstimationTask(rootElement, simContext);
            simContext.addAnalysisTask(parameterEstimationTask);
        }
    } catch (MathException | MappingException | PropertyVetoException | ExpressionException e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) MathException(cbit.vcell.math.MathException) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException)

Example 15 with MappingException

use of cbit.vcell.mapping.MappingException in project vcell by virtualcell.

the class StochtestRunService method runOne.

public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
    String biomodelXML = null;
    if (stochtestRun != null) {
        String networkGenProbs = null;
        try {
            User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
            ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
            biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
            bioModel.refreshDependencies();
            SimulationContext srcSimContext = null;
            for (SimulationContext sc : bioModel.getSimulationContexts()) {
                if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
                    srcSimContext = sc;
                }
            }
            if (srcSimContext == null) {
                throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
            }
            // 
            for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
                scs.setConstant(false);
            }
            SimulationContext simContext = srcSimContext;
            StochtestMathType parentMathType = stochtestRun.parentMathType;
            StochtestMathType mathType = stochtestRun.mathType;
            if (parentMathType != mathType) {
                if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
                } else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
                } else {
                    throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
                }
                bioModel.addSimulationContext(simContext);
            }
            MathMappingCallback mathMappingCallback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
            simContext.setMathDescription(mathDesc);
            if (simContext.isInsufficientIterations()) {
                networkGenProbs = "insufficientIterations";
            } else if (simContext.isInsufficientMaxMolecules()) {
                networkGenProbs = "insufficientMaxMolecules";
            }
            File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
            try {
                OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
                double endTime = 10.0;
                computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
                StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
            } finally {
                StochtestFileUtils.clearDir(baseDirectory);
            }
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
            // 
            if (biomodelXML != null) {
                XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
            }
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MathDescription(cbit.vcell.math.MathDescription) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) StringWriter(java.io.StringWriter) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

MappingException (cbit.vcell.mapping.MappingException)25 ExpressionException (cbit.vcell.parser.ExpressionException)20 PropertyVetoException (java.beans.PropertyVetoException)17 MathException (cbit.vcell.math.MathException)13 ModelException (cbit.vcell.model.ModelException)13 Expression (cbit.vcell.parser.Expression)13 MathDescription (cbit.vcell.math.MathDescription)11 MatrixException (cbit.vcell.matrix.MatrixException)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 StructureMapping (cbit.vcell.mapping.StructureMapping)9 DataAccessException (org.vcell.util.DataAccessException)9 BioModel (cbit.vcell.biomodel.BioModel)8 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)8 XmlParseException (cbit.vcell.xml.XmlParseException)8 Model (cbit.vcell.model.Model)7 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)7 XMLSource (cbit.vcell.xml.XMLSource)7 Structure (cbit.vcell.model.Structure)6 Vector (java.util.Vector)6 ImageException (cbit.image.ImageException)5