Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #146 from BasisHub/feature/#144-missing-attributes
Browse files Browse the repository at this point in the history
Feature/#144 missing attributes
  • Loading branch information
DaAmore committed May 27, 2019
2 parents dc7d930 + 89f44b4 commit 25873fd
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 461 deletions.
3 changes: 0 additions & 3 deletions pom.xml
Expand Up @@ -214,15 +214,12 @@
<version>5.3.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand Down
44 changes: 18 additions & 26 deletions src/main/java/com/basiscomponents/db/DataRow.java
@@ -1,39 +1,27 @@
package com.basiscomponents.db;

import static com.basiscomponents.db.util.DataRowMatcherProvider.createMatcher;

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.xml.bind.DatatypeConverter;

import com.basis.bbj.datatypes.TemplatedString;
import com.basis.util.common.BasisNumber;
import com.basis.util.common.TemplateInfo;
import com.basiscomponents.db.constants.ConstantsResolver;
import com.basiscomponents.db.exception.DataFieldNotFoundException;
import com.basiscomponents.db.model.Attribute;
import com.basiscomponents.db.util.DataFieldConverter;
import com.basiscomponents.db.util.DataRowFromJsonProvider;
import com.basiscomponents.db.util.DataRowMatcher;
import com.basiscomponents.db.util.JRDataSourceAdapter;
import com.basiscomponents.db.util.TemplateParser;
import com.basiscomponents.db.util.*;
import com.fasterxml.jackson.core.JsonParseException;

import com.google.gson.JsonElement;
import net.sf.jasperreports.engine.JRDataSource;

import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import static com.basiscomponents.db.util.DataRowMatcherProvider.createMatcher;

/**
* A DataRow is a container object with key/value pairs. Each key being a String
* and each value being a com.basiscomponents.db.DataField object.
Expand Down Expand Up @@ -114,6 +102,10 @@ public DataRow(Map<String, Object> map) throws ParseException {
}
}

public static DataRow fromJson(String in, DataRow meta, JsonElement attributes) throws IOException, ParseException {
return DataRowFromJsonProvider.fromJson(in, meta, attributes);
}

/**
* Returns the row ID of this DataRow object.
*
Expand Down Expand Up @@ -1409,7 +1401,7 @@ public static DataRow fromJson(String j) throws JsonParseException, IOException,
* Gets thrown in case the JSON could not be parsed / is invalid
*/
public static DataRow fromJson(String in, DataRow meta) throws IOException, ParseException {
return DataRowFromJsonProvider.fromJson(in, meta);
return DataRowFromJsonProvider.fromJson(in, meta, null);
}

public void setFieldAttributes(String fieldName, Map<String, String> attr) {
Expand Down
92 changes: 50 additions & 42 deletions src/main/java/com/basiscomponents/db/ResultSet.java
@@ -1,32 +1,5 @@
package com.basiscomponents.db;

import static com.basiscomponents.util.StringHelper.invert;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.basis.util.common.BasisNumber;
import com.basis.util.common.Template;
import com.basis.util.common.TemplateInfo;
Expand All @@ -39,9 +12,20 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;

import net.sf.jasperreports.engine.JRDataSource;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Date;
import java.sql.*;
import java.text.ParseException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.basiscomponents.util.StringHelper.invert;

/**
* The ResultSet class is a container class for DataRow objects.
*/
Expand Down Expand Up @@ -171,7 +155,7 @@ public void orderByRowID() {
*
* CAUTION: this method is experimental!!
*
* @param QueryClause: the query
* @param queryClause: the query
* @return ResultSet: the records that match the query clause
* @throws Exception
*/
Expand Down Expand Up @@ -1444,7 +1428,7 @@ public void setSchemaName(int column, String schemaName) {
* for the column at the specified index.
*
* @param column The column index.
* @param name The value of the TableName property to set.
* @param tableName The value of the TableName property to set.
*/
public void setTableName(int column, String tableName) {
this.MetaData.get(column).put("TableName", tableName);
Expand Down Expand Up @@ -1506,7 +1490,6 @@ public void setDefinitelyWritable(int column, Boolean flag) {
* </ul>
*
* @param column The column index.
* @param flag The value of the Nullable property to set..
*
* @throws Exception Gets thrown in case the Nullable flag is not equal any of the above mentioned types.
*/
Expand Down Expand Up @@ -1916,6 +1899,10 @@ public Clob getClob(int column) {
return field.getClob();
}

public ArrayList<HashMap<String, Object>> getMetaData() {
return new ArrayList<>(MetaData);
}

/**
* Retrieves the DataField object of the current DataRow for the specified column index,
* and returns the DataField's value object as NClob.
Expand Down Expand Up @@ -2027,13 +2014,33 @@ public String toJson(Boolean f_meta) throws Exception {
public String toJson(Boolean f_meta, String addIndexColumn) throws Exception {
return toJson(f_meta, addIndexColumn, true);
}

public String toJson(Boolean f_meta, String addIndexColumn, Boolean f_trimStrings) throws Exception {

/**
*
* @param meta if MetaData should be printed
* @param addIndexColumn The Index column which is generated (@Code{null} if it doesn't exist)
* @param trimStrings if Strings should be trimmed
* @return The Json String containing this ResultSet
* @throws Exception
*/
public String toJson(boolean meta, String addIndexColumn, boolean trimStrings) throws Exception {
if (addIndexColumn!=null)
createIndex();
return ResultSetJsonMapper.toJson(this.DataRows, this.MetaData, f_meta, addIndexColumn, f_trimStrings);
return toJson(meta , addIndexColumn, trimStrings, false);
}
/**
*
* @param meta if MetaData should be printed
* @param addIndexColumn The Index column which is generated (@Code{null} if it doesn't exist)
* @param trimStrings if Strings should be trimmed
* @return The Json String containing this ResultSet
* @throws Exception
*/
public String toJson(boolean meta, String addIndexColumn, boolean trimStrings, boolean writeDataRowAttributes) throws Exception {
if (addIndexColumn!=null)
createIndex();
return ResultSetJsonMapper.toJson(this,meta , addIndexColumn, trimStrings, writeDataRowAttributes);
}

/**
* Returns this ResultSet as a JRDataSource
*
Expand Down Expand Up @@ -2082,20 +2089,22 @@ public static ResultSet fromJson(final String js) throws JsonParseException, IOE
meta = o.get(0).getAsJsonObject().getAsJsonObject("meta");
try {
metaRow = DataRow.fromJson(o.get(0).toString());
metaRow.clear();
//metaRow.clear();
} catch (Exception ex) {
}
}
if (meta == null) {
System.err.println("error parsing - meta data missing");
}
Iterator<JsonElement> it = o.iterator();
while (it.hasNext()) {
JsonElement el = it.next();

for (JsonElement el:o) {
if (el.getAsJsonObject().getAsJsonObject("meta") == null)
el.getAsJsonObject().add("meta", meta);

rs.add(DataRow.fromJson(el.toString(), metaRow));
if(el.getAsJsonObject().get(ResultSetJsonMapper.ATTRIBUTES)!=null){
rs.add(DataRow.fromJson(el.toString(), metaRow,el.getAsJsonObject().get(ResultSetJsonMapper.ATTRIBUTES)));
}else{
rs.add(DataRow.fromJson(el.toString(), metaRow));
}
}
return rs;
}
Expand Down Expand Up @@ -2488,7 +2497,6 @@ private static DataRow sortDataRow(DataRow dr, int sort) throws Exception {
* @see #sumByGroup(String, String, String, int, int)
*
* @param fieldname The name of the field.
* @param labelname The label name.
* @param sumfieldname The field name whose value should be summed
*
* @return A DataRow object with the field values from the DataRows defined in this ResultSet as field names and with the sum
Expand Down
@@ -1,15 +1,5 @@
package com.basiscomponents.db.util;

import java.io.IOException;
import java.sql.Types;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.basiscomponents.db.DataField;
import com.basiscomponents.db.DataRow;
import com.basiscomponents.db.ResultSet;
Expand All @@ -20,13 +10,21 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.google.gson.JsonElement;

import java.io.IOException;
import java.sql.Types;
import java.text.ParseException;
import java.util.*;

public class DataRowFromJsonProvider {

private static final String COLUMN_TYPE = "ColumnType";

public static DataRow fromJson(final String in, final DataRow meta)
throws JsonParseException, IOException, ParseException {
public static DataRow fromJson(final String in, final DataRow meta) throws IOException, ParseException {
return fromJson(in,meta,null);
}
public static DataRow fromJson(final String in, final DataRow meta, JsonElement attributes)
throws IOException, ParseException {
String input = in;
if (input.length() < 2) {
return new DataRow();
Expand All @@ -45,7 +43,6 @@ public static DataRow fromJson(final String in, final DataRow meta)

List<?> navigation = objectMapper.readValue(jsonParser,
objectMapper.getTypeFactory().constructCollectionType(List.class, Object.class));

if (navigation.isEmpty()) {
return new DataRow();
}
Expand All @@ -68,6 +65,9 @@ public static DataRow fromJson(final String in, final DataRow meta)
} else {
handleOldFormat(navigation, dr);
}
if (attributes!=null){
attributes.getAsJsonObject().entrySet().stream().forEach(entry->dr.setAttribute(entry.getKey(),entry.getValue().getAsString()));
}
return dr;
}
}
Expand Down

0 comments on commit 25873fd

Please sign in to comment.