first commit
commit
2c0b705ab6
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Dossiers générés par l'IDE
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Fichiers de configuration spécifiques à l'IDE
|
||||||
|
*.iml
|
||||||
|
*.iws
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
# Dossiers générés par Maven
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Fichiers de configuration de Maven
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
|
||||||
|
# Fichiers générés par Tomcat
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
work/
|
||||||
|
temp/
|
||||||
|
logs/
|
||||||
|
|
||||||
|
# Dossiers spécifiques à Eclipse
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# Fichiers spécifiques à Eclipse
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
|
||||||
|
# Dossiers spécifiques à NetBeans
|
||||||
|
nb-configuration/
|
||||||
|
nbproject/private/
|
||||||
|
|
||||||
|
# Fichiers spécifiques à NetBeans
|
||||||
|
nb-configuration.xml
|
||||||
|
|
||||||
|
# Dossiers spécifiques à VS Code
|
||||||
|
.vscode/
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>hdpos</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>hdpos Maven Webapp</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JDBC Driver for Oracle Database -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.oracle.database.jdbc</groupId>
|
||||||
|
<artifactId>ojdbc10</artifactId>
|
||||||
|
<version>19.8.0.0</version> <!-- Assurez-vous d'utiliser la version compatible avec votre Oracle Database -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Jersey for JAX-RS (Java API for RESTful Web Services) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-server</artifactId>
|
||||||
|
<version>2.41</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
|
<version>2.41</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.inject</groupId>
|
||||||
|
<artifactId>jersey-hk2</artifactId>
|
||||||
|
<version>2.41</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>4.0.1</version> <!-- Remplacez par la version appropriée -->
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.13.0</version> <!-- Utilisez la dernière version disponible -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>hdpos</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
|
<artifactId>cargo-maven2-plugin</artifactId>
|
||||||
|
<version>1.8.3</version>
|
||||||
|
<configuration>
|
||||||
|
<container>
|
||||||
|
<containerId>tomcat9x</containerId>
|
||||||
|
<type>embedded</type>
|
||||||
|
</container>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.example;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletResponse; // Importez cette classe
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CorsFilters implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
|
||||||
|
// Utilisez HttpServletResponse au lieu de ServletResponse
|
||||||
|
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||||
|
|
||||||
|
// Autoriser l'accès depuis n'importe quelle origine
|
||||||
|
httpResponse.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
|
// Autoriser les méthodes HTTP spécifiées (GET, POST, OPTIONS, PUT, DELETE)
|
||||||
|
httpResponse.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
|
||||||
|
|
||||||
|
// Autoriser les en-têtes spécifiés dans la requête
|
||||||
|
httpResponse.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||||
|
|
||||||
|
// Permettre l'envoi de cookies (si nécessaire)
|
||||||
|
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
|
||||||
|
// Durée de validité des résultats préalables (pré-vérifications OPTIONS)
|
||||||
|
httpResponse.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
|
||||||
|
// Continuer la chaîne de filtres
|
||||||
|
chain.doFilter(request, httpResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
// Initialisation du filtre
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
// Destruction du filtre
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DatabaseConnection implements AutoCloseable {
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
public DatabaseConnection(String dbHost, String username, String password) throws SQLException {
|
||||||
|
// Initialiser votre connexion à la base de données ici
|
||||||
|
connection = DriverManager.getConnection("jdbc:oracle:thin:@" + dbHost + ":1521/XSTORE", username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DatabaseConnectionDS implements AutoCloseable {
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
public DatabaseConnectionDS(String username, String password) throws SQLException {
|
||||||
|
// Initialiser votre connexion à la base de données ici
|
||||||
|
// jdbc:oracle:thin:@v-aspd-b01-ii-d.adic.lan:1521/IASPDI
|
||||||
|
// jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI
|
||||||
|
connection = DriverManager.getConnection("jdbc:oracle:thin:@v-aspd-b01-irdc.adic.lan:1521/MASPDI", username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/database")
|
||||||
|
public class DatabaseService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/replication")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getCount(@QueryParam("dbHost") String dbHost) {
|
||||||
|
|
||||||
|
if (dbHost == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||||
|
|
||||||
|
try (DatabaseConnection databaseConnection = new DatabaseConnection(dbHost, "repqueue", "repqueue")) {
|
||||||
|
String query = "SELECT COUNT(*) FROM CTL_REPLICATION_QUEUE";
|
||||||
|
|
||||||
|
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query);
|
||||||
|
ResultSet resultSet = statement.executeQuery()) {
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
long count = resultSet.getLong(1);
|
||||||
|
// Construction manuelle de la réponse JSON
|
||||||
|
String jsonResponse = "{\"count\":" + count + "}";
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace(); // Gérer les exceptions correctement dans un environnement de production
|
||||||
|
|
||||||
|
// Construction de la réponse JSON en cas d'erreur
|
||||||
|
String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}";
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
@Path("/hello")
|
||||||
|
public class HelloWebService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public String sayHello() {
|
||||||
|
return "Hello, world!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,385 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/items")
|
||||||
|
public class ItemService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getItemById(
|
||||||
|
@QueryParam("dbHost") String dbHost,
|
||||||
|
@QueryParam("itemId") String itemId) {
|
||||||
|
|
||||||
|
if (dbHost == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemId == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"itemId parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||||
|
|
||||||
|
try (DatabaseConnection databaseConnection = new DatabaseConnection(dbHost, "dtv", "dtv")) {
|
||||||
|
String query = "SELECT * FROM ITM_ITEM WHERE ITEM_ID LIKE ?" ;
|
||||||
|
|
||||||
|
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||||
|
// Concaténer % au paramètre itemId
|
||||||
|
statement.setString(1, itemId + "%");
|
||||||
|
|
||||||
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
|
List<Item> itemList = new ArrayList<>();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
Item item = mapResultSetToItem(resultSet);
|
||||||
|
itemList.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!itemList.isEmpty()) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonResponse = objectMapper.writeValueAsString(itemList);
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No items found\"}").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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Item mapResultSetToItem(ResultSet resultSet) throws SQLException {
|
||||||
|
Item item = new Item();
|
||||||
|
item.setOrganizationId(resultSet.getLong("ORGANIZATION_ID"));
|
||||||
|
item.setItemId(resultSet.getString("ITEM_ID"));
|
||||||
|
item.setOrgCode(resultSet.getString("ORG_CODE"));
|
||||||
|
item.setOrgValue(resultSet.getString("ORG_VALUE"));
|
||||||
|
item.setName(resultSet.getString("NAME"));
|
||||||
|
item.setDescription(resultSet.getString("DESCRIPTION"));
|
||||||
|
item.setMerchLevel1(resultSet.getString("MERCH_LEVEL_1"));
|
||||||
|
item.setMerchLevel2(resultSet.getString("MERCH_LEVEL_2"));
|
||||||
|
item.setMerchLevel3(resultSet.getString("MERCH_LEVEL_3"));
|
||||||
|
item.setMerchLevel4(resultSet.getString("MERCH_LEVEL_4"));
|
||||||
|
item.setListPrice(resultSet.getInt("LIST_PRICE"));
|
||||||
|
item.setMeasureReqFlag(resultSet.getInt("MEASURE_REQ_FLAG"));
|
||||||
|
item.setItemLevelCode(resultSet.getString("ITEM_LVLCODE"));
|
||||||
|
item.setParentItemId(resultSet.getString("PARENT_ITEM_ID"));
|
||||||
|
item.setNotInventoriedFlag(resultSet.getInt("NOT_INVENTORIED_FLAG"));
|
||||||
|
item.setSerializedItemFlag(resultSet.getInt("SERIALIZED_ITEM_FLAG"));
|
||||||
|
item.setItemTypeCode(resultSet.getString("ITEM_TYPCODE"));
|
||||||
|
item.setDtvClassName(resultSet.getString("DTV_CLASS_NAME"));
|
||||||
|
item.setDimensionSystem(resultSet.getString("DIMENSION_SYSTEM"));
|
||||||
|
item.setDisallowMatrixDisplayFlag(resultSet.getInt("DISALLOW_MATRIX_DISPLAY_FLAG"));
|
||||||
|
item.setItemMatrixColor(resultSet.getString("ITEM_MATRIX_COLOR"));
|
||||||
|
item.setDimension1(resultSet.getString("DIMENSION1"));
|
||||||
|
item.setDimension2(resultSet.getString("DIMENSION2"));
|
||||||
|
item.setDimension3(resultSet.getString("DIMENSION3"));
|
||||||
|
item.setExternalSystem(resultSet.getString("EXTERNAL_SYSTEM"));
|
||||||
|
item.setCreateDate(resultSet.getTimestamp("CREATE_DATE"));
|
||||||
|
item.setCreateUserId(resultSet.getString("CREATE_USER_ID"));
|
||||||
|
item.setUpdateDate(resultSet.getTimestamp("UPDATE_DATE"));
|
||||||
|
item.setUpdateUserId(resultSet.getString("UPDATE_USER_ID"));
|
||||||
|
item.setRecordState(resultSet.getString("RECORD_STATE"));
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
private Long organizationId;
|
||||||
|
private String itemId;
|
||||||
|
private String orgCode;
|
||||||
|
private String orgValue;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String merchLevel1;
|
||||||
|
private String merchLevel2;
|
||||||
|
private String merchLevel3;
|
||||||
|
private String merchLevel4;
|
||||||
|
private Integer listPrice;
|
||||||
|
private Integer measureReqFlag;
|
||||||
|
private String itemLevelCode;
|
||||||
|
private String parentItemId;
|
||||||
|
private Integer notInventoriedFlag;
|
||||||
|
private Integer serializedItemFlag;
|
||||||
|
private String itemTypeCode;
|
||||||
|
private String dtvClassName;
|
||||||
|
private String dimensionSystem;
|
||||||
|
private Integer disallowMatrixDisplayFlag;
|
||||||
|
private String itemMatrixColor;
|
||||||
|
private String dimension1;
|
||||||
|
private String dimension2;
|
||||||
|
private String dimension3;
|
||||||
|
private String externalSystem;
|
||||||
|
private Timestamp createDate;
|
||||||
|
private String createUserId;
|
||||||
|
private Timestamp updateDate;
|
||||||
|
private String updateUserId;
|
||||||
|
private String recordState;
|
||||||
|
|
||||||
|
// Getters and Setters for all fields
|
||||||
|
|
||||||
|
public Long getOrganizationId() {
|
||||||
|
return organizationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrganizationId(Long organizationId) {
|
||||||
|
this.organizationId = organizationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemId(String itemId) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgCode() {
|
||||||
|
return orgCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgCode(String orgCode) {
|
||||||
|
this.orgCode = orgCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrgValue() {
|
||||||
|
return orgValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgValue(String orgValue) {
|
||||||
|
this.orgValue = orgValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMerchLevel1() {
|
||||||
|
return merchLevel1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchLevel1(String merchLevel1) {
|
||||||
|
this.merchLevel1 = merchLevel1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMerchLevel2() {
|
||||||
|
return merchLevel2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchLevel2(String merchLevel2) {
|
||||||
|
this.merchLevel2 = merchLevel2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMerchLevel3() {
|
||||||
|
return merchLevel3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchLevel3(String merchLevel3) {
|
||||||
|
this.merchLevel3 = merchLevel3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMerchLevel4() {
|
||||||
|
return merchLevel4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchLevel4(String merchLevel4) {
|
||||||
|
this.merchLevel4 = merchLevel4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getListPrice() {
|
||||||
|
return listPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListPrice(Integer listPrice) {
|
||||||
|
this.listPrice = listPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMeasureReqFlag() {
|
||||||
|
return measureReqFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMeasureReqFlag(Integer measureReqFlag) {
|
||||||
|
this.measureReqFlag = measureReqFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemLevelCode() {
|
||||||
|
return itemLevelCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemLevelCode(String itemLevelCode) {
|
||||||
|
this.itemLevelCode = itemLevelCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentItemId() {
|
||||||
|
return parentItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentItemId(String parentItemId) {
|
||||||
|
this.parentItemId = parentItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNotInventoriedFlag() {
|
||||||
|
return notInventoriedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotInventoriedFlag(Integer notInventoriedFlag) {
|
||||||
|
this.notInventoriedFlag = notInventoriedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSerializedItemFlag() {
|
||||||
|
return serializedItemFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSerializedItemFlag(Integer serializedItemFlag) {
|
||||||
|
this.serializedItemFlag = serializedItemFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemTypeCode() {
|
||||||
|
return itemTypeCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemTypeCode(String itemTypeCode) {
|
||||||
|
this.itemTypeCode = itemTypeCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDtvClassName() {
|
||||||
|
return dtvClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDtvClassName(String dtvClassName) {
|
||||||
|
this.dtvClassName = dtvClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDimensionSystem() {
|
||||||
|
return dimensionSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDimensionSystem(String dimensionSystem) {
|
||||||
|
this.dimensionSystem = dimensionSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDisallowMatrixDisplayFlag() {
|
||||||
|
return disallowMatrixDisplayFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisallowMatrixDisplayFlag(Integer disallowMatrixDisplayFlag) {
|
||||||
|
this.disallowMatrixDisplayFlag = disallowMatrixDisplayFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemMatrixColor() {
|
||||||
|
return itemMatrixColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemMatrixColor(String itemMatrixColor) {
|
||||||
|
this.itemMatrixColor = itemMatrixColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDimension1() {
|
||||||
|
return dimension1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDimension1(String dimension1) {
|
||||||
|
this.dimension1 = dimension1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDimension2() {
|
||||||
|
return dimension2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDimension2(String dimension2) {
|
||||||
|
this.dimension2 = dimension2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDimension3() {
|
||||||
|
return dimension3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDimension3(String dimension3) {
|
||||||
|
this.dimension3 = dimension3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExternalSystem() {
|
||||||
|
return externalSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalSystem(String externalSystem) {
|
||||||
|
this.externalSystem = externalSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getCreateDate() {
|
||||||
|
return createDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateDate(Timestamp createDate) {
|
||||||
|
this.createDate = createDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreateUserId() {
|
||||||
|
return createUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateUserId(String createUserId) {
|
||||||
|
this.createUserId = createUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getUpdateDate() {
|
||||||
|
return updateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateDate(Timestamp updateDate) {
|
||||||
|
this.updateDate = updateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpdateUserId() {
|
||||||
|
return updateUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateUserId(String updateUserId) {
|
||||||
|
this.updateUserId = updateUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRecordState() {
|
||||||
|
return recordState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordState(String recordState) {
|
||||||
|
this.recordState = recordState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,179 @@
|
||||||
|
package com.example.services;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
@Path("/stores")
|
||||||
|
public class StoreService {
|
||||||
|
private static List<store> cachedStoreList;
|
||||||
|
private static final Lock cacheLock = new ReentrantLock();
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getStoreById(@QueryParam("storeId") String storeId) {
|
||||||
|
if (storeId == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"storeId parameter is required\"}").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||||
|
|
||||||
|
// IASPDI com02 / B1Xto9pAbtBCOxuecG7W
|
||||||
|
// MASPDI com02 /
|
||||||
|
try (DatabaseConnectionDS databaseConnection = new DatabaseConnectionDS("com02", "B1Xto9pAbtBCOxuecG7W")) {
|
||||||
|
String query = "SELECT id_structure,nom,'10.100.0.18' AS ip, tel1 AS telephone FROM structure WHERE id_structure = ?" ;
|
||||||
|
|
||||||
|
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||||
|
statement.setString(1, storeId);
|
||||||
|
|
||||||
|
try (ResultSet resultSet = statement.executeQuery()) {
|
||||||
|
if (resultSet.next()) {
|
||||||
|
store store = mapResultSetTostore(resultSet);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonResponse = objectMapper.writeValueAsString(store);
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No store found\"}").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("/getAll")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getAllStores() {
|
||||||
|
if (cachedStoreList == null) {
|
||||||
|
// Utilisation d'un verrou pour éviter que plusieurs requêtes déclenchent la récupération simultanée
|
||||||
|
cacheLock.lock();
|
||||||
|
try {
|
||||||
|
// Vérification à nouveau après avoir acquis le verrou
|
||||||
|
if (cachedStoreList == null) {
|
||||||
|
// Récupérer depuis la base de données seulement si la liste n'est pas en cache
|
||||||
|
cachedStoreList = retrieveStoresFromDatabase();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cacheLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cachedStoreList.isEmpty()) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonResponse;
|
||||||
|
try {
|
||||||
|
jsonResponse = objectMapper.writeValueAsString(cachedStoreList);
|
||||||
|
return Response.ok(jsonResponse).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity("{\"error\":\"No stores found\"}").build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<store> retrieveStoresFromDatabase() {
|
||||||
|
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||||
|
|
||||||
|
try (DatabaseConnectionDS databaseConnection = new DatabaseConnectionDS("com02", "B1Xto9pAbtBCOxuecG7W")) {
|
||||||
|
String query = "SELECT st.id_structure, TRIM(st.nom) as nom, '10.100.0.18' AS ip, " +
|
||||||
|
"st.tel1 AS telephone " +
|
||||||
|
"FROM COM02.STRUCTURE st " +
|
||||||
|
"LEFT OUTER JOIN omni.ASPD_XSTO_STRUCTURE axs ON st.ID_STRUCTURE = axs.ID_STRUCTURE " +
|
||||||
|
"WHERE st.id_structure < 50";
|
||||||
|
|
||||||
|
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query);
|
||||||
|
ResultSet resultSet = statement.executeQuery()) {
|
||||||
|
|
||||||
|
List<store> storeList = new ArrayList<>();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
store store = mapResultSetTostore(resultSet);
|
||||||
|
storeList.add(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
return storeList;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private store mapResultSetTostore(ResultSet resultSet) throws SQLException {
|
||||||
|
store store = new store();
|
||||||
|
|
||||||
|
store.setId_structure(resultSet.getInt("ID_STRUCTURE"));
|
||||||
|
store.setNom(resultSet.getString("NOM"));
|
||||||
|
store.setIp(resultSet.getString("IP"));
|
||||||
|
store.setTelephone(resultSet.getString("TELEPHONE"));
|
||||||
|
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class store {
|
||||||
|
private Integer id_structure;
|
||||||
|
private String nom;
|
||||||
|
private String ip;
|
||||||
|
private String telephone;
|
||||||
|
|
||||||
|
public Integer getId_structure() {
|
||||||
|
return id_structure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_structure(Integer id_structure) {
|
||||||
|
this.id_structure = id_structure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNom(String nom) {
|
||||||
|
this.nom = nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIp(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTelephone() {
|
||||||
|
return telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTelephone(String telephone) {
|
||||||
|
this.telephone = telephone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||||
|
|
||||||
|
<web-app>
|
||||||
|
<display-name>Archetype Created Web Application</display-name>
|
||||||
|
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>index.html</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Jersey Web Application</servlet-name>
|
||||||
|
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>jersey.config.server.provider.packages</param-name>
|
||||||
|
<param-value>com.example.services</param-value>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Jersey Web Application</servlet-name>
|
||||||
|
<url-pattern>/api/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<filter-name>CorsFilter</filter-name>
|
||||||
|
<filter-class>com.example.CorsFilters</filter-class>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CorsFilter</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
</web-app>
|
||||||
Loading…
Reference in New Issue