Search in sources :

Example 1 with SystemEntityType

use of org.molgenis.data.meta.SystemEntityType in project molgenis by molgenis.

the class SystemEntityTypeInitializer method initialize.

public void initialize(ContextRefreshedEvent event) {
    ApplicationContext ctx = event.getApplicationContext();
    ctx.getBeansOfType(SystemPackage.class).values().forEach(SystemPackage::bootstrap);
    EntityTypeMetadata entityTypeMetaData = ctx.getBean(EntityTypeMetadata.class);
    ctx.getBean(AttributeMetadata.class).bootstrap(entityTypeMetaData);
    // TODO: doesn't this mean all attributes get added twice?
    Map<String, SystemEntityType> systemEntityTypeMap = ctx.getBeansOfType(SystemEntityType.class);
    genericDependencyResolver.resolve(systemEntityTypeMap.values(), SystemEntityType::getDependencies).forEach(systemEntityType -> initialize(systemEntityType, entityTypeMetaData));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) EntityTypeMetadata(org.molgenis.data.meta.model.EntityTypeMetadata) SystemPackage(org.molgenis.data.meta.SystemPackage) RootSystemPackage(org.molgenis.data.system.model.RootSystemPackage) AttributeMetadata(org.molgenis.data.meta.model.AttributeMetadata) SystemEntityType(org.molgenis.data.meta.SystemEntityType)

Example 2 with SystemEntityType

use of org.molgenis.data.meta.SystemEntityType in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testGetSystemEntityTypesNotPermitted.

@Test
public void testGetSystemEntityTypesNotPermitted() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(false);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertEquals(systemEntityTypeRegistry.getSystemEntityTypes().count(), 0);
}
Also used : SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with SystemEntityType

use of org.molgenis.data.meta.SystemEntityType in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testGetSystemAttributeCompound.

@Test
public void testGetSystemAttributeCompound() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    Attribute attr = when(mock(Attribute.class).getIdentifier()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(AttributeType.STRING);
    Attribute compoundAttr = when(mock(Attribute.class).getIdentifier()).thenReturn("compoundAttr").getMock();
    when(compoundAttr.getDataType()).thenReturn(AttributeType.COMPOUND);
    when(compoundAttr.getChildren()).thenReturn(singletonList(attr));
    when(systemEntityType.getAllAttributes()).thenReturn(singletonList(compoundAttr));
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertEquals(systemEntityTypeRegistry.getSystemAttribute("attr"), attr);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 4 with SystemEntityType

use of org.molgenis.data.meta.SystemEntityType in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testHasSystemAttributePermittedNotExists.

@Test
public void testHasSystemAttributePermittedNotExists() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    when(systemEntityType.getAllAttributes()).thenReturn(emptyList());
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertFalse(systemEntityTypeRegistry.hasSystemAttribute("attr"));
}
Also used : SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 5 with SystemEntityType

use of org.molgenis.data.meta.SystemEntityType in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testGetSystemEntityTypesPermitted.

@Test
public void testGetSystemEntityTypesPermitted() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertEquals(systemEntityTypeRegistry.getSystemEntityTypes().collect(toList()), singletonList(systemEntityType));
}
Also used : SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

SystemEntityType (org.molgenis.data.meta.SystemEntityType)16 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Test (org.testng.annotations.Test)13 Attribute (org.molgenis.data.meta.model.Attribute)6 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)2 EntityTypeMetadata (org.molgenis.data.meta.model.EntityTypeMetadata)2 ApplicationContext (org.springframework.context.ApplicationContext)2 SystemPackage (org.molgenis.data.meta.SystemPackage)1 RootSystemPackage (org.molgenis.data.system.model.RootSystemPackage)1 GenericDependencyResolver (org.molgenis.data.util.GenericDependencyResolver)1 BeforeClass (org.testng.annotations.BeforeClass)1