Search in sources :

Example 21 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class AwesomeDynamicListModelUtilsImpl method proxyBelongsToField.

private void proxyBelongsToField(final FieldDefinition fieldDefinition, final Entity entity) {
    Long belongsToEntityId = getBelongsToEntityId(entity.getField(fieldDefinition.getName()));
    if (belongsToEntityId == null) {
        return;
    }
    DataDefinition belongsToDataDefinition = ((BelongsToType) fieldDefinition.getType()).getDataDefinition();
    Entity belongsToEntity = new ProxyEntity(belongsToDataDefinition, belongsToEntityId);
    entity.setField(fieldDefinition.getName(), belongsToEntity);
}
Also used : Entity(com.qcadoo.model.api.Entity) ProxyEntity(com.qcadoo.model.internal.ProxyEntity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) ProxyEntity(com.qcadoo.model.internal.ProxyEntity) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 22 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class AwesomeDynamicListModelUtilsImplTest method init.

@Before
public final void init() {
    awesomeDynamicListModelUtils = new AwesomeDynamicListModelUtilsImpl();
    BelongsToType belongsToType = mock(BelongsToType.class);
    when(belongsToType.getDataDefinition()).thenReturn(belongsToDataDefinition);
    fieldDefinition = mock(FieldDefinition.class);
    when(fieldDefinition.getType()).thenReturn(belongsToType);
    when(fieldDefinition.getName()).thenReturn(BELONGS_TO_FIELD_NAME);
    @SuppressWarnings("unchecked") Entry<String, FieldDefinition> fieldEntry = mock(Entry.class);
    when(fieldEntry.getKey()).thenReturn(BELONGS_TO_FIELD_NAME);
    when(fieldEntry.getValue()).thenReturn(fieldDefinition);
    @SuppressWarnings("unchecked") Iterator<Entry<String, FieldDefinition>> iterator = mock(Iterator.class);
    when(iterator.hasNext()).thenReturn(true, false);
    when(iterator.next()).thenReturn(fieldEntry);
    @SuppressWarnings("unchecked") Set<Entry<String, FieldDefinition>> entrySet = mock(Set.class);
    when(entrySet.iterator()).thenReturn(iterator);
    when(entrySet.size()).thenReturn(1);
    @SuppressWarnings("unchecked") Map<String, FieldDefinition> fields = mock(Map.class);
    when(fields.entrySet()).thenReturn(entrySet);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    when(dataDefinition.getFields()).thenReturn(fields);
    entity = mock(Entity.class);
    when(entity.getDataDefinition()).thenReturn(dataDefinition);
    belongsToDataDefinition = mock(DataDefinition.class);
    when(belongsToDataDefinition.getName()).thenReturn("modelName");
    when(belongsToDataDefinition.getPluginIdentifier()).thenReturn("pluginIdentifier");
    when(belongsToType.getDataDefinition()).thenReturn(belongsToDataDefinition);
}
Also used : Entity(com.qcadoo.model.api.Entity) Entry(java.util.Map.Entry) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Before(org.junit.Before)

Example 23 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldHaveScopeFieldName.

@Test
public void shouldHaveScopeFieldName() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    given(belongsToFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(hasManyFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertEquals("joinName", options.getString("belongsToFieldName"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 24 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldReturnState.

@Test
public void shouldReturnState() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
    assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 25 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class InitializationTest method shouldGetDataDefinitionFromBelongsToTypeScopeFieldDefinition.

@Test
public void shouldGetDataDefinitionFromBelongsToTypeScopeFieldDefinition() throws Exception {
    // given
    BelongsToType fieldType = mock(BelongsToType.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(fieldType);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    DataDefinition belongsToDefinition = mock(DataDefinition.class);
    given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
    setField(parent, "dataDefinition", dataDefinition);
    setField(parent, "initialized", true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "field", parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
    Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

BelongsToType (com.qcadoo.model.api.types.BelongsToType)26 FieldDefinition (com.qcadoo.model.api.FieldDefinition)19 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)13 Entity (com.qcadoo.model.api.Entity)12 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)10 HasManyType (com.qcadoo.model.api.types.HasManyType)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)5 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)5 Before (org.junit.Before)4 EntityList (com.qcadoo.model.api.EntityList)2 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)2 FieldType (com.qcadoo.model.api.types.FieldType)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)2 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)2 Map (java.util.Map)2