Search in sources :

Example 31 with UserCancelException

use of org.vcell.util.UserCancelException in project vcell by virtualcell.

the class SEDMLChooserPanel method chooseTask.

public static AbstractTask chooseTask(SedML sedml, Component requester, String name) {
    SEDMLChooserPanel panel = new SEDMLChooserPanel(sedml);
    int oKCancel = DialogUtils.showComponentOKCancelDialog(requester, panel, "Import Sed-ML file: " + name);
    if (oKCancel == JOptionPane.CANCEL_OPTION || oKCancel == JOptionPane.DEFAULT_OPTION) {
        throw new UserCancelException("Canceling Import");
    }
    SEDMLRadioButtonModel bm = (SEDMLRadioButtonModel) panel.group.getSelection();
    AbstractTask tt = bm.getTask();
    return tt;
}
Also used : AbstractTask(org.jlibsedml.AbstractTask) UserCancelException(org.vcell.util.UserCancelException)

Example 32 with UserCancelException

use of org.vcell.util.UserCancelException in project vcell by virtualcell.

the class NetworkTransformer method generateNetwork.

private BNGOutputSpec generateNetwork(SimulationContext simContext, MathMappingCallback mathMappingCallback, NetworkGenerationRequirements networkGenerationRequirements) throws ClassNotFoundException, IOException {
    TaskCallbackMessage tcm;
    BNGOutputSpec outputSpec;
    speciesEquivalenceMap.clear();
    kineticsParameterMap.clear();
    String input = convertToBngl(simContext, true, mathMappingCallback, networkGenerationRequirements);
    for (Map.Entry<FakeSeedSpeciesInitialConditionsParameter, Pair<SpeciesContext, Expression>> entry : speciesEquivalenceMap.entrySet()) {
        FakeSeedSpeciesInitialConditionsParameter key = entry.getKey();
        Pair<SpeciesContext, Expression> value = entry.getValue();
        SpeciesContext sc = value.one;
        Expression initial = value.two;
        System.out.println("key: " + key.fakeParameterName + ",   species: " + sc.getName() + ", initial: " + initial.infix());
    }
    String md5hash = MD5.md5(input);
    if (isBngHashValid(input, md5hash, simContext)) {
        String s = "Previously saved outputSpec is up-to-date, no need to generate network.";
        System.out.println(s);
        // not an error, we just want to show it in red
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
        simContext.appendToConsole(tcm);
        if (simContext.isInsufficientIterations()) {
            s = NetworkTransformer.getInsufficientIterationsMessage();
            System.out.println(s);
            tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
            simContext.appendToConsole(tcm);
        }
        if (simContext.isInsufficientMaxMolecules()) {
            s = NetworkTransformer.getInsufficientMaxMoleculesMessage();
            System.out.println(s);
            tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s);
            simContext.appendToConsole(tcm);
        }
        outputSpec = simContext.getMostRecentlyCreatedOutputSpec();
        return (BNGOutputSpec) BeanUtils.cloneSerializable(outputSpec);
    }
    BNGInput bngInput = new BNGInput(input);
    BNGOutput bngOutput = null;
    try {
        final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, networkGenerationRequirements.timeoutDurationMS);
        bngService.registerBngUpdaterCallback(simContext);
        bngOutput = bngService.executeBNG();
    } catch (BNGException ex) {
        ex.printStackTrace(System.out);
        System.out.println("bionetgen exception");
        if (ex.getMessage().contains("was asked to write the network, but no reactions were found")) {
            RuntimeException rex = new RuntimeException("Specified species and reaction rules are not sufficient to define reaction network.");
            throw rex;
        } else {
            // rethrow without losing context
            throw ex;
        }
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.out);
        System.out.println("runtime exception");
        throw ex;
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        System.out.println("other exception");
        throw new RuntimeException(ex.getMessage());
    }
    // simContext.setInsufficientIterations(false);
    // simContext.setInsufficientMaxMolecules(false);
    String bngConsoleString = bngOutput.getConsoleOutput();
    // TODO: this message we check if insufficient iterations / max molecules
    // DO IT OUTSIDE (in the bng service), we now can
    // tcm = new TaskCallbackMessage(TaskCallbackStatus.DetailBatch, bngConsoleString);
    // simContext.appendToConsole(tcm);
    tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskEndNotificationOnly, "");
    simContext.setNewCallbackMessage(tcm);
    tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskEndAdjustSimulationContextFlagsOnly, "");
    simContext.setNewCallbackMessage(tcm);
    String bngNetString = bngOutput.getNetFileContent();
    outputSpec = BNGOutputFileParser.createBngOutputSpec(bngNetString);
    // prints all output to console
    BNGOutputFileParser.printBNGNetOutput(outputSpec);
    if (mathMappingCallback.isInterrupted()) {
        String msg = "Canceled by user.";
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, msg);
        simContext.appendToConsole(tcm);
        // clean the cache if the user interrupts
        simContext.setMd5hash(null);
        throw new UserCancelException(msg);
    }
    if (outputSpec.getBNGSpecies().length > NetworkTransformer.speciesLimit) {
        String message = NetworkTransformer.getSpeciesLimitExceededMessage(outputSpec);
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, message);
        simContext.appendToConsole(tcm);
        simContext.setMd5hash(null);
        message = "Unable to generate Math for Application " + simContext.getName() + ".\n" + message;
        throw new RuntimeException(message);
    }
    if (outputSpec.getBNGReactions().length > NetworkTransformer.reactionsLimit) {
        String message = NetworkTransformer.getReactionsLimitExceededMessage(outputSpec);
        tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, message);
        simContext.appendToConsole(tcm);
        simContext.setMd5hash(null);
        message = "Unable to generate Math for Application " + simContext.getName() + ".\n" + message;
        throw new RuntimeException(message);
    }
    // System.out.println("old hash: " + simContext.getMd5hash());
    if (md5hash != null && md5hash.length() != 0 && outputSpec != null) {
        System.out.println("saving hash and output spec");
        synchronized (this) {
            simContext.setMd5hash(md5hash);
            simContext.setMostRecentlyCreatedOutputSpec(outputSpec);
        }
    } else {
        System.out.println("something is wrong with the hash and/or output spec");
    }
    return (BNGOutputSpec) BeanUtils.cloneSerializable(outputSpec);
}
Also used : UserCancelException(org.vcell.util.UserCancelException) SpeciesContext(cbit.vcell.model.SpeciesContext) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) BNGOutput(cbit.vcell.server.bionetgen.BNGOutput) FakeSeedSpeciesInitialConditionsParameter(org.vcell.model.rbm.FakeSeedSpeciesInitialConditionsParameter) BNGOutputSpec(cbit.vcell.bionetgen.BNGOutputSpec) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ParseException(org.vcell.model.bngl.ParseException) BNGException(cbit.vcell.server.bionetgen.BNGException) ModelException(cbit.vcell.model.ModelException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) BNGException(cbit.vcell.server.bionetgen.BNGException) Expression(cbit.vcell.parser.Expression) BNGInput(cbit.vcell.server.bionetgen.BNGInput) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(org.vcell.util.Pair)

Example 33 with UserCancelException

use of org.vcell.util.UserCancelException in project vcell by virtualcell.

the class ClientRequestManager method getISizeFromUser.

public static ISize getISizeFromUser(Component guiParent, ISize initISize, String textMessage) throws UserCancelException {
    Integer imageDimension = (initISize == null ? null : (initISize.getX() != 1 ? 1 : 0) + (initISize.getY() != 1 ? 1 : 0) + (initISize.getZ() != 1 ? 1 : 0));
    if (imageDimension != null && (imageDimension < 1 || imageDimension > 3)) {
        throw new IllegalArgumentException("Dimension must be 1, 2 or 3.");
    }
    try {
        int xsize = (imageDimension == null ? -1 : initISize.getX());
        int ysize = (imageDimension == null ? -1 : initISize.getY());
        int zsize = (imageDimension == null ? -1 : initISize.getZ());
        do {
            String result = (imageDimension == null ? "256,256,8" : xsize + "," + ysize + "," + zsize);
            result = DialogUtils.showInputDialog0(guiParent, textMessage, result);
            String tempResult = result;
            try {
                if (result == null || result.length() == 0) {
                    result = "";
                    throw new Exception("No size values entered.");
                }
                xsize = Integer.parseInt(tempResult.substring(0, tempResult.indexOf(",")));
                tempResult = tempResult.substring(tempResult.indexOf(",") + 1, tempResult.length());
                ysize = Integer.parseInt(tempResult.substring(0, tempResult.indexOf(",")));
                tempResult = tempResult.substring(tempResult.indexOf(",") + 1, tempResult.length());
                zsize = Integer.parseInt(tempResult);
                if (imageDimension != null) {
                    if (imageDimension == 2 && zsize != 1) {
                        throw new Exception("Dimension " + imageDimension + " must have z = 1.");
                    } else if (imageDimension == 1 && zsize != 1 && ysize != 1) {
                        throw new Exception("Dimension " + imageDimension + " must have z = 1 and y = 1.");
                    }
                }
                ISize isize = new ISize(xsize, ysize, zsize);
                if (isize.getXYZ() <= 0) {
                    throw new Exception("Total pixels (" + xsize + "*" + ysize + "*" + zsize + ") cannot be <=0.");
                }
                return isize;
            } catch (Exception e) {
                DialogUtils.showErrorDialog(guiParent, "Error entering starting sizes\n" + e.getMessage(), e);
            }
        } while (true);
    } catch (UtilCancelException e2) {
        throw UserCancelException.CANCEL_GENERIC;
    }
}
Also used : UtilCancelException(org.vcell.util.UtilCancelException) ISize(org.vcell.util.ISize) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException)

Example 34 with UserCancelException

use of org.vcell.util.UserCancelException in project vcell by virtualcell.

the class TestingFrameworkWindowManager method generateTestCaseReport.

/**
 * Insert the method's description here.
 * Creation date: (8/18/2003 5:36:47 PM)
 */
public String generateTestCaseReport(TestCaseNew testCase, TestCriteriaNew onlyThisTCrit, ClientTaskStatusSupport pp, TFGenerateReport.VCDocumentAndSimInfo userDefinedRefSimInfo) {
    StringBuffer reportTCBuffer = new StringBuffer();
    if (testCase == null) {
        reportTCBuffer.append("\n\tTEST CASE :\tERROR: Test Case is NULL\n");
    } else {
        pp.setMessage(testCase.getVersion().getName() + " " + testCase.getType() + " Getting Simulations");
        // Get the Simulations
        Simulation[] sims = null;
        reportTCBuffer.append("\n\tTEST CASE : " + (testCase.getVersion() != null ? testCase.getVersion().getName() : "Null") + "\n\tAnnotation : " + testCase.getAnnotation() + "\n");
        try {
            if (testCase instanceof TestCaseNewMathModel) {
                MathModelInfo mmInfo = ((TestCaseNewMathModel) testCase).getMathModelInfo();
                MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mmInfo);
                sims = mathModel.getSimulations();
                reportTCBuffer.append("\tMathModel : " + mmInfo.getVersion().getName() + ", " + mmInfo.getVersion().getDate().toString() + "\n");
            } else if (testCase instanceof TestCaseNewBioModel) {
                TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
                // bioTestCase.
                BioModelInfo bmInfo = bioTestCase.getBioModelInfo();
                BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bmInfo);
                SimulationContext[] simContextArr = bioModel.getSimulationContexts();
                if (simContextArr != null && simContextArr.length > 0) {
                    SimulationContext simContext = null;
                    for (int i = 0; i < simContextArr.length; i += 1) {
                        if (simContextArr[i].getVersion().getVersionKey().compareEqual(bioTestCase.getSimContextKey())) {
                            simContext = simContextArr[i];
                            break;
                        }
                    }
                    if (simContext != null) {
                        sims = bioModel.getSimulations(simContext);
                        reportTCBuffer.append("\tBioModel : " + bmInfo.getVersion().getName() + ", " + bmInfo.getVersion().getDate().toString() + "\n");
                    }
                }
            }
            if (sims == null || sims.length == 0) {
                reportTCBuffer.append("\tERROR " + "No sims found for TestCase " + (testCase.getVersion() != null ? "name=" + testCase.getVersion().getName() : "key=" + testCase.getTCKey()) + "\n");
            }
            if (testCase.getTestCriterias() == null || sims.length != testCase.getTestCriterias().length) {
                reportTCBuffer.append("\tNote " + "Num sims=" + sims.length + " does not match testCriteria length=" + (testCase.getTestCriterias() != null ? testCase.getTestCriterias().length + "" : "null") + " for TestCase " + (testCase.getVersion() != null ? "name=" + testCase.getVersion().getName() : "key=" + testCase.getTCKey()) + "\n");
            }
            // Sort
            if (sims.length > 0) {
                java.util.Arrays.sort(sims, new java.util.Comparator<Simulation>() {

                    public int compare(Simulation si1, Simulation si2) {
                        return si1.getName().compareTo(si2.getName());
                    }

                    public boolean equals(Object obj) {
                        return false;
                    }
                });
            }
            TestCriteriaNew[] testCriterias = (onlyThisTCrit != null ? new TestCriteriaNew[] { onlyThisTCrit } : testCase.getTestCriterias());
            for (int k = 0; k < sims.length; k++) {
                TestCriteriaNew testCriteria = getMatchingTestCriteria(sims[k], testCriterias);
                if (testCriteria != null) {
                    pp.setMessage((testCase instanceof TestCaseNewMathModel ? "(MM)" : "(BM)") + " " + (onlyThisTCrit == null ? "sim " + (k + 1) + " of " + sims.length : "sim=" + onlyThisTCrit.getSimInfo().getName()) + "  " + testCase.getVersion().getName() + " " + testCase.getType());
                    reportTCBuffer.append(generateTestCriteriaReport(testCase, testCriteria, sims[k], userDefinedRefSimInfo));
                }
            }
        } catch (UserCancelException e) {
            throw e;
        } catch (Throwable e) {
            e.printStackTrace();
            reportTCBuffer.append("\tERROR " + e.getClass().getName() + " mesg=" + e.getMessage() + "\n");
            try {
                if (onlyThisTCrit != null) {
                    updateTCritStatus(onlyThisTCrit, TestCriteriaNew.TCRIT_STATUS_RPERROR, "TestCase Error " + e.getClass().getName() + " " + e.getMessage());
                } else if (testCase.getTestCriterias() != null) {
                    for (int i = 0; i < testCase.getTestCriterias().length; i += 1) {
                        updateTCritStatus(testCase.getTestCriterias()[i], TestCriteriaNew.TCRIT_STATUS_RPERROR, "TestCase Error " + e.getClass().getName() + " " + e.getMessage());
                    }
                }
            } catch (Throwable e2) {
            // 
            }
        }
    }
    return reportTCBuffer.toString();
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) AddTestCasesOPMathModel(cbit.vcell.numericstest.AddTestCasesOPMathModel) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) EditTestCriteriaOPMathModel(cbit.vcell.numericstest.EditTestCriteriaOPMathModel) AddTestCriteriaOPMathModel(cbit.vcell.numericstest.AddTestCriteriaOPMathModel) BioModelInfo(org.vcell.util.document.BioModelInfo) UserCancelException(org.vcell.util.UserCancelException) MathModelInfo(org.vcell.util.document.MathModelInfo) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) SimulationContext(cbit.vcell.mapping.SimulationContext) Simulation(cbit.vcell.solver.Simulation) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) AddTestCasesOPBioModel(cbit.vcell.numericstest.AddTestCasesOPBioModel) BioModel(cbit.vcell.biomodel.BioModel) EditTestCriteriaOPBioModel(cbit.vcell.numericstest.EditTestCriteriaOPBioModel) AddTestCriteriaOPBioModel(cbit.vcell.numericstest.AddTestCriteriaOPBioModel) TestCriteriaNew(cbit.vcell.numericstest.TestCriteriaNew) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel)

Example 35 with UserCancelException

use of org.vcell.util.UserCancelException in project vcell by virtualcell.

the class TestingFrameworkWindowManager method generateTestSuiteReport.

/**
 * Insert the method's description here.
 * Creation date: (8/18/2003 5:36:47 PM)
 */
public String generateTestSuiteReport(TestSuiteInfoNew testSuiteInfo, ClientTaskStatusSupport pp) {
    if (testSuiteInfo == null) {
        return "Test Suite is null";
    }
    StringBuffer sb = new StringBuffer();
    try {
        // Iterate thro' testSuiteInfo to add annotation to reportTSBuffer and get all test cases
        // Get TestSuite corresponding to argument testSuiteInfo
        TestSuiteNew testSuite = getRequestManager().getDocumentManager().getTestSuite(testSuiteInfo.getTSKey());
        // Get MathmodelInfos associated with each test suite
        TestCaseNew[] testCases = null;
        testCases = testSuite.getTestCases();
        if (testCases == null) {
            return testSuiteInfo.toString() + " has not testcases";
        }
        // Iterate thro' test cases to get all simulations and get the variableSimulationSummary, add to buffer
        sb.append("\n" + testSuiteInfo.toString() + "\n");
        for (int j = 0; j < testCases.length; j++) {
            pp.setProgress(1 + (int) ((((double) j / (double) testCases.length) * 100)));
            sb.append(generateTestCaseReport(testCases[j], null, pp, null));
        }
    } catch (UserCancelException e) {
        throw e;
    } catch (Throwable e) {
        e.printStackTrace();
        sb.append("ERROR " + e.getClass().getName() + " mesg=" + e.getMessage());
    }
    return sb.toString();
}
Also used : TestSuiteNew(cbit.vcell.numericstest.TestSuiteNew) UserCancelException(org.vcell.util.UserCancelException) TestCaseNew(cbit.vcell.numericstest.TestCaseNew)

Aggregations

UserCancelException (org.vcell.util.UserCancelException)44 Hashtable (java.util.Hashtable)15 UtilCancelException (org.vcell.util.UtilCancelException)15 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)14 PropertyVetoException (java.beans.PropertyVetoException)11 DataAccessException (org.vcell.util.DataAccessException)10 Vector (java.util.Vector)9 ActionEvent (java.awt.event.ActionEvent)8 DataFormatException (java.util.zip.DataFormatException)8 BioModel (cbit.vcell.biomodel.BioModel)7 ActionListener (java.awt.event.ActionListener)7 IOException (java.io.IOException)7 Point (java.awt.Point)6 ArrayList (java.util.ArrayList)6 ImageException (cbit.image.ImageException)5 CSGObject (cbit.vcell.geometry.CSGObject)5 GeometryException (cbit.vcell.geometry.GeometryException)5 Structure (cbit.vcell.model.Structure)5 JButton (javax.swing.JButton)5 ProgrammingException (org.vcell.util.ProgrammingException)5