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