From 2831d87ab25a660183f16d94e2388d69b02056d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Sun, 7 Jan 2024 21:09:45 +0100 Subject: [PATCH 1/6] feat: add obi order visualization --- pom.xml | 9 +- .../services/DatabaseConnectDOTSOFT.java | 4 +- .../example/services/DatabaseConnectOBI.java | 73 ++++ .../services/DatabaseConnectXADMIN.java | 15 +- .../com/example/services/OrderService.java | 378 ++++++++++++++++++ .../com/example/services/order/Order.java | 235 +++++++++++ src/main/resources/db.properties | 37 +- 7 files changed, 730 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/example/services/DatabaseConnectOBI.java create mode 100644 src/main/java/com/example/services/OrderService.java create mode 100644 src/main/java/com/example/services/order/Order.java diff --git a/pom.xml b/pom.xml index aba3cfa..c413cae 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,14 @@ com.oracle.database.jdbc ojdbc8 - 18.3.0.0 + 18.3.0.0 + + + + + org.postgresql + postgresql + 42.2.5 diff --git a/src/main/java/com/example/services/DatabaseConnectDOTSOFT.java b/src/main/java/com/example/services/DatabaseConnectDOTSOFT.java index 67eb675..9da0e0f 100644 --- a/src/main/java/com/example/services/DatabaseConnectDOTSOFT.java +++ b/src/main/java/com/example/services/DatabaseConnectDOTSOFT.java @@ -21,8 +21,8 @@ public class DatabaseConnectDOTSOFT implements AutoCloseable { try { Properties dbProperties = loadDatabaseProperties(); - String url = dbProperties.getProperty(environment + ".db.url"); - String userpassword = dbProperties.getProperty(environment + ".db." + username + ".password"); + String url = dbProperties.getProperty(environment + ".dotsoft.db.url"); + String userpassword = dbProperties.getProperty(environment + ".dotsoft.db." + username + ".password"); connection = DriverManager.getConnection(url, username, userpassword); diff --git a/src/main/java/com/example/services/DatabaseConnectOBI.java b/src/main/java/com/example/services/DatabaseConnectOBI.java new file mode 100644 index 0000000..30607f8 --- /dev/null +++ b/src/main/java/com/example/services/DatabaseConnectOBI.java @@ -0,0 +1,73 @@ +package com.example.services; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DatabaseConnectOBI implements AutoCloseable { + private static final Logger logger = LoggerFactory.getLogger(DatabaseConnectOBI.class); + + private Connection connection; + + public DatabaseConnectOBI(String username) throws SQLException { + String environment = loadEnvironment(); + + //TODO TO DELETE + environment="preprod"; + + 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); + 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); + throw e; // re-throw the exception + } + } + + public Connection getConnection() { + return connection; + } + + @Override + public void close() throws SQLException { + if (connection != null && !connection.isClosed()) { + connection.close(); + logger.info("OBI Connection closed"); + } + } + + private String loadEnvironment() { + Properties envProperties = loadProperties("env.properties"); + return envProperties.getProperty("environment"); + } + + private Properties loadDatabaseProperties() { + Properties dbProperties = loadProperties("db.properties"); + return dbProperties; + } + + 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; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/services/DatabaseConnectXADMIN.java b/src/main/java/com/example/services/DatabaseConnectXADMIN.java index d7f68b7..a7e9172 100644 --- a/src/main/java/com/example/services/DatabaseConnectXADMIN.java +++ b/src/main/java/com/example/services/DatabaseConnectXADMIN.java @@ -16,17 +16,19 @@ public class DatabaseConnectXADMIN implements AutoCloseable { private Connection connection; public DatabaseConnectXADMIN(String username) throws SQLException { + String environment = loadEnvironment(); + try { Properties dbProperties = loadDatabaseProperties(); - String url = dbProperties.getProperty("xadmin.db.url"); - String userpassword = dbProperties.getProperty("xadmin.db." + username + ".password"); + String url = dbProperties.getProperty(environment + ".xadmin.db.url"); + String userpassword = dbProperties.getProperty(environment + ".xadmin.db." + username + ".password"); connection = DriverManager.getConnection(url, username, userpassword); - logger.info("XADMIN Connection OK for user " + username); + logger.info("XADMIN Connection OK for user " + username + " on environment " + environment); } catch (SQLException e) { - logger.error("Failed to connect to XADMIN database for user " + username, e); + logger.error("Failed to connect to XADMIN database for user " + username + " on environment " + environment, e); throw e; // re-throw the exception } } @@ -43,6 +45,11 @@ public class DatabaseConnectXADMIN implements AutoCloseable { } } + private String loadEnvironment() { + Properties envProperties = loadProperties("env.properties"); + return envProperties.getProperty("environment"); + } + private Properties loadDatabaseProperties() { Properties dbProperties = loadProperties("db.properties"); return dbProperties; diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java new file mode 100644 index 0000000..4e746b3 --- /dev/null +++ b/src/main/java/com/example/services/OrderService.java @@ -0,0 +1,378 @@ +package com.example.services; + +import com.example.services.order.Order; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; +import java.io.StringReader; +import java.math.BigDecimal; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +@Path("/obi") +public class OrderService { + private static final Logger logger = LoggerFactory.getLogger(OrderService.class); + + @GET + @Path("/order") + @Produces(MediaType.APPLICATION_JSON) + public Response getAllOrders(@QueryParam("q") String q, + @QueryParam("page") int page, + @QueryParam("itemsPerPage") int itemsPerPage, + @QueryParam("sortBy") String sortBy, + @QueryParam("orderBy") String orderBy) { + + DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes + + try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI("mobi")) { + String countQuery = "SELECT COUNT(*) FROM obi_order oo "; + String query = + "SELECT oo.request_id, " + + "oo.order_id, " + + "oo.transaction_date, " + + "oo.status as status, " + + "ott.transaction_type_description " + + "FROM obi_order oo " + + "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id"; + + List conditions = new ArrayList<>(); + if (q != null && !q.isEmpty()) { + conditions.add(" oo.order_id LIKE ? "); + } + if (!conditions.isEmpty()) { + countQuery += " WHERE " + String.join(" AND ", conditions); + query += " WHERE " + String.join(" AND ", conditions); + } + + if (sortBy != null && !sortBy.isEmpty()) { + query += " ORDER BY " + sortBy; + if (orderBy != null && !orderBy.isEmpty()) { + query += " " + orderBy; + } + } + if (page > 0 && itemsPerPage > 0) { + query += " LIMIT " + itemsPerPage + " OFFSET " + (page - 1) * itemsPerPage; + } + + logger.info(query); + + try (PreparedStatement countStatement = databaseConnection.getConnection().prepareStatement(countQuery); + PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { + int index = 1; + + if (q != null && !q.isEmpty()) { + countStatement.setString(index, "%" + q + "%"); + statement.setString(index++, "%" + q + "%"); + } + + ResultSet countResultSet = countStatement.executeQuery(); + countResultSet.next(); + int total = countResultSet.getInt(1); + + ResultSet resultSet = statement.executeQuery(); { + List orderList = new ArrayList<>(); + + while (resultSet.next()) { + Order order = mapResultSetToOrderList(resultSet); + orderList.add(order); + } + + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode responseNode = objectMapper.createObjectNode(); + responseNode.put("total", total); + responseNode.set("orders", objectMapper.valueToTree(orderList)); + + String jsonResponse; + + try { + jsonResponse = objectMapper.writeValueAsString(responseNode); + return Response.ok(jsonResponse).build(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build(); + } + } + } + } catch (SQLException e) { + e.printStackTrace(); + String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}"; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build(); + } +} + + @GET + @Path("/order/{requestId}") + @Produces(MediaType.APPLICATION_JSON) + public Response getOrderById( @PathParam("requestId") Long requestId) throws SQLException { + + DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes + + try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI("mobi")) { + 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, " + + "ott.transaction_type_description " + + "FROM obi_order oo " + + "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id " + + "WHERE oo.request_id = ?"; + + logger.info(orderQuery); + + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(orderQuery)) { + statement.setLong(1, requestId); + + try (ResultSet resultSet = statement.executeQuery()) { + if (resultSet.next()) { + Order order = mapResultSetToOrder(resultSet); + + String orderLinesQuery = "SELECT olo.line_order_id, olo.line_item_no, olo.order_id, olo.request_id, olo.line_item_oms, " + + "olo.item_id, olo.ordered_line_qty, olo.status, olo.transaction_date, olo.shipping_agent, " + + "olo.tracking_number, olo.fulfillment_id, olo.carton_number, olo.fdate_creation, olo.consumed " + + "FROM obi.obi_ln_order olo " + + "WHERE olo.request_id = ? " + + "ORDER BY olo.line_item_no"; + + logger.info(orderLinesQuery); + + try (PreparedStatement linesStatement = databaseConnection.getConnection().prepareStatement(orderLinesQuery)) { + linesStatement.setLong(1, requestId); + + try (ResultSet linesResultSet = linesStatement.executeQuery()) { + List orderLinesList = new ArrayList<>(); + + while (linesResultSet.next()) { + orderLinesList.add(mapResultSetToOrderLine(linesResultSet)); + + String orderLinesHistoryQuery = "SELECT ohlo.status_id, ohlo.line_order_id, ohlo.status, ohlo.transaction_date, ohlo.fdate_creation " + + "FROM obi.obi_h_ln_order ohlo " + + "WHERE ohlo.line_order_id = ? " + + "ORDER BY ohlo.status_id DESC"; + + logger.info(orderLinesHistoryQuery); + + try (PreparedStatement orderLinesHistoryStatement = databaseConnection.getConnection().prepareStatement(orderLinesHistoryQuery)) { + orderLinesHistoryStatement.setLong(1, orderLinesList.get(orderLinesList.size() - 1).getLineOrderId()); + + try (ResultSet orderLinesHistoryResultSet = orderLinesHistoryStatement.executeQuery()) { + List orderLinesHistoryList = new ArrayList<>(); + + while (orderLinesHistoryResultSet.next()) { + orderLinesHistoryList.add(mapResultSetToOrderLinesHistory(orderLinesHistoryResultSet)); + } + + orderLinesList.get(orderLinesList.size() - 1).setHistory(orderLinesHistoryList); + } + } + } + + order.setLines(orderLinesList); + } + + String orderHistoryQuery = "SELECT oho.status_id, oho.request_id, oho.status, oho.transaction_date, oho.fdate_creation " + + "FROM obi.obi_h_order oho " + + "WHERE oho.request_id = ? " + + "ORDER BY oho.status_id DESC"; + + logger.info(orderHistoryQuery); + + try (PreparedStatement orderHistoryStatement = databaseConnection.getConnection().prepareStatement(orderHistoryQuery)) { + orderHistoryStatement.setLong(1, requestId); + + try (ResultSet orderHistoryResultSet = orderHistoryStatement.executeQuery()) { + List orderHistoryList = new ArrayList<>(); + + while (orderHistoryResultSet.next()) { + orderHistoryList.add(mapResultSetToOrderHistory(orderHistoryResultSet)); + } + + order.setHistory(orderHistoryList); + } + } + + ObjectMapper objectMapper = new ObjectMapper(); + String jsonResponse = objectMapper.writeValueAsString(order); + + return Response.ok(jsonResponse).build(); + } catch (SQLException e) { + e.printStackTrace(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"" + e.getMessage() + "\"}").build(); + } + } else { + return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No order found\"}").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(); + } + } catch (SQLException e) { + e.printStackTrace(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"" + e.getMessage() + "\"}").build(); + } + } + } + + private Order.History mapResultSetToOrderLinesHistory(ResultSet resultSet) throws SQLException { + Order.History orderLinesHistory = new Order().new History(); + + orderLinesHistory.setStatusId(resultSet.getInt("STATUS_ID")); + orderLinesHistory.setId(resultSet.getLong("LINE_ORDER_ID")); + orderLinesHistory.setStatus(resultSet.getString("STATUS")); + orderLinesHistory.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + orderLinesHistory.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + + return orderLinesHistory; + } + + private Order.History mapResultSetToOrderHistory(ResultSet resultSet) throws SQLException { + Order.History orderHistory = new Order().new History(); + + orderHistory.setStatusId(resultSet.getInt("STATUS_ID")); + orderHistory.setId(resultSet.getLong("REQUEST_ID")); + orderHistory.setStatus(resultSet.getString("STATUS")); + orderHistory.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + orderHistory.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + + return orderHistory; + } + + private Order.Lines mapResultSetToOrderLine(ResultSet resultSet) throws SQLException { + Order.Lines orderLine = new Order().new Lines(); + + orderLine.setLineOrderId(resultSet.getLong("LINE_ORDER_ID")); + orderLine.setLineItemNo(resultSet.getInt("LINE_ITEM_NO")); + orderLine.setLineItemOms(resultSet.getString("LINE_ITEM_OMS")); + orderLine.setItemId(resultSet.getString("ITEM_ID")); + orderLine.setOrderedLineQty(resultSet.getInt("ORDERED_LINE_QTY")); + orderLine.setStatus(resultSet.getString("STATUS")); + orderLine.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + orderLine.setShippingAgent(resultSet.getString("SHIPPING_AGENT")); + orderLine.setTrackingNumber(resultSet.getString("TRACKING_NUMBER")); + orderLine.setFulfillmentId(resultSet.getString("FULFILLMENT_ID")); + orderLine.setCartonNumber(resultSet.getString("CARTON_NUMBER")); + orderLine.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + orderLine.setConsumed(resultSet.getBoolean("CONSUMED")); + + return orderLine; + } + + private Order mapResultSetToOrderList(ResultSet resultSet) throws SQLException { + Order order = new Order(); + Order.Meta meta = new Order.Meta(); + Order.Common common = order.new Common(); + Order.Common.StatusData statusData = common.new StatusData(); + Order.Common.Transaction transaction = common.new Transaction(); + + meta.setId(resultSet.getLong("REQUEST_ID")); + order.setMeta(meta); + + statusData.setCode(resultSet.getString("STATUS")); + statusData.setTitle("TEST"); + + common.setOrderId(resultSet.getString("ORDER_ID")); + + transaction.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + transaction.setTransactionTypeDescription(resultSet.getString("TRANSACTION_TYPE_DESCRIPTION")); + + common.setStatusData(statusData); + common.setTransaction(transaction); + + order.setMeta(meta); + order.setCommon(common); + + return order; + } + + private Order mapResultSetToOrder(ResultSet resultSet) throws SQLException { + Order order = new Order(); + Order.Meta meta = new Order.Meta(); + Order.Common common = order.new Common(); + Order.Common.StatusData statusData = common.new StatusData(); + Order.Common.Transaction transaction = common.new Transaction(); + + meta.setId(resultSet.getLong("REQUEST_ID")); + order.setMeta(meta); + + statusData.setCode(resultSet.getString("STATUS")); + statusData.setTitle("TEST"); + + common.setOrderId(resultSet.getString("ORDER_ID")); + common.setRequestingLocationCd(resultSet.getString("REQUESTING_LOCATION_CD")); + common.setRequestingSystemCd(resultSet.getString("REQUESTING_SYSTEM_CD")); + common.setCustomerId(resultSet.getString("CUSTOMER_ID")); + //common.setSubmitOrdMsg(resultSet.getString("SUBMIT_ORD_MSG")); + common.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + common.setConsumed(resultSet.getBoolean("CONSUMED")); + common.setShipforpickupLocationCd(resultSet.getString("SHIPFORPICKUP_LOCATION_CD")); + common.setShipforpickupSystemCd(resultSet.getString("SHIPFORPICKUP_SYSTEM_CD")); + + transaction.setTransactionNo(resultSet.getString("TRANSACTION_NO")); + transaction.setTransactionTypeId(resultSet.getInt("TRANSACTION_TYPE_ID")); + transaction.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + transaction.setTransactionTypeDescription(resultSet.getString("TRANSACTION_TYPE_DESCRIPTION")); + + // get subtotal, tax, total + String xmlString = resultSet.getString("SUBMIT_ORD_MSG"); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + + try { + builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new InputSource(new StringReader(xmlString))); + doc.getDocumentElement().normalize(); + + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + + String firstName = xpath.evaluate("//sold_to_customer/name/first", doc.getDocumentElement()); + String lastName = xpath.evaluate("//sold_to_customer/name/last", doc.getDocumentElement()); + + common.setCustomerFirstName(firstName); + common.setCustomerLastName(lastName); + + String transaction_subtotal = xpath.evaluate("//transaction_subtotal", doc.getDocumentElement()); + String transaction_tax = xpath.evaluate("//transaction_tax", doc.getDocumentElement()); + String transaction_total = xpath.evaluate("//transaction_total", doc.getDocumentElement()); + + transaction.setTransactionSubtotal(null == transaction_subtotal ? null : new BigDecimal(transaction_subtotal)); + transaction.setTransactionTax(null == transaction_tax ? null : new BigDecimal(transaction_tax)); + transaction.setTransactionTotal(null == transaction_total ? null : new BigDecimal(transaction_total)); + + } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) { + e.printStackTrace(); + } + + common.setStatusData(statusData); + common.setTransaction(transaction); + + order.setMeta(meta); + order.setCommon(common); + + return order; + } +} diff --git a/src/main/java/com/example/services/order/Order.java b/src/main/java/com/example/services/order/Order.java new file mode 100644 index 0000000..b706ad7 --- /dev/null +++ b/src/main/java/com/example/services/order/Order.java @@ -0,0 +1,235 @@ +package com.example.services.order; + +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.math.BigDecimal; +import java.sql.Timestamp; +public class Order { + private Meta meta; + private Common common; + private List lines = new ArrayList<>(); + private List history = new ArrayList<>(); + + // getters and setters for Order + public Meta getMeta() { return meta; } + public void setMeta(Meta meta) { this.meta = meta; } + public Common getCommon() { return common; } + public void setCommon(Common common) { this.common = common; } + public List getLines() { return lines; } + public void setLines(List lines) { this.lines = lines; } + public List getHistory() { return history; } + public void setHistory(List history) { this.history = history; } + + public static class Meta { + private long id; + + // getters and setters + + public String getModel() { + return "Order"; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + } + + public class Common { + private String orderId; + private String requestingLocationCd; + private String requestingSystemCd; + private String customerId; + private String customerFirstName; + private String customerLastName; + private String submitOrdMsg; + private Timestamp fdateCreation; + private boolean consumed; + private String shipforpickupLocationCd; + private String shipforpickupSystemCd; + private StatusData statusData; + private Transaction transaction; + + // getters for Common + public String getOrderId() { return orderId; } + public String getRequestingLocationCd() { return requestingLocationCd; } + public String getRequestingSystemCd() { return requestingSystemCd; } + public String getCustomerId() { return customerId; } + public String getCustomerFirstName() { return customerFirstName; } + public String getCustomerLastName() { return customerLastName; } + public String getSubmitOrdMsg() { return submitOrdMsg; } + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + public boolean isConsumed() { return consumed; } + public String getShipforpickupLocationCd() { return shipforpickupLocationCd; } + public String getShipforpickupSystemCd() { return shipforpickupSystemCd; } + + // setters for Common + public void setOrderId(String orderId) { this.orderId = orderId; } + public void setRequestingLocationCd(String requestingLocationCd) { this.requestingLocationCd = requestingLocationCd; } + public void setRequestingSystemCd(String requestingSystemCd) { this.requestingSystemCd = requestingSystemCd; } + public void setCustomerId(String customerId) { this.customerId = customerId; } + public void setCustomerFirstName(String customerFirstName) { this.customerFirstName = customerFirstName; } + public void setCustomerLastName(String customerLastName) { this.customerLastName = customerLastName; } + public void setSubmitOrdMsg(String submitOrdMsg) { this.submitOrdMsg = submitOrdMsg; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + public void setConsumed(boolean consumed) { this.consumed = consumed; } + public void setShipforpickupLocationCd(String shipforpickupLocationCd) { this.shipforpickupLocationCd = shipforpickupLocationCd; } + public void setShipforpickupSystemCd(String shipforpickupSystemCd) { this.shipforpickupSystemCd = shipforpickupSystemCd; } + + public class StatusData { + private String code; + private String title; + + // getters for StatusData + public String getCode() { return code; } + public String getTitle() { return title; } + + // setters for StatusData + public void setCode(String code) { this.code = code; } + public void setTitle(String title) { this.title = title; } + } + + // getters for order/statusdata + public StatusData getStatusData() { return statusData; } + + // setters for order/statusdata + public void setStatusData(StatusData statusData) { this.statusData = statusData; } + + public class Transaction { + + private Integer transactionTypeId; + private Timestamp transactionDate; + private String transactionNo; + private String transactionTypeDescription; + private BigDecimal transactionSubtotal; + private BigDecimal transactionTax; + private BigDecimal transactionTotal; + + // getters for Transaction + public Integer getTransactionTypeId() { return transactionTypeId; } + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return transactionDate != null ? formatter.format(transactionDate.toInstant()) : ""; + } + public String getTransactionNo() { return transactionNo; } + public String getTransactionTypeDescription() { return transactionTypeDescription; } + public BigDecimal getTransactionSubtotal() { return transactionSubtotal; } + public BigDecimal getTransactionTax() { return transactionTax; } + public BigDecimal getTransactionTotal() { return transactionTotal; } + + // setters for Transaction + public void setTransactionTypeId(Integer transactionTypeId) { this.transactionTypeId = transactionTypeId; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setTransactionNo(String transactionNo) { this.transactionNo = transactionNo; } + public void setTransactionTypeDescription(String transactionTypeDescription) { this.transactionTypeDescription = transactionTypeDescription; } + public void setTransactionSubtotal(BigDecimal transactionSubtotal) { this.transactionSubtotal = transactionSubtotal; } + public void setTransactionTax(BigDecimal transactionTax) { this.transactionTax = transactionTax; } + public void setTransactionTotal(BigDecimal transactionTotal) { this.transactionTotal = transactionTotal; } + } + + // getters for order/transaction + public Transaction getTransaction() { return transaction; } + + // setters for order/transaction + public void setTransaction(Transaction transaction) { this.transaction = transaction; } + } + + public class Lines { + private Long lineOrderId; + private Integer lineItemNo; + private String orderId; + private Long requestId; + private String lineItemOms; + private String itemId; + private Integer orderedLineQty; + private String status; + private Timestamp transactionDate; + private String shippingAgent; + private String trackingNumber; + private String fulfillmentId; + private String cartonNumber; + private Timestamp fdateCreation; + private Boolean consumed; + private List history = new ArrayList<>(); + + // getters + public Long getLineOrderId() { return lineOrderId; } + public Integer getLineItemNo() { return lineItemNo; } + public String getOrderId() { return orderId; } + public Long getRequestId() { return requestId; } + public String getLineItemOms() { return lineItemOms; } + public String getItemId() { return itemId; } + public Integer getOrderedLineQty() { return orderedLineQty; } + public String getStatus() { return status; } + public Timestamp getTransactionDate() { return transactionDate; } + public String getShippingAgent() { return shippingAgent; } + public String getTrackingNumber() { return trackingNumber; } + public String getFulfillmentId() { return fulfillmentId; } + public String getCartonNumber() { return cartonNumber; } + public Timestamp getFdateCreation() { return fdateCreation; } + public Boolean isConsumed() { return consumed; } + public List getHistory() { return history; } + + // setters + public void setLineOrderId(Long lineOrderId) { this.lineOrderId = lineOrderId; } + public void setLineItemNo(Integer lineItemNo) { this.lineItemNo = lineItemNo; } + public void setOrderId(String orderId) { this.orderId = orderId; } + public void setRequestId(Long requestId) { this.requestId = requestId; } + public void setLineItemOms(String lineItemOms) { this.lineItemOms = lineItemOms; } + public void setItemId(String itemId) { this.itemId = itemId; } + public void setOrderedLineQty(Integer orderedLineQty) { this.orderedLineQty = orderedLineQty; } + public void setStatus(String status) { this.status = status; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setShippingAgent(String shippingAgent) { this.shippingAgent = shippingAgent; } + public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } + public void setFulfillmentId(String fulfillmentId) { this.fulfillmentId = fulfillmentId; } + public void setCartonNumber(String cartonNumber) { this.cartonNumber = cartonNumber; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + public void setConsumed(Boolean consumed) { this.consumed = consumed; } + public void setHistory(List history) { this.history = history; } + } + + public class History { + private Integer statusId; + private Long Id; + private String status; + private Timestamp transactionDate; + private Timestamp fdateCreation; + + // Getters + public Integer getStatusId() { return statusId; } + public Long getId() { return Id; } + public String getStatus() { return status; } + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(transactionDate.toInstant()) : ""; + } + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + + // Setters + public void setStatusId(Integer statusId) { this.statusId = statusId; } + public void setId(Long Id) { this.Id = Id; } + public void setStatus(String status) { this.status = status; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + } +} diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index e9410c6..2259485 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -1,17 +1,17 @@ -# Development environment settings (dev) -dev.db.url=jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI -dev.db.oai.password=base -dev.db.com02.password=B1Xto9pAbtBCOxuecG7W +# Development DOTSOFT environment settings +dev.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI +dev.dotsoft.db.oai.password=base +dev.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W -# Pre-production environment settings (preprod) -preprod.db.url=jdbc:oracle:thin:@v-aspd-b01-ii-d.adic.lan:1521/IASPDI -preprod.db.oai.password=base -preprod.db.com02.password=B1Xto9pAbtBCOxuecG7W +# Pre-production DOTSOFT environment settings +preprod.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b01-ii-d.adic.lan:1521/IASPDI +preprod.dotsoft.db.oai.password=base +preprod.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W -# Production environment settings (prod) -prod.db.url=jdbc:oracle:thin:@v-aspd-b03-ip-d.adic.lan:1521/PASPDI -prod.db.oai.password=base -prod.db.com02.password=com20 +# Production DOTSOFT environment settings +prod.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b03-ip-d.adic.lan:1521/PASPDI +prod.dotsoft.db.oai.password=base +prod.dotsoft.db.com02.password=com20 # XSTORE environment settings xstore.db.url=jdbc:oracle:thin:@HOST:1521/XSTORE @@ -19,5 +19,14 @@ xstore.db.dtv.password=dtv xstore.db.repqueue.password=repqueue # XADMIN environment settings -xadmin.db.url=jdbc:oracle:thin:@p-ODBG-b01-ipDC.tech.ikks.lan:1522/PXSTOREI -xadmin.db.dtv.password=oY3poRSprOuqasO \ No newline at end of file +prod.xadmin.db.url=jdbc:oracle:thin:@p-ODBG-b01-ipDC.tech.ikks.lan:1522/PXSTOREI +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 + +# 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 + From 6016ce0dabece166ce06662e72258ab15f92a246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Wed, 10 Jan 2024 22:06:11 +0100 Subject: [PATCH 2/6] feat: obi and proximis --- pom.xml | 7 +- .../example/services/DatabaseConnectOBI.java | 16 ++- .../com/example/services/OrderService.java | 54 +++++++++- .../com/example/services/ProximisService.java | 102 ++++++++++++++++++ src/main/resources/api.properties | 5 + src/main/resources/db.properties | 8 +- 6 files changed, 175 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/example/services/ProximisService.java create mode 100644 src/main/resources/api.properties diff --git a/pom.xml b/pom.xml index c413cae..ad30694 100644 --- a/pom.xml +++ b/pom.xml @@ -64,13 +64,18 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - 2.13.0 + 2.13.0 org.glassfish.jersey.media jersey-media-json-jackson 2.13 + + org.json + json + 20231013 + diff --git a/src/main/java/com/example/services/DatabaseConnectOBI.java b/src/main/java/com/example/services/DatabaseConnectOBI.java index 30607f8..101d883 100644 --- a/src/main/java/com/example/services/DatabaseConnectOBI.java +++ b/src/main/java/com/example/services/DatabaseConnectOBI.java @@ -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 } } diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java index 4e746b3..278d5bb 100644 --- a/src/main/java/com/example/services/OrderService.java +++ b/src/main/java/com/example/services/OrderService.java @@ -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")); diff --git a/src/main/java/com/example/services/ProximisService.java b/src/main/java/com/example/services/ProximisService.java new file mode 100644 index 0000000..ec5ffc1 --- /dev/null +++ b/src/main/java/com/example/services/ProximisService.java @@ -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 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; + } + +} \ No newline at end of file diff --git a/src/main/resources/api.properties b/src/main/resources/api.properties new file mode 100644 index 0000000..1f8552a --- /dev/null +++ b/src/main/resources/api.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 diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index 2259485..da3d0a4 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -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 From 9b97645e53919db3aab110bf0e028d40074c0bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Sat, 13 Jan 2024 06:48:21 +0100 Subject: [PATCH 3/6] feat: obi API --- .../com/example/services/OrderService.java | 48 +------------------ .../com/example/services/ProximisService.java | 28 +++++++---- .../com/example/services/order/Order.java | 16 ------- src/main/resources/api.properties | 3 ++ 4 files changed, 25 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java index 278d5bb..b3ca503 100644 --- a/src/main/java/com/example/services/OrderService.java +++ b/src/main/java/com/example/services/OrderService.java @@ -6,9 +6,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import java.io.IOException; -import java.io.StringReader; -import java.math.BigDecimal; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -23,18 +20,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import org.json.JSONObject; import org.json.XML; @@ -140,7 +128,7 @@ public class OrderService { 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, " + + "oo.fdate_creation, oo.consumed, oo.shipforpickup_location_cd, oo.shipforpickup_system_cd, " + "ott.transaction_type_description " + "FROM obi_order oo " + "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id " @@ -267,7 +255,7 @@ public class OrderService { return Response.ok(jsonNode).build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No order found with the provided ID\"}").build(); + return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No transaction found with the provided ID\"}").build(); } } catch (SQLException e) { e.printStackTrace(); @@ -371,7 +359,6 @@ public class OrderService { common.setRequestingLocationCd(resultSet.getString("REQUESTING_LOCATION_CD")); common.setRequestingSystemCd(resultSet.getString("REQUESTING_SYSTEM_CD")); common.setCustomerId(resultSet.getString("CUSTOMER_ID")); - //common.setSubmitOrdMsg(resultSet.getString("SUBMIT_ORD_MSG")); common.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); common.setConsumed(resultSet.getBoolean("CONSUMED")); common.setShipforpickupLocationCd(resultSet.getString("SHIPFORPICKUP_LOCATION_CD")); @@ -382,37 +369,6 @@ public class OrderService { transaction.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); transaction.setTransactionTypeDescription(resultSet.getString("TRANSACTION_TYPE_DESCRIPTION")); - // get subtotal, tax, total - String xmlString = resultSet.getString("SUBMIT_ORD_MSG"); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder; - - try { - builder = factory.newDocumentBuilder(); - Document doc = builder.parse(new InputSource(new StringReader(xmlString))); - doc.getDocumentElement().normalize(); - - XPathFactory xPathfactory = XPathFactory.newInstance(); - XPath xpath = xPathfactory.newXPath(); - - String firstName = xpath.evaluate("//sold_to_customer/name/first", doc.getDocumentElement()); - String lastName = xpath.evaluate("//sold_to_customer/name/last", doc.getDocumentElement()); - - common.setCustomerFirstName(firstName); - common.setCustomerLastName(lastName); - - String transaction_subtotal = xpath.evaluate("//transaction_subtotal", doc.getDocumentElement()); - String transaction_tax = xpath.evaluate("//transaction_tax", doc.getDocumentElement()); - String transaction_total = xpath.evaluate("//transaction_total", doc.getDocumentElement()); - - transaction.setTransactionSubtotal(null == transaction_subtotal ? null : new BigDecimal(transaction_subtotal)); - transaction.setTransactionTax(null == transaction_tax ? null : new BigDecimal(transaction_tax)); - transaction.setTransactionTotal(null == transaction_total ? null : new BigDecimal(transaction_total)); - - } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) { - e.printStackTrace(); - } - common.setStatusData(statusData); common.setTransaction(transaction); diff --git a/src/main/java/com/example/services/ProximisService.java b/src/main/java/com/example/services/ProximisService.java index ec5ffc1..562493a 100644 --- a/src/main/java/com/example/services/ProximisService.java +++ b/src/main/java/com/example/services/ProximisService.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,15 +37,19 @@ public class ProximisService { String environment = loadEnvironment(); + environment = "preprod"; //TODO ATTENTION !!! 1382020000348 + try { Properties apiProperties = loadApiProperties(); String url = apiProperties.getProperty(environment + ".proximis.api.url"); + String urlApp = apiProperties.getProperty(environment + ".proximis.app.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 = ?"; + String query = "SELECT authorization_value FROM obi.obi_param_access_token WHERE authorization_header = ?" + + " and cloud_type = 'PROXIMIS' AND application = 'OBI_ACCESS_TOKEN' AND version = 'V2'"; PreparedStatement stmt = databaseConnection.getConnection().prepareStatement(query); stmt.setString(1, "Authorization"); @@ -56,7 +61,7 @@ public class ProximisService { } if (bearerToken == null || bearerToken.isEmpty()) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Failed to access proximis API\"}").build(); + return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"Empty bearer token\"}").build(); } else { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() @@ -66,16 +71,24 @@ public class ProximisService { .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - + if (response.statusCode() == 200) { - return Response.ok(response.body()).build(); + JSONObject commonObject = new JSONObject(); + commonObject.put("urlApp", urlApp); + + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("common", commonObject); + jsonResponse.put("oms", new JSONObject(response.body())); + + return Response.ok(jsonResponse.toString()).build(); + } else if (response.statusCode() == 401) { + return Response.status(Response.Status.UNAUTHORIZED).entity("{\"error\":\"Invalid token\"}").build(); } else { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Failed to get order detail\"}").build(); + return Response.status(Response.Status.NOT_FOUND).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(); + return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("{\"error\":\"Unexpected error\"}").build(); } } @@ -98,5 +111,4 @@ public class ProximisService { } return properties; } - } \ No newline at end of file diff --git a/src/main/java/com/example/services/order/Order.java b/src/main/java/com/example/services/order/Order.java index b706ad7..7887414 100644 --- a/src/main/java/com/example/services/order/Order.java +++ b/src/main/java/com/example/services/order/Order.java @@ -4,7 +4,6 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; -import java.math.BigDecimal; import java.sql.Timestamp; public class Order { private Meta meta; @@ -45,8 +44,6 @@ public class Order { private String requestingLocationCd; private String requestingSystemCd; private String customerId; - private String customerFirstName; - private String customerLastName; private String submitOrdMsg; private Timestamp fdateCreation; private boolean consumed; @@ -60,8 +57,6 @@ public class Order { public String getRequestingLocationCd() { return requestingLocationCd; } public String getRequestingSystemCd() { return requestingSystemCd; } public String getCustomerId() { return customerId; } - public String getCustomerFirstName() { return customerFirstName; } - public String getCustomerLastName() { return customerLastName; } public String getSubmitOrdMsg() { return submitOrdMsg; } public String getFdateCreation() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") @@ -78,8 +73,6 @@ public class Order { public void setRequestingLocationCd(String requestingLocationCd) { this.requestingLocationCd = requestingLocationCd; } public void setRequestingSystemCd(String requestingSystemCd) { this.requestingSystemCd = requestingSystemCd; } public void setCustomerId(String customerId) { this.customerId = customerId; } - public void setCustomerFirstName(String customerFirstName) { this.customerFirstName = customerFirstName; } - public void setCustomerLastName(String customerLastName) { this.customerLastName = customerLastName; } public void setSubmitOrdMsg(String submitOrdMsg) { this.submitOrdMsg = submitOrdMsg; } public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } public void setConsumed(boolean consumed) { this.consumed = consumed; } @@ -111,9 +104,6 @@ public class Order { private Timestamp transactionDate; private String transactionNo; private String transactionTypeDescription; - private BigDecimal transactionSubtotal; - private BigDecimal transactionTax; - private BigDecimal transactionTotal; // getters for Transaction public Integer getTransactionTypeId() { return transactionTypeId; } @@ -125,18 +115,12 @@ public class Order { } public String getTransactionNo() { return transactionNo; } public String getTransactionTypeDescription() { return transactionTypeDescription; } - public BigDecimal getTransactionSubtotal() { return transactionSubtotal; } - public BigDecimal getTransactionTax() { return transactionTax; } - public BigDecimal getTransactionTotal() { return transactionTotal; } // setters for Transaction public void setTransactionTypeId(Integer transactionTypeId) { this.transactionTypeId = transactionTypeId; } public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } public void setTransactionNo(String transactionNo) { this.transactionNo = transactionNo; } public void setTransactionTypeDescription(String transactionTypeDescription) { this.transactionTypeDescription = transactionTypeDescription; } - public void setTransactionSubtotal(BigDecimal transactionSubtotal) { this.transactionSubtotal = transactionSubtotal; } - public void setTransactionTax(BigDecimal transactionTax) { this.transactionTax = transactionTax; } - public void setTransactionTotal(BigDecimal transactionTotal) { this.transactionTotal = transactionTotal; } } // getters for order/transaction diff --git a/src/main/resources/api.properties b/src/main/resources/api.properties index 1f8552a..53850a0 100644 --- a/src/main/resources/api.properties +++ b/src/main/resources/api.properties @@ -1,5 +1,8 @@ # Pre-production API Proximis preprod.proximis.api.url=https://proximis-ikks-recette.stg.proximis.com/publicAPI.php/V2 +preprod.proximis.app.url=https://proximis-ikks-recette.stg.proximis.com # production API Proximis prod.proximis.api.url=https://ikks.omn.proximis.com/publicAPI.php/V2 +prod.proximis.app.url=https://ikks.omn.proximis.com + From bac5868b7277bc67615d11482956fec4296ae572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Sat, 13 Jan 2024 07:09:54 +0100 Subject: [PATCH 4/6] fix: preprod, prod xadmin env --- src/main/java/com/example/services/DatabaseConnectOBI.java | 2 -- src/main/java/com/example/services/ProximisService.java | 2 -- src/main/resources/db.properties | 2 ++ src/main/resources/env.properties | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/services/DatabaseConnectOBI.java b/src/main/java/com/example/services/DatabaseConnectOBI.java index 101d883..6087394 100644 --- a/src/main/java/com/example/services/DatabaseConnectOBI.java +++ b/src/main/java/com/example/services/DatabaseConnectOBI.java @@ -18,8 +18,6 @@ public class DatabaseConnectOBI implements AutoCloseable { public DatabaseConnectOBI() throws SQLException { String environment = loadEnvironment(); - environment = "preprod"; //TODO ATTENTION !!! - try { Properties dbProperties = loadDatabaseProperties(); diff --git a/src/main/java/com/example/services/ProximisService.java b/src/main/java/com/example/services/ProximisService.java index 562493a..88ba610 100644 --- a/src/main/java/com/example/services/ProximisService.java +++ b/src/main/java/com/example/services/ProximisService.java @@ -37,8 +37,6 @@ public class ProximisService { String environment = loadEnvironment(); - environment = "preprod"; //TODO ATTENTION !!! 1382020000348 - try { Properties apiProperties = loadApiProperties(); String url = apiProperties.getProperty(environment + ".proximis.api.url"); diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index da3d0a4..3930020 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -19,6 +19,8 @@ xstore.db.dtv.password=dtv xstore.db.repqueue.password=repqueue # XADMIN environment settings +preprod.xadmin.db.url=jdbc:oracle:thin:@v-xsto-b01-irdc.adic.lan:1521/RXSTOI +preprod.xadmin.db.dtv.password=Dtv.x#33 prod.xadmin.db.url=jdbc:oracle:thin:@p-ODBG-b01-ipDC.tech.ikks.lan:1522/PXSTOREI prod.xadmin.db.dtv.password=oY3poRSprOuqasO diff --git a/src/main/resources/env.properties b/src/main/resources/env.properties index e30e658..40b8a7c 100644 --- a/src/main/resources/env.properties +++ b/src/main/resources/env.properties @@ -1,2 +1,2 @@ # Indicates the current environment (dev, preprod, prod, etc.). -environment=prod \ No newline at end of file +environment=preprod \ No newline at end of file From 0065ac650c13621996f81245a16be2c5631417a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Mon, 15 Jan 2024 00:23:23 +0100 Subject: [PATCH 5/6] feat: Order preparation and reception --- .../com/example/services/OrderService.java | 282 +++++++++++++++-- .../com/example/services/order/Order.java | 285 +++++++++++++++++- src/main/resources/env.properties | 2 +- 3 files changed, 537 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java index b3ca503..8b6dc5a 100644 --- a/src/main/java/com/example/services/OrderService.java +++ b/src/main/java/com/example/services/OrderService.java @@ -116,7 +116,7 @@ public class OrderService { String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}"; return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build(); } -} + } @GET @Path("/order/{requestId}") @@ -126,6 +126,7 @@ public class OrderService { DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) { + // ORDER SECTION --------------------------------- 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.fdate_creation, oo.consumed, oo.shipforpickup_location_cd, oo.shipforpickup_system_cd, " @@ -143,6 +144,7 @@ public class OrderService { if (resultSet.next()) { Order order = mapResultSetToOrder(resultSet); + // ORDER LINES SECTION --------------------------------- String orderLinesQuery = "SELECT olo.line_order_id, olo.line_item_no, olo.order_id, olo.request_id, olo.line_item_oms, " + "olo.item_id, olo.ordered_line_qty, olo.status, olo.transaction_date, olo.shipping_agent, " + "olo.tracking_number, olo.fulfillment_id, olo.carton_number, olo.fdate_creation, olo.consumed " @@ -185,36 +187,167 @@ public class OrderService { order.setLines(orderLinesList); } - - String orderHistoryQuery = "SELECT oho.status_id, oho.request_id, oho.status, oho.transaction_date, oho.fdate_creation " - + "FROM obi.obi_h_order oho " - + "WHERE oho.request_id = ? " - + "ORDER BY oho.status_id DESC"; - - logger.info(orderHistoryQuery); - - try (PreparedStatement orderHistoryStatement = databaseConnection.getConnection().prepareStatement(orderHistoryQuery)) { - orderHistoryStatement.setLong(1, requestId); - - try (ResultSet orderHistoryResultSet = orderHistoryStatement.executeQuery()) { - List orderHistoryList = new ArrayList<>(); - - while (orderHistoryResultSet.next()) { - orderHistoryList.add(mapResultSetToOrderHistory(orderHistoryResultSet)); - } - - order.setHistory(orderHistoryList); - } - } - - ObjectMapper objectMapper = new ObjectMapper(); - String jsonResponse = objectMapper.writeValueAsString(order); - - return Response.ok(jsonResponse).build(); - } catch (SQLException e) { - e.printStackTrace(); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"" + e.getMessage() + "\"}").build(); } + + // ORDER HISTORY SECTION --------------------------------- + String orderHistoryQuery = "SELECT oho.status_id, oho.request_id, oho.status, oho.transaction_date, oho.fdate_creation " + + "FROM obi.obi_h_order oho " + + "WHERE oho.request_id = ? " + + "ORDER BY oho.status_id DESC"; + + logger.info(orderHistoryQuery); + + try (PreparedStatement orderHistoryStatement = databaseConnection.getConnection().prepareStatement(orderHistoryQuery)) { + orderHistoryStatement.setLong(1, requestId); + + try (ResultSet orderHistoryResultSet = orderHistoryStatement.executeQuery()) { + List orderHistoryList = new ArrayList<>(); + + while (orderHistoryResultSet.next()) { + orderHistoryList.add(mapResultSetToOrderHistory(orderHistoryResultSet)); + } + + order.setHistory(orderHistoryList); + } + } + + // PREPARATION SECTION --------------------------------- + String preparationQuery = "SELECT oop.prep_int_id, oop.prep_id, oop.order_id, oop.request_id, oop.transaction_date, oop.fulfillment_system_cd, " + + "oop.fulfillment_location_cd, oop.status, oop.date_prepartion, oop.fdate_creation " + + "FROM obi.obi_order_prep oop " + + "WHERE oop.request_id = ? " + + "ORDER BY oop.prep_int_id DESC"; + + logger.info(preparationQuery); + + try(PreparedStatement preparationStatement = databaseConnection.getConnection().prepareStatement(preparationQuery)) { + preparationStatement.setLong(1, requestId); + + try(ResultSet preparationResultSet = preparationStatement.executeQuery()) { + List preparationList = new ArrayList<>(); + + while(preparationResultSet.next()) { + preparationList.add(mapResultSetToPreparation(preparationResultSet)); + + // PREPARATION LINES SECTION --------------------------------- + String preparationLinesQuery = + "SELECT " + + "olop.line_fulfill_id, " + + "olop.line_order_id, " + + "olop.prep_int_id, " + + "olop.order_id, " + + "olop.request_id, " + + "olop.transaction_date, " + + "olop.line_item_no, " + + "olop.item_id, " + + "olop.line_item_oms, " + + "olop.fulfill_qty, " + + "olop.validated_fulfill_qty, " + + "olop.fulfillment_system_cd, " + + "olop.fulfillment_location_cd, " + + "olop.status, " + + "olop.numero_expedition, " + + "olop.season_code, " + + "olop.finition_speciale, " + + "olop.carrier, " + + "olop.tracking_code, " + + "olop.tracking_url, " + + "olop.fdate_creation, " + + "olop.fdate_modification, " + + "olop.to_orlix_consumed, " + + "null as restocking_code " //"olop.restocking_code " + + "FROM obi.obi_ln_order_prep olop " + + "WHERE olop.prep_int_id = ? " + + "ORDER BY olop.line_item_oms"; + + logger.info(preparationLinesQuery); + + try(PreparedStatement preparationLinesStatement = databaseConnection.getConnection().prepareStatement(preparationLinesQuery)) { + preparationLinesStatement.setLong(1, preparationList.get(preparationList.size() - 1).getPrepIntId()); + + try(ResultSet preparationLinesResultSet = preparationLinesStatement.executeQuery()) { + List preparationLinesList = new ArrayList<>(); + + while(preparationLinesResultSet.next()) { + preparationLinesList.add(mapResultSetToPreparationLines(preparationLinesResultSet)); + } + + preparationList.get(preparationList.size() - 1).setLines(preparationLinesList); + } + } + } + + order.setPreparations(preparationList); + } + } + + // RECEPTION SECTION --------------------------------- + String receptionQuery = "SELECT ocr.intransit_int_id, ocr.intransit_id, ocr.prep_int_id, " + + "ocr.order_id, ocr.request_id, ocr.status, ocr.transaction_date, " + + "ocr.intransit_system_cd, ocr.intransit_location_cd, ocr.fdate_receipt, " + + "ocr.fdate_creation " + + "FROM obi.obi_cr_receipt ocr " + + "WHERE ocr.request_id = ? " + + "ORDER BY ocr.intransit_id DESC"; + + logger.info(receptionQuery); + + try(PreparedStatement receptionStatement = databaseConnection.getConnection().prepareStatement(receptionQuery)) { + receptionStatement.setLong(1, requestId); + + try(ResultSet receptionResultSet = receptionStatement.executeQuery()) { + List receptionList = new ArrayList<>(); + + while(receptionResultSet.next()) { + receptionList.add(mapResultSetToReception(receptionResultSet)); + + // RECEPTION LINES SECTION --------------------------------- + String receptionLinesQuery = "SELECT " + + "olcr.line_intransit_id AS line_intransit_id, " + + "olcr.intransit_int_id AS intransit_int_id, " + + "olcr.line_fulfill_id AS line_fulfill_id, " + + "olcr.transaction_date AS transaction_date, " + + "olcr.line_item_no AS line_item_no, " + + "olcr.item_id AS item_id, " + + "olcr.intransit_qty AS intransit_qty, " + + "olcr.validated_intransit_qty AS validated_intransit_qty, " + + "olcr.intransit_system_cd AS intransit_system_cd, " + + "olcr.intransit_location_cd AS intransit_location_cd, " + + "olcr.status AS status, " + + "olcr.colis_id AS colis_id, " + + "olcr.fdate_creation AS fdate_creation, " + + "olcr.fdate_receipt AS fdate_receipt, " + + "olcr.order_line_ship_weight AS order_line_ship_weight, " + + "olcr.tracking_number AS tracking_number " + + "FROM obi.obi_ln_cr_receipt olcr " + + "WHERE olcr.intransit_int_id = ? " + + "ORDER BY olcr.line_item_no"; + + logger.info(receptionLinesQuery); + + try(PreparedStatement receptionLinesStatement = databaseConnection.getConnection().prepareStatement(receptionLinesQuery)) { + receptionLinesStatement.setLong(1, receptionList.get(receptionList.size() - 1).getIntransitIntId()); + + try(ResultSet receptionLinesResultSet = receptionLinesStatement.executeQuery()) { + List receptionLinesList = new ArrayList<>(); + + while(receptionLinesResultSet.next()) { + receptionLinesList.add(mapResultSetToReceptionLines(receptionLinesResultSet)); + } + + receptionList.get(receptionList.size() - 1).setLines(receptionLinesList); + } + } + } + + order.setReceptions(receptionList); + } + } + + ObjectMapper objectMapper = new ObjectMapper(); + String jsonResponse = objectMapper.writeValueAsString(order); + + return Response.ok(jsonResponse).build(); } else { return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No order found\"}").build(); } @@ -271,6 +404,95 @@ public class OrderService { } } + private Order.Preparation.PreparationLines mapResultSetToPreparationLines(ResultSet resultSet) throws SQLException { + Order.Preparation.PreparationLines preparationLines = new Order().new Preparation().new PreparationLines(); + + preparationLines.setLineFulfillId(resultSet.getInt("LINE_FULFILL_ID")); + preparationLines.setLineOrderId(resultSet.getInt("LINE_ORDER_ID")); + preparationLines.setPrepIntId(resultSet.getInt("PREP_INT_ID")); + preparationLines.setOrderId(resultSet.getString("ORDER_ID")); + preparationLines.setRequestId(resultSet.getLong("REQUEST_ID")); + preparationLines.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + preparationLines.setLineItemNo(resultSet.getInt("LINE_ITEM_NO")); + preparationLines.setItemId(resultSet.getString("ITEM_ID")); + preparationLines.setLineItemOms(resultSet.getString("LINE_ITEM_OMS")); + preparationLines.setFulfillQty(resultSet.getInt("FULFILL_QTY")); + preparationLines.setValidatedFulfillQty(resultSet.getInt("VALIDATED_FULFILL_QTY")); + preparationLines.setFulfillmentSystemCd(resultSet.getString("FULFILLMENT_SYSTEM_CD")); + preparationLines.setFulfillmentLocationCd(resultSet.getString("FULFILLMENT_LOCATION_CD")); + preparationLines.setStatus(resultSet.getString("STATUS")); + preparationLines.setNumeroExpedition(resultSet.getString("NUMERO_EXPEDITION")); + preparationLines.setSeasonCode(resultSet.getString("SEASON_CODE")); + preparationLines.setFinitionSpeciale(resultSet.getString("FINITION_SPECIALE")); + preparationLines.setCarrier(resultSet.getString("CARRIER")); + preparationLines.setTrackingCode(resultSet.getString("TRACKING_CODE")); + preparationLines.setTrackingUrl(resultSet.getString("TRACKING_URL")); + preparationLines.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + preparationLines.setFdateModification(resultSet.getTimestamp("FDATE_MODIFICATION")); + preparationLines.setToOrlixConsumed(resultSet.getBoolean("TO_ORLIX_CONSUMED")); + preparationLines.setRestockingCode(resultSet.getString("RESTOCKING_CODE")); + + return preparationLines; + } + + private Order.Preparation mapResultSetToPreparation(ResultSet resultSet) throws SQLException { + Order.Preparation preparation = new Order().new Preparation(); + + preparation.setPrepIntId(resultSet.getInt("PREP_INT_ID")); + preparation.setPrepId(resultSet.getInt("PREP_ID")); + preparation.setOrderId(resultSet.getString("ORDER_ID")); + preparation.setRequestId(resultSet.getLong("REQUEST_ID")); + preparation.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + preparation.setFulfillmentSystemCd(resultSet.getString("FULFILLMENT_SYSTEM_CD")); + preparation.setFulfillmentLocationCd(resultSet.getString("FULFILLMENT_LOCATION_CD")); + preparation.setStatus(resultSet.getString("STATUS")); + preparation.setDatePreparation(resultSet.getTimestamp("DATE_PREPARTION")); + preparation.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + + return preparation; + } + + private Order.Reception.ReceptionLines mapResultSetToReceptionLines(ResultSet resultSet) throws SQLException { + Order.Reception.ReceptionLines receptionLines = new Order().new Reception().new ReceptionLines(); + + receptionLines.setLineIntransitId(resultSet.getInt("LINE_INTRANSIT_ID")); + receptionLines.setIntransitIntId(resultSet.getInt("INTRANSIT_INT_ID")); + receptionLines.setLineFulfillId(resultSet.getInt("LINE_FULFILL_ID")); + receptionLines.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + receptionLines.setLineItemNo(resultSet.getInt("LINE_ITEM_NO")); + receptionLines.setItemId(resultSet.getString("ITEM_ID")); + receptionLines.setIntransitQty(resultSet.getInt("INTRANSIT_QTY")); + receptionLines.setValidatedIntransitQty(resultSet.getInt("VALIDATED_INTRANSIT_QTY")); + receptionLines.setIntransitSystemCd(resultSet.getString("INTRANSIT_SYSTEM_CD")); + receptionLines.setIntransitLocationCd(resultSet.getString("INTRANSIT_LOCATION_CD")); + receptionLines.setStatus(resultSet.getString("STATUS")); + receptionLines.setColisId(resultSet.getString("COLIS_ID")); + receptionLines.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + receptionLines.setFdateReceipt(resultSet.getTimestamp("FDATE_RECEIPT")); + receptionLines.setOrderLineShipWeight(resultSet.getDouble("ORDER_LINE_SHIP_WEIGHT")); + receptionLines.setTrackingNumber(resultSet.getString("TRACKING_NUMBER")); + + return receptionLines; + } + + private Order.Reception mapResultSetToReception(ResultSet resultSet) throws SQLException { + Order.Reception reception = new Order().new Reception(); + + reception.setIntransitIntId(resultSet.getInt("INTRANSIT_INT_ID")); + reception.setIntransitId(resultSet.getString("INTRANSIT_ID")); + reception.setPrepIntId(resultSet.getInt("PREP_INT_ID")); + reception.setOrderId(resultSet.getString("ORDER_ID")); + reception.setRequestId(resultSet.getLong("REQUEST_ID")); + reception.setStatus(resultSet.getString("STATUS")); + reception.setTransactionDate(resultSet.getTimestamp("TRANSACTION_DATE")); + reception.setIntransitSystemCd(resultSet.getString("INTRANSIT_SYSTEM_CD")); + reception.setIntransitLocationCd(resultSet.getString("INTRANSIT_LOCATION_CD")); + reception.setFdateReceipt(resultSet.getTimestamp("FDATE_RECEIPT")); + reception.setFdateCreation(resultSet.getTimestamp("FDATE_CREATION")); + + return reception; + } + private Order.History mapResultSetToOrderLinesHistory(ResultSet resultSet) throws SQLException { Order.History orderLinesHistory = new Order().new History(); diff --git a/src/main/java/com/example/services/order/Order.java b/src/main/java/com/example/services/order/Order.java index 7887414..4ed6fb1 100644 --- a/src/main/java/com/example/services/order/Order.java +++ b/src/main/java/com/example/services/order/Order.java @@ -10,6 +10,8 @@ public class Order { private Common common; private List lines = new ArrayList<>(); private List history = new ArrayList<>(); + private List preparations = new ArrayList<>(); + private List receptions = new ArrayList<>(); // getters and setters for Order public Meta getMeta() { return meta; } @@ -20,6 +22,10 @@ public class Order { public void setLines(List lines) { this.lines = lines; } public List getHistory() { return history; } public void setHistory(List history) { this.history = history; } + public List getPreparations() { return preparations; } + public void setPreparations(List preparation) { this.preparations = preparation; } + public List getReceptions() { return receptions; } + public void setReceptions(List reception) { this.receptions = reception; } public static class Meta { private long id; @@ -99,7 +105,6 @@ public class Order { public void setStatusData(StatusData statusData) { this.statusData = statusData; } public class Transaction { - private Integer transactionTypeId; private Timestamp transactionDate; private String transactionNo; @@ -216,4 +221,282 @@ public class Order { public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } } + + public class Preparation { + private Integer prepIntId; + private Integer prepId; + private String orderId; + private Long requestId; + private Timestamp transactionDate; + private String fulfillmentSystemCd; + private String fulfillmentLocationCd; + private String status; + private Timestamp datePreparation; + private Timestamp fdateCreation; + private List lines = new ArrayList<>(); + + public List getLines() { return lines; } + public void setLines(List lines) { this.lines = lines; } + + // Getters + public Integer getPrepIntId() { return prepIntId; } + public Integer getPrepId() { return prepId; } + public String getOrderId() { return orderId; } + public Long getRequestId() { return requestId; } + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return transactionDate != null ? formatter.format(transactionDate.toInstant()) : ""; + } + public String getFulfillmentSystemCd() { return fulfillmentSystemCd; } + public String getFulfillmentLocationCd() { return fulfillmentLocationCd; } + public String getStatus() { return status; } + public String getDatePreparation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return datePreparation != null ? formatter.format(datePreparation.toInstant()) : ""; + } + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + + // Setters + public void setPrepIntId(Integer prepIntId) { this.prepIntId = prepIntId; } + public void setPrepId(Integer prepId) { this.prepId = prepId; } + public void setOrderId(String orderId) { this.orderId = orderId; } + public void setRequestId(Long requestId) { this.requestId = requestId; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setFulfillmentSystemCd(String fulfillmentSystemCd) { this.fulfillmentSystemCd = fulfillmentSystemCd; } + public void setFulfillmentLocationCd(String fulfillmentLocationCd) { this.fulfillmentLocationCd = fulfillmentLocationCd; } + public void setStatus(String status) { this.status = status; } + public void setDatePreparation(Timestamp datePreparation) { this.datePreparation = datePreparation; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + + public class PreparationLines { + private Integer lineFulfillId; + private Integer lineOrderId; + private Integer prepIntId; + private String orderId; + private Long requestId; + private Timestamp transactionDate; + private Integer lineItemNo; + private String itemId; + private String lineItemOms; + private Integer fulfillQty; + private Integer validatedFulfillQty; + private String fulfillmentSystemCd; + private String fulfillmentLocationCd; + private String status; + private String numeroExpedition; + private String seasonCode; + private String finitionSpeciale; + private String carrier; + private String trackingCode; + private String trackingUrl; + private Timestamp fdateCreation; + private Timestamp fdateModification; + private Boolean toOrlixConsumed; + private String restockingCode; + + // Getters + public Integer getLineFulfillId() { return lineFulfillId; } + public Integer getLineOrderId() { return lineOrderId; } + public Integer getPrepIntId() { return prepIntId; } + public String getOrderId() { return orderId; } + public Long getRequestId() { return requestId; } + + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return transactionDate != null ? formatter.format(transactionDate.toInstant()) : ""; + } + + public Integer getLineItemNo() { return lineItemNo; } + public String getItemId() { return itemId; } + public String getLineItemOms() { return lineItemOms; } + public Integer getFulfillQty() { return fulfillQty; } + public Integer getValidatedFulfillQty() { return validatedFulfillQty; } + public String getFulfillmentSystemCd() { return fulfillmentSystemCd; } + public String getFulfillmentLocationCd() { return fulfillmentLocationCd; } + public String getStatus() { return status; } + public String getNumeroExpedition() { return numeroExpedition; } + public String getSeasonCode() { return seasonCode; } + public String getFinitionSpeciale() { return finitionSpeciale; } + public String getCarrier() { return carrier; } + public String getTrackingCode() { return trackingCode; } + public String getTrackingUrl() { return trackingUrl; } + + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + + public String getFdateModification() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return fdateModification != null ? formatter.format(fdateModification.toInstant()) : ""; + } + + public Boolean getToOrlixConsumed() { return toOrlixConsumed; } + public String getRestockingCode() { return restockingCode; } + + // Setters + public void setLineFulfillId(Integer lineFulfillId) { this.lineFulfillId = lineFulfillId; } + public void setLineOrderId(Integer lineOrderId) { this.lineOrderId = lineOrderId; } + public void setPrepIntId(Integer prepIntId) { this.prepIntId = prepIntId; } + public void setOrderId(String orderId) { this.orderId = orderId; } + public void setRequestId(Long requestId) { this.requestId = requestId; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setLineItemNo(Integer lineItemNo) { this.lineItemNo = lineItemNo; } + public void setItemId(String itemId) { this.itemId = itemId; } + public void setLineItemOms(String lineItemOms) { this.lineItemOms = lineItemOms; } + public void setFulfillQty(Integer fulfillQty) { this.fulfillQty = fulfillQty; } + public void setValidatedFulfillQty(Integer validatedFulfillQty) { this.validatedFulfillQty = validatedFulfillQty; } + public void setFulfillmentSystemCd(String fulfillmentSystemCd) { this.fulfillmentSystemCd = fulfillmentSystemCd; } + public void setFulfillmentLocationCd(String fulfillmentLocationCd) { this.fulfillmentLocationCd = fulfillmentLocationCd; } + public void setStatus(String status) { this.status = status; } + public void setNumeroExpedition(String numeroExpedition) { this.numeroExpedition = numeroExpedition; } + public void setSeasonCode(String seasonCode) { this.seasonCode = seasonCode; } + public void setFinitionSpeciale(String finitionSpeciale) { this.finitionSpeciale = finitionSpeciale; } + public void setCarrier(String carrier) { this.carrier = carrier; } + public void setTrackingCode(String trackingCode) { this.trackingCode = trackingCode; } + public void setTrackingUrl(String trackingUrl) { this.trackingUrl = trackingUrl; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + public void setFdateModification(Timestamp fdateModification) { this.fdateModification = fdateModification; } + public void setToOrlixConsumed(Boolean toOrlixConsumed) { this.toOrlixConsumed = toOrlixConsumed; } + public void setRestockingCode(String restockingCode) { this.restockingCode = restockingCode; } + } + } + + public class Reception { + private int intransitIntId; + private String intransitId; + private int prepIntId; + private String orderId; + private long requestId; + private String status; + private Timestamp transactionDate; + private String intransitSystemCd; + private String intransitLocationCd; + private Timestamp fdateReceipt; + private Timestamp fdateCreation; + private List lines = new ArrayList<>(); + + public List getLines() { return lines; } + public void setLines(List lines) { this.lines = lines; } + + // Getters + public int getIntransitIntId() { return intransitIntId; } + public String getIntransitId() { return intransitId; } + public int getPrepIntId() { return prepIntId; } + public String getOrderId() { return orderId; } + public long getRequestId() { return requestId; } + public String getStatus() { return status; } + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(transactionDate.toInstant()) : ""; + } + public String getIntransitSystemCd() { return intransitSystemCd; } + public String getIntransitLocationCd() { return intransitLocationCd; } + public String getFdateReceipt() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateReceipt != null ? formatter.format(fdateReceipt.toInstant()) : ""; + } + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + + // Setters + public void setIntransitIntId(int intransitIntId) { this.intransitIntId = intransitIntId; } + public void setIntransitId(String intransitId) { this.intransitId = intransitId; } + public void setPrepIntId(int prepIntId) { this.prepIntId = prepIntId; } + public void setOrderId(String orderId) { this.orderId = orderId; } + public void setRequestId(long requestId) { this.requestId = requestId; } + public void setStatus(String status) { this.status = status; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setIntransitSystemCd(String intransitSystemCd) { this.intransitSystemCd = intransitSystemCd; } + public void setIntransitLocationCd(String intransitLocationCd) { this.intransitLocationCd = intransitLocationCd; } + public void setFdateReceipt(Timestamp fdateReceipt) { this.fdateReceipt = fdateReceipt; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + + public class ReceptionLines { + private int lineIntransitId; + private int intransitIntId; + private int lineFulfillId; + private Timestamp transactionDate; + private int lineItemNo; + private String itemId; + private int intransitQty; + private int validatedIntransitQty; + private String intransitSystemCd; + private String intransitLocationCd; + private String status; + private String colisId; + private Timestamp fdateCreation; + private Timestamp fdateReceipt; + private Double orderLineShipWeight; + private String trackingNumber; + + // Getters + public int getLineIntransitId() { return lineIntransitId; } + public int getIntransitIntId() { return intransitIntId; } + public int getLineFulfillId() { return lineFulfillId; } + public String getTransactionDate() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return transactionDate != null ? formatter.format(transactionDate.toInstant()) : ""; + } + public int getLineItemNo() { return lineItemNo; } + public String getItemId() { return itemId; } + public int getIntransitQty() { return intransitQty; } + public int getValidatedIntransitQty() { return validatedIntransitQty; } + public String getIntransitSystemCd() { return intransitSystemCd; } + public String getIntransitLocationCd() { return intransitLocationCd; } + public String getStatus() { return status; } + public String getColisId() { return colisId; } + public String getFdateCreation() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return fdateCreation != null ? formatter.format(fdateCreation.toInstant()) : ""; + } + public String getFdateReceipt() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX") + .withZone(ZoneId.of("Europe/Paris")); + return fdateReceipt != null ? formatter.format(fdateReceipt.toInstant()) : ""; + } + public Double getOrderLineShipWeight() { return orderLineShipWeight; } + public String getTrackingNumber() { return trackingNumber; } + + // Setters + public void setLineIntransitId(int lineIntransitId) { this.lineIntransitId = lineIntransitId; } + public void setIntransitIntId(int intransitIntId) { this.intransitIntId = intransitIntId; } + public void setLineFulfillId(int lineFulfillId) { this.lineFulfillId = lineFulfillId; } + public void setTransactionDate(Timestamp transactionDate) { this.transactionDate = transactionDate; } + public void setLineItemNo(int lineItemNo) { this.lineItemNo = lineItemNo; } + public void setItemId(String itemId) { this.itemId = itemId; } + public void setIntransitQty(int intransitQty) { this.intransitQty = intransitQty; } + public void setValidatedIntransitQty(int validatedIntransitQty) { this.validatedIntransitQty = validatedIntransitQty; } + public void setIntransitSystemCd(String intransitSystemCd) { this.intransitSystemCd = intransitSystemCd; } + public void setIntransitLocationCd(String intransitLocationCd) { this.intransitLocationCd = intransitLocationCd; } + public void setStatus(String status) { this.status = status; } + public void setColisId(String colisId) { this.colisId = colisId; } + public void setFdateCreation(Timestamp fdateCreation) { this.fdateCreation = fdateCreation; } + public void setFdateReceipt(Timestamp fdateReceipt) { this.fdateReceipt = fdateReceipt; } + public void setOrderLineShipWeight(Double orderLineShipWeight) { this.orderLineShipWeight = orderLineShipWeight; } + public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; } + } + } } diff --git a/src/main/resources/env.properties b/src/main/resources/env.properties index 40b8a7c..e30e658 100644 --- a/src/main/resources/env.properties +++ b/src/main/resources/env.properties @@ -1,2 +1,2 @@ # Indicates the current environment (dev, preprod, prod, etc.). -environment=preprod \ No newline at end of file +environment=prod \ No newline at end of file From 2b26a170356aab7e6a340ba1c4717eb2e715dc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rik=20BENOIST?= Date: Sun, 21 Jan 2024 16:31:52 +0100 Subject: [PATCH 6/6] feat: obi visualization --- .../com/example/services/ItemService.java | 8 ++ .../com/example/services/OrderService.java | 118 ++++++++++++++++-- .../com/example/services/StoreService.java | 23 +++- 3 files changed, 132 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/services/ItemService.java b/src/main/java/com/example/services/ItemService.java index 958184d..cd7569d 100644 --- a/src/main/java/com/example/services/ItemService.java +++ b/src/main/java/com/example/services/ItemService.java @@ -53,6 +53,8 @@ public class ItemService { try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(dbHost, "dtv")) { String query = "SELECT * FROM dtv.ITM_ITEM WHERE ORGANIZATION_ID = 1 AND ITEM_ID LIKE ?"; + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { // Concatenate % to parameter itemId statement.setString(1, itemId + "%"); @@ -105,6 +107,8 @@ public class ItemService { "FROM dtv.ITM_ITEM_OPTIONS " + "WHERE ORGANIZATION_ID = 1 AND ITEM_ID LIKE ?"; + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { // Concatenate % to parameter itemId statement.setString(1, itemId + "%"); @@ -157,6 +161,8 @@ public class ItemService { "FROM dtv.itm_item_prices " + "WHERE organization_id = 1 AND item_id LIKE ?"; + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { // Concatenate % to parameter itemId statement.setString(1, itemId + "%"); @@ -209,6 +215,8 @@ public class ItemService { "FROM dtv.inv_stock_ledger_acct " + "WHERE organization_id = 1 AND item_id LIKE ?"; + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { // Concatenate % to parameter itemId statement.setString(1, itemId + "%"); diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java index 8b6dc5a..d6b8950 100644 --- a/src/main/java/com/example/services/OrderService.java +++ b/src/main/java/com/example/services/OrderService.java @@ -4,12 +4,16 @@ 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.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; @@ -35,28 +39,58 @@ public class OrderService { @Path("/order") @Produces(MediaType.APPLICATION_JSON) public Response getAllOrders(@QueryParam("q") String q, - @QueryParam("page") int page, - @QueryParam("itemsPerPage") int itemsPerPage, - @QueryParam("sortBy") String sortBy, - @QueryParam("orderBy") String orderBy) { + @QueryParam("page") int page, + @QueryParam("itemsPerPage") int itemsPerPage, + @QueryParam("sortBy") String sortBy, + @QueryParam("orderBy") String orderBy, + @QueryParam("status") String status, + @QueryParam("type") String type, + @QueryParam("minDate") String minDate, + @QueryParam("maxDate") String maxDate) { DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) { - String countQuery = "SELECT COUNT(*) FROM obi_order oo "; + String countQuery = "SELECT COUNT(*), " + + "SUM (CASE WHEN oo.status = 'new_order' THEN 1 ELSE 0 END) AS stat_status1, " + + "SUM (CASE WHEN oo.status = 'polled' THEN 1 ELSE 0 END) AS stat_status2, " + + "SUM (CASE WHEN oo.status = 'fulfilled' THEN 1 ELSE 0 END) AS stat_status3, " + + "SUM (CASE WHEN oo.status = 'received' THEN 1 ELSE 0 END) AS stat_status4, " + + "SUM (CASE WHEN oo.status = 'unfulfillable' THEN 1 ELSE 0 END) AS stat_status5, " + + "SUM (CASE WHEN oo.status = 'canceled' THEN 1 ELSE 0 END) AS stat_status6 " + + "FROM obi_order oo " + + "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id"; + String query = - "SELECT oo.request_id, " + - "oo.order_id, " + - "oo.transaction_date, " + - "oo.status as status, " + - "ott.transaction_type_description " + - "FROM obi_order oo " + - "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id"; + "SELECT oo.request_id, " + + "oo.order_id, " + + "oo.transaction_date, " + + "oo.status as status, " + + "ott.transaction_type_description " + + "FROM obi_order oo " + + "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id"; List conditions = new ArrayList<>(); if (q != null && !q.isEmpty()) { conditions.add(" oo.order_id LIKE ? "); } + + if (status != null && !status.isEmpty()) { + conditions.add(" oo.status = ? "); + } + + if (type != null && !type.isEmpty()) { + conditions.add(" ott.transaction_type_code = ? "); + } + + if (minDate != null && !minDate.isEmpty()) { + conditions.add(" oo.transaction_date >= ? "); + } + + if (maxDate != null && !maxDate.isEmpty()) { + conditions.add(" oo.transaction_date <= ? "); + } + if (!conditions.isEmpty()) { countQuery += " WHERE " + String.join(" AND ", conditions); query += " WHERE " + String.join(" AND ", conditions); @@ -83,9 +117,54 @@ public class OrderService { statement.setString(index++, "%" + q + "%"); } + if(status != null && !status.isEmpty()) { + countStatement.setString(index, status ); + statement.setString(index++, status ); + } + + if (type != null && !type.isEmpty()) { + countStatement.setString(index, type); + statement.setString(index++, type); + } + + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); + + if (minDate != null && !minDate.isEmpty()) { + logger.info("minDate: " + minDate); + try { + java.util.Date parsedMinDate = dateFormat.parse(minDate); + java.sql.Date sqlMinDate = new java.sql.Date(parsedMinDate.getTime()); + + countStatement.setDate(index, sqlMinDate); + statement.setDate(index++, sqlMinDate); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + if (maxDate != null && !maxDate.isEmpty()) { + logger.info("maxDate: " + maxDate); + try { + java.util.Date parsedMaxDate = dateFormat.parse(maxDate); + java.sql.Date sqlMaxDate = new java.sql.Date(parsedMaxDate.getTime()); + + countStatement.setDate(index, sqlMaxDate); + statement.setDate(index++, sqlMaxDate); + } catch (ParseException e) { + e.printStackTrace(); + } + } + ResultSet countResultSet = countStatement.executeQuery(); countResultSet.next(); int total = countResultSet.getInt(1); + int statStatus1 = countResultSet.getInt(2); + int statStatus2 = countResultSet.getInt(3); + int statStatus3 = countResultSet.getInt(4); + int statStatus4 = countResultSet.getInt(5); + int statStatus5 = countResultSet.getInt(6); + int statStatus6 = countResultSet.getInt(7); ResultSet resultSet = statement.executeQuery(); { List orderList = new ArrayList<>(); @@ -98,6 +177,21 @@ public class OrderService { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode responseNode = objectMapper.createObjectNode(); responseNode.put("total", total); + + ArrayNode statisticsArray = objectMapper.createArrayNode(); + String[] titles = {"new_order", "polled", "fulfilled", "received","unfulfillable","canceled"}; + String[] icons = {"tabler-calendar-stats", "tabler-progress-check", "tabler-checks", "tabler-checks","tabler-wallet","tabler-circle-x"}; + int[] counts = {statStatus1, statStatus2, statStatus3, statStatus4, statStatus5, statStatus6}; + + for (int i = 0; i < titles.length; i++) { + ObjectNode node = objectMapper.createObjectNode(); + node.put("title", titles[i]); + node.put("value", counts[i]); + node.put("icon", icons[i]); + statisticsArray.add(node); + } + responseNode.set("statistics", statisticsArray); + responseNode.set("orders", objectMapper.valueToTree(orderList)); String jsonResponse; diff --git a/src/main/java/com/example/services/StoreService.java b/src/main/java/com/example/services/StoreService.java index 26c888a..2ab56ed 100644 --- a/src/main/java/com/example/services/StoreService.java +++ b/src/main/java/com/example/services/StoreService.java @@ -76,6 +76,7 @@ public class StoreService { " WHERE st.id_structure = ?"; logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { statement.setString(1, storeId); @@ -186,7 +187,8 @@ public class StoreService { " WHERE axs.date_stock is not null AND st.ID_NIVEAU=4 AND st.STATUT=2 AND st.id_canal_distribution = 1 and st.magasin_demo = 0" + " ORDER BY st.id_structure"; - logger.info(query); + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query); ResultSet resultSet = statement.executeQuery()) { @@ -230,6 +232,7 @@ public class StoreService { "ORDER BY WKSTN_ID, SEQUENCE_ID"; logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { ResultSet resultSet = statement.executeQuery(); @@ -282,6 +285,7 @@ public class StoreService { "ORDER BY WKSTN_ID"; logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { ResultSet resultSet = statement.executeQuery(); @@ -335,7 +339,8 @@ public class StoreService { "WHERE organization_id = 1 AND customer IS NOT NULL " + "ORDER BY seq DESC"; - logger.info(query); + logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { ResultSet resultSet = statement.executeQuery(); @@ -449,6 +454,7 @@ public class StoreService { "ORDER BY cel.CREATE_DATE DESC"; logger.info(query); + try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) { statement.setString(1, logDate + " 00:00:00"); statement.setString(2, logDate + " 23:59:59"); @@ -659,6 +665,7 @@ public class StoreService { " WHERE st.id_structure = ?"; logger.info(storeQuery); + try (PreparedStatement storeStatement = databaseConnectionDS.getConnection().prepareStatement(storeQuery)) { storeStatement.setInt(1, storeId); // Set the value of the parameter @@ -685,6 +692,7 @@ public class StoreService { for (StorePos pos : storeDetails.getPos()) { logger.info(boTransactionQuery); + try (PreparedStatement boTransactionStatement = databaseConnectionDS.getConnection().prepareStatement(boTransactionQuery)) { boTransactionStatement.setInt(1, storeId); boTransactionStatement.setInt(2, pos.getWorkstationId()); @@ -720,6 +728,7 @@ public class StoreService { "WHERE crq.organization_id = 1 AND crq.RTL_LOC_ID = ? and crq.WKSTN_ID = ?"; logger.info(replicationQuery); + try (PreparedStatement replicationStatement = databaseConnection.getConnection().prepareStatement(replicationQuery)) { replicationStatement.setInt(1, storeId); replicationStatement.setInt(2, workstationId); @@ -746,7 +755,8 @@ public class StoreService { "AND lsj.STRING_VALUE = 'OPEN'"; logger.info(openingQuery); - try (PreparedStatement openingStatement = databaseConnection.getConnection().prepareStatement(openingQuery)) { + + try (PreparedStatement openingStatement = databaseConnection.getConnection().prepareStatement(openingQuery)) { openingStatement.setInt(1, storeId); openingStatement.setInt(2, workstationId); @@ -771,7 +781,8 @@ public class StoreService { "AND lsj.STRING_VALUE = 'CLOSED'"; logger.info(closingQuery); - try (PreparedStatement closingStatement = databaseConnection.getConnection().prepareStatement(closingQuery)) { + + try (PreparedStatement closingStatement = databaseConnection.getConnection().prepareStatement(closingQuery)) { closingStatement.setInt(1, storeId); closingStatement.setInt(2, workstationId); @@ -797,7 +808,8 @@ public class StoreService { "AND tt.trans_TYPCODE = 'RETAIL_SALE' " + "AND tt.TRANS_STATCODE = 'COMPLETE'"; - logger.info(saleTransactionQuery); + logger.info(saleTransactionQuery); + try (PreparedStatement saleTransactionStatement = databaseConnection.getConnection().prepareStatement(saleTransactionQuery)) { saleTransactionStatement.setInt(1, storeId); saleTransactionStatement.setDate(2, pos.getBusinessDate()); @@ -823,6 +835,7 @@ public class StoreService { "AND cel.LOG_LEVEL = 'FATAL'"; logger.info(logQuery); + try (PreparedStatement logStatement = databaseConnection.getConnection().prepareStatement(logQuery)) { logStatement.setInt(1, storeId); logStatement.setInt(2, workstationId);