Search in sources :

Example 1 with DependencyException

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

the class SimulationContextDbDriver method updateVersionable.

/**
 * This method was created in VisualAge.
 * @return cbit.image.VCImage
 * @param user cbit.vcell.server.User
 * @param image cbit.image.VCImage
 */
public KeyValue updateVersionable(InsertHashtable hash, Connection con, User user, SimulationContext simContext, KeyValue updatedMathDescKey, Model updatedModel, KeyValue updatedGeometryKey, boolean bVersion) throws DataAccessException, SQLException, RecordChangedException {
    Version newVersion = null;
    try {
        newVersion = updateVersionableInit(hash, con, user, simContext, bVersion);
        insertSimulationContext(hash, con, user, simContext, updatedMathDescKey, updatedModel, updatedGeometryKey, newVersion, bVersion);
    } catch (DependencyException e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException("MathException: " + e.getMessage());
    }
    return newVersion.getVersionKey();
}
Also used : Version(org.vcell.util.document.Version) DependencyException(org.vcell.util.DependencyException) DataAccessException(org.vcell.util.DataAccessException)

Example 2 with DependencyException

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

the class SimulationDbDriver method deleteSimulationSQL.

/**
 * removeModel method comment.
 */
private void deleteSimulationSQL(Connection con, User user, KeyValue simKey) throws SQLException, DataAccessException, DependencyException {
    // 
    // check for external references (from a BioModel or a MathModel)
    // 
    failOnExternalRefs(con, MathModelSimulationLinkTable.table.simRef, MathModelSimulationLinkTable.table, simKey, SimulationTable.table);
    failOnExternalRefs(con, BioModelSimulationLinkTable.table.simRef, BioModelSimulationLinkTable.table, simKey, SimulationTable.table);
    // 
    // delete the Simulation (the ResultSetMetaData should be deleted by ON DELETE CASCADE)
    // 
    String sql = DatabasePolicySQL.enforceOwnershipDelete(user, simTable, simTable.id.getQualifiedColName() + " = " + simKey);
    updateCleanSQL(con, sql);
    // 
    // try to delete the parentSimulation ... it's OK if it fails
    // 
    KeyValue parentSimKey = getParentSimulation(con, user, simKey);
    if (parentSimKey != null) {
        try {
            deleteVersionable(con, user, VersionableType.Simulation, parentSimKey);
        } catch (Exception e) {
            lg.error("failed to delete parent simulation, key=" + parentSimKey + ": " + e.getMessage(), e);
        }
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) RecordChangedException(cbit.sql.RecordChangedException) DataAccessException(org.vcell.util.DataAccessException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) DependencyException(org.vcell.util.DependencyException)

Example 3 with DependencyException

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

the class SimulationContextDbDriver method deleteSimContextSQL.

/**
 * removeModel method comment.
 */
private void deleteSimContextSQL(Connection con, User user, KeyValue simContextKey) throws SQLException, PermissionException, DataAccessException, DependencyException {
    // log.print("deleteSimContextSQL(user=" + user + ", simContextKey=" + simContextKey + ")");
    // 
    // check for external references (from BioModel)
    // 
    failOnExternalRefs(con, BioModelSimContextLinkTable.table.simContextRef, BioModelSimContextLinkTable.table, simContextKey, SimContextTable.table);
    KeyValue mathKey = getDeletableMathKeyFromSimContext(con, user, simContextKey);
    // 
    // delete SimulationContext (Model and Geometry link tables are ON DELETE CASCADE)
    // 
    String sql;
    sql = DatabasePolicySQL.enforceOwnershipDelete(user, simContextTable, simContextTable.id.getQualifiedColName() + " = " + simContextKey);
    updateCleanSQL(con, sql);
    // 
    try {
        mathDescDB.deleteVersionable(con, user, VersionableType.MathDescription, mathKey);
        if (lg.isTraceEnabled()) {
            lg.trace("SimulationContextDbDriver.delete(" + simContextKey + ") deletion of MathDescription(" + mathKey + ") succeeded");
        }
    } catch (PermissionException | DependencyException e) {
        if (lg.isWarnEnabled()) {
            lg.warn("SimulationContextDbDriver.delete(" + simContextKey + ") deletion of MathDescription(" + mathKey + ") failed: " + e.getMessage());
        }
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) DependencyException(org.vcell.util.DependencyException)

Example 4 with DependencyException

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

the class DbDriver method deleteVersionableInit.

/**
 * This method was created in VisualAge.
 * @param user cbit.vcell.server.User
 * @param vType int
 * @param versionKey cbit.sql.KeyValue
 */
protected void deleteVersionableInit(Connection con, User user, VersionableType vType, KeyValue versionKey) throws DependencyException, ObjectNotFoundException, SQLException, DataAccessException, PermissionException {
    Vector<VersionInfo> versionInfoVector = getVersionableInfos(con, user, vType, true, versionKey, true, dbSyntax);
    if (versionInfoVector.size() == 0) {
        throw new ObjectNotFoundException("DbDriver:deleteVersionableInit " + vType.getTypeName() + "(" + versionKey + ") not found for user=" + user);
    } else if (versionInfoVector.size() > 1) {
        throw new DataAccessException("DbDriver:deleteVersionableInit " + vType.getTypeName() + "(" + versionKey + ") found more than one entry  DB ERROR,BAD!!!!!MUST CHECK");
    }
    VersionInfo versionInfo = versionInfoVector.firstElement();
    // 
    if (versionInfo.getVersion().getFlag().compareEqual(VersionFlag.Archived) || versionInfo.getVersion().getFlag().compareEqual(VersionFlag.Published)) {
        throw new DataAccessException("DbDriver:deleteVersionableInit " + vType.getTypeName() + "(" + versionKey + ") Cannot DELETE\n" + "because document " + versionInfo.getVersion().getName() + "(" + versionInfo.getVersion().getDate() + ") is " + (versionInfo.getVersion().getFlag().compareEqual(VersionFlag.Archived) ? "ARCHIVED" : "PUBLISHED"));
    }
    // 
    if (!versionInfo.getVersion().getOwner().compareEqual(user)) {
        throw new PermissionException("deletion failed on " + vType.getTypeName() + " '" + versionInfo.getVersion().getName() + "' (" + versionKey + "), not owned by user " + user);
    }
    // 
    if (versionInfo.getVersion().getFlag().isArchived()) {
        throw new PermissionException("deletion failed on archived " + vType.getTypeName() + " '" + versionInfo.getVersion().getName() + "' (" + versionKey + ")");
    }
    // 
    if (isBranchPointOrBaseSimulation(con, vType, versionKey)) {
        throw new DependencyException(VersionTable.getVersionTable(vType) + ",id=" + versionKey + " can't be deleted, it is either a branch point or a base Simulation");
    }
    // if(VersionTable.hasExternalRef(con,user,vType,versionKey)){
    // throw new DependencyException( vTable + ",id=" + versionKey + " has external references");
    // }
    updateCleanSQL(con, "DELETE FROM " + SoftwareVersionTable.table.getTableName() + " WHERE " + SoftwareVersionTable.table.versionableRef.toString() + " = " + versionKey.toString());
}
Also used : PermissionException(org.vcell.util.PermissionException) VersionInfo(org.vcell.util.document.VersionInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DependencyException(org.vcell.util.DependencyException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

DependencyException (org.vcell.util.DependencyException)4 DataAccessException (org.vcell.util.DataAccessException)3 PermissionException (org.vcell.util.PermissionException)3 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 KeyValue (org.vcell.util.document.KeyValue)2 RecordChangedException (cbit.sql.RecordChangedException)1 PropertyVetoException (java.beans.PropertyVetoException)1 SQLException (java.sql.SQLException)1 Version (org.vcell.util.document.Version)1 VersionInfo (org.vcell.util.document.VersionInfo)1