Search in sources :

Example 26 with Package

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));
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 27 with Package

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetaUtils.getEntityTypeFetch(org.molgenis.data.meta.MetaUtils.getEntityTypeFetch) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 28 with Package

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_));
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 29 with 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();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) Tag(org.molgenis.data.meta.model.Tag)

Example 30 with Package

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\" = ?))");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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