-
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.
persist highlights, refactor metadata
- Loading branch information
1 parent
76fbaf7
commit a2ca875
Showing
40 changed files
with
385 additions
and
293 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
hawk/src/main/java/io/irw/hawk/configuration/PersistenceConfiguration.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,5 @@ | ||
package io.irw.hawk.configuration; | ||
|
||
public class PersistenceConfiguration { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...rw/hawk/dto/ebay/EbayListingTypeEnum.java → ...w/hawk/dto/ebay/EbayBuyingOptionEnum.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
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
25 changes: 16 additions & 9 deletions
25
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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
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 io.irw.hawk.dto.merchandise.MerchandiseVerdictType; | ||
import io.irw.hawk.scraper.model.ProcessingPipelineMetadata; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
|
||
/** | ||
* DTO for {@link io.irw.hawk.entity.EbayHighlight} | ||
*/ | ||
@Value | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Data | ||
@Builder | ||
public class EbayHighlightDto implements Serializable { | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
public class EbayHighlightDto { | ||
|
||
Long id; | ||
HawkScrapeRunDto run; | ||
EbayFindingDto ebayFinding; | ||
ProcessingPipelineMetadata pipelineMetadata; | ||
MerchandiseVerdictType finalVerdict; | ||
} | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...scraper/model/MerchandiseVerdictType.java → ...o/merchandise/MerchandiseVerdictType.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
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
31 changes: 31 additions & 0 deletions
31
hawk/src/main/java/io/irw/hawk/entity/type/CustomObjectMapperSupplier.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,31 @@ | ||
package io.irw.hawk.entity.type; | ||
|
||
import com.fasterxml.jackson.core.Version; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.fasterxml.jackson.databind.util.StdDateFormat; | ||
import io.hypersistence.utils.hibernate.type.util.ObjectMapperSupplier; | ||
|
||
public class CustomObjectMapperSupplier | ||
implements ObjectMapperSupplier { | ||
|
||
@Override | ||
public ObjectMapper get() { | ||
ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules(); | ||
|
||
// Configure it to use ISO 8601 date format for serialization | ||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
objectMapper.setDateFormat(new StdDateFormat()); | ||
|
||
SimpleModule customBigDecimalMoneyModule = new SimpleModule( | ||
"CustomBigDecimalMoneyModule", | ||
new Version(1, 0, 0, null, null, null) | ||
); | ||
customBigDecimalMoneyModule.addSerializer(new MoneySerializer()); | ||
|
||
objectMapper.registerModule(customBigDecimalMoneyModule); | ||
|
||
return objectMapper; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
hawk/src/main/java/io/irw/hawk/entity/type/MoneySerializer.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,27 @@ | ||
package io.irw.hawk.entity.type; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
|
||
public class MoneySerializer | ||
extends JsonSerializer<BigDecimal> { | ||
|
||
@Override | ||
public void serialize( | ||
BigDecimal value, | ||
JsonGenerator jsonGenerator, | ||
SerializerProvider provider) | ||
throws IOException { | ||
jsonGenerator.writeString( | ||
value.setScale(2, BigDecimal.ROUND_HALF_UP).toString() | ||
); | ||
} | ||
|
||
@Override | ||
public Class<BigDecimal> handledType() { | ||
return BigDecimal.class; | ||
} | ||
} |
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
37 changes: 0 additions & 37 deletions
37
hawk/src/main/java/io/irw/hawk/scraper/model/MerchandiseMetadataDto.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
hawk/src/main/java/io/irw/hawk/scraper/model/MerchandiseReasoningDto.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
hawk/src/main/java/io/irw/hawk/scraper/model/MerchandiseReasoningLog.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,24 @@ | ||
package io.irw.hawk.scraper.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import io.irw.hawk.dto.merchandise.MerchandiseVerdictType; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder | ||
@NoArgsConstructor | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
@JsonTypeName("merchandiseReasoning") | ||
public class MerchandiseReasoningLog extends PipelineStepLog { | ||
|
||
String reasoningMatcher; | ||
MerchandiseVerdictType verdict; | ||
String reason; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
hawk/src/main/java/io/irw/hawk/scraper/model/PipelineStepLog.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,25 @@ | ||
package io.irw.hawk.scraper.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import java.time.Instant; | ||
import lombok.Builder.Default; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@SuperBuilder | ||
@Data | ||
@NoArgsConstructor | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = MerchandiseReasoningLog.class, name = "merchandiseReasoning"), | ||
// other subclasses | ||
}) | ||
public class PipelineStepLog { | ||
|
||
@Default | ||
Instant timestamp = Instant.now(); | ||
String message; | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
hawk/src/main/java/io/irw/hawk/scraper/model/ProcessingPipelineMetadata.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,52 @@ | ||
package io.irw.hawk.scraper.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Builder.Default; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Data | ||
@Builder | ||
@FieldDefaults(level = AccessLevel.PRIVATE) | ||
public class ProcessingPipelineMetadata { | ||
|
||
@Default | ||
List<ProcessingPipelineStepMetadata> pipelineStepMetadata = new ArrayList<>(); | ||
|
||
public void newStep(Class<? extends ProcessingPipelineStep> processingPipelineStep) { | ||
pipelineStepMetadata.add(ProcessingPipelineStepMetadata.builder() | ||
.pipelineStepClass(processingPipelineStep) | ||
.build()); | ||
} | ||
|
||
public void addReasoning(MerchandiseReasoningLog reasoningDto) { | ||
getLastPipelineStep().getLog().add(reasoningDto); | ||
} | ||
|
||
|
||
|
||
public void addLog(String message) { | ||
getLastPipelineStep().getLog().add(PipelineStepLog.builder() | ||
.message(message) | ||
.build()); | ||
} | ||
|
||
public List<MerchandiseReasoningLog> filterReasoningsFromLog() { //retrieve from logs by instanceof | ||
return getLastPipelineStep().getLog().stream() | ||
.filter(MerchandiseReasoningLog.class::isInstance) | ||
.map(MerchandiseReasoningLog.class::cast) | ||
.toList(); | ||
} | ||
|
||
private ProcessingPipelineStepMetadata getLastPipelineStep() { | ||
return pipelineStepMetadata.get(pipelineStepMetadata.size() - 1); | ||
} | ||
|
||
} |
Oops, something went wrong.