Search in sources :

Example 36 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class TestApiWidgetTypeInterface method getJaxbWidgetType.

private JAXBWidgetType getJaxbWidgetType(WidgetType widgetType) throws Throwable {
    assertNotNull(widgetType);
    GuiFragment singleGuiFragment = null;
    List<GuiFragment> fragments = new ArrayList<>();
    if (!widgetType.isLogic()) {
        singleGuiFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetType.getCode());
    } else {
        List<String> fragmentCodes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetType.getCode());
        if (null != fragmentCodes) {
            for (int i = 0; i < fragmentCodes.size(); i++) {
                String fragmentCode = fragmentCodes.get(i);
                GuiFragment fragment = this._guiFragmentManager.getGuiFragment(fragmentCode);
                if (null != fragment) {
                    fragments.add(fragment);
                }
            }
        }
    }
    return new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ArrayList(java.util.ArrayList)

Example 37 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class TestApiWidgetTypeInterface method testInvokeUpdateJaxbNoLogicWidgetType.

private void testInvokeUpdateJaxbNoLogicWidgetType(String widgetTypeCode, ApsProperties titles, boolean removeParametersFromCall, String customSingleGui, boolean expectedSuccess) throws Throwable {
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToEdit = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    ApsProperties originalTitles = widgetType.getTitles();
    try {
        JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(widgetTypeToEdit);
        if (StringUtils.isNotBlank(customSingleGui)) {
            jaxbWidgetType.setGui(customSingleGui);
        }
        if (null != titles) {
            jaxbWidgetType.setTitles(titles);
        }
        if (removeParametersFromCall) {
            jaxbWidgetType.setTypeParameters(null);
        }
        this._apiWidgetTypeInterface.updateWidgetType(jaxbWidgetType);
        if (!expectedSuccess) {
            fail();
        }
        WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
        assertNotNull(extractedWidgetType);
        assertEquals(widgetType.getMainGroup(), extractedWidgetType.getMainGroup());
        assertEquals(titles, extractedWidgetType.getTitles());
        assertEquals(widgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
        assertEquals(widgetType.isLocked(), extractedWidgetType.isLocked());
        if (StringUtils.isNotBlank(customSingleGui) && null == previousFragment) {
            assertNotNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
        }
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null == previousFragment) {
            List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode);
            if (null != codes) {
                for (int i = 0; i < codes.size(); i++) {
                    String code = codes.get(i);
                    this._guiFragmentManager.deleteGuiFragment(code);
                }
            }
        } else if (null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
            this._guiFragmentManager.addGuiFragment(previousFragment);
        } else {
            this._guiFragmentManager.updateGuiFragment(previousFragment);
        }
        this._widgetTypeManager.updateWidgetType(widgetType.getCode(), originalTitles, widgetType.getConfig(), widgetType.getMainGroup(), widgetType.getConfigUi(), widgetType.getBundleId());
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 38 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class TestApiWidgetTypeInterface method testInvokeDeleteJaxbNoLogicWidgetType.

private void testInvokeDeleteJaxbNoLogicWidgetType(String widgetTypeCode, boolean expectedSuccess) throws Throwable {
    Properties properties = new Properties();
    properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
    properties.put("code", widgetTypeCode);
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToDelete = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    try {
        this._apiWidgetTypeInterface.deleteWidgetType(properties);
        if (!expectedSuccess) {
            fail();
        }
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        assertNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
    } catch (ApiException ae) {
        if (expectedSuccess) {
            throw ae;
        }
    } catch (Throwable t) {
        if (expectedSuccess) {
            throw t;
        }
    } finally {
        if (null != previousFragment && null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
            this._guiFragmentManager.addGuiFragment(previousFragment);
        }
        if (null == this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
            this._widgetTypeManager.addWidgetType(widgetTypeToDelete);
        }
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 39 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class GuiFragmentSettingsControllerIntegrationTest method testGetPluginsMapping.

@Test
public void testGetPluginsMapping() throws Exception {
    String code = "info";
    GuiFragment fragment = new GuiFragment();
    fragment.setCode(code);
    fragment.setDefaultGui("hello world");
    this.guiFragmentManager.addGuiFragment(fragment);
    try {
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = this.executeGet("/fragments/info/plugins", accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.size()", is(0)));
        ResultActions resultFragment = this.executeGet("/fragments/info", accessToken, status().isOk());
        resultFragment.andExpect(jsonPath("$.payload.code", is(code)));
        resultFragment.andExpect(jsonPath("$.payload.locked", is(false)));
    } finally {
        this.guiFragmentManager.deleteGuiFragment(code);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 40 with GuiFragment

use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.

the class GuiFragmentValidatorTest method validateExistingAndInvalidFragment.

@Test
public void validateExistingAndInvalidFragment() throws Exception {
    GuiFragment existing = new GuiFragment();
    existing.setCode("existing");
    when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
    GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "");
    MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
    validator.validate(request, bindingResult);
    Assert.assertTrue(bindingResult.hasErrors());
    Assert.assertEquals(2, bindingResult.getErrorCount());
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) GuiFragmentRequestBody(org.entando.entando.web.guifragment.model.GuiFragmentRequestBody) MapBindingResult(org.springframework.validation.MapBindingResult) Test(org.junit.Test)

Aggregations

GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)41 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)10 ArrayList (java.util.ArrayList)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)6 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)5 ApsProperties (com.agiletec.aps.util.ApsProperties)4 IGuiFragmentManager (org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager)4 List (java.util.List)3 Test (org.junit.Test)3 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)2 Template (freemarker.template.Template)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 ExecutorBeanContainer (org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)2 GuiFragmentUtilizer (org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer)2 GuiFragmentRequestBody (org.entando.entando.web.guifragment.model.GuiFragmentRequestBody)2 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)2 MapBindingResult (org.springframework.validation.MapBindingResult)2 RequestContext (com.agiletec.aps.system.RequestContext)1