Search in sources :

Example 26 with Version

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

the class ModelDbDriver method insertVersionable.

/**
 * This method was created in VisualAge.
 * @return cbit.sql.KeyValue
 * @param versionable cbit.sql.Versionable
 * @param pRef cbit.sql.KeyValue
 * @param bCommit boolean
 */
public KeyValue insertVersionable(InsertHashtable hash, Connection con, User user, Model model, String name, boolean bVersion) throws DataAccessException, SQLException, RecordChangedException {
    Version newVersion = insertVersionableInit(hash, con, user, model, name, model.getDescription(), bVersion);
    insertModel(hash, con, user, model, newVersion);
    return newVersion.getVersionKey();
}
Also used : Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion)

Example 27 with Version

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

the class ModelTable method getModel.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public Model getModel(ResultSet rset, Connection con) throws SQLException, DataAccessException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    ModelUnitSystem modelUnitSystem = ModelUnitSystem.createDefaultVCModelUnitSystem();
    String unitSystemXML = rset.getString(ModelTable.table.unitSystemXML.toString());
    if (!rset.wasNull()) {
        unitSystemXML = org.vcell.util.TokenMangler.getSQLRestoredString(unitSystemXML);
        XmlReader xmlReader = new XmlReader(false);
        modelUnitSystem = xmlReader.getUnitSystem(XmlUtil.stringToXML(unitSystemXML, null).getRootElement());
    }
    return new Model(version, modelUnitSystem);
}
Also used : Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Model(cbit.vcell.model.Model) XmlReader(cbit.vcell.xml.XmlReader) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 28 with Version

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

the class ModelTable method getInfo.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.geometry.GeometryInfo
 * @param rset java.sql.ResultSet
 * @param log cbit.vcell.server.SessionLog
 */
public VersionInfo getInfo(ResultSet rset, Connection con) throws SQLException, DataAccessException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    String softwareVersion = rset.getString(SoftwareVersionTable.table.softwareVersion.toString());
    return new ModelInfo(version, VCellSoftwareVersion.fromString(softwareVersion));
}
Also used : ModelInfo(cbit.vcell.model.ModelInfo) Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion)

Example 29 with Version

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

the class DbDriver method curate.

/**
 * Insert the method's description here.
 * Creation date: (5/23/2006 10:44:52 AM)
 */
public static VCDocumentInfo curate(CurateSpec curateSpec, Connection con, User user, DatabaseSyntax dbSyntax) throws DataAccessException, SQLException {
    VersionableType vType = null;
    if (curateSpec.getVCDocumentInfo() instanceof BioModelInfo) {
        vType = VersionableType.BioModelMetaData;
    } else if (curateSpec.getVCDocumentInfo() instanceof MathModelInfo) {
        vType = VersionableType.MathModelMetaData;
    } else {
        throw new DataAccessException("Expecting BioModelInfo or MathModelInfo but got type=" + curateSpec.getVCDocumentInfo().getClass().getName());
    }
    KeyValue vKey = curateSpec.getVCDocumentInfo().getVersion().getVersionKey();
    Version dbVersion = getVersionFromKeyValue(con, vType, vKey);
    // Must be owner to curate
    if (!dbVersion.getOwner().compareEqual(user)) {
        throw new PermissionException("Cannot curate " + vType.getTypeName() + " \"" + dbVersion.getName() + "\" (" + vKey + "), not owned by " + user.getName());
    }
    VersionFlag updatedVersionFlag = null;
    if (curateSpec.getCurateType() == CurateSpec.ARCHIVE) {
        if (!dbVersion.getFlag().compareEqual(VersionFlag.Current)) {
            throw new IllegalArgumentException("Only non-archived, non-published documents can be ARCHIVED");
        }
        updatedVersionFlag = VersionFlag.Archived;
    } else if (curateSpec.getCurateType() == CurateSpec.PUBLISH) {
        // Must have PUBLISH rights
        if (!dbVersion.getOwner().isPublisher()) {
            throw new PermissionException("Cannot curate " + vType.getTypeName() + " \"" + dbVersion.getName() + "\" (" + vKey + "), user " + user.getName() + " not granted PUBLISHING rights");
        }
        // Must be ARCHIVED and Public before PUBLISH is allowed
        if (!dbVersion.getFlag().compareEqual(VersionFlag.Archived) || !(dbVersion.getGroupAccess() instanceof GroupAccessAll)) {
            throw new IllegalArgumentException("Only ARCHIVED documents with PUBLIC permission can be PUBLISHED");
        }
        updatedVersionFlag = VersionFlag.Published;
    } else {
        throw new DataAccessException("Expecting CurateType " + CurateSpec.ARCHIVE + "(ARCHIVE) or " + CurateSpec.PUBLISH + "(PUBLISH) but got type=" + curateSpec.getCurateType());
    }
    VersionTable vTable = VersionTable.getVersionTable(vType);
    String set = vTable.versionFlag.getQualifiedColName() + " = " + updatedVersionFlag.getIntValue();
    String cond = vTable.id.getQualifiedColName() + " = " + vKey;
    String sql = DatabasePolicySQL.enforceOwnershipUpdate(user, vTable, set, cond);
    int numRowsProcessed = updateCleanSQL(con, sql);
    // Clear XML
    if (vType.equals(VersionableType.BioModelMetaData)) {
        updateCleanSQL(con, "DELETE FROM " + BioModelXMLTable.table.getTableName() + " WHERE " + BioModelXMLTable.table.bioModelRef.getQualifiedColName() + " = " + vKey.toString());
    } else if (vType.equals(VersionableType.MathModelMetaData)) {
        updateCleanSQL(con, "DELETE FROM " + MathModelXMLTable.table.getTableName() + " WHERE " + MathModelXMLTable.table.mathModelRef.getQualifiedColName() + " = " + vKey.toString());
    }
    VCDocumentInfo dbVCDocumentInfo = (VCDocumentInfo) getVersionableInfos(con, user, vType, false, vKey, false, dbSyntax).elementAt(0);
    return dbVCDocumentInfo;
}
Also used : PermissionException(org.vcell.util.PermissionException) KeyValue(org.vcell.util.document.KeyValue) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) VersionableType(org.vcell.util.document.VersionableType) VersionFlag(org.vcell.util.document.VersionFlag) GroupAccessAll(org.vcell.util.document.GroupAccessAll) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 30 with Version

use of org.vcell.util.document.Version 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 + ")");
        }
    }
}
Also used : User(org.vcell.util.document.User) BigDecimal(java.math.BigDecimal) GroupAccessNone(org.vcell.util.document.GroupAccessNone) VersionInfo(org.vcell.util.document.VersionInfo) GroupAccessAll(org.vcell.util.document.GroupAccessAll) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) ResultSet(java.sql.ResultSet) Statement(java.sql.Statement) GroupAccessSome(org.vcell.util.document.GroupAccessSome) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

Version (org.vcell.util.document.Version)74 VCellSoftwareVersion (org.vcell.util.document.VCellSoftwareVersion)27 DataAccessException (org.vcell.util.DataAccessException)24 KeyValue (org.vcell.util.document.KeyValue)22 BigDecimal (java.math.BigDecimal)17 Geometry (cbit.vcell.geometry.Geometry)13 SimulationVersion (org.vcell.util.document.SimulationVersion)12 PropertyVetoException (java.beans.PropertyVetoException)10 User (org.vcell.util.document.User)10 VersionableTypeVersion (org.vcell.util.document.VersionableTypeVersion)10 Element (org.jdom.Element)9 MathDescription (cbit.vcell.math.MathDescription)8 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)8 SimulationContext (cbit.vcell.mapping.SimulationContext)7 ResultSet (java.sql.ResultSet)7 Statement (java.sql.Statement)7 ImageException (cbit.image.ImageException)6 Simulation (cbit.vcell.solver.Simulation)6 VersionFlag (org.vcell.util.document.VersionFlag)6 Model (cbit.vcell.model.Model)5