feat: obi API
parent
6016ce0dab
commit
9b97645e53
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
@ -68,14 +73,22 @@ public class ProximisService {
|
|||
HttpResponse<String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue