Search in sources :

Example 76 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testGetXrefScript.

@Test
public void testGetXrefScript() throws ParseException {
    // xref entities
    EntityType entityTypeXref = entityTypeFactory.create("xrefEntity1");
    entityTypeXref.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeXref.addAttribute(attrMetaFactory.create().setName("field1"));
    Entity xref1a = new DynamicEntity(entityTypeXref);
    xref1a.set("id", 1);
    xref1a.set("field1", "Test");
    EntityType entityTypeXref2 = entityTypeFactory.create("xrefEntity2");
    entityTypeXref2.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeXref2.addAttribute(attrMetaFactory.create().setName("field2"));
    Entity xref2a = new DynamicEntity(entityTypeXref2);
    xref2a.set("id", 2);
    xref2a.set("field2", "Test");
    // source Entity
    EntityType entityTypeSource = entityTypeFactory.create("Source");
    entityTypeSource.addAttribute(attrMetaFactory.create().setName("id").setDataType(INT), ROLE_ID);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName("xref").setDataType(XREF));
    Entity source = new DynamicEntity(entityTypeSource);
    source.set("id", 1);
    source.set("xref", xref2a);
    Attribute targetAttribute = attrMetaFactory.create().setName("field1");
    targetAttribute.setDataType(XREF);
    targetAttribute.setRefEntity(entityTypeXref);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('xref').map({'1':'2', '2':'1'}).value();");
    when(entityManager.getReference(entityTypeXref, 1)).thenReturn(xref1a);
    Entity result = (Entity) algorithmService.apply(attributeMapping, source, entityTypeSource);
    assertEquals(result.get("field1"), xref2a.get("field2"));
}
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 77 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testApply.

@Test(dataProvider = "testApplyProvider")
public void testApply(AttributeType sourceAttributeType, Object sourceAttributeValue, String algorithm, AttributeType targetAttributeType, Object expected, String message) {
    String idAttrName = "id";
    EntityType entityType = entityTypeFactory.create("LL");
    entityType.addAttribute(attrMetaFactory.create().setName(idAttrName).setDataType(INT), ROLE_ID);
    entityType.addAttribute(attrMetaFactory.create().setName("source").setDataType(sourceAttributeType));
    Entity source = new DynamicEntity(entityType);
    source.set(idAttrName, 1);
    source.set("source", sourceAttributeValue);
    Attribute targetAttribute = attrMetaFactory.create().setName("target");
    targetAttribute.setDataType(targetAttributeType);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm(algorithm);
    Object result = algorithmService.apply(attributeMapping, source, entityType);
    assertEquals(result, expected, message);
}
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) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 78 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testDotAnnotationWithXref.

@Test
public void testDotAnnotationWithXref() throws ParseException {
    EntityType referenceEntityType = entityTypeFactory.create("reference");
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("label"));
    Entity referenceEntity = new DynamicEntity(referenceEntityType);
    referenceEntity.set("id", "1");
    referenceEntity.set("label", "label 1");
    EntityType sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("source_xref").setDataType(XREF));
    Entity sourceEntity = new DynamicEntity(sourceEntityType);
    sourceEntity.set("id", "1");
    sourceEntity.set("source_xref", referenceEntity);
    Attribute targetAttribute = attrMetaFactory.create().setName("target_label");
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('source_xref.label').value()");
    Object result = algorithmService.apply(attributeMapping, sourceEntity, sourceEntityType);
    assertEquals(result, "label 1");
}
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 79 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testApplyMrefNillable.

@Test
public void testApplyMrefNillable() throws ParseException {
    String refEntityName = "refEntity";
    String refEntityIdAttrName = "id";
    String refEntityLabelAttrName = "label";
    String sourceEntityName = "source";
    String sourceEntityAttrName = "mref-source";
    String targetEntityAttrName = "mref-target";
    // ref entities
    EntityType refEntityType = entityTypeFactory.create(refEntityName);
    refEntityType.addAttribute(attrMetaFactory.create().setName(refEntityIdAttrName), ROLE_ID);
    refEntityType.addAttribute(attrMetaFactory.create().setName(refEntityLabelAttrName), ROLE_LABEL);
    // mapping
    Attribute targetAttribute = attrMetaFactory.create().setName(targetEntityAttrName);
    targetAttribute.setDataType(MREF).setNillable(true).setRefEntity(refEntityType);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('" + sourceEntityAttrName + "').value()");
    // source Entity
    EntityType entityTypeSource = entityTypeFactory.create(sourceEntityName);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName(refEntityIdAttrName).setDataType(INT).setAuto(true), ROLE_ID);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName(sourceEntityAttrName).setDataType(MREF).setNillable(true).setRefEntity(refEntityType));
    Entity source = new DynamicEntity(entityTypeSource);
    source.set(sourceEntityAttrName, emptyList());
    Object result = algorithmService.apply(attributeMapping, source, entityTypeSource);
    assertEquals(result, emptyList());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 80 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testApplyMref.

@Test
public void testApplyMref() throws ParseException {
    String refEntityName = "refEntity";
    String refEntityIdAttrName = "id";
    String refEntityLabelAttrName = "label";
    String refEntityId0 = "id0";
    String refEntityId1 = "id1";
    String sourceEntityName = "source";
    String sourceEntityAttrName = "mref-source";
    String targetEntityAttrName = "mref-target";
    // ref entities
    EntityType refEntityType = entityTypeFactory.create(refEntityName);
    refEntityType.addAttribute(attrMetaFactory.create().setName(refEntityIdAttrName), ROLE_ID);
    refEntityType.addAttribute(attrMetaFactory.create().setName(refEntityLabelAttrName).setDataType(STRING), ROLE_LABEL);
    Entity refEntity0 = new DynamicEntity(refEntityType);
    refEntity0.set(refEntityIdAttrName, refEntityId0);
    refEntity0.set(refEntityLabelAttrName, "label0");
    Entity refEntity1 = new DynamicEntity(refEntityType);
    refEntity1.set(refEntityIdAttrName, refEntityId1);
    refEntity1.set(refEntityLabelAttrName, "label1");
    // mapping
    Attribute targetAttribute = attrMetaFactory.create().setName(targetEntityAttrName);
    targetAttribute.setDataType(MREF).setNillable(false).setRefEntity(refEntityType);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("$('" + sourceEntityAttrName + "').value()");
    when(entityManager.getReference(refEntityType, refEntityId0)).thenReturn(refEntity0);
    when(entityManager.getReference(refEntityType, refEntityId1)).thenReturn(refEntity1);
    // source Entity
    EntityType entityTypeSource = entityTypeFactory.create(sourceEntityName);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName(refEntityIdAttrName).setDataType(INT).setAuto(true), ROLE_ID);
    entityTypeSource.addAttribute(attrMetaFactory.create().setName(sourceEntityAttrName).setDataType(MREF).setNillable(false).setRefEntity(refEntityType));
    Entity source = new DynamicEntity(entityTypeSource);
    source.set(sourceEntityAttrName, Arrays.asList(refEntity0, refEntity1));
    Object result = algorithmService.apply(attributeMapping, source, entityTypeSource);
    assertEquals(result, Arrays.asList(refEntity0, refEntity1));
}
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) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16