Search in sources :

Example 11 with GuiFragment

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

the class TestWidgetTypeAction method testAddNewWidgetType.

// TODO ADD MORE TESTS for add new widget
public void testAddNewWidgetType() throws Throwable {
    String widgetTypeCode = "randomWidgetCode_4";
    List<String> fragmantCodes = null;
    try {
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        assertNull(this._guiFragmentManager.getGuiFragment(widgetTypeCode));
        String result = this.executeAddWidgetType("admin", widgetTypeCode, "**GUI**");
        assertEquals(Action.SUCCESS, result);
        WidgetType addedType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
        assertNotNull(addedType);
        FieldSearchFilter filterByType = new FieldSearchFilter("widgettypecode", widgetTypeCode, false);
        FieldSearchFilter[] filters = { filterByType };
        fragmantCodes = this._guiFragmentManager.searchGuiFragments(filters);
        assertNotNull(fragmantCodes);
        assertEquals(1, fragmantCodes.size());
        assertEquals(widgetTypeCode, fragmantCodes.get(0));
        GuiFragment guiFragment = this._guiFragmentManager.getGuiFragment(fragmantCodes.get(0));
        assertNotNull(guiFragment);
        assertEquals(widgetTypeCode, guiFragment.getWidgetTypeCode());
        assertEquals("**GUI**", guiFragment.getGui());
        assertFalse(guiFragment.isLocked());
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != fragmantCodes) {
            for (int i = 0; i < fragmantCodes.size(); i++) {
                String code = fragmantCodes.get(i);
                this._guiFragmentManager.deleteGuiFragment(code);
            }
        }
        this._widgetTypeManager.deleteWidgetType(widgetTypeCode);
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 12 with GuiFragment

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

the class TestGuiFragmentAction method createMockFragment.

protected GuiFragment createMockFragment(String code, String gui, String widgetTypeCode) {
    GuiFragment mFragment = new GuiFragment();
    mFragment.setCode(code);
    mFragment.setGui(gui);
    mFragment.setWidgetTypeCode(widgetTypeCode);
    return mFragment;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment)

Example 13 with GuiFragment

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

the class GuiFragmentValidatorTest method validateExistingFragment.

@Test
public void validateExistingFragment() throws Exception {
    GuiFragment existing = new GuiFragment();
    existing.setCode("existing");
    when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
    GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "<h1>code</h1>");
    MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
    validator.validate(request, bindingResult);
    Assert.assertTrue(bindingResult.hasErrors());
    Assert.assertEquals(1, 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)

Example 14 with GuiFragment

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

the class ApiGuiFragmentInterface method getGuiFragment.

public JAXBGuiFragment getGuiFragment(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    JAXBGuiFragment jaxbGuiFragment = null;
    try {
        GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
        if (null == guiFragment) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with id '" + code + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbGuiFragment = new JAXBGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating jaxb object of fragment - code '{}'", code, t);
        throw t;
    }
    return jaxbGuiFragment;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 15 with GuiFragment

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

the class ApiGuiFragmentInterface method addGuiFragment.

public void addGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
    try {
        if (null != this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + jaxbGuiFragment.getCode() + " already exists", Response.Status.CONFLICT);
        }
        GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
        if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().addGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error adding new fragment", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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