Search in sources :

Example 1 with GroupAccessAll

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

the class XmlReader method getGroupAccess.

/**
 * This method returns a GroupAccess object from an XML format.
 * Creation date: (5/23/2003 7:27:10 PM)
 * @return cbit.vcell.server.GroupAccess
 * @param xmlGroup org.jdom.Element
 */
private GroupAccess getGroupAccess(Element xmlGroup) {
    // guess the type of group
    String temp = xmlGroup.getAttributeValue(XMLTags.TypeAttrTag);
    java.math.BigDecimal type = new java.math.BigDecimal(temp);
    if (type.equals(GroupAccess.GROUPACCESS_ALL)) {
        // Type ALL
        return new GroupAccessAll();
    } else if (type.equals(GroupAccess.GROUPACCESS_NONE)) {
        // Type NONE
        return new GroupAccessNone();
    } else {
        // Type SOME
        // Read attributes
        // *groupid
        temp = xmlGroup.getAttributeValue(XMLTags.TypeAttrTag);
        java.math.BigDecimal groupid = new java.math.BigDecimal(temp);
        // *hash
        temp = xmlGroup.getAttributeValue(XMLTags.HashAttrTag);
        java.math.BigDecimal hashcode = new java.math.BigDecimal(temp);
        // *users
        List<Element> userlist = xmlGroup.getChildren(XMLTags.UserTag, vcNamespace);
        User[] userArray = new User[userlist.size()];
        boolean[] booleanArray = new boolean[userlist.size()];
        int counter = 0;
        for (Element userElement : userlist) {
            String userid = unMangle(userElement.getAttributeValue(XMLTags.NameAttrTag));
            KeyValue key = new KeyValue(userElement.getAttributeValue(XMLTags.KeyValueAttrTag));
            boolean hidden = Boolean.valueOf(userElement.getAttributeValue(XMLTags.HiddenTag)).booleanValue();
            userArray[counter] = new User(userid, key);
            booleanArray[counter] = hidden;
            counter++;
        }
        // create and return the GroupAccess
        return new GroupAccessSome(groupid, hashcode, userArray, booleanArray);
    }
}
Also used : GroupAccessNone(org.vcell.util.document.GroupAccessNone) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) GroupAccessAll(org.vcell.util.document.GroupAccessAll) Element(org.jdom.Element) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) GroupAccessSome(org.vcell.util.document.GroupAccessSome)

Example 2 with GroupAccessAll

use of org.vcell.util.document.GroupAccessAll 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 3 with GroupAccessAll

use of org.vcell.util.document.GroupAccessAll 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

GroupAccessAll (org.vcell.util.document.GroupAccessAll)3 DataAccessException (org.vcell.util.DataAccessException)2 GroupAccessNone (org.vcell.util.document.GroupAccessNone)2 GroupAccessSome (org.vcell.util.document.GroupAccessSome)2 KeyValue (org.vcell.util.document.KeyValue)2 User (org.vcell.util.document.User)2 Version (org.vcell.util.document.Version)2 VersionableTypeVersion (org.vcell.util.document.VersionableTypeVersion)2 BigDecimal (java.math.BigDecimal)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Element (org.jdom.Element)1 PermissionException (org.vcell.util.PermissionException)1 BioModelInfo (org.vcell.util.document.BioModelInfo)1 MathModelInfo (org.vcell.util.document.MathModelInfo)1 VCDocumentInfo (org.vcell.util.document.VCDocumentInfo)1 VersionFlag (org.vcell.util.document.VersionFlag)1