Search in sources :

Example 11 with IEventBus

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()));
        }
    });
}
Also used : Iterables(com.google.common.collect.Iterables) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Operation(io.swagger.v3.oas.annotations.Operation) HttpHeaders(com.google.common.net.HttpHeaders) Map(java.util.Map) RemoteJobs(com.b2international.snowowl.core.jobs.RemoteJobs) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ResourceURI(com.b2international.snowowl.core.ResourceURI) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) IDs(com.b2international.snowowl.core.id.IDs) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ValidationConfiguration(com.b2international.snowowl.core.internal.validation.ValidationConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) ValidationRequests(com.b2international.snowowl.core.validation.ValidationRequests) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 12 with IEventBus

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();
    });
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) IEventBus(com.b2international.snowowl.eventbus.IEventBus) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) NotFoundException(com.b2international.commons.exceptions.NotFoundException) ResourceURI(com.b2international.snowowl.core.ResourceURI) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 13 with IEventBus

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;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ScheduleJobRequestBuilder(com.b2international.snowowl.core.jobs.ScheduleJobRequestBuilder) Promise(com.b2international.snowowl.core.events.util.Promise) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CompositeClassLoader(com.b2international.commons.CompositeClassLoader) IEventBus(com.b2international.snowowl.eventbus.IEventBus) IMessage(com.b2international.snowowl.eventbus.IMessage) Collections(java.util.Collections) IHandler(com.b2international.snowowl.eventbus.IHandler) Promise(com.b2international.snowowl.core.events.util.Promise) IMessage(com.b2international.snowowl.eventbus.IMessage) CompositeClassLoader(com.b2international.commons.CompositeClassLoader)

Example 14 with IEventBus

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);
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 15 with IEventBus

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);
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Aggregations

IEventBus (com.b2international.snowowl.eventbus.IEventBus)17 Test (org.junit.Test)10 ResourceURI (com.b2international.snowowl.core.ResourceURI)3 Promise (com.b2international.snowowl.core.events.util.Promise)3 TimeUnit (java.util.concurrent.TimeUnit)3 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)2 JWTGenerator (com.b2international.snowowl.core.identity.JWTGenerator)2 Permission (com.b2international.snowowl.core.identity.Permission)2 Role (com.b2international.snowowl.core.identity.Role)2 User (com.b2international.snowowl.core.identity.User)2 JobRequests (com.b2international.snowowl.core.jobs.JobRequests)2 AbstractRestService (com.b2international.snowowl.core.rest.AbstractRestService)2 IMessage (com.b2international.snowowl.eventbus.IMessage)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Parameter (io.swagger.v3.oas.annotations.Parameter)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2 Tag (io.swagger.v3.oas.annotations.tags.Tag)2 HttpStatus (org.springframework.http.HttpStatus)2 ResponseEntity (org.springframework.http.ResponseEntity)2