diff --git a/knowagecockpitengine/src/main/java/it/eng/spagobi/engine/chart/util/DataSetTransformer.java b/knowagecockpitengine/src/main/java/it/eng/spagobi/engine/chart/util/DataSetTransformer.java index a2219ec958e..5f21a2cb2ee 100644 --- a/knowagecockpitengine/src/main/java/it/eng/spagobi/engine/chart/util/DataSetTransformer.java +++ b/knowagecockpitengine/src/main/java/it/eng/spagobi/engine/chart/util/DataSetTransformer.java @@ -36,7 +36,8 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.text.StringEscapeUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -48,28 +49,23 @@ public class DataSetTransformer { - private static final String COLUMN = "column"; + private static final Logger LOGGER = LogManager.getLogger(DataSetTransformer.class); - public static transient Logger logger = Logger.getLogger(DataSetTransformer.class); + private static final String COLUMN = "column"; public void print(Object object) { - System.out.println("-----------------------"); - System.out.println(object); - if (object != null) - System.out.println(object.getClass().toString()); - System.out.println("-----------------------"); - - logger.debug("-----------------------"); - logger.debug(object); - if (object != null) - logger.debug(object.getClass().toString()); - logger.debug("-----------------------"); + LOGGER.debug("-----------------------"); + LOGGER.debug(object); + if (object != null) { + LOGGER.debug(object.getClass().toString()); + } + LOGGER.debug("-----------------------"); } - public JSONArray toWordcloud(Object columnsNeeded, Object dataColumnsMapper, List dataRows, Object serie, Object sizeCriteria, - Object groupingFunction) throws JSONException { + public JSONArray toWordcloud(Object columnsNeeded, Object dataColumnsMapper, List dataRows, Object serie, + Object sizeCriteria, Object groupingFunction) throws JSONException { Map mapper = (Map) dataColumnsMapper; @@ -103,29 +99,29 @@ public JSONArray toWordcloud(Object columnsNeeded, Object dataColumnsMapper, Lis for (int i = 0; i < dataRows.size(); i++) { Map row = (Map) dataRows.get(i); - HashMap record = new HashMap<>(); + HashMap currRecord = new HashMap<>(); /* For every record take these columns */ for (int j = 0; j < listColumns.size(); j++) { Object x = row.get(listColumns.get(j)); - record.put(columns.get(j).toString(), x.toString()); + currRecord.put(columns.get(j).toString(), x.toString()); } if (categoryIdColumn != null) { - record.put("category_id_value", row.get(categoryIdColumn).toString()); + currRecord.put("category_id_value", row.get(categoryIdColumn).toString()); } if (serie != null) { - record.put(serie.toString(), row.get(serieRawColumn).toString()); + currRecord.put(serie.toString(), row.get(serieRawColumn).toString()); // Added for the purposes of the cross-navigation execution. // (author: danristo) - record.put("seriesItemName", serie.toString()); + currRecord.put("seriesItemName", serie.toString()); } - result.put(new Integer(i), record); + result.put(i, currRecord); } JSONArray res = toWordcloudArray(columns, serie, result, sizeCriteria); @@ -134,7 +130,8 @@ public JSONArray toWordcloud(Object columnsNeeded, Object dataColumnsMapper, Lis } - private JSONArray toWordcloudArray(Map columns, Object serie, HashMap result, Object sizeCriteria) throws JSONException { + private JSONArray toWordcloudArray(Map columns, Object serie, HashMap result, + Object sizeCriteria) throws JSONException { JSONArray fr = new JSONArray(); @@ -166,7 +163,8 @@ private JSONArray toWordcloudArray(Map columns, Object serie, Ha } valueMap.put(categoryName, value); res.put(name, valueMap); - categoryToId.put((String) result.get(i).get(categoryName), (String) result.get(i).get("category_id_value")); + categoryToId.put((String) result.get(i).get(categoryName), + (String) result.get(i).get("category_id_value")); } else { @@ -196,7 +194,8 @@ private JSONArray toWordcloudArray(Map columns, Object serie, Ha res.remove(name); res.put(name, oldValueMap); - categoryToId.put((String) result.get(i).get(categoryName), (String) result.get(i).get("category_id_value")); + categoryToId.put((String) result.get(i).get(categoryName), + (String) result.get(i).get("category_id_value")); } @@ -236,8 +235,8 @@ private JSONArray toWordcloudArray(Map columns, Object serie, Ha /** * Method that serves for preparing the data that JS code will use for rendering the CHORD chart * - * @param dataRows List of objects that represent the result of the query based on the result of the dataset linked to the chart (document) and on - * the query formed upon the XML of the document (VALUES tag, particularly CATEGORY and SERIE subtags) + * @param dataRows List of objects that represent the result of the query based on the result of the dataset linked to the chart (document) and on the + * query formed upon the XML of the document (VALUES tag, particularly CATEGORY and SERIE subtags) * @param columnsNeeded Categories (columns of the resulting table) that are needed by the request formulated through the XML tag CATEGORY * @param serie Column of the resulting table that is specified as the SERIE column through the XML tag SERIE * @param dataColumnsMapper Mapping between the name of the columns (categories and serie) and their ordinal (raw value: column_1, column_2, ...) @@ -245,8 +244,8 @@ private JSONArray toWordcloudArray(Map columns, Object serie, Ha * * @author Danilo Ristovski (danilo.ristovski@mht.net) */ - public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object serie, Object dataColumnsMapper, Object groupingFunction) - throws JSONException { + public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object serie, Object dataColumnsMapper, + Object groupingFunction) throws JSONException { Map categories = (Map) columnsNeeded; Map columnsMapper = (Map) dataColumnsMapper; @@ -270,9 +269,9 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s // column_2 /** - * Take all columns of the future perfect matrix (same values in the same order both in rows and columns of the matrix). These are the target items - * (items towards which source items (rows of the matrix) are going. This variable serves as a container of all columns and rows at the same time (since - * the matrix must be perfect - all items in its rows and columns must be the same and in the same order). + * Take all columns of the future perfect matrix (same values in the same order both in rows and columns of the matrix). These are the target items (items + * towards which source items (rows of the matrix) are going. This variable serves as a container of all columns and rows at the same time (since the matrix + * must be perfect - all items in its rows and columns must be the same and in the same order). */ ArrayList allColumns = new ArrayList<>(); @@ -290,15 +289,15 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s } /** - * All columns (and rows) are now arranged in the ascending order so we can have (i,i) mapping between columns and rows inside the matrix with the same - * name (as said here: https://github.com/mbostock/d3/wiki/Chord-Layout, under "# chord.matrix([matrix])" header of the text). + * All columns (and rows) are now arranged in the ascending order so we can have (i,i) mapping between columns and rows inside the matrix with the same name (as + * said here: https://github.com/mbostock/d3/wiki/Chord-Layout, under "# chord.matrix([matrix])" header of the text). */ Collections.sort(allColumns); /** - * Create an unordered map of maps that will only contain data about pairs of row and columns available in existing data obtained when executing the not - * pivoted dataset. Later we are going to create a matrix in the form of the JSON object, so we will extend the second dimension of this structure (add - * columns for which rows we do not have corresponding data and fill it with value of zero - form a complete matrix). + * Create an unordered map of maps that will only contain data about pairs of row and columns available in existing data obtained when executing the not pivoted + * dataset. Later we are going to create a matrix in the form of the JSON object, so we will extend the second dimension of this structure (add columns for + * which rows we do not have corresponding data and fill it with value of zero - form a complete matrix). */ Map> availableDataMapOfMaps = new HashMap<>(); @@ -327,20 +326,24 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s HashMap submapWithNewColumn = new HashMap<>(); - if (record.get(columnsMapper.get(serie + "_" + aggregationType)).getClass().toString().equals("class java.lang.Integer")) { + if (record.get(columnsMapper.get(serie + "_" + aggregationType)).getClass().toString() + .equals("class java.lang.Integer")) { /** - * Serie value for the current row and column (their intersection - value inside the intersection of the future matrix's current row and - * current column (values in variables of an appropriate name in this code. + * Serie value for the current row and column (their intersection - value inside the intersection of the future matrix's current row and current column (values + * in variables of an appropriate name in this code. * * NOTE: The same goes for other variables of the same name ('serieValueForXOfRowAndColumn') in the code afterwards. */ - Integer serieValueForXOfRowAndColumn = (int) record.get(columnsMapper.get(serie + "_" + aggregationType)); - submapWithNewColumn.put(currentColumn, Float.parseFloat(Integer.toString(serieValueForXOfRowAndColumn))); + Integer serieValueForXOfRowAndColumn = (int) record + .get(columnsMapper.get(serie + "_" + aggregationType)); + submapWithNewColumn.put(currentColumn, + Float.parseFloat(Integer.toString(serieValueForXOfRowAndColumn))); } else { - String serieValueForXOfRowAndColumn = (record.get(columnsMapper.get(serie + "_" + aggregationType))).toString(); + String serieValueForXOfRowAndColumn = (record.get(columnsMapper.get(serie + "_" + aggregationType))) + .toString(); submapWithNewColumn.put(currentColumn, Float.parseFloat(serieValueForXOfRowAndColumn)); } @@ -348,15 +351,20 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s } else { - if (record.get(columnsMapper.get(serie + "_" + aggregationType)).getClass().toString().equals("class java.lang.Integer")) { + if (record.get(columnsMapper.get(serie + "_" + aggregationType)).getClass().toString() + .equals("class java.lang.Integer")) { - Integer serieValueForXOfRowAndColumn = (int) record.get(columnsMapper.get(serie + "_" + aggregationType)); - availableDataMapOfMaps.get(currentRow).put(currentColumn, Float.parseFloat(Integer.toString(serieValueForXOfRowAndColumn))); + Integer serieValueForXOfRowAndColumn = (int) record + .get(columnsMapper.get(serie + "_" + aggregationType)); + availableDataMapOfMaps.get(currentRow).put(currentColumn, + Float.parseFloat(Integer.toString(serieValueForXOfRowAndColumn))); } else { - String serieValueForXOfRowAndColumn = (record.get(columnsMapper.get(serie + "_" + aggregationType))).toString(); - availableDataMapOfMaps.get(currentRow).put(currentColumn, Float.parseFloat(serieValueForXOfRowAndColumn)); + String serieValueForXOfRowAndColumn = (record.get(columnsMapper.get(serie + "_" + aggregationType))) + .toString(); + availableDataMapOfMaps.get(currentRow).put(currentColumn, + Float.parseFloat(serieValueForXOfRowAndColumn)); } @@ -370,8 +378,8 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s JSONObject finalJsonResult = new JSONObject(); /** - * JSON object for collecting the data (labels with their values and JSON array) for meta data ('root' label and 'fields' JSON array) connected to the - * final data obtained from the dataset. + * JSON object for collecting the data (labels with their values and JSON array) for meta data ('root' label and 'fields' JSON array) connected to the final + * data obtained from the dataset. */ JSONObject jsonObjectMetadata = new JSONObject(); @@ -381,9 +389,8 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s jsonObjectMetadata.put("root", "rows"); /** - * JSON array under the 'fields' label of the 'metaData' label that will contain information about all columns of the matrix that we need to create so - * to deliver it to the rendering (client) side. It will contain information about all columns (name and their ordinal value) in alphabetically - * ascending order. + * JSON array under the 'fields' label of the 'metaData' label that will contain information about all columns of the matrix that we need to create so to + * deliver it to the rendering (client) side. It will contain information about all columns (name and their ordinal value) in alphabetically ascending order. */ JSONArray jsonArrayMetadataFields = new JSONArray(); @@ -393,8 +400,8 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s int columnCounter = 1; /** - * Populate the 'jsonArrayMetadataFields' array with the fields and the data that will contain necessary data (name, data index and header) about the - * all the columns arranged in ascending order. + * Populate the 'jsonArrayMetadataFields' array with the fields and the data that will contain necessary data (name, data index and header) about the all the + * columns arranged in ascending order. */ for (int i = 0; i < allColumns.size(); i++) { @@ -412,8 +419,8 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s } /** - * Join this JSON array under the 'fields' label of the 'metaData' label of the final JSON object. It serves as an informer of which fields are we - * expecting when data comes from the server-side and which rows and columns is the CHORD matrix going to possess. + * Join this JSON array under the 'fields' label of the 'metaData' label of the final JSON object. It serves as an informer of which fields are we expecting + * when data comes from the server-side and which rows and columns is the CHORD matrix going to possess. */ jsonObjectMetadata.put("fields", jsonArrayMetadataFields); @@ -423,16 +430,14 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s finalJsonResult.put("metaData", jsonObjectMetadata); /** - * Label that contains the information about the total number of rows/column if the matrix that we are now going to create through the form of JSON - * object. + * Label that contains the information about the total number of rows/column if the matrix that we are now going to create through the form of JSON object. */ finalJsonResult.put("results", availableDataMapOfMaps.size()); /** - * JSON array that will contain JSON objects that are representing all rows with data about values of their intersection with the appropriate column - * pair and that are arranged in ascending order. This way we are extending dimension of current data, so we are going to have all (row,column) pairs - * with their dedicated appropriate values (as said here: https://github.com/mbostock/d3/wiki/Chord-Layout, under this header: "# - * chord.matrix([matrix])"). + * JSON array that will contain JSON objects that are representing all rows with data about values of their intersection with the appropriate column pair and + * that are arranged in ascending order. This way we are extending dimension of current data, so we are going to have all (row,column) pairs with their + * dedicated appropriate values (as said here: https://github.com/mbostock/d3/wiki/Chord-Layout, under this header: "# chord.matrix([matrix])"). */ JSONArray jsonArrayResultsRows = new JSONArray(); @@ -442,31 +447,31 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s for (int i = 0; i < allColumns.size(); i++) { /** - * For every new row create a JSON object that will contain values of intersection with all existing columns (previously arranged in alphabetically - * ascending order) of future matrix (in form of the final JSON object). This JSON object will be inserted into the JSON array of numerical results - * ('rows' label of the final JSON object). These data are going to be used by the client (JS, particularly D3) code that will render the CHORD - * chart. + * For every new row create a JSON object that will contain values of intersection with all existing columns (previously arranged in alphabetically ascending + * order) of future matrix (in form of the final JSON object). This JSON object will be inserted into the JSON array of numerical results ('rows' label of the + * final JSON object). These data are going to be used by the client (JS, particularly D3) code that will render the CHORD chart. */ JSONObject jsonObjectRowWithAllItsColumns = new JSONObject(); /** - * As zeroth column (label) set the name of the row to which we are going to link data (values) of the intersection of it with the particular - * column. + * As zeroth column (label) set the name of the row to which we are going to link data (values) of the intersection of it with the particular column. */ jsonObjectRowWithAllItsColumns.put("column_0", allColumns.get(i)); /** - * With this two-step for-loop we will have appropriate matrix - the (row,column) pairs will be in the form in which i-th row with some name will be - * of the same name as the i-th column (names of rows and columns on the main diagonal of the matrix will be the same). (as specified here: + * With this two-step for-loop we will have appropriate matrix - the (row,column) pairs will be in the form in which i-th row with some name will be of the same + * name as the i-th column (names of rows and columns on the main diagonal of the matrix will be the same). (as specified here: * https://github.com/mbostock/d3/wiki/Chord-Layout) */ for (int j = 0; j < allColumns.size(); j++) { String columnOrder = "column_" + (j + 1); - if (availableDataMapOfMaps.get(allColumns.get(i)) != null && availableDataMapOfMaps.get(allColumns.get(i)).get(allColumns.get(j)) != null) { + if (availableDataMapOfMaps.get(allColumns.get(i)) != null + && availableDataMapOfMaps.get(allColumns.get(i)).get(allColumns.get(j)) != null) { - jsonObjectRowWithAllItsColumns.put(columnOrder, availableDataMapOfMaps.get(allColumns.get(i)).get(allColumns.get(j))); + jsonObjectRowWithAllItsColumns.put(columnOrder, + availableDataMapOfMaps.get(allColumns.get(i)).get(allColumns.get(j))); } else { @@ -481,8 +486,7 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s } /** - * Set the JSON array of all rows of the matrix (and their intersected values with all the columns) into the final JSON object and link it to the 'rows' - * label. + * Set the JSON array of all rows of the matrix (and their intersected values with all the columns) into the final JSON object and link it to the 'rows' label. */ finalJsonResult.put("rows", jsonArrayResultsRows); @@ -491,7 +495,8 @@ public JSONObject toMatrix(List dataRows, Object columnsNeeded, Object s /* Merging codes - Sunburst */ - public JSONArray toTree(Object columnsNeeded, Object serie, Object dataColumnsMapper, List dataRows, Object groupingFunction) throws JSONException { + public JSONArray toTree(Object columnsNeeded, Object serie, Object dataColumnsMapper, List dataRows, + Object groupingFunction) throws JSONException { // Data columns mapper (as map) Map mapper = (Map) dataColumnsMapper; @@ -543,7 +548,8 @@ public JSONArray toTree(Object columnsNeeded, Object serie, Object dataColumnsMa return res; } - public JSONArray countSequence(Map columns, Object serie, HashMap result) throws JSONException { + public JSONArray countSequence(Map columns, Object serie, HashMap result) + throws JSONException { HashMap endresult = new HashMap<>(); JSONArray ja = new JSONArray(); @@ -586,8 +592,8 @@ public JSONArray countSequence(Map columns, Object serie, HashMa return ja; } - public JSONObject createTreeChart(Object columnsNeeded, Object serie, Object dataColumnsMapper, List dataRows, Object groupingFunction) - throws JSONException { + public JSONObject createTreeChart(Object columnsNeeded, Object serie, Object dataColumnsMapper, + List dataRows, Object groupingFunction) throws JSONException { Map mapper = (Map) dataColumnsMapper; Map columns = (Map) columnsNeeded; @@ -627,7 +633,8 @@ public JSONObject createTreeChart(Object columnsNeeded, Object serie, Object dat } - public JSONObject createTreeMap(Map columns, Object serie, HashMap result) throws JSONException { + public JSONObject createTreeMap(Map columns, Object serie, HashMap result) + throws JSONException { JSONObject root = new JSONObject(); @@ -661,7 +668,8 @@ public JSONObject createTreeMap(Map columns, Object serie, HashM return root; } - public String getGroupsForParallelChart(Object columnsNeeded, Object dataColumnsMapper, List dataRows) throws JSONException { + public String getGroupsForParallelChart(Object columnsNeeded, Object dataColumnsMapper, List dataRows) + throws JSONException { JSONArray ja = new JSONArray(); @@ -713,8 +721,8 @@ public String getGroupsForParallelChart(Object columnsNeeded, Object dataColumns * */ - public LinkedHashMap> prepareDataForGroupingForBar(List dataRows, String isCockpitEngine, String categorieColumnsMapped) - throws JSONException { + public LinkedHashMap> prepareDataForGroupingForBar(List dataRows, + String isCockpitEngine, String categorieColumnsMapped) throws JSONException { boolean isCockpit = Boolean.parseBoolean(isCockpitEngine); LinkedHashMap> map = new LinkedHashMap<>(); String primCat; @@ -745,7 +753,11 @@ public LinkedHashMap> prepareDataForGroupingForBar(Lis } - public JSONArray getCategoriesCardinality(List dataRows, Object categories, Map dataColumnsMapper) { + public JSONArray getCategoriesCardinality(List dataRows, Object categories, + Map dataColumnsMapper) { + + LOGGER.debug("Getting categories cardinality for rows {}, categories {} and {}", dataRows, categories, + dataColumnsMapper); final JSONArray categoriesCardinality = new JSONArray(); JSONObject jsonObject = new JSONObject(); @@ -763,6 +775,9 @@ public JSONArray getCategoriesCardinality(List dataRows, Object categori } + LOGGER.debug("Categories cardinality for rows {}, categories {} and {} is {}", dataRows, categories, + dataColumnsMapper, categories); + return categoriesCardinality; } @@ -772,9 +787,11 @@ public JSONArray getCategoriesCardinality(List dataRows, Object categori * @param jsonObject * @param innerEntrySet */ - private void addDistinctForCategory(List dataRows, Map dataColumnsMapper, JSONObject jsonObject, Object object) { + private void addDistinctForCategory(List dataRows, Map dataColumnsMapper, + JSONObject jsonObject, Object object) { Set entrySet = ((LinkedHashMap) object).entrySet(); - Optional columnName = entrySet.stream().filter(y -> String.valueOf(((Map.Entry) y).getKey()).equals(COLUMN)).findFirst(); + Optional columnName = entrySet.stream() + .filter(y -> String.valueOf(((Map.Entry) y).getKey()).equals(COLUMN)).findFirst(); if (columnName.isPresent()) { String value = String.valueOf((columnName.get().getValue())); @@ -794,7 +811,8 @@ private void addDistinctForCategory(List dataRows, Map d } } - public JSONArray getRange(List dataRows, Map dataColumnsMapper, LinkedHashMap serieMap) { + public JSONArray getRange(List dataRows, Map dataColumnsMapper, + LinkedHashMap serieMap) { JSONArray ranges = new JSONArray(); if (dataRows != null && dataRows.size() > 0) { @@ -818,7 +836,8 @@ public JSONArray getRange(List dataRows, Map dataColumns r.put("min", min.getAsDouble()); r.put("max", max.getAsDouble()); } catch (JSONException e) { - throw new SpagoBIServiceException("Error while calculating min and max for serie" + elementMap.get("name"), e); + throw new SpagoBIServiceException( + "Error while calculating min and max for serie" + elementMap.get("name"), e); } ranges.put(r); } @@ -839,7 +858,8 @@ public JSONArray getRange(List dataRows, Map dataColumns private String getColumnMappedValue(Map dataColumnsMapper, String name, String groupingFunction) { String completeName = StringUtils.isNotBlank(groupingFunction) ? name + "_" + groupingFunction : name; - Optional mappedColumn = dataColumnsMapper.keySet().stream().filter(x -> completeName.equalsIgnoreCase(x)).findFirst(); + Optional mappedColumn = dataColumnsMapper.keySet().stream() + .filter(x -> completeName.equalsIgnoreCase(x)).findFirst(); if (mappedColumn.isPresent()) return dataColumnsMapper.get(mappedColumn.get()); @@ -901,7 +921,8 @@ private OptionalDouble getMinValue(List dataRows, String columnMap) { return minOD; } - public JSONObject prepareDataForOrderingColumnForBar(List dataRows, List metadataRows, Map drillOrder, String groupBy) { + public JSONObject prepareDataForOrderingColumnForBar(List dataRows, List metadataRows, + Map drillOrder, String groupBy) { String orderColumn = ""; if (drillOrder != null) { for (String key : drillOrder.keySet()) { @@ -948,9 +969,9 @@ public String escapeStringForJavascript(JSONObject stringToEscaPe) { return StringEscapeUtils.escapeEcmaScript(stringToEscaPe.toString()); } - public LinkedHashMap> prepareDataForGrouping(List dataRows, String isCockpitEngine, String groupSeries, - String groupSeriesCateg, Map dataColumnsMapper, Map categorieColumns, String groupedSerie, - Map drillOrder) { + public LinkedHashMap> prepareDataForGrouping(List dataRows, + String isCockpitEngine, String groupSeries, String groupSeriesCateg, Map dataColumnsMapper, + Map categorieColumns, String groupedSerie, Map drillOrder) { boolean isCockpit = Boolean.parseBoolean(isCockpitEngine); boolean groupSeriesBool = Boolean.parseBoolean(groupSeries); @@ -992,9 +1013,9 @@ public LinkedHashMap> prepareDataForGrouping(List< } } - logger.debug("primCat: " + primCat); - logger.debug("secCat: " + secCat); - logger.debug("seria: " + seria); + LOGGER.debug("primCat: {}", primCat); + LOGGER.debug("secCat: {}", secCat); + LOGGER.debug("seria: {}", seria); for (Object singleObject : dataRows) { categories.add(((Map) singleObject).get(primCat)); } @@ -1040,14 +1061,15 @@ public LinkedHashMap> prepareDataForGrouping(List< map.put(newCol, newListOfOrderColumnItems); } - JSONObject jo = newListOfOrderColumnItems.get(categoriesListIndexMap.get(((Map) singleObject).get(primCat))); + JSONObject jo = newListOfOrderColumnItems + .get(categoriesListIndexMap.get(((Map) singleObject).get(primCat))); jo.put("y", serieValue); } } - logger.debug("map: " + map); + LOGGER.debug("map: {}", map); } catch (Exception e) { throw new CockpitEngineRuntimeException("Cannot group data", e); @@ -1060,12 +1082,14 @@ public LinkedHashMap> prepareDataForGrouping(List< * @param drillOrder * @param categorieColumns */ - private void removeOrderColumn(Map dataColumnsMapper, Map drillOrder, Map categorieColumns) { + private void removeOrderColumn(Map dataColumnsMapper, Map drillOrder, + Map categorieColumns) { if (drillOrder != null) { for (String key : drillOrder.keySet()) { Map keyMapper = (Map) drillOrder.get(key); if (keyMapper.get("orderColumn") != null && !keyMapper.get("orderColumn").equals("") - && !keyMapper.get("orderColumn").equals(categorieColumns.get(COLUMN)) && !drillOrder.containsKey(keyMapper.get("orderColumn"))) { + && !keyMapper.get("orderColumn").equals(categorieColumns.get(COLUMN)) + && !drillOrder.containsKey(keyMapper.get("orderColumn"))) { dataColumnsMapper.remove(keyMapper.get("orderColumn").toLowerCase()); } } @@ -1078,15 +1102,17 @@ private void removeOrderColumn(Map dataColumnsMapper, Map> prepareDataForGroupingBubble(List dataRows, Map dataColumnsMapper, - Map categorieColumns, String groupedSerie, String serieForZAxis, String serieForXAxis, String coloredCategory) { + public LinkedHashMap> prepareDataForGroupingBubble(List dataRows, + Map dataColumnsMapper, Map categorieColumns, String groupedSerie, + String serieForZAxis, String serieForXAxis, String coloredCategory) { ArrayList categories = new ArrayList<>(); LinkedHashMap> map = new LinkedHashMap<>(); try { String columnForGroupingSerie = dataColumnsMapper.get(groupedSerie).toLowerCase(); - if (!categorieColumns.get("orderColumn").equals("") && !categorieColumns.get("orderColumn").equals(categorieColumns.get(COLUMN)) + if (!categorieColumns.get("orderColumn").equals("") + && !categorieColumns.get("orderColumn").equals(categorieColumns.get(COLUMN)) && !categorieColumns.get("groupby").contains(categorieColumns.get("orderColumn"))) { dataColumnsMapper.remove(categorieColumns.get("orderColumn").toLowerCase()); } @@ -1120,9 +1146,9 @@ public LinkedHashMap> prepareDataForGroupingBubble String z = dataColumnsMapper.get(serieForZAxis); String x = dataColumnsMapper.get(serieForXAxis); - logger.debug("primCat: " + primColumn); - logger.debug("secCat: " + secCat); - logger.debug("seria: " + seriaColumn); + LOGGER.debug("primCat: {}", primColumn); + LOGGER.debug("secCat: {}", secCat); + LOGGER.debug("seria: {}", seriaColumn); for (Object singleObject : dataRows) { categories.add(((Map) singleObject).get(primColumn)); @@ -1147,8 +1173,8 @@ public LinkedHashMap> prepareDataForGroupingBubble if (key.equals(seria)) { newCol = ((Map) singleObject).get(seriaColumn).toString(); serieValue = ((Map) singleObject).get(secCat).toString(); - } else if (isDifferent(key, primCateg) && isDifferent(key, serieForXAxis) && isDifferent(key, serieForZAxis) - && isDifferent(key, groupedSerie)) { + } else if (isDifferent(key, primCateg) && isDifferent(key, serieForXAxis) + && isDifferent(key, serieForZAxis) && isDifferent(key, groupedSerie)) { newCol = key; serieValue = ((Map) singleObject).get(dataColumnsMapper.get(key)).toString(); @@ -1173,7 +1199,8 @@ && isDifferent(key, groupedSerie)) { map.put(newCol, newListOfOrderColumnItems); } - JSONObject jo = newListOfOrderColumnItems.get(categoriesListIndexMap.get(((Map) singleObject).get(primColumn))); + JSONObject jo = newListOfOrderColumnItems + .get(categoriesListIndexMap.get(((Map) singleObject).get(primColumn))); jo.put("y", serieValue); jo.put("x", ((Map) singleObject).get(x).toString()); jo.put("z", ((Map) singleObject).get(z).toString()); @@ -1189,7 +1216,7 @@ && isDifferent(key, groupedSerie)) { } - logger.debug("map: " + map); + LOGGER.debug("map: {}", map); } catch (Exception e) { throw new CockpitEngineRuntimeException("Cannot group data", e); } @@ -1213,16 +1240,16 @@ private boolean isDifferent(String key, String seria) { /** * Method that serves for preparing the data that JS code will use for rendering the SCATTER chart * - * @param dataRows List of objects that represent the result of the query based on the result of the dataset linked to the chart (document) and on - * the query formed upon the XML of the document (VALUES tag, particularly CATEGORY and SERIE subtags) + * @param dataRows List of objects that represent the result of the query based on the result of the dataset linked to the chart (document) and on the + * query formed upon the XML of the document (VALUES tag, particularly CATEGORY and SERIE subtags) * @param columnCategorie column_x that is category * @param columnSerie column_y,z that is serie * @author rselakov, radmila.selakovic@mht.net * */ - public LinkedHashMap>> prepareDataForScater(List dataRows, String columnCategorie, String isCockpitEngine, - String columnSerie) { + public LinkedHashMap>> prepareDataForScater(List dataRows, + String columnCategorie, String isCockpitEngine, String columnSerie) { LinkedHashMap>> map = new LinkedHashMap<>(); try { boolean isCockpit = Boolean.parseBoolean(isCockpitEngine); @@ -1315,7 +1342,8 @@ public ArrayList getXAxisMap(LinkedHashMap category, return xAxisMap; } - public LinkedHashMap seriesMapTransformedMethod(LinkedHashMap serieMap) throws JSONException { + public LinkedHashMap seriesMapTransformedMethod( + LinkedHashMap serieMap) throws JSONException { LinkedHashMap newSerieMap = new LinkedHashMap<>(); String serieName = ""; int counter = 1; @@ -1364,8 +1392,8 @@ public String seriesRangeName(LinkedHashMap serieMap) thr * abbreviations (number suffix) along with the scaled number. * @author Danilo Ristovski (danristo, danilo.ristovski@mht.net) */ - public JSONArray getSeriesForParallelChart(Object serieNeeded, Object groupingFunction, Object seriePrefix, Object seriePostfix, Object seriePrecision, - Object serieScaleFactor) throws JSONException { + public JSONArray getSeriesForParallelChart(Object serieNeeded, Object groupingFunction, Object seriePrefix, + Object seriePostfix, Object seriePrecision, Object serieScaleFactor) throws JSONException { JSONArray ja = new JSONArray(); @@ -1415,10 +1443,10 @@ public JSONArray getColorPallete(Object colorsRequired) throws JSONException { JSONArray ja = new JSONArray(); /** - * If we receive colors from the velocity model of the PARALLEL chart with the ArrayList structure, then we are dealing with the single color that is - * going to be presented on the chart (as color of chart lines). That single color can be result of the situation in which user (1) did not specify any - * color in the Designer or (2) he specified single color (just one). In case (1) VM is sets a single default color value for lines on the chart, - * otherwise it takes the single one that user provided on the Designer. + * If we receive colors from the velocity model of the PARALLEL chart with the ArrayList structure, then we are dealing with the single color that is going to + * be presented on the chart (as color of chart lines). That single color can be result of the situation in which user (1) did not specify any color in the + * Designer or (2) he specified single color (just one). In case (1) VM is sets a single default color value for lines on the chart, otherwise it takes the + * single one that user provided on the Designer. * * @author: danristo (danilo.ristovski@mht.net) */ @@ -1436,8 +1464,8 @@ public JSONArray getColorPallete(Object colorsRequired) throws JSONException { } /** - * If we receive colors from the velocity model of the PARALLEL chart with the LinkedHashMap structure, then we are dealing with the collection of - * colors that are going to be presented on the chart (as colors of chart lines). + * If we receive colors from the velocity model of the PARALLEL chart with the LinkedHashMap structure, then we are dealing with the collection of colors that + * are going to be presented on the chart (as colors of chart lines). * * @commentedBy: danristo (danilo.ristovski@mht.net) */ @@ -1467,8 +1495,8 @@ public JSONArray getColorPallete(Object colorsRequired) throws JSONException { } - public JSONArray toParallelChart(Object columnsNeeded, Object dataColumnsMapper, List dataRows, Object serieNeeded, Object groupingFunction) - throws JSONException { + public JSONArray toParallelChart(Object columnsNeeded, Object dataColumnsMapper, List dataRows, + Object serieNeeded, Object groupingFunction) throws JSONException { JSONArray res = new JSONArray(); @@ -1525,7 +1553,8 @@ public JSONArray toParallelChart(Object columnsNeeded, Object dataColumnsMapper, } - public Map getData(List dataRows, Object serie, Object columnsNeeded, Object dataColumnsMapper, Object groupingFunction) { + public Map getData(List dataRows, Object serie, Object columnsNeeded, Object dataColumnsMapper, + Object groupingFunction) { Map mapper = (Map) dataColumnsMapper; @@ -1572,10 +1601,9 @@ public boolean isFirstCategoryDate(Map firstresult, Object col DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); /** - * -------------------------------------------------------------------- ---------------------- KNOWAGE-778 ( "COCKPIT-Chart: heatmap hangs in loading - * when the selections return no data" ) ------------------------------------------------------------------ ------------------------ If there is no data - * in the "firstresult" (if it is an empty map), return the false boolean value to the VM. The first category (that does not exist) is definitely not of - * type DATE. + * -------------------------------------------------------------------- ---------------------- KNOWAGE-778 ( "COCKPIT-Chart: heatmap hangs in loading when the + * selections return no data" ) ------------------------------------------------------------------ ------------------------ If there is no data in the + * "firstresult" (if it is an empty map), return the false boolean value to the VM. The first category (that does not exist) is definitely not of type DATE. * * @modifiedBy Danilo Ristovski (danristo, danilo.ristovski@mht.net) */ @@ -1679,8 +1707,8 @@ public JSONArray getStoreResult(Map firstresult, Object column } - public JSONArray getResult(Map firstresult, Object serie, HashMap columns, boolean isDate) - throws JSONException, ParseException { + public JSONArray getResult(Map firstresult, Object serie, HashMap columns, + boolean isDate) throws JSONException, ParseException { JSONArray result = new JSONArray(); @@ -1707,7 +1735,8 @@ public JSONArray getResult(Map firstresult, Object serie, Hash jo.put(columns.get(0).toString(), value); } - if (firstresult.get(i).get(columns.get(1).toString()) != null && firstresult.get(i).get(columns.get(1).toString()) instanceof Integer) { + if (firstresult.get(i).get(columns.get(1).toString()) != null + && firstresult.get(i).get(columns.get(1).toString()) instanceof Integer) { Integer value = (Integer) firstresult.get(i).get(columns.get(1).toString()); jo.put(columns.get(1).toString(), value); @@ -1765,7 +1794,8 @@ public String setGroupingFunctionToLowerCase(String value) { String returnedValue = ""; for (int i = 0; i < arrayOfGroupingFunction.length; i++) { if (value.contains("_" + arrayOfGroupingFunction[i])) { - returnedValue = value.replace("_" + arrayOfGroupingFunction[i], "_" + arrayOfGroupingFunction[i].toLowerCase()); + returnedValue = value.replace("_" + arrayOfGroupingFunction[i], + "_" + arrayOfGroupingFunction[i].toLowerCase()); break; } @@ -1780,7 +1810,8 @@ public String setGroupingFunctionToLowerCase(String value) { } public JSONObject getColorObject(int counter) { - String[] defaultColors = { "#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b", "#91e8e1" }; + String[] defaultColors = { "#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", + "#2b908f", "#f45b5b", "#91e8e1" }; JSONObject toReturn = new JSONObject(); String name = defaultColors[counter].substring(1); String value = defaultColors[counter]; @@ -1788,7 +1819,7 @@ public JSONObject getColorObject(int counter) { toReturn.put("name", name); toReturn.put("value", value); } catch (JSONException e) { - logger.error("Can not create JSON object", e); + LOGGER.error("Can not create JSON object", e); } return toReturn; } diff --git a/knowagecockpitengine/src/main/resources/log4j2.xml b/knowagecockpitengine/src/main/resources/log4j2.xml index c55684e0964..82f6dbc8b40 100644 --- a/knowagecockpitengine/src/main/resources/log4j2.xml +++ b/knowagecockpitengine/src/main/resources/log4j2.xml @@ -52,6 +52,9 @@ + + +