Refactor services: remove unused SOAP service, add new REST services with application properties

This commit is contained in:
Lemonochrme 2024-12-13 22:39:53 +01:00
parent f17b60fbc4
commit 99ecb2efb6
23 changed files with 265 additions and 300 deletions

View file

@ -22,3 +22,79 @@ mvn spring-boot:run -pl soap-service
```
Vérifier le bon fonctionnement en accédant à `localhost:8080/hello` pour REST et `localhost:8081/ws` pour SOAP.
# Specifications
### **1. Objectifs de l'application**
- **Aider les personnes en besoin** : Faciliter la publication de demandes daide par des personnes en situation de vulnérabilité.
- **Mobiliser des volontaires** : Permettre aux volontaires de répondre à des demandes daide ou de proposer une aide spontanée.
- **Gérer ladministration** : Faciliter ladministration et le suivi des demandes.
### **2. REST Microservices**
#### **2.1 User Service**
- **Features:**
- Account creation for requesters, volunteers, and administrators.
- User profile management (modification and deletion).
- Authentication and role management (requester, volunteer, administrator).
- **Main Endpoints:**
- `POST /users`: Create a user.
- `GET /users/{id}`: View a user's profile.
- `PUT /users/{id}`: Update a user.
- `DELETE /users/{id}`: Delete a user.
#### **2.2 Request Service**
- **Features:**
- Creation, validation, and management of help requests.
- Management of request statuses: Pending, validated, rejected, completed.
- Viewing and filtering requests by status.
- **Main Endpoints:**
- `POST /requests`: Create a request.
- `GET /requests`: List of requests (with possible filters).
- `GET /requests/{id}`: View a specific request.
- `PUT /requests/{id}`: Update the status or details of a request.
- `DELETE /requests/{id}`: Delete a request.
#### **2.3 Volunteer Service**
- **Features:**
- Viewing available requests.
- Offering help for a specific request.
- Posting spontaneous help offers.
- **Main Endpoints:**
- `GET /volunteers/requests`: List of available requests.
- `POST /volunteers/{id}/help`: Respond to a specific request.
- `POST /volunteers/spontaneous`: Post a spontaneous help offer.
#### **2.4 Feedback Service**
- **Features:**
- Recording and managing feedback after a request is completed.
- Viewing feedback associated with a request or user.
- **Main Endpoints:**
- `POST /feedbacks`: Add feedback.
- `GET /feedbacks`: View feedback (with possible filters).
#### **2.5 Administration Service**
- **Features:**
- Validation or rejection of help requests.
- Management of rejection reasons.
- Viewing global statistics (e.g., number of completed requests).
- **Main Endpoints:**
- `GET /admin/requests`: List of requests to be validated.
- `PUT /admin/requests/{id}/validate`: Validate a request.
- `PUT /admin/requests/{id}/reject`: Reject a request with justification.
### **3. Architecture technique**
- **Communication :** Chaque microservice expose une API REST avec des endpoints bien définis.
- **Base de données :** Chaque microservice possède sa propre base de données pour favoriser la décentralisation (database-per-service).
- **Authentification :** Utilisation de JWT pour sécuriser les communications.
- **Load Balancing et Gateway :** Utilisation dun API Gateway pour la gestion des requêtes et la sécurité.
- **Monitoring :** Intégration de services comme Prometheus et Grafana pour le suivi des performances.
### **4. Avantages de cette architecture**
- **Scalabilité** : Les microservices peuvent être déployés et mis à l'échelle individuellement.
- **Flexibilité** : Possibilité dutiliser différentes technologies pour chaque service.
- **Maintenance** : Une meilleure isolation des fonctionnalités simplifie le débogage et les mises à jour.

View file

@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>insa.application.helpapp</groupId>
<artifactId>helpapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>administration-service</artifactId>
<dependencies>
<!-- Dépendance pour créer un service REST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Plugin Maven pour Spring Boot -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.4</version>
</plugin>
<!-- Plugin pour configurer le compilateur -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>insa.application.helpapp</groupId>
<artifactId>helpapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feedback-service</artifactId>
<dependencies>
<!-- Dépendance pour créer un service REST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Plugin Maven pour Spring Boot -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.4</version>
</plugin>
<!-- Plugin pour configurer le compilateur -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,20 @@
package insa.application.helpapp.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "Hello from REST!";
}
}

View file

@ -0,0 +1 @@
server.port=8080

View file

@ -7,9 +7,11 @@
<packaging>pom</packaging>
<modules>
<module>rest-service</module>
<module>soap-service</module>
<module>user-service</module>
<module>user-service</module>
<module>request-service</module>
<module>volunteer-service</module>
<module>feedback-service</module>
<module>administration-service</module>
</modules>
<dependencyManagement>

View file

@ -5,7 +5,7 @@
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rest-service</artifactId>
<artifactId>request-service</artifactId>
<dependencies>
<!-- Dépendance pour créer un service REST -->

View file

@ -0,0 +1,20 @@
package insa.application.helpapp.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "Hello from REST!";
}
}

View file

@ -0,0 +1 @@
server.port=8080

View file

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>producing-web-service-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>producing-web-service-complete</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<!-- tag::springws[] -->
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<!-- end::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::xsd[] -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>${project.basedir}/src/main/resources/countries.xsd</source>
</sources>
</configuration>
</plugin>
<!-- end::xsd[] -->
</plugins>
</build>
</project>

View file

@ -1 +0,0 @@
io

View file

@ -1,31 +0,0 @@
package com.example.producingwebservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import io.spring.guides.gs_producing_web_service.GetCountryRequest;
import io.spring.guides.gs_producing_web_service.GetCountryResponse;
@Endpoint
public class CountryEndpoint {
private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
private CountryRepository countryRepository;
@Autowired
public CountryEndpoint(CountryRepository countryRepository) {
this.countryRepository = countryRepository;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
response.setCountry(countryRepository.findCountry(request.getName()));
return response;
}
}

View file

@ -1,47 +0,0 @@
package com.example.producingwebservice;
import jakarta.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import io.spring.guides.gs_producing_web_service.Country;
import io.spring.guides.gs_producing_web_service.Currency;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@Component
public class CountryRepository {
private static final Map<String, Country> countries = new HashMap<>();
@PostConstruct
public void initData() {
Country spain = new Country();
spain.setName("Spain");
spain.setCapital("Madrid");
spain.setCurrency(Currency.EUR);
spain.setPopulation(46704314);
countries.put(spain.getName(), spain);
Country poland = new Country();
poland.setName("Poland");
poland.setCapital("Warsaw");
poland.setCurrency(Currency.PLN);
poland.setPopulation(38186860);
countries.put(poland.getName(), poland);
Country uk = new Country();
uk.setName("United Kingdom");
uk.setCapital("London");
uk.setCurrency(Currency.GBP);
uk.setPopulation(63705000);
countries.put(uk.getName(), uk);
}
public Country findCountry(String name) {
Assert.notNull(name, "The country's name must not be null");
return countries.get(name);
}
}

View file

@ -1,12 +0,0 @@
package com.example.producingwebservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProducingWebServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ProducingWebServiceApplication.class, args);
}
}

View file

@ -1,40 +0,0 @@
package com.example.producingwebservice;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountriesPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(countriesSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
}
}

View file

@ -1,36 +0,0 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service"
targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified">
<xs:element name="getCountryRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getCountryResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="country" type="tns:country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="country">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:int"/>
<xs:element name="capital" type="xs:string"/>
<xs:element name="currency" type="tns:currency"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="currency">
<xs:restriction base="xs:string">
<xs:enumeration value="GBP"/>
<xs:enumeration value="EUR"/>
<xs:enumeration value="PLN"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View file

@ -1,56 +0,0 @@
/*
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.producingwebservice;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.spring.guides.gs_producing_web_service.GetCountryRequest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.util.ClassUtils;
import org.springframework.ws.client.core.WebServiceTemplate;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ProducingWebServiceApplicationIntegrationTests {
private Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
@LocalServerPort
private int port = 0;
@BeforeEach
public void init() throws Exception {
marshaller.setPackagesToScan(ClassUtils.getPackageName(GetCountryRequest.class));
marshaller.afterPropertiesSet();
}
@Test
public void testSendAndReceive() {
WebServiceTemplate ws = new WebServiceTemplate(marshaller);
GetCountryRequest request = new GetCountryRequest();
request.setName("Spain");
assertThat(ws.marshalSendAndReceive("http://localhost:"
+ port + "/ws", request) != null);
}
}

View file

@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent>
<groupId>insa.application.helpapp</groupId>
<artifactId>helpapp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>volunteer-service</artifactId>
<dependencies>
<!-- Dépendance pour créer un service REST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Plugin Maven pour Spring Boot -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.4</version>
</plugin>
<!-- Plugin pour configurer le compilateur -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,20 @@
package insa.application.helpapp.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "Hello from REST!";
}
}

View file

@ -0,0 +1 @@
server.port=8080