Commit 498e6f2b authored by pborate's avatar pborate

Updated common dashboard jar classes

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@182228 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b7306dc2
package ibase.dashboard.common.hibernate.bean;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
import org.json.JSONException;
import org.json.JSONObject;
import ibase.dashboard.common.hibernate.utility.HibernateUtil;
@Indexed
@Entity
@Table(name = "Pophelp")
@XmlRootElement(name = "System")
public class Pophelp implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column(name="FIELD_NAME")
@Field(store = Store.YES, analyze = Analyze.NO)
private String fieldName;
@Id
@Column(name="MOD_NAME")
private String modName;
@Column(name="SQL_INPUT")
private String sqlInput;
@Column(name="MULTI_OPT")
private Integer multiOpt;
@Column(name="AUTO_FILL_LEN")
private String autoFillLen;
@Column(name="DATA_MODEL_NAME")
private String dataModelName;
@Column(name="THUMB_OBJ")
private String thumbObj;
@Column(name="THUMB_IMAGE_COL")
private String thumbImageCol;
@Column(name="THUMB_ALT_COL")
private String thumbAltCol;
@Column(name="DIST_OPT")
private String distOpt;
@Column(name="FILTER_STRING")
private String filterString;
@Column(name="DEFAULT_COL")
private Integer defaultCol;
@Column(name="OBJ_NAME__DS")
private String objNameDs;
@Column(name="VALIDATE_DATA")
private String validateData;
@Column(name="ITEM_CHANGE")
private String itemChange;
@Column(name="HELP_OPTION")
private String helpOption;
public Pophelp() {
}
public Pophelp(String fieldName, String modName, String sqlInput, Integer multiOpt, String autoFillLen, String dataModelName,
String distOpt, String filterString, Integer defaultCol, String thumbObj, String thumbImageCol,
String thumbAltCol, String objNameDs, String validateData, String itemChange, String helpOption) {
super();
this.fieldName = fieldName;
this.modName = modName;
this.sqlInput = sqlInput;
this.multiOpt = multiOpt;
this.autoFillLen = autoFillLen;
this.dataModelName = dataModelName;
this.distOpt = distOpt;
this.filterString = filterString;
this.defaultCol = defaultCol;
this.thumbObj = thumbObj;
this.thumbImageCol = thumbImageCol;
this.thumbAltCol = thumbAltCol;
this.objNameDs = objNameDs;
this.validateData = validateData;
this.itemChange = itemChange;
this.helpOption=helpOption;
}
public String getHelpOption() {
return helpOption;
}
public void setHelpOption(String helpOption) {
this.helpOption = helpOption;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getModName() {
return modName;
}
public void setModName(String modName) {
this.modName = modName;
}
public String getSqlInput() {
return sqlInput;
}
public void setSqlInput(String sqlInput) {
this.sqlInput = sqlInput;
}
public Integer getMultiOpt() {
return multiOpt;
}
public void setMultiOpt(Integer multiOpt) {
this.multiOpt = multiOpt;
}
public String getAutoFillLen() {
return autoFillLen;
}
public void setAutoFillLen(String autoFillLen) {
this.autoFillLen = autoFillLen;
}
public String getDataModelName() {
return dataModelName;
}
public void setDataModelName(String dataModelName) {
this.dataModelName = dataModelName;
}
public String getDistOpt() {
return distOpt;
}
public void setDistOpt(String distOpt) {
this.distOpt = distOpt;
}
public String getFilterString() {
return filterString;
}
public void setFilterString(String filterString) {
this.filterString = filterString;
}
public Integer getDefaultCol() {
return defaultCol;
}
public void setDefaultCol(Integer defaultCol) {
this.defaultCol = defaultCol;
}
public String getThumbObj() {
return thumbObj;
}
public void setThumbObj(String thumbObj) {
this.thumbObj = thumbObj;
}
public String getThumbImageCol() {
return thumbImageCol;
}
public void setThumbImageCol(String thumbImageCol) {
this.thumbImageCol = thumbImageCol;
}
public String getThumbAltCol() {
return thumbAltCol;
}
public void setThumbAltCol(String thumbAltCol) {
this.thumbAltCol = thumbAltCol;
}
public String getObjNameDs() {
return objNameDs;
}
public void setObjNameDs(String objNameDs) {
this.objNameDs = objNameDs;
}
public String getValidateData() {
return validateData;
}
public void setValidateData(String validateData) {
this.validateData = validateData;
}
public String getItemChange() {
return itemChange;
}
public void setItemChange(String itemChange) {
this.itemChange = itemChange;
}
@Override
public String toString(){
return "\n Pophelp.toString >> [" + new JSONObject(this).toString() + "]";
}
}
package ibase.dashboard.common.hibernate.dao;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.dashboard.common.hibernate.bean.Employee;
import ibase.dashboard.common.hibernate.bean.Pophelp;
import ibase.dashboard.common.hibernate.utility.HibernateUtil;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import javassist.bytecode.Descriptor.Iterator;
public class DashboardUtil
{
public JSONArray getDashboardConfig(String dashboardFileName)
{
//JSONObject dashboardConfig = new JSONObject();
JSONArray dashboardConfigFinal = new JSONArray();
try
{
CommonConstants.setIBASEHOME();
System.out.println("Inside getDashboardConfig :: CommonConstants.JBOSSHOME ["+CommonConstants.JBOSSHOME+"]");
System.out.println("Final File Path =" + dashboardFileName);
File dashboardFile = new File( dashboardFileName );
String dashboardFileContents = FileUtils.readFileToString(dashboardFile);
System.out.println("dashboardFileContents =" + dashboardFileContents);
dashboardConfigFinal = processMetadataXML(dashboardFileContents);
}
catch (IOException e)
{
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("The final dashboard config" + dashboardConfigFinal);
return dashboardConfigFinal;
}
private JSONArray processMetadataXML(String dashboardFileContents)
{
JSONObject dashboardConfig = new JSONObject();
JSONArray dashboardConfig1 = new JSONArray();
try
{
E12GenericUtility utility = new E12GenericUtility();
Document dashboardDom = utility.parseString(dashboardFileContents);
NodeList rootNodeList = dashboardDom.getElementsByTagName("Root");
Node rootNode = null;
if( rootNodeList != null && rootNodeList.getLength() > 0 ){
rootNode = rootNodeList.item(0);
dashboardConfig = (JSONObject) xmlToJson(rootNode);
}
System.out.println("dashboardConfig xml>>" + dashboardConfig);
dashboardConfig1 = processDashboardMetadata(dashboardConfig);
System.out.println("dashboardConfig>>" + dashboardConfig1);
}
catch(Exception e){
}
return dashboardConfig1;
}
private JSONArray processDashboardMetadata(JSONObject dashboardConfig) throws JSONException
{
JSONArray popHelp = new JSONArray();
try
{
JSONObject popHelpFunction = new JSONObject();
JSONObject view =dashboardConfig.optJSONObject("view");
JSONArray viewArray =new JSONArray();
if(view != null)
{
System.out.println("view in if === "+view);
JSONArray componentDataNewArray = new JSONArray();
JSONObject componentData = view.optJSONObject("component");
if(componentData != null) {
componentData = getColumnsData(componentData);
componentDataNewArray.put(componentData);
}
else {
JSONArray componentDataArray = view.optJSONArray("component");
for(int i = 0, size = componentDataArray.length(); i < size; i++) {
componentData = getColumnsData(componentDataArray.optJSONObject(i));
componentDataNewArray.put(componentData);
}
}
view.put("component", componentDataNewArray);
viewArray.put(view);
}
else
{
//System.out.println("view in else === "+view);
JSONArray viewDataArray = dashboardConfig.optJSONArray("view");
//System.out.println("viewDataArray in else === "+viewDataArray);
for(int i = 0, viewsize = viewDataArray.length(); i < viewsize; i++) {
JSONArray componentDataNewArray = new JSONArray();
JSONObject viewData = viewDataArray.optJSONObject(i);
System.out.println("viewData::::::: "+i+">>>"+viewData);
JSONObject componentData = viewData.optJSONObject("component");
if(componentData != null) {
//System.out.println("viewDataArray in else if === "+componentData);
componentData = getColumnsData(componentData);
//System.out.println("viewDataArray in else if>>>>> === "+viewDataArray);
componentDataNewArray.put(componentData);
}
else {
//System.out.println("viewDataArray in else for === "+viewDataArray);
JSONArray componentDataArray = componentData.optJSONArray("component");
for(int j = 0, size = componentDataArray.length(); j < size; j++) {
componentData = getColumnsData(componentDataArray.optJSONObject(j));
componentDataNewArray.put(componentData);
}
}
//System.out.println("componentDataNewArray in else if>>>>> === "+componentDataNewArray);
viewData.put("component", componentDataNewArray);
viewArray.put(viewData);
}
}
System.out.println("viewArray in else if>>>>> === "+viewArray);
popHelpFunction.put("view", viewArray);
System.out.println("popHelpFunction type === "+popHelpFunction);
String page_title= dashboardConfig.getString("page_title");
System.out.println("page_title ::::"+page_title);
if(page_title.length()>0)
{
popHelpFunction.put("page_title", page_title);
}
Object datasourceVal=dashboardConfig.get("datasource");
System.out.println("datasourceVal ::::"+datasourceVal);
if(datasourceVal instanceof JSONArray) {
JSONArray datasource=new JSONArray();
datasource= dashboardConfig.optJSONArray("datasource");
System.out.println("datasource ::::["+datasource+"] datasource length ["+datasource.length()+"]");
popHelpFunction.put("datasource", datasource);
}
else {
JSONObject datasourceObj= dashboardConfig.optJSONObject("datasource");
System.out.println("datasourceObj ::::"+datasourceObj);
popHelpFunction.put("datasource", datasourceObj);
}
if(dashboardConfig.has("filters")) {
JSONObject filters= dashboardConfig.getJSONObject("filters");
System.out.println("filters ::::"+filters);
popHelpFunction=preapareFilterData(filters,popHelpFunction);
}
popHelp.put(popHelpFunction);
}
catch (Exception e) {
System.out.println("Exception"+e);
}
return popHelp;
//return dashboardConfig;
}
public JSONObject getColumnsData(JSONObject componentData) throws JSONException{
JSONObject finalDataObj = new JSONObject();
JSONArray finalDataArray = new JSONArray();
System.out.println("componentData>>>>>>>>>"+componentData + "\n");
JSONObject componentDescr=componentData.optJSONObject("component_descr");
finalDataObj.put("component_descr", componentDescr);
String type=componentData.optString("type");
finalDataObj.put("type", type);
String ComponentTitle=componentData.optString("ComponentTitle");
finalDataObj.put("ComponentTitle", ComponentTitle);
JSONObject componentCaption=componentData.optJSONObject("component_caption");
finalDataObj.put("component_caption", componentCaption);
JSONObject layout=componentData.optJSONObject("layout");
finalDataObj.put("layout", layout);
String componentType=componentData.optString("component_type");
finalDataObj.put("component_type", componentType);
if(componentType.equalsIgnoreCase("pivot-grid")) {
JSONObject pivotTableData=new JSONObject();
pivotTableData=getPivotTableData(componentData);
finalDataObj.put("slice", pivotTableData);
}
String componentIcon=componentData.optString("component_icon");
finalDataObj.put("component_icon", componentIcon);
String datasource=componentData.optString("datasource");
finalDataObj.put("datasource", datasource);
String componentName=componentData.optString("ComponentName");
finalDataObj.put("ComponentName", componentName);
String componentCss=componentData.optString("component_css");
finalDataObj.put("component_css", componentCss);
String idCol=componentData.optString("id");
finalDataObj.put("id", idCol);
System.out.println("finalDataObj before>>>>>>"+finalDataObj);
JSONArray columnGroup=componentData.optJSONArray("column_group");
//System.out.println("columnGroup:"+columnGroup + "\n");
if(columnGroup !=null) {
for(int i = 0, size = columnGroup.length(); i < size; i++) {
System.out.println("size>>>>>>>>>"+size + "\n");
JSONObject finalData = new JSONObject();
//System.out.println("filter>>>>>>"+columnGroup);
JSONObject columsObj= columnGroup.optJSONObject(i);
System.out.println("filter>>>>>>"+columsObj);
if(columsObj.optJSONArray("columns") instanceof JSONArray) {
JSONArray columsArray=columsObj.optJSONArray("columns");
System.out.println("columsArray>>>>>>"+columsArray);
}
else {
JSONObject columsArray=columsObj.optJSONObject("columns");
System.out.println("columsArray>>>>>>else"+columsArray);
JSONObject columArray=columsArray.optJSONObject("column");
System.out.println("columArray>>>>>>"+columArray);
if(columArray != null) {
String id=columArray.optString("id");
String value=columArray.optString("value");
finalData.put("uniqueName", id);
finalData.put("caption", value);
}
System.out.println("finalData>>>>>>"+finalData);
finalDataArray.put(finalData);
System.out.println("finalDataArray::::::::"+finalDataArray);
}
finalDataObj.put("columns", finalDataArray);
}
}
System.out.println("finalDataObj::::::::"+finalDataObj);
// finalDataObj=getPivotTableData(componentData);
return finalDataObj;
}
private JSONObject getPivotTableData(JSONObject dashboardConfig) throws JSONException {
System.out.println("INSIDE getPivotTableData ");
JSONObject finalDataObj1 = new JSONObject();
JSONObject finalDataObj = new JSONObject();
JSONObject pivotRowObj=new JSONObject();
JSONArray pivotRowArray= new JSONArray();
pivotRowObj=dashboardConfig.optJSONObject("pivotrows");
JSONArray pivotRowColArray=pivotRowObj.optJSONArray("column");
JSONObject pivotRowColObj=pivotRowObj.optJSONObject("column");
if(pivotRowColArray !=null) {
for(int i = 0, size = pivotRowColArray.length(); i < size; i++) {
JSONObject pivotRowData = pivotRowColArray.getJSONObject(i);
//System.out.println("pivotRowFinalData"+pivotRowData);
JSONObject pivotRowFinalData =new JSONObject();
pivotRowFinalData.put("uniqueName", pivotRowData.get("dataField"));
pivotRowFinalData.put("caption", pivotRowData.get("text"));
pivotRowArray.put(pivotRowFinalData);
}
}
else {
JSONObject pivotRowFinalData =new JSONObject();
pivotRowFinalData.put("uniqueName", pivotRowColObj.get("dataField"));
pivotRowFinalData.put("caption", pivotRowColObj.get("text"));
pivotRowArray.put(pivotRowFinalData);
}
finalDataObj.put("rows", pivotRowArray);
//System.out.println("finalDataObj after rows"+finalDataObj);
//FOR pivotColumns
JSONObject pivotColObj=new JSONObject();
JSONArray pivotColArray= new JSONArray();
pivotColObj=dashboardConfig.optJSONObject("pivotcolumns");
JSONArray pivotColParArray=pivotColObj.optJSONArray("column");
JSONObject pivotColParObj=pivotColObj.optJSONObject("column");
if(pivotColParArray !=null) {
for(int i = 0, size = pivotColParArray.length(); i < size; i++) {
JSONObject pivotColData = pivotRowColArray.getJSONObject(i);
// System.out.println("pivotColData"+pivotColData);
JSONObject pivotColFinalData =new JSONObject();
pivotColFinalData.put("uniqueName", pivotColData.get("dataField"));
pivotColFinalData.put("caption", pivotColData.get("text"));
pivotColArray.put(pivotColFinalData);
}
// System.out.println("pivotColArray"+pivotColArray);
}
else {
JSONObject pivotColFinalData =new JSONObject();
pivotColFinalData.put("uniqueName", pivotColParObj.get("dataField"));
pivotColFinalData.put("caption", pivotColParObj.get("text"));
pivotColArray.put(pivotColFinalData);
}
finalDataObj.put("columns", pivotColArray);
// System.out.println("finalDataObj after columns"+finalDataObj);
//FOR pivot pivotvalues
JSONObject pivotValueObj=new JSONObject();
JSONArray pivotValueArray= new JSONArray();
pivotValueObj=dashboardConfig.optJSONObject("pivotvalues");
JSONArray pivotValArray=pivotValueObj.optJSONArray("column");
JSONObject pivotValObj=pivotValueObj.optJSONObject("column");
if(pivotValArray !=null) {
for(int i = 0, size = pivotValArray.length(); i < size; i++) {
JSONObject pivotVALData = pivotValArray.getJSONObject(i);
//System.out.println("pivotColData"+pivotVALData);
JSONObject pivotValFinalData =new JSONObject();
pivotValFinalData.put("uniqueName", pivotVALData.get("dataField"));
pivotValFinalData.put("aggregation", pivotVALData.get("pivotfunction"));
pivotValueArray.put(pivotValFinalData);
}
//System.out.println("pivotValueArray"+pivotValueArray);
}
else {
JSONObject pivotValFinalData =new JSONObject();
pivotValFinalData.put("uniqueName", pivotValObj.get("text"));
pivotValFinalData.put("aggregation", pivotValObj.get("pivotfunction"));
pivotValueArray.put(pivotValFinalData);
}
finalDataObj.put("measures", pivotValueArray);
//finalDataObj1.put("slice", finalDataObj);
System.out.println("component type pivot-grid column:::: "+finalDataObj);
return finalDataObj;
}
private JSONObject preapareFilterData(JSONObject filters,JSONObject popHelpFunction) throws JSONException{
try
{
Object filterData=filters.get("filter");
JSONArray filter= filters.optJSONArray("filter");
JSONArray filterTemp=filter;
if(filterData instanceof JSONArray)
{
filter =new JSONArray();
List<String> systemOption = new ArrayList<String>();
for(int i = 0, size = filterTemp.length(); i < size; i++){
System.out.println("filter>>>>>>"+filterTemp);
JSONObject fil= filterTemp.getJSONObject(i);
String colName=fil.optString("col_name");
String modName=fil.optString("mod_name");
String type=fil.optString("type");
System.out.println("Inside type processDashboardFilter>>>>>>"+type);
JSONObject popHelpData = new JSONObject();
if(type.equalsIgnoreCase("1")) {
System.out.println("Inside if processDashboardFilter::::");
popHelpData=processPophelpData(colName, modName);
}
else {
popHelpData.put("is_pophelp", false);
}
popHelpData.put("type", checkNull(fil.optString("type")));
popHelpData.put("col_id", checkNull(fil.optString("col_id")));
popHelpData.put("col_descr", checkNull(fil.optString("col_descr")));
popHelpData.put("default_value", checkNull(fil.optString("default_value")));
popHelpData.put("col_name", checkNull(colName));
popHelpData.put("show_ontitle", checkNull(fil.optString("show_ontitle")));
popHelpData.put("mandatory", checkNull(fil.optString("mandatory")));
popHelpData.put("key_string", checkNull(fil.optString("key_string")));
System.out.println("processDashboardFilter ::::"+popHelpData);
filter.put( popHelpData);
System.out.println("filter ::::"+filter);
}
filters.put("filter", filter);
popHelpFunction.put("filters", filters);
System.out.println("popHelpFunction ::::"+popHelpFunction);
//System.out.println("popHelp ::::"+popHelpFunction);
}
else {
JSONObject filterObj= filters.optJSONObject("filter");
System.out.println("filter JSONObject>>>>>>"+filterObj);
String colName=filterObj.optString("col_name");
String modName=filterObj.optString("mod_name");
String type=filterObj.optString("type");
System.out.println("Inside type processDashboardFilter>>>>>>"+type);
JSONObject popHelpData = new JSONObject();
if(type.equalsIgnoreCase("1")) {
System.out.println("Inside if processDashboardFilter::::");
popHelpData=processPophelpData(colName, modName);
}
else {
popHelpData.put("is_pophelp", false);
}
popHelpData.put("type", checkNull(filterObj.optString("type")));
popHelpData.put("col_id", checkNull(filterObj.optString("col_id")));
popHelpData.put("col_descr", checkNull(filterObj.optString("col_descr")));
popHelpData.put("default_value", checkNull(filterObj.optString("default_value")));
popHelpData.put("col_name", checkNull(colName));
popHelpData.put("show_ontitle", checkNull(filterObj.optString("show_ontitle")));
popHelpData.put("mandatory", checkNull(filterObj.optString("mandatory")));
popHelpData.put("key_string", checkNull(filterObj.optString("key_string")));
System.out.println("processDashboardFilter else ::::"+popHelpData);
filter =new JSONArray();
filter.put(popHelpData);
System.out.println("filter ::::"+filter);
filters.put("filter", filter);
popHelpFunction.put("filters", filters);
System.out.println("popHelpFunction ::::"+popHelpFunction);
}
}
catch (Exception e) {
System.out.println("Exception"+e);
}
return popHelpFunction;
}
private JSONObject processPophelpData(String colName , String modName ) throws JSONException {
Pophelp pophelpData = fetchAllPophelpData(colName, modName );
System.out.println("pophelpList:::: processPophelpData"+pophelpData);
JSONObject pophelpConfig = new JSONObject();
if(pophelpData !=null) {
pophelpConfig.put("is_pophelp", true);
pophelpConfig.put("auto_fil_len", checkNull(pophelpData.getAutoFillLen()));
pophelpConfig.put("help_option", checkNull(pophelpData.getHelpOption()));
pophelpConfig.put("multi_option", checkNullInt(pophelpData.getMultiOpt()));
}
else {
pophelpConfig.put("is_pophelp", false);
}
System.out.println("is_pophelp:::: processPophelpData"+pophelpConfig);
return pophelpConfig;
}
private Pophelp fetchAllPophelpData(String colName , String modName )
{
Pophelp systemOption = null;
try
{
// 1. Get Session object
Session session = HibernateUtil.getSessionFactory().openSession();
System.out.println("fetchAllPophelpData fieldName ["+colName+"] modName ["+modName+"]");
// 2. Create Query
Query query = session.createQuery("from Pophelp WHERE fieldName='"+colName+"' and"
+ " modName ='"+modName+"'");
System.out.println("Inside fetchAllPophelpData query: [" + query + "]");
List<Pophelp> pophelpDataList = query.getResultList();
System.out.println("fetchAllPophelpData [" + pophelpDataList + "]");
if( pophelpDataList != null && pophelpDataList.size() > 0 )
{
systemOption = pophelpDataList.get(0);
}
System.out.println("fetchAllPophelpData System selected [" + systemOption + "]");
session.close();
}
catch (HibernateException e)
{
System.out.println("fetchAllSites HibernateException :");
System.out.println(e.getMessage());
}
return systemOption;
}
public Object xmlToJson(Node xmlObj) throws JSONException
{
// Create the return object
JSONObject jsonObj = new JSONObject();
// console.log('xmlObj.nodeType---', xmlObj.nodeType, xmlObj);
if (xmlObj.getNodeType() == Node.ELEMENT_NODE) { // element
// do attributes
if (xmlObj.hasAttributes()) {
NamedNodeMap attributes = xmlObj.getAttributes();
int attribLen = attributes.getLength();
for (int j = 0; j < attribLen; j++) {
Node attribute = attributes.item(j);
String name = attribute.getNodeName();
String value = attribute.getNodeValue();
jsonObj.put(name, value);
}
}
}
//System.out.println("jsonObj>>" + jsonObj);
// do children
if (xmlObj.hasChildNodes()) {
NodeList childNodes = xmlObj.getChildNodes();
int childNodeLen = childNodes.getLength();
for (int i = 0; i < childNodeLen; i++)
{
Node childNode = childNodes.item(i);
String childNodeName = childNode.getNodeName();
String childNodeValue = childNode.getNodeValue();
if("#cdata-section".equalsIgnoreCase(childNodeName) )
{
if (xmlObj.hasAttributes())
{
jsonObj.put("value", childNodeValue);
return jsonObj;
}
else
{
return childNodeValue;
}
}
else if( !"#text".equalsIgnoreCase(childNodeName) )
{
System.out.println(childNodeName + "<<childNodeValue>>" + childNodeValue);
if( jsonObj.optJSONObject(childNodeName) != null )
{
JSONObject old = jsonObj.optJSONObject(childNodeName);
jsonObj.put(childNodeName, new JSONArray());
jsonObj.optJSONArray(childNodeName).put(old);
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else if( jsonObj.optJSONArray(childNodeName) != null )
{
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else
{
jsonObj.put(childNodeName, xmlToJson(childNode));
}
}
}
}
//System.out.println(xmlObj.getNodeName() + ">>childNodeName>" + jsonObj);
return jsonObj;
}
private String checkNull(String str)
{
if(str == null)
{
return "NA";
}
else
{
return str ;
}
}
private int checkNullInt(int str)
{
System.out.println("checknull int"+str);
if(str == 0)
{
return 0;
}
else
{
return str ;
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- Datasource for Hibernate Connection -->
<property name="hibernate.connection.datasource">java:/OracleDS</property>
<property name="hibernate.cache.use_query_cache">false</property>
<!-- Echo all executed SQL to sysout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
<!-- Map Entity Class -->
<mapping class="ibase.dashboard.common.hibernate.bean.LoginTrace"></mapping>
<mapping class="ibase.dashboard.common.hibernate.bean.Employee"></mapping>
<mapping class="ibase.dashboard.common.hibernate.bean.UserProfile"></mapping>
<mapping class="ibase.dashboard.common.hibernate.bean.UserDevice"></mapping>
</session-factory>
</hibernate-configuration>
package ibase.dashboard.common.webService;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.json.JSONArray;
//import com.sun.corba.se.impl.javax.rmi.CORBA.Util;
import ibase.dashboard.common.hibernate.dao.DashboardUtil;
import ibase.utility.CommonConstants;
@Path("/dashboard")
public class DashboardService {
@Context
HttpServletRequest request; // The proxy of Request will be injected into this singleton
@GET
@Path("/metadata/{dashboardFileName}")
@Produces(MediaType.APPLICATION_JSON)
public String getDashboardMetadata( @PathParam("dashboardFileName") String dashboardFileName ) throws Exception
{
System.out.println("getDashboardMetadata ["+CommonConstants.JBOSSHOME+"] dashboardFileName[" + dashboardFileName + "] ");
String dashboardMetadataFilePath = CommonConstants.JBOSSHOME + File.separator + "server" + File.separator + "default" + File.separator + "deploy" + File.separator + "ibase.ear" + File.separator + "ibase.war" + File.separator + "dashboard" + File.separator + "metadataxml" + File.separator +dashboardFileName+".xml";
System.out.println("Final File Path =" + dashboardMetadataFilePath);
DashboardUtil util = new DashboardUtil();
JSONArray dashboardMetadata = util.getDashboardConfig(dashboardMetadataFilePath);
return dashboardMetadata.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment