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