Search in sources :

Example 1 with DefExplorerQueryResult

use of org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceImpl method resolveQuery.

private DefExplorerQueryResult resolveQuery(final DefExplorerQuery query) {
    final DefExplorerQueryResult result = new DefExplorerQueryResult();
    // load the organizational units.
    final Collection<OrganizationalUnit> organizationalUnits = resolveOrganizationalUnits();
    // piggyback the organizational units.
    result.getOrganizationalUnits().addAll(organizationalUnits);
    if (query.getOrganizationalUnit() == null || !containsOU(organizationalUnits, query.getOrganizationalUnit())) {
        // if no OU was set for filtering or the selected OU has been removed or has changed in backend.
        return result;
    }
    // set the repositories for current OU.
    final Map<String, Repository> repositories = resolveRepositories(query.getOrganizationalUnit());
    // piggyback the repositories.
    result.getRepositories().addAll(repositories.values());
    if (query.getRepository() == null || !repositories.containsKey(query.getRepository().getAlias())) {
        // changed in backend.
        return result;
    }
    // load the modules for current OU/Repository and the selected branch.
    final Map<String, Module> modules = resolveModules(repositories, query.getBranchName());
    result.getModules().addAll(modules.values());
    if (query.getModule() == null || !modules.containsKey(query.getModule().getModuleName())) {
        // changed in backend.
        return result;
    }
    // get the data sources and drivers for the selected module.
    result.setDataSourceDefs(queryService.findModuleDataSources(query.getModule()));
    result.setDriverDefs(queryService.findModuleDrivers(query.getModule()));
    return result;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Module(org.guvnor.common.services.project.model.Module) DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult)

Example 2 with DefExplorerQueryResult

use of org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult in project kie-wb-common by kiegroup.

the class ExplorerBaseTest method setup.

protected void setup() {
    queryServiceCaller = new CallerMock<>(queryService);
    result = new DefExplorerQueryResult();
}
Also used : DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult)

Example 3 with DefExplorerQueryResult

use of org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceImpl method executeQuery.

public DefExplorerQueryResult executeQuery(final DefExplorerQuery query) {
    checkNotNull("query", query);
    if (query.isGlobalQuery()) {
        DefExplorerQueryResult result = new DefExplorerQueryResult();
        result.setDataSourceDefs(queryService.findGlobalDataSources(true));
        result.setDriverDefs(queryService.findGlobalDrivers());
        return result;
    } else {
        return resolveQuery(query);
    }
}
Also used : DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult)

Example 4 with DefExplorerQueryResult

use of org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceTest method testQueryForOrganizationalUnitRepository.

/**
 * Tests a query for a given Organizational Unit and a given repository. In this case the list of available
 * authorized modules for the given repository should be returned.
 */
@Test
public void testQueryForOrganizationalUnitRepository() {
    DefExplorerQuery query = new DefExplorerQuery();
    query.setOrganizationalUnit(o3);
    query.setRepository(repo_o3_3);
    query.setBranchName("master");
    DefExplorerQueryResult result = explorerQueryService.executeQuery(query);
    verifyResultForQueryForOrganizationalUnitRepository(result);
}
Also used : DefExplorerQuery(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQuery) DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult) Test(org.junit.Test)

Example 5 with DefExplorerQueryResult

use of org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceTest method testQueryForOrganizationalUnit.

/**
 * Tests a query for a given Organizational Unit as the only parameter. In this case the query should return the
 * list of available authorized repositories for the selected OU.
 */
@Test
public void testQueryForOrganizationalUnit() {
    DefExplorerQuery query = new DefExplorerQuery();
    query.setOrganizationalUnit(o2);
    DefExplorerQueryResult result = explorerQueryService.executeQuery(query);
    // o1 should not be included in the result since it's not authorized.
    assertFalse(result.getOrganizationalUnits().contains(o1));
    // o2 must be included in the result.
    assertTrue(result.getOrganizationalUnits().contains(o2));
    // o3 is still included in the result since organizational units are piggybacked to let the UI be refreshed
    assertTrue(result.getOrganizationalUnits().contains(o3));
    // authorized repositories for organizational unit o2 must be in the result.
    assertTrue(result.getRepositories().contains(repo_o2_1));
    assertTrue(result.getRepositories().contains(repo_o2_2));
    assertEquals(2, result.getRepositories().size());
}
Also used : DefExplorerQuery(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQuery) DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult) Test(org.junit.Test)

Aggregations

DefExplorerQueryResult (org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult)7 Test (org.junit.Test)4 DefExplorerQuery (org.kie.workbench.common.screens.datasource.management.service.DefExplorerQuery)4 Module (org.guvnor.common.services.project.model.Module)1 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)1 Repository (org.guvnor.structure.repositories.Repository)1