use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class MetaDataServiceImplTest method getPackages.
@Test
public void getPackages() {
Package package0 = mock(Package.class);
Package package1 = mock(Package.class);
when(dataService.findAll(PACKAGE, Package.class)).thenReturn(Stream.of(package0, package1));
assertEquals(metaDataServiceImpl.getPackages(), newArrayList(package0, package1));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class MetaDataServiceImplTest method getRepositoryTyped.
@SuppressWarnings("unchecked")
@Test
public void getRepositoryTyped() {
String entityTypeId = "entity";
EntityType entityType = when(mock(EntityType.class).isAbstract()).thenReturn(false).getMock();
String backendName = "backend";
when(entityType.getBackend()).thenReturn(backendName);
when(dataService.findOneById(eq(ENTITY_TYPE_META_DATA), eq(entityTypeId), any(Fetch.class), eq(EntityType.class))).thenReturn(entityType);
RepositoryCollection repoCollection = mock(RepositoryCollection.class);
Repository<Package> repo = mock(Repository.class);
when(repoCollection.getRepository(entityType)).thenReturn((Repository<Entity>) (Repository<?>) repo);
when(repoCollectionRegistry.getRepositoryCollection(backendName)).thenReturn(repoCollection);
assertEquals(metaDataServiceImpl.getRepository(entityTypeId, Package.class), repo);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class MetaUtilsTest method isSystemPackageTrue.
@Test
public void isSystemPackageTrue() {
Package package_ = mock(Package.class);
when(package_.getId()).thenReturn(PACKAGE_SYSTEM);
assertTrue(MetaUtils.isSystemPackage(package_));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EntityUtils method equals.
/**
* Returns true if entity metadata equals another entity metadata. TODO docs
*/
public static boolean equals(EntityType entityType, EntityType otherEntityType) {
if (entityType == null && otherEntityType != null)
return false;
if (entityType != null && otherEntityType == null)
return false;
if (!(entityType != null && entityType.getId().equals(otherEntityType.getId())))
return false;
if (!Objects.equals(entityType.getLabel(), otherEntityType.getLabel()))
return false;
if (!Objects.equals(entityType.getDescription(), otherEntityType.getDescription()))
return false;
if (entityType.isAbstract() != otherEntityType.isAbstract())
return false;
// NB This is at such a low level that we do not know the default backend
// so we don't check if the other one is the default if the backend is null.
String backend = entityType.getBackend();
String otherBackend = otherEntityType.getBackend();
if ((backend == null && otherBackend != null) || (backend != null && otherBackend == null) || (backend != null && !backend.equals(otherBackend))) {
return false;
}
// compare package identifiers
Package pack = entityType.getPackage();
Package otherPackage = otherEntityType.getPackage();
if (pack == null && otherPackage != null)
return false;
if (pack != null && otherPackage == null)
return false;
if (pack != null && !pack.getIdValue().equals(otherPackage.getIdValue())) {
return false;
}
// compare id attribute identifier (identifier might be null if id attribute hasn't been persisted yet)
Attribute ownIdAttribute = entityType.getOwnIdAttribute();
Attribute otherOwnIdAttribute = otherEntityType.getOwnIdAttribute();
if (ownIdAttribute == null && otherOwnIdAttribute != null)
return false;
if (ownIdAttribute != null && otherOwnIdAttribute == null)
return false;
if (ownIdAttribute != null && !Objects.equals(ownIdAttribute.getIdentifier(), otherOwnIdAttribute.getIdentifier()))
return false;
// compare label attribute identifier (identifier might be null if id attribute hasn't been persisted yet)
Attribute ownLabelAttribute = entityType.getOwnLabelAttribute();
Attribute otherOwnLabelAttribute = otherEntityType.getOwnLabelAttribute();
if (ownLabelAttribute == null && otherOwnLabelAttribute != null)
return false;
if (ownLabelAttribute != null && otherOwnLabelAttribute == null)
return false;
if (ownLabelAttribute != null && !Objects.equals(ownLabelAttribute.getIdentifier(), otherOwnLabelAttribute.getIdentifier()))
return false;
// compare lookup attribute identifiers
List<Attribute> lookupAttrs = newArrayList(entityType.getOwnLookupAttributes());
List<Attribute> otherLookupAttrs = newArrayList(otherEntityType.getOwnLookupAttributes());
if (lookupAttrs.size() != otherLookupAttrs.size())
return false;
for (int i = 0; i < lookupAttrs.size(); ++i) {
// identifier might be null if id attribute hasn't been persisted yet
if (!Objects.equals(lookupAttrs.get(i).getIdentifier(), otherLookupAttrs.get(i).getIdentifier())) {
return false;
}
}
// compare extends entity identifier
EntityType extendsEntityType = entityType.getExtends();
EntityType otherExtendsEntityType = otherEntityType.getExtends();
if (extendsEntityType == null && otherExtendsEntityType != null)
return false;
if (extendsEntityType != null && otherExtendsEntityType == null)
return false;
if (extendsEntityType != null && !extendsEntityType.getId().equals(otherExtendsEntityType.getId()))
return false;
// compare attributes
if (!equals(entityType.getOwnAllAttributes(), otherEntityType.getOwnAllAttributes()))
return false;
// compare tag identifiers
List<Tag> tags = newArrayList(entityType.getTags());
List<Tag> otherTags = newArrayList(otherEntityType.getTags());
if (tags.size() != otherTags.size())
return false;
for (int i = 0; i < tags.size(); ++i) {
if (!tags.get(i).getId().equals(otherTags.get(i).getId()))
return false;
}
return entityType.getIndexingDepth() == otherEntityType.getIndexingDepth();
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PostgreSqlQueryGeneratorTest method getSqlWhere.
@Test
public void getSqlWhere() {
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("data_categories", categoryEntity);
when(collectionsEntity.getPackage()).thenReturn(eric);
when(collectionsEntity.getAttribute("type")).thenReturn(typeAttribute);
when(collectionsEntity.getAttribute("data_categories")).thenReturn(categoryAttribute);
when(collectionsEntity.getAtomicAttributes()).thenReturn(asList(collectionsIdAttribute, typeAttribute, categoryAttribute));
QueryRule typeRule = new QueryRule(NESTED, newArrayList(new QueryRule("type", EQUALS, "POPULATION_BASED"), new QueryRule(OR), new QueryRule("type", EQUALS, "QUALITY_CONTROL")));
QueryRule categoryRule = new QueryRule(NESTED, newArrayList(new QueryRule("data_categories", EQUALS, "MEDICAL_RECORDS"), new QueryRule(OR), new QueryRule("data_categories", EQUALS, "NATIONAL_REGISTRIES")));
QueryImpl<Entity> q = new QueryImpl<>(new QueryRule(NESTED, newArrayList(newArrayList(typeRule, new QueryRule(AND), categoryRule))));
List<Object> parameters = Lists.newArrayList();
String sqlWhere = PostgreSqlQueryGenerator.getSqlWhere(collectionsEntity, q, parameters, new AtomicInteger());
assertEquals(sqlWhere, "((\"type_filter1\".\"type\" = ? OR \"type_filter2\".\"type\" = ?)" + " AND " + "(\"data_categories_filter3\".\"data_categories\" = ? OR \"data_categories_filter4\".\"data_categories\" = ?))");
}
Aggregations