Search in sources :

Example 1 with VersionFlag

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);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Element(org.jdom.Element) VersionFlag(org.vcell.util.document.VersionFlag) SimulationVersion(org.vcell.util.document.SimulationVersion) SpeciesContext(cbit.vcell.model.SpeciesContext) DataContext(cbit.vcell.data.DataContext) ReactionContext(cbit.vcell.mapping.ReactionContext) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) SimulationContext(cbit.vcell.mapping.SimulationContext) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) ParameterContext(cbit.vcell.mapping.ParameterContext) GroupAccess(org.vcell.util.document.GroupAccess) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with VersionFlag

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);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Element(org.jdom.Element) VersionFlag(org.vcell.util.document.VersionFlag) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) SpeciesContext(cbit.vcell.model.SpeciesContext) DataContext(cbit.vcell.data.DataContext) ReactionContext(cbit.vcell.mapping.ReactionContext) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) SimulationContext(cbit.vcell.mapping.SimulationContext) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) ParameterContext(cbit.vcell.mapping.ParameterContext) GroupAccess(org.vcell.util.document.GroupAccess) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with VersionFlag

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;
}
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 4 with VersionFlag

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);
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VersionableType(org.vcell.util.document.VersionableType) GroupAccessNone(org.vcell.util.document.GroupAccessNone) BigDecimal(java.math.BigDecimal) VersionFlag(org.vcell.util.document.VersionFlag) Version(org.vcell.util.document.Version) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) GroupAccess(org.vcell.util.document.GroupAccess) DataAccessException(org.vcell.util.DataAccessException)

Example 5 with VersionFlag

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;
}
Also used : VersionFlag(org.vcell.util.document.VersionFlag) Version(org.vcell.util.document.Version) VCDocumentType(org.vcell.util.document.VCDocument.VCDocumentType)

Aggregations

VersionFlag (org.vcell.util.document.VersionFlag)7 KeyValue (org.vcell.util.document.KeyValue)6 Version (org.vcell.util.document.Version)6 User (org.vcell.util.document.User)5 DataAccessException (org.vcell.util.DataAccessException)4 GroupAccess (org.vcell.util.document.GroupAccess)4 SimulationVersion (org.vcell.util.document.SimulationVersion)3 VersionableTypeVersion (org.vcell.util.document.VersionableTypeVersion)3 DataContext (cbit.vcell.data.DataContext)2 ParameterContext (cbit.vcell.mapping.ParameterContext)2 ReactionContext (cbit.vcell.mapping.ReactionContext)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 OutputFunctionContext (cbit.vcell.solver.OutputFunctionContext)2 BigDecimal (java.math.BigDecimal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Element (org.jdom.Element)2 RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)2 PermissionException (org.vcell.util.PermissionException)2 VersionableType (org.vcell.util.document.VersionableType)2