Search in sources :

Example 1 with WsmWorkspaceApplication

use of bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationServiceTest method enumerateCheck.

private void enumerateCheck(boolean leoEnabled, boolean carmenEnabled, boolean normEnabled) {
    List<WsmWorkspaceApplication> wsmAppList = appService.listWorkspaceApplications(USER_REQUEST, workspaceId, 0, 10);
    // There may be stray applications in the DB, so we make sure that we at least have ours
    assertThat(wsmAppList.size(), greaterThanOrEqualTo(3));
    for (WsmWorkspaceApplication wsmApp : wsmAppList) {
        if (wsmApp.getApplication().getApplicationId().equals(LEO_UUID)) {
            assertEquals(leoEnabled, wsmApp.isEnabled());
        } else if (wsmApp.getApplication().getApplicationId().equals(CARMEN_UUID)) {
            assertEquals(carmenEnabled, wsmApp.isEnabled());
        } else if (wsmApp.getApplication().getApplicationId().equals(NORM_UUID)) {
            assertEquals(normEnabled, wsmApp.isEnabled());
        }
    }
}
Also used : WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Example 2 with WsmWorkspaceApplication

use of bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationAblePrecheckStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    WsmApplication application = applicationDao.getApplication(applicationId);
    // For enable, we require that the application be in the operating state
    if (ableEnum == AbleEnum.ENABLE) {
        if (application.getState() != WsmApplicationState.OPERATING) {
            throw new InvalidApplicationStateException("Applications is " + application.getState().toApi() + " and cannot be enabled");
        }
    }
    FlightMap workingMap = context.getWorkingMap();
    workingMap.put(WsmApplicationKeys.WSM_APPLICATION, application);
    // See if the application is enabled
    WsmWorkspaceApplication workspaceApp;
    try {
        workspaceApp = applicationDao.getWorkspaceApplication(workspaceId, applicationId);
        workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, workspaceApp.isEnabled()));
    } catch (ApplicationNotFoundException e) {
        workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, false));
    }
    // See if the application already has APPLICATION role for the workspace
    boolean enabledSam = samService.isApplicationEnabledInSam(workspaceId, application.getServiceAccount(), userRequest);
    workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_SAM, computeCorrectState(ableEnum, enabledSam));
    return StepResult.getStepResultSuccess();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) ApplicationNotFoundException(bio.terra.workspace.db.exception.ApplicationNotFoundException) FlightMap(bio.terra.stairway.FlightMap) InvalidApplicationStateException(bio.terra.workspace.db.exception.InvalidApplicationStateException) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Example 3 with WsmWorkspaceApplication

use of bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationDao method getWorkspaceApplicationWorker.

// internal workspace application lookup
private WsmWorkspaceApplication getWorkspaceApplicationWorker(UUID workspaceId, UUID applicationId) {
    final String sql = WORKSPACE_APPLICATION_QUERY + " WHERE A.application_id = :application_id";
    var params = new MapSqlParameterSource().addValue("application_id", applicationId.toString()).addValue("workspace_id", workspaceId.toString());
    try {
        WsmWorkspaceApplication result = DataAccessUtils.requiredSingleResult(jdbcTemplate.query(sql, params, WORKSPACE_APPLICATION_ROW_MAPPER));
        result.workspaceId(workspaceId);
        return result;
    } catch (EmptyResultDataAccessException e) {
        throw new ApplicationNotFoundException(String.format("Application %s not found.", applicationId.toString()));
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ApplicationNotFoundException(bio.terra.workspace.db.exception.ApplicationNotFoundException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Example 4 with WsmWorkspaceApplication

use of bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApplicationApiController method disableWorkspaceApplication.

@Override
public ResponseEntity<ApiWorkspaceApplicationDescription> disableWorkspaceApplication(@PathVariable("workspaceId") UUID workspaceId, @PathVariable("applicationId") UUID applicationId) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    WsmWorkspaceApplication wsmApp = appService.disableWorkspaceApplication(userRequest, workspaceId, applicationId);
    ApiWorkspaceApplicationDescription response = makeApiWorkspaceApplication(wsmApp);
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiWorkspaceApplicationDescription(bio.terra.workspace.generated.model.ApiWorkspaceApplicationDescription) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Example 5 with WsmWorkspaceApplication

use of bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApplicationApiController method enableWorkspaceApplication.

@Override
public ResponseEntity<ApiWorkspaceApplicationDescription> enableWorkspaceApplication(@PathVariable("workspaceId") UUID workspaceId, @PathVariable("applicationId") UUID applicationId) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    WsmWorkspaceApplication wsmApp = appService.enableWorkspaceApplication(userRequest, workspaceId, applicationId);
    ApiWorkspaceApplicationDescription response = makeApiWorkspaceApplication(wsmApp);
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiWorkspaceApplicationDescription(bio.terra.workspace.generated.model.ApiWorkspaceApplicationDescription) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Aggregations

WsmWorkspaceApplication (bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)10 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 ResponseEntity (org.springframework.http.ResponseEntity)4 ApiWorkspaceApplicationDescription (bio.terra.workspace.generated.model.ApiWorkspaceApplicationDescription)3 FlightMap (bio.terra.stairway.FlightMap)2 ApplicationNotFoundException (bio.terra.workspace.db.exception.ApplicationNotFoundException)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 ReadTransaction (bio.terra.common.db.ReadTransaction)1 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 InvalidApplicationStateException (bio.terra.workspace.db.exception.InvalidApplicationStateException)1 ApiWorkspaceApplicationDescriptionList (bio.terra.workspace.generated.model.ApiWorkspaceApplicationDescriptionList)1 WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)1 Test (org.junit.jupiter.api.Test)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1