Search in sources :

Example 1 with SystemPackage

use of org.molgenis.data.meta.SystemPackage 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 SystemPackage

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

the class SystemEntityTypePersisterTest method persistSystemPackageNoChange.

// regression test for https://github.com/molgenis/molgenis/issues/5168
@SuppressWarnings("unchecked")
@Test
public void persistSystemPackageNoChange() {
    Attribute attr = mock(Attribute.class);
    when(attrMetaMeta.getAttribute(REF_ENTITY_TYPE)).thenReturn(attr);
    when(attr.setDataType(any())).thenReturn(attr);
    when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenAnswer(invocation -> Stream.empty());
    when(dataService.findAll(eq(ENTITY_TYPE_META_DATA), objectIdCaptor.capture(), eq(EntityType.class))).thenAnswer(invocation -> Stream.empty());
    when(systemEntityTypeRegistry.getSystemEntityTypes()).thenAnswer(invocation -> Stream.empty());
    String packageId0 = "packageId0";
    String packageName0 = "packageName0";
    SystemPackage package0 = when(mock(SystemPackage.class).getId()).thenReturn(packageName0).getMock();
    when(package0.getId()).thenReturn(packageId0);
    String packageId1 = "packageId1";
    String packageName1 = "packageName1";
    SystemPackage package1 = when(mock(SystemPackage.class).getId()).thenReturn(packageName1).getMock();
    when(package1.getId()).thenReturn(packageId1);
    when(systemPackageRegistry.getSystemPackages()).thenReturn(Stream.of(package0, package1));
    when(dataService.findAll(PACKAGE, Package.class)).thenAnswer(invocation -> Stream.of(package0, package1));
    systemEntityTypePersister.persist();
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
    verify(metaDataService).upsertPackages(captor.capture());
    assertEquals(captor.getValue().collect(toList()), newArrayList(package0, package1));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemPackage(org.molgenis.data.meta.SystemPackage) Attribute(org.molgenis.data.meta.model.Attribute) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with SystemPackage

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

the class SystemEntityTypePersisterTest method removeNonExistingSystemEntities.

@Test
public void removeNonExistingSystemEntities() throws Exception {
    Package systemPackage = mock(Package.class);
    when(systemPackage.getId()).thenReturn(PACKAGE_SYSTEM);
    EntityType refRemovedMeta = when(mock(EntityType.class).getId()).thenReturn("refRemoved").getMock();
    when(refRemovedMeta.getPackage()).thenReturn(systemPackage);
    when(refRemovedMeta.toString()).thenReturn("refRemoved");
    when(refRemovedMeta.getAtomicAttributes()).thenReturn(emptyList());
    EntityType removedMeta = when(mock(EntityType.class).getId()).thenReturn("removed").getMock();
    when(removedMeta.getPackage()).thenReturn(systemPackage);
    when(removedMeta.toString()).thenReturn("removed");
    Attribute refAttr = when(mock(Attribute.class).getRefEntity()).thenReturn(refRemovedMeta).getMock();
    when(removedMeta.getAtomicAttributes()).thenReturn(singletonList(refAttr));
    EntityType refEntityType = when(mock(EntityType.class).getId()).thenReturn("refEntity").getMock();
    when(refEntityType.getPackage()).thenReturn(systemPackage);
    when(refEntityType.toString()).thenReturn("refEntity");
    when(refEntityType.getAtomicAttributes()).thenReturn(emptyList());
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    when(entityType.getPackage()).thenReturn(systemPackage);
    when(entityType.toString()).thenReturn("entity");
    when(entityType.getAtomicAttributes()).thenReturn(emptyList());
    when(systemEntityTypeRegistry.hasSystemEntityType("removed")).thenReturn(false);
    when(systemEntityTypeRegistry.hasSystemEntityType("refRemoved")).thenReturn(false);
    when(systemEntityTypeRegistry.hasSystemEntityType("entity")).thenReturn(true);
    when(systemEntityTypeRegistry.hasSystemEntityType("refEntity")).thenReturn(true);
    when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(refEntityType, entityType, refRemovedMeta, removedMeta));
    systemEntityTypePersister.removeNonExistingSystemEntityTypes();
    verify(metaDataService).deleteEntityType(newArrayList(refRemovedMeta, removedMeta));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) SystemPackage(org.molgenis.data.meta.SystemPackage) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 4 with SystemPackage

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

the class SystemEntityTypePersisterTest method persistSystemPackageChange.

@Test
public void persistSystemPackageChange() {
    Attribute attr = mock(Attribute.class);
    when(attrMetaMeta.getAttribute(REF_ENTITY_TYPE)).thenReturn(attr);
    when(attr.setDataType(any())).thenReturn(attr);
    when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenAnswer(invocation -> Stream.empty());
    when(dataService.findAll(eq(ENTITY_TYPE_META_DATA), objectIdCaptor.capture(), eq(EntityType.class))).thenAnswer(invocation -> Stream.empty());
    when(systemEntityTypeRegistry.getSystemEntityTypes()).thenAnswer(invocation -> Stream.empty());
    String packageId0 = "packageId0";
    String packageName0 = "packageName0";
    SystemPackage package0 = when(mock(SystemPackage.class).getId()).thenReturn(packageName0).getMock();
    when(package0.getId()).thenReturn(packageId0);
    String packageId1 = "packageId1";
    String packageName1 = "packageName1";
    SystemPackage package1 = when(mock(SystemPackage.class).getId()).thenReturn(packageName1).getMock();
    when(package1.getId()).thenReturn(packageId1);
    when(systemPackageRegistry.getSystemPackages()).thenReturn(Stream.of(package0, package1));
    when(dataService.findAll(PACKAGE, Package.class)).thenAnswer(invocation -> Stream.of(package0));
    systemEntityTypePersister.persist();
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
    verify(metaDataService).upsertPackages(captor.capture());
    assertEquals(captor.getValue().collect(toList()), newArrayList(package0, package1));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemPackage(org.molgenis.data.meta.SystemPackage) Attribute(org.molgenis.data.meta.model.Attribute) Stream(java.util.stream.Stream) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 5 with SystemPackage

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

the class SystemPackageRegistrar method register.

public void register(ContextRefreshedEvent event) {
    ApplicationContext ctx = event.getApplicationContext();
    Map<String, SystemPackage> systemPackageMap = ctx.getBeansOfType(SystemPackage.class);
    systemPackageMap.values().forEach(this::register);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SystemPackage(org.molgenis.data.meta.SystemPackage)

Aggregations

SystemPackage (org.molgenis.data.meta.SystemPackage)5 Attribute (org.molgenis.data.meta.model.Attribute)3 EntityType (org.molgenis.data.meta.model.EntityType)3 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)3 Test (org.testng.annotations.Test)3 Stream (java.util.stream.Stream)2 ApplicationContext (org.springframework.context.ApplicationContext)2 SystemEntityType (org.molgenis.data.meta.SystemEntityType)1 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)1 EntityTypeMetadata (org.molgenis.data.meta.model.EntityTypeMetadata)1 Package (org.molgenis.data.meta.model.Package)1 RootSystemPackage (org.molgenis.data.system.model.RootSystemPackage)1