diff --git a/bruno/chatrct/PromptActions.bru b/bruno/chatrct/PromptActions.bru new file mode 100644 index 0000000..8b05105 --- /dev/null +++ b/bruno/chatrct/PromptActions.bru @@ -0,0 +1,16 @@ +meta { + name: PromptActions + type: http + seq: 5 +} + +get { + url: {{host}}/hdpos/api/chatrct/actions?itemId=XY10000-08-3A&produitId=3700824 + body: none + auth: none +} + +query { + itemId: XY10000-08-3A + produitId: 3700824 +} diff --git a/bruno/chatrct/PromptDistributor.bru b/bruno/chatrct/PromptDistributor.bru new file mode 100644 index 0000000..91c15a4 --- /dev/null +++ b/bruno/chatrct/PromptDistributor.bru @@ -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 +} diff --git a/bruno/chatrct/PromptRCT.bru b/bruno/chatrct/PromptRCT.bru new file mode 100644 index 0000000..273dfdc --- /dev/null +++ b/bruno/chatrct/PromptRCT.bru @@ -0,0 +1,15 @@ +meta { + name: PromptRCT + type: http + seq: 2 +} + +get { + url: {{host}}/hdpos/api/chatrct/rct?itemId=XY10000-08-3A + body: none + auth: none +} + +query { + itemId: XY10000-08-3A +} diff --git a/bruno/chatrct/PromptStore.bru b/bruno/chatrct/PromptStore.bru new file mode 100644 index 0000000..4f2f764 --- /dev/null +++ b/bruno/chatrct/PromptStore.bru @@ -0,0 +1,18 @@ +meta { + name: PromptStore + type: http + seq: 4 +} + +get { + url: {{host}}/hdpos/api/chatrct/store/4?storeId=4&distributorId=1&itemId=XY10000-08-3A&produitId=3700824 + body: none + auth: none +} + +query { + storeId: 4 + distributorId: 1 + itemId: XY10000-08-3A + produitId: 3700824 +} diff --git a/bruno/chatrct/RctForceCache.bru b/bruno/chatrct/RctForceCache.bru new file mode 100644 index 0000000..8b01b2b --- /dev/null +++ b/bruno/chatrct/RctForceCache.bru @@ -0,0 +1,24 @@ +meta { + name: RctForceCache + type: http + seq: 6 +} + +put { + url: {{host}}/hdpos/api/chatrct/rct/forceCache + body: json + auth: none +} + +body:json { + { + "itemId": "XY10000", + "comment": "Test FRED" + } + +} + +body:form-urlencoded { + itemId: 9999999 + comment: test +} diff --git a/bruno/chatrct/RctForceException.bru b/bruno/chatrct/RctForceException.bru new file mode 100644 index 0000000..dd17a1c --- /dev/null +++ b/bruno/chatrct/RctForceException.bru @@ -0,0 +1,27 @@ +meta { + name: RctForceException + type: http + seq: 7 +} + +put { + url: {{host}}/hdpos/api/chatrct/rct/forceException + body: json + auth: none +} + +body:json { + { + "id_produit":3700821, + "id_distrib":1, + "fdate":"20241220", + "forcer_cache":1, + "modul_trait":"HDPOS" + } + +} + +body:form-urlencoded { + itemId: 9999999 + comment: test +} diff --git a/bruno/chatrct/hello.bru b/bruno/chatrct/hello.bru new file mode 100644 index 0000000..37beaf2 --- /dev/null +++ b/bruno/chatrct/hello.bru @@ -0,0 +1,11 @@ +meta { + name: Hello + type: http + seq: 1 +} + +get { + url: {{host}}/hdpos/api/chatrct/hello + body: none + auth: none +} \ No newline at end of file diff --git a/src/main/java/com/example/services/ChatRctService.java b/src/main/java/com/example/services/ChatRctService.java new file mode 100644 index 0000000..9166de4 --- /dev/null +++ b/src/main/java/com/example/services/ChatRctService.java @@ -0,0 +1,474 @@ +package com.example.services; + +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.ws.rs.BadRequestException; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +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") + @Produces(MediaType.APPLICATION_JSON) + public Response getRctById(@QueryParam("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()); + + // Convert Unicode representations to emojis + String resultWithEmojis = convertUnicodeStrsToEmojis(result); + + ObjectMapper objectMapper = new ObjectMapper(); + String jsonResponse = objectMapper.writeValueAsString(resultWithEmojis); + + 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") Integer distributorId, + @QueryParam("itemId") String itemId, + @QueryParam("produitId") Integer 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.setInt(1, distributorId); + callableStatement.setString(2, itemId); + callableStatement.setInt(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()); + + // Convert Unicode representations to emojis + String resultWithEmojis = convertUnicodeStrsToEmojis(result); + + ObjectMapper objectMapper = new ObjectMapper(); + String jsonResponse = objectMapper.writeValueAsString(resultWithEmojis); + + 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("/store/{storeId}") + @Produces(MediaType.APPLICATION_JSON) + public Response getStoreById( + @PathParam("storeId") Integer storeId, + @QueryParam("distributorId") Integer distributorId, + @QueryParam("itemId") String itemId, + @QueryParam("produitId") Integer produitId) { + + if (storeId == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"storeId parameter is required\"}").build(); + } + + 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(); + } + + String ip = ""; + String enseigne = ""; + int vendable = -1; // error by default + int gerable = -1; // error by default + + DriverManager.setLoginTimeout(5); // Set timeout to 5 seconds + + try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) { + String ipQuery = "SELECT hsc.ip FROM com02.HOTLINE_STRUCTURE_CAISSE hsc WHERE hsc.ID_STRUCTURE = ? AND hsc.ID_CAISSE = 20"; + logger.info(ipQuery); + + PreparedStatement ipStatement = databaseConnection.getConnection().prepareStatement(ipQuery); + ipStatement.setInt(1, storeId); + ResultSet ipResultSet = ipStatement.executeQuery(); + + if (ipResultSet.next()) { + ip = ipResultSet.getString("ip"); + } + + String enseigneQuery = "SELECT xs.enseigne FROM omni.xst_structure xs WHERE xs.ID_STRUCTURE = ?"; + logger.info(enseigneQuery); + + PreparedStatement enseigneStatement = databaseConnection.getConnection().prepareStatement(enseigneQuery); + enseigneStatement.setInt(1, storeId); + ResultSet enseigneResultSet = enseigneStatement.executeQuery(); + + if (enseigneResultSet.next()) { + enseigne = enseigneResultSet.getString("enseigne"); + } + + } catch (SQLException e) { + e.printStackTrace(); + } + + logger.info("Try to connect on IP :" + ip); + + // if Ip address is not null and enseigne is not null + if (ip.length() > 0 && enseigne.length() > 0) { + try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(ip,"dtv")) { + String itemQuery = "SELECT COUNT(*) as gerable " + + "FROM dtv.ITM_ITEM " + + "WHERE ORGANIZATION_ID = 1 AND ITEM_ID = ?"; + + logger.info(itemQuery); + + try (PreparedStatement itemStatement = databaseConnection.getConnection().prepareStatement(itemQuery)) { + itemStatement.setString(1, itemId); + + ResultSet itemResultSet = itemStatement.executeQuery(); + + if (itemResultSet.next()) { + if (itemResultSet.getInt("gerable") > 0) + gerable = 1; + else + gerable = 0; + } + } + + String optionsQuery = "SELECT COUNT(*) as vendable " + + "FROM dtv.ITM_ITEM_OPTIONS " + + "WHERE ORGANIZATION_ID = 1 AND ITEM_ID = ? AND LEVEL_CODE = 'ENSEIGNE' AND LEVEL_VALUE = ? AND ITEM_AVAILABILITY_CODE = 'AVAILABLE'"; + + logger.info(optionsQuery); + + try (PreparedStatement optionsStatement = databaseConnection.getConnection().prepareStatement(optionsQuery)) { + optionsStatement.setString(1, itemId); + optionsStatement.setString(2, enseigne); + + ResultSet optionsResultSet = optionsStatement.executeQuery(); + + if (optionsResultSet.next()) { + if (optionsResultSet.getInt("vendable") > 0) + vendable = 1; + else + vendable = 0; + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + if (vendable == -1) { + logger.info("Unable to determine vendable status for store " + storeId); + } + + try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("omni")) { + String call = "{ call fbe_hdpos.chatrct_prompt_store(?,?,?,?,?,?,?,?) }"; + + logger.info(call); + + try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(call)) { + // Set input parameters + callableStatement.setInt(1, storeId); + callableStatement.setInt(2, distributorId); + callableStatement.setString(3, itemId); + callableStatement.setInt(4, produitId); + callableStatement.setString(5, enseigne); + callableStatement.setInt(6, gerable); + callableStatement.setInt(7, vendable); + + // Set output parameters + callableStatement.registerOutParameter(8, Types.CLOB); + + // Execute the stored procedure + callableStatement.execute(); + + // Retrieve results + Clob resultClob = callableStatement.getClob(8); + String result = resultClob.getSubString(1, (int) resultClob.length()); + + // Convert Unicode representations to emojis + String resultWithEmojis = convertUnicodeStrsToEmojis(result); + + ObjectMapper objectMapper = new ObjectMapper(); + String jsonResponse = objectMapper.writeValueAsString(resultWithEmojis); + + 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(); + } + } + + @PUT + @Path("/rct/forceCache") + @Consumes(MediaType.APPLICATION_JSON) + public Response putRctForceCache(Map request) { + String itemId = request.get("itemId"); + String comment = request.get("comment"); + + if (itemId == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"itemId parameter is required\"}").build(); + } + + if (comment == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"comment parameter is required\"}").build(); + } + + try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("omni")) { + String enableOutput = "begin dbms_output.enable; end;"; + try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(enableOutput)) { + callableStatement.execute(); + } + + String call = "{ call p_xsto_itm_force_cache(?,?) }"; + + logger.info(call); + + try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(call)) { + // Set input parameters + callableStatement.setString(1, itemId); + callableStatement.setString(2, comment); + + // Execute the stored procedure + callableStatement.execute(); + + Map result = new HashMap<>(); + + // Retrieve DBMS_OUTPUT + String getOutput = "begin dbms_output.get_line(?, ?); end;"; + try (CallableStatement outputCallableStatement = databaseConnection.getConnection().prepareCall(getOutput)) { + outputCallableStatement.registerOutParameter(1, Types.VARCHAR); + outputCallableStatement.registerOutParameter(2, Types.INTEGER); + + StringBuilder output = new StringBuilder(); + int status = 0; + do { + outputCallableStatement.execute(); + status = outputCallableStatement.getInt(2); + if (status == 0) { + output.append(outputCallableStatement.getString(1)); + } + } while (status == 0); + + // Add DBMS_OUTPUT to your result + result.put("output", output.toString()); + } + + 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(); + } + } + + @PUT + @Path("/rct/forceException") + @Consumes(MediaType.APPLICATION_JSON) + public Response putRctForceException(Map request) { + String id_produit_str = request.get("id_produit"); + String id_distrib_str = request.get("id_distrib"); + String fdate = request.get("fdate"); + String forcer_cache_str = request.get("forcer_cache"); + String modul_trait = request.get("modul_trait"); + + Long id_produit = Optional.ofNullable(id_produit_str) + .map(Long::parseLong) + .orElseThrow(() -> new BadRequestException("id_produit parameter is required")); + + Integer id_distrib = Optional.ofNullable(id_distrib_str) + .map(Integer::parseInt) + .orElseThrow(() -> new BadRequestException("id_distrib parameter is required")); + + Integer forcer_cache = Optional.ofNullable(forcer_cache_str) + .map(Integer::parseInt) + .orElseThrow(() -> new BadRequestException("forcer_cache parameter is required")); + + if (fdate == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"fdate parameter is required\"}").build(); + } + + if (modul_trait == null) { + return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"modul_trait parameter is required\"}").build(); + } + + try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("omni")) { + String enableOutput = "begin dbms_output.enable; end;"; + try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(enableOutput)) { + callableStatement.execute(); + } + + String call = "{ call p_xsto_itm_force_exception(?,?,?,?,?) }"; + + logger.info(call); + + try (CallableStatement callableStatement = databaseConnection.getConnection().prepareCall(call)) { + // Set input parameters + callableStatement.setLong(1, id_produit); + callableStatement.setInt(2, id_distrib); + callableStatement.setString(3, fdate); + callableStatement.setInt(4, forcer_cache); + callableStatement.setString(5, modul_trait); + + // Execute the stored procedure + callableStatement.execute(); + + Map result = new HashMap<>(); + + // Retrieve DBMS_OUTPUT + String getOutput = "begin dbms_output.get_line(?, ?); end;"; + try (CallableStatement outputCallableStatement = databaseConnection.getConnection().prepareCall(getOutput)) { + outputCallableStatement.registerOutParameter(1, Types.VARCHAR); + outputCallableStatement.registerOutParameter(2, Types.INTEGER); + StringBuilder output = new StringBuilder(); + int status = 0; + do { + outputCallableStatement.execute(); + status = outputCallableStatement.getInt(2); + if (status == 0) { + output.append(outputCallableStatement.getString(1)); + } + } while (status == 0); + + // Add DBMS_OUTPUT to your result + result.put("output", output.toString()); + } + + 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(); + } + } + + public static String convertUnicodeStrsToEmojis(String str) { + Pattern pattern = Pattern.compile("U\\+[0-9A-Fa-f]+"); + Matcher matcher = pattern.matcher(str); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String unicodeStr = matcher.group(); + String emoji = convertUnicodeStrToEmoji(unicodeStr); + matcher.appendReplacement(sb, emoji); + } + matcher.appendTail(sb); + return sb.toString(); + } + + public static String convertUnicodeStrToEmoji(String unicodeStr) { + String[] parts = unicodeStr.split("\\+"); + int unicodeInt = Integer.parseInt(parts[1], 16); + return new String(Character.toChars(unicodeInt)); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/services/OrderService.java b/src/main/java/com/example/services/OrderService.java index 79a7bd1..2068de0 100644 --- a/src/main/java/com/example/services/OrderService.java +++ b/src/main/java/com/example/services/OrderService.java @@ -7,7 +7,6 @@ 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; diff --git a/src/main/java/com/example/services/ProximisService.java b/src/main/java/com/example/services/ProximisService.java index 88ba610..690bd95 100644 --- a/src/main/java/com/example/services/ProximisService.java +++ b/src/main/java/com/example/services/ProximisService.java @@ -1,8 +1,5 @@ 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; @@ -14,10 +11,12 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; 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.InputStream; -import java.net.URI; import org.json.JSONObject; import org.slf4j.Logger; @@ -48,6 +47,9 @@ public class ProximisService { try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) { 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'"; + + logger.info(query); + PreparedStatement stmt = databaseConnection.getConnection().prepareStatement(query); stmt.setString(1, "Authorization"); @@ -61,28 +63,29 @@ public class ProximisService { if (bearerToken == null || bearerToken.isEmpty()) { return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"Empty bearer token\"}").build(); } else { - HttpClient client = HttpClient.newHttpClient(); - HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(url + "/project/fulfillment/" + orderCode)) + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(url + "/project/fulfillment/" + orderCode); + Response response = target.request(MediaType.APPLICATION_JSON) .header("Authorization", bearerToken) - .GET() - .build(); + .get(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - - if (response.statusCode() == 200) { - 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.NOT_FOUND).entity("{\"error\":\"Failed to get order detail\"}").build(); + try { + if (response.getStatus() == 200) { + JSONObject commonObject = new JSONObject(); + commonObject.put("urlApp", urlApp); + + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("common", commonObject); + jsonResponse.put("oms", new JSONObject(response.readEntity(String.class))); + + return Response.ok(jsonResponse.toString()).build(); + } else if (response.getStatus() == 401) { + return Response.status(Response.Status.UNAUTHORIZED).entity("{\"error\":\"Invalid token\"}").build(); + } else { + 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) { diff --git a/src/main/java/com/example/services/StoreService.java b/src/main/java/com/example/services/StoreService.java index 2ab56ed..3ece428 100644 --- a/src/main/java/com/example/services/StoreService.java +++ b/src/main/java/com/example/services/StoreService.java @@ -179,12 +179,12 @@ public class StoreService { " AND hsc2.id_caisse BETWEEN 20 AND 39) AS caisses," + " REPLACE(REPLACE(TRIM(st.adresse1), chr(10), ''), chr(13), '') AS adresse," + " axs.date_stock as date_migration" + - " FROM COM02.structure st" + + " FROM com02.STRUCTURE st" + + " JOIN omni.ASPD_XSTO_STRUCTURE axs ON st.ID_STRUCTURE = axs.ID_STRUCTURE" + " JOIN com02.PARAM_PAYS pp ON pp.id_pays = st.id_pays" + " LEFT OUTER JOIN mobretail.mp_etab_param metabp ON metabp.id_etab = st.id_structure" + " LEFT OUTER JOIN mobretail.mr_photo mpprinc ON mpprinc.id_photo = metabp.id_photo_principale" + - " LEFT OUTER JOIN omni.ASPD_XSTO_STRUCTURE axs ON st.ID_STRUCTURE = axs.ID_STRUCTURE" + - " 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" + + " WHERE axs.date_stock is not null AND st.id_niveau=4 AND st.statut=2 AND st.id_canal_distribution = 1" + " ORDER BY st.id_structure"; logger.info(query); diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index 3930020..27f3483 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -2,16 +2,19 @@ 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 +dev.dotsoft.db.omni.password=k5.Omni.Paspdi # 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 +preprod.dotsoft.db.omni.password=k5.Omni.Paspdi # 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 +prod.dotsoft.db.omni.password=k5.Omni.Paspdi # XSTORE environment settings xstore.db.url=jdbc:oracle:thin:@HOST:1521/XSTORE