Search in sources :

Example 81 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class MappingTargetRepositoryImpl method upsert.

private Entity upsert(MappingTarget mappingTarget) {
    List<Entity> entityMappingEntities = entityMappingRepository.upsert(mappingTarget.getEntityMappings());
    Entity mappingTargetEntity;
    if (mappingTarget.getIdentifier() == null) {
        mappingTarget.setIdentifier(idGenerator.generateId());
        mappingTargetEntity = toMappingTargetEntity(mappingTarget, entityMappingEntities);
        dataService.add(mappingTargetMetaData.getId(), mappingTargetEntity);
    } else {
        mappingTargetEntity = toMappingTargetEntity(mappingTarget, entityMappingEntities);
        dataService.update(mappingTargetMetaData.getId(), mappingTargetEntity);
    }
    return mappingTargetEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity)

Example 82 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class OneToOneCategoryAlgorithmGeneratorTest method init.

@BeforeMethod
public void init() {
    dataService = Mockito.mock(DataService.class);
    categoryAlgorithmGenerator = new OneToOneCategoryAlgorithmGenerator(dataService);
    EntityType targetRefEntityType = createCategoricalRefEntityType("POTATO_REF");
    Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Almost daily + daily"));
    Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "Several times a week"));
    Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "About once a week"));
    Entity targetEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "Never + fewer than once a week"));
    Entity targetEntity5 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
    targetAttribute = attrMetaFactory.create().setName("Current Consumption Frequency of Potatoes").setDataType(CATEGORICAL);
    targetAttribute.setRefEntity(targetRefEntityType);
    Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3, targetEntity4, targetEntity5));
    targetEntityType = entityTypeFactory.create("target");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceRefEntityType = createCategoricalRefEntityType("LifeLines_POTATO_REF");
    Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Not this month"));
    Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1 day per month"));
    Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "2-3 days per month"));
    Entity sourceEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "1 day per week"));
    Entity sourceEntity5 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "2-3 days per week"));
    Entity sourceEntity6 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "4-5 days per week"));
    Entity sourceEntity7 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "6-7 days per week"));
    Entity sourceEntity8 = new DynamicEntity(targetRefEntityType, of("code", 8, "label", "9 days per week"));
    sourceAttribute = attrMetaFactory.create().setName("MESHED_POTATO").setDataType(CATEGORICAL);
    sourceAttribute.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
    sourceAttribute.setRefEntity(sourceRefEntityType);
    Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3, sourceEntity4, sourceEntity5, sourceEntity6, sourceEntity7, sourceEntity8));
    sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttributes(Lists.newArrayList(sourceAttribute));
}
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) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 83 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class OneToOneCategoryAlgorithmGeneratorTest method testGenerateRules.

@Test
public void testGenerateRules() {
    EntityType targetRefEntityType = createCategoricalRefEntityType("HOP_HYPERTENSION");
    Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 0, "label", "Never had high blood pressure "));
    Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Ever had high blood pressure "));
    Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "Missing"));
    Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3));
    targetAttribute = attrMetaFactory.create().setName("History of Hypertension").setDataType(CATEGORICAL);
    targetAttribute.setRefEntity(targetRefEntityType);
    EntityType sourceRefEntityType = createCategoricalRefEntityType("High_blood_pressure_ref");
    Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes"));
    Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no"));
    Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "I do not know"));
    Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3));
    sourceAttribute = attrMetaFactory.create().setName("High_blood_pressure").setDataType(CATEGORICAL);
    sourceAttribute.setRefEntity(sourceRefEntityType);
    String generatedAlgorithm = categoryAlgorithmGenerator.generate(targetAttribute, singletonList(sourceAttribute), targetEntityType, sourceEntityType);
    String expectedAlgorithm = "$('High_blood_pressure').map({\"1\":\"1\",\"2\":\"0\",\"3\":\"9\"}, null, null).value();";
    Assert.assertEquals(generatedAlgorithm, expectedAlgorithm);
}
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) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 84 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EffectStructureConverterTest method testCreateVcfEntityStructure.

@Test
public void testCreateVcfEntityStructure() {
    Entity effect1 = mock(Entity.class);
    Entity effect2 = mock(Entity.class);
    Entity effect3 = mock(Entity.class);
    when(effect1.getIdValue()).thenReturn("effect_ID1");
    when(effect1.getEntity(VARIANT)).thenReturn(variant1);
    when(effect1.getEntityType()).thenReturn(effectEntityType);
    when(effect1.get("Alt_Allele")).thenReturn("1");
    when(effect1.get("Gene_Name")).thenReturn("2");
    when(effect1.get("Annotation")).thenReturn("3");
    when(effect1.get("Putative_impact")).thenReturn("4");
    when(effect1.get("Gene_ID")).thenReturn("5");
    when(effect1.get("Feature_type")).thenReturn("6");
    when(effect1.get("Feature_ID")).thenReturn("7");
    when(effect1.get("Transcript_biotype")).thenReturn("8");
    when(effect1.get("Rank_total")).thenReturn("9");
    when(effect2.getIdValue()).thenReturn("effect_ID2");
    when(effect2.getEntity(VARIANT)).thenReturn(variant1);
    when(effect2.getEntityType()).thenReturn(effectEntityType);
    when(effect2.get("Alt_Allele")).thenReturn("1");
    when(effect2.get("Gene_Name")).thenReturn("2");
    when(effect2.get("Annotation")).thenReturn("3");
    when(effect2.get("Putative_impact")).thenReturn("4");
    when(effect2.get("Gene_ID")).thenReturn("5");
    when(effect2.get("Feature_type")).thenReturn("6");
    when(effect2.get("Feature_ID")).thenReturn("7");
    when(effect2.get("Transcript_biotype")).thenReturn("8");
    when(effect2.get("Rank_total")).thenReturn("9");
    when(effect3.getIdValue()).thenReturn("effect_ID3");
    when(effect3.getEntity(VARIANT)).thenReturn(variant2);
    when(effect3.getEntityType()).thenReturn(effectEntityType);
    when(effect3.get("Alt_Allele")).thenReturn("1");
    when(effect3.get("Gene_Name")).thenReturn("2");
    when(effect3.get("Annotation")).thenReturn("3");
    when(effect3.get("Putative_impact")).thenReturn("4");
    when(effect3.get("Gene_ID")).thenReturn("5");
    when(effect3.get("Feature_type")).thenReturn("6");
    when(effect3.get("Feature_ID")).thenReturn("7");
    when(effect3.get("Transcript_biotype")).thenReturn("8");
    when(effect3.get("Rank_total")).thenReturn("9");
    Iterator<Entity> result = effectStructureConverter.createVcfEntityStructure(Arrays.asList(effect1, effect2, effect3).iterator());
    assertTrue(result.hasNext());
    Entity expectedVariant1 = result.next();
    assertEquals(2, Iterables.size(expectedVariant1.getEntities("EFFECT")));
    Iterator<Entity> effectsIterator = expectedVariant1.getEntities("EFFECT").iterator();
    assertEquals(effectsIterator.next().getIdValue(), "effect_ID1");
    assertEquals(effectsIterator.next().getIdValue(), "effect_ID2");
    assertTrue(result.hasNext());
    Entity expectedVariant2 = result.next();
    assertEquals(1, Iterables.size(expectedVariant2.getEntities("EFFECT")));
    effectsIterator = expectedVariant2.getEntities("EFFECT").iterator();
    assertEquals(effectsIterator.next().getIdValue(), "effect_ID3");
    assertFalse(result.hasNext());
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 85 with Entity

use of org.molgenis.data.Entity in project molgenis by molgenis.

the class EffectStructureConverterTest method testCreateVariantEffectStructure.

@Test
public void testCreateVariantEffectStructure() {
    VcfRepository vcfRepository = mock(VcfRepository.class);
    when(vcfRepository.getEntityType()).thenReturn(vcfInputEntityType);
    when(vcfRepository.spliterator()).thenReturn(entities.spliterator());
    List<Entity> resultEntities = effectStructureConverter.createVariantEffectStructure(EFFECT, Collections.emptyList(), vcfRepository).collect(Collectors.toList());
    assertEquals(resultEntities.size(), 3);
    assertEquals(resultEntities.get(0).get("Alt_Allele"), "A");
    assertEquals(resultEntities.get(0).get("Gene_Name"), "GEN1");
    assertEquals(resultEntities.get(0).get("Annotation"), "missense_variant");
    assertEquals(resultEntities.get(0).get("Putative_impact"), "MODERATE");
    assertEquals(resultEntities.get(0).get("Gene_ID"), "GEN1");
    assertEquals(resultEntities.get(0).get("Feature_type"), "transcript");
    assertEquals(resultEntities.get(0).get("Feature_ID"), "NM_123456.7");
    assertEquals(resultEntities.get(0).get("Transcript_biotype"), "Coding");
    assertEquals(resultEntities.get(0).get("Rank_total"), "4/4");
    assertEquals(resultEntities.get(0).get("HGVS_c"), "c.1234C>T");
    assertEquals(resultEntities.get(0).get("HGVS_p"), "p.Thr123Met");
    assertEquals(resultEntities.get(0).get("cDNA_position"), "1234/5678");
    assertEquals(resultEntities.get(0).get("CDS_position"), "2345/6789");
    assertEquals(resultEntities.get(0).get("Protein_position"), "111/222");
    assertEquals(resultEntities.get(0).get("Distance_to_feature"), "");
    assertEquals(resultEntities.get(0).get("Errors"), "");
    assertEquals(resultEntities.get(0).get("VARIANT").toString(), variant1.toString());
    assertEquals(resultEntities.get(1).get("Alt_Allele"), "A");
    assertEquals(resultEntities.get(1).get("Gene_Name"), "GEN1");
    assertEquals(resultEntities.get(1).get("Annotation"), "missense_variant");
    assertEquals(resultEntities.get(1).get("Putative_impact"), "MODERATE");
    assertEquals(resultEntities.get(1).get("Gene_ID"), "GEN1");
    assertEquals(resultEntities.get(1).get("Feature_type"), "transcript");
    assertEquals(resultEntities.get(1).get("Feature_ID"), "NM_123456.7");
    assertEquals(resultEntities.get(1).get("Transcript_biotype"), "Coding");
    assertEquals(resultEntities.get(1).get("Rank_total"), "4/4");
    assertEquals(resultEntities.get(1).get("HGVS_c"), "c.1234C>T");
    assertEquals(resultEntities.get(1).get("HGVS_p"), "p.Thr123Met");
    assertEquals(resultEntities.get(1).get("cDNA_position"), "1234/5678");
    assertEquals(resultEntities.get(1).get("CDS_position"), "2345/6789");
    assertEquals(resultEntities.get(1).get("Protein_position"), "111/222");
    assertEquals(resultEntities.get(1).get("Distance_to_feature"), "");
    assertEquals(resultEntities.get(1).get("Errors"), "");
    assertEquals(resultEntities.get(1).get("VARIANT").toString(), variant2.toString());
    assertEquals(resultEntities.get(2).get("Alt_Allele"), "A");
    assertEquals(resultEntities.get(2).get("Gene_Name"), "GEN2");
    assertEquals(resultEntities.get(2).get("Annotation"), "missense_variant");
    assertEquals(resultEntities.get(2).get("Putative_impact"), "MODERATE");
    assertEquals(resultEntities.get(2).get("Gene_ID"), "GEN2");
    assertEquals(resultEntities.get(2).get("Feature_type"), "transcript");
    assertEquals(resultEntities.get(2).get("Feature_ID"), "NM_123456.7");
    assertEquals(resultEntities.get(2).get("Transcript_biotype"), "Coding");
    assertEquals(resultEntities.get(2).get("Rank_total"), "4/4");
    assertEquals(resultEntities.get(2).get("HGVS_c"), "c.1234C>T");
    assertEquals(resultEntities.get(2).get("HGVS_p"), "p.Thr123Met");
    assertEquals(resultEntities.get(2).get("cDNA_position"), "1234/5678");
    assertEquals(resultEntities.get(2).get("CDS_position"), "2345/6789");
    assertEquals(resultEntities.get(2).get("Protein_position"), "111/222");
    assertEquals(resultEntities.get(2).get("Distance_to_feature"), "");
    assertEquals(resultEntities.get(2).get("Errors"), "");
    assertEquals(resultEntities.get(2).get("VARIANT").toString(), variant2.toString());
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) VcfRepository(org.molgenis.data.vcf.VcfRepository) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

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