Package it.eng.spagobi.tools.dataset.bo

Examples of it.eng.spagobi.tools.dataset.bo.IDataSet


    boolean queryRootEntity;
    // custom query
    String lookupQuery;
   
    IDataStore dataStore = null;
    IDataSet dataSet = null;
    JSONDataWriter dataSetWriter;
    Query query = null;
    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
   
    logger.debug("IN");
   
    try {
     
      super.service(request, response)
   
      totalTimeMonitor = MonitorFactory.start("QbeEngine.getFilterValuesAction.totalTime");
     
      queryType = getAttributeAsString(QUERY_TYPE);
      logger.debug("Parameter [" + QUERY_TYPE + "] is equals to [" + queryType + "]");
      if(StringUtilities.isEmpty(queryType)) {
        queryType = "standard";
        logger.debug("Parameter [" + QUERY_TYPE + "] set up to default value [" + queryType + "]");
      }
     
      lookupQuery = getAttributeAsString(LOOKUP_QUERY);
      logger.debug("Parameter [" + LOOKUP_QUERY + "] is equals to [" + lookupQuery + "]");
     
      entityId = getAttributeAsString(ENTITY_ID);
      logger.debug("Parameter [" + ENTITY_ID + "] is equals to [" + entityId + "]");
     
      orderEntity = getAttributeAsString(ORDER_ENTITY);
      logger.debug("Parameter [" + ORDER_ENTITY + "] is equals to [" + orderEntity + "]");
 
      orderType = getAttributeAsString(ORDER_TYPE);
      logger.debug("Parameter [" + ORDER_TYPE + "] is equals to [" + orderType + "]");
     
      queryRootEntity = getAttributeAsBoolean(QUERY_ROOT_ENTITY);
      logger.debug("Parameter [" + QUERY_ROOT_ENTITY + "] is equals to [" + queryRootEntity + "]");
     
      if(queryType.equalsIgnoreCase("standard")) {
        query = buildQuery(entityId, orderEntity, orderType, queryRootEntity);
      } else {
        QbeEngineInstance engineInstance = this.getEngineInstance();
        QueryCatalogue queryCatalogue = engineInstance.getQueryCatalogue();
        query = queryCatalogue.getQuery(lookupQuery);
        if(query == null) {
          throw new SpagoBIEngineServiceException(getActionName(), "Impossible to retrive custom query [" + lookupQuery + "] from catalogue");
        }
       
      }
     
      statement = getDataSource().createStatement( query );
     
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
      //String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
      //logger.debug("Executable query (SQL): [" + sqlQuery + "]");
     
      try {
        logger.debug("Executing query ...");
        dataSet = QbeDatasetFactory.createDataSet(statement);
        dataSet.setAbortOnOverflow(true);
       
        Map userAttributes = new HashMap();
        UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
        Iterator it = profile.getUserAttributeNames().iterator();
        while(it.hasNext()) {
          String attributeName = (String)it.next();
          Object attributeValue = profile.getUserAttribute(attributeName);
          userAttributes.put(attributeName, attributeValue);
        }
        dataSet.addBinding("attributes", userAttributes);
        dataSet.addBinding("parameters", this.getEnv());
        dataSet.loadData();
       
        dataStore = dataSet.getDataStore();
        Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
      dataSetWriter = new JSONDataWriter();
      gridDataFeed = (JSONObject)dataSetWriter.write(dataStore);
     
View Full Code Here


    Integer limit = null;
    Integer start = null;
    Integer maxSize = null;
    boolean isMaxResultsLimitBlocking = false;
    IDataStore dataStore = null;
    IDataSet dataSet = null;
    JSONDataWriter serializer;
    LookupStoreJSONSerializer serializer2;
    JSONObject filtersJSON = null;
    Query query = null;
    IStatement statement = null;
   
    Integer resultNumber = null;
    JSONObject gridDataFeed = new JSONObject();
   
    Monitor totalTimeMonitor = null;
    Monitor errorHitsMonitor = null;
   
    logger.debug("IN");
   
    try {
     
      super.service(request, response)
   
      totalTimeMonitor = MonitorFactory.start("QbeEngine.GetValuesForQbeFilterLookup.totalTime");
     
      entityId = getAttributeAsString( ENTITY_ID );
      if(this.requestContainsAttribute( FILTERS ) ) {
        filtersJSON = getAttributeAsJSONObject( FILTERS );
      }
      query = buildQuery(entityId, filtersJSON);
      statement = getDataSource().createStatement( query );
     
      statement.setParameters( getEnv() );
     
      String jpaQueryStr = statement.getQueryString();
    //  String sqlQuery = statement.getSqlQueryString();
      logger.debug("Executable query (HQL/JPQL): [" +  jpaQueryStr+ "]");
    //  logger.debug("Executable query (SQL): [" + sqlQuery + "]");
     
      start = getAttributeAsInteger( START );
      limit = getAttributeAsInteger( LIMIT );
     
      logger.debug("Parameter [" + ENTITY_ID + "] is equals to [" + entityId + "]");
      logger.debug("Parameter [" + START + "] is equals to [" + start + "]");
      logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]");
     
      Assert.assertNotNull(entityId, "Parameter [" + ENTITY_ID + "] cannot be null" );
   
      try {
        logger.debug("Executing query ...");
        dataSet = QbeDatasetFactory.createDataSet(statement);
        dataSet.setAbortOnOverflow(true);
       
        Map userAttributes = new HashMap();
        UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
        Iterator it = profile.getUserAttributeNames().iterator();
        while(it.hasNext()) {
          String attributeName = (String)it.next();
          Object attributeValue = profile.getUserAttribute(attributeName);
          userAttributes.put(attributeName, attributeValue);
        }
        dataSet.addBinding("attributes", userAttributes);
        dataSet.addBinding("parameters", this.getEnv());
        dataSet.loadData(start, limit, (maxSize == null? -1: maxSize.intValue()));
       
        dataStore = dataSet.getDataStore();
        Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      } catch (Exception e) {
        logger.debug("Query execution aborted because of an internal exceptian");
        SpagoBIEngineServiceException exception;
        String message;
       
        message = "An error occurred in " + getActionName() + " service while executing query: [" +  statement.getQueryString() + "]";       
        exception = new SpagoBIEngineServiceException(getActionName(), message, e);
        exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
        exception.addHint("Check connection configuration");
        exception.addHint("Check the qbe jar file");
       
        throw exception;
      }
      logger.debug("Query executed succesfully");
     
      resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
      Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
      logger.debug("Total records: " + resultNumber);     
     
      //serializer = new DataStoreJSONSerializer();
      //gridDataFeed = (JSONObject)serializer.serialize(dataStore);
     
View Full Code Here

          }else{
            k.setIsAdditive(new Boolean(false));
          }
          if(dsLabel != null){
            k.setDsLabel(dsLabel);
            IDataSet ds = dsDao.loadActiveDataSetByLabel(dsLabel);

            if(ds!=null){
              int dsId = ds.getId();
              k.setKpiDsId(new Integer(dsId));
            }       
          }
          if(thresholdCode != null){
            Threshold t = thrDao.loadThresholdByCode(thresholdCode);
            k.setThreshold(t);
          }

          k.setKpiName(name);
          k.setCode(code);

          if(description != null){
            k.setDescription(description);
          }
          if(weight != null && !weight.equalsIgnoreCase("")){
            k.setStandardWeight(Double.valueOf(weight));
         
          if(dsLabel != null){
            k.setDsLabel(dsLabel);
            IDataSet ds = dsDao.loadActiveDataSetByLabel(dsLabel);

            if(ds!=null){
              int dsId = ds.getId();
              k.setKpiDsId(new Integer(dsId));
            }       
          }
          if(thresholdCode != null){
            Threshold t = thrDao.loadThresholdByCode(thresholdCode);
            k.setThreshold(t);
          }

          List docsList = null;
          if(docLabelsJSON != null){
            docsList = deserializeDocLabelsJSONArray(docLabelsJSON);
            k.setSbiKpiDocuments(docsList);
          }else if(docs!=null && !docs.equalsIgnoreCase("")){
            KpiDocuments d = new KpiDocuments();
            d.setBiObjLabel(docs);
            docsList = new ArrayList();
            docsList.add(d);
            k.setSbiKpiDocuments(docsList);
          }

          if(interpretation != null){
            k.setInterpretation(interpretation);
          }
          if(algdesc != null){
            k.setMetric(algdesc);
          }
          if(inputAttr != null){
            k.setInputAttribute(inputAttr);
          }
          if(modelReference != null){
            k.setModelReference(modelReference);
          }
          if(targetAudience != null){
            k.setTargetAudience(targetAudience);
          }
          if(kpiTypeCd != null){
            k.setKpiTypeCd(kpiTypeCd);
            k.setKpiTypeId(kpiTypeId);
          }
          if(metricScaleCd != null){
            k.setMetricScaleCd(metricScaleCd);
            k.setMetricScaleId(metricScaleId);
          }
          if(measureTypeCd != null){
            k.setMeasureTypeCd(measureTypeCd);
            k.setMeasureTypeId(measureTypeId);
          }   

          // add to Kpi Definition UDP Value list...
          //List udpValues = k.getUdpValues();
          List<UdpValue> udpValues = new ArrayList<UdpValue>()
          for(int i=0; i< udpValuesArrayJSon.length(); i++){
            JSONObject obj = (JSONObject)udpValuesArrayJSon.get(i);
            // only label and value information are retrieved by JSON object
            String label = obj.getString("name")
            String value = obj.getString("value")

            UdpValue udpValue = new UdpValue();

            // reference id is the kpi id
            Integer kpiId = k.getKpiId();

            //udpValue.setLabel(label);
            udpValue.setValue(value);
            udpValue.setReferenceId(kpiId);

            // get the UDP to get ID (otherwise could be taken in js page)
            Udp udp = DAOFactory.getUdpDAO().loadByLabelAndFamily(label, "KPI");
            Domain familyDomain = DAOFactory.getDomainDAO().loadDomainById(udp.getFamilyId());

            Integer idUdp = udp.getUdpId();

            udpValue.setLabel(udp.getLabel());
            udpValue.setName(udp.getName());
            udpValue.setFamily(familyDomain != null ? familyDomain.getValueCd() : null);
            udpValue.setUdpId(udp.getUdpId());

            udpValues.add(udpValue);
          }

          k.setUdpValues(udpValues);


          if(id != null && !id.equals("") && !id.equals("0")){             
            k.setKpiId(Integer.valueOf(id));
            kpiDao.modifyKpi(k);
            logger.debug("threshold "+id+" updated");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", id);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }else{
            Integer kpiID = kpiDao.insertKpi(k);
            logger.debug("New threshold inserted");
            JSONObject attributesResponseSuccessJSON = new JSONObject();
            attributesResponseSuccessJSON.put("success", true);
            attributesResponseSuccessJSON.put("responseText", "Operation succeded");
            attributesResponseSuccessJSON.put("id", kpiID);
            writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
          }

        } catch(EMFUserError e){
          logger.error("EMFUserError");
          e.printStackTrace();
        } catch (JSONException e) {
          logger.error("JSONException");
          e.printStackTrace();
        } catch (IOException e) {
          logger.error("IOException");
          e.printStackTrace();
        }

      }else{
        logger.error("Resource name, code or type are missing");
        throw new SpagoBIServiceException(SERVICE_NAME,  "Please fill threshold name, code and type");
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_DELETE)) {
      Integer id = getAttributeAsInteger(ID);
      try {
        kpiDao.deleteKpi(id);
        logger.debug("Resource deleted");
        writeBackToClient( new JSONAcknowledge("Operation succeded") );
      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving resource to delete", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving resource to delete", e);
      }
    }else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINKS)) {     
      try {
        Integer id =null;
        try{
          id = getAttributeAsInteger(ID);
        }catch (Exception e) {
          logger.debug("No Kpi Instance Id");
        }
        ArrayList <KpiRel> relations = new ArrayList<KpiRel>();
        //looks up for relations
        if(id != null){
          relations = (ArrayList <KpiRel>)kpiDao.loadKpiRelListByParentId(id);
          logger.debug("Kpi relations loaded");
 
          //looks up for dataset parameters       
          IDataSet dataSet = kpiDao.getDsFromKpiId(id);
          if(dataSet != null){
            String parametersString = dataSet.getParameters();
   
            ArrayList<String> parameters = new ArrayList<String>();
            logger.debug("Dataset Parameters loaded");
            if(parametersString != null){
              SourceBean source = SourceBean.fromXMLString(parametersString);
              if(source.getName().equals("PARAMETERSLIST")) {
                List<SourceBean> rows = source.getAttributeAsList("ROWS.ROW");
                for(int i=0; i< rows.size(); i++){
                  SourceBean row = rows.get(i);
                  String name = (String)row.getAttribute("name");
                  parameters.add(name);
                }
              }
              JSONArray paramsJSON = serializeParametersList(parameters, relations);
              JSONObject paramsResponseJSON = createJSONResponseResources(paramsJSON, parameters.size());
              writeBackToClient(new JSONSuccess(paramsResponseJSON));
            }else{
              writeBackToClient(new JSONSuccess(new JSONObject()));
            }
          }else{
            writeBackToClient(new JSONSuccess(new JSONObject()));
          }
        }else{
          writeBackToClient(new JSONSuccess(new JSONObject()));
        }

      } catch (Throwable e) {
        logger.error("Exception occurred while retrieving kpi links", e);
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving kpi links", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(KPI_LINKS_BY_DS)) {     
      try {
        String labelDS = getAttributeAsString("label");
        //looks up for relations
        ArrayList <KpiRel> relations = new ArrayList <KpiRel>();

        //looks up for dataset parameters       
        IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(labelDS);
        String parametersString = dataSet.getParameters();

        ArrayList<String> parameters = new ArrayList<String>();
        logger.debug("Dataset Parameters loaded");
        if(parametersString != null){
          SourceBean source = SourceBean.fromXMLString(parametersString);
View Full Code Here

   
 
  public void doService( EngineStartServletIOManager servletIOManager ) throws SpagoBIEngineException {
   
    IDataSource dataSource;
        IDataSet dataSet;
        String connectionName;
        String outputType;
       
        JasperReportEngineTemplate template;
        JasperReportEngineInstance engineInstance;
 
        logger.debug("IN");
       
        try {
          // log some contextual infos
          logger.debug("User: [" + servletIOManager.getUserId() + "]");
          logger.debug("Document: [" + servletIOManager.getDocumentId() + "]");
         
          dataSource = servletIOManager.getDataSource();
          logger.debug("Datasource: [" + (dataSource == null? dataSource: dataSource.getLabel()) + "]");
          if (dataSource==null){
            logger.warn("This document doesn't have the Data Source");
          }
          
          dataSet = servletIOManager.getDataSet();
          logger.debug("Dataset: [" + (dataSet == null? dataSource: dataSet.getName()) + "]");
         
          // read and log builtin parameters
          connectionName = servletIOManager.getParameterAsString(CONNECTION_NAME);
          logger.debug("Parameter [" + CONNECTION_NAME + "] is equal to [" + connectionName + "]");
         
View Full Code Here

    Map env = null;
   
    env = super.getEnv();
   
    IDataSource dataSource = getDataSource();
    IDataSet dataset = getDataSet();
    if( dataset != null ) {
      dataset.setUserProfileAttributes(UserProfileUtils.getProfileAttributesgetUserProfile() ));
     
      dataset.setParamsMap( env );
    }
   
    env.put(EngineConstants.ENV_DATASOURCE, dataSource);
    env.put(EngineConstants.ENV_DATASET, dataset);
   
View Full Code Here

    Map env = null;
   
    env = super.getEnv();
   
    IDataSource dataSource = getDataSource();
    IDataSet dataset = getDataSet();
    if( dataset != null ) {
      dataset.setUserProfileAttributes(UserProfileUtils.getProfileAttributesgetUserProfile()  ));
     
      dataset.setParamsMap( env );
    }
   
    env.put(EngineConstants.ENV_DATASOURCE, dataSource);
    env.put(EngineConstants.ENV_DATASET, dataset);
   
View Full Code Here

  }
    }


    public IDataSet getDataSetByLabel(String label) {
      IDataSet dataSet = null;
      SpagoBiDataSet dataSetConfig = null;
     
      logger.debug("IN.dataset.label="+label);
     
      if (label==null || label.length()==0){
View Full Code Here

      return dataSet;
    }
   
  
    public IDataSet getDataSet(String documentId) {
      IDataSet dataSet = null;
      SpagoBiDataSet dataSetConfig = null;
     
      logger.debug("IN.documentId="+documentId);
     
      if (documentId==null || documentId.length()==0){
View Full Code Here

            SourceBean tempFileSB = SourceBean.fromXMLString(tempFileStr);
            SourceBean datasetnameSB = (SourceBean) tempFileSB.getFilteredSourceBeanAttribute("CONF.PARAMETER", "name", "confdataset");
            if (datasetnameSB != null) {
              String datasetLabel = (String) datasetnameSB.getAttribute("value");
              IDataSetDAO datasetDao = DAOFactory.getDataSetDAO();
              IDataSet dataset = datasetDao.loadActiveDataSetByLabel(datasetLabel);
              GuiGenericDataSet guiGenericDataSet = datasetDao.loadDataSetByLabel(datasetLabel);



              if (dataset == null) {
View Full Code Here

      if(trasfTypeCd!=null && !trasfTypeCd.equals("")){
        dsActiveDetail = setTransformer(dsActiveDetail, trasfTypeCd);
      }
     
      IDataSet ds = null;   
      try {
        if ( dsType!=null && !dsType.equals("")) {
         
          ds = instantiateCorrectIDataSetType(dsType);   
          if(ds!=null){                 
View Full Code Here

TOP

Related Classes of it.eng.spagobi.tools.dataset.bo.IDataSet

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.