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