Search in sources :

Example 1 with DatabaseTimestamp

use of massbank.db.DatabaseTimestamp in project MassBank-web by MassBank.

the class Contents method init.

public void init() throws ServletException {
    try {
        result = new SearchExecution(null).exec(new RecordIndexCount());
        // construct and show pie charts
        int MAX_DISP_DATA = 10;
        PieDataset siteGraphData = createDataset(result.mapSiteToRecordCount, MAX_DISP_DATA);
        PieDataset instGraphData = createDataset(result.mapInstrumentToRecordCount, MAX_DISP_DATA);
        PieDataset msGraphData = createDataset(result.mapMsTypeToRecordCount, MAX_DISP_DATA);
        int siteTopNum = (siteGraphData.getItemCount() < MAX_DISP_DATA) ? siteGraphData.getItemCount() : MAX_DISP_DATA;
        int instTopNum = (instGraphData.getItemCount() < MAX_DISP_DATA) ? instGraphData.getItemCount() : MAX_DISP_DATA;
        int msTopNum = (msGraphData.getItemCount() < MAX_DISP_DATA) ? msGraphData.getItemCount() : MAX_DISP_DATA;
        JFreeChart sitechart = drawDataset(siteGraphData, "Contributor top " + siteTopNum);
        JFreeChart instchart = drawDataset(instGraphData, "Instrument Type top " + instTopNum);
        JFreeChart mschart = drawDataset(msGraphData, "MS Type top " + msTopNum);
        SVGGraphics2D g2 = new SVGGraphics2D(900, 350);
        Rectangle r = new Rectangle(0, 0, 900, 350);
        sitechart.draw(g2, r);
        sitechartSVG = g2.getSVGElement();
        instchart.draw(g2, r);
        instchartSVG = g2.getSVGElement();
        mschart.draw(g2, r);
        mschartSVG = g2.getSVGElement();
        // get the current database timestamp
        timestamp = new DatabaseTimestamp();
    } catch (SQLException | ConfigurationException e) {
        logger.error(e.getMessage());
    }
}
Also used : RecordIndexCount(massbank.web.recordindex.RecordIndexCount) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) SQLException(java.sql.SQLException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) SearchExecution(massbank.web.SearchExecution) Rectangle(java.awt.Rectangle) SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) DatabaseTimestamp(massbank.db.DatabaseTimestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with DatabaseTimestamp

use of massbank.db.DatabaseTimestamp in project MassBank-web by MassBank.

the class SiteMapServlet method init.

public void init() throws ServletException {
    logger.trace("ServletContext.TEMPDIR: " + getServletContext().getAttribute(ServletContext.TEMPDIR));
    File tmpdir = (File) getServletContext().getAttribute(ServletContext.TEMPDIR);
    // remove old index
    for (File file : tmpdir.listFiles()) {
        if (file.getName().matches("sitemap.*\\.xml$")) {
            logger.trace("Remove old sitemap: " + file.toString());
            file.delete();
        }
    }
    try {
        // create sitemap generator
        String sitemapbaseurl = Config.get().SitemapBaseURL();
        if (!sitemapbaseurl.endsWith("/"))
            sitemapbaseurl = sitemapbaseurl + "/";
        WebSitemapGenerator wsg = new WebSitemapGenerator(sitemapbaseurl, tmpdir);
        // add static content
        wsg.addUrl(sitemapbaseurl);
        wsg.addUrl(sitemapbaseurl + "Index");
        wsg.addUrl(sitemapbaseurl + "Search");
        wsg.addUrl(sitemapbaseurl + "RecordIndex");
        // add dynamic content
        DatabaseManager databaseManager = new DatabaseManager("MassBank");
        PreparedStatement stmnt = databaseManager.getConnection().prepareStatement("SELECT ACCESSION FROM RECORD");
        ResultSet res = stmnt.executeQuery();
        while (res.next()) {
            wsg.addUrl(sitemapbaseurl + "RecordDisplay?id=" + res.getString(1));
        }
        databaseManager.closeConnection();
        // write new sitemaps
        List<File> sitemaps = wsg.write();
        logger.trace("File(s) written:\n" + sitemaps);
        // write sitemap index
        SitemapIndexGenerator sig = new SitemapIndexGenerator(sitemapbaseurl, new File(tmpdir, "sitemapindex.xml"));
        for (File sitemap : sitemaps) {
            sig.addUrl(sitemapbaseurl + "sitemap/" + sitemap.getName());
        }
        sig.write();
        // get the current database timestamp
        timestamp = new DatabaseTimestamp();
    } catch (ConfigurationException | MalformedURLException | SQLException e) {
        logger.error(e.getMessage());
    }
}
Also used : SitemapIndexGenerator(com.redfin.sitemapgenerator.SitemapIndexGenerator) WebSitemapGenerator(com.redfin.sitemapgenerator.WebSitemapGenerator) MalformedURLException(java.net.MalformedURLException) DatabaseManager(massbank.db.DatabaseManager) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) ResultSet(java.sql.ResultSet) DatabaseTimestamp(massbank.db.DatabaseTimestamp) File(java.io.File)

Aggregations

SQLException (java.sql.SQLException)2 DatabaseTimestamp (massbank.db.DatabaseTimestamp)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 SitemapIndexGenerator (com.redfin.sitemapgenerator.SitemapIndexGenerator)1 WebSitemapGenerator (com.redfin.sitemapgenerator.WebSitemapGenerator)1 Rectangle (java.awt.Rectangle)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 DatabaseManager (massbank.db.DatabaseManager)1 SearchExecution (massbank.web.SearchExecution)1 RecordIndexCount (massbank.web.recordindex.RecordIndexCount)1 JFreeChart (org.jfree.chart.JFreeChart)1 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)1 PieDataset (org.jfree.data.general.PieDataset)1 SVGGraphics2D (org.jfree.graphics2d.svg.SVGGraphics2D)1