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