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;
}
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);
}
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;
}
}
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();
}
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();
}
Aggregations