Search in sources :

Example 1 with GridComponentColumn

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;
}
Also used : GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn)

Example 2 with GridComponentColumn

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"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) 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) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 3 with GridComponentColumn

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);
}
Also used : Locale(java.util.Locale) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) FieldType(com.qcadoo.model.api.types.FieldType) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 4 with GridComponentColumn

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 5 with GridComponentColumn

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 Test (org.junit.Test)5 Entity (com.qcadoo.model.api.Entity)4 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)4 JSONObject (org.json.JSONObject)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 EnumType (com.qcadoo.model.internal.types.EnumType)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)2 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)2 ComponentState (com.qcadoo.view.api.ComponentState)2 GridComponent (com.qcadoo.view.api.components.GridComponent)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2