Package it.eng.spagobi.events

Examples of it.eng.spagobi.events.EventsManager


        if (aSession.isOpen()) aSession.close();
      }
    }
    //End writing log in the DB
   
    EventsManager eventsManager = EventsManager.getInstance();   
    List firedEventsList = eventsManager.getRegisteredEvents(profile);
        SingletonConfig config = SingletonConfig.getInstance();
        String formatSB = config.getConfigValue("SPAGOBI.DATE-FORMAT.format");
        String format = (formatSB==null)?"": formatSB;
      format = format.replaceAll("D", "d");
      format = format.replaceAll("m", "M");
View Full Code Here


   
    IBIObjectDAO biobjdao;
    BIObject biobj;
    ExecutionController executionController;
    ExecutionProxy executionProxy;
    EventsManager eventManager;
   
    logger.debug("IN");
   
    try {
      profile = UserProfile.createSchedulerUserProfile();
      jobDataMap = jobExecutionContext.getMergedJobDataMap();
      biobjdao = DAOFactory.getBIObjectDAO();
     
      String doclabelsConcat = jobDataMap.getString("documentLabels");
      String[] docLabels = doclabelsConcat.split(",");
      Iterator itr = jobDataMap.keySet().iterator();
      while(itr.hasNext()) {
        Object key = itr.next();
        Object value = jobDataMap.get(key);
        logger.debug("jobDataMap parameter [" + key + "] is equal to [" + value + "]");
      }
     
      long startSchedule = System.currentTimeMillis();
      logger.debug("Scheduled activity contains [" + docLabels.length + "] documnt(s)");

      for(int ind = 0; ind < docLabels.length; ind++) {
        documentInstanceName = docLabels[ind];
        documentLabel = documentInstanceName.substring(0, documentInstanceName.lastIndexOf("__"));
        logger.debug("Processing document [" + (ind+1) + "] with label [" + documentLabel + "] ...");
       
        inputParametersQueryString = jobDataMap.getString(documentInstanceName);
        logger.debug("Input parameters query string for documet [" + documentLabel + "] is equal to [" + inputParametersQueryString + "]");
       
        // load bidocument
        biobj = biobjdao.loadBIObjectByLabel(documentLabel);
       
        // get the save options
        String saveOptString = jobDataMap.getString("biobject_id_" + biobj.getId() + "__"+ (ind+1));
        SaveInfo saveInfo = SchedulerUtilities.fromSaveInfoString(saveOptString);
       
        // create the execution controller
        executionController = new ExecutionController();
        executionController.setBiObject(biobj);
       
        // fill parameters
        executionController.refreshParameters(biobj, inputParametersQueryString);

        String iterativeParametersString = jobDataMap.getString(documentInstanceName + "_iterative");
        logger.debug("Iterative parameter configuration for documet [" + documentLabel + "] is equal to [" + iterativeParametersString + "]");
        setIterativeParameters(biobj, iterativeParametersString);
       
        String loadAtRuntimeParametersString = jobDataMap.getString(documentInstanceName + "_loadAtRuntime");
        logger.debug("Runtime parameter configuration for documet [" + documentLabel + "] is equal to [" + loadAtRuntimeParametersString + "]");
        setLoadAtRuntimeParameters(biobj, loadAtRuntimeParametersString);
       
        String useFormulaParametersString = jobDataMap.getString(documentInstanceName + "_useFormula");
        logger.debug("Formuula based parameter configuration for documet [" + documentLabel + "] is equal to [" + useFormulaParametersString + "]");
        setUseFormulaParameters(biobj, useFormulaParametersString);

        retrieveParametersValues(biobj);

        //gets the dataset data about the email address
        IDataStore emailDispatchDataStore = null;
        if (saveInfo.isUseDataSet()) {
          IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(saveInfo.getDataSetLabel());
          dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(profile));
          dataSet.loadData();
          emailDispatchDataStore = dataSet.getDataStore();
        }
        //gets the dataset data about the folder for the document save
        IDataStore folderDispatchDataSotre = null;
        if (saveInfo.isUseFolderDataSet()) {
          IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(saveInfo.getDataSetFolderLabel());
            dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(profile));
          dataSet.loadData();
           folderDispatchDataSotre = dataSet.getDataStore();
        }
       
        eventManager = EventsManager.getInstance();
        List roles = DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(biobj.getId());
       
        String startExecMsg = "${scheduler.startexecsched} " + biobj.getName()
        Integer idEvent = eventManager.registerEvent("Scheduler", startExecMsg, "", roles);

       
        Map tempParMap = new HashMap();
        BIObjectParametersIterator objectParametersIterator = new BIObjectParametersIterator(biobj.getBiObjectParameters());
        while (objectParametersIterator.hasNext()) {
          List parameters = (List) objectParametersIterator.next();
          biobj.setBiObjectParameters(parameters);
       

          StringBuffer toBeAppendedToName = new StringBuffer();
          StringBuffer toBeAppendedToDescription = new StringBuffer(" [");
          Iterator parametersIt = parameters.iterator();
          while (parametersIt.hasNext()) {
           
            BIObjectParameter aParameter = (BIObjectParameter) parametersIt.next();
           
            tempParMap.put(aParameter.getParameterUrlName(), aParameter.getParameterValuesAsString());
            if (aParameter.isIterative()) {
              toBeAppendedToName.append("_" + aParameter.getParameterValuesAsString());
              toBeAppendedToDescription.append(aParameter.getLabel() + ":" + aParameter.getParameterValuesAsString() + "; ");
            }
          }
          // if there are no iterative parameters, toBeAppendedToDescription is " [" and must be cleaned
          if (toBeAppendedToDescription.length() == 2) {
            toBeAppendedToDescription.delete(0, 2);
          } else {
            // toBeAppendedToDescription ends with "; " and must be cleaned
            toBeAppendedToDescription.delete(toBeAppendedToDescription.length() - 2, toBeAppendedToDescription.length());
            toBeAppendedToDescription.append("]");
          }

          // appending the current date
          Date date = new Date();
          SimpleDateFormat sdf = new SimpleDateFormat();
          sdf.applyPattern("dd:MM:yyyy");
          String dateStr = sdf.format(date);
          toBeAppendedToName.append("_" + dateStr);
         
         

          //check parameters value: if a parameter hasn't value but isn't mandatory the process
          //must go on and so hasValidValue is set to true
          List tmpBIObjectParameters = biobj.getBiObjectParameters();
          Iterator it = tmpBIObjectParameters.iterator();
          while (it.hasNext()){
            boolean isMandatory = false;
            BIObjectParameter aBIObjectParameter = (BIObjectParameter)it.next();
            List checks = aBIObjectParameter.getParameter().getChecks();
            if (checks != null && !checks.isEmpty()) {
              Iterator checksIt = checks.iterator();
              while (checksIt.hasNext()) {
                Check check = (Check) checksIt.next();
                if (check.getValueTypeCd().equalsIgnoreCase("MANDATORY")) {
                  isMandatory = true;
                  break;
                }
              }
            }
            if (!isMandatory &&
                (aBIObjectParameter.getParameterValues() == null  || aBIObjectParameter.getParameterValues().size() == 0)) {
              aBIObjectParameter.setParameterValues(new ArrayList());
              aBIObjectParameter.setHasValidValues(true);
            }
          }


          // exec the document only if all its parameter are filled
          if(executionController.directExecution()) {
           
            logger.debug("Save as snapshot is eual to [" + saveInfo.isSaveAsSnapshot() + "]");
            logger.debug("Dispatch to a distribution list is eual to [" + saveInfo.isSendToDl() + "]");
            logger.debug("Dispatch to a java class is eual to [" + saveInfo.isSendToJavaClass() + "]");
            logger.debug("Dispatch by mail-list is eual to [" + saveInfo.isSendMail() + "]");
            logger.debug("Dispatch by folder-list is eual to [" + saveInfo.isSaveAsDocument() + "]");
           
            if(!saveInfo.isSaveAsSnapshot() && !saveInfo.isSendToDl() && !saveInfo.isSendToJavaClass()) {
              boolean noValidDispatchTarget = false;
              if(saveInfo.isSendMail()) {
                String[] recipients = findRecipients(saveInfo, biobj, emailDispatchDataStore);
                if (recipients != null && recipients.length > 0) {
                  noValidDispatchTarget = false;
                  logger.debug("Found at least one target of type mail");
                }else{
                  noValidDispatchTarget = true;
                }
              }
             
              if(saveInfo.isSaveAsDocument()) {
                List storeInFunctionalities = findFolders(saveInfo, biobj, folderDispatchDataSotre);
                if(storeInFunctionalities != null && !storeInFunctionalities.isEmpty()) {
                  noValidDispatchTarget = false;
                  logger.debug("Found at least one target of type folder");
                }else{
                  noValidDispatchTarget = true;
                }
              }
             
              if(noValidDispatchTarget) {
                logger.debug("No valid dispatch target for document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters [" + toBeAppendedToDescription +"]");
                logger.info("Document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription + " not executed: no valid dispatch target");
                continue;
              } else if(!saveInfo.isSaveAsDocument() && !saveInfo.isSendMail()){
                logger.debug("There are no dispatch targets for document with label [" + documentInstanceName + "] - if not an ETL, WEKA or KPI document a dispatch target should be added");
              }else{
                logger.debug("There is at list one dispatch target for document with label [" + documentInstanceName + "]");
              }
            }

            executionProxy = new ExecutionProxy();
            executionProxy.setBiObject(biobj);
           
           
           
           
            logger.info("Executing document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription +" ...");
            long start = System.currentTimeMillis();
            byte[] response = executionProxy.exec(profile, "SCHEDULATION", null);
            if (response == null || response.length == 0) {
              logger.debug("Document executed without any response");
            }
            String retCT = executionProxy.getReturnedContentType();
            String fileextension = executionProxy.getFileExtensionFromContType(retCT);
            long end = System.currentTimeMillis();     
            long elapsed = (end - start)/1000;
            logger.info("Document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription +" executed in [" + elapsed + "]");
           
           
            if(saveInfo.isSaveAsSnapshot()) {
              saveAsSnap(saveInfo, biobj, response, toBeAppendedToName.toString(), toBeAppendedToDescription.toString(),profile);
            }

            if(saveInfo.isSaveAsDocument()) {
              saveAsDocument(saveInfo, biobj,jobExecutionContext, response, fileextension, folderDispatchDataSotre, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
            }

            if(saveInfo.isSendMail()) {
              sendMail(saveInfo, biobj, tempParMap, response, retCT, fileextension, emailDispatchDataStore, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
            }
            if(saveInfo.isSendToDl()) {
              sendToDl(saveInfo, biobj, response, retCT, fileextension, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
              if(jobExecutionContext.getNextFireTime()== null){
                String triggername = jobExecutionContext.getTrigger().getName();
                List dlIds = saveInfo.getDlIds();
                it = dlIds.iterator();
                while(it.hasNext()){
                  Integer dlId = (Integer)it.next();
                  DistributionList dl = DAOFactory.getDistributionListDAO().loadDistributionListById(dlId);
                  DAOFactory.getDistributionListDAO().eraseDistributionListObjects(dl, (biobj.getId()).intValue(), triggername);
                }
              }
            }

            if(saveInfo.isSendToJavaClass()) {
              sendToJavaClass(saveInfo, biobj, response);
            }


          } else {
            logger.warn("The document with label "+documentInstanceName+" cannot be executed directly, " +
            "maybe some prameters are not filled ");
            throw new Exception("The document with label "+documentInstanceName+" cannot be executed directly, " +
            "maybe some prameters are not filled ");
          }
        }
       
        String endExecMsg = "${scheduler.endexecsched} " + biobj.getName();
        eventManager.registerEvent("Scheduler", endExecMsg, "", roles);

      }

     
      long endSchedule = System.currentTimeMillis();
View Full Code Here

TOP

Related Classes of it.eng.spagobi.events.EventsManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.