-
Notifications
You must be signed in to change notification settings - Fork 3
/
EnrichedListingEvent.java
58 lines (49 loc) · 1.96 KB
/
EnrichedListingEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//------------------------------------------------------------------
// Copyright 2020 mobile.de GmbH.
// Author/Developer: Philipp Bartsch
//
// This code is licensed under MIT license (see LICENSE for details)
//------------------------------------------------------------------
package org.example.move.webhookreceiver.rest.listing;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import ecg.move.sellermodel.dealer.DealerLogMessageV2;
import ecg.move.sellermodel.listing.Listing;
import ecg.move.sellermodel.promotion.PublicPromotionShortModel;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.move.webhookreceiver.cpo.OemVerifiedCpo;
import org.example.move.webhookreceiver.movemodel.listing.ListingBeforeAfter;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class EnrichedListingEvent implements IsListing {
@JsonProperty("listing")
private ListingBeforeAfter beforeAfter;
@JsonProperty("dealer")
private DealerLogMessageV2 dealer;
@JsonProperty("promotions")
private PublicPromotionShortModel[] promotions;
@JsonProperty("oemVerifiedCpo")
private OemVerifiedCpo oemVerifiedCpo;
@JsonIgnore
public String getForeignId() {
return Optional.ofNullable(getMostRecentListing()).map(Listing::getForeignId).orElse(null);
}
@JsonIgnore
public String getEntityId() {
return Optional.ofNullable(getMostRecentListing()).map(Listing::getId).orElse(null);
}
@JsonIgnore
private Listing getMostRecentListing() {
return getBeforeAfter().getNewState() != null ? getBeforeAfter().getNewState() : getBeforeAfter().getOldState();
}
}