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