use of com.qcadoo.view.internal.components.grid.GridComponentColumn in project qcadoo by qcadoo.
the class GridComponentFilterSQLUtils method getFieldNameByColumnName.
public static String getFieldNameByColumnName(final Map<String, GridComponentColumn> columns, final String columnName) {
GridComponentColumn column = columns.get(columnName);
if (column == null) {
return null;
}
final String expression = column.getExpression();
if (StringUtils.isNotBlank(expression)) {
return getFieldNameFromExpression(expression);
} else if (column.getFields().size() == 1) {
return column.getFields().get(0).getName();
}
return null;
}
use of com.qcadoo.view.internal.components.grid.GridComponentColumn in project qcadoo by qcadoo.
the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.
@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
// given
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setDataDefinition(dataDefinition);
GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
columnModel.setWidth(100);
pattern.addColumn("disabledPlugin", columnModel);
pattern.initialize();
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof GridComponent);
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
@SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
assertEquals(2, patternColumns.size());
assertEquals(2, stateColumns.size());
assertTrue(patternColumns.keySet().contains("name"));
assertNotNull(patternColumns.get("name"));
assertTrue(patternColumns.keySet().contains("invisible"));
assertNotNull(patternColumns.get("invisible"));
assertTrue(stateColumns.keySet().contains("name"));
assertNotNull(stateColumns.get("name"));
assertTrue(stateColumns.keySet().contains("invisible"));
assertNotNull(stateColumns.get("invisible"));
}
use of com.qcadoo.view.internal.components.grid.GridComponentColumn in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldGetValueUsingExpression.
@Test
public void shouldGetValueUsingExpression() throws Exception {
// given
FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
given(productDataDefinition.getField("name")).willReturn(nameFieldDefinition);
FieldType nameFieldType = mock(FieldType.class);
given(nameFieldDefinition.getType()).willReturn(nameFieldType);
given(nameFieldType.toString(anyString(), any(Locale.class))).willAnswer(invocation -> Objects.toString(invocation.getArguments()[0]));
GridComponentColumn column = new GridComponentColumn("name");
column.setExpression("#name + ' ' + #id");
Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John"));
// when
String value = column.getValue(entity, Locale.ENGLISH);
// then
assertEquals("John 13", value);
}
use of com.qcadoo.view.internal.components.grid.GridComponentColumn in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldGetValueUsingFields.
@Test
public void shouldGetValueUsingFields() throws Exception {
// given
FieldDefinition field1 = mock(FieldDefinition.class);
given(field1.getName()).willReturn("name");
given(field1.getValue("John", Locale.ENGLISH)).willReturn("Johny");
FieldDefinition field2 = mock(FieldDefinition.class);
given(field2.getName()).willReturn("lastname");
given(field2.getValue("Smith", Locale.ENGLISH)).willReturn("Smithy");
GridComponentColumn column = new GridComponentColumn("name");
column.addField(field1);
column.addField(field2);
Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John", "lastname", (Object) "Smith"));
// when
String value = column.getValue(entity, Locale.ENGLISH);
// then
assertEquals("Johny, Smithy", value);
}
use of com.qcadoo.view.internal.components.grid.GridComponentColumn in project qcadoo by qcadoo.
the class GridComponentStateTest method shouldGetValueUsingField.
@Test
public void shouldGetValueUsingField() throws Exception {
// given
FieldDefinition field = mock(FieldDefinition.class);
given(field.getName()).willReturn("name");
given(field.getValue("John", Locale.ENGLISH)).willReturn("Johny");
GridComponentColumn column = new GridComponentColumn("name");
column.addField(field);
Entity entity = new DefaultEntity(productDataDefinition, 13L, ImmutableMap.of("name", (Object) "John"));
// when
String value = column.getValue(entity, Locale.ENGLISH);
// then
assertEquals("Johny", value);
}
Aggregations