use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.
the class RepositoryValidationRestService method getValidationResults.
@Operation(summary = "Retrieve the validation issues from a completed validation on a branch. Output may differ by the chosen content type.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@RequestMapping(value = "/validations/{validationId}/issues", method = RequestMethod.GET, produces = { AbstractRestService.JSON_MEDIA_TYPE, AbstractRestService.CSV_MEDIA_TYPE })
@ResponseBody
public Promise<Collection<Object>> getValidationResults(@Parameter(description = "The unique validation identifier.") @PathVariable(value = "validationId") final String validationId, @Parameter(description = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter, @Parameter(description = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit, @Parameter(hidden = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.JSON_MEDIA_TYPE, required = false) final String contentType) {
final IEventBus bus = getBus();
return getValidationRun(validationId).thenWith(validationJob -> {
final ResourceURI codeSystemURI = getCodeSystemURIFromJob(validationJob);
if (AbstractRestService.CSV_MEDIA_TYPE.equals(contentType)) {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).all().filterByResourceUri(codeSystemURI).sortBy(Sort.fieldAsc(ValidationIssue.Fields.RULE_ID)).buildAsync().execute(bus).then(issues -> {
final Set<String> rulesToFetch = issues.stream().map(ValidationIssue::getRuleId).collect(Collectors.toSet());
final Map<String, String> ruleDescriptionById = ValidationRequests.rules().prepareSearch().all().filterByIds(rulesToFetch).buildAsync().execute(bus).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(ValidationRule::getId, ValidationRule::getMessageTemplate));
return issues.stream().map(issue -> {
final String ruleId = issue.getRuleId();
final String ruleDescription = ruleDescriptionById.get(ruleId);
final String affectedComponentLabel = Iterables.getFirst(issue.getAffectedComponentLabels(), "No label found");
final String affectedComponentId = issue.getAffectedComponent().getComponentId();
return new ValidationIssueReport(ruleId, ruleDescription, affectedComponentId, affectedComponentLabel);
}).collect(Collectors.toList());
});
} else {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).setLimit(limit).setSearchAfter(searchAfter).filterByResourceUri(codeSystemURI).buildAsync().execute(bus).then(issues -> issues.getItems().stream().collect(Collectors.toList()));
}
});
}
use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.
the class CodeSystemUpgradeRestService method upgrade.
@Operation(summary = "Start a Code System dependency upgrade (EXPERIMENTAL)", description = "Starts the upgrade process of a Code System to a newer extensionOf Code System dependency than the current extensionOf.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Upgrade created"), @ApiResponse(responseCode = "400", description = "Code System cannot be upgraded") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.CREATED)
public Promise<ResponseEntity<Void>> upgrade(@RequestBody final UpgradeRestInput body) {
final UriComponentsBuilder uriBuilder = createURIBuilder();
final ResourceURI upgradeOf = new ResourceURI(body.getUpgradeOf());
final IEventBus bus = getBus();
return // TODO move this to generic resource controller
CodeSystemRequests.prepareGetCodeSystem(upgradeOf.getResourceId()).buildAsync().execute(bus).thenWith(codeSystem -> {
return CodeSystemRequests.prepareUpgrade(upgradeOf, new ResourceURI(body.getExtensionOf())).setResourceId(body.getCodeSystemId()).buildAsync().execute(bus);
}).then(upgradeCodeSystemId -> {
return ResponseEntity.created(uriBuilder.pathSegment(upgradeCodeSystemId).build().toUri()).build();
});
}
use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.
the class AsyncRequest method execute.
/**
* Executes the asynchronous request using the event bus passed in.
* @param bus
* @return {@link Promise}
*/
public Promise<R> execute(IEventBus bus) {
final Promise<R> promise = new Promise<>();
final Class<R> responseType = request.getReturnType();
final CompositeClassLoader classLoader = new CompositeClassLoader();
classLoader.add(request.getClassLoader());
request.getNestedRequests().stream().map(Request::getClassLoader).forEach(classLoader::add);
request.getNestedRequests().stream().map(r -> r.getClass().getClassLoader()).forEach(classLoader::add);
bus.send(Request.ADDRESS, request, Request.TAG, Collections.emptyMap(), new IHandler<IMessage>() {
@Override
public void handle(IMessage message) {
try {
if (message.isSucceeded()) {
promise.resolve(message.body(responseType, classLoader), message.headers());
} else {
promise.reject(message.body(Throwable.class, AsyncRequest.class.getClassLoader()));
}
} catch (Throwable e) {
promise.reject(e);
}
}
});
return promise;
}
use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.
the class EventBusHandlerRegistrationTest method test_UnregisterHandler_NotRegistered.
@Test
public void test_UnregisterHandler_NotRegistered() {
final IEventBus actual = bus.unregisterHandler(ADDRESS, noopHandler);
assertEquals(bus, actual);
}
use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.
the class EventBusHandlerRegistrationTest method test_RegisterHandler_NonNull_Null.
@Test
public void test_RegisterHandler_NonNull_Null() {
final IEventBus actual = bus.registerHandler(ADDRESS, null);
assertEquals(bus, actual);
}
Aggregations