From b34e5a08495dcb2a91d9dddd70c4480ac9adf654 Mon Sep 17 00:00:00 2001 From: Angular2guy Date: Sat, 13 Jan 2024 14:37:21 +0100 Subject: [PATCH] feat: update importer --- .../adapter/client/ImportRestClient.java | 61 ++++-- .../repository/JpaWorkLinkRepository.java | 21 ++ .../repository/WorkLinkRepositoryBean.java | 39 ++++ .../domain/client/ImportClient.java | 12 +- .../domain/model/dto/AmazonProductDto.java | 179 ---------------- .../domain/model/dto/ArtistDto.java | 87 ++++++++ .../domain/model/dto/MuseumDto.java | 91 +++++++++ .../domain/model/dto/MuseumHoursDto.java | 45 ++++ .../domain/model/dto/ProductDto.java | 193 ------------------ .../domain/model/dto/SubjectDto.java | 34 +++ .../domain/model/dto/SupermarketDto.java | 58 ------ .../domain/model/dto/WorkDto.java | 75 +++++++ .../domain/model/dto/WorkLinkDto.java | 67 ++++++ .../domain/model/dto/ZipcodeDto.java | 65 ------ .../domain/model/entity/MuseumHoursId.java | 27 +++ .../model/entity/WorkLinkRepository.java | 20 ++ .../usecase/mapping/TableMapper.java | 141 ++++++------- .../usecase/service/ImportService.java | 53 +++-- .../usecase/service/TableService.java | 14 +- .../dbchangelog/changes/db.changelog-2.xml | 10 +- 20 files changed, 670 insertions(+), 622 deletions(-) create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/JpaWorkLinkRepository.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/WorkLinkRepositoryBean.java delete mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/AmazonProductDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ArtistDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumHoursDto.java delete mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ProductDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SubjectDto.java delete mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SupermarketDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkLinkDto.java delete mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ZipcodeDto.java create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/WorkLinkRepository.java diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/ImportRestClient.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/ImportRestClient.java index 1520e0d..4270949 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/ImportRestClient.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/ImportRestClient.java @@ -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; @@ -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 @@ -45,12 +48,13 @@ public ImportRestClient(TableMapper tableMapper) { this.csvMapper.registerModule(new JavaTimeModule()); } - public List importZipcodes() { + @Override + public List 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 List mapString(String result, Class myClass) { @@ -64,29 +68,48 @@ private List mapString(String result, Class myClass) { return zipcodes; } - public List importSupermarkets() { + @Override + public List 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 importAmazonProducts() { + @Override + public List 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 importProducts() { + @Override + public List 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 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 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(); } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/JpaWorkLinkRepository.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/JpaWorkLinkRepository.java new file mode 100644 index 0000000..82e61c2 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/JpaWorkLinkRepository.java @@ -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 { + +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/WorkLinkRepositoryBean.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/WorkLinkRepositoryBean.java new file mode 100644 index 0000000..6746218 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/WorkLinkRepositoryBean.java @@ -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 saveAll(Iterable entities) { + return this.jpaWorkLinkRepository.saveAll(entities); + } + + @Override + public void deleteAll() { + this.jpaWorkLinkRepository.deleteAll(); + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/client/ImportClient.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/client/ImportClient.java index 9e4add6..a593e40 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/client/ImportClient.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/client/ImportClient.java @@ -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 importZipcodes(); - List importSupermarkets(); - List importAmazonProducts(); - List importProducts(); + List importArtists(); + List importMuseums(); + List importMuseumHours(); + List importWorks(); + List importSubjects(); + List importWorkLinks(); } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/AmazonProductDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/AmazonProductDto.java deleted file mode 100644 index 33069f6..0000000 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/AmazonProductDto.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * 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.domain.model.dto; - -import java.time.LocalDate; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AmazonProductDto { - private String id; - @JsonProperty("date_amazon") - @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "M/d/yyyy") - private LocalDate dateAmazon; - @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "M/d/yyyy") - private LocalDate date; - private double price; - @JsonProperty("price_online") - private double priceOnline; - @JsonProperty("price_amazon") - private double priceAmazon; - @JsonProperty("sale_online") - private int saleOnline; - @JsonProperty("product_online") - private String productOnline; - @JsonProperty("product_amazon") - private String productAmazon; - private String merchant; - @JsonProperty("URL") - private String url; - private int imputed; - @JsonProperty("COMMENTS") - private String comments; - @JsonProperty("PRICETYPE") - private String pricetype; - private int datediff; - @JsonProperty("cat_id") - private int catId; - private String category; - @JsonProperty("retailer_id") - private Long retailerId; - @JsonProperty("retailer_s") - private String retailerS; - - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public LocalDate getDateAmazon() { - return dateAmazon; - } - public void setDateAmazon(LocalDate dateAmazon) { - this.dateAmazon = dateAmazon; - } - public LocalDate getDate() { - return date; - } - public void setDate(LocalDate date) { - this.date = date; - } - public double getPrice() { - return price; - } - public void setPrice(double price) { - this.price = price; - } - public double getPriceOnline() { - return priceOnline; - } - public void setPriceOnline(double priceOnline) { - this.priceOnline = priceOnline; - } - public double getPriceAmazon() { - return priceAmazon; - } - public void setPriceAmazon(double priceAmazon) { - this.priceAmazon = priceAmazon; - } - public int isSaleOnline() { - return saleOnline; - } - public void setSaleOnline(int saleOnline) { - this.saleOnline = saleOnline; - } - public String getProductOnline() { - return productOnline; - } - public void setProductOnline(String productOnline) { - this.productOnline = productOnline; - } - public String getProductAmazon() { - return productAmazon; - } - public void setProductAmazon(String productAmazon) { - this.productAmazon = productAmazon; - } - public String getMerchant() { - return merchant; - } - public void setMerchant(String merchant) { - this.merchant = merchant; - } - public String getUrl() { - return url; - } - public void setUrl(String url) { - this.url = url; - } - public int getImputed() { - return imputed; - } - public void setImputed(int imputed) { - this.imputed = imputed; - } - public String getComments() { - return comments; - } - public void setComments(String comments) { - this.comments = comments; - } - public String getPricetype() { - return pricetype; - } - public void setPricetype(String pricetype) { - this.pricetype = pricetype; - } - public int getDatediff() { - return datediff; - } - public void setDatediff(int datediff) { - this.datediff = datediff; - } - public int getCatId() { - return catId; - } - public void setCatId(int catId) { - this.catId = catId; - } - public String getCategory() { - return category; - } - public void setCategory(String category) { - this.category = category; - } - public Long getRetailerId() { - return retailerId; - } - public void setRetailerId(Long retailerId) { - this.retailerId = retailerId; - } - public String getRetailerS() { - return retailerS; - } - public void setRetailerS(String retailerS) { - this.retailerS = retailerS; - } - - @Override - public String toString() { - return "AmazonProductDto [id=" + id + ", dateAmazon=" + dateAmazon + ", date=" + date + ", price=" + price - + ", priceOnline=" + priceOnline + ", priceAmazon=" + priceAmazon + ", saleOnline=" + saleOnline - + ", productOnline=" + productOnline + ", productAmazon=" + productAmazon + ", merchant=" + merchant - + ", url=" + url + ", imputed=" + imputed + ", comments=" + comments + ", pricetype=" + pricetype - + ", datediff=" + datediff + ", catId=" + catId + ", category=" + category + ", retailerId=" - + retailerId + ", retailerS=" + retailerS + "]"; - } -} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ArtistDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ArtistDto.java new file mode 100644 index 0000000..81c0171 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ArtistDto.java @@ -0,0 +1,87 @@ +/** + * 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.domain.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ArtistDto { + @JsonProperty("artist_id") + private Long id; + @JsonProperty("full_name") + private String fullName; + @JsonProperty("first_name") + private String firstName; + @JsonProperty("middle_names") + private String middleName; + @JsonProperty("last_name") + private String lastName; + private String nationality; + private String style; + private Integer birth; + private Integer death; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getFullName() { + return fullName; + } + public void setFullName(String fullName) { + this.fullName = fullName; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + public String getMiddleName() { + return middleName; + } + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public String getNationality() { + return nationality; + } + public void setNationality(String nationality) { + this.nationality = nationality; + } + public String getStyle() { + return style; + } + public void setStyle(String style) { + this.style = style; + } + public Integer getBirth() { + return birth; + } + public void setBirth(Integer birth) { + this.birth = birth; + } + public Integer getDeath() { + return death; + } + public void setDeath(Integer death) { + this.death = death; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumDto.java new file mode 100644 index 0000000..941fe89 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumDto.java @@ -0,0 +1,91 @@ +/** + * 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.domain.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MuseumDto { + @JsonProperty("MUSEUM_ID") + private Long id; + @JsonProperty("NAME") + private String name; + @JsonProperty("ADDRESS") + private String address; + @JsonProperty("CITY") + private String city; + @JsonProperty("STATE") + private String state; + @JsonProperty("POSTAL") + private String postal; + @JsonProperty("COUNTRY") + private String country; + @JsonProperty("PHONE") + private String phone; + @JsonProperty("URL") + private String url; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getCity() { + return city; + } + public void setCity(String city) { + this.city = city; + } + public String getState() { + return state; + } + public void setState(String state) { + this.state = state; + } + public String getPostal() { + return postal; + } + public void setPostal(String postal) { + this.postal = postal; + } + public String getCountry() { + return country; + } + public void setCountry(String country) { + this.country = country; + } + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumHoursDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumHoursDto.java new file mode 100644 index 0000000..1bb5213 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/MuseumHoursDto.java @@ -0,0 +1,45 @@ +/** + * 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.domain.model.dto; + +public class MuseumHoursDto { + private Long museumId; + private String day; + private String open; + private String close; + + public Long getMuseumId() { + return museumId; + } + public void setMuseumId(Long museumId) { + this.museumId = museumId; + } + public String getDay() { + return day; + } + public void setDay(String day) { + this.day = day; + } + public String getOpen() { + return open; + } + public void setOpen(String open) { + this.open = open; + } + public String getClose() { + return close; + } + public void setClose(String close) { + this.close = close; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ProductDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ProductDto.java deleted file mode 100644 index 7e32bb9..0000000 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ProductDto.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * 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.domain.model.dto; - -import java.time.LocalDate; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ProductDto { - private String id; - @JsonProperty("COUNTRY") - private String country; - private Long retailer; - @JsonProperty("retailer_s") - private String retailerS; - @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "M/d/yyyy") - private LocalDate date; - private int day; - private int month; - private int year; - private double price; - @JsonProperty("price_online") - private double priceOnline; - private int imputed; - @JsonProperty("DEVICEID") - private String deviceid; - @JsonProperty("TIME") - private String time; - @JsonProperty("ZIPCODE") - private String zipcode; - @JsonProperty("PHOTO") - private String photo; - @JsonProperty("OTHERSKUITEM") - private String otherskuitem; - @JsonProperty("COMMENTS") - private String comments; - @JsonProperty("PRICETYPE") - private String pricetype; - @JsonProperty("CODE") - private String code; - @JsonProperty("sale_online") - private String saleOnline; - @JsonProperty("country_s") - private String countryS; - - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getCountry() { - return country; - } - public void setCountry(String country) { - this.country = country; - } - public Long getRetailer() { - return retailer; - } - public void setRetailer(Long retailer) { - this.retailer = retailer; - } - public String getRetailerS() { - return retailerS; - } - public void setRetailerS(String retailerS) { - this.retailerS = retailerS; - } - public LocalDate getDate() { - return date; - } - public void setDate(LocalDate date) { - this.date = date; - } - public int getDay() { - return day; - } - public void setDay(int day) { - this.day = day; - } - public int getMonth() { - return month; - } - public void setMonth(int month) { - this.month = month; - } - public int getYear() { - return year; - } - public void setYear(int year) { - this.year = year; - } - public double getPrice() { - return price; - } - public void setPrice(double price) { - this.price = price; - } - public double getPriceOnline() { - return priceOnline; - } - public void setPriceOnline(double priceOnline) { - this.priceOnline = priceOnline; - } - public int getImputed() { - return imputed; - } - public void setImputed(int imputed) { - this.imputed = imputed; - } - public String getDeviceid() { - return deviceid; - } - public void setDeviceid(String deviceid) { - this.deviceid = deviceid; - } - public String getTime() { - return time; - } - public void setTime(String time) { - this.time = time; - } - public String getZipcode() { - return zipcode; - } - public void setZipcode(String zipcode) { - this.zipcode = zipcode; - } - public String getPhoto() { - return photo; - } - public void setPhoto(String photo) { - this.photo = photo; - } - public String getOtherskuitem() { - return otherskuitem; - } - public void setOtherskuitem(String otherskuitem) { - this.otherskuitem = otherskuitem; - } - public String getComments() { - return comments; - } - public void setComments(String comments) { - this.comments = comments; - } - public String getPricetype() { - return pricetype; - } - public void setPricetype(String pricetype) { - this.pricetype = pricetype; - } - public String getCode() { - return code; - } - public void setCode(String code) { - this.code = code; - } - public String getSaleOnline() { - return saleOnline; - } - public void setSaleOnline(String saleOnline) { - this.saleOnline = saleOnline; - } - public String getCountryS() { - return countryS; - } - public void setCountryS(String countryS) { - this.countryS = countryS; - } - - @Override - public String toString() { - return "ProductDto [id=" + id + ", country=" + country + ", retailer=" + retailer + ", retailerS=" + retailerS - + ", date=" + date + ", day=" + day + ", month=" + month + ", year=" + year + ", price=" + price - + ", priceOnline=" + priceOnline + ", imputed=" + imputed + ", deviceid=" + deviceid + ", time=" + time - + ", zipcode=" + zipcode + ", photo=" + photo + ", otherskuitem=" + otherskuitem + ", comments=" - + comments + ", pricetype=" + pricetype + ", code=" + code + ", saleOnline=" + saleOnline - + ", countryS=" + countryS + "]"; - } -} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SubjectDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SubjectDto.java new file mode 100644 index 0000000..445f54c --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SubjectDto.java @@ -0,0 +1,34 @@ +/** + * 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.domain.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SubjectDto { + @JsonProperty("work_id") + private Long workId; + private String subject; + + public Long getWorkId() { + return workId; + } + public void setWorkId(Long workId) { + this.workId = workId; + } + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SupermarketDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SupermarketDto.java deleted file mode 100644 index bef3cd9..0000000 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/SupermarketDto.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.domain.model.dto; - -public class SupermarketDto { - private Long id; - private double price; - private String zip; - private int prices; - private int zips; - - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } - public double getPrice() { - return price; - } - public void setPrice(double price) { - this.price = price; - } - public String getZip() { - return zip; - } - public void setZip(String zip) { - this.zip = zip; - } - public int getPrices() { - return prices; - } - public void setPrices(int prices) { - this.prices = prices; - } - public int getZips() { - return zips; - } - public void setZips(int zips) { - this.zips = zips; - } - - @Override - public String toString() { - return "SupermarketDto [id=" + id + ", price=" + price + ", zip=" + zip + ", prices=" + prices + ", zips=" - + zips + "]"; - } -} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkDto.java new file mode 100644 index 0000000..6ae90cd --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkDto.java @@ -0,0 +1,75 @@ +/** + * 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.domain.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WorkDto { + @JsonProperty("WORK_ID") + private Long id; + @JsonProperty("NAME") + private String name; + @JsonProperty("ARTIST_ID") + private Long artistId; + @JsonProperty("STYLE") + private String style; + @JsonProperty("MUSEUM_ID") + private Long museumId; + @JsonProperty("WIDTH") + private Integer width; + @JsonProperty("HEIGHT") + private Integer height; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Long getArtistId() { + return artistId; + } + public void setArtistId(Long artistId) { + this.artistId = artistId; + } + public String getStyle() { + return style; + } + public void setStyle(String style) { + this.style = style; + } + public Long getMuseumId() { + return museumId; + } + public void setMuseumId(Long museumId) { + this.museumId = museumId; + } + public Integer getWidth() { + return width; + } + public void setWidth(Integer width) { + this.width = width; + } + public Integer getHeight() { + return height; + } + public void setHeight(Integer height) { + this.height = height; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkLinkDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkLinkDto.java new file mode 100644 index 0000000..a4fc0b1 --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/WorkLinkDto.java @@ -0,0 +1,67 @@ +/** + * 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.domain.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WorkLinkDto { + @JsonProperty("WORK_ID") + private Long workId; + @JsonProperty("NAME") + private String name; + @JsonProperty("ARTIST_ID") + private Long artistId; + @JsonProperty("STYLE") + private String style; + @JsonProperty("MUSEUM_ID") + private Long museumId; + @JsonProperty("IMAGE_LINK") + private String imageLink; + + public Long getWorkId() { + return workId; + } + public void setWorkId(Long workId) { + this.workId = workId; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Long getArtistId() { + return artistId; + } + public void setArtistId(Long artistId) { + this.artistId = artistId; + } + public String getStyle() { + return style; + } + public void setStyle(String style) { + this.style = style; + } + public Long getMuseumId() { + return museumId; + } + public void setMuseumId(Long museumId) { + this.museumId = museumId; + } + public String getImageLink() { + return imageLink; + } + public void setImageLink(String imageLink) { + this.imageLink = imageLink; + } +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ZipcodeDto.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ZipcodeDto.java deleted file mode 100644 index 1b7d50f..0000000 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/ZipcodeDto.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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.domain.model.dto; - -public class ZipcodeDto { - private String zipcode; - private String zipcodetype; - private String city; - private String state; - private double lat = 0.0; - private double lgt = 0.0; - - public String getZipcode() { - return zipcode; - } - public void setZipcode(String zipcode) { - this.zipcode = zipcode; - } - public String getZipcodetype() { - return zipcodetype; - } - public void setZipcodetype(String zipcodetype) { - this.zipcodetype = zipcodetype; - } - public String getCity() { - return city; - } - public void setCity(String city) { - this.city = city; - } - public String getState() { - return state; - } - public void setState(String state) { - this.state = state; - } - public double getLat() { - return lat; - } - public void setLat(double lat) { - this.lat = lat; - } - public double getLgt() { - return lgt; - } - public void setLgt(double lgt) { - this.lgt = lgt; - } - - @Override - public String toString() { - return "ZipcodeDto [zipcode=" + zipcode + ", zipcodetype=" + zipcodetype + ", city=" + city + ", state=" + state - + ", lat=" + lat + ", lgt=" + lgt + "]"; - } -} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/MuseumHoursId.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/MuseumHoursId.java index 03f4aed..166f2f2 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/MuseumHoursId.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/MuseumHoursId.java @@ -12,6 +12,8 @@ */ package ch.xxx.aidoclibchat.domain.model.entity; +import java.util.Objects; + import jakarta.persistence.Embeddable; @Embeddable @@ -19,6 +21,14 @@ public class MuseumHoursId { private Long museumId; private String day; + public MuseumHoursId() { } + + public MuseumHoursId(Long museumId, String day) { + super(); + this.museumId = museumId; + this.day = day; + } + public Long getMuseumId() { return museumId; } @@ -31,4 +41,21 @@ public String getDay() { public void setDay(String day) { this.day = day; } + + @Override + public int hashCode() { + return Objects.hash(day, museumId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MuseumHoursId other = (MuseumHoursId) obj; + return Objects.equals(day, other.day) && Objects.equals(museumId, other.museumId); + } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/WorkLinkRepository.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/WorkLinkRepository.java new file mode 100644 index 0000000..ffb7a1a --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/entity/WorkLinkRepository.java @@ -0,0 +1,20 @@ +/** + * 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.domain.model.entity; + +import java.util.List; + +public interface WorkLinkRepository { + List saveAll(Iterable entities); + void deleteAll(); +} diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/mapping/TableMapper.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/mapping/TableMapper.java index 392c90a..ef23b21 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/mapping/TableMapper.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/mapping/TableMapper.java @@ -12,100 +12,87 @@ */ package ch.xxx.aidoclibchat.usecase.mapping; -import java.util.Optional; - import org.springframework.stereotype.Component; -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.MuseumHoursId; +import ch.xxx.aidoclibchat.domain.model.entity.Subject; import ch.xxx.aidoclibchat.domain.model.entity.Work; +import ch.xxx.aidoclibchat.domain.model.entity.WorkLink; @Component public class TableMapper { - public Work map(ZipcodeDto dto) { + public Work map(WorkDto dto) { var entity = new Work(); -// entity.setCity(dto.getCity()); -// entity.setLat(dto.getLat()); -// entity.setLgt(dto.getLgt()); -// entity.setState(dto.getState()); -// entity.setZipcode(dto.getZipcode()); -// entity.setZipcodetype(dto.getZipcodetype()); + entity.setArtistId(dto.getArtistId()); + entity.setHeight(dto.getHeight()); + entity.setId(dto.getId()); + entity.setMuseumId(dto.getMuseumId()); + entity.setName(dto.getName()); + entity.setStyle(dto.getStyle()); + entity.setWidth(dto.getWidth()); return entity; } - public MuseumHours map(SupermarketDto dto) { + public MuseumHours map(MuseumHoursDto dto) { var entity = new MuseumHours(); -// entity.setId(dto.getId()); -// entity.setPrice(dto.getPrice()); -// entity.setPrices(dto.getPrices()); -// entity.setZip(dto.getZip()); -// entity.setZips(dto.getZips()); + entity.setClose(dto.getClose()); + entity.setOpen(dto.getOpen()); + entity.setMuseumHoursId(new MuseumHoursId(dto.getMuseumId(), dto.getDay())); return entity; } - - public Optional map(ProductDto dto) { - var myOpt = Optional.of(new Museum()); - var entity = myOpt.get(); - try { -// entity.setCode(dto.getCode()); -// entity.setComments(dto.getComments()); -// entity.setCountry(dto.getCountry()); -// entity.setCountryS(dto.getCountryS()); -// entity.setDate(dto.getDate()); -// entity.setDay(dto.getDay()); -// entity.setDeviceid(dto.getDeviceid()); -// entity.setId(Long.parseLong(dto.getId())); -// entity.setImputed(dto.getImputed() == 1); -// entity.setMonth(dto.getMonth()); -// entity.setOtherskuitem(dto.getOtherskuitem()); -// entity.setPhoto(dto.getPhoto()); -// entity.setPrice(dto.getPrice()); -// entity.setPrice(dto.getPrice()); -// entity.setPriceOnline(dto.getPriceOnline()); -// entity.setPricetype(dto.getPricetype()); -// entity.setRetailer(dto.getRetailer()); -// entity.setRetailerS(dto.getRetailerS()); -// entity.setSaleOnline(Optional.ofNullable(dto.getSaleOnline()).stream().allMatch(myStr -> !myStr.isBlank())); -// entity.setTime(dto.getTime()); -// entity.setYear(dto.getYear()); -// entity.setZipcode(dto.getZipcode()); - } catch (Exception e) { - myOpt = Optional.empty(); - } - return myOpt; + + public Museum map(MuseumDto dto) { + var entity = new Museum(); + entity.setAddress(dto.getAddress()); + entity.setCity(dto.getCity()); + entity.setCountry(dto.getCountry()); + entity.setId(dto.getId()); + entity.setName(dto.getName()); + entity.setPhone(dto.getPhone()); + entity.setPostal(dto.getPostal()); + entity.setState(dto.getState()); + entity.setUrl(dto.getUrl()); + return entity; } - public Optional map(AmazonProductDto dto) { - var myOpt = Optional.of(new Artist()); - var entity = myOpt.get(); - try { -// entity.setCategory(dto.getCategory()); -// entity.setCatId(dto.getCatId()); -// entity.setComments(dto.getComments()); -// entity.setDate(dto.getDate()); -// entity.setDateAmazon(dto.getDateAmazon()); -// entity.setDatediff(dto.getDatediff()); -// entity.setId(Long.parseLong(dto.getId())); -// entity.setImputed(dto.getImputed() == 1); -// entity.setMerchant(dto.getMerchant()); -// entity.setPrice(dto.getPrice()); -// entity.setPriceAmazon(dto.getPriceAmazon()); -// entity.setPriceOnline(dto.getPriceOnline()); -// entity.setPricetype(dto.getPricetype()); -// entity.setProductAmazon(dto.getProductAmazon()); -// entity.setPriceOnline(dto.getPriceOnline()); -// entity.setRetailerId(dto.getRetailerId()); -// entity.setRetailerS(dto.getRetailerS()); -// entity.setSaleOnline(dto.isSaleOnline() == 1); -// entity.setUrl(dto.getUrl()); - }catch(Exception e) { - myOpt = Optional.empty(); - } - return myOpt; + public Artist map(ArtistDto dto) { + var entity = new Artist(); + entity.setBirth(dto.getBirth()); + entity.setDeath(dto.getDeath()); + entity.setFirstName(dto.getFirstName()); + entity.setFullName(dto.getFullName()); + entity.setId(dto.getId()); + entity.setLastName(dto.getLastName()); + entity.setMiddleName(dto.getMiddleName()); + entity.setNationality(dto.getNationality()); + entity.setStyle(dto.getStyle()); + return entity; + } + + public Subject map(SubjectDto dto) { + var entity = new Subject(); + entity.setSubject(dto.getSubject()); + entity.setWorkId(dto.getWorkId()); + return entity; + } + + public WorkLink map(WorkLinkDto dto) { + var entity = new WorkLink(); + entity.setArtistId(dto.getArtistId()); + entity.setImageLink(dto.getImageLink()); + entity.setMuseumId(dto.getMuseumId()); + entity.setName(dto.getName()); + entity.setStyle(dto.getStyle()); + entity.setWorkId(dto.getWorkId()); + return entity; } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImportService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImportService.java index 99a4b96..9966485 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImportService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImportService.java @@ -20,9 +20,13 @@ import ch.xxx.aidoclibchat.domain.model.entity.ArtistRepository; import ch.xxx.aidoclibchat.domain.model.entity.Museum; import ch.xxx.aidoclibchat.domain.model.entity.MuseumRepository; +import ch.xxx.aidoclibchat.domain.model.entity.Subject; +import ch.xxx.aidoclibchat.domain.model.entity.SubjectRepository; import ch.xxx.aidoclibchat.domain.model.entity.MuseumHours; import ch.xxx.aidoclibchat.domain.model.entity.MuseumHoursRepository; import ch.xxx.aidoclibchat.domain.model.entity.Work; +import ch.xxx.aidoclibchat.domain.model.entity.WorkLink; +import ch.xxx.aidoclibchat.domain.model.entity.WorkLinkRepository; import ch.xxx.aidoclibchat.domain.model.entity.WorkRepository; import jakarta.transaction.Transactional; import jakarta.transaction.Transactional.TxType; @@ -30,31 +34,40 @@ @Service @Transactional(value = TxType.REQUIRES_NEW) public class ImportService { - private final WorkRepository zipcodeRepository; - private final MuseumHoursRepository supermarketRepository; - private final MuseumRepository productRepository; - private final ArtistRepository amazonProductRepository; + private final WorkRepository workRepository; + private final MuseumHoursRepository museumHoursRepository; + private final MuseumRepository museumRepository; + private final ArtistRepository artistRepository; + private final SubjectRepository subjectRepository; + private final WorkLinkRepository workLinkRepository; + - public ImportService(WorkRepository zipcodeRepository, MuseumHoursRepository supermarketRepository, - MuseumRepository productRepository, ArtistRepository amazonProductRepository) { - this.zipcodeRepository = zipcodeRepository; - this.supermarketRepository = supermarketRepository; - this.productRepository = productRepository; - this.amazonProductRepository = amazonProductRepository; + public ImportService(WorkRepository zipcodeRepository, MuseumHoursRepository supermarketRepository,WorkLinkRepository workLinkRepository, + MuseumRepository productRepository, ArtistRepository amazonProductRepository, SubjectRepository subjectRepository) { + this.workRepository = zipcodeRepository; + this.museumHoursRepository = supermarketRepository; + this.museumRepository = productRepository; + this.artistRepository = amazonProductRepository; + this.subjectRepository = subjectRepository; + this.workLinkRepository = workLinkRepository; } public void deleteData() { - this.amazonProductRepository.deleteAll(); - this.supermarketRepository.deleteAll(); - this.productRepository.deleteAll(); - this.zipcodeRepository.deleteAll(); + this.subjectRepository.deleteAll(); + this.workLinkRepository.deleteAll(); + this.museumHoursRepository.deleteAll(); + this.workRepository.deleteAll(); + this.artistRepository.deleteAll(); + this.museumRepository.deleteAll(); } - public void saveAllData(List zipcodes, List supermarkets, List products, - List amazonProducts) { - this.zipcodeRepository.saveAll(zipcodes); - this.supermarketRepository.saveAll(supermarkets); - this.productRepository.saveAll(products); - this.amazonProductRepository.saveAll(amazonProducts); + public void saveAllData(List works, List museumHours, List museums, + List artists, List subjects, List workLinks) { + this.museumRepository.saveAll(museums); + this.artistRepository.saveAll(artists); + this.workRepository.saveAll(works); + this.museumHoursRepository.saveAll(museumHours); + this.subjectRepository.saveAll(subjects); + this.workLinkRepository.saveAll(workLinks); } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java index 7e6f66b..cb774fb 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java @@ -24,7 +24,9 @@ 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 jakarta.transaction.Transactional; @Service @@ -43,16 +45,18 @@ public TableService(ImportClient importClient, ImportService importService) { public void importData() { var start = new Date(); LOGGER.info("Import started."); - List zipcodes = this.importClient.importZipcodes(); - List supermarkets = this.importClient.importSupermarkets(); - List products = this.importClient.importProducts(); - List amazonProducts = this.importClient.importAmazonProducts(); + List artists = this.importClient.importArtists(); + List museums = this.importClient.importMuseums(); + List museumHours = this.importClient.importMuseumHours(); + List works = this.importClient.importWorks(); + List sujects = this.importClient.importSubjects(); + List workLinks = this.importClient.importWorkLinks(); LOGGER.info("Data fetched in {}ms", new Date().getTime() - start.getTime()); var deleteStart = new Date(); this.importService.deleteData(); LOGGER.info("Data deleted in {}ms", new Date().getTime() - deleteStart.getTime()); var saveStart = new Date(); - this.importService.saveAllData(zipcodes, supermarkets, products, amazonProducts); + //this.importService.saveAllData(zipcodes, supermarkets, products, amazonProducts); LOGGER.info("Data saved in {}ms", new Date().getTime() - saveStart.getTime()); LOGGER.info("Import done in {}ms.", new Date().getTime() - start.getTime()); } diff --git a/backend/src/main/resources/dbchangelog/changes/db.changelog-2.xml b/backend/src/main/resources/dbchangelog/changes/db.changelog-2.xml index 765bff5..e6fa12a 100644 --- a/backend/src/main/resources/dbchangelog/changes/db.changelog-2.xml +++ b/backend/src/main/resources/dbchangelog/changes/db.changelog-2.xml @@ -75,13 +75,19 @@ - + + + - + + +