Search in sources :

Example 6 with VersionFlag

use of org.vcell.util.document.VersionFlag in project vcell by virtualcell.

the class DbDriver method updateVersionableInit.

/**
 * This method was created in VisualAge.
 * @return cbit.image.VCImage
 * @param user cbit.vcell.server.User
 * @param image cbit.image.VCImage
 */
protected Version updateVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, boolean bVersion) throws DataAccessException, SQLException, RecordChangedException {
    if (hash.getDatabaseKey(versionable) != null) {
        throw new DataAccessException(versionable + " already inserted in this transaction");
    }
    if (versionable.getVersion() == null || versionable.getVersion().getVersionKey() == null) {
        throw new DataAccessException(versionable + " Not expecting null key before update.  Update Failed");
    }
    // Can only update things we own
    if (!versionable.getVersion().getOwner().equals(user)) {
        throw new PermissionException("Versionable name=" + versionable.getName() + " type=" + VersionTable.versionableTypeFromVersionable(versionable) + "\nuser=" + versionable.getVersion().getOwner() + " Not Equal to client user=" + user);
    }
    // 
    // get new Version info
    // 
    User owner = user;
    GroupAccess accessInfo = versionable.getVersion().getGroupAccess();
    // 
    if (versionable instanceof BioModelMetaData || versionable instanceof MathModelMetaData || versionable instanceof Geometry) {
        Statement stmt = null;
        try {
            stmt = con.createStatement();
            String sql = "SELECT " + VersionTable.privacy_ColumnName + " FROM " + VersionTable.getVersionTable(versionable).getTableName() + " WHERE " + VersionTable.id_ColumnName + " = " + versionable.getVersion().getVersionKey();
            ResultSet rset = stmt.executeQuery(sql);
            BigDecimal dbgrpid = null;
            if (rset.next()) {
                dbgrpid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
            }
            rset.close();
            if (!dbgrpid.equals(versionable.getVersion().getGroupAccess().getGroupid())) {
                accessInfo = getGroupAccessFromGroupID(con, dbgrpid);
            }
        } catch (Throwable e) {
        // Don't fail, just keep the permission versionable came in with
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
    }
    KeyValue versionKey = keyFactory.getNewKey(con);
    java.util.Date date = getNewDate(con);
    // 
    // always use the previous BranchPointReference unless branching
    // 
    KeyValue branchPointRefKey = versionable.getVersion().getBranchPointRefKey();
    // Check for Archive and Publish not needed in update because versionflag is always forced to Current
    VersionFlag versionFlag = null;
    // if (bVersion){
    // versionFlag = VersionFlag.Archived;
    // }else{
    versionFlag = VersionFlag.Current;
    // }
    String versionName = versionable.getVersion().getName();
    java.math.BigDecimal branchID = versionable.getVersion().getBranchID();
    String annot = versionable.getDescription();
    // 
    // Insert Software Version
    // 
    insertSoftwareVersion(con, versionKey);
    // 
    return new Version(versionKey, versionName, owner, accessInfo, branchPointRefKey, branchID, date, versionFlag, annot);
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) MathModelMetaData(cbit.vcell.mathmodel.MathModelMetaData) BioModelMetaData(cbit.vcell.biomodel.BioModelMetaData) BigDecimal(java.math.BigDecimal) Geometry(cbit.vcell.geometry.Geometry) BigDecimal(java.math.BigDecimal) VersionFlag(org.vcell.util.document.VersionFlag) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) ResultSet(java.sql.ResultSet) GroupAccess(org.vcell.util.document.GroupAccess) DataAccessException(org.vcell.util.DataAccessException)

Example 7 with VersionFlag

use of org.vcell.util.document.VersionFlag in project vcell by virtualcell.

the class VersionTable method getVersion.

/**
 * This method was created in VisualAge.
 * @return cbit.util.Version
 * @param rset ResultSet
 * @param log SessionLog
 */
public static Version getVersion(ResultSet rset, GroupAccess groupAccess) throws SQLException, DataAccessException {
    KeyValue vBranchPointRef = null;
    java.math.BigDecimal vBranchID = null;
    java.util.Date vDate = null;
    VersionFlag vFlag = null;
    String vAnnot = null;
    // 
    java.math.BigDecimal vBranchPointRefDB = rset.getBigDecimal(versionBranchPointRef_ColumnName);
    if (rset.wasNull()) {
        vBranchPointRef = null;
    } else {
        vBranchPointRef = new KeyValue(vBranchPointRefDB);
    }
    java.math.BigDecimal vBranchIDDB = rset.getBigDecimal(versionBranchID_ColumnName);
    if (rset.wasNull()) {
        vBranchID = null;
    } else {
        vBranchID = vBranchIDDB;
    }
    vDate = getDate(rset, versionDate_ColumnName);
    if (vDate == null) {
        throw new DataAccessException("could not parse date");
    }
    // 
    vFlag = VersionFlag.fromInt(rset.getInt(VersionTable.versionFlag_ColumnName));
    // 
    String vAnnotDB = rset.getString(versionAnnot_ColumnName);
    if (rset.wasNull()) {
        vAnnot = null;
    } else {
        vAnnot = org.vcell.util.TokenMangler.getSQLRestoredString(vAnnotDB);
    }
    boolean bFoundParentSimRefColumn = false;
    KeyValue parentSimRef = null;
    try {
        java.sql.ResultSetMetaData rsetMetaData = rset.getMetaData();
        int numColumns = rsetMetaData.getColumnCount();
        for (int i = 0; i < numColumns; i++) {
            if (rsetMetaData.getColumnName(i + 1).toUpperCase().endsWith(SimulationTable.table.versionParentSimRef.toString().toUpperCase())) {
                bFoundParentSimRefColumn = true;
                break;
            }
        }
        if (bFoundParentSimRefColumn) {
            java.math.BigDecimal parentSimRefDB = rset.getBigDecimal(SimulationTable.table.versionParentSimRef.toString());
            if (rset.wasNull()) {
                parentSimRef = null;
            } else {
                parentSimRef = new KeyValue(parentSimRefDB);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace(System.out);
        lg.warn("VersionTable.getVersion(): consuming exception for missing column " + versionParentSimRef_ColumnName + ": " + e.getMessage(), e);
    }
    // 
    KeyValue key = new KeyValue(rset.getBigDecimal(Table.id_ColumnName));
    String name = TokenMangler.getSQLRestoredString(rset.getString(VersionTable.name_ColumnName));
    String ownerName = rset.getString(UserTable.table.userid.toString());
    KeyValue ownerID = new KeyValue(rset.getBigDecimal(VersionTable.ownerRef_ColumnName));
    User owner = new User(ownerName, ownerID);
    // 
    if (bFoundParentSimRefColumn) {
        return new SimulationVersion(key, name, owner, groupAccess, vBranchPointRef, vBranchID, vDate, vFlag, vAnnot, parentSimRef);
    } else {
        return new Version(key, name, owner, groupAccess, vBranchPointRef, vBranchID, vDate, vFlag, vAnnot);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) SQLException(java.sql.SQLException) VersionFlag(org.vcell.util.document.VersionFlag) SimulationVersion(org.vcell.util.document.SimulationVersion) Version(org.vcell.util.document.Version) SimulationVersion(org.vcell.util.document.SimulationVersion) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

VersionFlag (org.vcell.util.document.VersionFlag)7 KeyValue (org.vcell.util.document.KeyValue)6 Version (org.vcell.util.document.Version)6 User (org.vcell.util.document.User)5 DataAccessException (org.vcell.util.DataAccessException)4 GroupAccess (org.vcell.util.document.GroupAccess)4 SimulationVersion (org.vcell.util.document.SimulationVersion)3 VersionableTypeVersion (org.vcell.util.document.VersionableTypeVersion)3 DataContext (cbit.vcell.data.DataContext)2 ParameterContext (cbit.vcell.mapping.ParameterContext)2 ReactionContext (cbit.vcell.mapping.ReactionContext)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 OutputFunctionContext (cbit.vcell.solver.OutputFunctionContext)2 BigDecimal (java.math.BigDecimal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Element (org.jdom.Element)2 RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)2 PermissionException (org.vcell.util.PermissionException)2 VersionableType (org.vcell.util.document.VersionableType)2