Search in sources :

Example 11 with EntityType

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

the class EntityTypeRepositoryDecorator method addAndRemoveAttributesInBackend.

/**
 * Add and remove entity attributes in the backend for an {@link EntityType}.
 * If the {@link EntityType} is abstract, will update all concrete extending {@link EntityType}s.
 * Attribute updates are handled by the {@link AttributeRepositoryDecorator}.
 *
 * @param entityType {@link EntityType} containing the desired situation.
 */
private void addAndRemoveAttributesInBackend(EntityType entityType) {
    EntityType existingEntityType = delegate().findOneById(entityType.getId());
    Map<String, Attribute> attrsMap = toAttributesMap(entityType);
    Map<String, Attribute> existingAttrsMap = toAttributesMap(existingEntityType);
    dataService.getMeta().getConcreteChildren(entityType).forEach(concreteEntityType -> {
        RepositoryCollection backend = dataService.getMeta().getBackend(concreteEntityType);
        EntityType concreteExistingEntityType = delegate().findOneById(concreteEntityType.getId());
        addNewAttributesInBackend(attrsMap, existingAttrsMap, backend, concreteExistingEntityType);
        deleteRemovedAttributesInBackend(attrsMap, existingAttrsMap, backend, concreteExistingEntityType);
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute)

Example 12 with EntityType

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

the class EntityTypeRepositoryDecorator method add.

@Override
public Integer add(Stream<EntityType> entities) {
    AtomicInteger count = new AtomicInteger();
    entities.filter(entity -> {
        count.incrementAndGet();
        return true;
    }).forEach(this::addEntityType);
    return count.get();
}
Also used : Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) org.molgenis.data(org.molgenis.data) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) String.format(java.lang.String.format) TreeTraverser(com.google.common.collect.TreeTraverser) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Sets.difference(com.google.common.collect.Sets.difference) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Function.identity(java.util.function.Function.identity) Lists.reverse(com.google.common.collect.Lists.reverse) Nonnull(javax.annotation.Nonnull) Spliterator(java.util.Spliterator) ATTRIBUTE_META_DATA(org.molgenis.data.meta.model.AttributeMetadata.ATTRIBUTE_META_DATA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 13 with EntityType

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

the class EntityUtilsTest method getTypedValueStringAttributeEntityManagerXref.

@Test
public void getTypedValueStringAttributeEntityManagerXref() {
    String valueStr = "0";
    Attribute attr = mock(Attribute.class);
    EntityType refEntityType = mock(EntityType.class);
    Attribute refIdAttr = mock(Attribute.class);
    when(refIdAttr.getDataType()).thenReturn(STRING);
    when(refEntityType.getIdAttribute()).thenReturn(refIdAttr);
    when(attr.getRefEntity()).thenReturn(refEntityType);
    when(attr.getDataType()).thenReturn(XREF);
    Entity entity = mock(Entity.class);
    EntityManager entityManager = mock(EntityManager.class);
    when(entityManager.getReference(refEntityType, valueStr)).thenReturn(entity);
    assertEquals(EntityUtils.getTypedValue(valueStr, attr, entityManager), entity);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) EntityManager(org.molgenis.data.EntityManager) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 14 with EntityType

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

the class EntityUtilsTest method isEmptyNoAttributes.

@Test
public void isEmptyNoAttributes() {
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    when(entityType.getAtomicAttributes()).thenReturn(emptyList());
    assertTrue(EntityUtils.isEmpty(new DynamicEntity(entityType)));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

Example 15 with EntityType

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

the class EntityUtilsTest method isEmptyAttributeValuesNotNull.

@Test
public void isEmptyAttributeValuesNotNull() {
    EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    Attribute attr = when(mock(Attribute.class).getName()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(STRING);
    when(entityType.getAtomicAttributes()).thenReturn(singletonList(attr));
    when(entityType.getAttribute("attr")).thenReturn(attr);
    assertFalse(EntityUtils.isEmpty(new DynamicEntity(entityType, of("attr", "val"))));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test)

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