use of org.vcell.util.document.GroupAccessSome 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);
}
}
use of org.vcell.util.document.GroupAccessSome in project vcell by virtualcell.
the class DatabaseWindowManager method accessPermissions.
/**
* Insert the method's description here.
* Creation date: (5/14/2004 5:35:55 PM)
*/
public void accessPermissions(final Component requester, final VersionInfo selectedVersionInfo) {
final GroupAccess groupAccess = selectedVersionInfo.getVersion().getGroupAccess();
final DocumentManager docManager = getRequestManager().getDocumentManager();
AsynchClientTask task1 = new AsynchClientTask("show dialog", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
getAclEditor().clearACLList();
getAclEditor().setACLState(new ACLEditor.ACLState(groupAccess));
Object choice = showAccessPermissionDialog(getAclEditor(), requester);
if (choice != null) {
hashTable.put("choice", choice);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("access permission", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
Object choice = hashTable.get("choice");
if (choice != null && choice.equals("OK")) {
ACLEditor.ACLState aclState = getAclEditor().getACLState();
if (aclState != null) {
if (aclState.isAccessPrivate() || (aclState.getAccessList() != null && aclState.getAccessList().length == 0)) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPrivate((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPrivate((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPrivate((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPrivate((VCImageInfo) selectedVersionInfo);
}
} else if (aclState.isAccessPublic()) {
VersionInfo vInfo = null;
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.setGroupPublic((BioModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.setGroupPublic((MathModelInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.setGroupPublic((GeometryInfo) selectedVersionInfo);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.setGroupPublic((VCImageInfo) selectedVersionInfo);
}
} else {
String[] aclUserNames = aclState.getAccessList();
String[] originalGroupAccesNames = new String[0];
// Turn User[] into String[]
if (groupAccess instanceof GroupAccessSome) {
GroupAccessSome gas = (GroupAccessSome) groupAccess;
User[] originalUsers = gas.getNormalGroupMembers();
for (int i = 0; i < originalUsers.length; i += 1) {
originalGroupAccesNames = (String[]) BeanUtils.addElement(originalGroupAccesNames, originalUsers[i].getName());
}
}
// Determine users needing adding
String[] needToAddUsers = new String[0];
for (int i = 0; i < aclUserNames.length; i += 1) {
if (!BeanUtils.arrayContains(originalGroupAccesNames, aclUserNames[i])) {
System.out.println("Added user=" + aclUserNames[i]);
needToAddUsers = (String[]) BeanUtils.addElement(needToAddUsers, aclUserNames[i]);
}
}
// Determine users needing removing
String[] needToRemoveUsers = new String[0];
for (int i = 0; i < originalGroupAccesNames.length; i += 1) {
if (!BeanUtils.arrayContains(aclUserNames, originalGroupAccesNames[i])) {
System.out.println("Removed user=" + originalGroupAccesNames[i]);
needToRemoveUsers = (String[]) BeanUtils.addElement(needToRemoveUsers, originalGroupAccesNames[i]);
}
}
VersionInfo vInfo = null;
String errorNames = "";
// Add Users to Group Access List
for (int i = 0; i < needToAddUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.addUserToGroup((BioModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.addUserToGroup((MathModelInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.addUserToGroup((GeometryInfo) selectedVersionInfo, needToAddUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.addUserToGroup((VCImageInfo) selectedVersionInfo, needToAddUsers[i]);
}
} catch (ObjectNotFoundException e) {
errorNames += "Error changing permissions.\n" + selectedVersionInfo.getVersionType().getTypeName() + " \"" + selectedVersionInfo.getVersion().getName() + "\" edition (" + selectedVersionInfo.getVersion().getDate() + ")\nnot found, " + "your model list may be out of date, please go to menu Server->Reconnect to refresh the model list" + "\n";
break;
} catch (DataAccessException e) {
errorNames += "Error adding user '" + needToAddUsers[i] + "' : " + e.getMessage() + "\n";
}
}
// Remove users from Group Access List
for (int i = 0; i < needToRemoveUsers.length; i++) {
try {
if (selectedVersionInfo instanceof BioModelInfo) {
vInfo = docManager.removeUserFromGroup((BioModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof MathModelInfo) {
vInfo = docManager.removeUserFromGroup((MathModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof GeometryInfo) {
vInfo = docManager.removeUserFromGroup((GeometryInfo) selectedVersionInfo, needToRemoveUsers[i]);
} else if (selectedVersionInfo instanceof VCImageInfo) {
vInfo = docManager.removeUserFromGroup((VCImageInfo) selectedVersionInfo, needToRemoveUsers[i]);
}
} catch (DataAccessException e) {
errorNames += "Error Removing user '" + needToRemoveUsers[i] + "'\n -----" + e.getMessage() + "\n";
}
}
if (errorNames.length() > 0) {
if (DatabaseWindowManager.this.getComponent() != null) {
PopupGenerator.showErrorDialog(DatabaseWindowManager.this, errorNames);
} else {
DialogUtils.showErrorDialog(requester, errorNames);
}
accessPermissions(requester, selectedVersionInfo);
}
}
}
}
}
};
ClientTaskDispatcher.dispatch(requester, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
use of org.vcell.util.document.GroupAccessSome 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 + ")");
}
}
}
use of org.vcell.util.document.GroupAccessSome in project vcell by virtualcell.
the class DbDriver method groupRemoveUser.
/**
* This method was created in VisualAge.
* @return cbit.sql.Versionable
* @param user cbit.vcell.server.User
* @param versionable cbit.sql.Versionable
*/
public static void groupRemoveUser(Connection con, KeyFactory keyFactory, User owner, VersionableType vType, KeyValue vKey, String userRemoveFromGroupString, boolean isHiddenFromOwner, DatabaseSyntax dbSyntax) throws SQLException, ObjectNotFoundException, DataAccessException {
User userRemoveFromGroup = getUserFromUserid(con, userRemoveFromGroupString);
if (userRemoveFromGroup == null) {
throw new IllegalArgumentException("User name " + userRemoveFromGroupString + " not found");
}
//
if ((con == null) || (vType == null) || (owner == null) || (vKey == null) || (userRemoveFromGroup == null)) {
throw new IllegalArgumentException("Improper parameters for groupRemoveUser userRemoveFromGroupString=" + (userRemoveFromGroupString == null ? "NULL" : userRemoveFromGroupString));
}
//
Version currentVersion = permissionInit(con, vType, vKey, owner);
// If userRemoveFromGroup is not in group it is an error, or if not a "real" group
boolean bExists = false;
if (currentVersion.getGroupAccess() instanceof GroupAccessSome) {
bExists = (((GroupAccessSome) currentVersion.getGroupAccess()).isNormalMember(userRemoveFromGroup) && !isHiddenFromOwner) || (((GroupAccessSome) currentVersion.getGroupAccess()).isHiddenMember(userRemoveFromGroup) && isHiddenFromOwner);
}
if (!bExists) {
throw new DataAccessException(userRemoveFromGroup + " not a member of group");
}
if (lg.isTraceEnabled())
lg.trace("DbDriver.groupAccessRemoveUser(user=" + owner + ", type =" + vType + ", key=" + vKey + ")");
GroupAccessSome currentGroup = (GroupAccessSome) currentVersion.getGroupAccess();
VersionTable vTable = VersionTable.getVersionTable(vType);
//
// calculate hash after removing user (null if last user in group)
//
BigDecimal newHash = null;
int count = (currentGroup.getNormalGroupMembers() != null ? currentGroup.getNormalGroupMembers().length : 0) + (currentGroup.getHiddenGroupMembers() != null ? currentGroup.getHiddenGroupMembers().length : 0);
if (count > 1) {
// See if group already exists without member and get it's ID
newHash = currentGroup.calculateHashWithoutMember(userRemoveFromGroup, isHiddenFromOwner);
}
//
BigDecimal updatedGroupID = null;
String sql = null;
//
if (newHash != null) {
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()) {
// Group already exists,Re-Use
updatedGroupID = rset.getBigDecimal(GroupTable.table.groupid.toString());
}
} finally {
stmt.close();
}
} else {
//
// user was last user in group, new group is the Private Group (AccessNone), groupID is predefined.
//
updatedGroupID = GroupAccess.GROUPACCESS_NONE;
}
//
if (updatedGroupID == null) {
updatedGroupID = getNewGroupID(con, keyFactory);
//
// Re-Add Normal users not removed
//
User[] normalUsers = currentGroup.getNormalGroupMembers();
for (int i = 0; normalUsers != null && i < normalUsers.length; i += 1) {
if (!(normalUsers[i].compareEqual(userRemoveFromGroup)) || isHiddenFromOwner) {
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);
}
}
//
// Re-Add Hidden users not removed
//
User[] hiddenUsers = currentGroup.getHiddenGroupMembers();
for (int i = 0; hiddenUsers != null && i < hiddenUsers.length; i += 1) {
if (!(hiddenUsers[i].compareEqual(userRemoveFromGroup)) || !isHiddenFromOwner) {
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);
}
}
}
//
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, or just already updated
//
Vector<VersionInfo> versionInfoList = getVersionableInfos(con, owner, vType, false, vKey, true, dbSyntax);
if (versionInfoList.size() == 0) {
throw new DataAccessException("Remove User " + userRemoveFromGroup + " Permission to access failed, " + vType.getTypeName() + "(" + vKey + ") record not found");
} else {
throw new DataAccessException("Remove User " + userRemoveFromGroup + " Permission to access failed " + vType.getTypeName() + "(" + vKey + ")");
}
}
}
Aggregations