use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.
the class SystemTaskRepositoryTest method testDelete.
@Test
public void testDelete() {
SystemTask task = buildSystemTask();
SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
// fetch SystemTask
TestObserver<SystemTask> testObserver = taskRepository.findById(systemTaskCreated.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(s -> s.getId().equals(systemTaskCreated.getId()));
// delete SystemTask
TestObserver testObserver1 = taskRepository.delete(systemTaskCreated.getId()).test();
testObserver1.awaitTerminalEvent();
// fetch SystemTask
taskRepository.findById(systemTaskCreated.getId()).test().assertEmpty();
}
use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.
the class SystemTaskRepositoryTest method testFindById.
@Test
public void testFindById() {
// create task
SystemTask task = buildSystemTask();
SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
// fetch task
TestObserver<SystemTask> testObserver = taskRepository.findById(systemTaskCreated.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(task, task.getOperationId(), testObserver);
}
use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.
the class SystemTaskRepositoryTest method testUpdateIf.
@Test
public void testUpdateIf() {
SystemTask task = buildSystemTask();
SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
SystemTask updatedSystemTask = buildSystemTask();
updatedSystemTask.setId(systemTaskCreated.getId());
TestObserver<SystemTask> testObserver = taskRepository.updateIf(updatedSystemTask, systemTaskCreated.getOperationId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(updatedSystemTask, updatedSystemTask.getOperationId(), testObserver);
}
use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.
the class SystemTaskRepositoryTest method buildSystemTask.
private SystemTask buildSystemTask() {
SystemTask task = new SystemTask();
String rand = UUID.randomUUID().toString();
task.setId(rand);
task.setType(rand);
task.setStatus(rand);
task.setOperationId(rand);
task.setCreatedAt(new Date());
task.setUpdatedAt(new Date());
return task;
}
use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.
the class ApplicationScopeSettingsUpgrader method migrateScopeSettings.
private Single<Boolean> migrateScopeSettings(SystemTask task) {
return applicationService.findAll().flatMapPublisher(apps -> Flowable.fromIterable(apps)).flatMapSingle(app -> {
logger.debug("Process application '{}'", app.getId());
if (app.getSettings() != null && app.getSettings().getOauth() != null) {
final ApplicationOAuthSettings oauthSettings = app.getSettings().getOauth();
List<ApplicationScopeSettings> scopeSettings = new ArrayList<>();
if (oauthSettings.getScopes() != null && !oauthSettings.getScopes().isEmpty()) {
logger.debug("Process scope options for application '{}'", app.getId());
for (String scope : oauthSettings.getScopes()) {
ApplicationScopeSettings setting = new ApplicationScopeSettings();
setting.setScope(scope);
setting.setDefaultScope(oauthSettings.getDefaultScopes() != null && oauthSettings.getDefaultScopes().contains(scope));
if (oauthSettings.getScopeApprovals() != null && oauthSettings.getScopeApprovals().containsKey(scope)) {
setting.setScopeApproval(oauthSettings.getScopeApprovals().get(scope));
}
scopeSettings.add(setting);
}
oauthSettings.setScopeSettings(scopeSettings);
// remove old values
oauthSettings.setScopes(null);
oauthSettings.setDefaultScopes(null);
oauthSettings.setScopeApprovals(null);
logger.debug("Update settings for application '{}'", app.getId());
return applicationService.update(app);
} else {
logger.debug("No scope to process for application '{}'", app.getId());
}
} else {
logger.debug("No scope to process for application '{}'", app.getId());
}
return Single.just(app);
}).ignoreElements().doOnError(err -> updateSystemTask(task, (SystemTaskStatus.FAILURE), task.getOperationId()).subscribe()).andThen(updateSystemTask(task, SystemTaskStatus.SUCCESS, task.getOperationId()).map(__ -> true).onErrorResumeNext((err) -> {
logger.error("Unable to update status for migrate scope options task: {}", err.getMessage());
return Single.just(false);
})).onErrorResumeNext((err) -> {
logger.error("Unable to migrate scope options for applications: {}", err.getMessage());
return Single.just(false);
});
}
Aggregations