use of org.vcell.util.document.VersionFlag in project vcell by virtualcell.
the class XmlReader method getSimulationVersion.
/**
* This method returns a Version object from an XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @return cbit.sql.Version
* @param param org.jdom.Element
*/
private SimulationVersion getSimulationVersion(Element xmlVersion) throws XmlParseException {
if (xmlVersion == null) {
return null;
}
// determine if it should be processed using the 'fromVersionable'
if (xmlVersion.getAttributeValue(XMLTags.FromVersionableTag) == null || Boolean.valueOf(xmlVersion.getAttributeValue(XMLTags.FromVersionableTag)).booleanValue() || this.readKeysFlag == false) {
// this came from a versionable object, so skip! Or it should not explicitly import the information inside the Version
return null;
}
// Read all the attributes
// *name
String name = unMangle(xmlVersion.getAttributeValue(XMLTags.NameAttrTag));
// *key
String temp = xmlVersion.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(temp);
// *owner
Element tempElement = xmlVersion.getChild(XMLTags.OwnerTag, vcNamespace);
User owner = new User(unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag)), new KeyValue(tempElement.getAttributeValue(XMLTags.IdentifierAttrTag)));
// *access
GroupAccess groupAccess = getGroupAccess(xmlVersion.getChild(XMLTags.GroupAccessTag, vcNamespace));
// *Branchpointref
temp = xmlVersion.getAttributeValue(XMLTags.BranchPointRefTag);
KeyValue branchpointref = null;
if (temp != null) {
branchpointref = new KeyValue(temp);
}
// *BranchID
java.math.BigDecimal branchId = new java.math.BigDecimal(xmlVersion.getAttributeValue(XMLTags.BranchIdAttrTag));
// *Flag
temp = xmlVersion.getAttributeValue(XMLTags.FlagAttrTag);
VersionFlag flag = VersionFlag.fromInt(Integer.parseInt(temp));
// *Date
java.util.Date date = null;
temp = xmlVersion.getAttributeValue(XMLTags.DateAttrTag);
if (temp != null) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BeanUtils.vcDateFormat, Locale.US);
date = simpleDateFormat.parse(temp);
} catch (java.text.ParseException e) {
e.printStackTrace();
throw new XmlParseException("Invalid date:" + temp, e);
}
}
// *DataSimulationRef
KeyValue parentSimRefKey = null;
tempElement = xmlVersion.getChild(XMLTags.ParentSimRefTag, vcNamespace);
if (tempElement != null) {
parentSimRefKey = new KeyValue(tempElement.getAttributeValue(XMLTags.KeyValueAttrTag));
}
// *Annotation
String annotation = null;
String annotationText = xmlVersion.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
annotation = unMangle(annotationText);
}
// Create and return the version object
return new SimulationVersion(key, name, owner, groupAccess, branchpointref, branchId, date, flag, annotation, parentSimRefKey);
}
use of org.vcell.util.document.VersionFlag in project vcell by virtualcell.
the class XmlReader method getVersion.
/**
* This method returns a Version object from an XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @return cbit.sql.Version
* @param param org.jdom.Element
*/
private Version getVersion(Element xmlVersion) throws XmlParseException {
if (xmlVersion == null) {
return null;
}
// determine if it should be processed using the 'fromVersionable'
if (xmlVersion.getAttributeValue(XMLTags.FromVersionableTag) == null || Boolean.valueOf(xmlVersion.getAttributeValue(XMLTags.FromVersionableTag)).booleanValue() || this.readKeysFlag == false) {
// this came from a versionable object, so skip! Or it should not explicitly import the information inside the Version
return null;
}
// Read all the attributes
// *name
String name = unMangle(xmlVersion.getAttributeValue(XMLTags.NameAttrTag));
// *key
String temp = xmlVersion.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = new KeyValue(temp);
// *owner
Element tempElement = xmlVersion.getChild(XMLTags.OwnerTag, vcNamespace);
User owner = new User(unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag)), new KeyValue(tempElement.getAttributeValue(XMLTags.IdentifierAttrTag)));
// *access
GroupAccess groupAccess = getGroupAccess(xmlVersion.getChild(XMLTags.GroupAccessTag, vcNamespace));
// *Branchpointref
temp = xmlVersion.getAttributeValue(XMLTags.BranchPointRefTag);
KeyValue branchpointref = null;
if (temp != null) {
branchpointref = new KeyValue(temp);
}
// *BranchID
java.math.BigDecimal branchId = new java.math.BigDecimal(xmlVersion.getAttributeValue(XMLTags.BranchIdAttrTag));
// *Flag
temp = xmlVersion.getAttributeValue(XMLTags.FlagAttrTag);
VersionFlag flag = VersionFlag.fromInt(Integer.parseInt(temp));
// *Date
java.util.Date date = null;
temp = xmlVersion.getAttributeValue(XMLTags.DateAttrTag);
if (temp != null) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BeanUtils.vcDateFormat, Locale.US);
date = simpleDateFormat.parse(temp);
} catch (java.text.ParseException e) {
e.printStackTrace();
throw new XmlParseException("Invalid date:" + temp, e);
}
}
// *Annotation
String annotation = null;
String annotationText = xmlVersion.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
annotation = unMangle(annotationText);
}
// Create and return the version object
return new Version(key, name, owner, groupAccess, branchpointref, branchId, date, flag, annotation);
}
use of org.vcell.util.document.VersionFlag 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.VersionFlag 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.VersionFlag in project vcell by virtualcell.
the class ClientMDIManager method createCanonicalTitle.
/**
* Insert the method's description here.
* Creation date: (5/27/2006 4:10:10 PM)
* @return java.lang.String
* @param version cbit.sql.Version
*/
public static String createCanonicalTitle(VCDocument vcDocument) {
Version version = vcDocument.getVersion();
VCDocumentType docType = vcDocument.getDocumentType();
String docName = (version != null ? version.getName() : (vcDocument.getName() == null ? "NoName" : vcDocument.getName() + " (NoVersion)"));
java.util.Date docDate = (version != null ? version.getDate() : null);
VersionFlag versionFlag = (version != null ? version.getFlag() : null);
String title = (versionFlag != null && versionFlag.compareEqual(VersionFlag.Archived) ? "(" + CurateSpec.CURATE_TYPE_STATES[CurateSpec.ARCHIVE] + ") " : "") + (versionFlag != null && versionFlag.compareEqual(VersionFlag.Published) ? "(" + CurateSpec.CURATE_TYPE_STATES[CurateSpec.PUBLISH] + ") " : "") + (docType == VCDocumentType.BIOMODEL_DOC ? "BIOMODEL: " : "") + (docType == VCDocumentType.MATHMODEL_DOC ? "MATHMODEL: " : "") + (docType == VCDocumentType.GEOMETRY_DOC ? "GEOMETRY: " : "") + docName + " " + "(" + (docDate != null ? docDate.toString() : "NoDate") + ")";
title += " -- VCell " + DocumentWindowAboutBox.getVERSION_NO() + " (build " + DocumentWindowAboutBox.getBUILD_NO() + ")";
return title;
}
Aggregations