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