From 827d938c90d7def7dff357cfc6d34cd949c05655 Mon Sep 17 00:00:00 2001 From: Jesus Date: Mon, 21 Nov 2022 12:44:36 +0100 Subject: [PATCH] Added book model and data source --- books.csv | 212 ++++++++++++++++++ .../booksearch/config/AppConfig.java | 32 +++ .../booksearch/controller/CsvParser.java | 36 +++ .../com/jesuspinar/booksearch/model/Book.java | 118 ++++++++++ src/main/resources/application.properties | 1 - src/main/resources/booksearch.properties | 3 + 6 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 books.csv create mode 100644 src/main/java/com/jesuspinar/booksearch/config/AppConfig.java create mode 100644 src/main/java/com/jesuspinar/booksearch/controller/CsvParser.java create mode 100644 src/main/java/com/jesuspinar/booksearch/model/Book.java delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/booksearch.properties diff --git a/books.csv b/books.csv new file mode 100644 index 0000000..b7bb58d --- /dev/null +++ b/books.csv @@ -0,0 +1,212 @@ +Title;Author;Genre;Height;Publisher +Fundamentals of Wavelets;Goswami, Jaideva;signal processing;228;Wiley +Data Smart;Foreman, John;data science;235;Wiley +God Created the Integers;Hawking, Stephen;mathematics;197;Penguin +Superfreakonomics;Dubner, Stephen;economics;179;HarperCollins +Orientalism;Said, Edward;history;197;Penguin +Nature of Statistical Learning Theory;Vapnik, Vladimir;data science;230;Springer +Integration of the Indian States;Menon, V P;history;217;Orient Blackswan +Drunkard's Walk;Mlodinow, Leonard;science;197;Penguin +Image Processing & Mathematical Morphology;Shih, Frank;signal processing;241;CRC +How to Think Like Sherlock Holmes;Konnikova, Maria;psychology;240;Penguin +Data Scientists at Work;Sebastian Gutierrez ;data science;230;Apress +Slaughterhouse Five;Vonnegut, Kurt;fiction;198;Random House +Birth of a Theorem;Villani, Cedric;mathematics;234;Bodley Head +Structure & Interpretation of Computer Programs;Sussman, Gerald;computer science;240;MIT Press +Age of Wrath;Eraly, Abraham;history;238;Penguin +Trial;Kafka, Frank;fiction;198;Random House +Statistical Decision Theory';Pratt, John;data science;236;MIT Press +Data Mining Handbook;Nisbet, Robert;data science;242;Apress +New Machiavelli;Wells, H. G.;fiction;180;Penguin +Physics & Philosophy;Heisenberg, Werner;science;197;Penguin +Making Software;Oram, Andy;computer science;232;O'Reilly +Analysis, Vol I;Tao, Terence;mathematics;248;HBA +Machine Learning for Hackers;Conway, Drew;data science;233;O'Reilly +Signal and the Noise;Silver, Nate;data science;233;Penguin +Python for Data Analysis;McKinney, Wes;data science;233;O'Reilly +Introduction to Algorithms;Cormen, Thomas;computer science;234;MIT Press +Beautiful and the Damned;Deb, Siddhartha;nonfiction;198;Penguin +Outsider;Camus, Albert;fiction;198;Penguin +Complete Sherlock Holmes, The - Vol I;Doyle, Arthur Conan;fiction;176;Random House +Complete Sherlock Holmes, The - Vol II;Doyle, Arthur Conan;fiction;176;Random House +Wealth of Nations;Smith, Adam;economics;175;Random House +Pillars of the Earth;Follett, Ken;fiction;176;Random House +Mein Kampf;Hitler, Adolf;nonfiction;212;Rupa +Tao of Physics;Capra, Fritjof;science;179;Penguin +Surely You're Joking Mr Feynman;Feynman, Richard;science;198;Random House +Farewell to Arms, A;Hemingway, Ernest;fiction;179;Rupa +Veteran;Forsyth, Frederick;fiction;177;Transworld +False Impressions;Archer, Jeffery;fiction;177;Pan +Last Lecture;Pausch, Randy;nonfiction;197;Hyperion +Return of the Primitive;Rand, Ayn;philosophy;202;Penguin +Jurassic Park;Crichton, Michael;fiction;174;Random House +Russian Journal, A;Steinbeck, John;nonfiction;196;Penguin +Tales of Mystery and Imagination;Poe, Edgar Allen;fiction;172;HarperCollins +Freakonomics;Dubner, Stephen;economics;197;Penguin +Hidden Connections;Capra, Fritjof;science;197;HarperCollins +Story of Philosophy;Durant, Will;philosophy;170;Pocket +Asami Asami;Deshpande, P L;fiction;205;Mauj +Journal of a Novel;Steinbeck, John;fiction;196;Penguin +Once There Was a War;Steinbeck, John;nonfiction;196;Penguin +Moon is Down;Steinbeck, John;fiction;196;Penguin +Brethren;Grisham, John;fiction;174;Random House +In a Free State;Naipaul, V. S.;fiction;196;Rupa +Catch 22;Heller, Joseph;fiction;178;Random House +Complete Mastermind, The;BBC,nonfiction;178;BBC +Dylan on Dylan;Dylan, Bob;nonfiction;197;Random House +Soft Computing & Intelligent Systems;Gupta, Madan;data science;242;Elsevier +Textbook of Economic Theory;Stonier, Alfred;economics;242;Pearson +Econometric Analysis;Greene, W. H.;economics;242;Pearson +Learning OpenCV;Bradsky, Gary;data science;232;O'Reilly +Data Structures Using C & C++;Tanenbaum, Andrew;computer science;235;Prentice Hall +Computer Vision, A Modern Approach;Forsyth, David;data science;255;Pearson +Principles of Communication Systems;Taub, Schilling;computer science;240;TMH +Let Us C;Kanetkar, Yashwant;computer science;213;Prentice Hall +Amulet of Samarkand;Stroud, Jonathan;fiction;179;Random House +Crime and Punishment;Dostoevsky, Fyodor;fiction;180;Penguin +Angels & Demons;Brown, Dan;fiction;178;Random House +Argumentative Indian;Sen, Amartya;nonfiction;209;Picador +Sea of Poppies;Ghosh, Amitav;fiction;197;Penguin +Idea of Justice;Sen, Amartya;nonfiction;212;Penguin +Raisin in the Sun, A;Hansberry, Lorraine;fiction;175;Penguin +All the President's Men;Woodward, Bob;history;177;Random House +Prisoner of Birth, A;Archer, Jeffery;fiction;176;Pan +Scoop!;Nayar, Kuldip;history;216;HarperCollins +Ahe Manohar Tari;Deshpande, Sunita;nonfiction;213;Mauj +Last Mughal;Dalrymple, William;history;199;Penguin +Social Choice & Welfare, Vol 39 No. 1;Various;Economics;235;Springer +Radiowaril Bhashane & Shrutika;Deshpande, P L;nonfiction;213;Mauj +Gun Gayin Awadi;Deshpande, P L;nonfiction;212;Mauj +Aghal Paghal;Deshpande, P L;nonfiction;212;Mauj +Maqta-e-Ghalib;Garg, Sanjay;fiction;221;Mauj +Beyond Degrees ;nonfiction;222;HarperCollins +Manasa;Kale, V P;nonfiction;213;Mauj +India from Midnight to Milennium;Tharoor, Shashi;history;198;Penguin +World's Greatest Trials, The;;History;210; +Great Indian Novel;Tharoor, Shashi;fiction;198;Penguin +O Jerusalem!;Lapierre, Dominique;history;217;Vikas +City of Joy;Lapierre, Dominique;fiction;177;Vikas +Freedom at Midnight;Lapierre, Dominique;history;167;Vikas +Winter of Our Discontent;Steinbeck, John;fiction;196;Penguin +On Education;Russell, Bertrand;philosophy;203;Routledge +Free Will;Harris, Sam;philosophy;203;FreePress +Bookless in Baghdad;Tharoor, Shashi;nonfiction;206;Penguin +Case of the Lame Canary;Gardner, Earle Stanley;fiction;179; +Theory of Everything;Hawking, Stephen;science;217;Jaico +New Markets & Other Essays;Drucker, Peter;economics;176;Penguin +Electric Universe;Bodanis, David;science;201;Penguin +Hunchback of Notre Dame;Hugo, Victor;fiction;175;Random House +Burning Bright;Steinbeck, John;fiction;175;Penguin +Age of Discontuinity;Drucker, Peter;economics;178;Random House +Doctor in the Nude;Gordon, Richard;fiction;179;Penguin +Down and Out in Paris & London;Orwell, George;nonfiction;179;Penguin +Identity & Violence;Sen, Amartya;philosophy;219;Penguin +Beyond the Three Seas;Dalrymple, William;history;197;Random House +World's Greatest Short Stories, The;;Fiction;217;Jaico +Talking Straight;Iacoca, Lee;nonfiction;175; +Maugham's Collected Short Stories, Vol 3;Maugham, William S;fiction;171;Vintage +Phantom of Manhattan;Forsyth, Frederick;fiction;180; +Ashenden of The British Agent;Maugham, William S;fiction;160;Vintage +Zen & The Art of Motorcycle Maintenance;Pirsig, Robert;philosophy;172;Vintage +Great War for Civilization;Fisk, Robert;history;197;HarperCollins +We the Living;Rand, Ayn;fiction;178;Penguin +Artist and the Mathematician;Aczel, Amir;science;186;HighStakes +History of Western Philosophy;Russell, Bertrand;philosophy;213;Routledge +Selected Short Stories ;Fiction;215;Jaico +Rationality & Freedom;Sen, Amartya;economics;213;Springer +Clash of Civilizations and Remaking of the World Order;Huntington, Samuel;history;228;Simon&Schuster +Uncommon Wisdom;Capra, Fritjof;nonfiction;197;Fontana +One;Bach, Richard;nonfiction;172;Dell +Karl Marx Biography ;nonfiction;162; +To Sir With Love;Braithwaite;Fiction;197;Penguin +Half A Life;Naipaul, V S;fiction;196; +Discovery of India;Nehru, Jawaharlal;history;230; +Apulki;Deshpande, P L;nonfiction;211; +Unpopular Essays;Russell, Bertrand;philosophy;198; +Deceiver;Forsyth, Frederick;fiction;178; +Veil: Secret Wars of the CIA;Woodward, Bob;history;171; +Char Shabda;Deshpande, P L;nonfiction;214; +Rosy is My Relative;Durrell, Gerald;fiction;176; +Moon and Sixpence;Maugham, William S;fiction;180; +Political Philosophers ;Philosophy;162; +Short History of the World, A;Wells, H G;history;197; +Trembling of a Leaf;Maugham, William S;fiction;205; +Doctor on the Brain;Gordon, Richard;fiction;204; +Simpsons & Their Mathematical Secrets;Singh, Simon;science;233; +Pattern Classification;Duda, Hart;data science;241; +From Beirut to Jerusalem;Friedman, Thomas;history;202; +Code Book;Singh, Simon;science;197; +Age of the Warrior;Fisk, Robert;history;197; +Final Crisis ;Comic;257; +Killing Joke, The;;Comic;283; +Flashpoint ;Comic;265; +Batman Earth One ;Comic;265; +Crisis on Infinite Earths ;Comic;258; +Numbers Behind Numb3rs;Devlin, Keith;science;202; +Superman Earth One - 1;;Comic;259; +Superman Earth One - 2;;Comic;258; +Justice League: Throne of Atlantis ;Comic;258; +Justice League: The Villain's Journey ;Comic;258; +Death of Superman, The;;Comic;258; +History of the DC Universe ;Comic;258; +Batman: The Long Halloween ;Comic;258; +Life in Letters, A;Steinbeck, John;nonfiction;196; +Information;Gleick, James;science;233; +Journal of Economics, vol 106 No 3;;Economics;235; +Elements of Information Theory;Thomas, Joy;data science;229; +Power Electronics - Rashid;Rashid, Muhammad;computer science;235; +Power Electronics - Mohan;Mohan, Ned;computer science;237; +Neural Networks;Haykin, Simon;data science;240; +Grapes of Wrath;Steinbeck, John;fiction;196; +Vyakti ani Valli;Deshpande, P L;nonfiction;211; +Statistical Learning Theory;Vapnik, Vladimir;data science;228; +Empire of the Mughal - The Tainted Throne;Rutherford, Alex;history;180; +Empire of the Mughal - Brothers at War;Rutherford, Alex;history;180; +Empire of the Mughal - Ruler of the World;Rutherford, Alex;history;180; +Empire of the Mughal - The Serpent's Tooth;Rutherford, Alex;history;180; +Empire of the Mughal - Raiders from the North;Rutherford, Alex;history;180; +Mossad;Baz-Zohar, Michael;history;236; +Jim Corbett Omnibus;Corbett, Jim;nonfiction;223; +20000 Leagues Under the Sea;Verne, Jules;fiction;190; +Batatyachi Chal,Deshpande P L;Fiction;200; +Hafasavnuk,Deshpande P L;Fiction;211; +Urlasurla,Deshpande P L;Fiction;211; +Pointers in C;Kanetkar, Yashwant;computer science;213; +Cathedral and the Bazaar;Raymond, Eric;computer science;217; +Design with OpAmps;Franco, Sergio;computer science;240; +Think Complexity;Downey, Allen;data science;230; +Devil's Advocate;West, Morris;fiction;178; +Ayn Rand Answers;Rand, Ayn;philosophy;203; +Philosophy: Who Needs It;Rand, Ayn;philosophy;171; +World's Great Thinkers, The;;Philosophy;189; +Data Analysis with Open Source Tools;Janert, Phillip;data science;230; +Broca's Brain;Sagan, Carl;science;174; +Men of Mathematics;Bell, E T;mathematics;217; +Oxford book of Modern Science Writing;Dawkins, Richard;science;240; +Justice, Judiciary and Democracy;Ranjan, Sudhanshu;philosophy;224; +Arthashastra, The;Kautiyla;Philosophy;214; +We the People;Palkhivala;Philosophy;216; +We the Nation;Palkhivala;Philosophy;216; +Courtroom Genius, The;Sorabjee,nonfiction;217; +Dongri to Dubai;Zaidi, Hussain;nonfiction;216; +History of England, Foundation;Ackroyd, Peter;history;197; +City of Djinns;Dalrymple, William;history;198; +India's Legal System,Nariman,nonfiction;177; +More Tears to Cry;Sassoon, Jean;fiction;235; +Ropemaker;Dickinson, Peter;fiction;196; +Angels & Demons;Brown, Dan;fiction;170; +Judge, The;;Fiction;170; +Attorney, The;;Fiction;170; +Prince, The;Machiavelli;Philosophy;173; +Eyeless in Gaza;Huxley, Aldous;fiction;180; +Tales of Beedle the Bard;Rowling, J K;fiction;184; +Girl with the Dragon Tattoo;Larsson, Steig;fiction;179; +Girl who kicked the Hornet's Nest;Larsson, Steig;fiction;179; +Girl who played with Fire;Larsson, Steig;fiction;179; +Batman Handbook ;Comic;270; +Murphy's Law ;nonfiction;178; +Structure and Randomness;Tao, Terence;mathematics;252; +Image Processing with MATLAB;Eddins, Steve;signal processing;241; +Animal Farm;Orwell, George;fiction;180; +Idiot;Dostoevsky, Fyodor;fiction;197; +Christmas Carol, A;Dickens, Charles;fiction;196; \ No newline at end of file diff --git a/src/main/java/com/jesuspinar/booksearch/config/AppConfig.java b/src/main/java/com/jesuspinar/booksearch/config/AppConfig.java new file mode 100644 index 0000000..5a52f05 --- /dev/null +++ b/src/main/java/com/jesuspinar/booksearch/config/AppConfig.java @@ -0,0 +1,32 @@ +package com.jesuspinar.booksearch.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@ComponentScan(basePackages="com.jesuspinar.booksearch") +@PropertySource("classpath:/booksearch.properties") +public class AppConfig { + @Value("${file.path}") + public String file; + + @Value("${file.csv.separator}") + public String separator; + + @Value("${file.csv.list_separator}") + public String listSeparator; + + public String getFile() { + return file; + } + + public String getSeparator() { + return separator; + } + + public String getListSeparator() { + return listSeparator; + } +} diff --git a/src/main/java/com/jesuspinar/booksearch/controller/CsvParser.java b/src/main/java/com/jesuspinar/booksearch/controller/CsvParser.java new file mode 100644 index 0000000..85706f1 --- /dev/null +++ b/src/main/java/com/jesuspinar/booksearch/controller/CsvParser.java @@ -0,0 +1,36 @@ +package com.jesuspinar.booksearch.controller; + +import com.jesuspinar.booksearch.model.Book; +import org.springframework.util.ResourceUtils; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CsvParser { + + public static List readFile(final String path, final String separator, final String listSeparator) { + List result = new ArrayList<>(); + + try { + result = Files + .lines(Paths.get(ResourceUtils.getFile(path).toURI())) + .skip(1) + .map(line -> { + String[] values = line.split(separator); + return new Book(values[0], Arrays.asList(values[1].split(listSeparator)), values[2],values[3], values[4]); + }).collect(Collectors.toList()); + + } catch (Exception e) { + System.err.println("Error de lectura del fichero de datos: books.csv"); + System.exit(-1); + } + + return result; + + } + +} diff --git a/src/main/java/com/jesuspinar/booksearch/model/Book.java b/src/main/java/com/jesuspinar/booksearch/model/Book.java new file mode 100644 index 0000000..fa18664 --- /dev/null +++ b/src/main/java/com/jesuspinar/booksearch/model/Book.java @@ -0,0 +1,118 @@ +package com.jesuspinar.booksearch.model; + +import java.util.List; + +public class Book { + private static int AUTO_ID = 0; + + private long id; + private String title; + private List authors; + private String genre; + + private String height; + + private String publisher; + + public Book( String title, List authors, String genre,String height, String publisher) { + this.id = AUTO_ID++; + this.title = title; + this.authors = authors; + this.genre = genre; + this.height = height; + this.publisher = publisher; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public List getAuthors() { + return authors; + } + + public void setAuthors(List authors) { + this.authors = authors; + } + + public String getGenre() { + return genre; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + public String getHeight() { + return height; + } + + public void setHeight(String height) { + this.height = height; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((authors == null) ? 0 : authors.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((title == null) ? 0 : title.hashCode()); + result = prime * result + ((genre == null) ? 0 : genre.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Book other = (Book) obj; + if (authors == null) { + if (other.authors != null) + return false; + } else if (!authors.equals(other.authors)) + return false; + if (id != other.id) + return false; + if (title == null) { + if (other.title != null) + return false; + } else if (!title.equals(other.title)) + return false; + if (genre == null) { + if (other.genre != null) + return false; + } else if (!genre.equals(other.genre)) + return false; + return true; + } + + @Override + public String toString() { + return "Book [id=" + id + ", title=" + title + ", authors=" + authors + ", genre=" + genre + "]"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/booksearch.properties b/src/main/resources/booksearch.properties new file mode 100644 index 0000000..aeb6c2b --- /dev/null +++ b/src/main/resources/booksearch.properties @@ -0,0 +1,3 @@ +file.path=classpath:books.csv +file.csv.separator=; +file.csv.list_separator=,