use of org.vcell.util.document.VersionableType 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;
}
use of org.vcell.util.document.VersionableType in project vcell by virtualcell.
the class DbDriver method insertVersionableInit.
/**
* This method was created in VisualAge.
* @return cbit.sql.KeyValue
* @param versionable cbit.sql.Versionable
* @param pRef cbit.sql.KeyValue
* @param bCommit boolean
*/
protected Version insertVersionableInit(InsertHashtable hash, Connection con, User user, Versionable versionable, String name, String annot, boolean bVersion) throws SQLException, DataAccessException {
if (hash.getDatabaseKey(versionable) != null) {
throw new DataAccessException(versionable + " already inserted in this transaction");
}
VersionableType vType = VersionTable.versionableTypeFromVersionable(versionable);
if (vType.getIsTopLevel() && isNameUsed(con, vType, user, name)) {
throw new DataAccessException("'" + user.getName() + "' already has a " + vType.getTypeName() + " with name '" + name + "'");
}
User owner = user;
// AccessInfo accessInfo = new AccessInfo(AccessInfo.PRIVATE_CODE);
GroupAccess accessInfo = new GroupAccessNone();
KeyValue versionKey = keyFactory.getNewKey(con);
java.util.Date date = getNewDate(con);
// if(versionable.getVersion().getVersionKey() != null){
// throw new DataAccessException("GeomDbDriver:insertVersionable, VersionKey must be null to insert");
// }
String versionName = name;
// Check for Archive and Publish not needed in insert because versionflag is always forced to Current
VersionFlag versionFlag = null;
// if(bVersion){
// versionFlag = VersionFlag.Archived;
// }else{
versionFlag = VersionFlag.Current;
// }
KeyValue PRefKey = null;
java.math.BigDecimal branchID = getNewBranchID(con);
//
// Insert Software Version
//
insertSoftwareVersion(con, versionKey);
//
return new Version(versionKey, versionName, owner, accessInfo, PRefKey, branchID, date, versionFlag, annot);
}
use of org.vcell.util.document.VersionableType in project vcell by virtualcell.
the class DependencyTest method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
if (args.length != 2) {
throw new RuntimeException("Usage: DependencyTest VersionableType.toString() keyValue.toString()");
}
java.sql.Connection con = null;
try {
String versionableTypeS = args[0];
String keyValueS = args[1];
// new cbit.sql.KeyValue("1368");
org.vcell.util.document.KeyValue rootKey = new org.vcell.util.document.KeyValue(keyValueS);
// cbit.sql.VersionableType.VCImage;
org.vcell.util.document.VersionableType rootType = null;
if (VersionableType.VCImage.toString().equals(versionableTypeS)) {
rootType = VersionableType.VCImage;
} else if (VersionableType.Geometry.toString().equals(versionableTypeS)) {
rootType = VersionableType.Geometry;
} else if (VersionableType.Model.toString().equals(versionableTypeS)) {
rootType = VersionableType.Model;
} else if (VersionableType.MathDescription.toString().equals(versionableTypeS)) {
rootType = VersionableType.MathDescription;
} else if (VersionableType.SimulationContext.toString().equals(versionableTypeS)) {
rootType = VersionableType.SimulationContext;
} else {
throw new RuntimeException("Improper argument for VersionableType " + versionableTypeS);
}
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@nrcamdb.uchc.edu:1521:orc0";
con = java.sql.DriverManager.getConnection(url, "nrcamdbdev", "bogus");
System.out.println("Search for References to " + rootType.toString() + " id=" + rootKey.toString());
VersionableFamily vf = cbit.vcell.modeldb.DbDriver.getAllReferences(con, rootType, rootKey);
VersionableRelationship[] dependants = vf.getDependantRelationships();
for (int c = 0; c < dependants.length; c += 1) {
VersionableRelationship verrel = dependants[c];
VersionableTypeVersion from = verrel.from();
VersionableTypeVersion to = verrel.to();
System.out.println(from.getVType() + " " + from.getVersion().getVersionKey() + " ==> " + to.getVType() + " " + to.getVersion().getVersionKey());
}
System.out.println("------------------Top Down List-------------------");
VersionableTypeVersion[] topDown = vf.getDependantsTopDown();
byte[] spaces = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
for (int c = 0; c < topDown.length; c += 1) {
System.out.print(topDown[c].getVType());
System.out.write(spaces, 0, 30 - topDown[c].getVType().toString().length());
System.out.print(topDown[c].getVersion().getName());
System.out.write(spaces, 0, 40 - topDown[c].getVersion().getName().length());
System.out.println(topDown[c].getVersion().getVersionKey());
}
} catch (Throwable e) {
e.printStackTrace(System.out);
} finally {
try {
if (con != null) {
con.close();
}
} catch (java.sql.SQLException e) {
}
}
}
use of org.vcell.util.document.VersionableType in project vcell by virtualcell.
the class FieldDataWindowManager method findReferencingModels.
public boolean findReferencingModels(final ExternalDataIdentifier targetExtDataID, boolean bShowReferencingModelsList) throws DataAccessException, UserCancelException {
ReferenceQuerySpec rqs = new ReferenceQuerySpec(targetExtDataID);
ReferenceQueryResult rqr = getRequestManager().getDocumentManager().findReferences(rqs);
VersionableTypeVersion[] dependants = null;
Hashtable<VersionableTypeVersion, String[]> choices = new Hashtable<VersionableTypeVersion, String[]>();
boolean bDanglingReferences = false;
VersionableType bioModelType = VersionableType.BioModelMetaData;
VersionableType mathModelType = VersionableType.MathModelMetaData;
if (rqr != null) {
dependants = (rqr.getVersionableFamily().bDependants() ? rqr.getVersionableFamily().getUniqueDependants() : null);
if (dependants != null) {
for (int i = 0; i < dependants.length; i += 1) {
boolean isBioModel = dependants[i].getVType().equals(bioModelType);
boolean isTop = isBioModel || dependants[i].getVType().equals(mathModelType);
if (isTop) {
VersionableRelationship[] vrArr2 = rqr.getVersionableFamily().getDependantRelationships();
for (int j = 0; j < vrArr2.length; j += 1) {
if ((vrArr2[j].from() == dependants[i]) && vrArr2[j].to().getVType().equals((isBioModel ? VersionableType.SimulationContext : VersionableType.MathDescription))) {
for (int k = 0; k < vrArr2.length; k += 1) {
boolean bAdd = false;
if (k == j && vrArr2[k].from().getVType().equals(mathModelType)) {
bAdd = true;
}
if ((vrArr2[k].from() == vrArr2[j].to()) && vrArr2[k].to().getVType().equals(VersionableType.MathDescription)) {
bAdd = true;
}
if (bAdd) {
choices.put(dependants[i], new String[] { dependants[i].getVersion().getName(), (isBioModel ? bioModelType.getTypeName() : mathModelType.getTypeName()), (isBioModel ? vrArr2[k].from().getVersion().getName() : ""), dependants[i].getVersion().getVersionKey().toString() });
}
}
}
}
}
}
bDanglingReferences = (choices.size() == 0);
} else {
bDanglingReferences = true;
}
}
// FieldDataFileOperationResults fdfor = getRequestManager().getDocumentManager().fieldDataFileOperation(
// FieldDataFileOperationSpec.createDependantFuncsFieldDataFileOperationSpec(targetExtDataID));
FieldDataFileOperationResults fdfor = null;
boolean bHasReferences = false;
if (choices.size() > 0 || fdfor != null) {
bHasReferences = true;
if (bShowReferencingModelsList) {
String[] columnNames = new String[] { "Model", "Type", "Description" };
Vector<VersionableType> varTypeV = new Vector<VersionableType>();
Vector<KeyValue> keyValV = new Vector<KeyValue>();
Vector<String[]> choicesV = new Vector<String[]>();
String[][] modelListData = choices.values().toArray(new String[0][0]);
for (int i = 0; i < modelListData.length; i++) {
choicesV.add(new String[] { modelListData[i][0], modelListData[i][1], "Model Variable - " + (modelListData[i][2].length() == 0 ? "" : "App='" + modelListData[i][2] + "'") + " version[" + modelListData[i][3] + "]" });
varTypeV.add((modelListData[i][1].equals(bioModelType.getTypeName()) ? bioModelType : mathModelType));
keyValV.add(new KeyValue(modelListData[i][3]));
}
for (int i = 0; fdfor != null && i < fdfor.dependantFunctionInfo.length; i++) {
String functionNames = "";
for (int j = 0; j < fdfor.dependantFunctionInfo[i].funcNames.length; j++) {
functionNames += (j > 0 ? "," : "") + fdfor.dependantFunctionInfo[i].funcNames[j];
}
choicesV.add(new String[] { fdfor.dependantFunctionInfo[i].referenceSourceName, fdfor.dependantFunctionInfo[i].referenceSourceType, "Data Viewer Function(s) '" + functionNames + "' - " + (fdfor.dependantFunctionInfo[i].applicationName == null ? "" : "App='" + fdfor.dependantFunctionInfo[i].applicationName + "' ") + (fdfor.dependantFunctionInfo[i].simulationName == null ? "" : "Sim='" + fdfor.dependantFunctionInfo[i].simulationName + "' ") + "version[" + fdfor.dependantFunctionInfo[i].refSourceVersionDate + "]" });
if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME)) {
varTypeV.add(null);
} else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(bioModelType.getTypeName())) {
varTypeV.add(bioModelType);
} else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(mathModelType.getTypeName())) {
varTypeV.add(mathModelType);
} else {
throw new IllegalArgumentException("Unknown reference source type " + fdfor.dependantFunctionInfo[i].referenceSourceType);
}
keyValV.add(fdfor.dependantFunctionInfo[i].refSourceVersionKey);
}
int[] selectionArr = PopupGenerator.showComponentOKCancelTableList(getComponent(), "References to Field Data (Select To Open) " + targetExtDataID.getName(), columnNames, choicesV.toArray(new String[0][0]), ListSelectionModel.SINGLE_SELECTION);
if (selectionArr != null && selectionArr.length > 0) {
if (varTypeV.elementAt(selectionArr[0]) != null) {
if (varTypeV.elementAt(selectionArr[0]).equals(bioModelType)) {
BioModelInfo bmi = getRequestManager().getDocumentManager().getBioModelInfo(keyValV.elementAt(selectionArr[0]));
getRequestManager().openDocument(bmi, FieldDataWindowManager.this, true);
} else if (varTypeV.elementAt(selectionArr[0]).equals(mathModelType)) {
MathModelInfo mmi = getRequestManager().getDocumentManager().getMathModelInfo(keyValV.elementAt(selectionArr[0]));
getRequestManager().openDocument(mmi, FieldDataWindowManager.this, true);
} else {
throw new IllegalArgumentException("Not expecting varType " + varTypeV.elementAt(selectionArr[0]));
}
} else {
PopupGenerator.showInfoDialog(this, "use FiledDataManager to view FieldData '" + choicesV.elementAt(selectionArr[0])[0] + "'");
}
}
}
} else {
if (!bDanglingReferences) {
bHasReferences = false;
if (bShowReferencingModelsList) {
PopupGenerator.showInfoDialog(this, "No Model references found for Field Data " + targetExtDataID.getName());
}
} else {
bHasReferences = true;
if (bShowReferencingModelsList) {
PopupGenerator.showInfoDialog(this, "No current Model references found.\n" + "Field Data has internal database references from\n" + "previously linked Model(s) that have been deleted.\n" + "Note: Field Data '" + targetExtDataID.getName() + "' is not deletable\n" + "until database is culled (daily).");
}
}
}
return bHasReferences;
}
use of org.vcell.util.document.VersionableType in project vcell by virtualcell.
the class DBTopLevel method getMathModelXML.
/**
* This method was created in VisualAge.
* @return cbit.sql.Versionable
* @param object cbit.sql.Versionable
* @param name java.lang.String
* @param bVersion boolean
* @exception org.vcell.util.DataAccessException The exception description.
* @exception java.sql.SQLException The exception description.
* @exception cbit.sql.RecordChangedException The exception description.
*/
String getMathModelXML(User user, KeyValue key, boolean bEnableRetry) throws DataAccessException, java.sql.SQLException, ObjectNotFoundException {
Object lock = new Object();
VersionableType versionableType = VersionableType.MathModelMetaData;
Connection con = conFactory.getConnection(lock);
DbDriver driver = getDbDriver(versionableType);
try {
//
// Getting the corresponding VersionInfo will fail if you don't have permission to the object.
// This is needed because the DbDriver-level services can return objects directly from the
// cache without checking for permissions first.
//
// This check is placed in DbTopLevel because this is the client API entry point.
// Child objects (of the requested object) are given permission by reachablity anyway,
// so if the user is allowed permission to the parent, no further checks are necessary.
//
Vector<VersionInfo> vInfos = getVersionableInfos(user, key, versionableType, true, true, false);
if (vInfos.size() == 0) {
throw new ObjectNotFoundException(versionableType.getTypeName() + " not found");
}
return driver.getVersionableXML(con, versionableType, key);
} catch (Throwable e) {
lg.error(e.getMessage(), e);
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return getMathModelXML(user, key, false);
} else {
handle_DataAccessException_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
Aggregations