Search in sources :

Example 36 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PlatformIT method testDeletePackage.

@WithMockUser(username = USERNAME)
@Test(singleThreaded = true)
public void testDeletePackage() {
    populateUserPermissions();
    runAsSystem(() -> {
        MetaDataService metadataService = dataService.getMeta();
        Package parentPackage = packageFactory.create("parent").setLabel("parent");
        Package subPackage = packageFactory.create("parent_sub").setLabel("sub").setParent(parentPackage);
        metadataService.upsertPackages(Stream.of(parentPackage, subPackage));
        EntityType entityTypeInSubPackage = testHarness.createDynamicRefEntityType("entityInSub", subPackage);
        EntityType entityTypeInParentPackage = testHarness.createDynamicTestEntityType("entityInParent", parentPackage, entityTypeInSubPackage);
        metadataService.upsertEntityTypes(asList(entityTypeInSubPackage, entityTypeInParentPackage));
        List<Entity> entities = createAndAdd(entityTypeInParentPackage, entityTypeInSubPackage, 5);
        Set<Entity> refEntities = entities.stream().map(e -> e.getEntity(ATTR_XREF)).collect(toSet());
        assertPresent(entityTypeInParentPackage, entities);
        assertPresent(entityTypeInSubPackage, newArrayList(refEntities));
        dataService.deleteById(PACKAGE, "parent");
        assertNull(metadataService.getPackage("parent"));
        assertNull(metadataService.getPackage("parent_sub"));
        entities.forEach(this::assertNotPresent);
        refEntities.forEach(this::assertNotPresent);
    });
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) MetaDataServiceImpl(org.molgenis.data.meta.MetaDataServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) IndexActionRegisterServiceImpl(org.molgenis.data.index.IndexActionRegisterServiceImpl) L10N_STRING(org.molgenis.data.i18n.model.L10nStringMetaData.L10N_STRING) EntityListener(org.molgenis.data.listeners.EntityListener) MetaDataService(org.molgenis.data.meta.MetaDataService) Collections.singletonList(java.util.Collections.singletonList) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) ElasticsearchService(org.molgenis.data.elasticsearch.ElasticsearchService) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) L10nString(org.molgenis.data.i18n.model.L10nString) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) EntityTestHarness(org.molgenis.data.EntityTestHarness) LanguageService(org.molgenis.i18n.LanguageService) org.molgenis.data(org.molgenis.data) IndexJobScheduler(org.molgenis.data.index.job.IndexJobScheduler) IndexAction(org.molgenis.data.index.meta.IndexAction) READ(org.molgenis.data.security.EntityTypePermission.READ) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LANGUAGE(org.molgenis.data.i18n.model.LanguageMetadata.LANGUAGE) java.util(java.util) org.testng.annotations(org.testng.annotations) QueryImpl(org.molgenis.data.support.QueryImpl) EntityListenersService(org.molgenis.data.listeners.EntityListenersService) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) AggregateResult(org.molgenis.data.aggregation.AggregateResult) Assert(org.testng.Assert) WithSecurityContextTestExecutionListener(org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener) Objects.requireNonNull(java.util.Objects.requireNonNull) L10nStringMetaData(org.molgenis.data.i18n.model.L10nStringMetaData) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) AttributeType(org.molgenis.data.meta.AttributeType) Logger(org.slf4j.Logger) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) IndexActionMetaData(org.molgenis.data.index.meta.IndexActionMetaData) L10nStringFactory(org.molgenis.data.i18n.model.L10nStringFactory) LanguageFactory(org.molgenis.data.i18n.model.LanguageFactory) Collectors.toList(java.util.stream.Collectors.toList) org.molgenis.data.meta.model(org.molgenis.data.meta.model) ContextConfiguration(org.springframework.test.context.ContextConfiguration) WRITE(org.molgenis.data.security.EntityTypePermission.WRITE) Package(org.molgenis.data.meta.model.Package) Transactional(org.springframework.transaction.annotation.Transactional) MetaDataService(org.molgenis.data.meta.MetaDataService) Package(org.molgenis.data.meta.model.Package) WithMockUser(org.springframework.security.test.context.support.WithMockUser)

Example 37 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PlatformIT method testDeletePackageWithOneToMany.

@WithMockUser(username = USERNAME)
@Test(singleThreaded = true)
public void testDeletePackageWithOneToMany() {
    populateUserPermissions();
    runAsSystem(() -> {
        MetaDataService metadataService = dataService.getMeta();
        Package package_ = packageFactory.create("package_onetomany").setLabel("package");
        metadataService.upsertPackages(Stream.of(package_));
        EntityType refEntityType = testHarness.createDynamicRefEntityType("entityType_onetomany", package_);
        EntityType entityType = testHarness.createDynamicTestEntityType("refEntityType_onetomany", package_, refEntityType);
        Attribute oneToManyAttribute = attributeFactory.create("onetomany").setName("onetomany").setDataType(AttributeType.ONE_TO_MANY).setRefEntity(entityType).setMappedBy(entityType.getAttribute(ATTR_XREF));
        refEntityType.addAttribute(oneToManyAttribute);
        metadataService.upsertEntityTypes(asList(refEntityType, entityType));
        List<Entity> entities = createAndAdd(entityType, refEntityType, 5);
        Set<Entity> refEntities = entities.stream().map(e -> e.getEntity(ATTR_XREF)).collect(toSet());
        assertPresent(entityType, entities);
        assertPresent(refEntityType, newArrayList(refEntities));
        dataService.deleteById(PACKAGE, "package_onetomany");
        assertNull(metadataService.getPackage("package_onetomany"));
        assertNull(dataService.getEntityType(entityType.getId()));
        assertNull(dataService.getEntityType(refEntityType.getId()));
        entities.forEach(this::assertNotPresent);
        refEntities.forEach(this::assertNotPresent);
    });
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) MetaDataServiceImpl(org.molgenis.data.meta.MetaDataServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) IndexActionRegisterServiceImpl(org.molgenis.data.index.IndexActionRegisterServiceImpl) L10N_STRING(org.molgenis.data.i18n.model.L10nStringMetaData.L10N_STRING) EntityListener(org.molgenis.data.listeners.EntityListener) MetaDataService(org.molgenis.data.meta.MetaDataService) Collections.singletonList(java.util.Collections.singletonList) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) ElasticsearchService(org.molgenis.data.elasticsearch.ElasticsearchService) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collectors.toSet(java.util.stream.Collectors.toSet) L10nString(org.molgenis.data.i18n.model.L10nString) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) EntityTestHarness(org.molgenis.data.EntityTestHarness) LanguageService(org.molgenis.i18n.LanguageService) org.molgenis.data(org.molgenis.data) IndexJobScheduler(org.molgenis.data.index.job.IndexJobScheduler) IndexAction(org.molgenis.data.index.meta.IndexAction) READ(org.molgenis.data.security.EntityTypePermission.READ) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LANGUAGE(org.molgenis.data.i18n.model.LanguageMetadata.LANGUAGE) java.util(java.util) org.testng.annotations(org.testng.annotations) QueryImpl(org.molgenis.data.support.QueryImpl) EntityListenersService(org.molgenis.data.listeners.EntityListenersService) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) AggregateResult(org.molgenis.data.aggregation.AggregateResult) Assert(org.testng.Assert) WithSecurityContextTestExecutionListener(org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener) Objects.requireNonNull(java.util.Objects.requireNonNull) L10nStringMetaData(org.molgenis.data.i18n.model.L10nStringMetaData) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) AttributeType(org.molgenis.data.meta.AttributeType) Logger(org.slf4j.Logger) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) IndexActionMetaData(org.molgenis.data.index.meta.IndexActionMetaData) L10nStringFactory(org.molgenis.data.i18n.model.L10nStringFactory) LanguageFactory(org.molgenis.data.i18n.model.LanguageFactory) Collectors.toList(java.util.stream.Collectors.toList) org.molgenis.data.meta.model(org.molgenis.data.meta.model) ContextConfiguration(org.springframework.test.context.ContextConfiguration) WRITE(org.molgenis.data.security.EntityTypePermission.WRITE) Package(org.molgenis.data.meta.model.Package) Transactional(org.springframework.transaction.annotation.Transactional) MetaDataService(org.molgenis.data.meta.MetaDataService) Package(org.molgenis.data.meta.model.Package) WithMockUser(org.springframework.security.test.context.support.WithMockUser)

Example 38 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PostgreSqlQueryGeneratorTest method getSqlSelectMref.

@Test
public void getSqlSelectMref() {
    Package package_ = when(mock(Package.class).getId()).thenReturn("org_molgenis").getMock();
    Attribute ref1IdAttr = when(mock(Attribute.class).getName()).thenReturn("ref1Id").getMock();
    when(ref1IdAttr.getIdentifier()).thenReturn("ref1IdAttrId");
    EntityType ref1Meta = when(mock(EntityType.class).getId()).thenReturn("Ref1").getMock();
    when(ref1Meta.getId()).thenReturn("ref1Id");
    when(ref1Meta.getIdAttribute()).thenReturn(ref1IdAttr);
    Attribute ref2IdAttr = when(mock(Attribute.class).getName()).thenReturn("ref2Id").getMock();
    when(ref2IdAttr.getIdentifier()).thenReturn("ref2IdAttrId");
    EntityType ref2Meta = when(mock(EntityType.class).getId()).thenReturn("Ref2").getMock();
    when(ref2Meta.getId()).thenReturn("ref2Id");
    when(ref2Meta.getIdAttribute()).thenReturn(ref2IdAttr);
    Attribute masterIdAttr = when(mock(Attribute.class).getName()).thenReturn("masterId").getMock();
    when(masterIdAttr.getIdentifier()).thenReturn("masterIdAttrId");
    when(masterIdAttr.getDataType()).thenReturn(STRING);
    Attribute mref1Attr = when(mock(Attribute.class).getName()).thenReturn("mref1").getMock();
    when(mref1Attr.getIdentifier()).thenReturn("mref1AttrId");
    when(mref1Attr.getDataType()).thenReturn(MREF);
    when(mref1Attr.getRefEntity()).thenReturn(ref1Meta);
    Attribute mref2Attr = when(mock(Attribute.class).getName()).thenReturn("mref2").getMock();
    when(mref2Attr.getIdentifier()).thenReturn("mref2AttrId");
    when(mref2Attr.getDataType()).thenReturn(MREF);
    when(mref2Attr.getRefEntity()).thenReturn(ref2Meta);
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("org_molgenis_MasterEntity").getMock();
    when(entityType.getId()).thenReturn("entityTypeId");
    when(entityType.getPackage()).thenReturn(package_);
    when(entityType.getIdAttribute()).thenReturn(masterIdAttr);
    when(entityType.getAttribute("masterId")).thenReturn(masterIdAttr);
    when(entityType.getAttribute("mref1")).thenReturn(mref1Attr);
    when(entityType.getAttribute("mref2")).thenReturn(mref2Attr);
    when(entityType.getAtomicAttributes()).thenReturn(asList(masterIdAttr, mref1Attr, mref2Attr));
    QueryImpl<Entity> q = new QueryImpl<>();
    List<Object> parameters = Lists.newArrayList();
    String sqlSelect = PostgreSqlQueryGenerator.getSqlSelect(entityType, q, parameters, true);
    assertEquals(sqlSelect, "SELECT this.\"masterId\", (SELECT array_agg(DISTINCT ARRAY[\"mref1\".\"order\"::TEXT,\"mref1\".\"mref1\"::TEXT]) FROM \"entityTypeId#c34894ba_mref1\" AS \"mref1\" WHERE this.\"masterId\" = \"mref1\".\"masterId\") AS \"mref1\", (SELECT array_agg(DISTINCT ARRAY[\"mref2\".\"order\"::TEXT,\"mref2\".\"mref2\"::TEXT]) FROM \"entityTypeId#c34894ba_mref2\" AS \"mref2\" WHERE this.\"masterId\" = \"mref2\".\"masterId\") AS \"mref2\" FROM \"entityTypeId#c34894ba\" AS this ORDER BY \"masterId\" ASC");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 39 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PostgreSqlQueryGeneratorTest method getSqlFrom.

@Test
public void getSqlFrom() {
    Package eric = createPackage("eu_bbmri_eric");
    Attribute collectionsIdAttribute = createIdAttribute("collectionsId");
    EntityType collectionsEntity = createMockEntityWithIdAttribute("eu_bbmri_eric_collections", collectionsIdAttribute, "collectionsId");
    Attribute typeIdAttribute = createIdAttribute("typeId");
    EntityType typeEntity = createMockEntityWithIdAttribute("eu_bbmri_eric_type", typeIdAttribute, "typeId");
    Attribute categoryIdAttribute = createIdAttribute("categoryId");
    EntityType categoryEntity = createMockEntityWithIdAttribute("eu_bbmri_eric_category", categoryIdAttribute, "categoryId");
    Attribute typeAttribute = createMrefAttribute("type", typeEntity);
    Attribute categoryAttribute = createMrefAttribute("category", categoryEntity);
    when(collectionsEntity.getPackage()).thenReturn(eric);
    when(collectionsEntity.getAttribute("type")).thenReturn(typeAttribute);
    when(collectionsEntity.getAttribute("category")).thenReturn(categoryAttribute);
    when(collectionsEntity.getAtomicAttributes()).thenReturn(asList(collectionsIdAttribute, typeAttribute, categoryAttribute));
    QueryImpl<Entity> q = new QueryImpl<>();
    List<Object> parameters = Lists.newArrayList();
    String sqlSelect = PostgreSqlQueryGenerator.getSqlSelect(collectionsEntity, q, parameters, true);
    assertEquals(sqlSelect, "SELECT this.\"collectionsId\", (SELECT array_agg(DISTINCT ARRAY[\"type\".\"order\"::TEXT,\"type\".\"type\"::TEXT]) FROM \"eu_bbmri_eric_collecti#4dc023e6_type\" AS \"type\" WHERE this.\"collectionsId\" = \"type\".\"collectionsId\") AS \"type\", (SELECT array_agg(DISTINCT ARRAY[\"category\".\"order\"::TEXT,\"category\".\"category\"::TEXT]) FROM \"eu_bbmri_eric_collecti#4dc023e6_category\" AS \"category\" WHERE this.\"collectionsId\" = \"category\".\"collectionsId\") AS \"category\" FROM \"eu_bbmri_eric_collections#4dc023e6\" AS this ORDER BY \"collectionsId\" ASC");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 40 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PostgreSqlQueryGeneratorTest method getSqlSortOnUnselectedMref.

@Test
public void getSqlSortOnUnselectedMref() {
    Package package_ = when(mock(Package.class).getId()).thenReturn("org_molgenis").getMock();
    Attribute ref1IdAttr = when(mock(Attribute.class).getName()).thenReturn("ref1Id").getMock();
    when(ref1IdAttr.getIdentifier()).thenReturn("ref1IdAttrId");
    EntityType ref1Meta = when(mock(EntityType.class).getId()).thenReturn("Ref1").getMock();
    when(ref1Meta.getId()).thenReturn("ref1Id");
    when(ref1Meta.getIdAttribute()).thenReturn(ref1IdAttr);
    Attribute ref2IdAttr = when(mock(Attribute.class).getName()).thenReturn("ref2Id").getMock();
    when(ref2IdAttr.getIdentifier()).thenReturn("ref2IdAttrId");
    EntityType ref2Meta = when(mock(EntityType.class).getId()).thenReturn("Ref2").getMock();
    when(ref2Meta.getId()).thenReturn("ref2Id");
    when(ref2Meta.getIdAttribute()).thenReturn(ref2IdAttr);
    Attribute masterIdAttr = when(mock(Attribute.class).getName()).thenReturn("masterId").getMock();
    when(masterIdAttr.getIdentifier()).thenReturn("masterIdAttrId");
    when(masterIdAttr.getDataType()).thenReturn(STRING);
    Attribute mref1Attr = when(mock(Attribute.class).getName()).thenReturn("mref1").getMock();
    when(mref1Attr.getIdentifier()).thenReturn("mref1AttrId");
    when(mref1Attr.getDataType()).thenReturn(MREF);
    when(mref1Attr.getRefEntity()).thenReturn(ref1Meta);
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("org_molgenis_MasterEntity").getMock();
    when(entityType.getId()).thenReturn("entityTypeId");
    when(entityType.getPackage()).thenReturn(package_);
    when(entityType.getIdAttribute()).thenReturn(masterIdAttr);
    when(entityType.getAttribute("masterId")).thenReturn(masterIdAttr);
    when(entityType.getAttribute("mref1")).thenReturn(mref1Attr);
    when(entityType.getAtomicAttributes()).thenReturn(asList(masterIdAttr, mref1Attr));
    Fetch fetch = new Fetch().field("masterId");
    Sort sort = new Sort("mref1");
    QueryImpl<Entity> q = new QueryImpl<>();
    q.setFetch(fetch);
    q.setSort(sort);
    List<Object> parameters = Lists.newArrayList();
    String sqlSelect = PostgreSqlQueryGenerator.getSqlSelect(entityType, q, parameters, true);
    assertEquals(sqlSelect, "SELECT this.\"masterId\", (SELECT array_agg(DISTINCT ARRAY[\"mref1\".\"order\"::TEXT,\"mref1\".\"mref1\"::TEXT]) FROM \"entityTypeId#c34894ba_mref1\" AS \"mref1\" WHERE this.\"masterId\" = \"mref1\".\"masterId\") AS \"mref1\" FROM \"entityTypeId#c34894ba\" AS this ORDER BY \"mref1\" ASC, \"masterId\" ASC");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Aggregations

Package (org.molgenis.data.meta.model.Package)98 Test (org.testng.annotations.Test)70 EntityType (org.molgenis.data.meta.model.EntityType)22 Stream (java.util.stream.Stream)20 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Attribute (org.molgenis.data.meta.model.Attribute)11 DefaultPackage (org.molgenis.data.meta.DefaultPackage)10 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 Objects.requireNonNull (java.util.Objects.requireNonNull)6 L10nString (org.molgenis.data.i18n.model.L10nString)6 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 Collectors.toList (java.util.stream.Collectors.toList)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)5 DataService (org.molgenis.data.DataService)5 QueryImpl (org.molgenis.data.support.QueryImpl)5 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 java.util (java.util)3 Collections.singletonList (java.util.Collections.singletonList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3