Search in sources :

Example 6 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class EventBusHandlerRegistrationTest method test_RegisterHandler_NonNull_NonNull.

@Test
public void test_RegisterHandler_NonNull_NonNull() {
    final IEventBus actual = bus.registerHandler(ADDRESS, noopHandler);
    assertEquals(bus, actual);
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 7 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class EventBusSendTest method test_Publish_NoHandlers.

@Test
public void test_Publish_NoHandlers() throws InterruptedException {
    final IEventBus actual = bus.publish(ADDRESS, SEND_MESSAGE, null);
    assertEquals(bus, actual);
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 8 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class EventBusNet4jUtil method prepareContainer.

/**
 * Prepares the given {@link IManagedContainer} to deliver message through {@link IEventBus} instances over the
 * network.
 *
 * @param container
 * @param gzip - to enable gzip compression on the protocol or not
 * @param numberOfWorkers
 */
public static final void prepareContainer(IManagedContainer container, boolean gzip, int numberOfWorkers) {
    container.registerFactory(new EventBusProtocol.ClientFactory());
    container.registerFactory(new EventBusProtocol.ServerFactory());
    container.registerFactory(new EventBus.Factory());
    container.addPostProcessor(new EventBusProtocolInjector(numberOfWorkers));
    if (gzip) {
        container.addPostProcessor(new GZIPStreamWrapperInjector(EventBusConstants.PROTOCOL_NAME));
    }
}
Also used : EventBusProtocolInjector(com.b2international.snowowl.internal.eventbus.net4j.EventBusProtocolInjector) EventBusProtocol(com.b2international.snowowl.internal.eventbus.net4j.EventBusProtocol) GZIPStreamWrapperInjector(org.eclipse.net4j.signal.wrapping.GZIPStreamWrapperInjector) IEventBus(com.b2international.snowowl.eventbus.IEventBus) EventBus(com.b2international.snowowl.internal.eventbus.EventBus)

Example 9 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class SnomedContentRule method createCodeSystemIfNotExist.

private void createCodeSystemIfNotExist() {
    final IEventBus eventBus = Services.bus();
    final CodeSystems codeSystems = CodeSystemRequests.prepareSearchCodeSystem().setLimit(0).filterById(codeSystemId.getResourceId()).buildAsync().execute(eventBus).getSync();
    if (codeSystems.getTotal() > 0) {
        return;
    }
    final ResourceURI extensionOf = Optional.ofNullable(this.extensionOf).or(() -> {
        return ResourceRequests.prepareSearchVersion().filterByResource(SNOMEDCT).sortBy(Sort.fieldDesc(VersionDocument.Fields.EFFECTIVE_TIME)).setLimit(1).buildAsync().execute(eventBus).getSync().first().map(Version::getVersionResourceURI);
    }).orElse(null);
    CodeSystemRequests.prepareNewCodeSystem().setId(codeSystemId.getResourceId()).setBranchPath(SNOMEDCT.equals(codeSystemId) ? Branch.MAIN_PATH : null).setUrl(SNOMEDCT.equals(codeSystemId) ? SnomedTerminologyComponentConstants.SNOMED_URI_SCT + "/" + Concepts.MODULE_SCT_CORE : SnomedTerminologyComponentConstants.SNOMED_URI_SCT + "/" + codeSystemId.getResourceId()).setDescription("description").setExtensionOf(extensionOf).setLanguage("ENG").setTitle(codeSystemId.getResourceId()).setOid("oid:" + codeSystemId).setOwner("https://b2i.sg").setToolingId(SnomedTerminologyComponentConstants.TOOLING_ID).setSettings(Map.of(SnomedTerminologyComponentConstants.CODESYSTEM_LANGUAGE_CONFIG_KEY, List.of(Map.of("languageTag", "en", "languageRefSetIds", Lists.newArrayList(Concepts.REFSET_LANGUAGE_TYPE_UK, Concepts.REFSET_LANGUAGE_TYPE_US))))).build(RestExtensions.USER, String.format("Create code system %s", codeSystemId)).execute(eventBus).getSync(1, TimeUnit.MINUTES);
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystems(com.b2international.snowowl.core.codesystem.CodeSystems) IEventBus(com.b2international.snowowl.eventbus.IEventBus)

Example 10 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method searchCommitOnSubBranch.

@Test
public void searchCommitOnSubBranch() {
    // Search with no branch filter, to test security filter for user with limited resources
    final String oid = UUID.randomUUID().toString();
    final String shortName = "Resource7";
    final String comment = "Code system for commit info 7";
    final String branchName = "Test7";
    final String commitComment = "Create Description 7";
    final String term = "Test Description 7";
    // Commit on resource branch
    createCodeSystem(shortName, oid, comment);
    createDescription(ResourceURI.of(CodeSystem.RESOURCE_TYPE, shortName), term, commitComment);
    // Commit on version branch
    final String branchPath = createBranch(String.format("%s/%s", BRANCH, shortName), branchName);
    createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, branchName), term, commitComment);
    // Commit on deeper branch
    final String newBranchName = String.format("%s/%s", branchName, branchName);
    createBranch(branchPath, branchName);
    createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, newBranchName), term, commitComment);
    final Permission userPermission = Permission.requireAll(Permission.OPERATION_BROWSE, String.format("%s*", shortName));
    final List<Role> roles = List.of(new Role("Editor", List.of(userPermission)));
    final String userName = "User7";
    final User user = new User(userName, roles);
    final IEventBus authorizedBus = new AuthorizedEventBus(bus, ImmutableMap.of(AuthorizedRequest.AUTHORIZATION_HEADER, Services.service(JWTGenerator.class).generate(user)));
    // Search as user with permission only to access the resource and one sub branch
    assertEquals(2, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByComment(commitComment).build(REPOSITORY_ID).execute(authorizedBus).getSync().getTotal());
    // Search as admin user with permission to access all
    assertEquals(3, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByComment(commitComment).build(REPOSITORY_ID).execute(bus).getSync().getTotal());
}
Also used : Role(com.b2international.snowowl.core.identity.Role) User(com.b2international.snowowl.core.identity.User) JWTGenerator(com.b2international.snowowl.core.identity.JWTGenerator) Permission(com.b2international.snowowl.core.identity.Permission) AuthorizedEventBus(com.b2international.snowowl.core.authorization.AuthorizedEventBus) 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