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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations