-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft of Seller and Finding persistence
- Loading branch information
1 parent
49e530f
commit ff37f5e
Showing
20 changed files
with
389 additions
and
153 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
hawk/src/main/java/io/irw/hawk/dto/ebay/EbayHighlightDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.irw.hawk.dto.ebay; | ||
|
||
import io.irw.hawk.dto.merchandise.HawkScrapeRunDto; | ||
import io.irw.hawk.scraper.model.MerchandiseVerdictType; | ||
import java.io.Serializable; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
/** | ||
* DTO for {@link io.irw.hawk.entity.EbayHighlight} | ||
*/ | ||
@Value | ||
@Builder | ||
public class EbayHighlightDto implements Serializable { | ||
|
||
Long id; | ||
HawkScrapeRunDto run; | ||
EbayFindingDto ebayFinding; | ||
MerchandiseVerdictType finalVerdict; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 20 additions & 9 deletions
29
hawk/src/main/java/io/irw/hawk/mapper/EbayHighlightMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
package io.irw.hawk.mapper; | ||
|
||
import io.irw.hawk.entity.EbayFinding; | ||
import io.irw.hawk.dto.ebay.EbayFindingDto; | ||
import io.irw.hawk.dto.ebay.EbayHighlightDto; | ||
import io.irw.hawk.dto.merchandise.HawkScrapeRunDto; | ||
import io.irw.hawk.entity.EbayHighlight; | ||
import io.irw.hawk.entity.HawkScrapeRun; | ||
import io.irw.hawk.scraper.model.MerchandiseMetadataDto; | ||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.Mappings; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
|
||
@Mapper(config = ConfigMapper.class) | ||
@Mapper(config = ConfigMapper.class, uses = {HawkScrapeRunMapper.class, EbayFindingMapper.class}) | ||
public interface EbayHighlightMapper { | ||
|
||
// @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, | ||
// @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, | ||
// nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
@Mappings({ | ||
@Mapping(target = "id", ignore = true), | ||
@Mapping(target = "run", source = "hawkScrapeRun"), | ||
@Mapping(target = "ebayFinding", source = "ebayFinding"), | ||
@Mapping(target = "finalVerdict", source = "merchandiseMetadataDto.finalVerdict"), | ||
@Mapping(target = "run", source = "hawkScrapeRunDto"), | ||
@Mapping(target = "ebayFinding", source = "ebayFindingDto"), | ||
@Mapping(target = "finalVerdict", source = "merchandiseMetadataDto.finalVerdict") | ||
}) | ||
EbayHighlight toEntity(MerchandiseMetadataDto merchandiseMetadataDto, HawkScrapeRun hawkScrapeRun, | ||
EbayFinding ebayFinding); | ||
EbayHighlightDto fromRuntime(HawkScrapeRunDto hawkScrapeRunDto, | ||
EbayFindingDto ebayFindingDto, MerchandiseMetadataDto merchandiseMetadataDto); | ||
|
||
|
||
EbayHighlight toEntity(EbayHighlightDto ebayHighlightDto); | ||
|
||
EbayHighlightDto toDto(EbayHighlight ebayHighlight); | ||
|
||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
EbayHighlight partialUpdate( | ||
EbayHighlightDto ebayHighlightDto, @MappingTarget EbayHighlight ebayHighlight); | ||
} |
44 changes: 44 additions & 0 deletions
44
hawk/src/main/java/io/irw/hawk/mapper/EbaySellerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.irw.hawk.mapper; | ||
|
||
import com.ebay.buy.browse.model.Seller; | ||
import io.irw.hawk.dto.ebay.EbaySellerDto; | ||
import io.irw.hawk.entity.EbaySeller; | ||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.Named; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
|
||
@Mapper(config = ConfigMapper.class) | ||
public interface EbaySellerMapper { | ||
|
||
EbaySeller toEntity(EbaySellerDto ebaySellerDto); | ||
|
||
EbaySellerDto toDto(EbaySeller ebaySeller); | ||
|
||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
EbaySeller partialUpdate( | ||
EbaySellerDto ebaySellerDto, @MappingTarget EbaySeller ebaySeller); | ||
|
||
@Mapping(target = "reputationPercentage", source = "feedbackPercentage", qualifiedByName = "stringToFloat") | ||
@Mapping(target = "feedbackScore", source = "feedbackScore") | ||
@Mapping(target = "id", ignore = true) | ||
@Mapping(target = "ebayIdStr", source = "username") | ||
@Mapping(target = "registeredOn", ignore = true) // TODO: set from seller info | ||
EbaySellerDto sellerToEbaySellerDto(Seller seller); | ||
|
||
@Mapping(target = "id", ignore = true) | ||
@Mapping(target = "ebayIdStr", ignore = true) | ||
@Mapping(target = "registeredOn", ignore = true) | ||
EbaySeller updateSellerEntity(@MappingTarget EbaySeller persistentSellerEntity, EbaySellerDto latestSellerDto); | ||
|
||
@Named("stringToFloat") | ||
default float stringToFloat(String value) { | ||
try { | ||
return Float.parseFloat(value); | ||
} catch (NumberFormatException e) { | ||
return 0.0f; // or some default value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
hawk/src/main/java/io/irw/hawk/repository/EbaySellerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package io.irw.hawk.repository; | ||
|
||
import io.irw.hawk.entity.EbaySeller; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface EbaySellerRepository extends JpaRepository<EbaySeller, Long> { | ||
|
||
Optional<EbaySeller> findByEbayIdStr(String ebayIdStr); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
hawk/src/main/java/io/irw/hawk/scraper/service/domain/EbaySellerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.irw.hawk.scraper.service.domain; | ||
|
||
import io.irw.hawk.dto.ebay.EbaySellerDto; | ||
import io.irw.hawk.entity.EbaySeller; | ||
import io.irw.hawk.mapper.EbaySellerMapper; | ||
import io.irw.hawk.repository.EbaySellerRepository; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
@Service | ||
@Slf4j | ||
public class EbaySellerService { | ||
|
||
EbaySellerMapper ebaySellerMapper; | ||
EbaySellerRepository ebaySellerRepository; | ||
|
||
@Transactional | ||
public EbaySellerDto saveSeller(EbaySellerDto ebaySellerDto) { | ||
EbaySeller persisted = ebaySellerRepository.save(ebaySellerMapper.toEntity(ebaySellerDto)); | ||
return ebaySellerMapper.toDto(persisted); | ||
} | ||
|
||
@Transactional | ||
public EbaySellerDto upsertSeller(EbaySellerDto ebaySellerDto) { | ||
return ebaySellerRepository.findByEbayIdStr(ebaySellerDto.getEbayIdStr()) | ||
.map(existingSeller -> { | ||
EbaySeller updatedSeller = ebaySellerRepository.save( | ||
ebaySellerMapper.updateSellerEntity(existingSeller,ebaySellerDto)); | ||
return ebaySellerMapper.toDto(updatedSeller); | ||
}) | ||
.orElseGet(() -> saveSeller(ebaySellerDto)); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
hawk/src/main/java/io/irw/hawk/scraper/service/matchers/ItemAlreadyPersistedDataMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.irw.hawk.scraper.service.matchers; | ||
|
||
import io.irw.hawk.dto.merchandise.ProductVariantEnum; | ||
import io.irw.hawk.scraper.model.ProcessingPipelineStep; | ||
import io.irw.hawk.scraper.service.extractors.PieceCountExtractor; | ||
import io.irw.hawk.scraper.service.extractors.PriceExtractor; | ||
import io.irw.hawk.scraper.service.extractors.ShippingCostExtractor; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Virtual matcher that checks that basic fields are populated. This matcher is intended to be used as a common | ||
* dependency for more advanced matchers (instead of listing all other dependencies separately) | ||
*/ | ||
@RequiredArgsConstructor | ||
@Service | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
@Slf4j | ||
public class ItemAlreadyPersistedDataMatcher implements ItemSummaryMatcher { | ||
|
||
|
||
|
||
@Override | ||
public List<Class<? extends ProcessingPipelineStep>> dependsOn() { | ||
return List.of(BaselineItemDataMatcher.class); | ||
} | ||
|
||
@Override | ||
public boolean isApplicableTo(ProductVariantEnum productVariant) { | ||
return true; | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
hawk/src/main/java/io/irw/hawk/scraper/service/processors/ProductScrapeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package io.irw.hawk.scraper.service.processors; | ||
|
||
import io.irw.hawk.dto.merchandise.HawkScrapeRunDto; | ||
import io.irw.hawk.dto.ebay.SearchTermDto; | ||
import io.irw.hawk.dto.merchandise.ProductVariantEnum; | ||
import java.util.List; | ||
|
||
public interface ProductScrapeProcessor { | ||
|
||
boolean supports(ProductVariantEnum productVariant); | ||
|
||
void process(HawkScrapeRunDto hawkScrapeRunDto); | ||
List<SearchTermDto> generateSearchTerms(ProductVariantEnum productVariant); | ||
|
||
} |
Oops, something went wrong.