Skip to content

Commit

Permalink
chore: update to Jakarta EE 11
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and hantsy committed Jan 6, 2025
1 parent 3878708 commit 28f2de2
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 297 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@
<artifactId>cargo-maven3-plugin</artifactId>
<version>${cargo-maven3-plugin.version}</version>
</plugin>

<!-- Maven 4.0 requires locking clean/resources plugins in project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void inspectCargo(TrackingId trackingId) {

cargo.deriveDeliveryProgress(handlingHistory);

if (cargo.getDelivery().isMisdirected()) {
if (cargo.getDelivery().misdirected()) {
applicationEvents.cargoWasMisdirected(cargo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Iterator;
import java.util.logging.Logger;

/**
* The actual transportation of the cargo, as opposed to the customer requirement
Expand All @@ -31,8 +30,6 @@ public class Delivery implements Serializable {
// Null object pattern
public static final HandlingActivity NO_ACTIVITY = HandlingActivity.EMPTY;


// public static final HandlingActivity NO_ACTIVITY = null;
@Enumerated(EnumType.STRING)
@Column(name = "transport_status")
@NotNull
Expand Down Expand Up @@ -125,15 +122,15 @@ Delivery updateOnRouting(RouteSpecification routeSpecification, Itinerary itiner
return new Delivery(this.lastEvent, itinerary, routeSpecification);
}

public TransportStatus getTransportStatus() {
public TransportStatus transportStatus() {
return transportStatus;
}

public void setTransportStatus(TransportStatus transportStatus) {
this.transportStatus = transportStatus;
}

public Location getLastKnownLocation() {
public Location lastKnownLocation() {
return DomainObjectUtils.nullSafe(lastKnownLocation, Location.UNKNOWN);
}

Expand All @@ -145,7 +142,7 @@ public void setLastEvent(HandlingEvent lastEvent) {
this.lastEvent = lastEvent;
}

public Voyage getCurrentVoyage() {
public Voyage currentVoyage() {
return DomainObjectUtils.nullSafe(currentVoyage, Voyage.NONE);
}

Expand All @@ -162,22 +159,22 @@ public Voyage getCurrentVoyage() {
*
* @return <code>true</code> if the cargo has been misdirected,
*/
public boolean isMisdirected() {
public boolean misdirected() {
return misdirected;
}

public void setMisdirected(boolean misdirected) {
this.misdirected = misdirected;
}

public LocalDateTime getEstimatedTimeOfArrival() {
public LocalDateTime estimatedTimeOfArrival() {
return eta;
}

// Hibernate issue:
// After an empty HandlingActivity is persisted, when retrieving it from database it is a
// *NULL*.
public HandlingActivity getNextExpectedActivity() {
public HandlingActivity nextExpectedActivity() {
// return nextExpectedActivity;
return DomainObjectUtils.nullSafe(nextExpectedActivity, NO_ACTIVITY);
}
Expand All @@ -193,7 +190,7 @@ public void setUnloadedAtDestination(boolean isUnloadedAtDestination) {
this.isUnloadedAtDestination = isUnloadedAtDestination;
}

public RoutingStatus getRoutingStatus() {
public RoutingStatus routingStatus() {
return routingStatus;
}

Expand Down Expand Up @@ -231,7 +228,7 @@ private Location calculateLastKnownLocation() {
}

private Voyage calculateCurrentVoyage() {
if (getTransportStatus().equals(ONBOARD_CARRIER) && lastEvent != null) {
if (transportStatus().equals(ONBOARD_CARRIER) && lastEvent != null) {
return lastEvent.getVoyage();
} else {
return null;
Expand Down Expand Up @@ -266,7 +263,7 @@ private HandlingActivity calculateNextExpectedActivity(

return switch (lastEvent.getType()) {
case LOAD -> {
for (Leg leg : itinerary.getLegs()) {
for (Leg leg : itinerary.legs()) {
if (leg.getLoadLocation().sameIdentityAs(lastEvent.getLocation())) {
yield new HandlingActivity(
HandlingEvent.Type.UNLOAD,
Expand All @@ -277,8 +274,7 @@ yield new HandlingActivity(
yield NO_ACTIVITY;
}
case UNLOAD -> {
for (Iterator<Leg> iterator = itinerary.getLegs().iterator();
iterator.hasNext(); ) {
for (Iterator<Leg> iterator = itinerary.legs().iterator(); iterator.hasNext(); ) {
Leg leg = iterator.next();

if (leg.getUnloadLocation().sameIdentityAs(lastEvent.getLocation())) {
Expand All @@ -297,7 +293,7 @@ yield new HandlingActivity(
yield NO_ACTIVITY;
}
case RECEIVE -> {
Leg firstLeg = itinerary.getLegs().iterator().next();
Leg firstLeg = itinerary.legs().iterator().next();
yield new HandlingActivity(
HandlingEvent.Type.LOAD, firstLeg.getLoadLocation(), firstLeg.getVoyage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.eclipse.cargotracker.domain.model.cargo;

import static java.util.Collections.*;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
Expand All @@ -8,59 +10,52 @@
import org.eclipse.cargotracker.domain.model.handling.HandlingEvent;
import org.eclipse.cargotracker.domain.model.location.Location;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Embeddable
public class Itinerary implements Serializable {
public record Itinerary(
// TODO [Clean Code] Look into why cascade delete doesn't work.
// Hibernate issue:
// Changes applied according to WildFly/Hibernate requirements.
// The `orphanRemoval = true` option will causes a `all-delete-orphan` exception under
// WildFly/Hibernate.
// (There is a famous lazy initialization exception you could encounter WildFly/Hibernate.
// The `fetch = FetchType.EAGER` fixes the Hibernate lazy initialization exception
// but maybe cause bad performance. A good practice is accessing the one-to-many relations
// in a session/tx boundary)
//
// @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "cargo_id")
// TODO [Clean Code] Index this is in leg_index
// Hibernate issue:
// Hibernate does not persist the order of the list element when saving into db.
// The `OrderColumn` will persist the position of list elements in db.
@OrderColumn(name = "leg_index")
// The `OrderBy` only ensures the order of list elements in memory. Only
// `@OrderBy("loadTime")`
// is added some tests are still failed under WildFly/Hibernate.
// @OrderBy("loadTime")
@Size(min = 1)
@NotEmpty(message = "Legs must not be empty")
List<Leg> legs) {

// Null object pattern.
public static final Itinerary EMPTY_ITINERARY = new Itinerary();
private static final long serialVersionUID = 1L;

// TODO [Clean Code] Look into why cascade delete doesn't work.
// Hibernate issue:
// Changes applied according to WildFly/Hibernate requirements.
// The `orphanRemoval = true` option will causes a `all-delete-orphan` exception under
// WildFly/Hibernate.
// (There is a famous lazy initialization exception you could encounter WildFly/Hibernate.
// The `fetch = FetchType.EAGER` fixes the Hibernate lazy initialization exception
// but maybe cause bad performance. A good practice is accessing the one-to-many relations
// in a session/tx boundary)
//
// @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "cargo_id")
// TODO [Clean Code] Index this is in leg_index
// Hibernate issue:
// Hibernate does not persist the order of the list element when saving into db.
// The `OrderColumn` will persist the position of list elements in db.
@OrderColumn(name = "leg_index")
// The `OrderBy` only ensures the order of list elements in memory. Only `@OrderBy("loadTime")`
// is added some tests are still failed under WildFly/Hibernate.
// @OrderBy("loadTime")
@Size(min = 1)
@NotEmpty(message = "Legs must not be empty")
private List<Leg> legs = Collections.emptyList();

public Itinerary() {
// Nothing to initialize.
}
public static final Itinerary EMPTY_ITINERARY = new Itinerary(emptyList());

public Itinerary(List<Leg> legs) {
public Itinerary {
// Nothing to initialize.
Validate.notEmpty(legs);
Validate.noNullElements(legs);

this.legs = legs;
}

public List<Leg> getLegs() {
// this.legs.sort(Comparator.comparing(Leg::getLoadTime));
return Collections.unmodifiableList(this.legs);
}
//
// public List<Leg> legs() {
// // this.legs.sort(Comparator.comparing(Leg::getLoadTime));
// return Collections.unmodifiableList(this.legs);
// }

/** Test if the given handling event is expected when executing this itinerary. */
public boolean isExpected(HandlingEvent event) {
Expand Down Expand Up @@ -135,7 +130,7 @@ Leg getLastLeg() {
if (legs.isEmpty()) {
return null;
} else {
return legs.get(legs.size() - 1);
return legs.getLast();
}
}

Expand All @@ -148,38 +143,39 @@ private boolean sameValueAs(Itinerary other) {
return other != null && Objects.equals(List.copyOf(this.legs), List.copyOf(other.legs));
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

// if (o == null || getClass() != o.getClass()) {
// return false;
// }
//
// https://stackoverflow.com/questions/27581/what-issues-should-be-considered-when-overriding-equals-and-hashcode-in-java
// Hibernate issue:
// `getClass() != o.getClass()` will fail if comparing the objects in different
// transactions/sessions.
// The generated dynamic proxies are always different classes.
if (o == null || !(o instanceof Itinerary)) {
return false;
}

Itinerary itinerary = (Itinerary) o;

return sameValueAs(itinerary);
}

@Override
public int hashCode() {
// return legs.hashCode();
return Objects.hashCode(List.copyOf(legs));
}

@Override
public String toString() {
return "Itinerary{" + "legs=" + legs + '}';
}
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
//
// // if (o == null || getClass() != o.getClass()) {
// // return false;
// // }
// //
// //
// https://stackoverflow.com/questions/27581/what-issues-should-be-considered-when-overriding-equals-and-hashcode-in-java
// // Hibernate issue:
// // `getClass() != o.getClass()` will fail if comparing the objects in different
// // transactions/sessions.
// // The generated dynamic proxies are always different classes.
// if (o == null || !(o instanceof Itinerary)) {
// return false;
// }
//
// Itinerary itinerary = (Itinerary) o;
//
// return sameValueAs(itinerary);
// }
//
// @Override
// public int hashCode() {
// // return legs.hashCode();
// return Objects.hashCode(List.copyOf(legs));
// }
//
// @Override
// public String toString() {
// return "Itinerary{" + "legs=" + legs + '}';
// }Itinerary
}
Loading

0 comments on commit 28f2de2

Please sign in to comment.