feat: obi and proximis
parent
2831d87ab2
commit
6016ce0dab
7
pom.xml
7
pom.xml
|
|
@ -64,13 +64,18 @@
|
|||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>2.13.0</version> <!-- Use the latest version here -->
|
||||
<version>2.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20231013</version>
|
||||
</dependency>
|
||||
|
||||
<!-- LOG dependencies -->
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -15,25 +15,23 @@ public class DatabaseConnectOBI implements AutoCloseable {
|
|||
|
||||
private Connection connection;
|
||||
|
||||
public DatabaseConnectOBI(String username) throws SQLException {
|
||||
public DatabaseConnectOBI() throws SQLException {
|
||||
String environment = loadEnvironment();
|
||||
|
||||
//TODO TO DELETE
|
||||
environment="preprod";
|
||||
environment = "preprod"; //TODO ATTENTION !!!
|
||||
|
||||
try {
|
||||
Properties dbProperties = loadDatabaseProperties();
|
||||
|
||||
|
||||
String url = dbProperties.getProperty(environment + ".obi.db.url");
|
||||
String userpassword = dbProperties.getProperty(environment + ".obi.db." + username + ".password");
|
||||
logger.info(url);
|
||||
logger.info(username);
|
||||
logger.info(userpassword);
|
||||
String username = dbProperties.getProperty(environment + ".obi.db.username");
|
||||
String userpassword = dbProperties.getProperty(environment + ".obi.db.password");
|
||||
|
||||
connection = DriverManager.getConnection(url, username, userpassword);
|
||||
|
||||
logger.info("OBI Connection OK for user " + username + " on environment " + environment);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to connect to OBI database for user " + username + " on environment " + environment, e);
|
||||
logger.error("Failed to connect to OBI database on environment " + environment, e);
|
||||
throw e; // re-throw the exception
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.example.services;
|
|||
|
||||
import com.example.services.order.Order;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
|
@ -35,6 +36,9 @@ import org.w3c.dom.Document;
|
|||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.XML;
|
||||
|
||||
@Path("/obi")
|
||||
public class OrderService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderService.class);
|
||||
|
|
@ -50,7 +54,7 @@ public class OrderService {
|
|||
|
||||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI("mobi")) {
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
||||
String countQuery = "SELECT COUNT(*) FROM obi_order oo ";
|
||||
String query =
|
||||
"SELECT oo.request_id, " +
|
||||
|
|
@ -133,7 +137,7 @@ public class OrderService {
|
|||
|
||||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI("mobi")) {
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
||||
String orderQuery = "SELECT oo.request_id, oo.order_id, oo.requesting_location_cd, oo.requesting_system_cd, "
|
||||
+ "oo.customer_id, oo.transaction_no, oo.transaction_type_id, oo.transaction_date, oo.status, "
|
||||
+ "oo.submit_ord_msg, oo.fdate_creation, oo.consumed, oo.shipforpickup_location_cd, oo.shipforpickup_system_cd, "
|
||||
|
|
@ -237,6 +241,48 @@ public class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/order/{requestId}/orderMessage")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getOrderMessage(@PathParam("requestId") Long requestId) throws SQLException {
|
||||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
||||
String orderXmlQuery = "SELECT oo.submit_ord_msg "
|
||||
+ "FROM obi_order oo "
|
||||
+ "WHERE oo.request_id = ?";
|
||||
|
||||
logger.info(orderXmlQuery);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(orderXmlQuery)) {
|
||||
statement.setLong(1, requestId);
|
||||
|
||||
try (ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
String xmlString = resultSet.getString("SUBMIT_ORD_MSG");
|
||||
JSONObject jsonObject = XML.toJSONObject(xmlString);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(jsonObject.toString());
|
||||
|
||||
return Response.ok(jsonNode).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No order found with the provided ID\"}").build();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"" + e.getMessage() + "\"}").build();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"" + e.getMessage() + "\"}").build();
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace(); // Handle exceptions correctly in a production environment
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build();
|
||||
}
|
||||
}
|
||||
|
||||
private Order.History mapResultSetToOrderLinesHistory(ResultSet resultSet) throws SQLException {
|
||||
Order.History orderLinesHistory = new Order().new History();
|
||||
|
||||
|
|
@ -292,7 +338,7 @@ public class OrderService {
|
|||
order.setMeta(meta);
|
||||
|
||||
statusData.setCode(resultSet.getString("STATUS"));
|
||||
statusData.setTitle("TEST");
|
||||
statusData.setTitle("TEST"); // TODO A VOIR
|
||||
|
||||
common.setOrderId(resultSet.getString("ORDER_ID"));
|
||||
|
||||
|
|
@ -319,7 +365,7 @@ public class OrderService {
|
|||
order.setMeta(meta);
|
||||
|
||||
statusData.setCode(resultSet.getString("STATUS"));
|
||||
statusData.setTitle("TEST");
|
||||
statusData.setTitle("TEST"); // TODO A VOIR
|
||||
|
||||
common.setOrderId(resultSet.getString("ORDER_ID"));
|
||||
common.setRequestingLocationCd(resultSet.getString("REQUESTING_LOCATION_CD"));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
package com.example.services;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path("/proximis")
|
||||
public class ProximisService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProximisService.class);
|
||||
|
||||
@GET
|
||||
@Path("/project/fulfillment/{orderCode}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getOrderDetail(@PathParam("orderCode") String orderCode) {
|
||||
if (orderCode == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"orderCode is required\"}").build();
|
||||
}
|
||||
|
||||
String environment = loadEnvironment();
|
||||
|
||||
try {
|
||||
Properties apiProperties = loadApiProperties();
|
||||
String url = apiProperties.getProperty(environment + ".proximis.api.url");
|
||||
String bearerToken = "";
|
||||
|
||||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
||||
String query = "SELECT authorization_value FROM obi.obi_param_access_token WHERE authorization_header = ?";
|
||||
PreparedStatement stmt = databaseConnection.getConnection().prepareStatement(query);
|
||||
|
||||
stmt.setString(1, "Authorization");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
bearerToken = rs.getString(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (bearerToken == null || bearerToken.isEmpty()) {
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Failed to access proximis API\"}").build();
|
||||
} else {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url + "/project/fulfillment/" + orderCode))
|
||||
.header("Authorization", bearerToken)
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
return Response.ok(response.body()).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Failed to get order detail\"}").build();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to get order detail", e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Failed to get order detail\"}").build();
|
||||
}
|
||||
}
|
||||
|
||||
private String loadEnvironment() {
|
||||
Properties envProperties = loadProperties("env.properties");
|
||||
return envProperties.getProperty("environment");
|
||||
}
|
||||
|
||||
private Properties loadApiProperties() {
|
||||
Properties apiProperties = loadProperties("api.properties");
|
||||
return apiProperties;
|
||||
}
|
||||
private Properties loadProperties(String fileName) {
|
||||
Properties properties = new Properties();
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(fileName)) {
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Handle the exception correctly for your application
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# Pre-production API Proximis
|
||||
preprod.proximis.api.url=https://proximis-ikks-recette.stg.proximis.com/publicAPI.php/V2
|
||||
|
||||
# production API Proximis
|
||||
prod.proximis.api.url=https://ikks.omn.proximis.com/publicAPI.php/V2
|
||||
|
|
@ -24,9 +24,11 @@ prod.xadmin.db.dtv.password=oY3poRSprOuqasO
|
|||
|
||||
# Pre-production OBI environment settings
|
||||
preprod.obi.db.url=jdbc:postgresql://v-tlnd-b01-iidc.tech.ikks.lan:5432/mirobi
|
||||
preprod.obi.db.mobi.password=obi
|
||||
preprod.obi.db.username=mobi
|
||||
preprod.obi.db.password=obi
|
||||
|
||||
# production OBI environment settings
|
||||
prod.obi.db.url=FREDjdbc:postgresql://v-tlnd-b01-ipdc.tech.ikks.lan:5432/pirobi
|
||||
prod.obi.db.pobi.password=FREDy!h`AGZjGVa.ae;(N
|
||||
prod.obi.db.url=jdbc:postgresql://v-tlnd-b01-ipdc.tech.ikks.lan:5432/pirobi
|
||||
prod.obi.db.username=pobi
|
||||
prod.obi.db.password=y!h`AGZjGVa.ae;(N
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue