Search in sources :

Example 1 with DataSetLookup

use of org.dashbuilder.dataset.DataSetLookup in project jbpm by kiegroup.

the class BusinessAdminTasksPreprocessorTest method testQueryByNoBusinessAdmin.

@Test
public void testQueryByNoBusinessAdmin() {
    dataSetLookup = new DataSetLookup();
    String role1 = "role1";
    String role2 = "role2";
    String userId = "userId";
    when(identityProvider.getRoles()).thenReturn(Arrays.asList(role1, role2));
    when(identityProvider.getName()).thenReturn(userId);
    preprocessor.preprocess(dataSetLookup);
    assertEquals("ID = role1, role2, userId", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString());
}
Also used : DataSetLookup(org.dashbuilder.dataset.DataSetLookup) Test(org.junit.Test)

Example 2 with DataSetLookup

use of org.dashbuilder.dataset.DataSetLookup in project kie-wb-common by kiegroup.

the class DataManagementServiceImpl method getDisplayerSettings.

@Override
public DisplayerSettings getDisplayerSettings(String dataSourceUuid, String schema, String table) {
    checkNotNull("dataSourceUuid", dataSourceUuid);
    checkNotNull("table", table);
    try {
        DataSourceDeploymentInfo deploymentInfo = dataSourceRuntimeManager.getDataSourceDeploymentInfo(dataSourceUuid);
        DataSetDef dataSetDef = DataSetDefBuilder.newBuilder().dataSetUuid(buildDataSetUuid(dataSourceUuid, schema, table)).dataSetName(buildDataSetName(schema, table)).dataSourceUuid(deploymentInfo.getUuid()).schema(schema).table(buildDataSetTableName(dataSourceUuid, table)).isPublic(false).build();
        dataSetDefRegistry.registerDataSetDef(dataSetDef);
        DataSetLookup lookup = new DataSetLookup();
        lookup.setDataSetUUID(dataSetDef.getUUID());
        DataSet dataSet = dataSetManager.lookupDataSet(lookup);
        TableDisplayerSettingsBuilder settingsBuilder = DisplayerSettingsFactory.newTableSettings().dataset(dataSetDef.getUUID()).title(table).titleVisible(true).tablePageSize(20).tableOrderEnabled(true);
        List<DataColumn> columns = dataSet.getColumns();
        for (DataColumn column : columns) {
            settingsBuilder.column(column.getId());
        }
        int tableWith = columns.size() * COLUMN_WIDTH;
        settingsBuilder.tableWidth(tableWith);
        settingsBuilder.renderer(DefaultRenderer.UUID);
        return settingsBuilder.buildSettings();
    } catch (Exception e) {
        throw new GenericPortableException(e.getMessage());
    }
}
Also used : DataSetDef(org.dashbuilder.dataset.def.DataSetDef) DataSet(org.dashbuilder.dataset.DataSet) DataColumn(org.dashbuilder.dataset.DataColumn) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) TableDisplayerSettingsBuilder(org.dashbuilder.displayer.TableDisplayerSettingsBuilder) DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) DataSetLookup(org.dashbuilder.dataset.DataSetLookup) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException)

Example 3 with DataSetLookup

use of org.dashbuilder.dataset.DataSetLookup in project kie-wb-common by kiegroup.

the class DataManagementServiceImplTest method testGetDisplayerSettings.

@Test
public void testGetDisplayerSettings() {
    expectedDataSetUUID = DATASOURCE_UUID + SEPARATOR + SCHEMA + SEPARATOR + TABLE;
    DataSetLookup expectedLookup = new DataSetLookup();
    expectedLookup.setDataSetUUID(expectedDataSetUUID);
    DataSet expectedSet = mock(DataSet.class);
    List<DataColumn> dataColumns = new ArrayList<>();
    for (int i = 0; i < COLUMNS_COUNT; i++) {
        DataColumn dataColumn = mock(DataColumn.class);
        when(dataColumn.getId()).thenReturn(DATA_COLUMN + String.valueOf(i));
        dataColumns.add(dataColumn);
    }
    when(expectedSet.getColumns()).thenReturn(dataColumns);
    when(dataSetManager.lookupDataSet(expectedLookup)).thenReturn(expectedSet);
    DisplayerSettings settings = dataManagementService.getDisplayerSettings(DATASOURCE_UUID, SCHEMA, TABLE);
    verify(dataSetDefRegistry, times(1)).registerDataSetDef(dataSetDefCaptor.capture());
    verifyDataSetDef(dataSetDefCaptor.getValue());
    verifySettings(settings);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) DataColumn(org.dashbuilder.dataset.DataColumn) ArrayList(java.util.ArrayList) DisplayerSettings(org.dashbuilder.displayer.DisplayerSettings) DataSetLookup(org.dashbuilder.dataset.DataSetLookup) Test(org.junit.Test)

Example 4 with DataSetLookup

use of org.dashbuilder.dataset.DataSetLookup in project jbpm by kiegroup.

the class BusinessAdminTasksPreprocessorTest method testSetUserWithoutRoles.

@Test
public void testSetUserWithoutRoles() {
    dataSetLookup = new DataSetLookup();
    String userId = "userId";
    when(identityProvider.getRoles()).thenReturn(Collections.emptyList());
    when(identityProvider.getName()).thenReturn(userId);
    preprocessor.preprocess(dataSetLookup);
    assertEquals("ID = userId", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString());
}
Also used : DataSetLookup(org.dashbuilder.dataset.DataSetLookup) Test(org.junit.Test)

Example 5 with DataSetLookup

use of org.dashbuilder.dataset.DataSetLookup in project jbpm by kiegroup.

the class BusinessAdminTasksPreprocessor method preprocess.

@SuppressWarnings("rawtypes")
@Override
public void preprocess(DataSetLookup lookup) {
    if (identityProvider == null) {
        return;
    }
    if (ADMIN_USER.equals(identityProvider.getName()) || identityProvider.getRoles().stream().filter(s -> s.equals(ADMIN_GROUP)).findFirst().isPresent()) {
        return;
    }
    final List<Comparable> orgEntities = new ArrayList<Comparable>(identityProvider.getRoles());
    orgEntities.add(identityProvider.getName());
    final ColumnFilter columnFilter = equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, orgEntities);
    LOGGER.debug("Adding column filter: {}", columnFilter);
    if (lookup.getFirstFilterOp() != null) {
        lookup.getFirstFilterOp().addFilterColumn(columnFilter);
    } else {
        DataSetFilter filter = new DataSetFilter();
        filter.addFilterColumn(columnFilter);
        lookup.addOperation(filter);
    }
    super.preprocess(lookup);
}
Also used : FilterFactory.equalsTo(org.dashbuilder.dataset.filter.FilterFactory.equalsTo) IdentityProvider(org.kie.internal.identity.IdentityProvider) COLUMN_ORGANIZATIONAL_ENTITY(org.jbpm.services.api.query.QueryResultMapper.COLUMN_ORGANIZATIONAL_ENTITY) DataSetLookup(org.dashbuilder.dataset.DataSetLookup) List(java.util.List) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) DataSetMetadata(org.dashbuilder.dataset.DataSetMetadata) DataSetFilter(org.dashbuilder.dataset.filter.DataSetFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) DataSetFilter(org.dashbuilder.dataset.filter.DataSetFilter) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter)

Aggregations

DataSetLookup (org.dashbuilder.dataset.DataSetLookup)5 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DataColumn (org.dashbuilder.dataset.DataColumn)2 DataSet (org.dashbuilder.dataset.DataSet)2 List (java.util.List)1 DataSetMetadata (org.dashbuilder.dataset.DataSetMetadata)1 DataSetDef (org.dashbuilder.dataset.def.DataSetDef)1 ColumnFilter (org.dashbuilder.dataset.filter.ColumnFilter)1 DataSetFilter (org.dashbuilder.dataset.filter.DataSetFilter)1 FilterFactory.equalsTo (org.dashbuilder.dataset.filter.FilterFactory.equalsTo)1 DisplayerSettings (org.dashbuilder.displayer.DisplayerSettings)1 TableDisplayerSettingsBuilder (org.dashbuilder.displayer.TableDisplayerSettingsBuilder)1 GenericPortableException (org.guvnor.common.services.shared.exceptions.GenericPortableException)1 COLUMN_ORGANIZATIONAL_ENTITY (org.jbpm.services.api.query.QueryResultMapper.COLUMN_ORGANIZATIONAL_ENTITY)1 IdentityProvider (org.kie.internal.identity.IdentityProvider)1 DataSourceDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1