public SourceBean getTemplateAsSourceBean(byte[] content) { SourceBean templateSB = null; try { templateSB = SourceBean.fromXMLString(getTemplateAsString(content)); } catch (SourceBeanException e) { logger.error("Error while getting template source bean", e); } return templateSB; }
/** * This function returns the value of the attribute required, if existent in the xml field * * @param String attribute for which the value is requested * @return The value of the attribute */ public String getValueFromStandardXmlValue(String attribute) { String valToReturn = ""; if (valueXml != null) { try { SourceBean xmlValueSB = SourceBean.fromXMLString(valueXml); valToReturn = (String) xmlValueSB.getAttribute(attribute); } catch (SourceBeanException e) { logger.error("Source Bean Exception", e); e.printStackTrace(); } } return valToReturn; }
public Object deserialize(Object o, Class clazz) throws DeserializationException { Object result = null; try { Assert.assertNotNull(o, "Input parameter [" + o + "] cannot be null"); Assert.assertNotNull(o, "Input parameter [" + clazz + "] cannot be null"); SourceBean xml = null; if (o instanceof SourceBean) { xml = (SourceBean) o; } else if (o instanceof String) { xml = SourceBean.fromXMLString((String) o); } else { throw new DeserializationException( "Impossible to deserialize from an object of type [" + o.getClass().getName() + "]"); } Deserializer deserializer = mappings.get(clazz); if (deserializer == null) { throw new DeserializationException( "Impossible to deserialize to an object of type [" + clazz.getName() + "]"); } if (xml.getAttribute("ROWS") != null) { List list = new ArrayList(); List<SourceBean> rows = xml.getAttributeAsList("ROWS.ROW"); for (SourceBean row : rows) { list.add(deserializer.deserialize(row, clazz)); } result = list; } else { result = deserializer.deserialize(o, clazz); } } catch (Throwable t) { throw new DeserializationException("An error occurred while deserializing object: " + o, t); } finally { } return result; }
public String composeWorksheetTemplate( String workSheetDef, String workSheetQuery, String smartFilterValues, String originalQbeTempl) throws SourceBeanException { SourceBean templateSB = new SourceBean(TAG_WORKSHEET); templateSB.setAttribute(ATTRIBUTE_VERSION, CURRENT_VERSION); SourceBean confSB = SourceBean.fromXMLString(originalQbeTempl); // from version 0 to version 1 worksheet change compensation: on version 0 the // worksheet definition was inside QBE tag; on version 1 the QBE tag is inside // WORKSHEET tag if (confSB.getName().equalsIgnoreCase(TAG_QBE) || confSB.getName().equalsIgnoreCase(TAG_QBE_COMPOSITE) || confSB.getName().equalsIgnoreCase(TAG_SMART_FILTER)) { if (confSB.containsAttribute(TAG_WORKSHEET_DEFINITION)) { confSB.delAttribute(TAG_WORKSHEET_DEFINITION); } templateSB.setAttribute(confSB); SourceBean wk_def_sb = new SourceBean(TAG_WORKSHEET_DEFINITION); wk_def_sb.setCharacters(workSheetDef); templateSB.setAttribute(wk_def_sb); if (workSheetQuery != null && !workSheetQuery.equals("")) { SourceBean query_sb = new SourceBean(QUERY); query_sb.setCharacters(workSheetQuery); confSB.updAttribute(query_sb); } if (smartFilterValues != null && !smartFilterValues.equals("")) { SourceBean smartFilterValuesSB = new SourceBean(FORM_VALUES); smartFilterValuesSB.setCharacters(smartFilterValues); confSB.updAttribute(smartFilterValuesSB); } } else { SourceBean qbeSB = null; if (confSB.containsAttribute(TAG_QBE)) { qbeSB = (SourceBean) confSB.getAttribute(TAG_QBE); } else if (confSB.containsAttribute(TAG_QBE_COMPOSITE)) { qbeSB = (SourceBean) confSB.getAttribute(TAG_QBE_COMPOSITE); } else if (confSB.containsAttribute(TAG_SMART_FILTER)) { qbeSB = (SourceBean) confSB.getAttribute(TAG_SMART_FILTER); } if (qbeSB != null) { templateSB.setAttribute(qbeSB); if (workSheetQuery != null && !workSheetQuery.equals("")) { SourceBean query_sb = new SourceBean(QUERY); query_sb.setCharacters(workSheetQuery); qbeSB.updAttribute(query_sb); } if (smartFilterValues != null && !smartFilterValues.equals("")) { SourceBean smartFilterValuesSB = new SourceBean(FORM_VALUES); smartFilterValuesSB.setCharacters(smartFilterValues); qbeSB.updAttribute(smartFilterValuesSB); } } SourceBean wk_def_sb = new SourceBean(TAG_WORKSHEET_DEFINITION); wk_def_sb.setCharacters(workSheetDef); templateSB.setAttribute(wk_def_sb); } String template = templateSB.toXML(false); return template; }
/** * Inherited by IChart: calculates chart value. * * @return the dataset * @throws Exception the exception */ public DatasetMap calculateValue() throws Exception { logger.debug("IN"); String res = DataSetAccessFunctions.getDataSetResultFromId(profile, getData(), parametersObject); categories = new HashMap(); seriesCaptions = new LinkedHashMap(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); SourceBean sbRows = SourceBean.fromXMLString(res); List listAtts = sbRows.getAttributeAsList("ROW"); // run all categories (one for each row) categoriesNumber = 0; seriesNames = new Vector(); catGroupNames = new Vector(); // categories.put(new Integer(0), "All Categories"); if (filterCatGroups == true) { catGroups = new HashMap(); } boolean first = true; // run all dataset rows for (Iterator iterator = listAtts.iterator(); iterator.hasNext(); ) { SourceBean category = (SourceBean) iterator.next(); List atts = category.getContainedAttributes(); if (first) { if (name.indexOf("$F{") >= 0) { setTitleParameter(atts); } if (getSubName() != null && getSubName().indexOf("$F") >= 0) { setSubTitleParameter(atts); } first = false; } HashMap series = new HashMap(); String catValue = ""; String cat_group_name = ""; String name = ""; String value = ""; int contSer = 0; // run all the attributes in a row, to define series pertaining to a category! for (Iterator iterator2 = atts.iterator(); iterator2.hasNext(); ) { SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next(); name = new String(object.getKey()); value = new String((String) object.getValue()); // the one targeted x is the category name if (name.equalsIgnoreCase("x")) { catValue = value; categoriesNumber = categoriesNumber + 1; categories.put(new Integer(categoriesNumber), value); } else if (name.equalsIgnoreCase("cat_group")) { cat_group_name = value; } else if (this.getNumberSerVisualization().intValue() > 0 && contSer < this.getNumberSerVisualization().intValue()) { // map containing the series series.put(name, value); contSer++; } else if (seriesLabelsMap != null) { String serieLabel = (String) seriesLabelsMap.get(name); if (serieLabel != null) { series.put(serieLabel, value); seriesCaptions.put(serieLabel, name); } } else series.put(name, value); } // if a category group was found add it if (!cat_group_name.equalsIgnoreCase("") && !catValue.equalsIgnoreCase("") && catGroups != null) { catGroups.put(catValue, cat_group_name); if (!(catGroupNames.contains(cat_group_name))) { catGroupNames.add(cat_group_name); } } // add series to dataset only if not hidden for (Iterator iterator3 = series.keySet().iterator(); iterator3.hasNext(); ) { String nameS = (String) iterator3.next(); String labelS = ""; if (!hiddenSeries.contains(nameS)) { if (seriesLabelsMap != null && (seriesCaptions != null && seriesCaptions.size() > 0)) { nameS = (String) (seriesCaptions.get(nameS)); labelS = (String) seriesLabelsMap.get(nameS); } else labelS = nameS; String valueS = (String) series.get(labelS); if (labelS != null && valueS != null && !valueS.equals("null") && !valueS.equals("")) { // orig dataset.addValue(Double.valueOf(valueS).doubleValue(), nameS, catValue); dataset.addValue(Double.valueOf(valueS).doubleValue(), labelS, catValue); /*orig if(!seriesNames.contains(nameS)){ seriesNames.add(nameS); }*/ if (!seriesNames.contains(labelS)) { seriesNames.add(labelS); } } } } } if (listAtts.size() == 0) { if (name.indexOf("$F{") >= 0) { setTitleParameter(""); } if (getSubName() != null && getSubName().indexOf("$F") >= 0) { setSubTitleParameter(""); } } logger.debug("OUT"); DatasetMap datasets = new DatasetMap(); datasets.addDataset("1", dataset); return datasets; }
private ListIFace loadSpagoList( SourceBean request, SourceBean response, Integer parId, String roleName) throws Exception { logger.debug("IN"); 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, 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, 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); if (valuefilter != null) { String columnfilter = (String) request.getAttribute(SpagoBIConstants.COLUMN_FILTER); String typeFilter = (String) request.getAttribute(SpagoBIConstants.TYPE_FILTER); String typeValueFilter = (String) request.getAttribute(SpagoBIConstants.TYPE_VALUE_FILTER); list = DelegatedBasicListService.filterList( list, valuefilter, typeValueFilter, columnfilter, typeFilter, getResponseContainer().getErrorHandler()); } // fill response response.setAttribute(SpagoBIConstants.PARAMETER_FIELD_NAME, parameterFieldName); response.setAttribute(SpagoBIConstants.VALUE_COLUMN_NAME, valColName); logger.debug("OUT"); return list; }