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());
}
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;
}
Aggregations