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