Search in sources :

Example 71 with Entity

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]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 72 with Entity

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)));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 73 with Entity

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 74 with Entity

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);
}
Also used : Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 75 with Entity

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);
}
Also used : Entity(org.molgenis.data.Entity) ScriptException(org.molgenis.script.core.ScriptException) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

Entity (org.molgenis.data.Entity)448 Test (org.testng.annotations.Test)295 DynamicEntity (org.molgenis.data.support.DynamicEntity)192 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)120 Attribute (org.molgenis.data.meta.model.Attribute)111 EntityType (org.molgenis.data.meta.model.EntityType)110 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)37 MolgenisDataException (org.molgenis.data.MolgenisDataException)20 QueryImpl (org.molgenis.data.support.QueryImpl)20 AttributeType (org.molgenis.data.meta.AttributeType)18 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)18 Stream (java.util.stream.Stream)17 QueryRule (org.molgenis.data.QueryRule)16 MultiAllelicResultFilter (org.molgenis.data.annotation.core.filter.MultiAllelicResultFilter)16 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)16 Objects.requireNonNull (java.util.Objects.requireNonNull)15 DataService (org.molgenis.data.DataService)15 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 Instant (java.time.Instant)13