Skip to content

Commit

Permalink
feat: update importer
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jan 13, 2024
1 parent 9384073 commit b34e5a0
Show file tree
Hide file tree
Showing 20 changed files with 670 additions and 622 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
Expand All @@ -24,14 +23,18 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import ch.xxx.aidoclibchat.domain.client.ImportClient;
import ch.xxx.aidoclibchat.domain.model.dto.AmazonProductDto;
import ch.xxx.aidoclibchat.domain.model.dto.ProductDto;
import ch.xxx.aidoclibchat.domain.model.dto.SupermarketDto;
import ch.xxx.aidoclibchat.domain.model.dto.ZipcodeDto;
import ch.xxx.aidoclibchat.domain.model.dto.ArtistDto;
import ch.xxx.aidoclibchat.domain.model.dto.MuseumDto;
import ch.xxx.aidoclibchat.domain.model.dto.MuseumHoursDto;
import ch.xxx.aidoclibchat.domain.model.dto.SubjectDto;
import ch.xxx.aidoclibchat.domain.model.dto.WorkDto;
import ch.xxx.aidoclibchat.domain.model.dto.WorkLinkDto;
import ch.xxx.aidoclibchat.domain.model.entity.Artist;
import ch.xxx.aidoclibchat.domain.model.entity.Museum;
import ch.xxx.aidoclibchat.domain.model.entity.MuseumHours;
import ch.xxx.aidoclibchat.domain.model.entity.Subject;
import ch.xxx.aidoclibchat.domain.model.entity.Work;
import ch.xxx.aidoclibchat.domain.model.entity.WorkLink;
import ch.xxx.aidoclibchat.usecase.mapping.TableMapper;

@Component
Expand All @@ -45,12 +48,13 @@ public ImportRestClient(TableMapper tableMapper) {
this.csvMapper.registerModule(new JavaTimeModule());
}

public List<Work> importZipcodes() {
@Override
public List<Artist> importArtists() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/retailData/zipcodes.csv")
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/artist.csv")
.retrieve().body(String.class);
return this.mapString(result, ZipcodeDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
return this.mapString(result, ArtistDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}

private <T> List<T> mapString(String result, Class<T> myClass) {
Expand All @@ -64,29 +68,48 @@ private <T> List<T> mapString(String result, Class<T> myClass) {
return zipcodes;
}

public List<MuseumHours> importSupermarkets() {
@Override
public List<Museum> importMuseums() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/retailData/supermarket-1day-45zips.csv")
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/museum.csv")
.retrieve().body(String.class);
return this.mapString(result, SupermarketDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
return this.mapString(result, MuseumDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}

public List<Artist> importAmazonProducts() {
@Override
public List<MuseumHours> importMuseumHours() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/retailData/amazon_compare.csv")
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/museum_hours.csv")
.retrieve().body(String.class);
return this.mapString(result, AmazonProductDto.class).stream().map(myDto -> this.tableMapper.map(myDto))
.filter(Optional::isPresent).map(Optional::get).toList();
return this.mapString(result, MuseumHoursDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}

public List<Museum> importProducts() {
@Override
public List<Work> importWorks() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/retailData/online_offline_ALL_clean.csv")
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/work.csv")
.retrieve().body(String.class);
return this.mapString(result, ProductDto.class).stream().map(myDto -> this.tableMapper.map(myDto))
.filter(Optional::isPresent).map(Optional::get).toList();
return this.mapString(result, WorkDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}

@Override
public List<Subject> importSubjects() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/subject.csv")
.retrieve().body(String.class);
return this.mapString(result, SubjectDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}

@Override
public List<WorkLink> importWorkLinks() {
RestClient restClient = RestClient.create();
String result = restClient.get().uri(
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/subject.csv")
.retrieve().body(String.class);
return this.mapString(result, WorkLinkDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.adapter.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import ch.xxx.aidoclibchat.domain.model.entity.WorkLink;

public interface JpaWorkLinkRepository extends JpaRepository<WorkLink, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2023 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.aidoclibchat.adapter.repository;

import java.util.List;

import org.springframework.stereotype.Repository;

import ch.xxx.aidoclibchat.domain.model.entity.WorkLink;
import ch.xxx.aidoclibchat.domain.model.entity.WorkLinkRepository;

@Repository
public class WorkLinkRepositoryBean implements WorkLinkRepository {
private JpaWorkLinkRepository jpaWorkLinkRepository;

public WorkLinkRepositoryBean(JpaWorkLinkRepository jpaWorkLinkRepository) {
this.jpaWorkLinkRepository = jpaWorkLinkRepository;
}

@Override
public List<WorkLink> saveAll(Iterable<WorkLink> entities) {
return this.jpaWorkLinkRepository.saveAll(entities);
}

@Override
public void deleteAll() {
this.jpaWorkLinkRepository.deleteAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
import ch.xxx.aidoclibchat.domain.model.entity.Artist;
import ch.xxx.aidoclibchat.domain.model.entity.Museum;
import ch.xxx.aidoclibchat.domain.model.entity.MuseumHours;
import ch.xxx.aidoclibchat.domain.model.entity.Subject;
import ch.xxx.aidoclibchat.domain.model.entity.Work;
import ch.xxx.aidoclibchat.domain.model.entity.WorkLink;

public interface ImportClient {
List<Work> importZipcodes();
List<MuseumHours> importSupermarkets();
List<Artist> importAmazonProducts();
List<Museum> importProducts();
List<Artist> importArtists();
List<Museum> importMuseums();
List<MuseumHours> importMuseumHours();
List<Work> importWorks();
List<Subject> importSubjects();
List<WorkLink> importWorkLinks();
}

This file was deleted.

Loading

0 comments on commit b34e5a0

Please sign in to comment.