vivo-project / VIVO

VIVO is an extensible semantic web application for research discovery and showcasing scholarly work
http://vivoweb.org
BSD 3-Clause "New" or "Revised" License
208 stars 131 forks source link

VIVO-1077: Stop the application from connecting to the DB when configured to use Virtuoso #2761

Open chenejac opened 9 years ago

chenejac commented 9 years ago

Paul Albert (Migrated from VIVO-1077) said:

Eliza Chan implemented two fixes to ensure VIVO can talk to Virtuoso. He thought it would be useful to include in core. Let me know if any of this doesn't make sense.

i) /vivo-rel-1.7-wcmc-virtuoso/vitro-core/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/GuardAgainstUnmigratedRDB.java

Added the following check on configuration:

@Override

public void contextInitialized(ServletContextEvent sce) {

    ServletContext ctx = sce.getServletContext();

    ConfigurationProperties props = ConfigurationProperties.getBean(ctx);

    StartupStatus ss = StartupStatus.getBean(ctx);

    String url = props.getProperty(PROPERTY_DB_URL);

    String username = props.getProperty(PROPERTY_DB_USERNAME);

    String password = props.getProperty(PROPERTY_DB_PASSWORD);

    Properties connectionProps = new Properties();

    connectionProps.put("user", username);

    connectionProps.put("password", password);

    // Eliza: if using SPARQL endpoint, skip DB connection

    String endPointUri = props.getProperty(PROPERTY_ENDPOINT_URI);

    if (endPointUri == null || endPointUri.isEmpty()) {

        try (Connection conn = DriverManager

                .getConnection(url, connectionProps)) {

            boolean hasRdb = checkForRdbTables(conn);

            boolean hasBeenConverted = checkForConversionTable(conn);

            if (hasRdb && !hasBeenConverted) {

                ss.fatal(this, String.format(MESSAGE_PROBLEM, url));

                ss.fatal(this, String.format(MESSAGE_TECHNICAL, url));

                ss.fatal(this, String.format(MESSAGE_WHAT_NOW, url));

            }

        } catch (SQLException e) {

            ss.fatal(this, "Can't connect to the database: " + PROPERTY_DB_URL

                    + "='" + url + "', " + PROPERTY_DB_USERNAME + "='"

                    + username + "'", e);

            return;

        }

    }

...

ii) /vivo-rel-1.7-wcmc-virtuoso/vitro-core/webapp/src/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSmokeTests.java

Added the following check on configuration:

@Override

public void contextInitialized(ServletContextEvent sce) {

    ServletContext ctx = sce.getServletContext();

    ConfigurationProperties props = ConfigurationProperties.getBean(ctx);

    StartupStatus ss = StartupStatus.getBean(ctx);

    checkHomeDirectory(ctx, props, ss);

    // Eliza: if using SPARQL endpoint, there is no need to test database connection

    String endPointUri = props.getProperty(PROPERTY_ENDPOINT_URI);

    if (endPointUri == null || endPointUri.isEmpty()) {

        checkDatabaseConnection(ctx, props, ss);

    }

...

chenejac commented 3 years ago

Is this linked with VIVO-1025?