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();
List rows = null;
if(rowsSourceBean != null) {
rows = rowsSourceBean.getAttributeAsList(DataRow.ROW_TAG);
if((rows!=null) && (rows.size()!=0)) {
SourceBean row = (SourceBean)rows.get(0);
List rowAttrs = row.getContainedAttributes();
Iterator rowAttrsIter = rowAttrs.iterator();
while(rowAttrsIter.hasNext()) {
SourceBeanAttribute rowAttr = (SourceBeanAttribute)rowAttrsIter.next();
colNames.add(rowAttr.getKey());
}
}
}
// build module configuration for the list
String moduleConfigStr = "";
moduleConfigStr += "<CONFIG>";
moduleConfigStr += " <QUERIES/>";
moduleConfigStr += " <COLUMNS>";
// if there's no colum name add a fake column to show that there's no data
if(colNames.size()==0) {
moduleConfigStr += " <COLUMN name=\"No Result Found\" />";
} else {
Iterator iterColNames = colNames.iterator();
while(iterColNames.hasNext()) {
String colName = (String)iterColNames.next();
moduleConfigStr += " <COLUMN name=\"" + colName + "\" />";
}
}
moduleConfigStr += " </COLUMNS>";
moduleConfigStr += " <CAPTIONS/>";
moduleConfigStr += " <BUTTONS/>";
moduleConfigStr += "</CONFIG>";
SourceBean moduleConfig = SourceBean.fromXMLString(moduleConfigStr);
response.setAttribute(moduleConfig);
// filter the list
String valuefilter = (String) request.getAttribute(SpagoBIConstants.VALUE_FILTER);