Search in sources :

Example 1 with BioModelInfo

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

the class ClientRequestManager method curateDocument.

/**
 * Insert the method's description here.
 * Creation date: (6/22/2004 10:50:34 PM)
 * @param documentInfo cbit.vcell.document.VCDocumentInfo
 */
public void curateDocument(final VCDocumentInfo documentInfo, final int curateType, final TopLevelWindowManager requester) {
    if (documentInfo != null) {
        // see if we have this open
        String documentID = documentInfo.getVersion().getVersionKey().toString();
        if (getMdiManager().haveWindow(documentID)) {
            // already open, refuse
            PopupGenerator.showErrorDialog(requester, "Selected edition is open, cannot " + CurateSpec.CURATE_TYPE_NAMES[curateType]);
            return;
        } else {
            // don't have it open, try to CURATE it
            int confirm = PopupGenerator.showComponentOKCancelDialog(requester.getComponent(), new JTextArea(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " cannot be undone without VCELL administrative assistance.\n" + CurateSpec.CURATE_TYPE_STATES[curateType] + " versions of documents cannot be deleted without VCELL administrative assistance.\n" + (curateType == CurateSpec.PUBLISH ? CurateSpec.CURATE_TYPE_STATES[curateType] + " versions of documents MUST remain publically accessible to other VCELL users.\n" : "") + "Do you want to " + CurateSpec.CURATE_TYPE_NAMES[curateType] + " document '" + documentInfo.getVersion().getName() + "'" + "\nwith version date '" + documentInfo.getVersion().getDate().toString() + "'?"), "WARNING -- " + CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " operation cannot be undone");
            if (confirm == JOptionPane.OK_OPTION) {
                AsynchClientTask task1 = new AsynchClientTask(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " document...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                    @Override
                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                        if (documentInfo instanceof BioModelInfo) {
                            getDocumentManager().curate(new CurateSpec((BioModelInfo) documentInfo, curateType));
                        } else if (documentInfo instanceof MathModelInfo) {
                            getDocumentManager().curate(new CurateSpec((MathModelInfo) documentInfo, curateType));
                        } else {
                            throw new RuntimeException(CurateSpec.CURATE_TYPE_ACTIONS[curateType] + " not supported for VCDocumentInfo type " + documentInfo.getClass().getName());
                        }
                    }
                };
                ClientTaskDispatcher.dispatch(requester.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1 }, false);
            } else {
                // user canceled
                return;
            }
        }
    } else {
        // nothing selected
        return;
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) JTextArea(javax.swing.JTextArea) Hashtable(java.util.Hashtable) CurateSpec(org.vcell.util.document.CurateSpec) BioModelInfo(org.vcell.util.document.BioModelInfo) CSGObject(cbit.vcell.geometry.CSGObject) MathModelInfo(org.vcell.util.document.MathModelInfo)

Example 2 with BioModelInfo

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

the class ClientRequestManager method accessPermissions.

public void accessPermissions(Component requester, VCDocument vcDoc) {
    VersionInfo selectedVersionInfo = null;
    switch(vcDoc.getDocumentType()) {
        case BIOMODEL_DOC:
            BioModelInfo[] bioModelInfos = getDocumentManager().getBioModelInfos();
            for (BioModelInfo bioModelInfo : bioModelInfos) {
                if (bioModelInfo.getVersion().getVersionKey().equals(vcDoc.getVersion().getVersionKey())) {
                    selectedVersionInfo = bioModelInfo;
                    break;
                }
            }
            break;
        case MATHMODEL_DOC:
            MathModelInfo[] mathModelInfos = getDocumentManager().getMathModelInfos();
            for (MathModelInfo mathModelInfo : mathModelInfos) {
                if (mathModelInfo.getVersion().getVersionKey().equals(vcDoc.getVersion().getVersionKey())) {
                    selectedVersionInfo = mathModelInfo;
                    break;
                }
            }
            break;
        case GEOMETRY_DOC:
            GeometryInfo[] geoInfos = getDocumentManager().getGeometryInfos();
            for (GeometryInfo geoInfo : geoInfos) {
                if (geoInfo.getVersion().getVersionKey().equals(vcDoc.getVersion().getVersionKey())) {
                    selectedVersionInfo = geoInfo;
                    break;
                }
            }
            break;
    }
    getMdiManager().getDatabaseWindowManager().accessPermissions(requester, selectedVersionInfo);
}
Also used : VersionInfo(org.vcell.util.document.VersionInfo) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) MathModelInfo(org.vcell.util.document.MathModelInfo)

Example 3 with BioModelInfo

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

the class ClientRequestManager method openAfterChecking.

private void openAfterChecking(VCDocumentInfo documentInfo, final TopLevelWindowManager requester, final boolean inNewWindow) {
    final String DOCUMENT_INFO = "documentInfo";
    final String SEDML_TASK = "SedMLTask";
    final String SEDML_MODEL = "SedMLModel";
    final String BNG_UNIT_SYSTEM = "bngUnitSystem";
    /* asynchronous and not blocking any window */
    bOpening = true;
    Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
    // may want to insert corrected VCDocumentInfo later if our import debugger corrects it (BNGL Debugger).
    hashTable.put(DOCUMENT_INFO, documentInfo);
    // start a thread that gets it and updates the GUI by creating a new document desktop
    String taskName = null;
    if (documentInfo instanceof ExternalDocInfo) {
        taskName = "Importing document";
        ExternalDocInfo externalDocInfo = (ExternalDocInfo) documentInfo;
        File file = externalDocInfo.getFile();
        if (file != null && !file.getName().isEmpty() && file.getName().endsWith("bngl")) {
            BngUnitSystem bngUnitSystem = new BngUnitSystem(BngUnitOrigin.DEFAULT);
            String fileText;
            String originalFileText;
            try {
                fileText = BeanUtils.readBytesFromFile(file, null);
                originalFileText = new String(fileText);
            } catch (IOException e1) {
                e1.printStackTrace();
                DialogUtils.showErrorDialog(requester.getComponent(), "<html>Error reading file " + file.getPath() + "</html>");
                return;
            }
            Reader reader = externalDocInfo.getReader();
            boolean bException = true;
            while (bException) {
                try {
                    BioModel bioModel = createDefaultBioModelDocument(bngUnitSystem);
                    boolean bStochastic = true;
                    boolean bRuleBased = true;
                    SimulationContext ruleBasedSimContext = bioModel.addNewSimulationContext("temp NFSim app", SimulationContext.Application.RULE_BASED_STOCHASTIC);
                    List<SimulationContext> appList = new ArrayList<SimulationContext>();
                    appList.add(ruleBasedSimContext);
                    RbmModelContainer rbmModelContainer = bioModel.getModel().getRbmModelContainer();
                    RbmUtils.reactionRuleLabelIndex = 0;
                    RbmUtils.reactionRuleNames.clear();
                    ASTModel astModel = RbmUtils.importBnglFile(reader);
                    // for now, hasUnitSystem() always returns false
                    if (astModel.hasUnitSystem()) {
                        bngUnitSystem = astModel.getUnitSystem();
                    }
                    if (astModel.hasCompartments()) {
                        Structure struct = bioModel.getModel().getStructure(0);
                        if (struct != null) {
                            bioModel.getModel().removeStructure(struct);
                        }
                    }
                    BnglObjectConstructionVisitor constructionVisitor = null;
                    if (!astModel.hasMolecularDefinitions()) {
                        System.out.println("Molecular Definition Block missing.");
                        constructionVisitor = new BnglObjectConstructionVisitor(bioModel.getModel(), appList, bngUnitSystem, false);
                    } else {
                        constructionVisitor = new BnglObjectConstructionVisitor(bioModel.getModel(), appList, bngUnitSystem, true);
                    }
                    astModel.jjtAccept(constructionVisitor, rbmModelContainer);
                    bException = false;
                } catch (final Exception e) {
                    e.printStackTrace(System.out);
                    BNGLDebuggerPanel panel = new BNGLDebuggerPanel(fileText, e);
                    int oKCancel = DialogUtils.showComponentOKCancelDialog(requester.getComponent(), panel, "Bngl Debugger: " + file.getName());
                    if (oKCancel == JOptionPane.CANCEL_OPTION || oKCancel == JOptionPane.DEFAULT_OPTION) {
                        throw new UserCancelException("Canceling Import");
                    }
                    // inserting <potentially> corrected DocumentInfo
                    fileText = panel.getText();
                    externalDocInfo = new ExternalDocInfo(panel.getText());
                    reader = externalDocInfo.getReader();
                    hashTable.put(DOCUMENT_INFO, externalDocInfo);
                }
            }
            if (!originalFileText.equals(fileText)) {
                // file has been modified
                String message = "Importing <b>" + file.getName() + "</b> into vCell. <br>Overwrite the file on the disk?<br>";
                message = "<html>" + message + "</html>";
                Object[] options = { "Overwrite and Import", "Import Only", "Cancel" };
                int returnCode = JOptionPane.showOptionDialog(requester.getComponent(), message, "Bngl Debugger", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
                if (returnCode == JOptionPane.YES_OPTION) {
                    try {
                        FileWriter fw = new FileWriter(file);
                        fw.write(fileText);
                        fw.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else if (returnCode == JOptionPane.CANCEL_OPTION || returnCode == JOptionPane.CLOSED_OPTION) {
                    return;
                }
            }
            if (!(bngUnitSystem.getOrigin() == BngUnitOrigin.PARSER)) {
                BNGLUnitsPanel panel = new BNGLUnitsPanel(bngUnitSystem);
                int oKCancel = DialogUtils.showComponentOKCancelDialog(requester.getComponent(), panel, " Bngl Units Selector", null, false);
                if (oKCancel == JOptionPane.CANCEL_OPTION || oKCancel == JOptionPane.DEFAULT_OPTION) {
                    // TODO: or do nothing and continue with default values?
                    return;
                } else {
                    bngUnitSystem = panel.getUnits();
                }
            }
            hashTable.put(BNG_UNIT_SYSTEM, bngUnitSystem);
        } else if (file != null && !file.getName().isEmpty() && file.getName().toLowerCase().endsWith(".sedml")) {
            try {
                XMLSource xmlSource = externalDocInfo.createXMLSource();
                File sedmlFile = xmlSource.getXmlFile();
                SedML sedml = Libsedml.readDocument(sedmlFile).getSedMLModel();
                if (sedml == null || sedml.getModels().isEmpty()) {
                    return;
                }
                AbstractTask chosenTask = SEDMLChooserPanel.chooseTask(sedml, requester.getComponent(), file.getName());
                hashTable.put(SEDML_MODEL, sedml);
                hashTable.put(SEDML_TASK, chosenTask);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("failed to read document: " + e.getMessage(), e);
            }
        } else if (file != null && !file.getName().isEmpty() && (file.getName().toLowerCase().endsWith(".sedx") || file.getName().toLowerCase().endsWith(".omex"))) {
            try {
                ArchiveComponents ac = null;
                ac = Libsedml.readSEDMLArchive(new FileInputStream(file));
                SEDMLDocument doc = ac.getSedmlDocument();
                SedML sedml = doc.getSedMLModel();
                if (sedml == null) {
                    throw new RuntimeException("Failed importing " + file.getName());
                }
                if (sedml.getModels().isEmpty()) {
                    throw new RuntimeException("Unable to find any model in " + file.getName());
                }
                AbstractTask chosenTask = SEDMLChooserPanel.chooseTask(sedml, requester.getComponent(), file.getName());
                hashTable.put(SEDML_MODEL, sedml);
                hashTable.put(SEDML_TASK, chosenTask);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("failed to read archive: " + e.getMessage(), e);
            }
        }
    } else {
        taskName = "Loading document '" + documentInfo.getVersion().getName() + "' from database";
    }
    AsynchClientTask task0 = new AsynchClientTask(taskName, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (!inNewWindow) {
                // request was to replace the document in an existing window
                getMdiManager().blockWindow(requester.getManagerID());
            }
        }
    };
    AsynchClientTask task1 = new AsynchClientTask(taskName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VCDocument doc = null;
            VCDocumentInfo documentInfo = (VCDocumentInfo) hashTable.get(DOCUMENT_INFO);
            if (documentInfo instanceof BioModelInfo) {
                BioModelInfo bmi = (BioModelInfo) documentInfo;
                doc = getDocumentManager().getBioModel(bmi);
            } else if (documentInfo instanceof MathModelInfo) {
                MathModelInfo mmi = (MathModelInfo) documentInfo;
                doc = getDocumentManager().getMathModel(mmi);
            } else if (documentInfo instanceof GeometryInfo) {
                GeometryInfo gmi = (GeometryInfo) documentInfo;
                doc = getDocumentManager().getGeometry(gmi);
            } else if (documentInfo instanceof ExternalDocInfo) {
                ExternalDocInfo externalDocInfo = (ExternalDocInfo) documentInfo;
                File file = externalDocInfo.getFile();
                if (file != null && !file.getName().isEmpty() && (file.getName().toLowerCase().endsWith(".sedx") || file.getName().toLowerCase().endsWith(".omex"))) {
                    TranslationLogger transLogger = new TranslationLogger(requester);
                    doc = XmlHelper.sedmlToBioModel(transLogger, externalDocInfo, (SedML) hashTable.get(SEDML_MODEL), (AbstractTask) hashTable.get(SEDML_TASK));
                } else if (!externalDocInfo.isXML()) {
                    if (hashTable.containsKey(BNG_UNIT_SYSTEM)) {
                        // not XML, look for BNGL etc.
                        // we use the BngUnitSystem already created during the 1st pass
                        BngUnitSystem bngUnitSystem = (BngUnitSystem) hashTable.get(BNG_UNIT_SYSTEM);
                        BioModel bioModel = createDefaultBioModelDocument(bngUnitSystem);
                        SimulationContext ruleBasedSimContext = bioModel.addNewSimulationContext("NFSim app", SimulationContext.Application.RULE_BASED_STOCHASTIC);
                        SimulationContext odeSimContext = bioModel.addNewSimulationContext("BioNetGen app", SimulationContext.Application.NETWORK_DETERMINISTIC);
                        List<SimulationContext> appList = new ArrayList<SimulationContext>();
                        appList.add(ruleBasedSimContext);
                        appList.add(odeSimContext);
                        // set convention for initial conditions in generated application for seed species (concentration or count)
                        ruleBasedSimContext.setUsingConcentration(bngUnitSystem.isConcentration());
                        odeSimContext.setUsingConcentration(bngUnitSystem.isConcentration());
                        RbmModelContainer rbmModelContainer = bioModel.getModel().getRbmModelContainer();
                        RbmUtils.reactionRuleLabelIndex = 0;
                        RbmUtils.reactionRuleNames.clear();
                        Reader reader = externalDocInfo.getReader();
                        ASTModel astModel = RbmUtils.importBnglFile(reader);
                        if (bioModel.getModel() != null && bioModel.getModel().getVcMetaData() != null) {
                            VCMetaData vcMetaData = bioModel.getModel().getVcMetaData();
                            vcMetaData.setFreeTextAnnotation(bioModel, astModel.getProlog());
                        }
                        if (astModel.hasCompartments()) {
                            Structure struct = bioModel.getModel().getStructure(0);
                            if (struct != null) {
                                bioModel.getModel().removeStructure(struct);
                            }
                        }
                        BnglObjectConstructionVisitor constructionVisitor = null;
                        if (!astModel.hasMolecularDefinitions()) {
                            System.out.println("Molecular Definition Block missing. Extracting it from Species, Reactions, Obserbables.");
                            constructionVisitor = new BnglObjectConstructionVisitor(bioModel.getModel(), appList, bngUnitSystem, false);
                        } else {
                            constructionVisitor = new BnglObjectConstructionVisitor(bioModel.getModel(), appList, bngUnitSystem, true);
                        }
                        // we'll convert the kinetic parameters to BngUnitSystem inside the visit(ASTKineticsParameter...)
                        astModel.jjtAccept(constructionVisitor, rbmModelContainer);
                        // set the volume in the newly created application to BngUnitSystem.bnglModelVolume
                        // TODO: set the right values if we import compartments from the bngl file!
                        // if(!bngUnitSystem.isConcentration()) {
                        Expression sizeExpression = new Expression(bngUnitSystem.getVolume());
                        ruleBasedSimContext.getGeometryContext().getStructureMapping(0).getSizeParameter().setExpression(sizeExpression);
                        odeSimContext.getGeometryContext().getStructureMapping(0).getSizeParameter().setExpression(sizeExpression);
                        // }
                        // we remove the NFSim application if any seed species is clamped because NFSim doesn't know what to do with it
                        boolean bClamped = false;
                        for (SpeciesContextSpec scs : ruleBasedSimContext.getReactionContext().getSpeciesContextSpecs()) {
                            if (scs.isConstant()) {
                                bClamped = true;
                                break;
                            }
                        }
                        if (bClamped) {
                            bioModel.removeSimulationContext(ruleBasedSimContext);
                        }
                        // // TODO: DON'T delete this code
                        // // the code below is needed if we also want to create simulations, example for 1 rule based simulation
                        // // it is rule-based so it wont have to flatten, should be fast.
                        // MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                        // NetworkGenerationRequirements networkGenerationRequirements = null; // network generation should not be executed.
                        // ruleBasedSimContext.refreshMathDescription(callback,networkGenerationRequirements);
                        // Simulation sim = ruleBasedSimContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX,callback,networkGenerationRequirements);
                        doc = bioModel;
                    }
                } else {
                    // is XML
                    try (TranslationLogger transLogger = new TranslationLogger(requester)) {
                        XMLSource xmlSource = externalDocInfo.createXMLSource();
                        org.jdom.Element rootElement = xmlSource.getXmlDoc().getRootElement();
                        String xmlType = rootElement.getName();
                        String modelXmlType = null;
                        if (xmlType.equals(XMLTags.VcmlRootNodeTag)) {
                            // For now, assuming that <vcml> element has only one child (biomodel, mathmodel or geometry).
                            // Will deal with multiple children of <vcml> Element when we get to model composition.
                            @SuppressWarnings("unchecked") List<Element> childElementList = rootElement.getChildren();
                            // assuming first child is the biomodel, mathmodel or geometry.
                            Element modelElement = childElementList.get(0);
                            modelXmlType = modelElement.getName();
                        }
                        if (xmlType.equals(XMLTags.BioModelTag) || (xmlType.equals(XMLTags.VcmlRootNodeTag) && modelXmlType.equals(XMLTags.BioModelTag))) {
                            doc = XmlHelper.XMLToBioModel(xmlSource);
                        } else if (xmlType.equals(XMLTags.MathModelTag) || (xmlType.equals(XMLTags.VcmlRootNodeTag) && modelXmlType.equals(XMLTags.MathModelTag))) {
                            doc = XmlHelper.XMLToMathModel(xmlSource);
                        } else if (xmlType.equals(XMLTags.GeometryTag) || (xmlType.equals(XMLTags.VcmlRootNodeTag) && modelXmlType.equals(XMLTags.GeometryTag))) {
                            doc = XmlHelper.XMLToGeometry(xmlSource);
                        } else if (xmlType.equals(XMLTags.SbmlRootNodeTag)) {
                            Namespace namespace = rootElement.getNamespace(XMLTags.SBML_SPATIAL_NS_PREFIX);
                            boolean bIsSpatial = (namespace == null) ? false : true;
                            doc = XmlHelper.importSBML(transLogger, xmlSource, bIsSpatial);
                        } else if (xmlType.equals(XMLTags.CellmlRootNodeTag)) {
                            if (requester instanceof BioModelWindowManager) {
                                doc = XmlHelper.importBioCellML(transLogger, xmlSource);
                            } else {
                                doc = XmlHelper.importMathCellML(transLogger, xmlSource);
                            }
                        } else if (xmlType.equals(MicroscopyXMLTags.FRAPStudyTag)) {
                            doc = VFrapXmlHelper.VFRAPToBioModel(hashTable, xmlSource, getDocumentManager(), requester);
                        } else if (xmlType.equals(XMLTags.SedMLTypeTag)) {
                            doc = XmlHelper.sedmlToBioModel(transLogger, externalDocInfo, (SedML) hashTable.get(SEDML_MODEL), (AbstractTask) hashTable.get(SEDML_TASK));
                        } else {
                            // unknown XML format
                            throw new RuntimeException("unsupported XML format, first element tag is <" + rootElement.getName() + ">");
                        }
                        if (externalDocInfo.getDefaultName() != null) {
                            doc.setName(externalDocInfo.getDefaultName());
                        }
                    }
                }
                if (doc == null) {
                    File f = externalDocInfo.getFile();
                    if (f != null) {
                        throw new RuntimeException("Unable to determine type of file " + f.getCanonicalPath());
                    }
                    throw new ProgrammingException();
                }
            }
            // create biopax objects using annotation
            if (doc instanceof BioModel) {
                BioModel bioModel = (BioModel) doc;
                try {
                    bioModel.getVCMetaData().createBioPaxObjects(bioModel);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            requester.prepareDocumentToLoad(doc, inNewWindow);
            hashTable.put("doc", doc);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("Showing document", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            try {
                Throwable exc = (Throwable) hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR);
                if (exc == null) {
                    VCDocument doc = (VCDocument) hashTable.get("doc");
                    DocumentWindowManager windowManager = null;
                    if (inNewWindow) {
                        windowManager = createDocumentWindowManager(doc);
                        // request was to create a new top-level window with this doc
                        getMdiManager().createNewDocumentWindow(windowManager);
                    // if (windowManager instanceof BioModelWindowManager) {
                    // ((BioModelWindowManager)windowManager).preloadApps();
                    // }
                    } else {
                        // request was to replace the document in an existing window
                        windowManager = (DocumentWindowManager) requester;
                        getMdiManager().setCanonicalTitle(requester.getManagerID());
                        windowManager.resetDocument(doc);
                    }
                    hashTable.put(WIN_MGR_KEY, windowManager);
                }
            } finally {
                if (!inNewWindow) {
                    getMdiManager().unBlockWindow(requester.getManagerID());
                }
                bOpening = false;
            }
        }
    };
    AsynchClientTask task3 = new AsynchClientTask("Special Layout", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // TODO Auto-generated method stub
            if (documentInfo instanceof ExternalDocInfo) {
                ExternalDocInfo externalDocInfo = (ExternalDocInfo) documentInfo;
                if (externalDocInfo.isBioModelsNet()) {
                    DocumentWindowManager windowManager = (DocumentWindowManager) hashTable.get(WIN_MGR_KEY);
                    if (windowManager instanceof BioModelWindowManager) {
                        ((BioModelWindowManager) windowManager).specialLayout();
                    }
                }
            }
        }
    };
    AsynchClientTask task4 = new AsynchClientTaskFunction(ClientRequestManager::setWindowFocus, "Set window focus", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false);
    ClientTaskDispatcher.dispatch(requester.getComponent(), hashTable, new AsynchClientTask[] { task0, task1, task2, task3, task4 }, false);
}
Also used : ArrayList(java.util.ArrayList) UserCancelException(org.vcell.util.UserCancelException) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SedML(org.jlibsedml.SedML) ExternalDocInfo(cbit.vcell.xml.ExternalDocInfo) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) VCMetaData(cbit.vcell.biomodel.meta.VCMetaData) BnglObjectConstructionVisitor(org.vcell.model.rbm.RbmUtils.BnglObjectConstructionVisitor) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) GeometryInfo(cbit.vcell.geometry.GeometryInfo) VCDocument(org.vcell.util.document.VCDocument) FileInputStream(java.io.FileInputStream) Namespace(org.jdom.Namespace) BngUnitSystem(org.vcell.model.bngl.BngUnitSystem) BNGLDebuggerPanel(org.vcell.model.bngl.gui.BNGLDebuggerPanel) SEDMLDocument(org.jlibsedml.SEDMLDocument) CSGObject(cbit.vcell.geometry.CSGObject) ChooseFile(cbit.vcell.client.task.ChooseFile) File(java.io.File) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) AbstractTask(org.jlibsedml.AbstractTask) FileWriter(java.io.FileWriter) Element(org.jdom.Element) StlReader(cbit.vcell.geometry.surface.StlReader) FileReader(java.io.FileReader) ImageDatasetReader(org.vcell.vcellij.ImageDatasetReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) ArchiveComponents(org.jlibsedml.ArchiveComponents) ProgrammingException(org.vcell.util.ProgrammingException) Structure(cbit.vcell.model.Structure) Hashtable(java.util.Hashtable) BNGLUnitsPanel(org.vcell.model.bngl.gui.BNGLUnitsPanel) BioModelInfo(org.vcell.util.document.BioModelInfo) IOException(java.io.IOException) MathModelInfo(org.vcell.util.document.MathModelInfo) SimulationContext(cbit.vcell.mapping.SimulationContext) 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) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) Element(org.jdom.Element) ASTModel(org.vcell.model.bngl.ASTModel)

Example 4 with BioModelInfo

use of org.vcell.util.document.BioModelInfo 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 5 with BioModelInfo

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

the class DatabaseWindowManager method compareAnotherModel.

/**
 * Comment
 */
public void compareAnotherModel() {
    // 
    if (getPanelSelection() == null) {
        PopupGenerator.showErrorDialog(this, "Error Comparing documents : First document not selected");
        return;
    }
    VCDocumentInfo thisDocumentInfo = getPanelSelection();
    // Choose the other documentInfo. Bring up the appropriate dbTreePanel depending on the type of thisDocumentInfo
    VCDocumentInfo otherDocumentInfo = null;
    try {
        otherDocumentInfo = selectDocument(thisDocumentInfo.getVCDocumentType(), this);
    } catch (Exception e) {
        if (!(e instanceof UserCancelException)) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(this.getComponent(), "Error Comparing documents: " + e.getMessage());
        }
        return;
    }
    if (otherDocumentInfo == null) {
        // PopupGenerator.showErrorDialog(this, "Error Comparing documents : Second document is null ");
        return;
    }
    // Check if both document types are of the same kind. If not, throw an error.
    if (((thisDocumentInfo instanceof BioModelInfo) && !(otherDocumentInfo instanceof BioModelInfo)) || ((thisDocumentInfo instanceof MathModelInfo) && !(otherDocumentInfo instanceof MathModelInfo)) || ((thisDocumentInfo instanceof GeometryInfo) && !(otherDocumentInfo instanceof GeometryInfo))) {
        PopupGenerator.showErrorDialog(this, "Error Comparing documents : The two documents are not of the same type!");
        return;
    }
    // Now that we have both the document versions to be compared, do the comparison and display the result
    compareWithOther(otherDocumentInfo, thisDocumentInfo);
}
Also used : VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) UserCancelException(org.vcell.util.UserCancelException) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

BioModelInfo (org.vcell.util.document.BioModelInfo)79 DataAccessException (org.vcell.util.DataAccessException)38 MathModelInfo (org.vcell.util.document.MathModelInfo)37 BioModel (cbit.vcell.biomodel.BioModel)25 GeometryInfo (cbit.vcell.geometry.GeometryInfo)22 KeyValue (org.vcell.util.document.KeyValue)18 SimulationContext (cbit.vcell.mapping.SimulationContext)17 VCDocumentInfo (org.vcell.util.document.VCDocumentInfo)15 BigString (org.vcell.util.BigString)14 User (org.vcell.util.document.User)14 Vector (java.util.Vector)13 Simulation (cbit.vcell.solver.Simulation)12 XmlParseException (cbit.vcell.xml.XmlParseException)12 SQLException (java.sql.SQLException)12 XMLSource (cbit.vcell.xml.XMLSource)10 MathModel (cbit.vcell.mathmodel.MathModel)9 Hashtable (java.util.Hashtable)9 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)9 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)8 Geometry (cbit.vcell.geometry.Geometry)7