Esempio n. 1
0
  private Locale getLocale() {
    logger.debug("IN");
    try {
      Locale locale = null;

      if (RequestContainer.getRequestContainer() != null) {
        RequestContainer requestContainer = RequestContainer.getRequestContainer();
        SessionContainer permanentSession =
            requestContainer.getSessionContainer().getPermanentContainer();
        String language = (String) permanentSession.getAttribute(SpagoBIConstants.AF_LANGUAGE);
        String country = (String) permanentSession.getAttribute(SpagoBIConstants.AF_COUNTRY);
        logger.debug(
            "Language retrieved: [" + language + "]; country retrieved: [" + country + "]");
        locale = new Locale(language, country);
      } else {
        locale = GeneralUtilities.getDefaultLocale();
      }
      return locale;
    } catch (Exception e) {
      logger.error("Error while getting locale; using default one", e);
      return GeneralUtilities.getDefaultLocale();
    } finally {
      logger.debug("OUT");
    }
  }
  private void goToDocumentRating(SourceBean request, String mod, SourceBean response)
      throws EMFUserError, SourceBeanException {

    RequestContainer requestContainer = this.getRequestContainer();
    SessionContainer session = requestContainer.getSessionContainer();
    SessionContainer permanentSession = session.getPermanentContainer();
    String objId = (String) request.getAttribute("OBJECT_ID");

    response.setAttribute("OBJECT_ID", objId);
    response.setAttribute("MESSAGEDET", mod);
    response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "ratingBIObjectPubJ");
  }
  /**
   * Starting tag.
   *
   * @return the int
   * @throws JspException the jsp exception
   */
  public int doStartTag() throws JspException {
    httpRequest = (HttpServletRequest) pageContext.getRequest();
    RequestContainer requestContainer = ChannelUtilities.getRequestContainer(httpRequest);
    ResponseContainer responseContainer = ChannelUtilities.getResponseContainer(httpRequest);
    SourceBean serviceRequest = requestContainer.getServiceRequest();
    SourceBean serviceResponse = responseContainer.getServiceResponse();
    SourceBean moduleResponse = (SourceBean) serviceResponse.getAttribute(moduleName);

    List functionalitiesList = null;
    if (attributeToRender == null || attributeToRender.trim().equals("")) {
      functionalitiesList =
          (List) moduleResponse.getAttribute(SpagoBIConstants.FUNCTIONALITIES_LIST);
    } else {
      functionalitiesList = (List) moduleResponse.getAttribute(attributeToRender);
    }
    String initialPath = (String) moduleResponse.getAttribute(TreeObjectsModule.PATH_SUBTREE);
    ITreeHtmlGenerator gen = null;
    try {
      gen = (ITreeHtmlGenerator) Class.forName(htmlGeneratorClass).newInstance();
    } catch (Exception e) {
      return -1;
    }

    StringBuffer htmlStream = null;
    if (treeName == null) {
      htmlStream = gen.makeTree(functionalitiesList, httpRequest, initialPath);
    } else {
      htmlStream = gen.makeTree(functionalitiesList, httpRequest, initialPath, treeName);
    }

    try {
      pageContext.getOut().print(htmlStream);
    } catch (IOException ioe) {
      SpagoBITracer.major(
          SpagoBIConstants.NAME_MODULE,
          this.getClass().getName(),
          "doStartTag",
          "cannot start object tree tag: IOexception occurred",
          ioe);
    }
    return SKIP_BODY;
  }
  public void service(SourceBean serviceRequest, SourceBean serviceResponse) throws Exception {
    logger.debug("IN");
    RequestContainer reqCont = RequestContainer.getRequestContainer();
    SessionContainer sessCont = reqCont.getSessionContainer();
    SessionContainer permSess = sessCont.getPermanentContainer();

    String theme_name = (String) serviceRequest.getAttribute(THEME_NAME);
    logger.debug("theme selected: " + theme_name);

    permSess.setAttribute(SpagoBIConstants.THEME, theme_name);

    IEngUserProfile profile =
        (IEngUserProfile) permSess.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
    userProfile = null;
    if (profile instanceof UserProfile) {
      userProfile = (UserProfile) profile;
    }

    MenuUtilities.getMenuItems(serviceRequest, serviceResponse, profile);

    serviceResponse.setAttribute("MENU_MODE", "ALL_TOP");
    serviceResponse.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "userhome");
    logger.debug("OUT");
  }
  private void documentRating(SourceBean request, String mod, SourceBean response)
      throws EMFUserError, SourceBeanException {

    String objId = "";
    String rating = "";
    RequestContainer requestContainer = this.getRequestContainer();
    SessionContainer session = requestContainer.getSessionContainer();
    SessionContainer permanentSession = session.getPermanentContainer();
    UserProfile profile =
        (UserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
    IEngUserProfile profile2 =
        (IEngUserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
    String userId =
        (profile.getUserUniqueIdentifier() != null
            ? profile.getUserUniqueIdentifier().toString()
            : "");
    List params = request.getContainedAttributes();
    ListIterator it = params.listIterator();

    while (it.hasNext()) {

      Object par = it.next();
      SourceBeanAttribute p = (SourceBeanAttribute) par;
      String parName = (String) p.getKey();
      logger.debug("got parName=" + parName);
      if (parName.equals("OBJECT_ID")) {
        objId = (String) request.getAttribute("OBJECT_ID");
        logger.debug("got OBJECT_ID from Request=" + objId);
      } else if (parName.equals("RATING")) {
        rating = (String) request.getAttribute("RATING");
      }
    }
    boolean canSee = false;

    BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectById(new Integer(objId));
    try {
      canSee = ObjectsAccessVerifier.canSee(obj, profile);
    } catch (EMFInternalError e1) {
      e1.printStackTrace();
    }
    if (!canSee) {
      logger.error("Object with label = '" + obj.getLabel() + "' cannot be executed by the user!!");
      Vector v = new Vector();
      v.add(obj.getLabel());
      throw new EMFUserError(EMFErrorSeverity.ERROR, "1075", v, null);
    }
    // get all correct execution roles
    List correctRoles = new ArrayList();
    try {
      correctRoles =
          DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(new Integer(objId), profile2);
    } catch (NumberFormatException e2) {
      e2.printStackTrace();
    }
    if (correctRoles == null || correctRoles.size() == 0) {
      logger.warn("Object cannot be executed by no role of the user");
      throw new EMFUserError(EMFErrorSeverity.ERROR, 1006);
    }

    if (objId != null && !objId.equals("")) {
      if (rating != null && !rating.equals("")) {
        // VOTE!
        DAOFactory.getBIObjectRatingDAO().voteBIObject(obj, userId, rating);
      }
    }

    response.setAttribute("MESSAGEDET", mod);
    response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "ratingBIObjectPubJ");
    response.setAttribute("OBJECT_ID", objId);
  }
  /**
   * Do start tag.
   *
   * @return the int
   * @throws JspException the jsp exception
   * @see it.eng.spagobi.commons.presentation.tags.CheckListTag#doStartTag()
   */
  public int doStartTag() throws JspException {
    SpagoBITracer.info("Admintools", "ListTag", "doStartTag", " method invoked");
    httpRequest = (HttpServletRequest) pageContext.getRequest();
    renderResponse = (RenderResponse) httpRequest.getAttribute("javax.portlet.response");
    renderRequest = (RenderRequest) httpRequest.getAttribute("javax.portlet.request");

    _requestContainer = RequestContainerPortletAccess.getRequestContainer(httpRequest);
    portReq = PortletUtilities.getPortletRequest();
    _serviceRequest = _requestContainer.getServiceRequest();
    _responseContainer = ResponseContainerPortletAccess.getResponseContainer(httpRequest);

    msgBuilder = MessageBuilderFactory.getMessageBuilder();
    if (_bundle == null) _bundle = "messages";

    _session = _requestContainer.getSessionContainer();

    _serviceResponse = _responseContainer.getServiceResponse();
    ConfigSingleton configure = ConfigSingleton.getInstance();
    if (_actionName != null) {
      _serviceName = _actionName;
      _content = _serviceResponse;
      SourceBean actionBean =
          (SourceBean)
              configure.getFilteredSourceBeanAttribute("ACTIONS.ACTION", "NAME", _actionName);
      _layout = (SourceBean) actionBean.getAttribute("CONFIG");
      if (_layout == null) {
        // if the layout is dinamically created it is an attribute of the response
        _layout = (SourceBean) _serviceResponse.getAttribute("CONFIG");
      }
      _providerURL = "ACTION_NAME=" + _actionName + "&";
      _providerUrlMap.put("ACTION_NAME", _actionName);
      HashMap params = (HashMap) _serviceResponse.getAttribute("PARAMETERS_MAP");
      if (params != null) {
        _paramsMap = params;
        _providerUrlMap.putAll(_paramsMap);
      }
    } // if (_actionName != null)
    else if (_moduleName != null) {
      _serviceName = _moduleName;
      SpagoBITracer.debug("Admintools", "ListTag", "doStartTag", " Module Name: " + _moduleName);
      _content = (SourceBean) _serviceResponse.getAttribute(_moduleName);
      SourceBean moduleBean =
          (SourceBean)
              configure.getFilteredSourceBeanAttribute("MODULES.MODULE", "NAME", _moduleName);

      if (moduleBean != null)
        SpagoBITracer.debug(
            "Admintools", "ListTag", "doStartTag", _moduleName + " configuration loaded");
      _layout = (SourceBean) moduleBean.getAttribute("CONFIG");
      if (_layout == null) {
        // if the layout is dinamically created it is an attribute of the response
        _layout = (SourceBean) _serviceResponse.getAttribute(_moduleName + ".CONFIG");
      }
      String pageName = (String) _serviceRequest.getAttribute("PAGE");
      SpagoBITracer.debug("Admintools", "ListTag", "doStartTag", " PAGE: " + pageName);
      _providerURL = "PAGE=" + pageName + "&MODULE=" + _moduleName + "&";
      _providerUrlMap.put("PAGE", pageName);
      _providerUrlMap.put("MODULE", _moduleName);
      HashMap params = (HashMap) _serviceResponse.getAttribute(_moduleName + ".PARAMETERS_MAP");
      if (params != null) {
        _paramsMap = params;
        _providerUrlMap.putAll(_paramsMap);
      }
    } // if (_moduleName != null)
    else {
      SpagoBITracer.critical("Admintools", "ListTag", "doStartTag", "service name not specified");
      throw new JspException("Business name not specified !");
    } // if (_content == null)
    if (_content == null) {
      SpagoBITracer.warning("Admintools", "ListTag", "doStartTag", "list content null");
      return SKIP_BODY;
    } // if (_content == null)
    if (_layout == null) {
      SpagoBITracer.warning(
          "Admintools", "ListTag", "doStartTag", "list module configuration null");
      return SKIP_BODY;
    } // if (_layout == null)
    // if the LightNavigator is disabled entering the list, it is kept disabled untill exiting the
    // list
    Object lightNavigatorDisabledObj =
        _serviceRequest.getAttribute(LightNavigationManager.LIGHT_NAVIGATOR_DISABLED);
    if (lightNavigatorDisabledObj != null) {
      String lightNavigatorDisabled = (String) lightNavigatorDisabledObj;
      _providerUrlMap.put(LightNavigationManager.LIGHT_NAVIGATOR_DISABLED, lightNavigatorDisabled);
    }
    _htmlStream = new StringBuffer();

    PortletURL url = renderResponse.createActionURL();
    url.setParameter("PAGE", "DetailBIObjectPage");
    url.setParameter("MESSAGEDET", "RETURN_FROM_SUBREPORTS_LOOKUP");
    url.setParameter("LIGHT_NAVIGATOR_DISABLED", "true");

    _htmlStream.append(" <form method='POST' action='" + url.toString() + "'>\n");
    makeForm();
    _htmlStream.append(" </form>\n");
    try {
      pageContext.getOut().print(_htmlStream);
    } // try
    catch (Exception ex) {
      SpagoBITracer.critical(
          "Admintools", "ListTag", "doStartTag", "Impossible to send the stream");
      throw new JspException("Impossible to send the stream");
    } // catch (Exception ex)
    return SKIP_BODY;
  } // public int doStartTag() throws JspException
Esempio n. 7
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;
  }