|
22 | 22 | import org.pentaho.database.service.DatabaseDialectService; |
23 | 23 | import org.pentaho.database.util.DatabaseUtil; |
24 | 24 | import org.pentaho.di.core.encryption.Encr; |
| 25 | +import org.pentaho.di.core.variables.VariableSpace; |
| 26 | +import org.pentaho.di.core.variables.Variables; |
25 | 27 | import org.pentaho.platform.api.engine.IAuthorizationPolicy; |
26 | 28 | import org.pentaho.platform.api.engine.PentahoAccessControlException; |
| 29 | +import org.pentaho.platform.dataaccess.datasource.utils.DatabaseConnectionUtils; |
27 | 30 | import org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException; |
28 | 31 | import org.pentaho.platform.dataaccess.datasource.wizard.service.api.ConnectionsApi; |
29 | 32 | import org.pentaho.platform.dataaccess.datasource.wizard.service.impl.utils.UtilHtmlSanitizer; |
@@ -61,6 +64,7 @@ public class ConnectionService implements ConnectionsApi { |
61 | 64 | private static final Log logger = LogFactory.getLog( ConnectionService.class ); |
62 | 65 | protected static final String MEDIA_TYPE_JSON = "application/json"; |
63 | 66 | protected static final String MEDIA_TYPE_TEXT_PLAIN = "text/plain"; |
| 67 | + protected static final String CONNECTION_LEVEL_REPOSITORY = "Repository"; |
64 | 68 |
|
65 | 69 | private ConnectionServiceImpl connectionService; |
66 | 70 | private DatabaseDialectService dialectService; |
@@ -283,7 +287,7 @@ public IDatabaseConnectionPoolParameterList getPoolingParameters() { |
283 | 287 | @Override |
284 | 288 | public String testConnection( IDatabaseConnection databaseConnection, String projectDir ) { |
285 | 289 | try { |
286 | | - applySavedPassword( databaseConnection, projectDir ); |
| 290 | + applySavedPassword( databaseConnection, projectDir, true ); |
287 | 291 | boolean success = connectionService.testConnection( databaseConnection ); |
288 | 292 | if ( success ) { |
289 | 293 | return Messages.getString( "ConnectionServiceImpl.INFO_0001_CONNECTION_SUCCEED", databaseConnection |
@@ -319,7 +323,7 @@ public String testConnection( IDatabaseConnection databaseConnection ) { |
319 | 323 | public void updateConnection( IDatabaseConnection databaseConnection, String projectDir ) { |
320 | 324 | sanitizer.sanitizeConnectionParameters( databaseConnection ); |
321 | 325 | try { |
322 | | - applySavedPassword( databaseConnection ); |
| 326 | + applySavedPassword( databaseConnection, false ); |
323 | 327 | connectionService.updateConnection( databaseConnection ); |
324 | 328 | // explicitly return a 200 instead of 204 No Content |
325 | 329 | throw new WebApplicationException( Response.ok().build() ); |
@@ -358,12 +362,22 @@ public void updateConnection( IDatabaseConnection databaseConnection ) { |
358 | 362 | /** |
359 | 363 | * If password is empty, that means connection sent from UI and user didn't change password. Since we cleaned password |
360 | 364 | * during sending to UI, we need to use stored password. |
| 365 | + * |
| 366 | + * @param conn the connection to update |
| 367 | + * @param projectDir Optional project directory (used by subclasses) |
| 368 | + * @param resolveVariables whether to resolve variables in the connection |
361 | 369 | */ |
362 | | - protected void applySavedPassword( IDatabaseConnection conn, String projectDir ) throws ConnectionServiceException { |
363 | | - applySavedPassword( conn ); |
| 370 | + protected void applySavedPassword( IDatabaseConnection conn, String projectDir, boolean resolveVariables ) throws ConnectionServiceException { |
| 371 | + applySavedPassword( conn, resolveVariables ); |
364 | 372 | } |
365 | 373 |
|
366 | | - private void applySavedPassword( IDatabaseConnection conn ) throws ConnectionServiceException { |
| 374 | + private void applySavedPassword( IDatabaseConnection conn, boolean resolveVariables ) throws ConnectionServiceException { |
| 375 | + |
| 376 | + if ( resolveVariables ) { |
| 377 | + VariableSpace variables = Variables.getADefaultVariableSpace(); |
| 378 | + DatabaseConnectionUtils.applyEnvironmentSubstitution( conn, variables ); |
| 379 | + } |
| 380 | + |
367 | 381 | if ( StringUtils.isBlank( conn.getPassword() ) ) { |
368 | 382 | IDatabaseConnection savedConn; |
369 | 383 | if ( conn.getId() != null ) { |
@@ -519,19 +533,30 @@ private void validateAccess() throws PentahoAccessControlException { |
519 | 533 | * |
520 | 534 | */ |
521 | 535 | @Override |
522 | | - public IDatabaseConnectionList getConnections( String projectDir ) { |
| 536 | + public IDatabaseConnectionList getConnections( String projectDir, Boolean allLevels ) { |
523 | 537 | try { |
524 | 538 | IDatabaseConnectionList databaseConnections = new DefaultDatabaseConnectionList(); |
525 | 539 | List<IDatabaseConnection> conns = connectionService.getConnections( true ); |
| 540 | + for ( IDatabaseConnection conn : conns ) { |
| 541 | + setConnectionLevel( conn, CONNECTION_LEVEL_REPOSITORY ); |
| 542 | + } |
526 | 543 | databaseConnections.setDatabaseConnections( conns ); |
527 | 544 | return databaseConnections; |
528 | 545 | } catch ( ConnectionServiceException ex ) { |
529 | 546 | throw new WebApplicationException( ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR ); |
530 | 547 | } |
531 | 548 | } |
532 | 549 |
|
| 550 | + public IDatabaseConnectionList getConnections( String projectDir ) { |
| 551 | + return getConnections( projectDir, Boolean.FALSE ); |
| 552 | + } |
| 553 | + |
533 | 554 | public IDatabaseConnectionList getConnections() { |
534 | | - return getConnections( null ); |
| 555 | + return getConnections( null, Boolean.FALSE ); |
| 556 | + } |
| 557 | + |
| 558 | + protected void setConnectionLevel( IDatabaseConnection connection, String level ) { |
| 559 | + connection.setLevel( level ); |
535 | 560 | } |
536 | 561 |
|
537 | 562 | /** |
|
0 commit comments