-
Notifications
You must be signed in to change notification settings - Fork 9
Updated RI with location change #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
douradofrazer
wants to merge
1
commit into
master
Choose a base branch
from
location-change-475
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
91 changes: 75 additions & 16 deletions
91
tnt-service/src/main/java/org/dcsa/tnt/service/mapping/EventMapper.java
This file contains hidden or 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,31 +1,90 @@ | ||
| package org.dcsa.tnt.service.mapping; | ||
|
|
||
| import org.dcsa.tnt.domain.valueobjects.DomainEvent; | ||
| import org.dcsa.tnt.domain.valueobjects.EquipmentEvent; | ||
| import org.dcsa.tnt.domain.valueobjects.ShipmentEvent; | ||
| import org.dcsa.tnt.domain.valueobjects.TransportEvent; | ||
| import org.dcsa.tnt.transferobjects.EquipmentEventPayloadTO; | ||
| import org.dcsa.tnt.transferobjects.EventMetadataTO; | ||
| import org.dcsa.tnt.transferobjects.EventTO; | ||
| import org.dcsa.tnt.transferobjects.ShipmentEventPayloadTO; | ||
| import org.dcsa.tnt.transferobjects.TransportEventPayloadTO; | ||
| import org.dcsa.skernel.infrastructure.transferobject.AddressTO; | ||
| import org.dcsa.tnt.domain.valueobjects.*; | ||
| import org.dcsa.tnt.transferobjects.*; | ||
| import org.dcsa.tnt.transferobjects.enums.LocationType; | ||
| import org.mapstruct.Mapper; | ||
|
|
||
| @Mapper(componentModel = "spring") | ||
| public abstract class EventMapper { | ||
| public EventTO toDTO(DomainEvent event) { | ||
| return EventTO.builder() | ||
| .metadata(toMetadataTO(event)) | ||
| .payload(switch (event.getEventType()) { | ||
| case EQUIPMENT -> toEquipmentEventPayloadTO((EquipmentEvent) event); | ||
| case SHIPMENT -> toShipmentEventPayloadTO((ShipmentEvent) event); | ||
| case TRANSPORT -> toTransportEventPayloadTO((TransportEvent) event); | ||
| }) | ||
| .build(); | ||
| .metadata(toMetadataTO(event)) | ||
| .payload( | ||
| switch (event.getEventType()) { | ||
| case EQUIPMENT -> toEquipmentEventPayloadTO((EquipmentEvent) event); | ||
| case SHIPMENT -> toShipmentEventPayloadTO((ShipmentEvent) event); | ||
| case TRANSPORT -> toTransportEventPayloadTO((TransportEvent) event); | ||
| }) | ||
| .build(); | ||
| } | ||
|
|
||
| protected abstract EventMetadataTO toMetadataTO(DomainEvent event); | ||
|
|
||
| protected abstract EquipmentEventPayloadTO toEquipmentEventPayloadTO(EquipmentEvent event); | ||
|
|
||
| protected abstract ShipmentEventPayloadTO toShipmentEventPayloadTO(ShipmentEvent event); | ||
|
|
||
| protected abstract TransportEventPayloadTO toTransportEventPayloadTO(TransportEvent event); | ||
|
|
||
| protected LocationTO locationToLocationTO(Location location) { | ||
|
|
||
| LocationTO loc = null; | ||
|
|
||
| if (null != location) { | ||
|
|
||
| if (null != location.facilityCode()) { | ||
| loc = | ||
| FacilityLocationTO.builder() | ||
| .locationName(location.locationName()) | ||
| .locationType(LocationType.FACI) | ||
| .unLocationCode(location.UNLocationCode()) | ||
| .facilityCode(location.facilityCode()) | ||
| .facilityCodeListProvider(location.facilityCodeListProvider()) | ||
| .build(); | ||
|
|
||
| } else if (null != location.address()) { | ||
|
|
||
| Address address = location.address(); | ||
|
|
||
| return AddressLocationTO.builder() | ||
| .locationName(location.locationName()) | ||
| .locationType(LocationType.ADDR) | ||
| .address( | ||
| AddressTO.builder() | ||
| .name(address.name()) | ||
| .street(address.street()) | ||
| .streetNumber(address.streetNumber()) | ||
| .floor(address.floor()) | ||
| .postCode(address.postCode()) | ||
| .city(address.city()) | ||
| .stateRegion(address.stateRegion()) | ||
| .country(address.country()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| } else if (null != location.latitude() && null != location.longitude()) { | ||
|
|
||
| loc = | ||
| GeoLocationTO.builder() | ||
| .locationName(location.locationName()) | ||
| .locationType(LocationType.GEOL) | ||
| .latitude(location.latitude()) | ||
| .longitude(location.longitude()) | ||
| .build(); | ||
|
|
||
| } else { | ||
|
|
||
| loc = | ||
| UnLocationLocationTO.builder() | ||
| .locationName(location.locationName()) | ||
| .locationType(LocationType.UNLO) | ||
| .unLocationCode(location.UNLocationCode()) | ||
| .build(); | ||
| } | ||
| } | ||
|
|
||
| return loc; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/AddressLocationTO.java
This file contains hidden or 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,15 @@ | ||
| package org.dcsa.tnt.transferobjects; | ||
|
|
||
| import lombok.*; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.dcsa.skernel.infrastructure.transferobject.AddressTO; | ||
|
|
||
| @Data | ||
| @SuperBuilder(toBuilder = true) | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public final class AddressLocationTO extends LocationTO { | ||
| private AddressTO address; | ||
| } |
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/FacilityLocationTO.java
This file contains hidden or 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 org.dcsa.tnt.transferobjects; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.*; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.dcsa.skernel.infrastructure.transferobject.enums.FacilityCodeListProvider; | ||
|
|
||
| @Data | ||
| @SuperBuilder(toBuilder = true) | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public final class FacilityLocationTO extends LocationTO { | ||
| @JsonProperty("UNLocationCode") | ||
| @Size(max = 5) | ||
| private String unLocationCode; | ||
|
|
||
| @Size(max = 6) | ||
| private String facilityCode; | ||
|
|
||
| private FacilityCodeListProvider facilityCodeListProvider; | ||
| } |
19 changes: 19 additions & 0 deletions
19
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/GeoLocationTO.java
This file contains hidden or 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,19 @@ | ||
| package org.dcsa.tnt.transferobjects; | ||
|
|
||
| import jakarta.validation.constraints.Size; | ||
| import lombok.*; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| @Data | ||
| @SuperBuilder(toBuilder = true) | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public final class GeoLocationTO extends LocationTO { | ||
| @Size(max = 11) | ||
| private String latitude; | ||
|
|
||
| @Size(max = 11) | ||
| private String longitude; | ||
| } |
22 changes: 22 additions & 0 deletions
22
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/LocationTO.java
This file contains hidden or 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,22 @@ | ||
| package org.dcsa.tnt.transferobjects; | ||
|
|
||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.dcsa.tnt.transferobjects.enums.LocationType; | ||
|
|
||
| @JsonDeserialize(using = LocationTODeserializer.class) | ||
| @Data | ||
| @SuperBuilder(toBuilder = true) | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public abstract sealed class LocationTO | ||
| permits UnLocationLocationTO, FacilityLocationTO, AddressLocationTO, GeoLocationTO { | ||
| @Size(max = 100) | ||
| private String locationName; | ||
|
|
||
| private LocationType locationType; | ||
| } |
73 changes: 73 additions & 0 deletions
73
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/LocationTODeserializer.java
This file contains hidden or 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,73 @@ | ||
| package org.dcsa.tnt.transferobjects; | ||
|
|
||
| import com.fasterxml.jackson.core.JacksonException; | ||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||
| import com.fasterxml.jackson.databind.JsonDeserializer; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import java.io.IOException; | ||
| import org.dcsa.skernel.infrastructure.transferobject.AddressTO; | ||
| import org.dcsa.skernel.infrastructure.transferobject.enums.FacilityCodeListProvider; | ||
| import org.dcsa.tnt.transferobjects.enums.LocationType; | ||
|
|
||
|
|
||
| // Had to use a custom deserializer as the @JsonTypeInfo(use = Id.DEDUCTION) did not work. | ||
| public class LocationTODeserializer extends JsonDeserializer<LocationTO> { | ||
| @Override | ||
| public LocationTO deserialize( | ||
| JsonParser jsonParser, DeserializationContext deserializationContext) | ||
| throws IOException, JacksonException { | ||
| JsonNode node = jsonParser.readValueAsTree(); | ||
| String locationType = node.get("locationType").asText(); | ||
| String locationName = node.get("locationName").asText(""); | ||
|
|
||
| return switch (locationType) { | ||
| case "UNLO" -> UnLocationLocationTO.builder() | ||
| .locationName(locationName) | ||
| .locationType(LocationType.UNLO) | ||
| .unLocationCode(node.get("UNLocationCode").asText("")) | ||
| .build(); | ||
| case "FACI" -> FacilityLocationTO.builder() | ||
| .locationName(locationName) | ||
| .locationType(LocationType.FACI) | ||
| .unLocationCode(node.get("UNLocationCode").asText("")) | ||
| .facilityCode(node.get("facilityCode").asText("")) | ||
| .facilityCodeListProvider( | ||
| FacilityCodeListProvider.valueOf(node.get("facilityCodeListProvider").asText(""))) | ||
| .build(); | ||
| case "ADDR" -> { | ||
| AddressLocationTO addressLocationTO = | ||
| AddressLocationTO.builder() | ||
| .locationName(locationName) | ||
| .locationType(LocationType.ADDR) | ||
| .build(); | ||
|
|
||
| if (node.hasNonNull("address")) { | ||
| JsonNode aNode = node.get("address"); | ||
| yield addressLocationTO.toBuilder() | ||
| .address( | ||
| AddressTO.builder() | ||
| .name(aNode.get("name").asText("")) | ||
| .street(aNode.get("street").asText("")) | ||
| .streetNumber(aNode.get("streetNumber").asText("")) | ||
| .floor(aNode.get("floor").asText("")) | ||
| .postCode(aNode.get("postCode").asText("")) | ||
| .city(aNode.get("city").asText("")) | ||
| .stateRegion(aNode.get("stateRegion").asText("")) | ||
| .country(aNode.get("country").asText("")) | ||
| .build()) | ||
| .build(); | ||
| } else { | ||
| yield addressLocationTO; | ||
| } | ||
| } | ||
| case "GEOL" -> GeoLocationTO.builder() | ||
| .locationName(locationName) | ||
| .locationType(LocationType.GEOL) | ||
| .latitude(node.get("latitude").asText("")) | ||
| .longitude(node.get("longitude").asText("")) | ||
| .build(); | ||
| default -> throw new RuntimeException("Invalid location instance."); | ||
| }; | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/TransportCallTO.java
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the
locationTypeto switch on? The purpose of thelocationTypeis to be used as a discriminator..