Skip to content

Commit

Permalink
Merge pull request #132 from dcsaorg/feature/APCV-475
Browse files Browse the repository at this point in the history
Feature/apcv 475
  • Loading branch information
palatsangeetha authored Aug 3, 2023
2 parents 381872e + ad8d1ce commit 4ff462d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
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.tnt.transferobjects.*;
import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
Expand Down
54 changes: 54 additions & 0 deletions tnt-service/src/test/java/org/dcsa/tnt/service/LocationTOTest.java
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.dcsa.skernel.infrastructure.transferobject.LocationTO;
import org.dcsa.tnt.transferobjects.LocationTO;
import org.dcsa.tnt.transferobjects.EventPayloadTO.EventPayloadTOWithTransportCall;
import org.dcsa.tnt.transferobjects.enums.EmptyIndicatorCode;
import org.dcsa.tnt.transferobjects.enums.EquipmentEventTypeCode;
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.dcsa.tnt.transferobjects;

import lombok.Builder;
import org.dcsa.skernel.infrastructure.transferobject.LocationTO;
import org.dcsa.tnt.transferobjects.enums.FacilityTypeCode;

public record TransportCallTO(
Expand Down

0 comments on commit 4ff462d

Please sign in to comment.