private void addBIObjectParameterToDossier(
     BIObject dossier, BIObjectParameter parameterToBeAdded) {
   logger.debug("IN");
   IBIObjectParameterDAO objParDAO;
   try {
     objParDAO = DAOFactory.getBIObjectParameterDAO();
     BIObjectParameter objPar = new BIObjectParameter();
     objPar.setId(new Integer(-1));
     objPar.setBiObjectID(dossier.getId());
     objPar.setParID(parameterToBeAdded.getParID());
     Parameter par = new Parameter();
     par.setId(parameterToBeAdded.getParID());
     objPar.setParameter(par);
     objPar.setLabel(parameterToBeAdded.getLabel());
     objPar.setParameterUrlName(parameterToBeAdded.getParameterUrlName());
     objPar.setRequired(parameterToBeAdded.getRequired());
     objPar.setModifiable(parameterToBeAdded.getModifiable());
     objPar.setVisible(parameterToBeAdded.getVisible());
     objPar.setMultivalue(parameterToBeAdded.getMultivalue());
     List existingParameters = dossier.getBiObjectParameters();
     int priority = existingParameters != null ? existingParameters.size() + 1 : 1;
     objPar.setPriority(new Integer(priority));
     parameterToBeAdded.setId(new Integer(-1));
     objParDAO.insertBIObjectParameter(objPar);
   } catch (EMFUserError e) {
     throw new RuntimeException(
         "Cannot save new parameter into dossier with label " + dossier.getLabel(), e);
   }
   updateBIObjectParameters(dossier);
   logger.debug("OUT");
 }
  /**
   * Return a string representative an url with all parameters set with a request value (if it is
   * present) or with the default's value.
   *
   * @param doc the document object that is managed
   * @param document the document configurator
   * @param requestSB the request object
   * @return a string with the url completed
   */
  private static String getParametersUrl(
      BIObject obj, Document document, SourceBean requestSB, ExecutionInstance instance) {
    logger.debug("IN");
    String paramUrl = "";
    // set others parameters value
    Properties lstParams = document.getParams();
    String key = "";
    List values = new ArrayList();
    String singleValue = "";
    int cont = 0;

    try {
      if (lstParams != null) {
        ParameterValuesEncoder encoderUtility = new ParameterValuesEncoder();
        // while(enParams.hasMoreElements()) {
        for (int i = 0; i < lstParams.size(); i++) {
          String typeParam =
              lstParams.getProperty("type_par_" + document.getNumOrder() + "_" + cont);
          // only for parameter in input to the document managed (type equal 'IN')
          if (typeParam != null && typeParam.indexOf("IN") >= 0) {
            String tmpKey = "sbi_par_label_param_" + document.getNumOrder() + "_" + cont;
            key = lstParams.getProperty(tmpKey);
            if (key == null && !document.getTypeCross().equalsIgnoreCase(Constants.CROSS_EXTERNAL))
              break;

            values = (List) requestSB.getAttributeAsList(key);
            // if value isn't defined, check if there is a value into the instance(there is when a
            // document is called from a refresh o viewpoint mode)
            if (values == null || values.size() == 0 || ((String) values.get(0)).equals("")) {
              List instanceValue = getInstanceValue(key, instance);
              if (instanceValue != null
                  && instanceValue.size() > 0
                  && !instanceValue.get(0).equals("")) values = instanceValue;
            }
            // if value isn't defined, gets the default value from the template
            if (values == null || values.size() == 0 || ((String) values.get(0)).equals("")) {
              values.add(
                  lstParams.getProperty(
                      ("default_value_param_" + document.getNumOrder() + "_" + cont)));
            }
            logger.debug("Values to pass : "******"")) {
              // EXTERNAL ENGINES
              BIObjectParameter par = getBIObjectParameter(obj, key);
              par.setParameterValues(values);
              Parameter tmpPar = par.getParameter();
              logger.debug("Manage parameter : " + tmpPar.getLabel() + "...");
              if (tmpPar != null
                  && values.size() > 1
                  && tmpPar.getModalityValue() != null
                  && ((!(par).isMultivalue())
                      || tmpPar
                          .getModalityValue()
                          .getITypeCd()
                          .equalsIgnoreCase(SpagoBIConstants.INPUT_TYPE_MAN_IN_CODE))) {
                logger.debug("Force the multivalue modality for parameter " + tmpPar.getLabel());
                // force the multivalue management if the parameter has defined as MANUAL INPUT and
                // the values is multiple.
                tmpPar.getModalityValue().setMultivalue(true);
                tmpPar.getModalityValue().setITypeCd(SpagoBIConstants.INPUT_TYPE_QUERY_CODE);
                par.setParameter(tmpPar);
              }
              String parsValue = encoderUtility.encode(par);
              // conversion in UTF-8 of the par
              Map parsMap = new HashMap();
              parsMap.put(key, parsValue);
              String tmpUrl = GeneralUtilities.getUrl("", parsMap);
              logger.debug("tmpUrl for " + obj.getLabel() + ": " + tmpUrl);
              paramUrl += "&" + tmpUrl.substring(tmpUrl.indexOf("?") + 1);

              // paramUrl += "&" + key + "=" + tmpUrl;
            } else {
              // INTERNAL ENGINES
              for (int j = 0; j < values.size(); j++) {
                singleValue = (String) values.get(j);
                if (singleValue.equals("%")) singleValue = "%25";
                // setting an url likes &key=val1;val2;valn
                if (j == 0) {
                  paramUrl += "&" + key + "=" + singleValue;
                } else {
                  paramUrl += ";" + singleValue;
                }
              }
            }

            cont++;
          }
        }
      }
    } catch (Exception ex) {
      logger.error(
          "Error while getting parameter's document "
              + document.getSbiObjLabel()
              + " param: "
              + key
              + ": "
              + ex);
      return null;
    }

    /*
    if (forInternalEngine)
    	paramUrl = paramUrl.substring(0, paramUrl.length()-3);
    else
    	paramUrl = paramUrl.substring(0, paramUrl.length()-5);
     */
    logger.debug("paramUrl: " + paramUrl);
    logger.debug("OUT");
    return paramUrl;
  }
Пример #3
0
  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;
  }