RequestContainer requestContainer = getRequestContainer();
SessionContainer session = requestContainer.getSessionContainer();
String parameterFieldName = (String)request.getAttribute("parameterFieldName");
logger.debug("parameterFieldName="+parameterFieldName);
// define the spago paginator and list object
PaginatorIFace paginator = new GenericPaginator();
ListIFace list = new GenericList();
// define variable for value column name
String valColName = "";
// recover lov object
IParameterDAO pardao = DAOFactory.getParameterDAO();
Parameter par = pardao.loadForExecutionByParameterIDandRoleName(parId, roleName);
ModalitiesValue modVal = par.getModalityValue();
// get the lov provider
String looProvider = modVal.getLovProvider();
// get from the request the type of lov
String typeLov = LovDetailFactory.getLovTypeCode(looProvider);
// get the user profile
IEngUserProfile profile = null;
SessionContainer permanentSession = session.getPermanentContainer();
profile = (IEngUserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
// HttpServletRequest httpReq = (HttpServletRequest)requestContainer.getInternalRequest();
// HttpSession httpSess = httpReq.getSession();
// profile = (IEngUserProfile)httpSess.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
// based on lov type fill the spago list / paginator object / valColName
SourceBean rowsSourceBean = null;
if(typeLov.equalsIgnoreCase("QUERY")) {
QueryDetail qd = QueryDetail.fromXML(looProvider);
// if (qd.requireProfileAttributes()) {
// String message = PortletUtilities.getMessage("scheduler.noProfileAttributesSupported", "component_scheduler_messages");
// response.setAttribute(SpagoBIConstants.MESSAGE_INFO, message);
// return list;
// }
valColName = qd.getValueColumnName();
//String pool = qd.getConnectionName();
String datasource = qd.getDataSource();
String statement = qd.getQueryDefinition();
// execute query
try {
statement = StringUtilities.substituteProfileAttributesInString(statement, profile);
//rowsSourceBean = (SourceBean) executeSelect(getRequestContainer(), getResponseContainer(), pool, statement);
rowsSourceBean = (SourceBean) executeSelect(getRequestContainer(), getResponseContainer(), datasource, statement);
} catch (Exception e) {
String stacktrace = e.toString();
response.setAttribute("stacktrace", stacktrace);
int startIndex = stacktrace.indexOf("java.sql.");
int endIndex = stacktrace.indexOf("\n\tat ", startIndex);
if (endIndex == -1) endIndex = stacktrace.indexOf(" at ", startIndex);
if (startIndex != -1 && endIndex != -1)
response.setAttribute("errorMessage", stacktrace.substring(startIndex, endIndex));
response.setAttribute("testExecuted", "false");
}
} else if(typeLov.equalsIgnoreCase("FIXED_LIST")) {
FixedListDetail fixlistDet = FixedListDetail.fromXML(looProvider);
// if (fixlistDet.requireProfileAttributes()) {
// String message = PortletUtilities.getMessage("scheduler.noProfileAttributesSupported", "component_scheduler_messages");
// response.setAttribute(SpagoBIConstants.MESSAGE_INFO, message);
// return list;
// }
valColName = fixlistDet.getValueColumnName();
try{
String result = fixlistDet.getLovResult(profile, null, null);
rowsSourceBean = SourceBean.fromXMLString(result);
if(!rowsSourceBean.getName().equalsIgnoreCase("ROWS")) {
throw new Exception("The fix list is empty");
} else if (rowsSourceBean.getAttributeAsList(DataRow.ROW_TAG).size()==0) {
throw new Exception("The fix list is empty");
}
} catch (Exception e) {
SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(),
"getList", "Error while converting fix lov into spago list", e);
String stacktrace = e.toString();
response.setAttribute("stacktrace", stacktrace);
response.setAttribute("errorMessage", "Error while executing fix list lov");
response.setAttribute("testExecuted", "false");
return list;
}
} else if(typeLov.equalsIgnoreCase("SCRIPT")) {
ScriptDetail scriptDetail = ScriptDetail.fromXML(looProvider);
// if (scriptDetail.requireProfileAttributes()) {
// String message = PortletUtilities.getMessage("scheduler.noProfileAttributesSupported", "component_scheduler_messages");
// response.setAttribute(SpagoBIConstants.MESSAGE_INFO, message);
// return list;
// }
valColName = scriptDetail.getValueColumnName();
try{
String result = scriptDetail.getLovResult(profile, null, null);
rowsSourceBean = SourceBean.fromXMLString(result);
} catch (Exception e) {
SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(),
"getList", "Error while executing the script lov", e);
String stacktrace = e.toString();
response.setAttribute("stacktrace", stacktrace);
response.setAttribute("errorMessage", "Error while executing script");
response.setAttribute("testExecuted", "false");
return list;
}
} else if(typeLov.equalsIgnoreCase("JAVA_CLASS")) {
JavaClassDetail javaClassDetail = JavaClassDetail.fromXML(looProvider);
// if (javaClassDetail.requireProfileAttributes()) {
// String message = PortletUtilities.getMessage("scheduler.noProfileAttributesSupported", "component_scheduler_messages");
// response.setAttribute(SpagoBIConstants.MESSAGE_INFO, message);
// return list;
// }
valColName = javaClassDetail.getValueColumnName();
try{
String javaClassName = javaClassDetail.getJavaClassName();
IJavaClassLov javaClassLov = (IJavaClassLov) Class.forName(javaClassName).newInstance();
String result = javaClassLov.getValues(profile);
rowsSourceBean = SourceBean.fromXMLString(result);
} catch (Exception e) {
SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(),
"getList", "Error while executing the java class lov", e);
String stacktrace = e.toString();
response.setAttribute("stacktrace", stacktrace);
response.setAttribute("errorMessage", "Error while executing java class");
response.setAttribute("testExecuted", "false");
return list;
}
}
// fill paginator
int count = 0;
if(rowsSourceBean != null) {
List rows = rowsSourceBean.getAttributeAsList(DataRow.ROW_TAG);
for (int i = 0; i < rows.size(); i++){
paginator.addRow(rows.get(i));
count++;
}
}
paginator.setPageSize(count);
list.setPaginator(paginator);
// get all the columns name
rowsSourceBean = list.getPaginator().getAll();
List colNames = new ArrayList();