41
41
public class ImportRestClient implements ImportClient {
42
42
private final CsvMapper csvMapper ;
43
43
private final TableMapper tableMapper ;
44
+ private final RestClient restClient ;
44
45
45
- public ImportRestClient (TableMapper tableMapper ) {
46
+ public ImportRestClient (TableMapper tableMapper , RestClient restClient ) {
46
47
this .tableMapper = tableMapper ;
48
+ this .restClient = restClient ;
47
49
this .csvMapper = new CsvMapper ();
48
50
this .csvMapper .registerModule (new JavaTimeModule ());
49
51
}
50
52
51
53
@ Override
52
54
public List <Artist > importArtists () {
53
- RestClient restClient = RestClient .create ();
54
- String result = restClient .get ().uri (
55
+ String result = this .restClient .get ().uri (
55
56
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/artist.csv" )
56
57
.retrieve ().body (String .class );
57
58
return this .mapString (result , ArtistDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
@@ -70,44 +71,39 @@ private <T> List<T> mapString(String result, Class<T> myClass) {
70
71
71
72
@ Override
72
73
public List <Museum > importMuseums () {
73
- RestClient restClient = RestClient .create ();
74
- String result = restClient .get ().uri (
74
+ String result = this .restClient .get ().uri (
75
75
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/museum.csv" )
76
76
.retrieve ().body (String .class );
77
77
return this .mapString (result , MuseumDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
78
78
}
79
79
80
80
@ Override
81
81
public List <MuseumHours > importMuseumHours () {
82
- RestClient restClient = RestClient .create ();
83
- String result = restClient .get ().uri (
82
+ String result = this .restClient .get ().uri (
84
83
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/museum_hours.csv" )
85
84
.retrieve ().body (String .class );
86
85
return this .mapString (result , MuseumHoursDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
87
86
}
88
87
89
88
@ Override
90
89
public List <Work > importWorks () {
91
- RestClient restClient = RestClient .create ();
92
- String result = restClient .get ().uri (
90
+ String result = this .restClient .get ().uri (
93
91
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/work.csv" )
94
92
.retrieve ().body (String .class );
95
93
return this .mapString (result , WorkDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
96
94
}
97
95
98
96
@ Override
99
97
public List <Subject > importSubjects () {
100
- RestClient restClient = RestClient .create ();
101
- String result = restClient .get ().uri (
98
+ String result = this .restClient .get ().uri (
102
99
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/subject.csv" )
103
100
.retrieve ().body (String .class );
104
101
return this .mapString (result , SubjectDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
105
102
}
106
103
107
104
@ Override
108
105
public List <WorkLink > importWorkLinks () {
109
- RestClient restClient = RestClient .create ();
110
- String result = restClient .get ().uri (
106
+ String result = this .restClient .get ().uri (
111
107
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/work_link.csv" )
112
108
.retrieve ().body (String .class );
113
109
return this .mapString (result , WorkLinkDto .class ).stream ().map (myDto -> this .tableMapper .map (myDto )).toList ();
0 commit comments