Skip to content

Commit

Permalink
clean codes for wildfly
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Mar 21, 2021
1 parent 753f2dc commit c1f54d2
Show file tree
Hide file tree
Showing 23 changed files with 265 additions and 42 deletions.
Binary file not shown.
100 changes: 97 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.ee4j</groupId>
Expand Down Expand Up @@ -191,7 +191,7 @@
<version>2.33</version>
<scope>provided</scope>
</dependency>
<!-- Embedding the JDBC driver in the WAR works in Payara -->
<!-- Embedding the JDBC driver in the WAR works in Payara -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down Expand Up @@ -225,5 +225,99 @@
</plugins>
</build>
</profile>
<profile>
<id>wildfly</id>
<properties>
<wildfly.version>23.0.0.Final</wildfly.version>
<wildfly-maven-plugin.version>2.1.0.Beta1</wildfly-maven-plugin.version>
<wildfly-arquillian.version>3.0.1.Final</wildfly-arquillian.version>
<resteasy.version>3.14.0.Final</resteasy.version>
<jackson.version>2.11.3</jackson.version>
<!-- WildFly requires a DataSource impl -->
<db.driverClass>org.h2.jdbcx.JdbcDataSource</db.driverClass>
<!-- H2 file engine requires an absolute path, eg. ~/name, ./name or a full-qualified
path name (it should include driver name under Windows). -->
<db.jdbcUrl>jdbc:h2:file:./cargo-tracker-data/cargo-tracker-database;create=true</db.jdbcUrl>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<!-- H2 per deployment -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>${wildfly-arquillian.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>
src/main/java-wildfly
</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${wildfly-maven-plugin.version}</version>
<configuration>
<server-config>standalone-full.xml</server-config>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.eclipse.cargotracker.infrastructure.routing.client;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;

public JacksonObjectMapperContextResolver() {
this.objectMapper =
new ObjectMapper()
.findAndRegisterModules()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

@Override
public ObjectMapper getContext(Class<?> objectType) {
return objectMapper;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.eclipse.cargotracker.application.util;

import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.server.ServerProperties;
import java.util.HashMap;
import java.util.Map;

/** Jakarta REST configuration. */
@ApplicationPath("rest")
Expand All @@ -13,7 +12,11 @@ public class RestConfiguration extends Application {
@Override
public Map<String, Object> getProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
// properties.put(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
// for portable in other application servers.
// see:
// https://eclipse-ee4j.github.io/jersey.github.io/apidocs/latest/jersey/org/glassfish/jersey/server/ServerProperties.html#BV_SEND_ERROR_IN_RESPONSE
properties.put("jersey.config.beanValidation.enableOutputValidationErrorEntity.serve", true);
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
if (object == null || !(object instanceof Cargo)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof Delivery)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != this.getClass()) {
if (!(obj instanceof HandlingActivity)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.Validate;
Expand All @@ -23,10 +19,9 @@ public class Itinerary implements Serializable {
private static final long serialVersionUID = 1L;

// TODO [Clean Code] Look into why cascade delete doesn't work.
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "cargo_id")
// TODO [Clean Code] Index this is in leg_index
@OrderBy("loadTime")
@OrderColumn(name = "leg_index")
@Size(min = 1)
@NotEmpty(message = "Legs must not be empty.")
private List<Leg> legs = Collections.emptyList();
Expand Down Expand Up @@ -144,7 +139,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof Itinerary)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -61,8 +62,12 @@ public Leg(
this.voyage = voyage;
this.loadLocation = loadLocation;
this.unloadLocation = unloadLocation;
this.loadTime = loadTime;
this.unloadTime = unloadTime;
// Hibernate issue:
// when the `LocalDateTime` field is persisted into db, and retrieved from db, the values
// are different in nanoseconds.
// any good idea to overcome this?
this.loadTime = loadTime.truncatedTo(ChronoUnit.SECONDS);
this.unloadTime = unloadTime.truncatedTo(ChronoUnit.SECONDS);
}

public Voyage getVoyage() {
Expand Down Expand Up @@ -101,7 +106,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof Leg)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof RouteSpecification)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof TrackingId)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof HandlingEvent)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof HandlingHistory)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean equals(Object o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof UnLocode)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof CarrierMovement)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o == null || !(o instanceof Schedule)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
Expand Down Expand Up @@ -44,7 +45,16 @@ public class ExternalRoutingService implements RoutingService {

@PostConstruct
public void init() {
graphTraversalResource = ClientBuilder.newClient().target(graphTraversalUrl);
Client jaxrsClient = ClientBuilder.newClient();
try {
Class<?> clazz =
Class.forName(
"org.eclipse.cargotracker.infrastructure.routing.client.JacksonObjectMapperContextResolver");
jaxrsClient.register(clazz);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
graphTraversalResource = jaxrsClient.target(graphTraversalUrl);
}

@Override
Expand All @@ -64,8 +74,7 @@ public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpeci
List<Itinerary> itineraries = new ArrayList<>();

// Use the specification to safe-guard against invalid itineraries
transitPaths
.stream()
transitPaths.stream()
.map(this::toItinerary)
.forEach(
itinerary -> {
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/WEB-INF/jboss-deployment-structure.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
</exclusions>
<dependencies>
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" services="import"/>
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Loading

0 comments on commit c1f54d2

Please sign in to comment.