Esempio n. 1
0
  /**
   * Add into the parameters map the BIObject's BIParameter names and values
   *
   * @param biobj BIOBject to execute
   * @param pars Map of the parameters for the execution call
   * @return Map The map of the execution call parameters
   */
  private Map appendAnalyticalDriversToRequestParameters(BIObject biobj, Map pars) {
    logger.debug("IN");

    if (biobj == null) {
      logger.warn("BIObject parameter null");
      return pars;
    }

    ParameterValuesEncoder parValuesEncoder = new ParameterValuesEncoder();
    if (biobj.getBiObjectParameters() != null) {
      BIObjectParameter biobjPar = null;
      for (Iterator it = biobj.getBiObjectParameters().iterator(); it.hasNext(); ) {
        try {
          biobjPar = (BIObjectParameter) it.next();
          String value = parValuesEncoder.encode(biobjPar);
          pars.put(biobjPar.getParameterUrlName(), value);
          logger.debug("Add parameter:" + biobjPar.getParameterUrlName() + "/" + value);
        } catch (Exception e) {
          logger.error("Error while processing a BIParameter", e);
        }
      }
    }

    logger.debug("OUT");
    return pars;
  }
  /**
   * 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;
  }