Skip to content

Commit

Permalink
Merge pull request #10424 from averyniceday/java11dev
Browse files Browse the repository at this point in the history
Replace DB Prop Assertion with Warning
  • Loading branch information
dippindots authored Oct 9, 2023
2 parents f25e15a + b3bc8b2 commit 80f067d
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import org.mskcc.cbio.portal.util.DatabaseProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Data source that self-initializes based on cBioPortal configuration.
*/
public class JdbcDataSource extends BasicDataSource {

private static final Logger LOG = LoggerFactory.getLogger(JdbcDataSource.class);

public JdbcDataSource () {
DatabaseProperties dbProperties = DatabaseProperties.getInstance();
Expand All @@ -20,17 +24,17 @@ public JdbcDataSource () {
String database = dbProperties.getDbName();
String enablePooling = (!StringUtils.isBlank(dbProperties.getDbEnablePooling())) ? dbProperties.getDbEnablePooling(): "false";
String connectionURL = dbProperties.getConnectionURL();
Assert.isTrue(
!defined(host) && !defined(database) && !defined(dbProperties.getDbUseSSL()),
"\n----------------------------------------------------------------------------------------------------------------" +
"-- Connection error:\n" +
"-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties.\n" +
"-- Please remove these properties and use the 'db.connection_string' property instead. See https://docs.cbioportal.org/deployment/customization/portal.properties-reference/\n" +
"-- for assistance on building a valid connection string.\n" +
"----------------------------------------------------------------------------------------------------------------\n"
);

if (defined(host) || defined(database) || defined(dbProperties.getDbUseSSL())) {
LOG.warn("\n----------------------------------------------------------------------------------------------------------------" +
"-- Connection error:\n" +
"-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties.\n" +
"-- Please remove these properties and use the 'db.connection_string' property instead. See https://docs.cbioportal.org/deployment/customization/portal.properties-reference/\n" +
"-- for assistance on building a valid connection string.\n" +
"----------------------------------------------------------------------------------------------------------------\n"
);
}

Assert.hasText(userName, errorMessage("username", "db.user"));
Assert.hasText(password, errorMessage("password", "db.password"));
Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "db.driver"));
Expand All @@ -53,11 +57,11 @@ public JdbcDataSource () {
this.setValidationQuery("SELECT 1");
this.setJmxName("org.cbioportal:DataSource=" + database);
}

private String errorMessage(String displayName, String propertyName) {
return String.format("No %s provided for database connection. Please set '%s' in portal.properties.", displayName, propertyName);
}

private boolean defined(String property) {
return property != null && !property.isEmpty();
}
Expand Down

0 comments on commit 80f067d

Please sign in to comment.