Search in sources :

Example 1 with ViewDefinitionImpl

use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.

the class ViewDefinitionParserImpl method parseViewDefinition.

private InternalViewDefinition parseViewDefinition(final Node viewNode, final String pluginIdentifier) throws ViewDefinitionParserNodeException {
    currentIndexOrder = 1;
    String name = getStringAttribute(viewNode, "name");
    Preconditions.checkState(name != null && !"".equals(name.trim()), "Name attribute cannot be empty");
    LOG.info("Reading view " + name + " for plugin " + pluginIdentifier);
    boolean menuAccessible = getBooleanAttribute(viewNode, "menuAccessible", false);
    String windowWidthStr = getStringAttribute(viewNode, "windowWidth");
    String windowHeightStr = getStringAttribute(viewNode, "windowHeight");
    Integer windowWidth = null;
    Integer windowHeight = null;
    if (windowWidthStr != null) {
        windowWidth = Integer.parseInt(windowWidthStr);
    }
    if (windowHeightStr != null) {
        windowHeight = Integer.parseInt(windowHeightStr);
    }
    SecurityRole role = getAuthorizationRole(viewNode);
    DataDefinition dataDefinition = getDataDefinition(viewNode, pluginIdentifier);
    ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(name, pluginIdentifier, role, dataDefinition, menuAccessible, translationService);
    viewDefinition.setWindowDimmension(windowWidth, windowHeight);
    ComponentPattern root = null;
    NodeList childNodes = viewNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (Node.ELEMENT_NODE != child.getNodeType()) {
            continue;
        }
        if ("component".equals(child.getNodeName())) {
            root = parseComponent(child, viewDefinition, null, pluginIdentifier);
        } else if ("hooks".equals(child.getNodeName())) {
            parseViewHooks(child, viewDefinition);
        } else {
            throw new ViewDefinitionParserNodeException(child, "Unknown node: " + child.getNodeName());
        }
    }
    viewDefinition.addComponentPattern(root);
    viewDefinition.initialize();
    viewDefinition.registerViews(viewDefinitionService);
    return viewDefinition;
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 2 with ViewDefinitionImpl

use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnPattern.

@Test
public void shouldReturnPattern() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern = Mockito.mock(ComponentPattern.class);
    viewDefinition.registerComponent("reference", "path", pattern);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("reference");
    // then
    Assert.assertEquals(pattern, actualPattern);
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 3 with ViewDefinitionImpl

use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldThrowCyclicDependencyOnInitialize.

@Test(expected = IllegalStateException.class)
public void shouldThrowCyclicDependencyOnInitialize() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("test1");
    given(pattern1.initialize()).willReturn(false, false, false);
    ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("test2");
    given(pattern2.initialize()).willReturn(false, false, false);
    ComponentPattern pattern3 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test3");
    given(pattern3.initialize()).willReturn(false, true);
    ComponentPattern pattern4 = Mockito.mock(ComponentPattern.class);
    given(pattern3.getName()).willReturn("test4");
    given(pattern3.initialize()).willReturn(true);
    viewDefinition.addComponentPattern(pattern1);
    viewDefinition.addComponentPattern(pattern2);
    viewDefinition.addComponentPattern(pattern3);
    viewDefinition.addComponentPattern(pattern4);
    // when
    viewDefinition.initialize();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 4 with ViewDefinitionImpl

use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldCallEvent.

@Test
public void shouldCallEvent() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    TestEvent event = mock(TestEvent.class);
    ComponentStateMock state = new ComponentStateMock(new JSONObject(of("asd", "123")));
    state.registerTestEvent("eventName", event);
    ComponentPatternMock pattern = new ComponentPatternMock(getComponentDefinition("componentName", viewDefinition), state);
    viewDefinition.addComponentPattern(pattern);
    JSONObject eventJson = new JSONObject();
    eventJson.put(InternalViewDefinition.JSON_EVENT_NAME, "eventName");
    eventJson.put(InternalViewDefinition.JSON_EVENT_COMPONENT, "componentName");
    eventJson.put(InternalViewDefinition.JSON_EVENT_ARGS, new JSONArray(newArrayList("arg1", "arg2")));
    JSONObject contentJson = new JSONObject();
    contentJson.put("asd", "qwe");
    JSONObject componentJson = new JSONObject();
    componentJson.put(AbstractComponentState.JSON_CONTENT, contentJson);
    JSONObject json = new JSONObject();
    json.put(InternalViewDefinition.JSON_EVENT, eventJson);
    json.put(InternalViewDefinition.JSON_COMPONENTS, new JSONObject(of("componentName", componentJson)));
    // when
    JSONObject result = ((InternalComponentState) viewDefinition.performEvent(json, Locale.ENGLISH)).render();
    // then
    assertEquals(contentJson, state.getContent());
    verify(event).invoke(new String[] { "arg1", "arg2" });
    Assert.assertEquals("123", result.getJSONObject("components").getJSONObject("componentName").getJSONObject("content").get("asd"));
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) JSONObject(org.json.JSONObject) TestEvent(com.qcadoo.view.internal.states.ComponentStateMock.TestEvent) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONArray(org.json.JSONArray) ComponentPatternMock(com.qcadoo.view.internal.patterns.ComponentPatternMock) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentStateMock(com.qcadoo.view.internal.states.ComponentStateMock) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 5 with ViewDefinitionImpl

use of com.qcadoo.view.internal.internal.ViewDefinitionImpl in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnNullWhenPatternNotExists.

@Test
public void shouldReturnNullWhenPatternNotExists() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    // when
    ComponentPattern actualPattern = viewDefinition.getComponentByReference("xxx");
    // then
    assertNull(actualPattern);
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)11 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)11 Test (org.junit.Test)9 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)7 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)5 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 BelongsToType (com.qcadoo.model.api.types.BelongsToType)1 FieldType (com.qcadoo.model.api.types.FieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 SecurityRole (com.qcadoo.security.api.SecurityRole)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)1 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)1 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)1