use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class AlgorithmServiceImplIT method testDotAnnotationWithMref.
@Test
public void testDotAnnotationWithMref() throws ParseException {
EntityType referenceEntityType = entityTypeFactory.create("reference");
referenceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
referenceEntityType.addAttribute(attrMetaFactory.create().setName("label"));
Entity referenceEntity1 = new DynamicEntity(referenceEntityType);
referenceEntity1.set("id", "1");
referenceEntity1.set("label", "label 1");
Entity referenceEntity2 = new DynamicEntity(referenceEntityType);
referenceEntity2.set("id", "2");
referenceEntity2.set("label", "label 2");
EntityType sourceEntityType = entityTypeFactory.create("source");
sourceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
sourceEntityType.addAttribute(attrMetaFactory.create().setName("source_mref").setDataType(MREF));
Entity sourceEntity = new DynamicEntity(sourceEntityType);
sourceEntity.set("id", "1");
sourceEntity.set("source_mref", newArrayList(referenceEntity1, referenceEntity2));
Attribute targetAttribute = attrMetaFactory.create().setName("target_label");
AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
attributeMapping.setAlgorithm("var result = [];$('source_mref').map(function(mref){result.push(mref.val.label)});result");
Object result = algorithmService.apply(attributeMapping, sourceEntity, sourceEntityType);
assertEquals(result, "[label 1, label 2]");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class EntityMappingRepositoryImplTest method testUpsert.
@Test
public void testUpsert() {
Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
List<Attribute> sourceAttributes = Lists.newArrayList();
EntityType sourceEntityType = entityTypeFactory.create("source");
EntityType targetEntityType = entityTypeFactory.create("target");
targetEntityType.addAttribute(targetAttribute);
List<AttributeMapping> attributeMappings = Lists.newArrayList();
attributeMappings.add(new AttributeMapping("1", "targetAttribute", targetAttribute, "algorithm", sourceAttributes, CURATED.toString()));
Collection<EntityMapping> entityMappings = singletonList(new EntityMapping(AUTO_ID, sourceEntityType, targetEntityType, attributeMappings));
Entity attributeMappingEntity = new DynamicEntity(attrMappingMeta);
attributeMappingEntity.set(EntityMappingMetaData.IDENTIFIER, AUTO_ID);
attributeMappingEntity.set(AttributeMappingMetaData.TARGET_ATTRIBUTE, "targetAttribute");
attributeMappingEntity.set(AttributeMappingMetaData.SOURCE_ATTRIBUTES, "");
attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM, "algorithm");
attributeMappingEntity.set(AttributeMappingMetaData.ALGORITHM_STATE, CURATED.toString());
List<Entity> attributeMappingEntities = Lists.newArrayList();
attributeMappingEntities.add(attributeMappingEntity);
List<Entity> entityMappingEntities = Lists.newArrayList();
Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, AUTO_ID);
entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, "source");
entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
entityMappingEntities.add(entityMappingEntity);
Assert.assertTrue(EntityUtils.equals(entityMappingRepository.upsert(entityMappings).get(0), entityMappingEntities.get(0)));
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class MappingTargetRepositoryImplTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
// POJOs
EntityType sourceEntityType = entityTypeFactory.create("source");
targetEntityType = entityTypeFactory.create("target");
Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
targetEntityType.addAttribute(targetAttribute);
entityMappings = singletonList(new EntityMapping("entityMappingID", sourceEntityType, targetEntityType, emptyList()));
mappingTargets = singletonList(new MappingTarget("mappingTargetID", targetEntityType, entityMappings));
// Entities
Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, "entityMappingID");
entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, "source");
entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, emptyList());
Entity mappingTargetEntity = new DynamicEntity(mappingTargetMeta);
mappingTargetEntity.set(IDENTIFIER, "mappingTargetID");
mappingTargetEntity.set(TARGET, "target");
entityMappingEntities = singletonList(entityMappingEntity);
mappingTargetEntity.set(ENTITY_MAPPINGS, entityMappingEntities);
mappingTargetEntities = singletonList(mappingTargetEntity);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class MappingServiceImplTest method createEntities.
private void createEntities(EntityType targetMeta, List<Entity> sourceGeneEntities, List<Entity> expectedEntities) {
for (int i = 0; i < 4; ++i) {
Entity geneEntity = new DynamicEntity(geneMetaData);
geneEntity.set("id", String.valueOf(i));
geneEntity.set("length", i * 2d);
sourceGeneEntities.add(geneEntity);
when(algorithmService.apply(argThat(obj -> obj != null && obj.getAlgorithm().equals("$('id').value()")), ArgumentMatchers.eq(geneEntity), ArgumentMatchers.eq(geneMetaData))).thenReturn(geneEntity.getString("id"));
when(algorithmService.apply(argThat(obj -> obj != null && obj.getAlgorithm().equals("$('length').value()")), ArgumentMatchers.eq(geneEntity), ArgumentMatchers.eq(geneMetaData))).thenReturn(geneEntity.getDouble("length"));
Entity expectedEntity = new DynamicEntity(targetMeta);
expectedEntity.set("identifier", String.valueOf(i));
expectedEntity.set("height", i * 2d);
expectedEntity.set("source", geneMetaData.getId());
expectedEntities.add(expectedEntity);
}
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class AttributeMappingRepositoryImpl method toAttributeMappingEntity.
private Entity toAttributeMappingEntity(AttributeMapping attributeMapping) {
Entity attributeMappingEntity = new DynamicEntity(attributeMappingMetaData);
attributeMappingEntity.set(IDENTIFIER, attributeMapping.getIdentifier());
attributeMappingEntity.set(TARGET_ATTRIBUTE, attributeMapping.getTargetAttributeName());
attributeMappingEntity.set(ALGORITHM, attributeMapping.getAlgorithm());
attributeMappingEntity.set(SOURCE_ATTRIBUTES, attributeMapping.getSourceAttributes().stream().map(Attribute::getName).collect(Collectors.joining(",")));
attributeMappingEntity.set(ALGORITHM_STATE, attributeMapping.getAlgorithmState().toString());
return attributeMappingEntity;
}
Aggregations