Ejemplo n.º 1
0
  private Map applyService(Map parameters, BIObject biObject) {
    logger.debug("IN");

    try {
      Assert.assertNotNull(parameters, "Input [parameters] cannot be null");

      ObjTemplate objectTemplate = biObject.getActiveTemplate();
      byte[] content = objectTemplate.getContent();
      SourceBean sbTemplate = getTemplateAsSourceBean(content);

      if (sbTemplate.getName().equals(EngineConstants.SMART_FILTER_TAG)) {
        parameters.put(PARAM_SERVICE_NAME, "FORM_ENGINE_FROM_DATASET_START_ACTION");
        if (sbTemplate.containsAttribute("DATASET")) {
          String label =
              (String) ((SourceBean) sbTemplate.getAttribute("DATASET")).getAttribute("label");
          parameters.put("dataset_label", label);
        }
      } else {
        parameters.put(PARAM_SERVICE_NAME, "FORM_ENGINE_START_ACTION");
      }
      parameters.put(PARAM_MODALITY, "VIEW");

      parameters.put(PARAM_NEW_SESSION, "TRUE");
    } catch (Throwable t) {
      throw new RuntimeException("Cannot apply service parameters", t);
    } finally {
      logger.debug("OUT");
    }

    return parameters;
  }
Ejemplo n.º 2
0
  /**
   * Function not implemented. Thid method should not be called
   *
   * @param biobject The BIOBject to edit
   * @param profile the profile
   * @return the edits the document template build url
   * @throws InvalidOperationRequest the invalid operation request
   */
  public EngineURL getEditDocumentTemplateBuildUrl(Object biobject, IEngUserProfile profile)
      throws InvalidOperationRequest {

    EngineURL engineURL;
    BIObject obj;
    String documentId;
    Engine engine;
    String url;
    HashMap parameters;

    logger.debug("IN");

    try {
      obj = null;
      try {
        obj = (BIObject) biobject;
      } catch (ClassCastException cce) {
        logger.error("The input object is not a BIObject type", cce);
        return null;
      }

      documentId = obj.getId().toString();
      engine = obj.getEngine();
      url = engine.getUrl();

      parameters = new HashMap();

      // getting the dataset label from template, if smart filter is based on a dataset
      ObjTemplate objectTemplate = obj.getActiveTemplate();
      byte[] content = objectTemplate.getContent();
      SourceBean sbTemplate = getTemplateAsSourceBean(content);
      if (sbTemplate.getName().equals(EngineConstants.SMART_FILTER_TAG)
          && sbTemplate.containsAttribute("DATASET")) {
        String label =
            (String) ((SourceBean) sbTemplate.getAttribute("DATASET")).getAttribute("label");
        parameters.put("dataset_label", label);
      }
      parameters.put("document", documentId);
      parameters.put(PARAM_SERVICE_NAME, "FORM_ENGINE_TEMPLATE_BUILD_ACTION");
      parameters.put(PARAM_NEW_SESSION, "TRUE");
      parameters.put(PARAM_MODALITY, "EDIT");
      applySecurity(parameters, profile);

      engineURL = new EngineURL(url, parameters);
    } catch (Throwable t) {
      throw new RuntimeException("Cannot get engine edit URL", t);
    } finally {
      logger.debug("OUT");
    }

    return engineURL;
  }
Ejemplo n.º 3
0
  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;
  }
Ejemplo n.º 4
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;
  }