Search in sources :

Example 91 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class EntityMappingRepositoryImpl method toEntityMappingEntity.

private Entity toEntityMappingEntity(EntityMapping entityMapping, List<Entity> attributeMappingEntities) {
    Entity entityMappingEntity = new DynamicEntity(entityMappingMetaData);
    entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, entityMapping.getIdentifier());
    entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, entityMapping.getName());
    entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, entityMapping.getTargetEntityType() != null ? entityMapping.getTargetEntityType().getId() : null);
    entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
    return entityMappingEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 92 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class MappingTargetRepositoryImpl method toMappingTargetEntity.

/**
 * Creates a new {@link DynamicEntity} for this MappingProject. Doesn't yet fill the {@link EntityMapping}s.
 */
private Entity toMappingTargetEntity(MappingTarget mappingTarget, List<Entity> entityMappingEntities) {
    Entity mappingTargetEntity = new DynamicEntity(mappingTargetMetaData);
    mappingTargetEntity.set(MappingProjectMetaData.IDENTIFIER, mappingTarget.getIdentifier());
    mappingTargetEntity.set(MappingTargetMetaData.TARGET, mappingTarget.getTarget().getId());
    mappingTargetEntity.set(MappingTargetMetaData.ENTITY_MAPPINGS, entityMappingEntities);
    return mappingTargetEntity;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 93 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleInXref_Entities.

@Test
public void generateOneQueryRuleInXref_Entities() {
    Entity ref0 = new DynamicEntity(refEntityType);
    ref0.set(idAttrName, "id0");
    Entity ref1 = new DynamicEntity(refEntityType);
    ref1.set(idAttrName, "id1");
    Entity ref2 = new DynamicEntity(refEntityType);
    ref2.set(idAttrName, "id2");
    Iterable<Object> values = Arrays.asList(ref0, ref1, ref2);
    Query<Entity> q = new QueryImpl<>().in(xrefAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(xrefAttrName, termsQuery(xrefAttrName + '.' + idAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { "id0", "id1", "id2" }), ScoreMode.Avg));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 94 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleInMref_Entities.

@Test
public void generateOneQueryRuleInMref_Entities() {
    Entity ref0 = new DynamicEntity(refEntityType);
    ref0.set(idAttrName, "id0");
    Entity ref1 = new DynamicEntity(refEntityType);
    ref1.set(idAttrName, "id1");
    Entity ref2 = new DynamicEntity(refEntityType);
    ref2.set(idAttrName, "id2");
    Iterable<Object> values = Arrays.asList(ref0, ref1, ref2);
    Query<Entity> q = new QueryImpl<>().in(mrefAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(mrefAttrName, termsQuery(mrefAttrName + '.' + idAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { "id0", "id1", "id2" }), ScoreMode.Avg));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 95 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class ExcelSheetWriterTest method write.

@Test
public void write() throws IOException {
    Entity entity1 = new DynamicEntity(mock(EntityType.class)) {

        @Override
        protected void validateValueType(String attrName, Object value) {
        // noop
        }
    };
    entity1.set("col1", "val1");
    entity1.set("col2", "val2");
    excelSheetWriter.add(entity1);
    Entity entity2 = new DynamicEntity(mock(EntityType.class)) {

        @Override
        protected void validateValueType(String attrName, Object value) {
        // noop
        }
    };
    entity2.set("col1", "val3");
    entity2.set("col2", "val4");
    excelSheetWriter.add(entity2);
    excelWriter.close();
}
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)

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