Search in sources :

Example 1 with DecoratorConfiguration

use of org.molgenis.data.decorator.meta.DecoratorConfiguration in project molgenis by molgenis.

the class DynamicDecoratorIT method testDynamicDecorator.

@WithMockUser(username = USERNAME)
@Test
public void testDynamicDecorator() {
    populatePermissions();
    // Add decorator config
    DecoratorConfiguration decoratorConfiguration = decoratorConfigurationFactory.create("identifier");
    decoratorConfiguration.setDecorators(Arrays.asList(addingDynamicDecorator, postfixingDynamicDecorator));
    decoratorConfiguration.setEntityTypeId(entityTypeDynamic.getId());
    dataService.add(decoratorConfiguration.getEntityType().getId(), decoratorConfiguration);
    // update row
    Entity entity = dataService.findOneById(entityTypeDynamic.getId(), "0");
    dataService.update(entityTypeDynamic.getId(), entity);
    entity = dataService.findOneById(entityTypeDynamic.getId(), "0");
    assertEquals("string1_TEST", entity.getString("string_attr"));
    assertEquals(11, entity.getInt("int_attr").intValue());
    // remove second decorator
    decoratorConfiguration.setDecorators(Arrays.asList(addingDynamicDecorator));
    dataService.update(decoratorConfiguration.getEntityType().getId(), decoratorConfiguration);
    // update row again
    dataService.update(entityTypeDynamic.getId(), entity);
    entity = dataService.findOneById(entityTypeDynamic.getId(), "0");
    // stayed the same since the postfix decorator was removed
    assertEquals("string1_TEST", entity.getString("string_attr"));
    // added 1
    assertEquals(12, entity.getInt("int_attr").intValue());
}
Also used : DecoratorConfiguration(org.molgenis.data.decorator.meta.DecoratorConfiguration) Entity(org.molgenis.data.Entity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 2 with DecoratorConfiguration

use of org.molgenis.data.decorator.meta.DecoratorConfiguration in project molgenis by molgenis.

the class DynamicRepositoryDecoratorRegistryImpl method decorate.

@Override
public synchronized Repository<Entity> decorate(Repository<Entity> repository) {
    String entityTypeId = repository.getEntityType().getId();
    if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) {
        Query query = new QueryImpl().eq(ENTITY_TYPE_ID, entityTypeId);
        DecoratorConfiguration configuration = dataService.findOne(DECORATOR_CONFIGURATION, query, DecoratorConfiguration.class);
        if (configuration != null) {
            repository = decorateRepository(repository, configuration);
        }
    }
    return repository;
}
Also used : DecoratorConfiguration(org.molgenis.data.decorator.meta.DecoratorConfiguration) QueryImpl(org.molgenis.data.support.QueryImpl) Query(org.molgenis.data.Query)

Aggregations

DecoratorConfiguration (org.molgenis.data.decorator.meta.DecoratorConfiguration)2 Entity (org.molgenis.data.Entity)1 Query (org.molgenis.data.Query)1 QueryImpl (org.molgenis.data.support.QueryImpl)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 Test (org.testng.annotations.Test)1