Search in sources :

Example 41 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class BaseDataObjectRenderer method render.

@Override
public String render(DataObject dataobject, long modelId, String langCode, RequestContext reqCtx) {
    String renderedEntity = null;
    List<TextAttributeCharReplaceInfo> conversions = null;
    try {
        conversions = this.convertSpecialCharacters(dataobject, langCode);
        String contentModel = this.getModelShape(modelId);
        Context velocityContext = new VelocityContext();
        DataObjectWrapper contentWrapper = (DataObjectWrapper) this.getEntityWrapper(dataobject);
        contentWrapper.setRenderingLang(langCode);
        contentWrapper.setReqCtx(reqCtx);
        velocityContext.put(this.getEntityWrapperContextName(), contentWrapper);
        I18nManagerWrapper i18nWrapper = new I18nManagerWrapper(langCode, this.getI18nManager());
        velocityContext.put("i18n", i18nWrapper);
        SystemInfoWrapper systemInfoWrapper = new SystemInfoWrapper(reqCtx);
        velocityContext.put("info", systemInfoWrapper);
        StringWriter stringWriter = new StringWriter();
        boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", contentModel);
        if (!isEvaluated) {
            throw new ApsSystemException("Error rendering DataObject");
        }
        stringWriter.flush();
        renderedEntity = stringWriter.toString();
    } catch (Throwable t) {
        _logger.error("Error rendering dataobject", t);
        renderedEntity = "";
    } finally {
        if (null != conversions) {
            this.replaceSpecialCharacters(conversions);
        }
    }
    return renderedEntity;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) RequestContext(com.agiletec.aps.system.RequestContext) Context(org.apache.velocity.context.Context) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) TextAttributeCharReplaceInfo(com.agiletec.aps.system.common.renderer.TextAttributeCharReplaceInfo) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) I18nManagerWrapper(com.agiletec.aps.system.services.i18n.I18nManagerWrapper)

Example 42 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestDataObjectListHelper method testGetContents_1.

public void testGetContents_1() throws Throwable {
    String pageCode = "pagina_1";
    int frame = 1;
    try {
        this.setUserOnSession("guest");
        RequestContext reqCtx = this.valueRequestContext(pageCode, frame);
        MockDataObjectListTagBean bean = new MockDataObjectListTagBean();
        bean.setContentType("EVN");
        EntitySearchFilter filter = new EntitySearchFilter("DataInizio", true);
        filter.setOrder(EntitySearchFilter.DESC_ORDER);
        bean.addFilter(filter);
        List<String> contents = this._helper.getContentsId(bean, reqCtx);
        String[] expected = { "EVN194", "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191" };
        assertEquals(expected.length, contents.size());
        for (int i = 0; i < expected.length; i++) {
            assertEquals(expected[i], contents.get(i));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        this.setPageWidgets(pageCode, frame, null);
    }
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 43 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestDataObjectListHelper method testGetFilters_OneDefinition.

public void testGetFilters_OneDefinition() {
    RequestContext reqCtx = this.getRequestContext();
    String contentType = "ART";
    String showletParam = "(key=Titolo;attributeFilter=TRUE;start=START;end=END;like=FALSE;order=ASC)";
    EntitySearchFilter[] filters = this._helper.getFilters(contentType, showletParam, reqCtx);
    assertNotNull(filters);
    assertEquals(1, filters.length);
    EntitySearchFilter entitySearchFilter = filters[0];
    assertNotNull(entitySearchFilter);
    assertEquals("Titolo", entitySearchFilter.getKey());
    assertEquals("START", entitySearchFilter.getStart());
    assertEquals("END", entitySearchFilter.getEnd());
    assertEquals("ASC", entitySearchFilter.getOrder().toString());
    contentType = "ART";
    showletParam = "(key=Titolo;attributeFilter=TRUE;start=START;end=END;like=FALSE;order=DESC)";
    filters = this._helper.getFilters(contentType, showletParam, reqCtx);
    assertNotNull(filters);
    assertEquals(1, filters.length);
    entitySearchFilter = filters[0];
    assertNotNull(entitySearchFilter);
    assertEquals("Titolo", entitySearchFilter.getKey());
    assertEquals("START", entitySearchFilter.getStart());
    assertEquals("END", entitySearchFilter.getEnd());
    assertEquals("DESC", entitySearchFilter.getOrder().toString());
    contentType = "ART";
    showletParam = "(key=descr;value=VALUE;attributeFilter=FALSE;order=ASC)";
    filters = this._helper.getFilters(contentType, showletParam, reqCtx);
    assertNotNull(filters);
    assertEquals(1, filters.length);
    entitySearchFilter = filters[0];
    assertNotNull(entitySearchFilter);
    assertEquals("descr", entitySearchFilter.getKey());
    assertEquals(null, entitySearchFilter.getStart());
    assertEquals(null, entitySearchFilter.getEnd());
    assertEquals("ASC", entitySearchFilter.getOrder().toString());
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 44 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestDataObjectListHelper method valueRequestContext.

private RequestContext valueRequestContext(String pageCode, int frame) throws Throwable {
    RequestContext reqCtx = this.getRequestContext();
    try {
        Widget widgetToAdd = this.getShowletForTest("content_viewer_list", null);
        this.setPageWidgets(pageCode, frame, widgetToAdd);
        IPage page = this._pageManager.getOnlinePage(pageCode);
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, page);
        Widget widget = page.getWidgets()[frame];
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME, new Integer(frame));
    } catch (Throwable t) {
        this.setPageWidgets(pageCode, frame, null);
        throw t;
    }
    return reqCtx;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) RequestContext(com.agiletec.aps.system.RequestContext)

Example 45 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestDataObjectListHelper method testGetFilters_TwoDefinition.

public void testGetFilters_TwoDefinition() {
    RequestContext reqCtx = this.getRequestContext();
    String contentType = "ART";
    String showletParam = "(key=Titolo;attributeFilter=TRUE;start=START;end=END;like=FALSE;order=ASC)+(key=descr;value=VALUE;attributeFilter=FALSE;order=ASC)";
    EntitySearchFilter[] filters = this._helper.getFilters(contentType, showletParam, reqCtx);
    assertNotNull(filters);
    assertEquals(2, filters.length);
    EntitySearchFilter entitySearchFilter = filters[0];
    assertNotNull(entitySearchFilter);
    assertEquals("Titolo", entitySearchFilter.getKey());
    assertEquals("START", entitySearchFilter.getStart());
    assertEquals("END", entitySearchFilter.getEnd());
    assertEquals("ASC", entitySearchFilter.getOrder().toString());
    assertEquals(null, entitySearchFilter.getValue());
    assertTrue(entitySearchFilter.isAttributeFilter());
    entitySearchFilter = filters[1];
    assertNotNull(entitySearchFilter);
    assertEquals("descr", entitySearchFilter.getKey());
    assertEquals(null, entitySearchFilter.getStart());
    assertEquals(null, entitySearchFilter.getEnd());
    assertEquals("ASC", entitySearchFilter.getOrder().toString());
    assertFalse(entitySearchFilter.isAttributeFilter());
    Object obj = entitySearchFilter.getValue();
    assertNotNull(obj);
    assertEquals(String.class, obj.getClass());
    assertEquals("VALUE", (String) obj);
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)89 ServletRequest (javax.servlet.ServletRequest)25 JspException (javax.servlet.jsp.JspException)22 IPage (com.agiletec.aps.system.services.page.IPage)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)12 Lang (com.agiletec.aps.system.services.lang.Lang)10 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Widget (com.agiletec.aps.system.services.page.Widget)5 NavigatorTarget (com.agiletec.aps.system.services.page.widget.NavigatorTarget)5 IURLManager (com.agiletec.aps.system.services.url.IURLManager)5 ContentRenderizationInfo (com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo)5 DataObjectRenderizationInfo (org.entando.entando.aps.system.services.dataobjectdispenser.DataObjectRenderizationInfo)5 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ControllerManager (com.agiletec.aps.system.services.controller.ControllerManager)3 HeadInfoContainer (com.agiletec.aps.tags.util.HeadInfoContainer)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 IContentListWidgetHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper)3 IContentViewerHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper)3