Search in sources :

Example 46 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class TechnologyOperationComponentHooks method setParentIfRootNodeAlreadyExists.

private void setParentIfRootNodeAlreadyExists(final Entity technologyOperationComponent) {
    Entity technology = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    EntityTree tree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    if (Objects.isNull(tree) || tree.isEmpty()) {
        return;
    }
    EntityTreeNode rootNode = tree.getRoot();
    if (Objects.isNull(rootNode) || Objects.nonNull(technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.PARENT))) {
        return;
    }
    technologyOperationComponent.setField(TechnologyOperationComponentFields.PARENT, rootNode);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityTree(com.qcadoo.model.api.EntityTree)

Example 47 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DataAccessServiceGetTest method shouldGetTreeField.

@Test
public void shouldGetTreeField() throws Exception {
    // given
    SampleParentDatabaseObject parentDatabaseObject = new SampleParentDatabaseObject();
    parentDatabaseObject.setId(1L);
    parentDatabaseObject.setName("Mr T");
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(parentDatabaseObject);
    // when
    Entity entity = parentDataDefinition.get(1L);
    // then
    assertEquals(1L, entity.getId().longValue());
    assertEquals("Mr T", entity.getField("name"));
    assertThat(entity.getField("tree"), CoreMatchers.instanceOf(EntityTreeImpl.class));
    EntityTree tree = entity.getTreeField("tree");
    assertEquals(1L, getField(tree, "belongsToId"));
    assertEquals("owner", ((FieldDefinition) getField(tree, "joinFieldDefinition")).getName());
    assertEquals("tree.entity", ((DataDefinition) getField(tree, "dataDefinition")).getName());
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 48 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DataAccessServiceSaveTest method shouldNotSaveEntityTreeField.

@Test
public void shouldNotSaveEntityTreeField() throws Exception {
    // given
    EntityTree tree = new EntityTreeImpl(dataDefinition, "", 1L);
    Entity parent = new DefaultEntity(parentDataDefinition, 1L);
    parent.setField("tree", tree);
    SampleParentDatabaseObject existingParent = new SampleParentDatabaseObject(1L);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(existingParent);
    given(session.load(any(Class.class), Matchers.eq(1L))).willReturn(existingParent);
    given(criteria.uniqueResult()).willReturn(1L);
    // when
    Entity entity = parentDataDefinition.save(parent);
    // then
    assertTrue(entity.isValid());
    assertEquals(tree, entity.getField("tree"));
    verify(session, times(1)).save(Mockito.any());
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 49 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DetachedEntityTreeImplTest method shouldBuildTree.

@Test
public final void shouldBuildTree() throws Exception {
    // given
    Entity entity1 = mock(Entity.class);
    Entity entity2 = mock(Entity.class);
    Entity entity3 = mock(Entity.class);
    when(entity1.getId()).thenReturn(1L);
    when(entity2.getId()).thenReturn(2L);
    when(entity3.getId()).thenReturn(3L);
    when(entity1.getField("parent")).thenReturn(null);
    when(entity2.getField("parent")).thenReturn(1L);
    when(entity3.getField("parent")).thenReturn(2L);
    when(entity1.getBelongsToField("parent")).thenReturn(null);
    when(entity2.getBelongsToField("parent")).thenReturn(entity1);
    when(entity3.getBelongsToField("parent")).thenReturn(entity2);
    // when
    EntityTree tree = new DetachedEntityTreeImpl(Lists.newArrayList(entity1, entity2, entity3));
    // then
    Assert.assertEquals(3, tree.size());
    Assert.assertEquals(entity1.getId(), tree.getRoot().getId());
    Assert.assertEquals(entity2.getId(), tree.getRoot().getChildren().get(0).getId());
    Assert.assertEquals(entity3.getId(), tree.getRoot().getChildren().get(0).getChildren().get(0).getId());
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Example 50 with EntityTree

use of com.qcadoo.model.api.EntityTree in project qcadoo by qcadoo.

the class DetachedEntityTreeImplTest method shouldConvertToString.

@Test
public final void shouldConvertToString() throws Exception {
    // given
    Entity entity1 = mock(Entity.class);
    Entity entity2 = mock(Entity.class);
    Entity entity3 = mock(Entity.class);
    when(entity1.getId()).thenReturn(1L);
    when(entity2.getId()).thenReturn(2L);
    when(entity3.getId()).thenReturn(3L);
    when(entity1.getField("parent")).thenReturn(null);
    when(entity2.getField("parent")).thenReturn(1L);
    when(entity3.getField("parent")).thenReturn(2L);
    when(entity1.getBelongsToField("parent")).thenReturn(null);
    when(entity2.getBelongsToField("parent")).thenReturn(entity1);
    when(entity3.getBelongsToField("parent")).thenReturn(entity2);
    EntityTree tree = new DetachedEntityTreeImpl(Lists.newArrayList(entity1, entity2, entity3));
    // when
    String stringTree = tree.toString();
    // then
    Assert.assertEquals("EntityTree[DETACHED!][size=3]", stringTree);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTree(com.qcadoo.model.api.EntityTree) Test(org.junit.Test)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2