Search in sources :

Example 1 with InternalViewDefinitionState

use of com.qcadoo.view.internal.api.InternalViewDefinitionState in project qcadoo by qcadoo.

the class AwesomeDynamicListState method setFieldValue.

@SuppressWarnings("unchecked")
@Override
public void setFieldValue(final Object value) {
    requestRender();
    forms = new LinkedList<>();
    if (value instanceof List) {
        List<Entity> entities = (List<Entity>) value;
        for (Entity entity : entities) {
            InternalViewDefinitionState innerFormState = new ViewDefinitionStateImpl();
            FormComponentState formState = (FormComponentState) innerFormPattern.createComponentState(innerFormState);
            innerFormPattern.updateComponentStateListeners(innerFormState);
            try {
                formState.initialize(new JSONObject(), getLocale());
            } catch (JSONException e) {
                throw new IllegalStateException(e);
            }
            formState.setEntity(entity);
            forms.add(formState);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) JSONException(org.json.JSONException) List(java.util.List) LinkedList(java.util.LinkedList) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 2 with InternalViewDefinitionState

use of com.qcadoo.view.internal.api.InternalViewDefinitionState in project qcadoo by qcadoo.

the class AwesomeDynamicListState method initializeContent.

@Override
protected void initializeContent(final JSONObject json) throws JSONException {
    if (json.has(JSON_FORM_VALUES)) {
        forms = new LinkedList<>();
        JSONArray formValues = json.getJSONArray(JSON_FORM_VALUES);
        for (int i = 0; i < formValues.length(); i++) {
            JSONObject value = formValues.getJSONObject(i);
            String formName = value.getString("name");
            JSONObject formValue = value.getJSONObject("value");
            InternalViewDefinitionState innerFormState = new ViewDefinitionStateImpl();
            FormComponentState formState = (FormComponentState) innerFormPattern.createComponentState(innerFormState);
            formState.setName(formName);
            innerFormPattern.updateComponentStateListeners(innerFormState);
            formState.initialize(formValue, getLocale());
            forms.add(formState);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) JSONArray(org.json.JSONArray) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 3 with InternalViewDefinitionState

use of com.qcadoo.view.internal.api.InternalViewDefinitionState 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 4 with InternalViewDefinitionState

use of com.qcadoo.view.internal.api.InternalViewDefinitionState in project qcadoo by qcadoo.

the class CrudControllerTest method shouldPerformEvent.

@Test
public void shouldPerformEvent() throws Exception {
    // given
    InternalViewDefinitionState state = mock(InternalViewDefinitionState.class, Mockito.withSettings().extraInterfaces(InternalComponentState.class));
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ViewDefinitionService viewDefinitionService = mock(ViewDefinitionService.class);
    given(viewDefinitionService.get("testPlugin", "testView")).willReturn(viewDefinition);
    JSONObject jsonBody = new JSONObject();
    jsonBody.put("test", "testVal1");
    JSONObject jsonResult = new JSONObject();
    jsonResult.put("test", "testVal2");
    CrudService crud = new CrudServiceImpl();
    ReflectionTestUtils.setField(crud, "viewDefinitionService", viewDefinitionService);
    given(viewDefinition.performEvent(jsonBody, Locale.ENGLISH)).willReturn(state);
    given(((InternalComponentState) state).render()).willReturn(jsonResult);
    // when
    Object result = crud.invokeEventAndRenderView("testPlugin", "testView", jsonBody, Locale.ENGLISH);
    // then
    assertEquals(jsonResult, result);
}
Also used : CrudService(com.qcadoo.view.api.crud.CrudService) ViewDefinitionService(com.qcadoo.view.internal.api.ViewDefinitionService) JSONObject(org.json.JSONObject) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONObject(org.json.JSONObject) CrudServiceImpl(com.qcadoo.view.internal.crud.CrudServiceImpl) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 5 with InternalViewDefinitionState

use of com.qcadoo.view.internal.api.InternalViewDefinitionState in project qcadoo by qcadoo.

the class ViewDefinitionStateTest method shouldReturnStateByFunctionalPath.

@Test
public void shouldReturnStateByFunctionalPath() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
    ContainerState state = mock(ContainerState.class);
    viewDefinitionState.registerComponent("reference", state);
    // when
    ComponentState actualState = viewDefinitionState.getComponentByReference("reference");
    // then
    assertEquals(state, actualState);
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Aggregations

InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)9 Test (org.junit.Test)7 ComponentState (com.qcadoo.view.api.ComponentState)6 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)6 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 FieldDefinition (com.qcadoo.model.api.FieldDefinition)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 ComponentOption (com.qcadoo.view.internal.ComponentOption)3 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)3 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)3 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)3 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)3 Map (java.util.Map)3 JSONObject (org.json.JSONObject)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 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)2