-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from dcsaorg/feature/APCV-475
Feature/apcv 475
- Loading branch information
Showing
5 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
tnt-service/src/test/java/org/dcsa/tnt/service/LocationTOTest.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,54 @@ | ||
package org.dcsa.tnt.service; | ||
|
||
import org.dcsa.skernel.infrastructure.transferobject.AddressTO; | ||
import org.dcsa.tnt.transferobjects.LocationTO; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LocationTOTest { | ||
|
||
@Test | ||
public void testAddressLocationType() { | ||
AddressTO address = AddressTO.builder().build(); | ||
LocationTO location = LocationTO.builder().address(address).build(); | ||
assertEquals(LocationTO.LocationType.ADDR.name(), location.getLocationType()); | ||
} | ||
|
||
@Test | ||
public void testLatitudeAndLongitudeLocationType() { | ||
LocationTO location = LocationTO.builder().latitude("53.551° N").longitude("9.9937° E").build(); | ||
assertEquals(LocationTO.LocationType.GEO.name(), location.getLocationType()); | ||
} | ||
|
||
@Test | ||
public void testFacilityCodeLocationType() { | ||
LocationTO location = LocationTO.builder().facilityCode("DPWJA").build(); | ||
assertEquals(LocationTO.LocationType.FACI.name(), location.getLocationType()); | ||
} | ||
|
||
@Test | ||
public void testUNLocationCodeLocationType() { | ||
LocationTO location = LocationTO.builder().UNLocationCode("USNYC").build(); | ||
assertEquals(LocationTO.LocationType.UNLO.name(), location.getLocationType()); | ||
} | ||
|
||
@Test | ||
public void testAddressAndGeoLocationType() { | ||
AddressTO address = AddressTO.builder().build(); | ||
LocationTO location = LocationTO.builder().facilityCode("DPWJA").address(address).build(); | ||
assertEquals(LocationTO.LocationType.ADDR.name(), location.getLocationType()); | ||
} | ||
|
||
@Test | ||
public void testFacilityCodeAndGeoLocationType() { | ||
AddressTO address = AddressTO.builder().build(); | ||
LocationTO location = | ||
LocationTO.builder() | ||
.facilityCode("DPWJA") | ||
.latitude("53.551° N") | ||
.longitude("9.9937° E") | ||
.build(); | ||
assertEquals(LocationTO.LocationType.GEO.name(), location.getLocationType()); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/LocationTO.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,68 @@ | ||
package org.dcsa.tnt.transferobjects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.*; | ||
import org.dcsa.skernel.infrastructure.transferobject.AddressTO; | ||
import org.dcsa.skernel.infrastructure.transferobject.enums.FacilityCodeListProvider; | ||
|
||
@Builder | ||
@Data | ||
public class LocationTO { | ||
@Size(max = 100) | ||
private String locationName; | ||
|
||
@Size(max = 10) | ||
private String latitude; | ||
|
||
@Size(max = 11) | ||
private String longitude; | ||
|
||
@Size(max = 5) | ||
@JsonProperty("UNLocationCode") | ||
private String UNLocationCode; | ||
|
||
private String locationType; | ||
private AddressTO address; | ||
private String facilityCode; | ||
private FacilityCodeListProvider facilityCodeListProvider; | ||
|
||
public static LocationTOBuilder builder() { | ||
return new CustomLocationTOBuilder(); | ||
} | ||
|
||
private static class CustomLocationTOBuilder extends LocationTOBuilder { | ||
|
||
// This method overrides the build method invoked by the lombok Builder | ||
@Override | ||
public LocationTO build() { | ||
LocationTO locationTO = super.build(); | ||
|
||
// Setting the location type according to the conditions | ||
if (locationTO.getAddress() != null) { | ||
locationTO.setLocationType(String.valueOf(LocationType.ADDR)); | ||
return locationTO; | ||
} | ||
if (locationTO.getLatitude() != null && locationTO.getLongitude() != null) { | ||
locationTO.setLocationType(String.valueOf(LocationType.GEO)); | ||
return locationTO; | ||
} | ||
if (locationTO.getFacilityCode() != null) { | ||
locationTO.setLocationType(String.valueOf(LocationType.FACI)); | ||
return locationTO; | ||
} | ||
if (locationTO.getUNLocationCode() != null) { | ||
locationTO.setLocationType(String.valueOf(LocationType.UNLO)); | ||
return locationTO; | ||
} | ||
return locationTO; | ||
} | ||
} | ||
|
||
public enum LocationType { | ||
ADDR, | ||
UNLO, | ||
FACI, | ||
GEO; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
tnt-transfer-obj/src/main/java/org/dcsa/tnt/transferobjects/TransportCallTO.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