Package it.eng.spagobi.engines.qbe.analysisstateloaders

Source Code of it.eng.spagobi.engines.qbe.analysisstateloaders.Version0QbeEngineAnalysisStateLoader

/**

SpagoBI - The Business Intelligence Free Platform

Copyright (C) 2005-2009 Engineering Ingegneria Informatica S.p.A.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

**/
package it.eng.spagobi.engines.qbe.analysisstateloaders;

import it.eng.qbe.query.catalogue.QueryCatalogue;
import it.eng.spagobi.utilities.engines.SpagoBIEngineRuntimeException;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

/**
* @author Andrea Gioia (andrea.gioia@eng.it)
*/
public class Version0QbeEngineAnalysisStateLoader extends AbstractQbeEngineAnalysisStateLoader{

  public final static String FROM_VERSION = "0";
    public final static String TO_VERSION = "1";
   
  /** Logger component. */
    private static transient Logger logger = Logger.getLogger(Version0QbeEngineAnalysisStateLoader.class);
 
    public Version0QbeEngineAnalysisStateLoader() {
      super();
    }
   
    public Version0QbeEngineAnalysisStateLoader(IQbeEngineAnalysisStateLoader loader) {
      super(loader);
    }
   
  public JSONObject convert(JSONObject data) {
    JSONObject resultJSON;
    JSONObject catalogueJSON;
    JSONArray queriesJSON;
    JSONObject queryJSON;
    JSONArray filtersJSON;
    JSONObject filterJSON;
    // just to create well formed id for loaded queries
    QueryCatalogue catalogue;
   
    logger.debug("IN");
   
    resultJSON = new JSONObject();
    catalogueJSON = new JSONObject();
    queriesJSON = new JSONArray();
    try {
      logger.debug( "Converting from encoding version [" + FROM_VERSION + "] to encoding version [" + TO_VERSION + "] ..." );
     
      queryJSON = data;
      // fix query encoding ...
      catalogue = new QueryCatalogue();
      String queryId = catalogue.getNextValidId();
      queryJSON.put( "id",  queryId);
      queryJSON.put( "name", "query_" + queryId );
      queryJSON.put("description", "query_" + queryId );
      queryJSON.put( "distinct", false );
      queryJSON.put( "subqueries", new JSONArray() );
     
      filtersJSON = queryJSON.getJSONArray("filters");
      for(int i = 0; i < filtersJSON.length(); i++) {
        filterJSON = filtersJSON.getJSONObject(i);
        filterJSON.put("isfree", false);
        filterJSON.put("defaultvalue", "");
        filterJSON.put("lastvalue", "");
      }
           
      queriesJSON.put(queryJSON);
      catalogueJSON.put("queries", queriesJSON);
      resultJSON.put("catalogue", catalogueJSON);
      logger.debug( "Conversion from encoding version [" + FROM_VERSION + "] to encoding version [" + TO_VERSION + "] terminated succesfully" );
    }catch(Throwable t) {
      throw new SpagoBIEngineRuntimeException("Impossible to load from rowData [" + data + "]", t);
    } finally {
      logger.debug("OUT");
    }
   
    return resultJSON;
  }

}
TOP

Related Classes of it.eng.spagobi.engines.qbe.analysisstateloaders.Version0QbeEngineAnalysisStateLoader

TOP
Copyright © 2018 www.massapi.com. 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.