Search in sources :

Example 1 with PublicationInfo

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

the class VcmlOmexConverter method parseArgsAndConvert.

public static void parseArgsAndConvert(String[] args) throws IOException {
    File input = null;
    try {
        // TODO: handle if it's not valid PATH
        input = new File(args[1]);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    args = parseArgs(args);
    // if (bHasDataOnly) {
    try {
        conFactory = DatabaseService.getInstance().createConnectionFactory();
        adminDbTopLevel = new AdminDBTopLevel(conFactory);
    } catch (SQLException e) {
        System.err.println("\n\n\n=====>>>>EXPORT FAILED: connection to database failed");
        e.printStackTrace();
    }
    // }
    VCInfoContainer vcic;
    try {
        vcic = adminDbTopLevel.getPublicOracleVCInfoContainer(false);
        if (vcic != null) {
            User user = vcic.getUser();
            BioModelInfo[] bioModelInfos = vcic.getBioModelInfos();
            // int count = 0;
            for (BioModelInfo bi : bioModelInfos) {
                // if(bi.getPublicationInfos() != null && bi.getPublicationInfos().length > 0) {
                // // let's see what has PublicationInfo
                // System.out.println(bi.getVersion().getName());
                // count++;
                // }
                // build the biomodel id / biomodel info map
                String biomodelId = "biomodel_" + bi.getVersion().getVersionKey();
                String biomodelName = bi.getVersion().getName();
                // String biomodelId2 = "biomodel_" + bi.getModelKey();
                bioModelInfoMap.put(biomodelId, bi);
                bioModelInfoMap2.put(biomodelName, bi);
            }
        // System.out.println("User: " + user.getName() + "   count published biomodels: " + count);
        }
    } catch (SQLException | DataAccessException e1) {
        System.err.println("\n\n\n=====>>>>EXPORT FAILED: failed to retrieve metadata");
        e1.printStackTrace();
    }
    System.out.println("Found " + bioModelInfoMap.size() + " public BioNodelInfo objects");
    if (input != null && input.isDirectory()) {
        FilenameFilter filterVcmlFiles = (f, name) -> name.endsWith(".vcml");
        // jusr a list of vcml names, like biomodel-185577495.vcml, ...
        String[] inputFiles = input.list(filterVcmlFiles);
        if (inputFiles == null) {
            System.err.println("No VCML files found in the directory `" + input + "`");
        }
        // full directory name, like C:\TEMP\biomodel\omex\native
        String outputDir = args[3];
        CLIStandalone.writeSimErrorList(outputDir, "hasDataOnly is " + bHasDataOnly);
        CLIStandalone.writeSimErrorList(outputDir, "makeLogsOnly is " + bMakeLogsOnly);
        // assert inputFiles != null;
        for (String inputFile : inputFiles) {
            File file = new File(input, inputFile);
            System.out.println(" ============== start: " + inputFile);
            args[1] = file.toString();
            cliHandler = new CLIHandler(args);
            try {
                if (inputFile.endsWith(".vcml")) {
                    boolean isCreated = vcmlToOmexConversion(outputDir);
                    if (isCreated) {
                        System.out.println("Combine archive created for file(s) `" + input + "`");
                    } else {
                        System.err.println("Failed converting VCML to OMEX archive for `" + input + "`");
                    }
                } else {
                    System.err.println("No VCML files found in the directory `" + input + "`");
                }
            } catch (Exception e) {
                // e.printStackTrace(System.err);
                System.out.println("\n\n\n=====>>>>EXPORT FAILED: " + inputFile + "\n\n\n");
                CLIStandalone.writeDetailedErrorList(outputDir, inputFile + ",   " + e.getMessage());
            // System.exit(1);
            }
        }
    } else {
        try {
            assert input != null;
            if (input.toString().endsWith(".vcml")) {
                cliHandler = new CLIHandler(args);
                boolean isCreated = vcmlToOmexConversion(null);
                if (isCreated)
                    System.out.println("Combine archive created for `" + input + "`");
                else
                    System.err.println("Failed converting VCML to OMEX archive for `" + input + "`");
            } else
                System.err.println("No input files found in the directory `" + input + "`");
        } catch (Exception e) {
            // e.printStackTrace();
            System.out.println("\n\n\n=====>>>>EXPORT FAILED: " + input + "\n\n\n");
        // System.exit(1);
        }
    }
}
Also used : User(org.vcell.util.document.User) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) Date(java.util.Date) Graph(org.openrdf.model.Graph) XmlUtil(cbit.util.xml.XmlUtil) PropertyVetoException(java.beans.PropertyVetoException) SEDMLExporter(org.vcell.sedml.SEDMLExporter) Version(org.vcell.util.document.Version) Vector(java.util.Vector) RDFFormat(org.openrdf.rio.RDFFormat) XmlHelper(cbit.vcell.xml.XmlHelper) Map(java.util.Map) PublicationInfo(org.vcell.util.document.PublicationInfo) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) RDF(org.openrdf.model.vocabulary.RDF) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) Simulation(cbit.vcell.solver.Simulation) CLIHandler(org.vcell.cli.CLIHandler) Literal(org.openrdf.model.Literal) ValueFactory(org.openrdf.model.ValueFactory) DefaultNameSpaces(org.sbpax.schemas.util.DefaultNameSpaces) Set(java.util.Set) PubMet(org.vcell.sedml.PubMet) XMLSource(cbit.vcell.xml.XMLSource) FileNotFoundException(java.io.FileNotFoundException) FieldUtilities(cbit.vcell.field.FieldUtilities) BioPAX3(org.sbpax.schemas.BioPAX3) List(java.util.List) KnownFormats(org.sbml.libcombine.KnownFormats) OntUtil(org.sbpax.schemas.util.OntUtil) Expression(cbit.vcell.parser.Expression) FilenameUtils(org.apache.commons.io.FilenameUtils) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) Statement(org.openrdf.model.Statement) HashGraph(org.sbpax.impl.HashGraph) MathModelInfo(org.vcell.util.document.MathModelInfo) FilenameFilter(java.io.FilenameFilter) BioModelInfo(org.vcell.util.document.BioModelInfo) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) SBPAX3Util(org.sbpax.schemas.util.SBPAX3Util) SimpleDateFormat(java.text.SimpleDateFormat) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ConnectionFactory(org.vcell.db.ConnectionFactory) DatabaseService(org.vcell.db.DatabaseService) SQLException(java.sql.SQLException) VCInfoContainer(org.vcell.util.document.VCInfoContainer) Calendar(java.util.Calendar) SimulationInfo(cbit.vcell.solver.SimulationInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) GeometryInfo(cbit.vcell.geometry.GeometryInfo) XmlParseException(cbit.vcell.xml.XmlParseException) OutputStreamWriter(java.io.OutputStreamWriter) URI(org.openrdf.model.URI) NativeLoader(cbit.vcell.util.NativeLoader) LinkedHashSet(java.util.LinkedHashSet) Value(org.openrdf.model.Value) RDFHandlerException(org.openrdf.rio.RDFHandlerException) BioModel(cbit.vcell.biomodel.BioModel) ResourceUtil(cbit.vcell.resource.ResourceUtil) BufferedWriter(java.io.BufferedWriter) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) FileOutputStream(java.io.FileOutputStream) FieldDataDBOperationDriver(cbit.vcell.field.db.FieldDataDBOperationDriver) IOException(java.io.IOException) PropertyLoader(cbit.vcell.resource.PropertyLoader) OWL(org.openrdf.model.vocabulary.OWL) DataAccessException(org.vcell.util.DataAccessException) BNode(org.openrdf.model.BNode) File(java.io.File) SolverDescription(cbit.vcell.solver.SolverDescription) Variable(cbit.vcell.math.Variable) KeyValue(org.vcell.util.document.KeyValue) Resource(org.eclipse.jetty.util.resource.Resource) Paths(java.nio.file.Paths) CLIStandalone(org.vcell.cli.CLIStandalone) SesameRioUtil(org.sbpax.util.SesameRioUtil) CombineArchive(org.sbml.libcombine.CombineArchive) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) User(org.vcell.util.document.User) SQLException(java.sql.SQLException) BioModelInfo(org.vcell.util.document.BioModelInfo) CLIHandler(org.vcell.cli.CLIHandler) PropertyVetoException(java.beans.PropertyVetoException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) FilenameFilter(java.io.FilenameFilter) VCInfoContainer(org.vcell.util.document.VCInfoContainer) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException)

Example 2 with PublicationInfo

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

the class MathModelMetaDataCellRenderer method getTreeCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    // 
    if (!leaf && expanded) {
        setIcon(fieldFolderOpenIcon);
    } else if (!leaf && !expanded) {
        setIcon(fieldFolderClosedIcon);
    }
    try {
        if (value instanceof BioModelNode) {
            BioModelNode node = (BioModelNode) value;
            boolean bLoaded = false;
            // 
            if (node.getUserObject() instanceof String && "Geometry".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Geometry");
                component.setText(label);
                setIcon(fieldGeometryIcon);
            } else if (node.getUserObject() instanceof String && "SimulationContext".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Application");
                component.setText(label);
                setIcon(fieldSimulationContextIcon);
            } else if (node.getUserObject() instanceof String && "Simulation".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Simulation");
                component.setText(label);
                setIcon(fieldSimulationIcon);
            } else if (node.getUserObject() instanceof String && "AppType".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Model Type");
                component.setText(label);
                setIcon(fieldAppTypeIcon);
            } else if (node.getUserObject() instanceof String && "Provenance".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Provenance");
                component.setText("<html><b>" + label + "</b></html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof Annotation) {
                String label = ((Annotation) node.getUserObject()).toString();
                component.setToolTipText("Version Annotation");
                component.setText(label);
                setIcon(null);
            // ------------------------------------------------------
            } else if (node.getUserObject() instanceof String && "PublicationsInfo".equals(node.getRenderHint("type"))) {
                String label = (String) node.getUserObject();
                component.setToolTipText("Publications Info");
                component.setText("<html><b>" + label + "</b></html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoTitle".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Title");
                String text = "<b>" + info.getTitle() + "</b>";
                component.setText("<html>" + text + "</html>");
                setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoAuthors".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Authors");
                String text = "";
                int count = 0;
                for (String author : info.getAuthors()) {
                    if (count > 0) {
                        text += "; ";
                    }
                    text += author;
                    count++;
                }
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoCitation".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("Citation");
                String text = "";
                text += info.getCitation();
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoDoi".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("DOI");
                String text = "<a href=\"" + BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.DOI_URL) + info.getDoi() + "\">" + "DOI: " + info.getDoi() + "</a>";
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoUrl".equals(node.getRenderHint("type"))) {
                PublicationInfo info = (PublicationInfo) node.getUserObject();
                component.setToolTipText("PMID");
                // we know from the tree model that this is not null or empty
                String pmid = info.getUrl();
                if (pmid.contains("list_uids=")) {
                    // ex: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&dopt=Citation&list_uids=12644446
                    pmid = pmid.substring(pmid.lastIndexOf("list_uids=") + "list_uids=".length());
                } else if (pmid.contains("pubmed/")) {
                    // ex: http://www.ncbi.nlm.nih.gov/pubmed/23093806
                    pmid = pmid.substring(pmid.lastIndexOf("/") + 1);
                } else if (pmid.contains("pubmed.ncbi")) {
                    // ex: https://pubmed.ncbi.nlm.nih.gov/34360784/
                    if (pmid.endsWith("/")) {
                        pmid = pmid.substring(0, pmid.length() - 1);
                    }
                    pmid = pmid.substring(pmid.lastIndexOf("/") + 1);
                } else {
                    // something that we don't know how to parse
                    pmid = "?";
                }
                String text = "<a href=\"" + info.getUrl() + "\">" + "PubMed PMID: " + pmid + "</a>";
                component.setText("<html>" + text + "</html>");
                setIcon(null);
            } else if (node.getUserObject() instanceof String && "GeneralFileInfo".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Database File Info");
                String text = "<b>" + (String) node.getUserObject() + "</b>";
                component.setText("<html>" + text + "</html>");
                setIcon(fieldDatabaseIcon);
            } else if (node.getUserObject() instanceof String && "ModelName".equals(node.getRenderHint("type"))) {
                component.setToolTipText("BioModel Name");
                String text = "<b>" + (String) node.getUserObject() + "</b>";
                component.setText("<html>" + text + "</html>");
            // setIcon(fieldTextIcon);
            } else if (node.getUserObject() instanceof KeyValue && "VCellIdentifier".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Virtual Cell Identifier");
                KeyValue key = (KeyValue) node.getUserObject();
                String text = "mathmodel-" + key;
                component.setText("<html>" + text + "</html>");
                setIcon(fieldDatabaseModelKeyIcon);
            } else if (node.getUserObject() instanceof User && "ModelOwner".equals(node.getRenderHint("type"))) {
                String label = ((User) node.getUserObject()).getName();
                component.setToolTipText("Model Owner");
                component.setText("<html>" + label + "</html>");
                setIcon(fieldUserIcon);
            } else if (node.getUserObject() instanceof Date && "ModelDate".equals(node.getRenderHint("type"))) {
                Date date = (Date) node.getUserObject();
                component.setToolTipText("Last Modified");
                component.setText("<html>" + date + "</html>");
                setIcon(fieldCalendarIcon);
            } else if (node.getUserObject() instanceof String && "Permissions".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Permissions");
                String text = (String) node.getUserObject();
                component.setText("<html>" + text + "</html>");
                setIcon(fieldPermissionsIcon);
            } else if (node.getUserObject() instanceof String && "Annotations".equals(node.getRenderHint("type"))) {
                component.setToolTipText("Text Annotation");
                String text = (String) node.getUserObject();
                component.setText("<html>" + text + "</html>");
                setIcon(VCellIcons.noteIcon);
            } else {
                setComponentProperties(component, node.getUserObject());
            }
            if (selectedFont == null && component.getFont() != null) {
                selectedFont = component.getFont().deriveFont(Font.BOLD);
            }
            if (unselectedFont == null && component.getFont() != null) {
                unselectedFont = component.getFont().deriveFont(Font.PLAIN);
            }
            if (bLoaded) {
                component.setFont(selectedFont);
            } else {
                component.setFont(unselectedFont);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    // 
    return component;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) PublicationInfo(org.vcell.util.document.PublicationInfo) JLabel(javax.swing.JLabel) Date(java.util.Date)

Example 3 with PublicationInfo

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

the class VCDocumentDbTreeModel method initFinalTree.

protected static synchronized void initFinalTree(VCDocumentDbTreeModel vcDocumentDbTreeModel, TreeMap<String, BioModelNode> treeMap, User loginUser) {
    BioModelNode ownerNode = (BioModelNode) treeMap.get(loginUser.getName());
    BioModelNode tempNode = new BioModelNode();
    vcDocumentDbTreeModel.myModelsNode.setUserObject(loginUser);
    vcDocumentDbTreeModel.myModelsNode.removeAllChildren();
    for (int c = 0; c < ownerNode.getChildCount(); ) {
        // c stays zero, during each iteration we keep extracting the first element
        BioModelNode childNode = (BioModelNode) ownerNode.getChildAt(c);
        // VCDocumentInfoNode vcdDocumentInfoNode = (VCDocumentInfoNode) childNode.getUserObject();
        // System.out.println(vcdDocumentInfoNode.getVCDocumentInfo().getVersion().getName());
        BioModelNode cloneNode = childNode.clone();
        // this slowly empties ownerNode
        vcDocumentDbTreeModel.myModelsNode.add(childNode);
        boolean isPublic = false;
        for (int i = 0; i < childNode.getChildCount(); i++) {
            BioModelNode versionBioModelNode = (BioModelNode) childNode.getChildAt(i);
            VCDocumentInfo versionVCDocumentInfo = (VCDocumentInfo) versionBioModelNode.getUserObject();
            BigDecimal groupid = versionVCDocumentInfo.getVersion().getGroupAccess().getGroupid();
            if (groupid.equals(GroupAccess.GROUPACCESS_ALL)) {
                isPublic = true;
            }
        // use the form below if want to populate the Other folder with my Public models
        // if (groupid.equals(GroupAccess.GROUPACCESS_ALL)) {
        // use the form below to populate only the Published folder with my Published models
        // if(	versionVCDocumentInfo.getPublicationInfos() != null && versionVCDocumentInfo.getPublicationInfos().length > 0) {
        // BioModelNode versionCloneNode = versionBioModelNode.clone();
        // cloneNode.add(versionCloneNode);
        // }
        }
        if (isPublic) {
            BioModelNode publicClone = BioModelNode.deepClone(childNode);
            // we add all login user models that have at least one public version
            tempNode.add(publicClone);
        }
    // if(cloneNode.getChildCount() > 0) {
    // tempNode.add(cloneNode);					// we keep adding only the clones of the public versions (if any) to the cloneNode
    // }
    // ownerNode gets empty eventually
    }
    for (int c = 0; c < tempNode.getChildCount(); ) {
        // we put back in ownerNode the clone nodes with public versions
        BioModelNode childNode = (BioModelNode) tempNode.getChildAt(c);
        ownerNode.add(childNode);
    }
    // key is publicationKey, value is the list of model nodes associated with the PublicationInfo object
    LinkedHashMap<KeyValue, LinkedList<BioModelNode>> publishedModelsMap = new LinkedHashMap<>();
    LinkedHashMap<KeyValue, LinkedList<BioModelNode>> curatedModelsMap = new LinkedHashMap<>();
    // key is publicationKey, value is a PublicationInfo instance associated to the DOI
    LinkedHashMap<KeyValue, PublicationInfo> publicationsMap = new LinkedHashMap<>();
    vcDocumentDbTreeModel.sharedModelsNode.removeAllChildren();
    boolean bTutorial = vcDocumentDbTreeModel.tutorialModelsNode != null;
    // boolean bEducation = vcDocumentDbTreeModel.educationModelsNode != null;
    boolean bModelBricks = vcDocumentDbTreeModel.modelBricksNode != null;
    boolean bPublished = vcDocumentDbTreeModel.publishedModelsNode != null;
    boolean bCurated = vcDocumentDbTreeModel.curatedModelsNode != null;
    boolean bOther = vcDocumentDbTreeModel.otherModelsNode != null;
    if (bTutorial) {
        vcDocumentDbTreeModel.tutorialModelsNode.removeAllChildren();
    }
    // if(bEducation){vcDocumentDbTreeModel.educationModelsNode.removeAllChildren();}
    if (bModelBricks) {
        vcDocumentDbTreeModel.modelBricksNode.removeAllChildren();
    }
    if (bPublished) {
        vcDocumentDbTreeModel.publishedModelsNode.removeAllChildren();
    }
    if (bCurated) {
        vcDocumentDbTreeModel.curatedModelsNode.removeAllChildren();
    }
    if (bOther) {
        vcDocumentDbTreeModel.otherModelsNode.removeAllChildren();
    }
    for (String username : treeMap.keySet()) {
        // iterate through all users
        // if(username.equals(USER_modelBricks)) {
        // System.out.print(username);
        // System.out.println();
        // }
        BioModelNode userNode = treeMap.get(username);
        // initialize to something
        BioModelNode parentNode = vcDocumentDbTreeModel.sharedModelsNode;
        boolean bSpecificUser = true;
        if ((username.equals(USER_tutorial) || username.equals(USER_tutorial610) || username.equals(USER_tutorial611)) && bTutorial) {
            parentNode = vcDocumentDbTreeModel.tutorialModelsNode;
        // } else if (username.equals(USER_Education) && bEducation) {
        // parentNode = vcDocumentDbTreeModel.educationModelsNode;
        } else if (username.equals(USER_modelBricks) && bModelBricks) {
            parentNode = vcDocumentDbTreeModel.modelBricksNode;
        } else {
            bSpecificUser = false;
        }
        boolean added = false;
        UserNameNode userNameNode = new UserNameNode(username, true);
        for (int c = 0; c < userNode.getChildCount(); c++) {
            // we just navigate through all of them, remove none
            BioModelNode childNode = (BioModelNode) userNode.getChildAt(c);
            // --------------------------------------------- 'other' public folder ---------------------------------------
            if (!bSpecificUser) {
                // if(username.equalsIgnoreCase(loginUser.getName())) {
                // break;			// TODO: we skip login user from now because it needs real time recalculation
                // }
                parentNode = vcDocumentDbTreeModel.otherModelsNode;
                BioModelNode cloneNode = childNode.clone();
                for (int i = 0; i < childNode.getChildCount(); i++) {
                    BioModelNode versionBioModelNode = (BioModelNode) childNode.getChildAt(i);
                    VCDocumentInfo versionVCDocumentInfo = (VCDocumentInfo) versionBioModelNode.getUserObject();
                    BigDecimal groupid = versionVCDocumentInfo.getVersion().getGroupAccess().getGroupid();
                    if (groupid.equals(GroupAccess.GROUPACCESS_ALL)) {
                        if (versionVCDocumentInfo.getPublicationInfos() != null && versionVCDocumentInfo.getPublicationInfos().length > 0) {
                            // we don't show in "Other" anything that is published or curated
                            continue;
                        }
                        // clone the public versions
                        BioModelNode versionCloneNode = versionBioModelNode.clone();
                        // and add them to the clone node
                        cloneNode.add(versionCloneNode);
                    }
                }
                if (cloneNode.getChildCount() > 0) {
                    // we keep adding only the clones of the public versions (if any) to the cloneNode
                    userNameNode.add(cloneNode);
                    if (added == false) {
                        parentNode.add(userNameNode);
                        added = true;
                    }
                }
            } else {
                // anything belonging to users Education, Tutorial or modelBricks go to their own folders
                if (username.equals(USER_modelBricks)) {
                    // revision feb 13, 2020 danv
                    // for modelBricks, only the public clones go the Model Bricks folder
                    // we'll enforce a single version policy so that we won't have to look into versions to see
                    // the individual flag of each
                    VCDocumentInfoNode vcdDocumentInfoNode = (VCDocumentInfoNode) childNode.getUserObject();
                    BigDecimal groupid = vcdDocumentInfoNode.getVCDocumentInfo().getVersion().getGroupAccess().getGroupid();
                    // BigDecimal groupid = versionVCDocumentInfo.getVersion().getGroupAccess().getGroupid();
                    if (groupid.equals(GroupAccess.GROUPACCESS_ALL)) {
                        // only the public bricks go here
                        BioModelNode clone = BioModelNode.deepClone(childNode);
                        parentNode.add(clone);
                    }
                } else {
                    // for all the other special users we keep the old behavior
                    BioModelNode clone = BioModelNode.deepClone(childNode);
                    parentNode.add(clone);
                }
            }
        }
        // -------------------------------------------- shared folder -----------------------------------------------
        added = false;
        userNameNode = new UserNameNode(username, true);
        for (int c = 0; c < userNode.getChildCount(); c++) {
            // we just navigate through all of them, remove none
            if (username.equalsIgnoreCase(loginUser.getName())) {
                // the login user can't share with himself
                break;
            }
            BioModelNode childNode = (BioModelNode) userNode.getChildAt(c);
            if (!bSpecificUser) {
                parentNode = vcDocumentDbTreeModel.sharedModelsNode;
                BioModelNode cloneNode = childNode.clone();
                for (int i = 0; i < childNode.getChildCount(); i++) {
                    BioModelNode versionBioModelNode = (BioModelNode) childNode.getChildAt(i);
                    VCDocumentInfo versionVCDocumentInfo = (VCDocumentInfo) versionBioModelNode.getUserObject();
                    BigDecimal groupid = versionVCDocumentInfo.getVersion().getGroupAccess().getGroupid();
                    // System.out.println("    " + groupid);
                    if (groupid.equals(GroupAccess.GROUPACCESS_ALL) || groupid.equals(GroupAccess.GROUPACCESS_NONE)) {
                        // we skip private and public versions (that includes published versions)
                        continue;
                    }
                    // clone the shared versions
                    BioModelNode versionCloneNode = versionBioModelNode.clone();
                    // and add them to the clone node
                    cloneNode.add(versionCloneNode);
                }
                if (cloneNode.getChildCount() > 0) {
                    // we keep adding only the clones of the shared versions (if any) to the cloneNode
                    userNameNode.add(cloneNode);
                    if (added == false) {
                        // now that we know for sure that the user name node is populated, we add it to the shared node if it's not there already
                        parentNode.add(userNameNode);
                        added = true;
                    }
                }
            } else {
                if (username.equals(USER_modelBricks)) {
                    // revision feb 13, 2020 danv
                    // for modelBricks, we make a user name node and we populate it with all the bricks shared with
                    // the login user
                    // we'll enforce a single version policy so that we won't have to look into versions to see
                    // the individual flag of each
                    parentNode = vcDocumentDbTreeModel.sharedModelsNode;
                    VCDocumentInfoNode vcdDocumentInfoNode = (VCDocumentInfoNode) childNode.getUserObject();
                    BigDecimal groupid = vcdDocumentInfoNode.getVCDocumentInfo().getVersion().getGroupAccess().getGroupid();
                    if (groupid.equals(GroupAccess.GROUPACCESS_ALL) || groupid.equals(GroupAccess.GROUPACCESS_NONE)) {
                        // nothing to do here with public or private bricks
                        ;
                    } else {
                        BioModelNode cloneNode = BioModelNode.deepClone(childNode);
                        userNameNode.add(cloneNode);
                        if (added == false) {
                            // now that we know for sure that the user name node is populated, we add it to the shared node if it's not there already
                            parentNode.add(userNameNode);
                            added = true;
                        }
                    }
                }
            }
        }
        for (int c = 0; c < userNode.getChildCount(); ) {
            BioModelNode versionableNode = (BioModelNode) userNode.getChildAt(c);
            // Search through versions of BM/MM to see if any are published
            for (int i = 0; i < versionableNode.getChildCount(); ) {
                // the versions
                BioModelNode versionBioModelNode = (BioModelNode) versionableNode.getChildAt(i);
                VCDocumentInfo versionVCDocumentInfo = (VCDocumentInfo) versionBioModelNode.getUserObject();
                PublicationInfo[] piArray = versionVCDocumentInfo.getPublicationInfos();
                if (piArray != null && piArray.length > 0) {
                    // we already placed this version in Curated, no need to look for more publications for curated
                    boolean foundCurated = false;
                    // same as above for published
                    boolean foundPublished = false;
                    for (PublicationInfo pi : piArray) {
                        KeyValue key = pi.getPublicationKey();
                        if (!publicationsMap.containsKey(key)) {
                            publicationsMap.put(key, pi);
                        }
                        if (versionVCDocumentInfo.getVersion().getFlag().compareEqual(org.vcell.util.document.VersionFlag.Published)) {
                            // published
                            if (foundPublished) {
                                continue;
                            }
                            // String vn = versionVCDocumentInfo.getVersion().getName();
                            // String vo = versionVCDocumentInfo.getVersion().getOwner().getName();
                            // String vk = versionVCDocumentInfo.getVersion().getVersionKey().toString();
                            // System.out.println(vk);
                            LinkedList<BioModelNode> modelsList;
                            if (publishedModelsMap.containsKey(key)) {
                                modelsList = publishedModelsMap.get(key);
                            } else {
                                modelsList = new LinkedList<>();
                            }
                            BioModelNode newPublishedNode = new BioModelNode(new VCDocumentInfoNode(versionVCDocumentInfo), true);
                            BioModelNode clonedNode = versionBioModelNode.clone();
                            newPublishedNode.add(clonedNode);
                            modelsList.add(newPublishedNode);
                            publishedModelsMap.put(key, modelsList);
                            foundPublished = true;
                        } else {
                            // curated
                            if (foundCurated) {
                                // otherwise we may add the same version multiple times to Curated, once for each PublicationInfo
                                continue;
                            }
                            // the code below shows by author + model name
                            BioModelNode newCuratedNode = new BioModelNode(new VCDocumentInfoNode(versionVCDocumentInfo), true);
                            BioModelNode clonedNode = versionBioModelNode.clone();
                            newCuratedNode.add(clonedNode);
                            vcDocumentDbTreeModel.curatedModelsNode.add(newCuratedNode);
                            // the code below shows by Publication Title
                            // LinkedList<BioModelNode> modelsList;
                            // if(curatedModelsMap.containsKey(key)) {
                            // modelsList = curatedModelsMap.get(key);
                            // } else {
                            // modelsList = new LinkedList<> ();
                            // }
                            // BioModelNode newCuratedNode = new BioModelNode(new VCDocumentInfoNode(versionVCDocumentInfo), true);
                            // BioModelNode clonedNode = versionBioModelNode.clone();
                            // newCuratedNode.add(clonedNode);
                            // modelsList.add(newCuratedNode);
                            // curatedModelsMap.put(key, modelsList);
                            foundCurated = true;
                        }
                    }
                }
                versionableNode.remove(i);
            }
            userNode.remove(c);
        }
    }
    shallowOrderByPublication(publishedModelsMap, publicationsMap);
    for (KeyValue key : publishedModelsMap.keySet()) {
        LinkedList<BioModelNode> modelsList = publishedModelsMap.get(key);
        PublicationInfo pi = publicationsMap.get(key);
        BioModelNode newPublicationNode = new BioModelNode.PublicationInfoNode(pi, true);
        for (BioModelNode node : modelsList) {
            newPublicationNode.add(node);
        }
        vcDocumentDbTreeModel.publishedModelsNode.add(newPublicationNode);
    }
    // for (int c = 0; c < vcDocumentDbTreeModel.modelBricksNode.getChildCount(); c++) {
    if (bModelBricks) {
        for (int i = 0; i < vcDocumentDbTreeModel.modelBricksNode.getChildCount(); ) {
            BioModelNode childNode = (BioModelNode) vcDocumentDbTreeModel.modelBricksNode.getChildAt(0);
            vcDocumentDbTreeModel.curatedModelsNode.add(childNode);
        }
    }
}
Also used : UserNameNode(cbit.vcell.desktop.BioModelNode.UserNameNode) KeyValue(org.vcell.util.document.KeyValue) PublicationInfo(org.vcell.util.document.PublicationInfo) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) VCDocumentInfoNode(cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode) PublicationInfoNode(cbit.vcell.desktop.BioModelNode.PublicationInfoNode)

Example 4 with PublicationInfo

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

the class MathModelCellRenderer method getTreeCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    // 
    try {
        if (value instanceof UserNameNode) {
            UserNameNode node = (UserNameNode) value;
            String label = (String) node.getUserObject();
            String qualifier = "";
            if (sessionUser != null && sessionUser.getName().contentEquals(label)) {
                String colorString = (sel) ? "white" : "#8B0000";
                qualifier = "<font color=\"" + colorString + "\"><b>" + label + "</b></font>";
            } else {
                String colorString = (sel) ? "white" : "black";
                qualifier = "<font color=\"" + colorString + "\">" + label + "</font>";
            }
            component.setToolTipText(label);
            component.setText("<html>" + qualifier + " (" + node.getChildCount() + ")" + "</html>");
            component.setIcon(fieldFolderUserIcon);
        } else if (value instanceof PublicationInfoNode) {
            BioModelNode node = (PublicationInfoNode) value;
            PublicationInfo pi = (PublicationInfo) node.getUserObject();
            String label = pi.getTitle();
            String name = "";
            if (pi.getAuthors() != null && pi.getAuthors().length > 0) {
                name = pi.getAuthors()[0];
            }
            if (name.contains(",")) {
                name = name.substring(0, name.indexOf(","));
            }
            int year = Integer.parseInt((new SimpleDateFormat("yyyy")).format(pi.getPubDate()));
            String label2 = name + " " + year + " " + label;
            int maxLen = MaxPublicationLabelLength + (node.getChildCount() > 1 ? 0 : 4);
            if (label2.length() > maxLen) {
                label2 = label2.substring(0, maxLen) + "...";
            }
            if (node.getChildCount() > 1) {
                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                String suffix = sel ? "" : "</span>";
                label += prefix + " (" + node.getChildCount() + ")" + suffix;
                label2 += prefix + " (" + node.getChildCount() + ")" + suffix;
            }
            component.setText("<html>" + label2 + "</html>");
            component.setToolTipText("<html>" + label + "</html>");
            if (pi.getPubDate().compareTo(Calendar.getInstance().getTime()) > 0) {
                // sanity check
                setIcon(fieldFolderWarningIcon);
            } else if (pi.getDoi() == null) {
                setIcon(fieldFolderWarningIcon);
            } else if (name.contains(" ")) {
                setIcon(fieldFolderWarningIcon);
            } else {
                // publications have their own icon
                setIcon(fieldPublishedPublicationIcon);
            }
        } else if (value instanceof BioModelNode) {
            BioModelNode node = (BioModelNode) value;
            Object userObject = node.getUserObject();
            if (userObject instanceof User) {
                String label = null;
                if (sessionUser != null && sessionUser.compareEqual((User) userObject)) {
                    label = "My MathModels (" + ((User) userObject).getName() + ") (" + node.getChildCount() + ")";
                } else {
                    label = ((User) userObject).getName() + "                             ";
                }
                component.setToolTipText(label);
                component.setText(label);
            } else if (userObject instanceof MathModelInfo) {
                // a math model version
                MathModelInfo mathModelInfo = (MathModelInfo) userObject;
                if (mathModelInfo.getPublicationInfos() != null && mathModelInfo.getPublicationInfos().length > 0) {
                    if (mathModelInfo.getVersion().getFlag().compareEqual(org.vcell.util.document.VersionFlag.Published)) {
                        component.setText("(Published) " + component.getText());
                    } else {
                        component.setText("(Curated) " + component.getText());
                    }
                } else if (mathModelInfo.getVersion().getFlag().compareEqual(org.vcell.util.document.VersionFlag.Archived)) {
                    component.setText("(Archived) " + component.getText());
                }
                String str = component.getToolTipText();
                if (str != null && !str.isEmpty()) {
                    component.setToolTipText(str + " " + mathModelInfo.getVersion().getVersionKey());
                }
                // we change color of version if it's in the Other folder (Uncurated) and belongs to login user
                Object pNode = node.getParent();
                if (pNode instanceof BioModelNode) {
                    pNode = ((BioModelNode) pNode).getParent();
                    if (pNode instanceof BioModelNode && ((BioModelNode) pNode).getUserObject() instanceof String) {
                        str = (String) ((BioModelNode) pNode).getUserObject();
                        pNode = ((BioModelNode) pNode).getParent();
                        if (((BioModelNode) pNode).getUserObject() instanceof String && str.equalsIgnoreCase(sessionUser.getName())) {
                            str = (String) ((BioModelNode) pNode).getUserObject();
                            if (str.equals(VCDocumentDbTreeModel.Other_MathModels)) {
                                // GRAY
                                String prefix = sel ? "" : "<span style=\"color:#808080\">";
                                String suffix = sel ? "" : "</span>";
                                String str1 = prefix + component.getText() + suffix;
                                setText("<html>" + str1 + "</html>");
                            }
                        }
                    }
                }
            } else if (userObject instanceof VCDocumentInfoNode) {
                VCDocumentInfoNode infonode = (VCDocumentInfoNode) userObject;
                User nodeUser = infonode.getVCDocumentInfo().getVersion().getOwner();
                String modelName = infonode.getVCDocumentInfo().getVersion().getName();
                String username = nodeUser.getName();
                if (username.equals(VCDocumentDbTreeModel.USER_tutorial)) // || username.equals(VCDocumentDbTreeModel.USER_Education)
                {
                    if (node.getParent() instanceof BioModelNode && ((BioModelNode) node.getParent()).getUserObject() instanceof String) {
                        String pName = (String) ((BioModelNode) node.getParent()).getUserObject();
                        if (pName.equals(VCDocumentDbTreeModel.Curated_MathModels)) {
                            // we add the user name to Curated
                            setText("<html><b>" + nodeUser.getName() + " </b> : " + modelName + "</html>");
                        } else {
                            // keep it simple for Education and Tutorial
                            component.setText(modelName);
                        }
                    } else {
                        component.setText(modelName);
                    }
                } else if (nodeUser.compareEqual(sessionUser)) {
                    Object pNode = node.getParent();
                    if (pNode instanceof BioModelNode) {
                        BioModelNode parent = (BioModelNode) pNode;
                        if (parent.getUserObject() instanceof String) {
                            // the Published, Curated and Other folders are the only
                            // ones where the parent user object is a String
                            String str = (String) parent.getUserObject();
                            if (str.equals(VCDocumentDbTreeModel.Published_MathModels) || str.equals(VCDocumentDbTreeModel.Curated_MathModels)) /*|| str.equals(VCDocumentDbTreeModel.Other_MathModels)*/
                            {
                                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                String suffix = sel ? "" : "</span>";
                                setText("<html><b>" + prefix + nodeUser.getName() + suffix + "</b>  : " + modelName + "</html>");
                            } else {
                                // in the Other folder / owner folder
                                // GRAY
                                String prefix = sel ? "" : "<span style=\"color:#808080\">";
                                String suffix = sel ? "" : "</span>";
                                String str1 = prefix + modelName + suffix;
                                if (node.getChildCount() > 1) {
                                    prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                    suffix = sel ? "" : "</span>";
                                    str1 += prefix + " (" + node.getChildCount() + ")" + suffix;
                                }
                                // the name of the model container - which holds the versions
                                setText("<html>" + str1 + "</html>");
                            }
                        } else if (parent.getUserObject() instanceof PublicationInfo) {
                            String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                            String suffix = sel ? "" : "</span>";
                            setText("<html><b>" + prefix + nodeUser.getName() + suffix + "</b>  : " + modelName + "</html>");
                        } else {
                            String str = modelName;
                            if (node.getChildCount() > 1) {
                                String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                                String suffix = sel ? "" : "</span>";
                                str += prefix + " (" + node.getChildCount() + ")" + suffix;
                            }
                            setText("<html>" + str + "</html>");
                        }
                    } else {
                        // unreachable
                        setText(modelName);
                    }
                } else {
                    Object pNode = node.getParent();
                    if (pNode instanceof UserNameNode) {
                        // if we are inside an UserName folder (like Shared or Uncurated public),
                        // don't prefix again the model with the user name
                        String str = modelName;
                        if (node.getChildCount() > 1) {
                            String prefix = sel ? "" : "<span style=\"color:#8B0000\">";
                            String suffix = sel ? "" : "</span>";
                            str += prefix + " (" + node.getChildCount() + ")" + suffix;
                        }
                        setText("<html>" + str + "</html>");
                    } else {
                        // content of "Published" folder
                        setText("<html><b>" + nodeUser.getName() + " </b> : " + modelName + "</html>");
                    }
                }
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    // 
    if (component.getToolTipText() == null || component.getToolTipText().length() == 0) {
        component.setToolTipText(component.getText());
    }
    return component;
}
Also used : UserNameNode(cbit.vcell.desktop.BioModelNode.UserNameNode) User(org.vcell.util.document.User) PublicationInfo(org.vcell.util.document.PublicationInfo) JLabel(javax.swing.JLabel) MathModelInfo(org.vcell.util.document.MathModelInfo) SimpleDateFormat(java.text.SimpleDateFormat) PublicationInfoNode(cbit.vcell.desktop.BioModelNode.PublicationInfoNode)

Example 5 with PublicationInfo

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

the class BioModelMetaDataPanel method getJTree1.

private JTree getJTree1() {
    if (tree == null) {
        try {
            tree = new JTree();
            tree.setName("JTree1");
            tree.setToolTipText("Contents of saved BioModel");
            tree.setEnabled(true);
            tree.setRootVisible(false);
            tree.setRequestFocusEnabled(false);
            tree.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 1) {
                        DefaultMutableTreeNode value = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                        if (value instanceof BioModelNode) {
                            BioModelNode node = (BioModelNode) value;
                            try {
                                if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoDoi".equals(node.getRenderHint("type"))) {
                                    PublicationInfo info = (PublicationInfo) node.getUserObject();
                                    Desktop.getDesktop().browse(new URI(BeanUtils.getDynamicClientProperties().getProperty(PropertyLoader.DOI_URL) + info.getDoi()));
                                } else if (node.getUserObject() instanceof PublicationInfo && "PublicationInfoUrl".equals(node.getRenderHint("type"))) {
                                    PublicationInfo info = (PublicationInfo) node.getUserObject();
                                    Desktop.getDesktop().browse(new URI(info.getUrl()));
                                }
                            } catch (URISyntaxException | IOException ex) {
                                handleException(ex);
                            }
                        }
                    }
                }
            });
        } catch (java.lang.Throwable ex) {
            handleException(ex);
        }
    }
    return tree;
}
Also used : JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PublicationInfo(org.vcell.util.document.PublicationInfo) MouseAdapter(java.awt.event.MouseAdapter) URI(java.net.URI)

Aggregations

PublicationInfo (org.vcell.util.document.PublicationInfo)15 User (org.vcell.util.document.User)7 BioModelInfo (org.vcell.util.document.BioModelInfo)6 Date (java.util.Date)5 JLabel (javax.swing.JLabel)5 KeyValue (org.vcell.util.document.KeyValue)5 VCDocumentInfoNode (cbit.vcell.desktop.VCellBasicCellRenderer.VCDocumentInfoNode)4 SimpleDateFormat (java.text.SimpleDateFormat)4 MathModelInfo (org.vcell.util.document.MathModelInfo)4 VersionInfo (org.vcell.util.document.VersionInfo)4 PublicationInfoNode (cbit.vcell.desktop.BioModelNode.PublicationInfoNode)3 UserNameNode (cbit.vcell.desktop.BioModelNode.UserNameNode)3 GeometryInfo (cbit.vcell.geometry.GeometryInfo)3 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 RecordChangedException (cbit.sql.RecordChangedException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Set (java.util.Set)2