Search in sources :

Example 1 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DatabaseWindowManager method accessPermissions.

/**
 * Insert the method's description here.
 * Creation date: (5/14/2004 5:35:55 PM)
 */
public void accessPermissions(final Component requester, final VersionInfo selectedVersionInfo) {
    final GroupAccess groupAccess = selectedVersionInfo.getVersion().getGroupAccess();
    final DocumentManager docManager = getRequestManager().getDocumentManager();
    AsynchClientTask task1 = new AsynchClientTask("show dialog", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            getAclEditor().clearACLList();
            getAclEditor().setACLState(new ACLEditor.ACLState(groupAccess));
            Object choice = showAccessPermissionDialog(getAclEditor(), requester);
            if (choice != null) {
                hashTable.put("choice", choice);
            }
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("access permission", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Object choice = hashTable.get("choice");
            if (choice != null && choice.equals("OK")) {
                ACLEditor.ACLState aclState = getAclEditor().getACLState();
                if (aclState != null) {
                    if (aclState.isAccessPrivate() || (aclState.getAccessList() != null && aclState.getAccessList().length == 0)) {
                        VersionInfo vInfo = null;
                        if (selectedVersionInfo instanceof BioModelInfo) {
                            vInfo = docManager.setGroupPrivate((BioModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof MathModelInfo) {
                            vInfo = docManager.setGroupPrivate((MathModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof GeometryInfo) {
                            vInfo = docManager.setGroupPrivate((GeometryInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof VCImageInfo) {
                            vInfo = docManager.setGroupPrivate((VCImageInfo) selectedVersionInfo);
                        }
                    } else if (aclState.isAccessPublic()) {
                        VersionInfo vInfo = null;
                        if (selectedVersionInfo instanceof BioModelInfo) {
                            vInfo = docManager.setGroupPublic((BioModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof MathModelInfo) {
                            vInfo = docManager.setGroupPublic((MathModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof GeometryInfo) {
                            vInfo = docManager.setGroupPublic((GeometryInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof VCImageInfo) {
                            vInfo = docManager.setGroupPublic((VCImageInfo) selectedVersionInfo);
                        }
                    } else {
                        String[] aclUserNames = aclState.getAccessList();
                        String[] originalGroupAccesNames = new String[0];
                        // Turn User[] into String[]
                        if (groupAccess instanceof GroupAccessSome) {
                            GroupAccessSome gas = (GroupAccessSome) groupAccess;
                            User[] originalUsers = gas.getNormalGroupMembers();
                            for (int i = 0; i < originalUsers.length; i += 1) {
                                originalGroupAccesNames = (String[]) BeanUtils.addElement(originalGroupAccesNames, originalUsers[i].getName());
                            }
                        }
                        // Determine users needing adding
                        String[] needToAddUsers = new String[0];
                        for (int i = 0; i < aclUserNames.length; i += 1) {
                            if (!BeanUtils.arrayContains(originalGroupAccesNames, aclUserNames[i])) {
                                System.out.println("Added user=" + aclUserNames[i]);
                                needToAddUsers = (String[]) BeanUtils.addElement(needToAddUsers, aclUserNames[i]);
                            }
                        }
                        // Determine users needing removing
                        String[] needToRemoveUsers = new String[0];
                        for (int i = 0; i < originalGroupAccesNames.length; i += 1) {
                            if (!BeanUtils.arrayContains(aclUserNames, originalGroupAccesNames[i])) {
                                System.out.println("Removed user=" + originalGroupAccesNames[i]);
                                needToRemoveUsers = (String[]) BeanUtils.addElement(needToRemoveUsers, originalGroupAccesNames[i]);
                            }
                        }
                        VersionInfo vInfo = null;
                        String errorNames = "";
                        // Add Users to Group Access List
                        for (int i = 0; i < needToAddUsers.length; i++) {
                            try {
                                if (selectedVersionInfo instanceof BioModelInfo) {
                                    vInfo = docManager.addUserToGroup((BioModelInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof MathModelInfo) {
                                    vInfo = docManager.addUserToGroup((MathModelInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof GeometryInfo) {
                                    vInfo = docManager.addUserToGroup((GeometryInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof VCImageInfo) {
                                    vInfo = docManager.addUserToGroup((VCImageInfo) selectedVersionInfo, needToAddUsers[i]);
                                }
                            } catch (ObjectNotFoundException e) {
                                errorNames += "Error changing permissions.\n" + selectedVersionInfo.getVersionType().getTypeName() + " \"" + selectedVersionInfo.getVersion().getName() + "\" edition (" + selectedVersionInfo.getVersion().getDate() + ")\nnot found, " + "your model list may be out of date, please go to menu Server->Reconnect to refresh the model list" + "\n";
                                break;
                            } catch (DataAccessException e) {
                                errorNames += "Error adding user '" + needToAddUsers[i] + "' : " + e.getMessage() + "\n";
                            }
                        }
                        // Remove users from Group Access List
                        for (int i = 0; i < needToRemoveUsers.length; i++) {
                            try {
                                if (selectedVersionInfo instanceof BioModelInfo) {
                                    vInfo = docManager.removeUserFromGroup((BioModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof MathModelInfo) {
                                    vInfo = docManager.removeUserFromGroup((MathModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof GeometryInfo) {
                                    vInfo = docManager.removeUserFromGroup((GeometryInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof VCImageInfo) {
                                    vInfo = docManager.removeUserFromGroup((VCImageInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                }
                            } catch (DataAccessException e) {
                                errorNames += "Error Removing user '" + needToRemoveUsers[i] + "'\n  -----" + e.getMessage() + "\n";
                            }
                        }
                        if (errorNames.length() > 0) {
                            if (DatabaseWindowManager.this.getComponent() != null) {
                                PopupGenerator.showErrorDialog(DatabaseWindowManager.this, errorNames);
                            } else {
                                DialogUtils.showErrorDialog(requester, errorNames);
                            }
                            accessPermissions(requester, selectedVersionInfo);
                        }
                    }
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(requester, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) ACLEditor(cbit.vcell.client.desktop.ACLEditor) VersionInfo(org.vcell.util.document.VersionInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) GeometryInfo(cbit.vcell.geometry.GeometryInfo) GroupAccessSome(org.vcell.util.document.GroupAccessSome) GroupAccess(org.vcell.util.document.GroupAccess) VCImageInfo(cbit.image.VCImageInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 2 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DBReactionWizardPanel method searchUserReactions.

/**
 * Insert the method's description here.
 * Creation date: (7/12/2003 2:45:44 PM)
 */
private void searchUserReactions(final ReactionQuerySpec reactionQuerySpec) {
    if (getDocumentManager() != null) {
        final DocumentManager docManager = getDocumentManager();
        final JList jlist = getReactionsJList();
        // 
        final String RXSTRING_VALUE_KEY = "rxString";
        // 
        AsynchClientTask searchReactions = new AsynchClientTask("searching reactions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                try {
                    mapRXStringtoRXIDs.clear();
                    // 
                    ReactionDescription[] dbrd = docManager.getUserReactionDescriptions(reactionQuerySpec);
                    // 
                    if (dbrd != null && !(getStructure() instanceof Membrane)) {
                        Vector<ReactionDescription> noflux = new Vector<ReactionDescription>();
                        for (int i = 0; i < dbrd.length; i += 1) {
                            if (!dbrd[i].isFluxReaction()) {
                                noflux.add(dbrd[i]);
                            }
                        }
                        if (noflux.size() > 0) {
                            dbrd = new ReactionDescription[noflux.size()];
                            noflux.copyInto(dbrd);
                        }
                    }
                    // 
                    String[] dbrdS = null;
                    if (dbrd != null) {
                        // if(mapRXStringtoRXIDs == null){mapRXStringtoRXIDs = new java.util.Hashtable();}
                        for (int i = 0; i < dbrd.length; i += 1) {
                            String rxString = dbrd[i].toString();
                            if (!mapRXStringtoRXIDs.containsKey(rxString)) {
                                mapRXStringtoRXIDs.put(rxString, new Vector<String>());
                            }
                            mapRXStringtoRXIDs.get(rxString).add(dbrd[i].getVCellRXID().toString());
                            mapRXIDtoBMIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellBioModelID());
                            mapRXIDtoStructRefIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellStructRef());
                        }
                        dbrdS = (String[]) mapRXStringtoRXIDs.keySet().toArray(new String[0]);
                    }
                    // 
                    if (dbrd != null && dbrd.length > 0) {
                        hash.put(RXSTRING_VALUE_KEY, dbrdS);
                    }
                } catch (DataAccessException e) {
                    PopupGenerator.showErrorDialog(DBReactionWizardPanel.this, e.getMessage());
                }
            }
        };
        // 
        AsynchClientTask updateRXList = new AsynchClientTask("updateRXList", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                String[] dbrdS = (String[]) hash.get(RXSTRING_VALUE_KEY);
                if (dbrdS != null) {
                    jlist.setListData(dbrdS);
                } else {
                    jlist.setListData(new String[0]);
                }
                afterSearchConfigure();
            }
        };
        // 
        Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
        ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXList }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) Membrane(cbit.vcell.model.Membrane) ReactionDescription(cbit.vcell.model.ReactionDescription) Vector(java.util.Vector) JList(javax.swing.JList) DataAccessException(org.vcell.util.DataAccessException)

Example 3 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DBReactionWizardPanel method search.

/**
 * Comment
 */
private void search() {
    if (getDocumentManager() != null) {
        String textSearchS = getFindTextJTextField().getText();
        if (textSearchS != null && textSearchS.length() == 0) {
            textSearchS = null;
        }
        final ReactionQuerySpec reactionQuerySpec = new ReactionQuerySpec((getFindRXTextRadioButton().isSelected() ? formatLikeString(textSearchS) : null), (getKeggMoleculeJRadioButton().isSelected() ? getCurrentDBFormalSpecies() : null));
        if (getSearchUserJRadioButton().isSelected()) {
            searchUserReactions(reactionQuerySpec);
            return;
        }
        final DocumentManager docManager = getDocumentManager();
        final javax.swing.JList jlist = getReactionsJList();
        // 
        final String RXDESC_VALUE_KEY = "rxDesc";
        AsynchClientTask searchReactions = new AsynchClientTask("searching reactions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) throws DataAccessException {
                ReactionDescription[] dbfr = docManager.getDictionaryReactions(reactionQuerySpec);
                if (dbfr != null && dbfr.length > 0) {
                    hash.put(RXDESC_VALUE_KEY, dbfr);
                }
            }
        };
        // 
        AsynchClientTask updateRXList = new AsynchClientTask("updateRXList", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                ReactionDescription[] dbfr = (ReactionDescription[]) hash.get(RXDESC_VALUE_KEY);
                if (dbfr != null) {
                    jlist.setListData(dbfr);
                } else {
                    jlist.setListData(new ReactionDescription[0]);
                }
                afterSearchConfigure();
            }
        };
        // 
        Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
        ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXList }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) JList(javax.swing.JList) ReactionQuerySpec(cbit.vcell.model.ReactionQuerySpec) ReactionDescription(cbit.vcell.model.ReactionDescription)

Example 4 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class TestingFrameworkPanel method setdocumentManager1.

/**
 * Set the documentManager1 to a new value.
 * @param newValue cbit.vcell.clientdb.DocumentManager
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setdocumentManager1(DocumentManager newValue) {
    if (ivjdocumentManager1 != newValue) {
        try {
            DocumentManager oldValue = getdocumentManager1();
            ivjdocumentManager1 = newValue;
            if (oldValue != null) {
                oldValue.removeDatabaseListener(ivjEventHandler);
            }
            if (ivjdocumentManager1 != null) {
                ivjdocumentManager1.addDatabaseListener(ivjEventHandler);
            }
            connPtoP2SetSource();
            connEtoM1(ivjdocumentManager1);
            firePropertyChange(CommonTask.DOCUMENT_MANAGER.name, oldValue, newValue);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    ;
// user code begin {3}
// user code end
}
Also used : DocumentManager(cbit.vcell.clientdb.DocumentManager)

Example 5 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class ExportDocument method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    VCDocument documentToExport = (VCDocument) hashTable.get("documentToExport");
    File exportFile = fetch(hashTable, EXPORT_FILE, File.class, true);
    ExtensionFilter fileFilter = fetch(hashTable, FILE_FILTER, ExtensionFilter.class, true);
    DocumentManager documentManager = fetch(hashTable, DocumentManager.IDENT, DocumentManager.class, true);
    String resultString = null;
    FileCloseHelper closeThis = null;
    try {
        if (documentToExport instanceof BioModel) {
            if (!(fileFilter instanceof SelectorExtensionFilter)) {
                throw new Exception("Expecting fileFilter type " + SelectorExtensionFilter.class.getName() + " but got " + fileFilter.getClass().getName());
            }
            BioModel bioModel = (BioModel) documentToExport;
            SimulationContext chosenSimContext = fetch(hashTable, SIM_CONTEXT, SimulationContext.class, false);
            ((SelectorExtensionFilter) fileFilter).writeBioModel(documentManager, bioModel, exportFile, chosenSimContext);
        /*		DELETE this after finishing validation testing
			
			// check format requested
			if (fileFilter.getDescription().equals(FileFilters.FILE_FILTER_MATLABV6.getDescription())){
				// matlab from application; get application
		
				SimulationContext chosenSimContext = fetch(hashTable,SIM_CONTEXT,SimulationContext.class, true);
				// regenerate a fresh MathDescription
				MathMapping mathMapping = chosenSimContext.createNewMathMapping();
				MathDescription mathDesc = mathMapping.getMathDescription();
				if(mathDesc != null && !mathDesc.isSpatial() && !mathDesc.isNonSpatialStoch()){
					// do export
					resultString = exportMatlab(exportFile, fileFilter, mathDesc);
				}else{
					throw new Exception("Matlab export failed: NOT an non-spatial deterministic application!");
				}
			} else if (fileFilter.equals(FileFilters.FILE_FILTER_PDF)) {   
				FileOutputStream fos = null;
				try {
					fos = new FileOutputStream(exportFile);
					documentManager.generatePDF(bioModel, fos);				
				} finally {
					if(fos != null) {
						fos.close();					
					}
				}
				return; 									//will take care of writing to the file as well.
			}
			//Export a simulation to Smoldyn input file, if there are parameter scans
			//in simulation, we'll export multiple Smoldyn input files.
			else if (fileFilter.equals(FileFilters.FILE_FILTER_SMOLDYN_INPUT)) 
			{ 
				Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
				if (selectedSim != null) {
					int scanCount = selectedSim.getScanCount();
					if(scanCount > 1) // has parameter scan
					{
						String baseExportFileName = exportFile.getPath().substring(0, exportFile.getPath().indexOf("."));
						for(int i=0; i<scanCount; i++)
						{
							SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, i, null),0);
							// Need to export each parameter scan into a separate file
							String newExportFileName = baseExportFileName + "_" + i + SMOLDYN_INPUT_FILE_EXTENSION;
							exportFile = new File(newExportFileName);
							
							PrintWriter pw = new PrintWriter(exportFile);
							SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
							smf.write();
							pw.close();	
						}
					}
					else if(scanCount == 1)// regular simulation, no parameter scan
					{
						SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null),0);
						// export the simulation to the selected file
						PrintWriter pw = new PrintWriter(exportFile);
						SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
						smf.write();
						pw.close();
					}
					else
					{
						throw new Exception("Simulation scan count is smaller than 1.");
					}
				}
				return;
													
			} else {
				// convert it if other format
				if (!fileFilter.equals(FileFilters.FILE_FILTER_VCML)) {
					// SBML or CellML; get application name
					if ((fileFilter.equals(FileFilters.FILE_FILTER_SBML_12)) || (fileFilter.equals(FileFilters.FILE_FILTER_SBML_21)) || 
						(fileFilter.equals(FileFilters.FILE_FILTER_SBML_22)) || (fileFilter.equals(FileFilters.FILE_FILTER_SBML_23)) || 
						(fileFilter.equals(FileFilters.FILE_FILTER_SBML_24)) || (fileFilter.equals(FileFilters.FILE_FILTER_SBML_31_CORE)) || 
						(fileFilter.equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL)) ) {
						SimulationContext selectedSimContext = (SimulationContext)hashTable.get("selectedSimContext");
						Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
						int sbmlLevel = 0;
						int sbmlVersion = 0;
						int sbmlPkgVersion = 0;
						boolean bIsSpatial = false;
						if ((fileFilter.equals(FileFilters.FILE_FILTER_SBML_12))) {
							sbmlLevel = 1;
							sbmlVersion = 2;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_21)) {
							sbmlLevel = 2;
							sbmlVersion = 1;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_22)) {
							sbmlLevel = 2;
							sbmlVersion = 2;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_23)) {
							sbmlLevel = 2;
							sbmlVersion = 3;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_24)) {
							sbmlLevel = 2;
							sbmlVersion = 4;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_31_CORE)) {
							sbmlLevel = 3;
							sbmlVersion = 1;
						} else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_31_SPATIAL)) {
							sbmlLevel = 3;
							sbmlVersion = 1;
							sbmlPkgVersion = 1;
							bIsSpatial = true;
						}
						if (selectedSim == null) {
							resultString = XmlHelper.exportSBML(bioModel, sbmlLevel, sbmlVersion, sbmlPkgVersion, bIsSpatial, selectedSimContext, null);
							XmlUtil.writeXMLStringToFile(resultString, exportFile.getAbsolutePath(), true);
							return;
						} else {
							for (int sc = 0; sc < selectedSim.getScanCount(); sc++) {
								SimulationJob simJob = new SimulationJob(selectedSim, sc, null);
								resultString = XmlHelper.exportSBML(bioModel, sbmlLevel, sbmlVersion, sbmlPkgVersion, bIsSpatial, selectedSimContext, simJob);
								// Need to export each parameter scan into a separate file 
								String newExportFileName = exportFile.getPath().substring(0, exportFile.getPath().indexOf(".xml")) + "_" + sc + ".xml";
								exportFile.renameTo(new File(newExportFileName));
								XmlUtil.writeXMLStringToFile(resultString, exportFile.getAbsolutePath(), true);
							}
							return;
						}
					} else if (fileFilter.equals(FileFilters.FILE_FILTER_BNGL)) {
						RbmModelContainer rbmModelContainer = bioModel.getModel().getRbmModelContainer();
						StringWriter bnglStringWriter = new StringWriter();
						PrintWriter pw = new PrintWriter(bnglStringWriter);
						RbmNetworkGenerator.writeBngl(bioModel, pw);
						resultString = bnglStringWriter.toString();
						pw.close();
						
					} else if (fileFilter.equals(FileFilters.FILE_FILTER_NFSIM)) {
						// TODO: get the first thing we find for now, in the future we'll need to modify ChooseFile 
						//       to only offer the applications / simulations with bngl content
						SimulationContext simContexts[] = bioModel.getSimulationContexts();
						SimulationContext aSimulationContext = simContexts[0];
						Simulation selectedSim = aSimulationContext.getSimulations(0);
						//Simulation selectedSim = (Simulation)hashTable.get("selectedSimulation");
						SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, 0, null),0);
						long randomSeed = 0;	// a fixed seed will allow us to run reproducible simulations
						//long randomSeed = System.currentTimeMillis();
						NFsimSimulationOptions nfsimSimulationOptions = new NFsimSimulationOptions();
						// we get the data we need from the math description
						Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions);
						Document doc = new Document();
						doc.setRootElement(root);
						XMLOutputter xmlOut = new XMLOutputter();
						resultString = xmlOut.outputString(doc);
	
					} else if (fileFilter.equals(FileFilters.FILE_FILTER_CELLML)) {
						Integer chosenSimContextIndex = (Integer)hashTable.get("chosenSimContextIndex");
						String applicationName = bioModel.getSimulationContext(chosenSimContextIndex.intValue()).getName();
						resultString = XmlHelper.exportCellML(bioModel, applicationName);
						// cellml still uses default character encoding for now ... maybe UTF-8 in the future
					} else if (fileFilter.equals(FileFilters.FILE_FILTER_SEDML)) {
						// export the entire biomodel to a SEDML file (for now, only non-spatial,non-stochastic applns)
						int sedmlLevel = 1;
						int sedmlVersion = 1;
						String sPath = FileUtils.getFullPathNoEndSeparator(exportFile.getAbsolutePath());
						String sFile = FileUtils.getBaseName(exportFile.getAbsolutePath());
						String sExt = FileUtils.getExtension(exportFile.getAbsolutePath());
						
						SEDMLExporter sedmlExporter = null;
						if (bioModel instanceof BioModel) {
							sedmlExporter = new SEDMLExporter(bioModel, sedmlLevel, sedmlVersion);
							resultString = sedmlExporter.getSEDMLFile(sPath);
						} else {
							throw new RuntimeException("unsupported Document Type " + bioModel.getClass().getName() + " for SedML export");
						}
						if(sExt.equals("sedx")) {
							sedmlExporter.createManifest(sPath, sFile);
							String sedmlFileName = sPath + FileUtils.WINDOWS_SEPARATOR + sFile + ".sedml";
							XmlUtil.writeXMLStringToFile(resultString, sedmlFileName, true);
							sedmlExporter.addSedmlFileToList(sFile + ".sedml");
							sedmlExporter.addSedmlFileToList("manifest.xml");
							sedmlExporter.createZipArchive(sPath, sFile);
							return;
						} else {
							XmlUtil.writeXMLStringToFile(resultString, exportFile.getAbsolutePath(), true);
						}
					}
				} else {
					// if format is VCML, get it from biomodel.
					bioModel.getVCMetaData().cleanupMetadata();
					resultString = XmlHelper.bioModelToXML(bioModel);
					XmlUtil.writeXMLStringToFile(resultString, exportFile.getAbsolutePath(), true);
					return;
				}
			}*/
        } else if (documentToExport instanceof MathModel) {
            MathModel mathModel = (MathModel) documentToExport;
            // check format requested
            if (fileFilter.equals(FileFilters.FILE_FILTER_MATLABV6)) {
                // check if it's ODE
                if (mathModel.getMathDescription() != null && (!mathModel.getMathDescription().isSpatial() && !mathModel.getMathDescription().isNonSpatialStoch())) {
                    MathDescription mathDesc = mathModel.getMathDescription();
                    resultString = exportMatlab(exportFile, fileFilter, mathDesc);
                } else {
                    throw new Exception("Matlab export failed: NOT an non-spatial deterministic model.");
                }
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_PDF)) {
                FileOutputStream fos = new FileOutputStream(exportFile);
                documentManager.generatePDF(mathModel, fos);
                fos.close();
                // will take care of writing to the file as well.
                return;
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_VCML)) {
                resultString = XmlHelper.mathModelToXML(mathModel);
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_CELLML)) {
                resultString = XmlHelper.exportCellML(mathModel, null);
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_23)) {
                resultString = XmlHelper.exportSBML(mathModel, 2, 3, 0, false, null, null);
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_SBML_24)) {
                resultString = XmlHelper.exportSBML(mathModel, 2, 4, 0, false, null, null);
            } else // in simulation, we'll export multiple Smoldyn input files.
            if (fileFilter.equals(FileFilters.FILE_FILTER_SMOLDYN_INPUT)) {
                Simulation selectedSim = (Simulation) hashTable.get("selectedSimulation");
                if (selectedSim != null) {
                    int scanCount = selectedSim.getScanCount();
                    // -----
                    String baseExportFileName = (scanCount == 1 ? null : exportFile.getPath().substring(0, exportFile.getPath().indexOf(".")));
                    for (int i = 0; i < scanCount; i++) {
                        SimulationTask simTask = new SimulationTask(new SimulationJob(selectedSim, i, null), 0);
                        // Need to export each parameter scan into a separate file
                        File localExportFile = (scanCount == 1 ? exportFile : new File(baseExportFileName + "_" + i + SMOLDYN_INPUT_FILE_EXTENSION));
                        FileCloseHelper localCloseThis = new FileCloseHelper(localExportFile);
                        try {
                            SmoldynFileWriter smf = new SmoldynFileWriter(localCloseThis.getPrintWriter(), true, null, simTask, false);
                            smf.write();
                        } finally {
                            if (localCloseThis != null) {
                                localCloseThis.close();
                            }
                        }
                    }
                }
                return;
            }
        } else if (documentToExport instanceof Geometry) {
            Geometry geom = (Geometry) documentToExport;
            if (fileFilter.equals(FileFilters.FILE_FILTER_PDF)) {
                documentManager.generatePDF(geom, (closeThis = new FileCloseHelper(exportFile)).getFileOutputStream());
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_VCML)) {
                resultString = XmlHelper.geometryToXML(geom);
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_AVS)) {
                cbit.vcell.export.AVS_UCD_Exporter.writeUCDGeometryOnly(geom.getGeometrySurfaceDescription(), (closeThis = new FileCloseHelper(exportFile)).getFileWriter());
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_STL)) {
                // make sure filename end with .stl
                File stlFile = exportFile;
                if (!exportFile.getName().toLowerCase().endsWith(".stl")) {
                    stlFile = new File(exportFile.getParentFile(), exportFile.getName() + ".stl");
                }
                cbit.vcell.geometry.surface.StlExporter.writeBinaryStl(geom.getGeometrySurfaceDescription(), (closeThis = new FileCloseHelper(stlFile)).getRandomAccessFile("rw"));
            } else if (fileFilter.equals(FileFilters.FILE_FILTER_PLY)) {
                writeStanfordPolygon(geom.getGeometrySurfaceDescription(), (closeThis = new FileCloseHelper(exportFile)).getFileWriter());
            }
        }
        if (resultString != null) {
            (closeThis = new FileCloseHelper(exportFile)).getFileWriter().write(resultString);
        }
    } finally {
        if (closeThis != null) {
            closeThis.close();
        }
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) MathDescription(cbit.vcell.math.MathDescription) DocumentManager(cbit.vcell.clientdb.DocumentManager) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) SimulationContext(cbit.vcell.mapping.SimulationContext) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) ExtensionFilter(org.vcell.util.gui.exporter.ExtensionFilter) SelectorExtensionFilter(org.vcell.util.gui.exporter.SelectorExtensionFilter) BioModel(cbit.vcell.biomodel.BioModel) FileOutputStream(java.io.FileOutputStream) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SimulationJob(cbit.vcell.solver.SimulationJob)

Aggregations

DocumentManager (cbit.vcell.clientdb.DocumentManager)30 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)10 Hashtable (java.util.Hashtable)10 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)6 VCDocument (org.vcell.util.document.VCDocument)6 UserCancelException (org.vcell.util.UserCancelException)5 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)5 BioModel (cbit.vcell.biomodel.BioModel)4 Component (java.awt.Component)4 File (java.io.File)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 DatabaseWindowManager (cbit.vcell.client.DatabaseWindowManager)3 DocumentWindow (cbit.vcell.client.desktop.DocumentWindow)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 GeometryInfo (cbit.vcell.geometry.GeometryInfo)3 RegionImage (cbit.vcell.geometry.RegionImage)3 DataAccessException (org.vcell.util.DataAccessException)3 VCImageUncompressed (cbit.image.VCImageUncompressed)2 AnnotatedImageDataset (cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset)2 MicroscopyXmlReader (cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader)2