-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from metamug/develop
Develop
- Loading branch information
Showing
15 changed files
with
882 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 53 additions & 59 deletions
112
src/main/java/com/metamug/mason/entity/response/DatasetOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,53 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.metamug.mason.entity.response; | ||
|
||
import java.util.Map; | ||
import java.util.SortedMap; | ||
import javax.xml.bind.JAXBException; | ||
import org.apache.taglibs.standard.tag.common.sql.ResultImpl; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Dataset JSON output object | ||
*/ | ||
public class DatasetOutput extends JSONOutput { | ||
|
||
public static final String COLUMNS = "columns"; | ||
public static final String DATASET = "dataset"; | ||
|
||
public DatasetOutput(Map<String, Object> outputMap) throws JAXBException { | ||
super(outputMap); | ||
} | ||
|
||
@Override | ||
protected Object getJson(ResultImpl impl) { | ||
return resultSetToDataSet(impl); | ||
} | ||
|
||
private JSONObject resultSetToDataSet(ResultImpl resultImpl) { | ||
SortedMap[] rows = resultImpl.getRows(); | ||
String[] columnNames = resultImpl.getColumnNames(); | ||
JSONObject object = new JSONObject(); | ||
JSONArray columnArray = new JSONArray(); | ||
for (int i = 0; i < columnNames.length; i++) { | ||
String columnName = columnNames[i].isEmpty() || columnNames[i].equalsIgnoreCase("null") ? "col" + i : columnNames[i]; | ||
columnArray.put(columnName); | ||
} | ||
object.put(COLUMNS, columnArray); | ||
JSONArray dataSetArray = new JSONArray(); | ||
for (SortedMap row : rows) { | ||
JSONArray rowArray = new JSONArray(); | ||
for (int i = 0; i < columnNames.length; i++) { | ||
String columnName = columnNames[i].isEmpty() || columnNames[i].equalsIgnoreCase("null") ? "col" + i : columnNames[i]; | ||
rowArray.put((row.get(columnName) != null) ? row.get(columnName) : "null"); | ||
} | ||
dataSetArray.put(rowArray); | ||
} | ||
object.put(DATASET, dataSetArray); | ||
return object; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return HEADER_DATASET; | ||
} | ||
} | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.metamug.mason.entity.response; | ||
|
||
import java.util.SortedMap; | ||
import org.apache.taglibs.standard.tag.common.sql.ResultImpl; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Dataset JSON output object | ||
*/ | ||
public class DatasetOutput extends JSONOutput { | ||
|
||
public static final String COLUMNS = "columns"; | ||
public static final String DATASET = "dataset"; | ||
|
||
@Override | ||
protected Object getJson(ResultImpl impl) { | ||
return resultSetToDataSet(impl); | ||
} | ||
|
||
private JSONObject resultSetToDataSet(ResultImpl resultImpl) { | ||
SortedMap[] rows = resultImpl.getRows(); | ||
String[] columnNames = resultImpl.getColumnNames(); | ||
JSONObject object = new JSONObject(); | ||
JSONArray columnArray = new JSONArray(); | ||
for (int i = 0; i < columnNames.length; i++) { | ||
String columnName = columnNames[i].isEmpty() || columnNames[i].equalsIgnoreCase("null") ? "col" + i : columnNames[i]; | ||
columnArray.put(columnName); | ||
} | ||
object.put(COLUMNS, columnArray); | ||
JSONArray dataSetArray = new JSONArray(); | ||
for (SortedMap row : rows) { | ||
JSONArray rowArray = new JSONArray(); | ||
for (int i = 0; i < columnNames.length; i++) { | ||
String columnName = columnNames[i].isEmpty() || columnNames[i].equalsIgnoreCase("null") ? "col" + i : columnNames[i]; | ||
rowArray.put((row.get(columnName) != null) ? row.get(columnName) : "null"); | ||
} | ||
dataSetArray.put(rowArray); | ||
} | ||
object.put(DATASET, dataSetArray); | ||
return object; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return HEADER_DATASET; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.