Search in sources :

Example 6 with VCellSoftwareVersion

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

the class XmlHelper method XMLToBioModel.

static BioModel XMLToBioModel(XMLSource xmlSource, boolean printkeys, ModelUnitSystem forcedModelUnitSystem) throws XmlParseException {
    // long l0 = System.currentTimeMillis();
    BioModel bioModel = null;
    if (xmlSource == null) {
        throw new XmlParseException("Invalid xml for Biomodel.");
    }
    Document xmlDoc = xmlSource.getXmlDoc();
    // NOTES:
    // * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
    // * With the old-style vcml, the namespace was " "
    // * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
    // was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
    // "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
    // <biomdel>, etc. was " "
    // * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
    // for <vcml> and all children elements.
    // The code below attempts to take care of this situation.
    Element root = xmlDoc.getRootElement();
    Namespace ns = null;
    if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
        // NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
        ns = root.getNamespace();
        Element bioRoot = root.getChild(XMLTags.BioModelTag, ns);
        if (bioRoot == null) {
            bioRoot = root.getChild(XMLTags.BioModelTag);
            // bioRoot was null, so obtained the <Biomodel> element with namespace " ";
            // Re-set the namespace so that the correct XMLReader constructor is invoked.
            ns = null;
        }
        root = bioRoot;
    }
    // else - root is assumed to be old-style vcml with <Biomodel> as root.
    // common for both new way (with xml declaration, vcml element, etc) and existing way (biomodel is root)
    // If namespace is null, xml is the old-style xml with biomodel as root, so invoke XMLReader without namespace argument.
    XmlReader reader = null;
    VCellSoftwareVersion vCellSoftwareVersion = null;
    if (ns == null) {
        reader = new XmlReader(printkeys);
    } else {
        reader = new XmlReader(printkeys, ns);
        vCellSoftwareVersion = VCellSoftwareVersion.fromString(root.getAttributeValue(XMLTags.SoftwareVersionAttrTag, ns));
    }
    if (forcedModelUnitSystem != null) {
        reader.setForcedModelUnitSystem(forcedModelUnitSystem);
    }
    bioModel = reader.getBioModel(root, vCellSoftwareVersion);
    // long l1 = System.currentTimeMillis();
    bioModel.refreshDependencies();
    return bioModel;
}
Also used : VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) BioModel(cbit.vcell.biomodel.BioModel) Element(org.jdom.Element) Document(org.jdom.Document) VCDocument(org.vcell.util.document.VCDocument) Namespace(org.jdom.Namespace)

Example 7 with VCellSoftwareVersion

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

the class VisitorAdapter method filterBioModel.

/**
 * return true if major version >= {@link #minimumModelVersion()}
 * @param bioModelInfo not null
 */
public boolean filterBioModel(BioModelInfo bioModelInfo) {
    VCellSoftwareVersion sv = bioModelInfo.getSoftwareVersion();
    final boolean recentEnough = (sv.getMajorVersion() >= minimumModelVersion());
    if (!recentEnough && lg.isEnabledFor(level)) {
        lg.log(level, "skipping old (v" + sv.getMajorVersion() + ")" + bioModelInfo.toString());
    }
    return recentEnough;
}
Also used : VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion)

Example 8 with VCellSoftwareVersion

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

the class ModelDbDriver method getDiagramsFromModel.

/**
 * getModels method comment.
 */
private cbit.vcell.model.Diagram[] getDiagramsFromModel(QueryHashtable dbc, Connection con, KeyValue modelKey, StructureTopology structureTopology, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
    // log.print("ModelDbDriver.getDiagramsFromModel(modelKey=" + modelKey + ")");
    String sql;
    switch(dbSyntax) {
        case ORACLE:
            {
                sql = " SELECT *" + " FROM " + diagramTable.getTableName() + "," + SoftwareVersionTable.table.getTableName() + " WHERE " + diagramTable.modelRef + " = " + modelKey + " AND " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() + "(+)" + " ORDER BY " + diagramTable.id.getQualifiedColName();
                break;
            }
        case POSTGRES:
            {
                sql = " SELECT *" + " FROM " + diagramTable.getTableName() + " LEFT OUTER JOIN " + SoftwareVersionTable.table.getTableName() + " ON " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() + " WHERE " + diagramTable.modelRef + " = " + modelKey + // " AND " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() +"(+)" +
                " ORDER BY " + diagramTable.id.getQualifiedColName();
                break;
            }
        default:
            {
                throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
            }
    }
    Statement stmt = con.createStatement();
    Vector<Diagram> diagramList = new Vector<Diagram>();
    String softwareVersion = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        // 
        while (rset.next()) {
            Diagram diagram = getDiagram(dbc, con, rset, structureTopology);
            diagramList.addElement(diagram);
            softwareVersion = rset.getString(SoftwareVersionTable.table.softwareVersion.getUnqualifiedColName());
            if (rset.wasNull()) {
                softwareVersion = null;
            }
        }
    } finally {
        // Release resources include resultset
        stmt.close();
    }
    // 
    // put results in an array
    // 
    Diagram[] diagramArray = new Diagram[diagramList.size()];
    diagramList.copyInto(diagramArray);
    VCellSoftwareVersion vCellSoftwareVersion = VCellSoftwareVersion.fromString(softwareVersion);
    XmlReader.reorderDiagramsInPlace_UponRead(vCellSoftwareVersion, diagramArray, structureTopology);
    // //----------------------------------------
    return diagramArray;
}
Also used : VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) Diagram(cbit.vcell.model.Diagram)

Aggregations

VCellSoftwareVersion (org.vcell.util.document.VCellSoftwareVersion)8 Element (org.jdom.Element)3 BioModel (cbit.vcell.biomodel.BioModel)2 Version (org.vcell.util.document.Version)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathModel (cbit.vcell.mathmodel.MathModel)1 Diagram (cbit.vcell.model.Diagram)1 Model (cbit.vcell.model.Model)1 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)1 PropertyVetoException (java.beans.PropertyVetoException)1 BigDecimal (java.math.BigDecimal)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Vector (java.util.Vector)1 Document (org.jdom.Document)1 Namespace (org.jdom.Namespace)1 ProfileDataElement (org.vcell.optimization.ProfileDataElement)1 PathwayModel (org.vcell.pathway.PathwayModel)1 PathwayReaderBiopax3 (org.vcell.pathway.persistence.PathwayReaderBiopax3)1 RDFXMLContext (org.vcell.pathway.persistence.RDFXMLContext)1