Search in sources :

Example 86 with User

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

the class StochtestRunService method runOne.

public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
    String biomodelXML = null;
    if (stochtestRun != null) {
        String networkGenProbs = null;
        try {
            User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
            ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
            biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
            bioModel.refreshDependencies();
            SimulationContext srcSimContext = null;
            for (SimulationContext sc : bioModel.getSimulationContexts()) {
                if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
                    srcSimContext = sc;
                }
            }
            if (srcSimContext == null) {
                throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
            }
            // 
            for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
                scs.setConstant(false);
            }
            SimulationContext simContext = srcSimContext;
            StochtestMathType parentMathType = stochtestRun.parentMathType;
            StochtestMathType mathType = stochtestRun.mathType;
            if (parentMathType != mathType) {
                if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
                } else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
                } else {
                    throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
                }
                bioModel.addSimulationContext(simContext);
            }
            MathMappingCallback mathMappingCallback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
            simContext.setMathDescription(mathDesc);
            if (simContext.isInsufficientIterations()) {
                networkGenProbs = "insufficientIterations";
            } else if (simContext.isInsufficientMaxMolecules()) {
                networkGenProbs = "insufficientMaxMolecules";
            }
            File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
            try {
                OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
                double endTime = 10.0;
                computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
                StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
            } finally {
                StochtestFileUtils.clearDir(baseDirectory);
            }
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
            // 
            if (biomodelXML != null) {
                XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
            }
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MathDescription(cbit.vcell.math.MathDescription) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) StringWriter(java.io.StringWriter) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 87 with User

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

the class TestMissingSimData method createArrayList.

private static HashMap<String, ArrayList<SimIDAndJobID>> createArrayList(ResultSet rset) throws Exception {
    int lastTaskid = -1;
    long lastSimID = -1;
    HashMap<String, ArrayList<SimIDAndJobID>> mapUserToSimJobs = new HashMap<String, ArrayList<SimIDAndJobID>>();
    while (rset.next()) {
        int jobID = rset.getInt(2);
        if (rset.wasNull()) {
            jobID = 0;
        }
        int dimension = rset.getInt(7);
        User user = new User(rset.getString(4), new KeyValue(rset.getBigDecimal(3)));
        // ;
        ArrayList<SimIDAndJobID> simIDAndJobIDs = mapUserToSimJobs.get(user.getName());
        if (simIDAndJobIDs == null) {
            simIDAndJobIDs = new ArrayList<SimIDAndJobID>();
            mapUserToSimJobs.put(user.getName(), simIDAndJobIDs);
        }
        String modelName = rset.getString("modelName");
        String appName = rset.getString("appname");
        String simName = rset.getString("simName");
        int schedulerStatus = rset.getInt("schedulerStatus");
        int taskid = rset.getInt("taskid");
        BigDecimal simID = rset.getBigDecimal(1);
        if (lastSimID != simID.longValue()) {
            lastTaskid = -1;
        }
        String hasData = rset.getString("hasdata");
        Boolean bHasData = (hasData == null ? null : hasData.toLowerCase().equals("y"));
        BigDecimal privacy = rset.getBigDecimal("privacy");
        String softwareVersion = rset.getString("softwareversion");
        Timestamp timestamp = rset.getTimestamp("versiondate");
        SimIDAndJobID simIDAndJobID = new SimIDAndJobID(new KeyValue(simID), jobID, user, dimension, modelName, appName, simName, SimulationJobStatus.SchedulerStatus.values()[schedulerStatus], bHasData, privacy, softwareVersion, timestamp);
        if (lastTaskid == taskid) {
            simIDAndJobIDs.remove(simIDAndJobIDs.size() - 1);
        }
        lastTaskid = taskid;
        simIDAndJobIDs.add(simIDAndJobID);
    }
    return mapUserToSimJobs;
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 88 with User

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

the class ServerManageConsole method resubmitSimulation.

/**
 * Insert the method's description here.
 * Creation date: (7/19/2004 3:32:52 PM)
 * @param simKey cbit.sql.KeyValue
 */
public void resubmitSimulation(String userid, KeyValue simKey) {
    try {
        User user = adminDbTop.getUser(userid, true);
        UserLoginInfo userLoginInfo = new UserLoginInfo(user.getName(), null);
        userLoginInfo.setUser(user);
        String apihost = "vcellapi.cam.uchc.edu";
        Integer apiport = 8080;
        RemoteProxyVCellConnectionFactory remoteProxyVCellConnectionFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, userLoginInfo);
        VCellConnection vcConn = remoteProxyVCellConnectionFactory.createVCellConnection();
        BigString simxml = vcConn.getUserMetaDbServer().getSimulationXML(simKey);
        if (simxml == null) {
            javax.swing.JOptionPane.showMessageDialog(this, "Simulation [" + simKey + "] doesn't exit, might have been deleted.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
        Simulation sim = XmlHelper.XMLToSim(simxml.toString());
        if (sim == null) {
            javax.swing.JOptionPane.showMessageDialog(this, "Simulation [" + simKey + "] doesn't exit, might have been deleted.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
        vcConn.getSimulationController().startSimulation(sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
    } catch (Exception ex) {
        javax.swing.JOptionPane.showMessageDialog(this, "Resubmitting simulation failed:" + ex.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) User(org.vcell.util.document.User) Simulation(cbit.vcell.solver.Simulation) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) BigString(org.vcell.util.BigString) UserCancelException(org.vcell.util.UserCancelException)

Example 89 with User

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

the class MathModelDbTreeModel method databaseInsert.

/**
 * @param event cbit.vcell.clientdb.DatabaseEvent
 */
public void databaseInsert(DatabaseEvent databaseEvent) {
    if (databaseEvent.getNewVersionInfo() instanceof MathModelInfo) {
        try {
            MathModelInfo insertedMathModelInfo = (MathModelInfo) databaseEvent.getNewVersionInfo();
            // 
            // get parent of updated version
            // 
            // model1                           (VCDocumentInfoNode)
            // Fri Sept 2, 2001 12:00:00     (MathModelInfo)
            // Fri Sept 1, 2001 10:00:00     (MathModelInfo)
            // 
            // 
            BioModelNode newVersionNode = createVersionSubTree(insertedMathModelInfo);
            // 
            // find owner node (if it is displayed)
            // 
            User owner = insertedMathModelInfo.getVersion().getOwner();
            BioModelNode ownerRoot = ((BioModelNode) getRoot()).findNodeByUserObject(owner);
            BioModelNode parentNode = null;
            if (ownerRoot != null) {
                parentNode = ownerRoot.findNodeByUserObject(new VCDocumentInfoNode(insertedMathModelInfo));
            }
            if (parentNode == null) {
                // 
                // fresh insert
                // Have to create parent node, for all versions of this mathModel,
                // and stick it in the correct order in the tree.
                // 
                parentNode = new BioModelNode(new VCDocumentInfoNode(insertedMathModelInfo), true);
                parentNode.insert(newVersionNode, 0);
                // 
                if (ownerRoot != null) {
                    // !!!!!!!!!!!!!! new insert on top (index=0) .... should do insertion sort !!!!
                    ownerRoot.insert(parentNode, 0);
                    insertNodeInto(parentNode, ownerRoot, 0);
                }
            } else {
                // 
                // already versions there (just add child in the correct position within parent)
                // 
                // !!!!!!!!!! right now ignore order !!!!!!!!!!
                parentNode.insert(newVersionNode, 0);
                insertNodeInto(newVersionNode, parentNode, 0);
            }
        } catch (DataAccessException e) {
            e.printStackTrace(System.out);
            System.out.println("exception responding to databaseInsert(), refreshing whole tree");
            refreshTree();
        }
    }
}
Also used : User(org.vcell.util.document.User) VCDocumentInfoNode(cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode) MathModelInfo(org.vcell.util.document.MathModelInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 90 with User

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

the class MathModelDbTreeModel method createBaseTree.

/**
 * Insert the method's description here.
 * Creation date: (11/28/00 1:06:51 PM)
 * @return cbit.vcell.desktop.BioModelNode
 * @param docManager cbit.vcell.clientdb.DocumentManager
 */
protected void createBaseTree() throws DataAccessException {
    VCDocumentDbTreeModel.initBaseTree(rootNode, new BioModelNode[] { myModelsNode, sharedModelsNode, publicModelsNode, educationModelsNode }, "Math Models", sharedModelsNode, SHARED_MATH_MODELS);
    MathModelInfo[] mathModelInfos = getDocumentManager().getMathModelInfos();
    User loginUser = getDocumentManager().getUser();
    TreeMap<String, BioModelNode> treeMap = null;
    try {
        treeMap = VCDocumentDbTreeModel.initOwners(mathModelInfos, loginUser, this, this.getClass().getMethod("createOwnerSubTree", new Class[] { User.class, MathModelInfo[].class }));
    } catch (Exception e) {
        e.printStackTrace();
        treeMap = new TreeMap<String, BioModelNode>();
        treeMap.put(loginUser.getName(), new BioModelNode("Error:" + e.getMessage()));
    }
    initFinalTree(this, treeMap, loginUser);
}
Also used : User(org.vcell.util.document.User) MathModelInfo(org.vcell.util.document.MathModelInfo) TreeMap(java.util.TreeMap) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

User (org.vcell.util.document.User)159 KeyValue (org.vcell.util.document.KeyValue)68 DataAccessException (org.vcell.util.DataAccessException)46 SQLException (java.sql.SQLException)31 VCellApiApplication (org.vcell.rest.VCellApiApplication)30 File (java.io.File)25 BigString (org.vcell.util.BigString)22 ArrayList (java.util.ArrayList)21 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)21 BioModel (cbit.vcell.biomodel.BioModel)20 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)20 XmlParseException (cbit.vcell.xml.XmlParseException)17 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)16 XMLSource (cbit.vcell.xml.XMLSource)15 Simulation (cbit.vcell.solver.Simulation)14 BioModelInfo (org.vcell.util.document.BioModelInfo)14 SimulationContext (cbit.vcell.mapping.SimulationContext)13 ResultSet (java.sql.ResultSet)13 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)13 BigDecimal (java.math.BigDecimal)12