Search in sources :

Example 1 with EntityWithComputedAttributes

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

the class EntityHydrationTest method setUpBeforeMethod.

@BeforeMethod
public void setUpBeforeMethod() {
    // mock entity manager
    EntityManager entityManager = when(mock(EntityManager.class).create(entityType, EntityManager.CreationMode.NO_POPULATE)).thenReturn(new EntityWithComputedAttributes(new DynamicEntity(entityType))).getMock();
    when(entityManager.getReference(entityTypeArgumentCaptor.capture(), eq("0"))).thenReturn(refEntities.get(0));
    when(entityManager.getReferences(entityTypeArgumentCaptor.capture(), eq(newArrayList("0")))).thenReturn(refEntities);
    entityHydration = new EntityHydration(entityManager);
}
Also used : EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with EntityWithComputedAttributes

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

the class EntityManagerImpl method create.

private Entity create(EntityType entityType, Fetch fetch, CreationMode creationMode) {
    Entity entity = new DynamicEntity(entityType);
    if (fetch != null) {
        // create partial entity that loads attribute values not contained in the fetch on demand.
        entity = new PartialEntity(entity, fetch, this);
    }
    if (entityType.hasAttributeWithExpression()) {
        // create entity that computed values based on expressions defined in meta data
        entity = new EntityWithComputedAttributes(entity);
    }
    if (creationMode == POPULATE) {
        entityPopulator.populate(entity);
    }
    EntityFactory<? extends Entity, ?> entityFactory = entityFactoryRegistry.getEntityFactory(entityType);
    if (entityFactory != null) {
        // create static entity (e.g. Tag, Language, Package) that wraps the constructed dynamic or partial entity.
        return entityFactory.create(entity);
    }
    return entity;
}
Also used : PartialEntity(org.molgenis.data.support.PartialEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) PartialEntity(org.molgenis.data.support.PartialEntity) EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 3 with EntityWithComputedAttributes

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

the class EntityTestHarness method createEntity.

public Entity createEntity(EntityType entityType, int id, Entity refEntity) {
    Entity entity = new DynamicEntity(entityType);
    entity.set(ATTR_ID, "" + id);
    entity.set(ATTR_STRING, "string1");
    entity.set(ATTR_BOOL, id % 2 == 0);
    entity.set(ATTR_CATEGORICAL, refEntity);
    entity.set(ATTR_CATEGORICAL_MREF, refEntity == null ? emptyList() : singletonList(refEntity));
    entity.set(ATTR_DATE, date);
    entity.set(ATTR_DATETIME, dateTime);
    entity.set(ATTR_EMAIL, "this.is@mail.address");
    entity.set(ATTR_DECIMAL, id + 0.123);
    entity.set(ATTR_HTML, id % 2 == 1 ? "<html>where is my head and where is my body</html>" : null);
    entity.set(ATTR_HYPERLINK, "http://www.molgenis.org");
    entity.set(ATTR_LONG, id * 1000000L);
    entity.set(ATTR_INT, 10 + id);
    entity.set(ATTR_SCRIPT, "/bin/blaat/script.sh");
    entity.set(ATTR_XREF, refEntity);
    entity.set(ATTR_MREF, refEntity == null ? emptyList() : singletonList(refEntity));
    entity.set(ATTR_COMPOUND_CHILD_INT, 10 + id);
    entity.set(ATTR_ENUM, id % 2 == 0 ? "option1" : "option2");
    return new EntityWithComputedAttributes(entity);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 4 with EntityWithComputedAttributes

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

the class MetaDataServiceIT method testUpdateEntityType.

@WithMockUser(username = USERNAME)
@Test
public void testUpdateEntityType() {
    EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID);
    updatedEntityType.getAttribute(ATTR_STRING).setDataType(ENUM).setEnumOptions(asList("string0", "string1"));
    updatedEntityType.getAttribute(ATTR_BOOL).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_CATEGORICAL).setDataType(LONG).setRefEntity(null);
    updatedEntityType.getAttribute(ATTR_CATEGORICAL_MREF).setDataType(MREF);
    updatedEntityType.getAttribute(ATTR_DATE).setDataType(DATE_TIME);
    updatedEntityType.getAttribute(ATTR_DATETIME).setDataType(DATE);
    updatedEntityType.getAttribute(ATTR_EMAIL).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_DECIMAL).setDataType(INT);
    updatedEntityType.getAttribute(ATTR_HTML).setDataType(TEXT);
    updatedEntityType.getAttribute(ATTR_HYPERLINK).setDataType(STRING);
    updatedEntityType.getAttribute(ATTR_LONG).setDataType(DECIMAL);
    updatedEntityType.getAttribute(ATTR_INT).setDataType(LONG);
    updatedEntityType.getAttribute(ATTR_SCRIPT).setDataType(TEXT);
    updatedEntityType.getAttribute(ATTR_XREF).setDataType(CATEGORICAL);
    updatedEntityType.getAttribute(ATTR_MREF).setDataType(CATEGORICAL_MREF);
    updatedEntityType.getAttribute(ATTR_ENUM).setDataType(STRING).setEnumOptions(emptyList());
    metaDataService.updateEntityType(updatedEntityType);
    Entity expectedEntity = new DynamicEntity(updatedEntityType);
    expectedEntity.set(ATTR_ID, "0");
    expectedEntity.set(ATTR_STRING, "string1");
    expectedEntity.set(ATTR_BOOL, "true");
    expectedEntity.set(ATTR_CATEGORICAL, 0L);
    expectedEntity.set(ATTR_CATEGORICAL_MREF, singletonList(refEntities.get(0)));
    expectedEntity.set(ATTR_DATE, LocalDate.parse("2012-12-21").atStartOfDay(systemDefault()).toInstant());
    expectedEntity.set(ATTR_DATETIME, MolgenisDateFormat.parseLocalDate("1985-08-12T06:12:13Z"));
    expectedEntity.set(ATTR_EMAIL, "this.is@mail.address");
    // before update: 0.123
    expectedEntity.set(ATTR_DECIMAL, 0);
    expectedEntity.set(ATTR_HTML, null);
    expectedEntity.set(ATTR_HYPERLINK, "http://www.molgenis.org");
    expectedEntity.set(ATTR_LONG, 0.0);
    expectedEntity.set(ATTR_INT, 10L);
    expectedEntity.set(ATTR_SCRIPT, "/bin/blaat/script.sh");
    expectedEntity.set(ATTR_XREF, refEntities.get(0));
    expectedEntity.set(ATTR_MREF, singletonList(refEntities.get(0)));
    expectedEntity.set(ATTR_COMPOUND_CHILD_INT, 10);
    expectedEntity.set(ATTR_ENUM, "option1");
    expectedEntity = new EntityWithComputedAttributes(expectedEntity);
    assertTrue(EntityUtils.equals(dataService.findOneById(ENTITY_TYPE_ID, "0"), expectedEntity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 5 with EntityWithComputedAttributes

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

the class L2CacheTest method beforeClass.

@BeforeClass
public void beforeClass() {
    EntityType refEntityType = entityTestHarness.createDynamicRefEntityType();
    emd = entityTestHarness.createDynamicTestEntityType(refEntityType);
    List<Entity> refEntities = entityTestHarness.createTestRefEntities(refEntityType, 2);
    testEntities = entityTestHarness.createTestEntities(emd, 4, refEntities).collect(toList());
    when(entityManager.create(emd, NO_POPULATE)).thenAnswer(invocation -> new EntityWithComputedAttributes(new DynamicEntity(emd)));
    when(entityManager.getReference(any(EntityType.class), eq("0"))).thenReturn(refEntities.get(0));
    when(entityManager.getReference(any(EntityType.class), eq("1"))).thenReturn(refEntities.get(1));
    when(entityManager.getReferences(any(EntityType.class), eq(newArrayList("0")))).thenReturn(newArrayList(refEntities.get(0)));
    when(entityManager.getReferences(any(EntityType.class), eq(newArrayList("1")))).thenReturn(newArrayList(refEntities.get(1)));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) EntityWithComputedAttributes(org.molgenis.data.support.EntityWithComputedAttributes) DynamicEntity(org.molgenis.data.support.DynamicEntity) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)5 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)5 EntityType (org.molgenis.data.meta.model.EntityType)2 Entity (org.molgenis.data.Entity)1 PartialEntity (org.molgenis.data.support.PartialEntity)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1