+ private static FTSData getFTSData(Map<String, Object> tdbJsonStructure,
+ FTSRestRequest tdbRequest)
+ {
+ // TODO: consider reusing PDBFTSRestClient.getFTSData ?
+
+ String primaryKey = null;
+ Object[] summaryRowData;
+
+ SequenceI associatedSequence;
+
+ Collection<FTSDataColumnI> displayFields = tdbRequest.getWantedFields();
+ SequenceI associatedSeq = tdbRequest.getAssociatedSequence();
+ int colCounter = 0;
+ summaryRowData = new Object[(associatedSeq != null)
+ ? displayFields.size() + 1
+ : displayFields.size()];
+ if (associatedSeq != null)
+ {
+ associatedSequence = associatedSeq;
+ summaryRowData[0] = associatedSequence;
+ colCounter = 1;
+ }
+
+ for (FTSDataColumnI field : displayFields)
+ {
+ String fieldData = (tdbJsonStructure.get(field.getCode()) == null)
+ ? " "
+ : tdbJsonStructure.get(field.getCode()).toString();
+ // System.out.println("Field : " + field + " Data : " + fieldData);
+ if (field.isPrimaryKeyColumn())
+ {
+ primaryKey = fieldData;
+ summaryRowData[colCounter++] = primaryKey;
+ }
+ else if (fieldData == null || fieldData.trim().isEmpty())
+ {
+ summaryRowData[colCounter++] = null;
+ }
+ else
+ {
+ try
+ {
+ summaryRowData[colCounter++] = (field.getDataType()
+ .getDataTypeClass() == Integer.class)
+ ? Integer.valueOf(fieldData)
+ : (field.getDataType()
+ .getDataTypeClass() == Double.class)
+ ? Double.valueOf(fieldData)
+ : fieldData;
+ } catch (Exception e)
+ {
+ // e.printStackTrace();
+ System.out.println("offending value:" + fieldData + fieldData);
+ }
+ }
+ }
+ final String primaryKey1 = primaryKey;
+ final Object[] summaryRowData1 = summaryRowData;
+
+ return new FTSData()
+ {
+
+ @Override
+ public Object[] getSummaryData()
+ {
+ return summaryRowData1;
+ }
+
+ @Override
+ public Object getPrimaryKey()
+ {
+ return primaryKey1;
+ }
+
+ /**
+ * Returns a string representation of this object;
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder summaryFieldValues = new StringBuilder();
+ for (Object summaryField : summaryRowData1)
+ {
+ summaryFieldValues.append(
+ summaryField == null ? " " : summaryField.toString())
+ .append("\t");
+ }
+ return summaryFieldValues.toString();
+ }
+
+ /**
+ * Returns hash code value for this object
+ */
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(primaryKey1, this.toString());
+ }
+
+ @Override
+ public boolean equals(Object that)
+ {
+ return this.toString().equals(that.toString());
+ }
+ };
+ }
+
+ // private static FTSData getFTSData(Map<String, Object> doc,
+ // FTSRestRequest tdbRestRequest)
+ // {
+ // String primaryKey = null;
+ //
+ // Object[] summaryRowData;
+ //
+ // Collection<FTSDataColumnI> displayFields =
+ // tdbRestRequest.getWantedFields();
+ // int colCounter = 0;
+ // summaryRowData = new Object[displayFields.size() + 1];
+ //
+ // return null;
+ // }