Search in sources :

Example 61 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class MathModelDbDriver method getMathModelMetaData.

/**
 * getModel method comment.
 */
private MathModelMetaData getMathModelMetaData(Connection con, User user, KeyValue mathModelKey) throws SQLException, DataAccessException, ObjectNotFoundException {
    if (user == null || mathModelKey == null) {
        throw new IllegalArgumentException("Improper parameters for getMathModelMetaData");
    }
    if (lg.isTraceEnabled())
        lg.trace("MathModelDbDriver.getMathModelMetaData(user=" + user + ", id=" + mathModelKey + ")");
    // 
    // to construct a MathModelMetaData as an immutable object, lets collect all keys first
    // (even before authentication).  If the user doesn't authenticate, then throw away the
    // child keys (from link tables).
    // 
    // 
    // get Simulation Keys for mathModelKey
    // 
    KeyValue[] simKeys = getSimulationEntriesFromMathModel(con, mathModelKey);
    // 
    // get MathModelMetaData object for mathModelKey
    // 
    String sql;
    Field[] f = { new cbit.sql.StarField(mathModelTable), userTable.userid };
    Table[] t = { mathModelTable, userTable };
    String condition = mathModelTable.id.getQualifiedColName() + " = " + mathModelKey + " AND " + userTable.id.getQualifiedColName() + " = " + mathModelTable.ownerRef.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax, true);
    Statement stmt = con.createStatement();
    MathModelMetaData mathModelMetaData = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            mathModelMetaData = mathModelTable.getMathModelMetaData(rset, con, simKeys, dbSyntax);
        } else {
            throw new ObjectNotFoundException("MathModel id=" + mathModelKey + " not found for user '" + user + "'");
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    return mathModelMetaData;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Table(cbit.sql.Table) Statement(java.sql.Statement) MathModelMetaData(cbit.vcell.mathmodel.MathModelMetaData) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet)

Example 62 with ObjectNotFoundException

use of org.vcell.util.ObjectNotFoundException in project vcell by virtualcell.

the class DBTopLevel method getMathModelXML.

/**
 * This method was created in VisualAge.
 * @return cbit.sql.Versionable
 * @param object cbit.sql.Versionable
 * @param name java.lang.String
 * @param bVersion boolean
 * @exception org.vcell.util.DataAccessException The exception description.
 * @exception java.sql.SQLException The exception description.
 * @exception cbit.sql.RecordChangedException The exception description.
 */
String getMathModelXML(User user, KeyValue key, boolean bEnableRetry) throws DataAccessException, java.sql.SQLException, ObjectNotFoundException {
    Object lock = new Object();
    VersionableType versionableType = VersionableType.MathModelMetaData;
    Connection con = conFactory.getConnection(lock);
    DbDriver driver = getDbDriver(versionableType);
    try {
        // 
        // Getting the corresponding VersionInfo will fail if you don't have permission to the object.
        // This is needed because the DbDriver-level services can return objects directly from the
        // cache without checking for permissions first.
        // 
        // This check is placed in DbTopLevel because this is the client API entry point.
        // Child objects (of the requested object) are given permission by reachablity anyway,
        // so if the user is allowed permission to the parent, no further checks are necessary.
        // 
        Vector<VersionInfo> vInfos = getVersionableInfos(user, key, versionableType, true, true, false);
        if (vInfos.size() == 0) {
            throw new ObjectNotFoundException(versionableType.getTypeName() + " not found");
        }
        return driver.getVersionableXML(con, versionableType, key);
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
        if (bEnableRetry && isBadConnection(con)) {
            conFactory.failed(con, lock);
            return getMathModelXML(user, key, false);
        } else {
            handle_DataAccessException_SQLException(e);
            // never gets here;
            return null;
        }
    } finally {
        conFactory.release(con, lock);
    }
}
Also used : VersionInfo(org.vcell.util.document.VersionInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) Connection(java.sql.Connection) VersionableType(org.vcell.util.document.VersionableType)

Aggregations

ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)62 DataAccessException (org.vcell.util.DataAccessException)26 KeyValue (org.vcell.util.document.KeyValue)21 ResultSet (java.sql.ResultSet)18 Statement (java.sql.Statement)17 PermissionException (org.vcell.util.PermissionException)17 SQLException (java.sql.SQLException)13 User (org.vcell.util.document.User)12 BigString (org.vcell.util.BigString)11 XmlParseException (cbit.vcell.xml.XmlParseException)10 VersionInfo (org.vcell.util.document.VersionInfo)10 Field (cbit.sql.Field)9 SimulationRep (cbit.vcell.modeldb.SimulationRep)9 XMLSource (cbit.vcell.xml.XMLSource)9 Table (cbit.sql.Table)8 OuterJoin (cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin)8 PropertyVetoException (java.beans.PropertyVetoException)8 ResourceException (org.restlet.resource.ResourceException)8 VCellApiApplication (org.vcell.rest.VCellApiApplication)8 BioModel (cbit.vcell.biomodel.BioModel)7