Search in sources :

Example 1 with EntityType

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

the class EmxDataProvider method toRefEntities.

private List<Entity> toRefEntities(Attribute attr, Object emxValue) {
    List<Entity> refEntities;
    if (emxValue != null) {
        if (emxValue instanceof Iterable<?>) {
            List<Entity> mrefEntities = new ArrayList<>();
            for (Object emxValueItem : (Iterable<?>) emxValue) {
                Entity entityValue;
                if (emxValueItem instanceof Entity) {
                    entityValue = toEntity(attr.getRefEntity(), (Entity) emxValueItem);
                } else {
                    EntityType xrefEntity = attr.getRefEntity();
                    Object entityId = DataConverter.convert(emxValueItem, xrefEntity.getIdAttribute());
                    entityValue = entityManager.getReference(xrefEntity, entityId);
                }
                mrefEntities.add(entityValue);
            }
            refEntities = mrefEntities;
        } else {
            EntityType mrefEntity = attr.getRefEntity();
            Attribute refIdAttr = mrefEntity.getIdAttribute();
            String[] tokens = StringUtils.split(emxValue.toString(), ',');
            List<Entity> mrefEntities = new ArrayList<>();
            for (String token : tokens) {
                Object entityId = DataConverter.convert(token.trim(), refIdAttr);
                mrefEntities.add(entityManager.getReference(mrefEntity, entityId));
            }
            refEntities = mrefEntities;
        }
    } else {
        refEntities = emptyList();
    }
    return refEntities;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ArrayList(java.util.ArrayList)

Example 2 with EntityType

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

the class EmxDataProviderTest method testHasEntitiesTrue.

@Test
public void testHasEntitiesTrue() throws Exception {
    String entityTypeId = "EntityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    RepositoryCollection repositoryCollection = mock(RepositoryCollection.class);
    when(repositoryCollection.hasRepository(entityType)).thenReturn(true);
    when(emxImportJob.getSource()).thenReturn(repositoryCollection);
    assertTrue(emxDataProvider.hasEntities(entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with EntityType

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

the class EmxDataProviderTest method testHasEntitiesAlternativeEntityTypeIdTrue.

@Test
public void testHasEntitiesAlternativeEntityTypeIdTrue() throws Exception {
    String entityTypeId = "base_EntityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    RepositoryCollection repositoryCollection = mock(RepositoryCollection.class);
    when(repositoryCollection.hasRepository("EntityTypeId")).thenReturn(true);
    when(emxImportJob.getSource()).thenReturn(repositoryCollection);
    assertTrue(emxDataProvider.hasEntities(entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 4 with EntityType

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

the class EmxDataProviderTest method testHasEntitiesFalse.

@Test
public void testHasEntitiesFalse() throws Exception {
    String entityTypeId = "EntityTypeId";
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
    RepositoryCollection repositoryCollection = mock(RepositoryCollection.class);
    when(repositoryCollection.hasRepository(entityType)).thenReturn(false);
    when(emxImportJob.getSource()).thenReturn(repositoryCollection);
    assertFalse(emxDataProvider.hasEntities(entityType));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 5 with EntityType

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

the class IndexActionRepositoryDecorator method registerRefEntityIndexActions.

/**
 * Register index actions for the given entity for entity types with bidirectional attribute values.
 *
 * @param entity entity to add or delete
 */
private void registerRefEntityIndexActions(Entity entity) {
    // bidirectional attribute: register indexing actions for other side
    getEntityType().getMappedByAttributes().forEach(mappedByAttr -> {
        EntityType mappedByAttrRefEntity = mappedByAttr.getRefEntity();
        entity.getEntities(mappedByAttr.getName()).forEach(refEntity -> indexActionRegisterService.register(mappedByAttrRefEntity, refEntity.getIdValue()));
    });
    getEntityType().getInversedByAttributes().forEach(inversedByAttr -> {
        Entity refEntity = entity.getEntity(inversedByAttr.getName());
        if (refEntity != null) {
            EntityType inversedByAttrRefEntity = inversedByAttr.getRefEntity();
            indexActionRegisterService.register(inversedByAttrRefEntity, refEntity.getIdValue());
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15