feat: chatRCT
parent
60b8d222b4
commit
851a927265
|
|
@ -0,0 +1,15 @@
|
||||||
|
meta {
|
||||||
|
name: PromptDistributor
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/hdpos/api/chatrct/distributor/1?itemId=XY10000-08-3A
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
query {
|
||||||
|
itemId: XY10000-08-3A
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
meta {
|
||||||
|
name: PromptRCT
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/hdpos/api/chatrct/rct/XY10000-08-3A
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
meta {
|
||||||
|
name: Hello
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/hdpos/api/chatrct/hello
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
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 org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
@Path("/chatrct")
|
||||||
|
public class ChatRctService {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ChatRctService.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/hello")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getHello() {
|
||||||
|
return "# Bonjour'\\nIndiquez-moi la RCT sur laquelle vous souhaitez faire des recherches ...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/rct/{itemId}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getRctById(@PathParam("itemId") String itemId) {
|
||||||
|
|
||||||
|
if (itemId == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"itemId parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverManager.setLoginTimeout(5); // Set timeout to 5 seconds
|
||||||
|
|
||||||
|
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("omni")) {
|
||||||
|
String call = "{ call fbe_hdpos.chatrct_prompt_rct(?, ?) }";
|
||||||
|
|
||||||
|
logger.info(call);
|
||||||
|
|
||||||
|
try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(call)) {
|
||||||
|
// Set input parameters
|
||||||
|
callableStatement.setString(1, itemId);
|
||||||
|
|
||||||
|
// Set output parameters
|
||||||
|
callableStatement.registerOutParameter(2, Types.CLOB);
|
||||||
|
|
||||||
|
// Execute the stored procedure
|
||||||
|
callableStatement.execute();
|
||||||
|
|
||||||
|
// Retrieve results
|
||||||
|
Clob resultClob = callableStatement.getClob(2);
|
||||||
|
String result = resultClob.getSubString(1, (int) resultClob.length());
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonResponse = objectMapper.writeValueAsString(result);
|
||||||
|
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}";
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace(); // Gérer les exceptions correctement dans un environnement de production
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/distributor/{distributorId}")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getDistributorById(
|
||||||
|
@PathParam("distributorId") String distributorId,
|
||||||
|
@QueryParam("itemId") String itemId,
|
||||||
|
@QueryParam("produitId") String produitId) {
|
||||||
|
|
||||||
|
if (distributorId == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"distributorId parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemId == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"itemId parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverManager.setLoginTimeout(5); // Set timeout to 5 seconds
|
||||||
|
|
||||||
|
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("omni")) {
|
||||||
|
String call = "{ call fbe_hdpos.chatrct_prompt_distributor(?,?,?,?) }";
|
||||||
|
|
||||||
|
logger.info(call);
|
||||||
|
|
||||||
|
try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(call)) {
|
||||||
|
// Set input parameters
|
||||||
|
callableStatement.setString(1, distributorId);
|
||||||
|
callableStatement.setString(2, itemId);
|
||||||
|
callableStatement.setString(3, produitId);
|
||||||
|
|
||||||
|
// Set output parameters
|
||||||
|
callableStatement.registerOutParameter(4, Types.CLOB);
|
||||||
|
|
||||||
|
// Execute the stored procedure
|
||||||
|
callableStatement.execute();
|
||||||
|
|
||||||
|
// Retrieve results
|
||||||
|
Clob resultClob = callableStatement.getClob(4);
|
||||||
|
String result = resultClob.getSubString(1, (int) resultClob.length());
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonResponse = objectMapper.writeValueAsString(result);
|
||||||
|
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}";
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace(); // Gérer les exceptions correctement dans un environnement de production
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package com.example.services;
|
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.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
@ -14,10 +11,12 @@ import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.client.Client;
|
||||||
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -48,6 +47,9 @@ public class ProximisService {
|
||||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
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'";
|
+ " and cloud_type = 'PROXIMIS' AND application = 'OBI_ACCESS_TOKEN' AND version = 'V2'";
|
||||||
|
|
||||||
|
logger.info(query);
|
||||||
|
|
||||||
PreparedStatement stmt = databaseConnection.getConnection().prepareStatement(query);
|
PreparedStatement stmt = databaseConnection.getConnection().prepareStatement(query);
|
||||||
|
|
||||||
stmt.setString(1, "Authorization");
|
stmt.setString(1, "Authorization");
|
||||||
|
|
@ -61,28 +63,29 @@ public class ProximisService {
|
||||||
if (bearerToken == null || bearerToken.isEmpty()) {
|
if (bearerToken == null || bearerToken.isEmpty()) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"Empty bearer token\"}").build();
|
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"Empty bearer token\"}").build();
|
||||||
} else {
|
} else {
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
Client client = ClientBuilder.newClient();
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
WebTarget target = client.target(url + "/project/fulfillment/" + orderCode);
|
||||||
.uri(URI.create(url + "/project/fulfillment/" + orderCode))
|
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", bearerToken)
|
.header("Authorization", bearerToken)
|
||||||
.GET()
|
.get();
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
try {
|
||||||
|
if (response.getStatus() == 200) {
|
||||||
if (response.statusCode() == 200) {
|
JSONObject commonObject = new JSONObject();
|
||||||
JSONObject commonObject = new JSONObject();
|
commonObject.put("urlApp", urlApp);
|
||||||
commonObject.put("urlApp", urlApp);
|
|
||||||
|
JSONObject jsonResponse = new JSONObject();
|
||||||
JSONObject jsonResponse = new JSONObject();
|
jsonResponse.put("common", commonObject);
|
||||||
jsonResponse.put("common", commonObject);
|
jsonResponse.put("oms", new JSONObject(response.readEntity(String.class)));
|
||||||
jsonResponse.put("oms", new JSONObject(response.body()));
|
|
||||||
|
return Response.ok(jsonResponse.toString()).build();
|
||||||
return Response.ok(jsonResponse.toString()).build();
|
} else if (response.getStatus() == 401) {
|
||||||
} else if (response.statusCode() == 401) {
|
return Response.status(Response.Status.UNAUTHORIZED).entity("{\"error\":\"Invalid token\"}").build();
|
||||||
return Response.status(Response.Status.UNAUTHORIZED).entity("{\"error\":\"Invalid token\"}").build();
|
} else {
|
||||||
} else {
|
return Response.status(Response.Status.NOT_FOUND).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) {
|
||||||
|
return Response.serverError().entity("{\"error\":\"Failed to communicate with server\"}").build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,19 @@
|
||||||
dev.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI
|
dev.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI
|
||||||
dev.dotsoft.db.oai.password=base
|
dev.dotsoft.db.oai.password=base
|
||||||
dev.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W
|
dev.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W
|
||||||
|
dev.dotsoft.db.omni.password=k5.Omni.Paspdi
|
||||||
|
|
||||||
# Pre-production DOTSOFT environment settings
|
# Pre-production DOTSOFT environment settings
|
||||||
preprod.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b01-ii-d.adic.lan:1521/IASPDI
|
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.oai.password=base
|
||||||
preprod.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W
|
preprod.dotsoft.db.com02.password=B1Xto9pAbtBCOxuecG7W
|
||||||
|
preprod.dotsoft.db.omni.password=k5.Omni.Paspdi
|
||||||
|
|
||||||
# Production DOTSOFT environment settings
|
# Production DOTSOFT environment settings
|
||||||
prod.dotsoft.db.url=jdbc:oracle:thin:@v-aspd-b03-ip-d.adic.lan:1521/PASPDI
|
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.oai.password=base
|
||||||
prod.dotsoft.db.com02.password=com20
|
prod.dotsoft.db.com02.password=com20
|
||||||
|
prod.dotsoft.db.omni.password=k5.Omni.Paspdi
|
||||||
|
|
||||||
# XSTORE environment settings
|
# XSTORE environment settings
|
||||||
xstore.db.url=jdbc:oracle:thin:@HOST:1521/XSTORE
|
xstore.db.url=jdbc:oracle:thin:@HOST:1521/XSTORE
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
# Indicates the current environment (dev, preprod, prod, etc.).
|
# Indicates the current environment (dev, preprod, prod, etc.).
|
||||||
environment=prod
|
environment=preprod
|
||||||
Loading…
Reference in New Issue