feat: store detail adjustment / authentification
parent
844515f640
commit
1020d4ad1e
10
pom.xml
10
pom.xml
|
|
@ -54,6 +54,16 @@
|
|||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>2.13.0</version> <!-- Use the latest version here -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- LOG dependencies -->
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public class CorsFilters implements Filter {
|
|||
|
||||
// Autoriser les en-têtes spécifiés dans la requête
|
||||
httpResponse.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
httpResponse.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||
|
||||
// Permettre l'envoi de cookies (si nécessaire)
|
||||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
package com.example.services;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path("/auth")
|
||||
public class AuthService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthService.class);
|
||||
|
||||
public class UserAbilityRules {
|
||||
private List<String> rules;
|
||||
|
||||
public UserAbilityRules() {
|
||||
this.rules = Arrays.asList("admin", "editor");
|
||||
}
|
||||
|
||||
public List<String> getRules() {
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserData {
|
||||
private int id;
|
||||
private String fullName;
|
||||
private String username;
|
||||
private String avatar;
|
||||
private String email;
|
||||
private String role;
|
||||
|
||||
public UserData() {
|
||||
this.id = 1;
|
||||
this.fullName = "Frédérik Benoist";
|
||||
this.username = "fbenoist";
|
||||
this.avatar = "/images/avatars/avatar-1.png";
|
||||
this.email = "admin@demo.com";
|
||||
this.role = "admin";
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
public class AuthResponse {
|
||||
private String accessToken;
|
||||
private UserAbilityRules userAbilityRules;
|
||||
private UserData userData;
|
||||
|
||||
public AuthResponse() {
|
||||
this.accessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MX0.fhc3wykrAnRpcKApKhXiahxaOe8PSHatad31NuIZ0Zg";
|
||||
this.userAbilityRules = new UserAbilityRules();
|
||||
this.userData = new UserData();
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public UserAbilityRules getUserAbilityRules() {
|
||||
return userAbilityRules;
|
||||
}
|
||||
|
||||
public UserData getUserData() {
|
||||
return userData;
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public AuthResponse login(Credentials credentials) {
|
||||
logger.info(credentials.getUsername() + " is attempting to login");
|
||||
|
||||
if (!isValidPassword(credentials.getPassword())) {
|
||||
logger.info("User " + credentials.getUsername() + " failed to login");
|
||||
throw new WebApplicationException("Invalid password", Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
logger.info("User " + credentials.getUsername() + " successfully logged in");
|
||||
|
||||
return new AuthResponse();
|
||||
}
|
||||
|
||||
private boolean isValidPassword(String password) {
|
||||
return "admin123".equals(password) || "support123".equals(password);
|
||||
}
|
||||
|
||||
public static class Credentials {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
// Getter pour username
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
// Setter pour username
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
// Getter pour password
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
// Setter pour password
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.example.services.store.*;
|
|||
|
||||
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;
|
||||
|
|
@ -40,9 +41,9 @@ public class StoreService {
|
|||
* @return a response containing the store information in JSON format
|
||||
*/
|
||||
@GET
|
||||
@Path("/get")
|
||||
@Path("/{storeId}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getStoreById(@QueryParam("storeId") String storeId) {
|
||||
public Response getStoreById(@PathParam("storeId") String storeId) {
|
||||
if (storeId == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"storeId parameter is required\"}").build();
|
||||
}
|
||||
|
|
@ -50,13 +51,26 @@ public class StoreService {
|
|||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) {
|
||||
String query = "SELECT st.id_structure,TRIM(st.nom) as nom,'xxx.xxx.xxx.xxx' AS ip, st.tel1 as telephone, st.enseigne, " +
|
||||
"'https://mp4.ikksgroup.com/photos/' || CASE WHEN metabp.id_photo_principale IS NOT NULL THEN mpprinc.url || TO_CHAR (metabp.id_photo_principale) " +
|
||||
"ELSE '0/0' END || '-small.JPG' as photoLink " +
|
||||
"FROM COM02.structure st " +
|
||||
"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 " +
|
||||
"WHERE st.id_structure = ?";
|
||||
String query = "SELECT st.id_structure," +
|
||||
" TRIM(st.nom) as nom," +
|
||||
" st.tel1 as telephone," +
|
||||
" st.enseigne," +
|
||||
" 'https://mp4.ikksgroup.com/photos/' || CASE WHEN metabp.id_photo_principale IS NOT NULL THEN mpprinc.url || TO_CHAR (metabp.id_photo_principale) " + "ELSE '0/0' END || '-small.JPG' as photoLink," +
|
||||
" TRIM(pp.nom) AS pays, " +
|
||||
" (" +
|
||||
" SELECT" +
|
||||
" NVL(STRAGG(hsc2.id_caisse || '|' || hsc2.ip),'0|0.0.0.0')" +
|
||||
" FROM" +
|
||||
" com02.HOTLINE_STRUCTURE_CAISSE hsc2" +
|
||||
" WHERE" +
|
||||
" hsc2.id_structure = st.id_structure" +
|
||||
" AND hsc2.id_caisse BETWEEN 20 AND 39) AS caisses," +
|
||||
" REPLACE(REPLACE(TRIM(st.adresse1), chr(10), ''), chr(13), '') AS adresse" +
|
||||
" FROM COM02.structure st" +
|
||||
" 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" +
|
||||
" WHERE st.id_structure = ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
|
|
@ -69,6 +83,7 @@ public class StoreService {
|
|||
|
||||
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();
|
||||
|
|
@ -91,7 +106,6 @@ public class StoreService {
|
|||
* @return A JSON response containing the list of stores
|
||||
*/
|
||||
@GET
|
||||
@Path("/getAll")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getAllStores() {
|
||||
if (cachedStoreList == null) {
|
||||
|
|
@ -128,13 +142,28 @@ public class StoreService {
|
|||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) {
|
||||
String query = "SELECT st.id_structure, TRIM(st.nom) as nom, hsc.ip, " +
|
||||
"st.tel1 AS telephone, st.enseigne, null AS photoLink " +
|
||||
"FROM COM02.STRUCTURE st " +
|
||||
"LEFT OUTER JOIN omni.ASPD_XSTO_STRUCTURE axs ON st.ID_STRUCTURE = axs.ID_STRUCTURE " +
|
||||
"JOIN COM02.hotline_structure_caisse hsc ON hsc.id_structure = st.id_structure AND hsc.id_caisse = 1 " +
|
||||
"WHERE axs.date_stock is not null and st.id_structure < 9999 AND hsc.ip IS NOT NULL AND st.ID_NIVEAU=4 AND st.STATUT=2 " +
|
||||
"ORDER BY st.id_structure";
|
||||
String query = "SELECT st.id_structure," +
|
||||
" TRIM(st.nom) as nom," +
|
||||
" st.tel1 as telephone," +
|
||||
" st.enseigne," +
|
||||
" 'https://mp4.ikksgroup.com/photos/' || CASE WHEN metabp.id_photo_principale IS NOT NULL THEN mpprinc.url || TO_CHAR (metabp.id_photo_principale) " + "ELSE '0/0' END || '-small.JPG' as photoLink," +
|
||||
" TRIM(pp.nom) AS pays, " +
|
||||
" (" +
|
||||
" SELECT" +
|
||||
" NVL(STRAGG(hsc2.id_caisse || '|' || hsc2.ip),'0|0.0.0.0')" +
|
||||
" FROM" +
|
||||
" com02.HOTLINE_STRUCTURE_CAISSE hsc2" +
|
||||
" WHERE" +
|
||||
" hsc2.id_structure = st.id_structure" +
|
||||
" AND hsc2.id_caisse BETWEEN 20 AND 39) AS caisses," +
|
||||
" REPLACE(REPLACE(TRIM(st.adresse1), chr(10), ''), chr(13), '') AS adresse" +
|
||||
" FROM COM02.structure st" +
|
||||
" 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" +
|
||||
" ORDER BY st.id_structure";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
|
|
@ -308,20 +337,22 @@ public class StoreService {
|
|||
|
||||
store.setId_structure(resultSet.getInt("ID_STRUCTURE"));
|
||||
store.setNom(resultSet.getString("NOM"));
|
||||
store.setIp(resultSet.getString("IP"));
|
||||
store.setTelephone(resultSet.getString("TELEPHONE"));
|
||||
store.setEnseigne(resultSet.getString("ENSEIGNE"));
|
||||
store.setPhotoLink(resultSet.getString("PHOTOLINK"));
|
||||
store.setPays(resultSet.getString("PAYS"));
|
||||
store.setCaisses(resultSet.getString("CAISSES"));
|
||||
store.setAdresse(resultSet.getString("ADRESSE"));
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getStoreDetails")
|
||||
@Path("/{storeId}/details")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getStoreDetails(
|
||||
@QueryParam("dbHost") String dbHost,
|
||||
@QueryParam("storeId") Integer storeId) {
|
||||
@PathParam("storeId") Integer storeId,
|
||||
@QueryParam("dbHost") String dbHost) {
|
||||
|
||||
if (dbHost == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build();
|
||||
|
|
@ -359,17 +390,30 @@ public class StoreService {
|
|||
private StoreDetails retrieveStoreDetails(String dbHost, Integer storeId) {
|
||||
DriverManager.setLoginTimeout(5);
|
||||
|
||||
StoreDetails storeDetails = new StoreDetails(); // Déclarer l'objet en dehors des blocs try
|
||||
StoreDetails storeDetails = new StoreDetails(); // Declare object outside try blocks
|
||||
|
||||
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) {
|
||||
// Store section
|
||||
String storeQuery = "SELECT st.id_structure,TRIM(st.nom) as nom,'xxx.xxx.xxx.xxx' AS ip, st.tel1 as telephone, st.enseigne, " +
|
||||
"'https://mp4.ikksgroup.com/photos/' || CASE WHEN metabp.id_photo_principale IS NOT NULL THEN mpprinc.url || TO_CHAR (metabp.id_photo_principale) " +
|
||||
"ELSE '0/0' END || '-small.JPG' as photoLink " +
|
||||
"FROM COM02.structure st " +
|
||||
"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 " +
|
||||
"WHERE st.id_structure = ?";
|
||||
// Store section FRED
|
||||
String storeQuery = "SELECT st.id_structure," +
|
||||
" TRIM(st.nom) as nom," +
|
||||
" st.tel1 as telephone," +
|
||||
" st.enseigne," +
|
||||
" 'https://mp4.ikksgroup.com/photos/' || CASE WHEN metabp.id_photo_principale IS NOT NULL THEN mpprinc.url || TO_CHAR (metabp.id_photo_principale) " + "ELSE '0/0' END || '-small.JPG' as photoLink," +
|
||||
" TRIM(pp.nom) AS pays, " +
|
||||
" (" +
|
||||
" SELECT" +
|
||||
" NVL(STRAGG(hsc2.id_caisse || '|' || hsc2.ip),'0|0.0.0.0')" +
|
||||
" FROM" +
|
||||
" com02.HOTLINE_STRUCTURE_CAISSE hsc2" +
|
||||
" WHERE" +
|
||||
" hsc2.id_structure = st.id_structure" +
|
||||
" AND hsc2.id_caisse BETWEEN 20 AND 39) AS caisses," +
|
||||
" REPLACE(REPLACE(TRIM(st.adresse1), chr(10), ''), chr(13), '') AS adresse" +
|
||||
" FROM COM02.structure st" +
|
||||
" 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" +
|
||||
" WHERE st.id_structure = ?";
|
||||
|
||||
logger.info(storeQuery);
|
||||
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(storeQuery)) {
|
||||
|
|
@ -445,12 +489,14 @@ public class StoreService {
|
|||
private Store mapResultSetToStore(ResultSet resultSet) throws SQLException {
|
||||
Integer id_structure = resultSet.getInt("id_structure");
|
||||
String nom = resultSet.getString("nom");
|
||||
String ip = resultSet.getString("ip");
|
||||
String telephone = resultSet.getString("telephone");
|
||||
String photoLink = resultSet.getString("photoLink");
|
||||
String enseigne = resultSet.getString("enseigne");
|
||||
|
||||
return new Store(id_structure, nom, ip, telephone, photoLink, enseigne);
|
||||
String pays = resultSet.getString("pays");
|
||||
String caisses = resultSet.getString("caisses");
|
||||
String adresse = resultSet.getString("adresse");
|
||||
|
||||
return new Store(id_structure, nom, telephone, photoLink, enseigne, pays, caisses, adresse);
|
||||
}
|
||||
|
||||
private StoreReplication mapResultSetToStoreReplication(ResultSet resultSet) throws SQLException {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,21 @@
|
|||
package com.example.services.store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class Store {
|
||||
private Integer id_structure;
|
||||
private String nom;
|
||||
private String ip;
|
||||
private String ip_master;
|
||||
private String telephone;
|
||||
private String photoLink;
|
||||
private String enseigne;
|
||||
|
||||
private String pays;
|
||||
private Integer nbcaisses;
|
||||
private String adresse;
|
||||
private List<Caisse> caisses;
|
||||
|
||||
// Default constructor
|
||||
public Store() {
|
||||
|
|
@ -15,13 +23,16 @@ public class Store {
|
|||
}
|
||||
|
||||
// Constructor with parameters
|
||||
public Store(Integer id_structure, String nom, String ip, String telephone, String photoLink, String enseigne) {
|
||||
public Store(Integer id_structure, String nom, String telephone, String photoLink, String enseigne, String pays, String caisses, String adresse) {
|
||||
this.id_structure = id_structure;
|
||||
this.nom = nom;
|
||||
this.ip = ip;
|
||||
this.telephone = telephone;
|
||||
this.photoLink = photoLink;
|
||||
this.enseigne = enseigne;
|
||||
this.pays = pays;
|
||||
this.adresse = adresse;
|
||||
|
||||
setCaisses(caisses);
|
||||
}
|
||||
|
||||
public Integer getId_structure() {
|
||||
|
|
@ -40,12 +51,12 @@ public class Store {
|
|||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
public String getIp_master() {
|
||||
if (!this.caisses.isEmpty()) {
|
||||
return this.caisses.get(0).getIp();
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
|
|
@ -71,4 +82,64 @@ public class Store {
|
|||
public void setEnseigne(String enseigne) {
|
||||
this.enseigne = enseigne;
|
||||
}
|
||||
|
||||
public String getPays() {
|
||||
return pays;
|
||||
}
|
||||
|
||||
public void setPays(String pays) {
|
||||
this.pays = pays;
|
||||
}
|
||||
|
||||
public Integer getNbcaisses() {
|
||||
return this.caisses.size();
|
||||
}
|
||||
|
||||
public void setAdresse(String adresse) {
|
||||
this.adresse = adresse;
|
||||
}
|
||||
|
||||
public String getAdresse() {
|
||||
return this.adresse;
|
||||
}
|
||||
|
||||
public List<Caisse> getCaisses() {
|
||||
return this.caisses;
|
||||
}
|
||||
|
||||
public void setCaisses(String caisses) {
|
||||
this.caisses = new ArrayList<>();
|
||||
for (String caisse : caisses.split(",")) {
|
||||
String[] parts = caisse.split("\\|");
|
||||
this.caisses.add(new Caisse(Integer.parseInt(parts[0]), parts[1]));
|
||||
}
|
||||
|
||||
Collections.sort(this.caisses, Comparator.comparing(Caisse::getId_caisse));
|
||||
}
|
||||
|
||||
public class Caisse {
|
||||
private Integer id_caisse;
|
||||
private String ip;
|
||||
|
||||
public Caisse(Integer id_caisse, String ip) {
|
||||
this.id_caisse = id_caisse;
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Integer getId_caisse() {
|
||||
return id_caisse;
|
||||
}
|
||||
|
||||
public void setId_caisse(Integer id_caisse) {
|
||||
this.id_caisse = id_caisse;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@
|
|||
<param-name>jersey.config.server.provider.packages</param-name>
|
||||
<param-value>com.example.services</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jersey.config.server.provider.classnames</param-name>
|
||||
<param-value>org.glassfish.jersey.jackson.JacksonFeature</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue