Search in sources :

Example 26 with DynamicEntity

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]");
}
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 27 with DynamicEntity

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)));
}
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 28 with DynamicEntity

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);
}
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 29 with DynamicEntity

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);
    }
}
Also used : DefaultPackage(org.molgenis.data.meta.DefaultPackage) Progress(org.molgenis.jobs.Progress) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) AlgorithmService(org.molgenis.semanticmapper.service.AlgorithmService) PermissionSystemService(org.molgenis.data.security.permission.PermissionSystemService) MetaDataService(org.molgenis.data.meta.MetaDataService) Collections.singletonList(java.util.Collections.singletonList) User(org.molgenis.data.security.auth.User) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) JsMagmaScriptEvaluator(org.molgenis.js.magma.JsMagmaScriptEvaluator) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) SOURCE(org.molgenis.semanticmapper.service.impl.MappingServiceImpl.SOURCE) Collectors.toSet(java.util.stream.Collectors.toSet) UserFactory(org.molgenis.data.security.auth.UserFactory) UserTestConfig(org.molgenis.data.security.config.UserTestConfig) org.mockito(org.mockito) org.molgenis.data(org.molgenis.data) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) MappingProjectMetaData(org.molgenis.semanticmapper.meta.MappingProjectMetaData) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) EntityBaseTestConfig(org.molgenis.data.config.EntityBaseTestConfig) Strictness(org.mockito.quality.Strictness) EntityUtils(org.molgenis.data.util.EntityUtils) Assert.assertEquals(org.testng.Assert.assertEquals) Lists(com.google.common.collect.Lists) DynamicEntity(org.molgenis.data.support.DynamicEntity) Assert(org.testng.Assert) MAPPING_BATCH_SIZE(org.molgenis.semanticmapper.service.impl.MappingServiceImpl.MAPPING_BATCH_SIZE) MappingProjectRepository(org.molgenis.semanticmapper.repository.MappingProjectRepository) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) AttributeType(org.molgenis.data.meta.AttributeType) Import(org.springframework.context.annotation.Import) Mockito.when(org.mockito.Mockito.when) MappingTargetMetaData(org.molgenis.semanticmapper.meta.MappingTargetMetaData) Consumer(java.util.function.Consumer) ROLE_ID(org.molgenis.data.meta.model.EntityType.AttributeRole.ROLE_ID) org.molgenis.data.meta.model(org.molgenis.data.meta.model) MappingTarget(org.molgenis.semanticmapper.mapping.model.MappingTarget) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Package(org.molgenis.data.meta.model.Package) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 30 with DynamicEntity

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

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3