package io.pivotal.Domain;

import com.google.api.services.bigquery.model.TableCell;
import com.google.api.services.bigquery.model.TableRow;

import java.util.List;

/**
 * Created by mross on 10/7/16.
 */
public class QueryResultsViewMapping {

    String bookName;
    String authorName;
    String bookLocation;



    public QueryResultsViewMapping() {
        this.bookName = "N/A";
        this.authorName = "N/A";
        this.bookLocation = "N/A";
    }

    public QueryResultsViewMapping(TableRow rows) {
        int count =0;
        System.out.println("Entered the mapping");

        System.out.println(rows.toString());
        for (TableCell cell: rows.getF()) {

            if (count == 0 ) {
                bookName = cell.getV().toString();
            } else if (count == 1) {
                authorName = cell.getV().toString();
            } else {
                bookLocation = cell.getV().toString();

            }
            count++;
            System.out.printf("%-50s", cell.getV());
        }

        }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public String getBookLocation() {
        return bookLocation;
    }

    public void setBookLocation(String bookLocation) {
        this.bookLocation = bookLocation;
    }

    @Override
    public String toString() {
        return "QueryResultsViewMapping{" +
                "bookName='" + bookName + '\'' +
                ", authorName='" + authorName + '\'' +
                ", bookLocation='" + bookLocation + '\'' +
                '}';
    }
}

@@ -309,16 +309,82 @@
 ation;%0A%0A
+    private static final String DEFAULT_VALUE = %22(Not available)%22;
 %0A%0A    pu
@@ -737,16 +737,259 @@
 tF()) %7B%0A
+            // Why are we seeing %22author = java.lang.Object@3d347088%22?%0A            String stringVal = cell.getV().toString();%0A            if (stringVal.startsWith(%22java.lang.Object@%22)) %7B%0A                stringVal = DEFAULT_VALUE;%0A            %7D
 %0A       
@@ -1039,38 +1039,25 @@
 kName = 
-cell.getV().toS
+s
 tring
-()
+Val
 ;%0A      
@@ -1116,38 +1116,25 @@
 rName = 
-cell.getV().toS
+s
 tring
-()
+Val
 ;%0A      
@@ -1183,32 +1183,18 @@
 n = 
-cell.getV().toS
+s
 tring
-();%0A
+Val;
 %0A   

Fix for the 'java.lang.Object@3d347088' issue, for author (or other fields)