use of org.molgenis.data.Entity 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.Entity 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.Entity 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.Entity in project molgenis by molgenis.
the class AlgorithmServiceImplTest method testApplyConvertException.
private void testApplyConvertException(String algorithmResult, AttributeType attributeType) {
AttributeMapping attributeMapping = mock(AttributeMapping.class);
String algorithm = "algorithm";
when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
Attribute targetAttribute = when(mock(Attribute.class).getDataType()).thenReturn(attributeType).getMock();
when(attributeMapping.getTargetAttribute()).thenReturn(targetAttribute);
Entity sourceEntity = mock(Entity.class);
when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(algorithmResult);
algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class AlgorithmServiceImplTest method testApplyWithInvalidScript.
@Test(expectedExceptions = ScriptException.class, expectedExceptionsMessageRegExp = "algorithm is not defined")
public void testApplyWithInvalidScript() {
AttributeMapping attributeMapping = mock(AttributeMapping.class);
String algorithm = "algorithm";
when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
Entity sourceEntity = mock(Entity.class);
when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(new ScriptException("algorithm is not defined"));
algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
Aggregations