diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java index e76d1f3..a45eb6b 100755 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import java.net.*; import java.io.*; import java.nio.channels.*; @@ -25,7 +26,7 @@ public class MavenWrapperDownloader { * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; /** * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to @@ -54,7 +55,7 @@ public class MavenWrapperDownloader { // wrapperUrl parameter. File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { + if (mavenWrapperPropertyFile.exists()) { FileInputStream mavenWrapperPropertyFileInputStream = null; try { mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); @@ -65,7 +66,7 @@ public class MavenWrapperDownloader { System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); } finally { try { - if(mavenWrapperPropertyFileInputStream != null) { + if (mavenWrapperPropertyFileInputStream != null) { mavenWrapperPropertyFileInputStream.close(); } } catch (IOException e) { @@ -76,8 +77,8 @@ public class MavenWrapperDownloader { System.out.println("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } diff --git a/HELP.md b/HELP.md index 84dbb4b..eeee186 100755 --- a/HELP.md +++ b/HELP.md @@ -1,6 +1,7 @@ # Getting Started ### Reference Documentation + For further reference, please consider the following sections: * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) diff --git a/jasperReport/listBlocParStructure.jrxml b/jasperReport/listBlocParStructure.jrxml index 32e944f..6c10dd4 100644 --- a/jasperReport/listBlocParStructure.jrxml +++ b/jasperReport/listBlocParStructure.jrxml @@ -1,245 +1,270 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - <band height="134" splitType="Stretch"> - <staticText> - <reportElement x="179" y="75" width="421" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> - <textElement textAlignment="Center" verticalAlignment="Middle"> - <font size="16" isBold="true"/> - </textElement> - <text><![CDATA[LISTE DES BLOCS]]></text> - </staticText> - <staticText> - <reportElement x="0" y="112" width="90" height="20" uuid="4368e598-76c3-4ad7-867e-c3c9efe5ebd8"/> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font size="14" isBold="true"/> - </textElement> - <text><![CDATA[Structure :]]></text> - </staticText> - <textField > - <reportElement x="90" y="112" width="590" height="20" uuid="890f9a0d-98c7-4acd-becc-ea41d147c44d"/> - <textElement> - <font size="12"/> - </textElement> - <textFieldExpression><![CDATA[$P{structure}]]></textFieldExpression> - </textField> - <image> - <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> - <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> - </image> - <image> - <reportElement x="455" y="0" width="100" height="70" uuid="f2e94782-7bfb-4a44-b7d7-8a1815583080"/> - <imageExpression><![CDATA[$P{logoDroit}]]></imageExpression> - </image> - </band> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="134" splitType="Stretch"> + <staticText> + <reportElement x="179" y="75" width="421" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> + <textElement textAlignment="Center" verticalAlignment="Middle"> + <font size="16" isBold="true"/> + </textElement> + <text><![CDATA[LISTE DES BLOCS]]></text> + </staticText> + <staticText> + <reportElement x="0" y="112" width="90" height="20" uuid="4368e598-76c3-4ad7-867e-c3c9efe5ebd8"/> + <textElement textAlignment="Left" verticalAlignment="Middle"> + <font size="14" isBold="true"/> + </textElement> + <text><![CDATA[Structure :]]></text> + </staticText> + <textField> + <reportElement x="90" y="112" width="590" height="20" uuid="890f9a0d-98c7-4acd-becc-ea41d147c44d"/> + <textElement> + <font size="12"/> + </textElement> + <textFieldExpression><![CDATA[$P{structure}]]></textFieldExpression> + </textField> + <image> + <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> + <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> + </image> + <image> + <reportElement x="455" y="0" width="100" height="70" uuid="f2e94782-7bfb-4a44-b7d7-8a1815583080"/> + <imageExpression><![CDATA[$P{logoDroit}]]></imageExpression> + </image> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jasperReport/listEnqueteParBloc.jrxml b/jasperReport/listEnqueteParBloc.jrxml index 6a0e959..2edd642 100644 --- a/jasperReport/listEnqueteParBloc.jrxml +++ b/jasperReport/listEnqueteParBloc.jrxml @@ -1,419 +1,461 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <band height="170" splitType="Stretch"> - <staticText> - <reportElement x="302" y="70" width="190" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> - <textElement textAlignment="Center" verticalAlignment="Middle"> - <font size="16" isBold="true"/> - </textElement> - <text><![CDATA[LISTE DES ENQUETES]]></text> - </staticText> - <staticText> - <reportElement x="0" y="112" width="120" height="20" uuid="4368e598-76c3-4ad7-867e-c3c9efe5ebd8"/> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font size="14" isBold="true"/> - </textElement> - <text><![CDATA[Structure :]]></text> - </staticText> - <textField > - <reportElement x="120" y="112" width="260" height="20" uuid="890f9a0d-98c7-4acd-becc-ea41d147c44d"/> - <textElement> - <font size="12"/> - </textElement> - <textFieldExpression><![CDATA[$P{structure}]]></textFieldExpression> - </textField> - <image> - <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> - <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> - </image> - <textField > - <reportElement x="470" y="112" width="330" height="20" uuid="e89fe5e8-8c95-465a-963a-38c89fe7b45c"/> - <textElement> - <font size="14"/> - </textElement> - <textFieldExpression><![CDATA[$P{bloc}]]></textFieldExpression> - </textField> - <staticText> - <reportElement x="380" y="112" width="90" height="20" uuid="78fbd365-5e80-486f-8b79-fba9f57ff757"/> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font size="14" isBold="true"/> - </textElement> - <text><![CDATA[Bloc :]]></text> - </staticText> - <staticText> - <reportElement x="380" y="150" width="90" height="20" uuid="104de4fb-c535-4e31-a61b-a5c5066de836"/> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font size="14" isBold="true"/> - </textElement> - <text><![CDATA[Commune :]]></text> - </staticText> - <textField > - <reportElement x="470" y="150" width="330" height="20" uuid="7944bfcb-94e3-4fc3-b717-a65820dd64de"/> - <textElement> - <font size="14"/> - </textElement> - <textFieldExpression><![CDATA[$P{commune}]]></textFieldExpression> - </textField> - </band> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="170" splitType="Stretch"> + <staticText> + <reportElement x="302" y="70" width="190" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> + <textElement textAlignment="Center" verticalAlignment="Middle"> + <font size="16" isBold="true"/> + </textElement> + <text><![CDATA[LISTE DES ENQUETES]]></text> + </staticText> + <staticText> + <reportElement x="0" y="112" width="120" height="20" uuid="4368e598-76c3-4ad7-867e-c3c9efe5ebd8"/> + <textElement textAlignment="Left" verticalAlignment="Middle"> + <font size="14" isBold="true"/> + </textElement> + <text><![CDATA[Structure :]]></text> + </staticText> + <textField> + <reportElement x="120" y="112" width="260" height="20" uuid="890f9a0d-98c7-4acd-becc-ea41d147c44d"/> + <textElement> + <font size="12"/> + </textElement> + <textFieldExpression><![CDATA[$P{structure}]]></textFieldExpression> + </textField> + <image> + <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> + <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> + </image> + <textField> + <reportElement x="470" y="112" width="330" height="20" uuid="e89fe5e8-8c95-465a-963a-38c89fe7b45c"/> + <textElement> + <font size="14"/> + </textElement> + <textFieldExpression><![CDATA[$P{bloc}]]></textFieldExpression> + </textField> + <staticText> + <reportElement x="380" y="112" width="90" height="20" uuid="78fbd365-5e80-486f-8b79-fba9f57ff757"/> + <textElement textAlignment="Left" verticalAlignment="Middle"> + <font size="14" isBold="true"/> + </textElement> + <text><![CDATA[Bloc :]]></text> + </staticText> + <staticText> + <reportElement x="380" y="150" width="90" height="20" uuid="104de4fb-c535-4e31-a61b-a5c5066de836"/> + <textElement textAlignment="Left" verticalAlignment="Middle"> + <font size="14" isBold="true"/> + </textElement> + <text><![CDATA[Commune :]]></text> + </staticText> + <textField> + <reportElement x="470" y="150" width="330" height="20" uuid="7944bfcb-94e3-4fc3-b717-a65820dd64de"/> + <textElement> + <font size="14"/> + </textElement> + <textFieldExpression><![CDATA[$P{commune}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jasperReport/listEnqueteParFiltre.jrxml b/jasperReport/listEnqueteParFiltre.jrxml index 9cb5568..64a157b 100644 --- a/jasperReport/listEnqueteParFiltre.jrxml +++ b/jasperReport/listEnqueteParFiltre.jrxml @@ -1,396 +1,443 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <band height="106" splitType="Stretch"> - <staticText> - <reportElement x="240" y="70" width="400" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> - <textElement textAlignment="Center" verticalAlignment="Middle"> - <font size="16" isBold="true"/> - </textElement> - <text><![CDATA[LISTE DES ENQUETES]]></text> - </staticText> - <image> - <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> - <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> - </image> - </band> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="106" splitType="Stretch"> + <staticText> + <reportElement x="240" y="70" width="400" height="30" uuid="10a08362-9a39-4235-a0d1-33a733f0861e"/> + <textElement textAlignment="Center" verticalAlignment="Middle"> + <font size="16" isBold="true"/> + </textElement> + <text><![CDATA[LISTE DES ENQUETES]]></text> + </staticText> + <image> + <reportElement x="0" y="0" width="200" height="70" uuid="e194874d-8732-48bc-b829-5eee66cd557d"/> + <imageExpression><![CDATA[$P{logoGauche}]]></imageExpression> + </image> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index d4a9ea4..f58b9a9 100755 --- a/pom.xml +++ b/pom.xml @@ -1,149 +1,148 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.2 - - - io.gmss - Fiscad - 0.0.1-SNAPSHOT - fiscad - Application de collecte des données socio-foncières - - 11 - 2020.0.3 - - - - org.projectlombok - lombok - 1.18.30 - provided - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-validation - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.2 + + + io.gmss + Fiscad + 0.0.1-SNAPSHOT + fiscad + Application de collecte des données socio-foncières + + 11 + 2020.0.3 + + + + org.projectlombok + lombok + 1.18.30 + provided + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-validation + - - org.modelmapper - modelmapper - 3.1.1 - + + org.modelmapper + modelmapper + 3.1.1 + - - io.jsonwebtoken - jjwt - 0.9.1 - - - org.postgresql - postgresql - runtime - + + io.jsonwebtoken + jjwt + 0.9.1 + + + org.postgresql + postgresql + runtime + - - net.sf.jasperreports - jasperreports - 6.21.3 - - - com.lowagie - itext - - - - - com.lowagie - itext - 2.1.7 - + + net.sf.jasperreports + jasperreports + 6.21.3 + + + com.lowagie + itext + + + + + com.lowagie + itext + 2.1.7 + - - org.codehaus.groovy - groovy-all - 2.4.5 - - - org.springframework.boot - spring-boot-starter-mail - + + org.codehaus.groovy + groovy-all + 2.4.5 + + + org.springframework.boot + spring-boot-starter-mail + - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.6.0 - + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.6.0 + - - javax.xml.bind - jaxb-api - 2.3.0 - + + javax.xml.bind + jaxb-api + 2.3.0 + - - - org.locationtech.jts - jts-core - 1.19.0 - + + org.locationtech.jts + jts-core + 1.19.0 + - - org.hibernate - hibernate-spatial - ${hibernate.version} - + + org.hibernate + hibernate-spatial + ${hibernate.version} + - - org.n52.jackson - jackson-datatype-jts - 1.2.4 - - - org.teiid - teiid-optional-geo - 16.0.0 - + + org.n52.jackson + jackson-datatype-jts + 1.2.4 + + + org.teiid + teiid-optional-geo + 16.0.0 + - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/src/main/java/io/gmss/fiscad/FiscadApplication.java b/src/main/java/io/gmss/fiscad/FiscadApplication.java index 1c793dd..9b7bc40 100755 --- a/src/main/java/io/gmss/fiscad/FiscadApplication.java +++ b/src/main/java/io/gmss/fiscad/FiscadApplication.java @@ -9,12 +9,12 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @ConfigurationPropertiesScan public class FiscadApplication implements CommandLineRunner { - public static void main(String[] args) { - SpringApplication.run(FiscadApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(FiscadApplication.class, args); + } - @Override - public void run(String... args) throws Exception { - System.out.println("InfoCad Application start completed"); - } + @Override + public void run(String... args) throws Exception { + System.out.println("InfoCad Application start completed"); + } } diff --git a/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java b/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java index 7c84be9..67467a1 100755 --- a/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java +++ b/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java @@ -14,7 +14,7 @@ import java.util.HashSet; import java.util.Set; @Component -public class DataLoadConfig { +public class DataLoadConfig { private final RoleRepository roleRepository; private final UserRepository userRepository; @@ -31,16 +31,15 @@ public class DataLoadConfig { @PostConstruct - public void loadData(){ + public void loadData() { loadRoles(); loadUsers(); } + public void loadRoles() { - public void loadRoles(){ - - if(roleRepository.count() > 0) return; + if (roleRepository.count() > 0) return; Set roles = new HashSet<>(); roles.add(new Role(UserRole.ROLE_USER, "Role attribué aux utilisateurs simples.")); roles.add(new Role(UserRole.ROLE_ADMIN, "Role attribué aux administrateurs du système.")); @@ -52,8 +51,8 @@ public class DataLoadConfig { } - public void loadUsers(){ - if(userRepository.countAllByUsernameIsNotNull() == 0) { + public void loadUsers() { + if (userRepository.countAllByUsernameIsNotNull() == 0) { User admin = new User(); admin.setUsername("administrateur@infocad.bj"); admin.setEmail("administrateur@infocad.bj"); diff --git a/src/main/java/io/gmss/fiscad/configuration/ApplicationConfig.java b/src/main/java/io/gmss/fiscad/configuration/ApplicationConfig.java index 16ead9c..5b949be 100644 --- a/src/main/java/io/gmss/fiscad/configuration/ApplicationConfig.java +++ b/src/main/java/io/gmss/fiscad/configuration/ApplicationConfig.java @@ -9,7 +9,10 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; @@ -18,6 +21,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; public class ApplicationConfig { private final CustomUserDetailsService customUserDetailsService; + private final UserDetailsService userDetailsService; @Bean public AuthenticationProvider authenticationProvider() { @@ -37,13 +41,27 @@ public class ApplicationConfig { return new JwtAuthenticationFilter(); } - @Bean - public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { - return config.getAuthenticationManager(); - } +// @Bean +// public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { +// return config.getAuthenticationManager(); +// } @Bean public ModelMapper modelMapper() { return new ModelMapper(); } + + @Bean + public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception { + DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); + daoAuthenticationProvider.setUserDetailsService(customUserDetailsService); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder()); + + AuthenticationManagerBuilder authenticationManagerBuilder = + http.getSharedObject(AuthenticationManagerBuilder.class); + + authenticationManagerBuilder.authenticationProvider(daoAuthenticationProvider); + + return authenticationManagerBuilder.build(); + } } diff --git a/src/main/java/io/gmss/fiscad/configuration/AuditorAwareImpl.java b/src/main/java/io/gmss/fiscad/configuration/AuditorAwareImpl.java index 3afc8b9..1ffdf81 100755 --- a/src/main/java/io/gmss/fiscad/configuration/AuditorAwareImpl.java +++ b/src/main/java/io/gmss/fiscad/configuration/AuditorAwareImpl.java @@ -22,7 +22,7 @@ public class AuditorAwareImpl implements AuditorAware { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if(authentication == null || !authentication.isAuthenticated() || authentication instanceof AnonymousAuthenticationToken){ + if (authentication == null || !authentication.isAuthenticated() || authentication instanceof AnonymousAuthenticationToken) { return Optional.empty(); } UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal(); diff --git a/src/main/java/io/gmss/fiscad/configuration/JdbcConfig.java b/src/main/java/io/gmss/fiscad/configuration/JdbcConfig.java index 479765d..cc3d9ec 100644 --- a/src/main/java/io/gmss/fiscad/configuration/JdbcConfig.java +++ b/src/main/java/io/gmss/fiscad/configuration/JdbcConfig.java @@ -9,8 +9,7 @@ import javax.sql.DataSource; @Configuration public class JdbcConfig { @Bean - public JdbcTemplate jdbcTemplate(DataSource dataSource) - { + public JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } } diff --git a/src/main/java/io/gmss/fiscad/configuration/SpringSecurityConfig.java b/src/main/java/io/gmss/fiscad/configuration/SpringSecurityConfig.java index de7d731..9d15097 100755 --- a/src/main/java/io/gmss/fiscad/configuration/SpringSecurityConfig.java +++ b/src/main/java/io/gmss/fiscad/configuration/SpringSecurityConfig.java @@ -55,6 +55,7 @@ public class SpringSecurityConfig { // .csrf(csrf -> { // csrf.ignoringRequestMatchers("/api/**"); // }) + .exceptionHandling(ex -> ex.authenticationEntryPoint(jwtAuthenticationEntryPoint)) .authorizeHttpRequests(req -> req //.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() @@ -65,10 +66,11 @@ public class SpringSecurityConfig { .authenticationProvider(authenticationProvider) .sessionManagement(session -> session.sessionCreationPolicy(STATELESS)) .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) - .exceptionHandling(ex -> ex.authenticationEntryPoint(jwtAuthenticationEntryPoint)) + ; return http.build(); } + } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/configuration/SwaggerOAS3Config.java b/src/main/java/io/gmss/fiscad/configuration/SwaggerOAS3Config.java index f9196be..1858ecb 100644 --- a/src/main/java/io/gmss/fiscad/configuration/SwaggerOAS3Config.java +++ b/src/main/java/io/gmss/fiscad/configuration/SwaggerOAS3Config.java @@ -23,18 +23,18 @@ public class SwaggerOAS3Config { private static final String[] DECOUPAGE = { "/api/arrondissement/**", "/api/commune/**", "/api/departement/**", "/api/nationalite/**", "/api/quartier/**", - "/api/secteur/**","/api/secteur-decoupage/**" + "/api/secteur/**", "/api/secteur-decoupage/**" }; private static final String[] INFOCAD_METIER = { //metier - "/api/acteur-concerne/**","/api/commentaire/**","/api/enquete/**","/api/tpe/**","/api/upload/**", + "/api/acteur-concerne/**", "/api/commentaire/**", "/api/enquete/**", "/api/tpe/**", "/api/upload/**", }; private static final String[] INFOCAD_PARAMETERS = { - "/api/bloc/**","/api/mode-acquisition/**","/api/nature-domaine/**","/api/position-representation/**", - "/api/profession/**","/api/situation-geographique/**","/api/situation-matrimoniale/**","/api/source-droit/**", - "/api/structure/**","/api/type-contestation/**","/api/type-domaine/**","/api/type-personne/**","/api/type-piece/**", + "/api/bloc/**", "/api/mode-acquisition/**", "/api/nature-domaine/**", "/api/position-representation/**", + "/api/profession/**", "/api/situation-geographique/**", "/api/situation-matrimoniale/**", "/api/source-droit/**", + "/api/structure/**", "/api/type-contestation/**", "/api/type-domaine/**", "/api/type-personne/**", "/api/type-piece/**", "/api/type-representation/**" }; @@ -84,7 +84,6 @@ public class SwaggerOAS3Config { } - @Bean public GroupedOpenApi infocadMetierApi() { return GroupedOpenApi.builder() diff --git a/src/main/java/io/gmss/fiscad/controllers/OpenController.java b/src/main/java/io/gmss/fiscad/controllers/OpenController.java index e1d3be1..3b46bf6 100755 --- a/src/main/java/io/gmss/fiscad/controllers/OpenController.java +++ b/src/main/java/io/gmss/fiscad/controllers/OpenController.java @@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.util.JRSaver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -23,14 +25,16 @@ public class OpenController { @Value("${file.jasper-reports}") private String jaspersDir; + private static final Logger logger = LoggerFactory.getLogger(OpenController.class); + @GetMapping("/compile-report") public ResponseEntity compile(@RequestParam String jrxmlFileName) { - try{ + try { InputStream quitusReportStream = getStream(jaspersDir + "/" + jrxmlFileName + ".jrxml"); JasperReport jasperReport = JasperCompileManager.compileReport(quitusReportStream); JRSaver.saveObject(jasperReport, jaspersDir + "/" + jrxmlFileName + ".jasper"); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } return null; @@ -43,5 +47,4 @@ public class OpenController { } - } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java index e392e5b..ee9bc65 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java @@ -2,13 +2,15 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Arrondissement; -import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.ArrondissementService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -16,7 +18,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -27,6 +29,7 @@ import org.springframework.web.bind.annotation.*; public class ArrondissementController { private final ArrondissementService arrondissementService; + private static final Logger logger = LoggerFactory.getLogger(ArrondissementController.class); public ArrondissementController(ArrondissementService arrondissementService) { this.arrondissementService = arrondissementService; @@ -40,18 +43,26 @@ public class ArrondissementController { @io.swagger.v3.oas.annotations.responses.ApiResponse(description = "Unauthorized / Invalid Token", responseCode = "403")} ) @PostMapping("/create") - public ResponseEntity createArrondissement(@RequestBody @Valid @Validated Arrondissement arrondissement) { - try{ + public ResponseEntity createArrondissement(@RequestBody @Valid @Validated Arrondissement arrondissement) { + try { arrondissement = arrondissementService.createArrondissement(arrondissement); return new ResponseEntity<>( new ApiResponse<>(true, arrondissement, "Arrondissement créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @@ -64,73 +75,144 @@ public class ArrondissementController { ) @PutMapping("/update/{id}") public ResponseEntity updateArrondissement(@PathVariable Long id, @RequestBody Arrondissement arrondissement) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, arrondissementService.updateArrondissement(id, arrondissement), "Arrondissement mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteArrondissement(@PathVariable Long id) { - try{ + try { arrondissementService.deleteArrondissement(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Arrondissement supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Arrondissement supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllArrondissementList() { - return new ResponseEntity<>( - new ApiResponse<>(true, arrondissementService.getArrondissementList(), "Liste des arrondissements chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, arrondissementService.getArrondissementList(), "Liste des arrondissements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/all-paged") public ResponseEntity getAllArrondissementPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, arrondissementService.getArrondissementList(pageable), "Liste des arrondissements chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, arrondissementService.getArrondissementList(pageable), "Liste des arrondissements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getArrondissementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, arrondissementService.getArrondissementById(id), "Arrondissement trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, arrondissementService.getArrondissementById(id), "Arrondissement trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/commune/{communeId}") public ResponseEntity getArrondissementByCommune(@PathVariable Long communeId) { - - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, arrondissementService.getArrondissementByComune(communeId), "Liste des arrondissements par commune chargée avec succès."), HttpStatus.OK ); - }catch (NotFoundException e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java index 2599c2c..eb5181e 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java @@ -2,12 +2,14 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Commune; -import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.CommuneService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -15,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -27,95 +29,176 @@ public class CommuneController { private final CommuneService communeService; + private static final Logger logger = LoggerFactory.getLogger(CommuneController.class); + public CommuneController(CommuneService communeService) { this.communeService = communeService; } @PostMapping("/create") - public ResponseEntity createCommune(@RequestBody @Valid @Validated Commune commune) { - try{ + public ResponseEntity createCommune(@RequestBody @Valid @Validated Commune commune) { + try { commune = communeService.createCommune(commune); return new ResponseEntity<>( new ApiResponse<>(true, commune, "Commune créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCommune(@PathVariable Long id, @RequestBody Commune commune) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, communeService.updateCommune(id, commune), "Commune mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCommuner(@PathVariable Long id) { - try{ + try { communeService.deleteCommune(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Commune supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Commune supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCommuneList() { - return new ResponseEntity<>( - new ApiResponse<>(true, communeService.getCommuneList(), "Liste des communes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, communeService.getCommuneList(), "Liste des communes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/all-paged") public ResponseEntity getAllCommunePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, communeService.getCommuneList(pageable), "Liste des communes chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, communeService.getCommuneList(pageable), "Liste des communes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getCommuneById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, communeService.getCommuneById(id), "Commune trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, communeService.getCommuneById(id), "Commune trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/departement/{departementId}") public ResponseEntity getCommuneByDepartement(@PathVariable Long departementId) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, communeService.getCommunesByDepartement(departementId), "Liste des communes par département chargée avec succès."), HttpStatus.OK ); - }catch (NotFoundException e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java index cea7115..fb342d3 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Departement; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.DepartementService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,152 @@ import org.springframework.web.bind.annotation.*; public class DepartementController { private final DepartementService departementService; + private static final Logger logger = LoggerFactory.getLogger(DepartementController.class); public DepartementController(DepartementService departementService) { this.departementService = departementService; } @PostMapping("/create") - public ResponseEntity createDepartement(@RequestBody @Valid @Validated Departement departement) { - try{ + public ResponseEntity createDepartement(@RequestBody @Valid @Validated Departement departement) { + try { departement = departementService.createDepartement(departement); return new ResponseEntity<>( new ApiResponse<>(true, departement, "Departement créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateDepartement(@PathVariable Long id, @RequestBody Departement departement) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, departementService.updateDepartement(id, departement), "Département mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteDepartementr(@PathVariable Long id) { - try{ + try { departementService.deleteDepartement(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Département supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Département supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllDepartementList() { - return new ResponseEntity<>( - new ApiResponse<>(true, departementService.getDepartementList(), "Liste des département chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, departementService.getDepartementList(), "Liste des département chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/all-paged") public ResponseEntity getAllDepartementPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, departementService.getDepartementList(pageable), "Liste des département chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, departementService.getDepartementList(pageable), "Liste des département chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getDepartementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, departementService.getDepartementById(id), "Département trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, departementService.getDepartementById(id), "Département trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java index 1cf55df..eeb6c57 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Nationalite; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.NationaliteService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,151 @@ import org.springframework.web.bind.annotation.*; public class NationaliteController { private final NationaliteService nationaliteService; + private static final Logger logger = LoggerFactory.getLogger(NationaliteController.class); public NationaliteController(NationaliteService nationaliteService) { this.nationaliteService = nationaliteService; } @PostMapping("/create") - public ResponseEntity createNationalite(@RequestBody @Valid @Validated Nationalite nationalite) { - try{ + public ResponseEntity createNationalite(@RequestBody @Valid @Validated Nationalite nationalite) { + try { nationalite = nationaliteService.createNationalite(nationalite); return new ResponseEntity<>( new ApiResponse<>(true, nationalite, "Nationalite créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateNationalite(@PathVariable Long id, @RequestBody Nationalite nationalite) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, nationaliteService.updateNationalite(id, nationalite), "Nationalités mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteNationaliter(@PathVariable Long id) { - try{ + try { nationaliteService.deleteNationalite(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Nationalités supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Nationalités supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllNationaliteList() { - return new ResponseEntity<>( - new ApiResponse<>(true, nationaliteService.getNationaliteList(), "Liste des nationalités chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, nationaliteService.getNationaliteList(), "Liste des nationalités chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllNationalitePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, nationaliteService.getNationaliteList(pageable), "Liste des nationalités chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, nationaliteService.getNationaliteList(pageable), "Liste des nationalités chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getNationaliteById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, nationaliteService.getNationaliteById(id), "Nationalités trouvées avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, nationaliteService.getNationaliteById(id), "Nationalités trouvées avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java index 4ec66b9..30239f7 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java @@ -2,12 +2,14 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Quartier; -import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.QuartierService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -15,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,96 +28,174 @@ import org.springframework.web.bind.annotation.*; public class QuartierController { private final QuartierService quartierService; + private static final Logger logger = LoggerFactory.getLogger(QuartierController.class); public QuartierController(QuartierService quartierService) { this.quartierService = quartierService; } @PostMapping("/create") - public ResponseEntity createQuartier(@RequestBody @Valid @Validated Quartier quartier) { - try{ + public ResponseEntity createQuartier(@RequestBody @Valid @Validated Quartier quartier) { + try { quartier = quartierService.createQuartier(quartier); return new ResponseEntity<>( new ApiResponse<>(true, quartier, "Quartier créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateQuartier(@PathVariable Long id, @RequestBody Quartier quartier) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, quartierService.updateQuartier(id, quartier), "Quartier mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteQuartier(@PathVariable Long id) { - try{ + try { quartierService.deleteQuartier(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Quartier supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Quartier supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllQuartierList() { - return new ResponseEntity<>( - new ApiResponse<>(true, quartierService.getQuartierList(), "Liste des quartiers chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, quartierService.getQuartierList(), "Liste des quartiers chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllQuartierPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, quartierService.getQuartierList(pageable), "Liste des quartiers chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, quartierService.getQuartierList(pageable), "Liste des quartiers chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getQuartierById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, quartierService.getQuartierById(id), "Quartier trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, quartierService.getQuartierById(id), "Quartier trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/arrondissement/{arrondissementId}") public ResponseEntity getQuartierByArrondissement(@PathVariable Long arrondissementId) { - - try{ + + try { return new ResponseEntity<>( new ApiResponse<>(true, quartierService.getQuartierByArrondissement(arrondissementId), "Liste des quartiers par commune chargée avec succès."), HttpStatus.OK ); - }catch (NotFoundException e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurController.java index a4ab88f..98299bf 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurController.java @@ -1,12 +1,15 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.request.SecteurPayload; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -23,6 +27,7 @@ import org.springframework.web.bind.annotation.*; public class SecteurController { private final SecteurService secteurService; + private static final Logger logger = LoggerFactory.getLogger(SecteurController.class); public SecteurController(SecteurService secteurService) { this.secteurService = secteurService; @@ -30,87 +35,170 @@ public class SecteurController { @PostMapping("/create") - public ResponseEntity createSecteur(@RequestBody @Valid @Validated SecteurPayload secteurPayload) { - try{ + public ResponseEntity createSecteur(@RequestBody @Valid @Validated SecteurPayload secteurPayload) { + try { // Secteur secteur=getSecteurFromPayload(secteurPayload); Secteur secteur = secteurService.createSecteur(secteurPayload); return new ResponseEntity<>( new ApiResponse<>(true, secteur, "Secteur créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } - @PutMapping("/update/{id}") public ResponseEntity updateSecteur(@PathVariable Long id, @RequestBody SecteurPayload secteurPayload) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, secteurService.updateSecteur(id, secteurPayload), "Secteur mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteSecteurr(@PathVariable Long id) { - try{ + try { secteurService.deleteSecteur(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Secteur supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Secteur supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllSecteurList() { - return new ResponseEntity<>( - new ApiResponse<>(true, secteurService.getSecteurList(), "Liste des secteurs chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurService.getSecteurList(), "Liste des secteurs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllSecteurPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, secteurService.getSecteurList(pageable), "Liste des secteurs chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, secteurService.getSecteurList(pageable), "Liste des secteurs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getSecteurById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, secteurService.getSecteurById(id), "Secteur trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurService.getSecteurById(id), "Secteur trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/by-structure-id/{structureId}") public ResponseEntity getSecteurByStructureId(@PathVariable Long structureId) { - return new ResponseEntity<>( - new ApiResponse<>(true, secteurService.getSecteurById(structureId), "Secteur trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurService.getSecteurById(structureId), "Secteur trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java index ca1274e..ecc2b0c 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java @@ -1,11 +1,14 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -13,6 +16,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -22,6 +26,7 @@ import org.springframework.web.bind.annotation.*; public class SecteurDecoupageController { private final SecteurDecoupageService secteurDecoupageService; + private static final Logger logger = LoggerFactory.getLogger(SecteurDecoupageController.class); public SecteurDecoupageController(SecteurDecoupageService secteurDecoupageService) { this.secteurDecoupageService = secteurDecoupageService; @@ -29,75 +34,144 @@ public class SecteurDecoupageController { @PostMapping("/create") - public ResponseEntity createSecteurDecoupage(@RequestBody @Valid @Validated SecteurDecoupage secteurDecoupage) { - try{ + public ResponseEntity createSecteurDecoupage(@RequestBody @Valid @Validated SecteurDecoupage secteurDecoupage) { + try { secteurDecoupage = secteurDecoupageService.createSecteurDecoupage(secteurDecoupage); return new ResponseEntity<>( new ApiResponse<>(true, secteurDecoupage, "SecteurDecoupage créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateSecteurDecoupage(@PathVariable Long id, @RequestBody SecteurDecoupage secteurDecoupage) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, secteurDecoupageService.updateSecteurDecoupage(id, secteurDecoupage), "SecteurDecoupage mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteSecteurDecoupager(@PathVariable Long id) { - try{ + try { secteurDecoupageService.deleteSecteurDecoupage(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Secteur découpage supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Secteur découpage supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllSecteurDecoupageList() { - return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageList(), "Liste des secteurDecoupages chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageList(), "Liste des secteurDecoupages chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllSecteurDecoupagePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageList(pageable), "Liste des secteurDecoupages chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageList(pageable), "Liste des secteurDecoupages chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getSecteurDecoupageById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageById(id), "SecteurDecoupage trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageById(id), "SecteurDecoupage trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ActeurConcerneController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ActeurConcerneController.java index 643b0cf..e74eefc 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ActeurConcerneController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ActeurConcerneController.java @@ -1,13 +1,17 @@ package io.gmss.fiscad.controllers.infocad.metier; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.metier.ActeurConcerneService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @RequestMapping(value = "api/acteur-concerne", produces = MediaType.APPLICATION_JSON_VALUE) @@ -18,6 +22,8 @@ public class ActeurConcerneController { private final ActeurConcerneService acteurConcerneService; + private static final Logger logger = LoggerFactory.getLogger(ActeurConcerneController.class); + public ActeurConcerneController(ActeurConcerneService acteurConcerneService) { this.acteurConcerneService = acteurConcerneService; } @@ -25,10 +31,25 @@ public class ActeurConcerneController { @GetMapping("/id/{id}") public ResponseEntity getArrondissementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, acteurConcerneService.getActeurConcerneById(id).get(), "Arrondissement trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, acteurConcerneService.getActeurConcerneById(id).get(), "Arrondissement trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/CommentaireController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/CommentaireController.java index 3fec1bc..7549f7e 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/CommentaireController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/CommentaireController.java @@ -2,6 +2,7 @@ package io.gmss.fiscad.controllers.infocad.metier; import io.gmss.fiscad.entities.infocad.metier.Commentaire; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.metier.CommentaireService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.request.CommentaireRequest; @@ -9,11 +10,14 @@ import io.gmss.fiscad.paylaods.request.SyncCommentaireRequest; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; import java.time.LocalDateTime; import java.util.List; @@ -27,134 +31,295 @@ public class CommentaireController { private final CommentaireService commentaireService; + private static final Logger logger = LoggerFactory.getLogger(CommentaireController.class); + public CommentaireController(CommentaireService commentaireService) { this.commentaireService = commentaireService; } @PostMapping("/create") - public ResponseEntity createcommentaire(@RequestBody @Valid @Validated Commentaire commentaire) { - try{ + public ResponseEntity createcommentaire(@RequestBody @Valid @Validated Commentaire commentaire) { + try { commentaire.setDateCommentaire(LocalDateTime.now()); commentaire = commentaireService.createCommentaire(commentaire); return new ResponseEntity<>( new ApiResponse<>(true, commentaire, "Commentaire créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updatecommentaire(@PathVariable Long id, @RequestBody Commentaire commentaire) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, commentaireService.updateCommentaire(id, commentaire), "commentaire mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deletecommentaire(@PathVariable Long id) { - try{ + try { commentaireService.deleteCommentaire(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Commentaire supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Commentaire supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllcommentaireList() { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentaireList(), "Liste des commentaires chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentaireList(), "Liste des commentaires chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getcommentaireById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentaireById(id), "commentaire trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentaireById(id), "commentaire trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/nup/{nup}") public ResponseEntity getcommentaireByNup(@PathVariable String nup) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentaireByNup(nup), "commentaire trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentaireByNup(nup), "commentaire trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/enquete") public ResponseEntity getcommentaireByEnquete(@RequestBody Commentaire commentaire) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentairesByEnqueteAndTerminal(commentaire.getIdEnquete(), commentaire.getTerminalId()), "Liste des commentaires chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentairesByEnqueteAndTerminal(commentaire.getIdEnquete(), commentaire.getTerminalId()), "Liste des commentaires chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/enquete-and-state") //@ApiOperation(value = "Cette ressource permet d'avoir la liste de tous les commentaires d'une enquête avec le statut (lu ou non lu). Les champs a renseigner pour le payload sont idEnquete et lu") public ResponseEntity getcommentaireByEnqueteAndStatut(@RequestBody Commentaire commentaire) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentairesByEnqueteAndLu(commentaire.getIdEnquete(), commentaire.isLu()), "Liste des commentaires chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentairesByEnqueteAndLu(commentaire.getIdEnquete(), commentaire.isLu()), "Liste des commentaires chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/all-by-params") //@ApiOperation(value = "Cette ressource permet d'avoir 4 résultats différents. \n 1 - Liste des commentaires non lus provenant du Web. \n 2 - Liste des commentaires lus provenant du Web \n 3 - Liste des commentaires non lus provenant du mobile. \n 4 - Liste des commentaires lus provenant du mobile. \n A savoir : Les variables Origine et lu sont à varier pour avoir le résultat") public ResponseEntity getcommentaireByParams(@RequestBody CommentaireRequest commentaireRequest) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentairesByOrigineAndStateReadAndTerminalId(commentaireRequest.getOrigine(), commentaireRequest.isLu(), commentaireRequest.getTerminalId()), "Liste des commentaires chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentairesByOrigineAndStateReadAndTerminalId(commentaireRequest.getOrigine(), commentaireRequest.isLu(), commentaireRequest.getTerminalId()), "Liste des commentaires chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("synchronise/from-mobile") //@ApiOperation(value = "Cette ressource permet de synchroniser tous les commentaires effectués sur le mobile vers le backend.") public ResponseEntity synchroniseCommentairesFromMobile(@RequestBody List commentaires) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.saveAllCommentairesFromMobile(commentaires), "Liste des commentaires synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.saveAllCommentairesFromMobile(commentaires), "Liste des commentaires synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("synchronise/from-web") //@ApiOperation(value = "Cette ressource permet d'avoir 4 résultats différents. \n 1 - Liste des commentaires non synchronisés provenant du Web. \n 2 - Liste des commentaires synchronisés provenant du Web \n 3 - Liste des commentaires non synchronisés provenant du mobile. \n 4 - Liste des commentaires synchronisés provenant du mobile. \n A savoir : Les variables Origine et Synchronise sont à varier pour avoir le résultat") public ResponseEntity synchroniseCommentairesFromWeb(@RequestBody CommentaireRequest commentaireRequest) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.getCommentairesByOrigineAndStateSynchronizedAndTerminalId(commentaireRequest.getOrigine(), commentaireRequest.isSynchronise(), commentaireRequest.getTerminalId()), "Liste des commentaires chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.getCommentairesByOrigineAndStateSynchronizedAndTerminalId(commentaireRequest.getOrigine(), commentaireRequest.isSynchronise(), commentaireRequest.getTerminalId()), "Liste des commentaires chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("synchronise/notify-done-from-mobile") //@ApiOperation(value = "Cette ressource permet matérialiser coté backend les commentaires du WEB déjà synchronisé avec le MOBILE pour que les prochaines extractions ne prennent pas en compte cela. ") public ResponseEntity notifyDoneSynchronizedFromMobile(@RequestBody List syncCommentaireRequests) { - return new ResponseEntity<>( - new ApiResponse<>(true, commentaireService.notifySynchronizedDoneFromMobile(syncCommentaireRequests), "Synchronisation terminée."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, commentaireService.notifySynchronizedDoneFromMobile(syncCommentaireRequests), "Synchronisation terminée."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/EnqueteController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/EnqueteController.java index f75f178..5fac13b 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/EnqueteController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/EnqueteController.java @@ -1,5 +1,6 @@ package io.gmss.fiscad.controllers.infocad.metier; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.request.EnquetePayLoad; @@ -8,6 +9,8 @@ import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -15,6 +18,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; import java.util.List; @@ -25,7 +29,9 @@ import java.util.List; @CrossOrigin(origins = "*") public class EnqueteController { - private final EnqueteService enqueteService ; + private final EnqueteService enqueteService; + + private static final Logger logger = LoggerFactory.getLogger(EnqueteController.class); public EnqueteController(EnqueteService enqueteService) { this.enqueteService = enqueteService; @@ -33,7 +39,7 @@ public class EnqueteController { @PostMapping("/create") - public ResponseEntity createStructure(@RequestBody @Valid @Validated EnquetePayLoad enquetePayLoad) { + public ResponseEntity createStructure(@RequestBody @Valid @Validated EnquetePayLoad enquetePayLoad) { // try{ // enquete = enqueteService.createEnquete(enquete); // return new ResponseEntity<>( @@ -51,144 +57,304 @@ public class EnqueteController { @PutMapping("/validation") public ResponseEntity validerEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteService.validerEnquete(enqueteTraitementPayLoad), "Validation effectuée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false,"Impossible de valider l'enquête : "+e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/rejet") public ResponseEntity rejeterEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteService.rejeterEnquete(enqueteTraitementPayLoad), "Rejet effectuée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false,"Impossible de valider l'enquête : "+e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/validation-lot") public ResponseEntity validerEnqueteParLot(@RequestBody List enqueteTraitementPayLoads) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteService.validerEnquete(enqueteTraitementPayLoads), "Validation effectuée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false,"Impossible de valider l'enquête : " + e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/rejet-lot") public ResponseEntity rejeterEnqueteParLot(@RequestBody List enqueteTraitementPayLoads) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteService.rejeterEnquete(enqueteTraitementPayLoads), "Rejet effectuée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false,"Impossible de valider l'enquête : "+e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all/decoupage-admin-for-enquete") public ResponseEntity getAllByEnqueteDecoupageAdmin() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getDecoupageAdminUserConnecterAndStat(), "Liste des enquetes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getDecoupageAdminUserConnecterAndStat(), "Liste des enquetes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteStructurer(@PathVariable Long id) { - try{ + try { enqueteService.deleteEnquete(id); return new ResponseEntity<>( - new ApiResponse<>(true,"enquete supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "enquete supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllStructureList() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteList(), "Liste des enquetes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteList(), "Liste des enquetes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all/com-arrond-bloc") public ResponseEntity getAllByCommuneArrondBloc() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteCommuneArrondBloc(), "Liste des enquetes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteCommuneArrondBloc(), "Liste des enquetes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/all/com-arrond-bloc/filtre") public ResponseEntity getAllByCommuneArrondBlocFiltre(@RequestBody FiltreEnquetePayLoad filtreEnquetePayLoad) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteCommuneArrondBlocFiltre(filtreEnquetePayLoad), "Liste des enquetes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteCommuneArrondBlocFiltre(filtreEnquetePayLoad), "Liste des enquetes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllEnquetePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteList(pageable), "Liste des enquetes chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteList(pageable), "Liste des enquetes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/fiche/id/{id}") public ResponseEntity getFicheEnqueteById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getFicheEnquete(id), "enquete trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getFicheEnquete(id), "enquete trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getStructureById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteById(id), "enquete trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteById(id), "enquete trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/traiter-non-synch-to-mobile/{terminalId}") public ResponseEntity getEnqueteValideNonSynch(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteService.getEnqueteValideNonSynch(terminalId), "Liste des enquetes traitées non synchronisées sur le termianl."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteValideNonSynch(terminalId), "Liste des enquetes traitées non synchronisées sur le termianl."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/TpeController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/TpeController.java index 1abfe29..1dd398e 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/TpeController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/TpeController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.metier; import io.gmss.fiscad.entities.infocad.metier.Tpe; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.metier.TpeService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,105 +28,220 @@ import org.springframework.web.bind.annotation.*; public class TpeController { private final TpeService tpeService; + private static final Logger logger = LoggerFactory.getLogger(TpeController.class); public TpeController(TpeService tpeService) { this.tpeService = tpeService; } @PostMapping("/create") - public ResponseEntity createTpe(@RequestBody @Valid @Validated Tpe tpe) { - try{ + public ResponseEntity createTpe(@RequestBody @Valid @Validated Tpe tpe) { + try { tpe = tpeService.createTpe(tpe); return new ResponseEntity<>( new ApiResponse<>(true, tpe, "Tpe créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTpe(@PathVariable Long id, @RequestBody Tpe tpe) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, tpeService.updateTpe(id, tpe), "Tpe mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTper(@PathVariable Long id) { - try{ + try { tpeService.deleteTpe(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Tpe supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Tpe supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTpeList() { - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTpeList(), "Liste des tpe chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTpeList(), "Liste des tpe chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-by-model/{model}") public ResponseEntity getAllTpeListByModel(@PathVariable String model) { - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTpeListByModel(model), "Liste des tpe chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTpeListByModel(model), "Liste des tpe chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-by-userId/{userId}") public ResponseEntity getAllTpeListByUserId(@PathVariable Long userId) { - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTpeListByUserId(userId), "Liste des tpe de l'utilisateurs."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTpeListByUserId(userId), "Liste des tpe de l'utilisateurs."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTpePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTpeList(pageable), "Liste des tpe chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTpeList(pageable), "Liste des tpe chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTpeById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTpeById(id), "Tpe trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTpeById(id), "Tpe trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/identifier/{identifier}") public ResponseEntity getTpeByIdentifier(@PathVariable String identifier) { - return new ResponseEntity<>( - new ApiResponse<>(true, tpeService.getTepByIdentifier(identifier), "Tpe trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, tpeService.getTepByIdentifier(identifier), "Tpe trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/UploadController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/UploadController.java index ea35e79..e4444c9 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/UploadController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/UploadController.java @@ -36,7 +36,7 @@ import java.time.format.DateTimeFormatter; @CrossOrigin(origins = "*") public class UploadController { - boolean headIsValid=false; + boolean headIsValid = false; private static final Logger logger = LoggerFactory.getLogger(UploadController.class); @@ -44,7 +44,6 @@ public class UploadController { private UploadRepository uploadRepository; - @Autowired private FileStorageService fileStorageService; @@ -55,9 +54,6 @@ public class UploadController { // private ActeurRepository proprietaireRepository; - - - private int firstLineColumnNumber = 0; private String fileHeader; private String fileHeaderType; @@ -65,30 +61,26 @@ public class UploadController { private int indiceOfFile = 0; - private SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMDD"); private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYYMMDD"); - - - @GetMapping("/all") public ResponseEntity all() { try { if (uploadRepository.findAll().isEmpty()) { - return new ResponseEntity<>(new ApiResponse(true, uploadRepository.findAll(), "Empty list. No values present."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(true, uploadRepository.findAll(), "Empty list. No values present."), HttpStatus.OK); } else { return new ResponseEntity<>(new ApiResponse(true, uploadRepository.findAll(), "All uploads files founded."), HttpStatus.OK); } } catch (HttpClientErrorException.MethodNotAllowed e) { - return new ResponseEntity<>(new ApiResponse(false,null, "Method POST/GET is required."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); } catch (NullPointerException e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @@ -114,8 +106,6 @@ public class UploadController { // } - - @GetMapping("/id/{id}") public ResponseEntity one(@PathVariable Long id) { @@ -123,21 +113,20 @@ public class UploadController { if (uploadRepository.findById(id).isPresent()) { return new ResponseEntity<>(new ApiResponse(true, uploadRepository.getOne(id), "File with id {" + id + "} is found."), HttpStatus.OK); } else { - return new ResponseEntity<>(new ApiResponse(true, null,"The upload with id {" + id + "} you request for is not found."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(true, null, "The upload with id {" + id + "} you request for is not found."), HttpStatus.OK); } } catch (HttpClientErrorException.MethodNotAllowed e) { - return new ResponseEntity<>(new ApiResponse(false,null, "Method POST/GET is required."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); } catch (NullPointerException e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false, null,"An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } - /** * @param fileName * @param request @@ -168,7 +157,7 @@ public class UploadController { } @PostMapping("/save") - public ResponseEntity save(@RequestPart(required = true) MultipartFile file , @RequestParam String reference,@RequestParam String description /*, @RequestParam Long idTypeUpload*/) { + public ResponseEntity save(@RequestPart(required = true) MultipartFile file, @RequestParam String reference, @RequestParam String description /*, @RequestParam Long idTypeUpload*/) { try { Upload upload = new Upload(); @@ -187,22 +176,20 @@ public class UploadController { upload.setMimeType(file.getContentType()); upload.setSize(file.getSize()); upload.setOriginalFileName(file.getOriginalFilename()); - return new ResponseEntity<>(new ApiResponse(true,uploadRepository.save(upload), "File has been created successfully."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(true, uploadRepository.save(upload), "File has been created successfully."), HttpStatus.OK); } catch (HttpClientErrorException.MethodNotAllowed e) { - return new ResponseEntity<>(new ApiResponse(false,null, "Method POST/GET is required."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); } catch (NullPointerException e) { e.printStackTrace(); logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null,"An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } - - @DeleteMapping("/delete/id/{id}") public ResponseEntity delete(@PathVariable Long id) { try { @@ -210,18 +197,18 @@ public class UploadController { String name = uploadRepository.getOne(id).getFileName(); fileStorageService.deleteFile(name); uploadRepository.deleteById(id); - return new ResponseEntity<>(new ApiResponse(true,null, "File with name {" + name + "} has been deleted successfully."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(true, null, "File with name {" + name + "} has been deleted successfully."), HttpStatus.OK); } else { - return new ResponseEntity<>(new ApiResponse(true,null, "The upload specified in your request body is not found."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(true, null, "The upload specified in your request body is not found."), HttpStatus.OK); } } catch (HttpClientErrorException.MethodNotAllowed e) { - return new ResponseEntity<>(new ApiResponse(false,null, "Method POST/GET is required."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); } catch (NullPointerException e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { logger.error(e.getLocalizedMessage()); - return new ResponseEntity<>(new ApiResponse(false,null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/BlocController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/BlocController.java index d32ffb1..aa3f74d 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/BlocController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/BlocController.java @@ -2,13 +2,15 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.Bloc; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.BlocService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.security.CurrentUser; import io.gmss.fiscad.security.UserPrincipal; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -16,7 +18,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -27,106 +29,226 @@ import org.springframework.web.bind.annotation.*; public class BlocController { private final BlocService blocService; + private static final Logger logger = LoggerFactory.getLogger(BlocController.class); public BlocController(BlocService blocService) { this.blocService = blocService; } @PostMapping("/create") - public ResponseEntity createBloc(@RequestBody @Valid @Validated Bloc bloc, @CurrentUser UserPrincipal userPrincipal) { - try{ + public ResponseEntity createBloc(@RequestBody @Valid @Validated Bloc bloc, @CurrentUser UserPrincipal userPrincipal) { + try { bloc = blocService.createBloc(bloc); return new ResponseEntity<>( new ApiResponse<>(true, bloc, "Bloc créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateBloc(@PathVariable Long id, @RequestBody Bloc bloc) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, blocService.updateBloc(id, bloc), "Bloc mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteBlocr(@PathVariable Long id) { - try{ + try { blocService.deleteBloc(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Bloc supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Bloc supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllBlocList() { - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocList(), "Liste des blocs chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocList(), "Liste des blocs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/list-by-arrondissement") public ResponseEntity getAllBlocListByArrondissement(@RequestParam Long idArrondissement) { - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocsByArrondissement(idArrondissement), "Liste des blocs chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocsByArrondissement(idArrondissement), "Liste des blocs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/list-by-structure") public ResponseEntity getAllBlocListByStructure(@RequestParam Long idStructure) { - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocsByStructure(idStructure), "Liste des blocs chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocsByStructure(idStructure), "Liste des blocs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/list-by-secteur") - @Tag(name = "Liste blocs",description = "Liste des blocs d'un secteur") + @Tag(name = "Liste blocs", description = "Liste des blocs d'un secteur") public ResponseEntity getAllBlocListBySecteur(@RequestParam Long idSecteur) { - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocsBySecteur(idSecteur), "Liste des blocs chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocsBySecteur(idSecteur), "Liste des blocs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllBlocPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocList(pageable), "Liste des blocs chargée avec succès."), - HttpStatus.OK - ); + + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocList(pageable), "Liste des blocs chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getBlocById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, blocService.getBlocById(id), "Bloc trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, blocService.getBlocById(id), "Bloc trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ModeAcquisitionController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ModeAcquisitionController.java index f3fa4cb..f2a2591 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ModeAcquisitionController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ModeAcquisitionController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.ModeAcquisition; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.ModeAcquisitionService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -26,79 +29,150 @@ public class ModeAcquisitionController { private final ModeAcquisitionService modeAcquisitionService; + private static final Logger logger = LoggerFactory.getLogger(ModeAcquisitionController.class); + public ModeAcquisitionController(ModeAcquisitionService modeAcquisitionService) { this.modeAcquisitionService = modeAcquisitionService; } @PostMapping("/create") - public ResponseEntity createModeAcquisition(@RequestBody @Valid @Validated ModeAcquisition modeAcquisition) { - try{ + public ResponseEntity createModeAcquisition(@RequestBody @Valid @Validated ModeAcquisition modeAcquisition) { + try { modeAcquisition = modeAcquisitionService.createModeAcquisition(modeAcquisition); return new ResponseEntity<>( new ApiResponse<>(true, modeAcquisition, "Mode acquisition créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateModeAcquisition(@PathVariable Long id, @RequestBody ModeAcquisition modeAcquisition) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, modeAcquisitionService.updateModeAcquisition(id, modeAcquisition), "Mode d'acquisition mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteModeAcquisitionr(@PathVariable Long id) { - try{ + try { modeAcquisitionService.deleteModeAcquisition(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Mode d'acquisition supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Mode d'acquisition supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllModeAcquisitionList() { - return new ResponseEntity<>( - new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionList(), "Liste des modes d'acquisitions chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionList(), "Liste des modes d'acquisitions chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllModeAcquisitionPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionList(pageable), "Liste des modes d'acquisitions chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionList(pageable), "Liste des modes d'acquisitions chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getModeAcquisitionById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionById(id), "Mode d'acquisition trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, modeAcquisitionService.getModeAcquisitionById(id), "Mode d'acquisition trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/NatureDomaineController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/NatureDomaineController.java index 1a24791..1f4af25 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/NatureDomaineController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/NatureDomaineController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.NatureDomaine; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.NatureDomaineService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class NatureDomaineController { private final NatureDomaineService natureDomaineService; + private static final Logger logger = LoggerFactory.getLogger(NatureDomaineController.class); public NatureDomaineController(NatureDomaineService natureDomaineService) { this.natureDomaineService = natureDomaineService; } @PostMapping("/create") - public ResponseEntity createNatureDomaine(@RequestBody @Valid @Validated NatureDomaine natureDomaine) { - try{ + public ResponseEntity createNatureDomaine(@RequestBody @Valid @Validated NatureDomaine natureDomaine) { + try { natureDomaine = natureDomaineService.createNatureDomaine(natureDomaine); return new ResponseEntity<>( new ApiResponse<>(true, natureDomaine, "Nature Domaine créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateNatureDomaine(@PathVariable Long id, @RequestBody NatureDomaine natureDomaine) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, natureDomaineService.updateNatureDomaine(id, natureDomaine), "Nature Domaine mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteNatureDomainer(@PathVariable Long id) { - try{ + try { natureDomaineService.deleteNatureDomaine(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Nature Domaine supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Nature Domaine supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllNatureDomaineList() { - return new ResponseEntity<>( - new ApiResponse<>(true, natureDomaineService.getNatureDomaineList(), "Liste des natures de domaine chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, natureDomaineService.getNatureDomaineList(), "Liste des natures de domaine chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllNatureDomainePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, natureDomaineService.getNatureDomaineList(pageable), "Liste des natures de domaine chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, natureDomaineService.getNatureDomaineList(pageable), "Liste des natures de domaine chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getNatureDomaineById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, natureDomaineService.getNatureDomaineById(id), "Nature Domaine trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, natureDomaineService.getNatureDomaineById(id), "Nature Domaine trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/PositionRepresentationController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/PositionRepresentationController.java index 380f2a9..1c11774 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/PositionRepresentationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/PositionRepresentationController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.PositionRepresentation; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.PositionRepresentationService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,152 @@ import org.springframework.web.bind.annotation.*; public class PositionRepresentationController { private final PositionRepresentationService positionRepresentationService; + private static final Logger logger = LoggerFactory.getLogger(PositionRepresentationController.class); public PositionRepresentationController(PositionRepresentationService positionRepresentationService) { this.positionRepresentationService = positionRepresentationService; } @PostMapping("/create") - public ResponseEntity createPositionRepresentation(@RequestBody @Valid @Validated PositionRepresentation positionRepresentation) { - try{ + public ResponseEntity createPositionRepresentation(@RequestBody @Valid @Validated PositionRepresentation positionRepresentation) { + try { positionRepresentation = positionRepresentationService.createPositionRepresentation(positionRepresentation); return new ResponseEntity<>( new ApiResponse<>(true, positionRepresentation, "Position de representation créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updatePositionRepresentation(@PathVariable Long id, @RequestBody PositionRepresentation positionRepresentation) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, positionRepresentationService.updatePositionRepresentation(id, positionRepresentation), "Position de representation mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deletePositionRepresentation(@PathVariable Long id) { - try{ + try { positionRepresentationService.deletePositionRepresentation(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Position de representation supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Position de representation supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllPositionRepresentationList() { - return new ResponseEntity<>( - new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationList(), "Liste des positions de representation chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationList(), "Liste des positions de representation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllPositionRepresentationPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationList(pageable), "Liste des positions de representation chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationList(pageable), "Liste des positions de representation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + + } @GetMapping("/id/{id}") public ResponseEntity getPositionRepresentationById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationById(id), "Position de representation trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, positionRepresentationService.getPositionRepresentationById(id), "Position de representation trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ProfessionController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ProfessionController.java index 0a3e8d2..49ef435 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ProfessionController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/ProfessionController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.Profession; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.ProfessionService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,79 +29,152 @@ public class ProfessionController { private final ProfessionService professionService; + private static final Logger logger = LoggerFactory.getLogger(ProfessionController.class); + public ProfessionController(ProfessionService professionService) { this.professionService = professionService; } @PostMapping("/create") - public ResponseEntity createProfession(@RequestBody @Valid @Validated Profession profession) { - try{ + public ResponseEntity createProfession(@RequestBody @Valid @Validated Profession profession) { + try { profession = professionService.createProfession(profession); return new ResponseEntity<>( new ApiResponse<>(true, profession, "Profession créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateProfession(@PathVariable Long id, @RequestBody Profession profession) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, professionService.updateProfession(id, profession), "Profession mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteProfessionr(@PathVariable Long id) { - try{ + try { professionService.deleteProfession(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Profession supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Profession supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllProfessionList() { - return new ResponseEntity<>( - new ApiResponse<>(true, professionService.getProfessionList(), "Liste des professions chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, professionService.getProfessionList(), "Liste des professions chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/all-paged") public ResponseEntity getAllProfessionPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, professionService.getProfessionList(pageable), "Liste des professions chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, professionService.getProfessionList(pageable), "Liste des professions chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getProfessionById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, professionService.getProfessionById(id), "Profession trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, professionService.getProfessionById(id), "Profession trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationGeographiqueController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationGeographiqueController.java index a37734d..04e5c53 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationGeographiqueController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationGeographiqueController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.SituationGeographique; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.SituationGeographiqueService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class SituationGeographiqueController { private final SituationGeographiqueService situationGeographiqueService; + private static final Logger logger = LoggerFactory.getLogger(SituationGeographiqueController.class); public SituationGeographiqueController(SituationGeographiqueService situationGeographiqueService) { this.situationGeographiqueService = situationGeographiqueService; } @PostMapping("/create") - public ResponseEntity createSituationGeographique(@RequestBody @Valid @Validated SituationGeographique situationGeographique) { - try{ + public ResponseEntity createSituationGeographique(@RequestBody @Valid @Validated SituationGeographique situationGeographique) { + try { situationGeographique = situationGeographiqueService.createSituationGeographique(situationGeographique); return new ResponseEntity<>( new ApiResponse<>(true, situationGeographique, "Situation géographique créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateSituationGeographique(@PathVariable Long id, @RequestBody SituationGeographique situationGeographique) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, situationGeographiqueService.updateSituationGeographique(id, situationGeographique), "Situation géographique mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteSituationGeographiquer(@PathVariable Long id) { - try{ + try { situationGeographiqueService.deleteSituationGeographique(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Situation géographique supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Situation géographique supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllSituationGeographiqueList() { - return new ResponseEntity<>( - new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueList(), "Liste des situations géographiques chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueList(), "Liste des situations géographiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllSituationGeographiquePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueList(pageable), "Liste des situations géographiques chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueList(pageable), "Liste des situations géographiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getSituationGeographiqueById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueById(id), "Situation géographique trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, situationGeographiqueService.getSituationGeographiqueById(id), "Situation géographique trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationMatrimonialeController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationMatrimonialeController.java index f73f49d..f595068 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationMatrimonialeController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SituationMatrimonialeController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.SituationMatrimoniale; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.SituationMatrimonialeService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class SituationMatrimonialeController { private final SituationMatrimonialeService situationMatrimonialeService; + private static final Logger logger = LoggerFactory.getLogger(SituationMatrimonialeController.class); public SituationMatrimonialeController(SituationMatrimonialeService situationMatrimonialeService) { this.situationMatrimonialeService = situationMatrimonialeService; } @PostMapping("/create") - public ResponseEntity createSituationMatrimoniale(@RequestBody @Valid @Validated SituationMatrimoniale situationMatrimoniale) { - try{ + public ResponseEntity createSituationMatrimoniale(@RequestBody @Valid @Validated SituationMatrimoniale situationMatrimoniale) { + try { situationMatrimoniale = situationMatrimonialeService.createSituationMatrimoniale(situationMatrimoniale); return new ResponseEntity<>( new ApiResponse<>(true, situationMatrimoniale, "Situation matrimoniale créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateSituationMatrimoniale(@PathVariable Long id, @RequestBody SituationMatrimoniale situationMatrimoniale) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, situationMatrimonialeService.updateSituationMatrimoniale(id, situationMatrimoniale), "Situation matrimoniale mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteSituationMatrimonialer(@PathVariable Long id) { - try{ + try { situationMatrimonialeService.deleteSituationMatrimoniale(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Situation matrimoniale supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Situation matrimoniale supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllSituationMatrimonialeList() { - return new ResponseEntity<>( - new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeList(), "Liste des situations matrimoniales chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeList(), "Liste des situations matrimoniales chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllSituationMatrimonialePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeList(pageable), "Liste des situations matrimoniales chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeList(pageable), "Liste des situations matrimoniales chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getSituationMatrimonialeById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeById(id), "Situation matrimoniale trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, situationMatrimonialeService.getSituationMatrimonialeById(id), "Situation matrimoniale trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SourceDroitController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SourceDroitController.java index bfd1437..7c76f1d 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SourceDroitController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/SourceDroitController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.SourceDroit; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.SourceDroitService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class SourceDroitController { private final SourceDroitService sourceDroitService; + private static final Logger logger = LoggerFactory.getLogger(SourceDroitController.class); public SourceDroitController(SourceDroitService sourceDroitService) { this.sourceDroitService = sourceDroitService; } @PostMapping("/create") - public ResponseEntity createSourceDroit(@RequestBody @Valid @Validated SourceDroit sourceDroit) { - try{ + public ResponseEntity createSourceDroit(@RequestBody @Valid @Validated SourceDroit sourceDroit) { + try { sourceDroit = sourceDroitService.createSourceDroit(sourceDroit); return new ResponseEntity<>( new ApiResponse<>(true, sourceDroit, "Source de droit créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateSourceDroit(@PathVariable Long id, @RequestBody SourceDroit sourceDroit) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, sourceDroitService.updateSourceDroit(id, sourceDroit), "Source de droit mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteSourceDroitr(@PathVariable Long id) { - try{ + try { sourceDroitService.deleteSourceDroit(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Source de droit supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Source de droit supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllSourceDroitList() { - return new ResponseEntity<>( - new ApiResponse<>(true, sourceDroitService.getSourceDroitList(), "Liste des sources de droit chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, sourceDroitService.getSourceDroitList(), "Liste des sources de droit chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllSourceDroitPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, sourceDroitService.getSourceDroitList(pageable), "Liste des sources de droit chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, sourceDroitService.getSourceDroitList(pageable), "Liste des sources de droit chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getSourceDroitById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, sourceDroitService.getSourceDroitById(id), "Source de droit trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, sourceDroitService.getSourceDroitById(id), "Source de droit trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/StructureController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/StructureController.java index c139589..59f436d 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/StructureController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/StructureController.java @@ -2,12 +2,15 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.ArrondissementService; import io.gmss.fiscad.interfaces.infocad.parametre.StructureService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -15,6 +18,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -26,6 +30,7 @@ public class StructureController { private final StructureService structureService; private final ArrondissementService arrondissementService; + private static final Logger logger = LoggerFactory.getLogger(StructureController.class); public StructureController(StructureService structureService, ArrondissementService arrondissementService) { this.structureService = structureService; @@ -33,91 +38,175 @@ public class StructureController { } @PostMapping("/create") - public ResponseEntity createStructure(@RequestBody @Valid @Validated Structure structure) { - try{ + public ResponseEntity createStructure(@RequestBody @Valid @Validated Structure structure) { + try { structure = structureService.createStructure(structure); return new ResponseEntity<>( new ApiResponse<>(true, structure, "Structure créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateStructure(@PathVariable Long id, @RequestBody Structure structure) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, structureService.updateStructure(id, structure), "Structure mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteStructurer(@PathVariable Long id) { - try{ + try { structureService.deleteStructure(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Structure supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Structure supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllStructureList() { - return new ResponseEntity<>( - new ApiResponse<>(true, structureService.getStructureList(), "Liste des structures chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, structureService.getStructureList(), "Liste des structures chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-by-arrondissement") public ResponseEntity getAllStructureListByArrondissement(@RequestParam Long arrondissementId) { - - if(arrondissementService.getArrondissementById(arrondissementId).isPresent()){ - return new ResponseEntity<>( - new ApiResponse<>(true, structureService.getStructuresByArrondissement(arrondissementId), "Liste des structures chargée avec succès."), - HttpStatus.OK - ); - }else{ - return new ResponseEntity<>( - new ApiResponse<>(false,"Impossible de trouver l'arrondissement spécifiée."), - HttpStatus.OK - ); + try { + if (arrondissementService.getArrondissementById(arrondissementId).isPresent()) { + return new ResponseEntity<>( + new ApiResponse<>(true, structureService.getStructuresByArrondissement(arrondissementId), "Liste des structures chargée avec succès."), + HttpStatus.OK + ); + } else { + return new ResponseEntity<>( + new ApiResponse<>(false, "Impossible de trouver l'arrondissement spécifiée."), + HttpStatus.OK + ); + } + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all-paged") public ResponseEntity getAllStructurePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, structureService.getStructureList(pageable), "Liste des structures chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, structureService.getStructureList(pageable), "Liste des structures chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } @GetMapping("/id/{id}") public ResponseEntity getStructureById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, structureService.getStructureById(id), "Structure trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, structureService.getStructureById(id), "Structure trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeContestationController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeContestationController.java index 5c86085..1f571c8 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeContestationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeContestationController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.TypeContestation; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.TypeContestationService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class TypeContestationController { private final TypeContestationService typeContestationService; + private static final Logger logger = LoggerFactory.getLogger(TypeContestationController.class); public TypeContestationController(TypeContestationService typeContestationService) { this.typeContestationService = typeContestationService; } @PostMapping("/create") - public ResponseEntity createTypeContestation(@RequestBody @Valid @Validated TypeContestation typeContestation) { - try{ + public ResponseEntity createTypeContestation(@RequestBody @Valid @Validated TypeContestation typeContestation) { + try { typeContestation = typeContestationService.createTypeContestation(typeContestation); return new ResponseEntity<>( new ApiResponse<>(true, typeContestation, "Type de contestation créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypeContestation(@PathVariable Long id, @RequestBody TypeContestation typeContestation) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typeContestationService.updateTypeContestation(id, typeContestation), "Type de contestation mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypeContestationr(@PathVariable Long id) { - try{ + try { typeContestationService.deleteTypeContestation(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type de contestation supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type de contestation supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypeContestationList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typeContestationService.getTypeContestationList(), "Liste des types de contestation chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeContestationService.getTypeContestationList(), "Liste des types de contestation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypeContestationPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typeContestationService.getTypeContestationList(pageable), "Liste des types de contestation chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, typeContestationService.getTypeContestationList(pageable), "Liste des types de contestation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypeContestationById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typeContestationService.getTypeContestationById(id), "Type de contestation trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeContestationService.getTypeContestationById(id), "Type de contestation trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeDomaineController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeDomaineController.java index 5cba3f3..de2d3ae 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeDomaineController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeDomaineController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.TypeDomaine; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.TypeDomaineService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class TypeDomaineController { private final TypeDomaineService typeDomaineService; + private static final Logger logger = LoggerFactory.getLogger(TypeDomaineController.class); public TypeDomaineController(TypeDomaineService typeDomaineService) { this.typeDomaineService = typeDomaineService; } @PostMapping("/create") - public ResponseEntity createTypeDomaine(@RequestBody @Valid @Validated TypeDomaine typeDomaine) { - try{ + public ResponseEntity createTypeDomaine(@RequestBody @Valid @Validated TypeDomaine typeDomaine) { + try { typeDomaine = typeDomaineService.createTypeDomaine(typeDomaine); return new ResponseEntity<>( new ApiResponse<>(true, typeDomaine, "Type de domaine créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypeDomaine(@PathVariable Long id, @RequestBody TypeDomaine typeDomaine) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typeDomaineService.updateTypeDomaine(id, typeDomaine), "Type de domaine mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypeDomainer(@PathVariable Long id) { - try{ + try { typeDomaineService.deleteTypeDomaine(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type de domaine supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type de domaine supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypeDomaineList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typeDomaineService.getTypeDomaineList(), "Liste des types de domaine chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeDomaineService.getTypeDomaineList(), "Liste des types de domaine chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypeDomainePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typeDomaineService.getTypeDomaineList(pageable), "Liste des types de domaine chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, typeDomaineService.getTypeDomaineList(pageable), "Liste des types de domaine chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypeDomaineById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typeDomaineService.getTypeDomaineById(id), "Type de domaine trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeDomaineService.getTypeDomaineById(id), "Type de domaine trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePersonneController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePersonneController.java index fd0b82f..2ca5ed9 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePersonneController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePersonneController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.TypePersonne; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.TypePersonneService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class TypePersonneController { private final TypePersonneService typePersonneService; + private static final Logger logger = LoggerFactory.getLogger(TypePersonneController.class); public TypePersonneController(TypePersonneService typePersonneService) { this.typePersonneService = typePersonneService; } @PostMapping("/create") - public ResponseEntity createTypePersonne(@RequestBody @Valid @Validated TypePersonne typePersonne) { - try{ + public ResponseEntity createTypePersonne(@RequestBody @Valid @Validated TypePersonne typePersonne) { + try { typePersonne = typePersonneService.createTypePersonne(typePersonne); return new ResponseEntity<>( new ApiResponse<>(true, typePersonne, "Type de personne créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypePersonne(@PathVariable Long id, @RequestBody TypePersonne typePersonne) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typePersonneService.updateTypePersonne(id, typePersonne), "Type de personne mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypePersonner(@PathVariable Long id) { - try{ + try { typePersonneService.deleteTypePersonne(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type de personne supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type de personne supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypePersonneList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typePersonneService.getTypePersonneList(), "Liste des types de personne chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typePersonneService.getTypePersonneList(), "Liste des types de personne chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypePersonnePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typePersonneService.getTypePersonneList(pageable), "Liste des types de personne chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, typePersonneService.getTypePersonneList(pageable), "Liste des types de personne chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypePersonneById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typePersonneService.getTypePersonneById(id), "Type de personne trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typePersonneService.getTypePersonneById(id), "Type de personne trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePieceController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePieceController.java index cc9310b..758a56f 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePieceController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypePieceController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.TypePiece; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.TypePieceService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class TypePieceController { private final TypePieceService typePieceService; + private static final Logger logger = LoggerFactory.getLogger(TypePieceController.class); public TypePieceController(TypePieceService typePieceService) { this.typePieceService = typePieceService; } @PostMapping("/create") - public ResponseEntity createTypePiece(@RequestBody @Valid @Validated TypePiece typePiece) { - try{ + public ResponseEntity createTypePiece(@RequestBody @Valid @Validated TypePiece typePiece) { + try { typePiece = typePieceService.createTypePiece(typePiece); return new ResponseEntity<>( new ApiResponse<>(true, typePiece, "Type de piece créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypePiece(@PathVariable Long id, @RequestBody TypePiece typePiece) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typePieceService.updateTypePiece(id, typePiece), "Type de piece mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypePiecer(@PathVariable Long id) { - try{ + try { typePieceService.deleteTypePiece(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type de piece supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type de piece supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypePieceList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typePieceService.getTypePieceList(), "Liste des types de piece chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typePieceService.getTypePieceList(), "Liste des types de piece chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypePiecePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typePieceService.getTypePieceList(pageable), "Liste des types de piece chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, typePieceService.getTypePieceList(pageable), "Liste des types de piece chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypePieceById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typePieceService.getTypePieceById(id), "Type de piece trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typePieceService.getTypePieceById(id), "Type de piece trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeRepresentationController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeRepresentationController.java index eff4fdd..10c6554 100644 --- a/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeRepresentationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/parametre/TypeRepresentationController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.infocad.parametre; import io.gmss.fiscad.entities.infocad.parametre.TypeRepresentation; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.TypeRepresentationService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class TypeRepresentationController { private final TypeRepresentationService typeRepresentationService; + private static final Logger logger = LoggerFactory.getLogger(TypeRepresentationController.class); public TypeRepresentationController(TypeRepresentationService typeRepresentationService) { this.typeRepresentationService = typeRepresentationService; } @PostMapping("/create") - public ResponseEntity createTypeRepresentation(@RequestBody @Valid @Validated TypeRepresentation typeRepresentation) { - try{ + public ResponseEntity createTypeRepresentation(@RequestBody @Valid @Validated TypeRepresentation typeRepresentation) { + try { typeRepresentation = typeRepresentationService.createTypeRepresentation(typeRepresentation); return new ResponseEntity<>( new ApiResponse<>(true, typeRepresentation, "Type de representation créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypeRepresentation(@PathVariable Long id, @RequestBody TypeRepresentation typeRepresentation) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typeRepresentationService.updateTypeRepresentation(id, typeRepresentation), "Type de representation mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypeRepresentationr(@PathVariable Long id) { - try{ + try { typeRepresentationService.deleteTypeRepresentation(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type de representation supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type de representation supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypeRepresentationList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationList(), "Liste des types de representation chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationList(), "Liste des types de representation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypeRepresentationPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationList(pageable), "Liste des types de representation chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationList(pageable), "Liste des types de representation chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypeRepresentationById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationById(id), "Type de representation trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeRepresentationService.getTypeRepresentationById(id), "Type de representation trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/notification/EmailController.java b/src/main/java/io/gmss/fiscad/controllers/notification/EmailController.java index 0cbb01c..d43fabb 100644 --- a/src/main/java/io/gmss/fiscad/controllers/notification/EmailController.java +++ b/src/main/java/io/gmss/fiscad/controllers/notification/EmailController.java @@ -4,6 +4,8 @@ import io.gmss.fiscad.interfaces.notification.EmailService; import io.gmss.fiscad.paylaods.EmailDetails; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -15,6 +17,7 @@ import org.springframework.web.bind.annotation.*; public class EmailController { private final EmailService emailService; + private static final Logger logger = LoggerFactory.getLogger(EmailController.class); public EmailController(EmailService emailService) { this.emailService = emailService; @@ -22,16 +25,14 @@ public class EmailController { // Sending a simple Email @PostMapping("/sendMail") - public String sendMail(@RequestBody EmailDetails details) - { + public String sendMail(@RequestBody EmailDetails details) { return emailService.sendSimpleMail(details); } // Sending email with attachment @PostMapping("/sendMailWithAttachment") public String sendMailWithAttachment( - @RequestBody EmailDetails details) - { + @RequestBody EmailDetails details) { String status = emailService.sendMailWithAttachment(details); diff --git a/src/main/java/io/gmss/fiscad/controllers/report/ReportingController.java b/src/main/java/io/gmss/fiscad/controllers/report/ReportingController.java index 73368cb..1bcfc3d 100644 --- a/src/main/java/io/gmss/fiscad/controllers/report/ReportingController.java +++ b/src/main/java/io/gmss/fiscad/controllers/report/ReportingController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.*; @CrossOrigin(origins = "*") public class ReportingController { private final ReportService reportService; + private final BlocRepository blocRepository; private final StructureRepository structureRepository; private static final Logger logger = LoggerFactory.getLogger(ReportingController.class); @@ -43,7 +44,7 @@ public class ReportingController { @GetMapping("/structure/blocs/{formatRapport}/{structureId}") public void imprimerBlocsParStructure(HttpServletResponse response, @PathVariable FormatRapport formatRapport, @PathVariable Long structureId) { try { - reportService.imprimerBlocsStructure(response,formatRapport,structureId); + reportService.imprimerBlocsStructure(response, formatRapport, structureId); } catch (Exception e) { e.printStackTrace(); } @@ -52,7 +53,7 @@ public class ReportingController { @GetMapping("/bloc/enquetes/{formatRapport}/{blocId}") public void imprimerEnqueteParBloc(HttpServletResponse response, @PathVariable FormatRapport formatRapport, @PathVariable Long blocId) { try { - reportService.imprimerEnqueteParBloc(response,formatRapport,blocId); + reportService.imprimerEnqueteParBloc(response, formatRapport, blocId); } catch (Exception e) { e.printStackTrace(); } @@ -61,7 +62,7 @@ public class ReportingController { @PostMapping("/filtre/enquetes/{formatRapport}") public void imprimerEnqueteParFiltre(HttpServletResponse response, @RequestBody FiltreEnquetePayLoad filtreEnquetePayLoad, @PathVariable FormatRapport formatRapport) { try { - reportService.imprimerEnqueteParFiltre(response,filtreEnquetePayLoad,formatRapport); + reportService.imprimerEnqueteParFiltre(response, filtreEnquetePayLoad, formatRapport); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java index fcab8ee..0de03a8 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.Batiment; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.BatimentService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -26,79 +29,150 @@ public class BatimentController { private final BatimentService batimentService; + private static final Logger logger = LoggerFactory.getLogger(BatimentController.class); + public BatimentController(BatimentService batimentService) { this.batimentService = batimentService; } @PostMapping("/create") - public ResponseEntity createBatiment(@RequestBody @Valid @Validated Batiment batiment) { - try{ + public ResponseEntity createBatiment(@RequestBody @Valid @Validated Batiment batiment) { + try { batiment = batimentService.createBatiment(batiment); return new ResponseEntity<>( new ApiResponse<>(true, batiment, "Batiment créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateBatiment(@PathVariable Long id, @RequestBody Batiment batiment) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, batimentService.updateBatiment(id, batiment), "Batiment mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteBatiment(@PathVariable Long id) { - try{ + try { batimentService.deleteBatiment(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Batiment supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Batiment supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllBatimentList() { - return new ResponseEntity<>( - new ApiResponse<>(true, batimentService.getBatimentList(), "Liste des caractéristiques chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, batimentService.getBatimentList(), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllBatimentPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, batimentService.getBatimentList(pageable), "Liste des caractéristiques chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, batimentService.getBatimentList(pageable), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getBatimentById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, batimentService.getBatimentById(id), "Batiment trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, batimentService.getBatimentById(id), "Batiment trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueBatimentController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueBatimentController.java index 0ffc26c..16900af 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueBatimentController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueBatimentController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueBatiment; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueBatimentService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class CaracteristiqueBatimentController { private final CaracteristiqueBatimentService caracteristiqueBatimentService; + private static final Logger logger = LoggerFactory.getLogger(CaracteristiqueBatimentController.class); public CaracteristiqueBatimentController(CaracteristiqueBatimentService caracteristiqueBatimentService) { this.caracteristiqueBatimentService = caracteristiqueBatimentService; } @PostMapping("/create") - public ResponseEntity createCaracteristiqueBatiment(@RequestBody @Valid @Validated CaracteristiqueBatiment caracteristiqueBatiment) { - try{ + public ResponseEntity createCaracteristiqueBatiment(@RequestBody @Valid @Validated CaracteristiqueBatiment caracteristiqueBatiment) { + try { caracteristiqueBatiment = caracteristiqueBatimentService.createCaracteristiqueBatiment(caracteristiqueBatiment); return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueBatiment, "Caracteristique du batiment créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCaracteristiqueBatiment(@PathVariable Long id, @RequestBody CaracteristiqueBatiment caracteristiqueBatiment) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueBatimentService.updateCaracteristiqueBatiment(id, caracteristiqueBatiment), "Caracteristique du batiment mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCaracteristiqueBatiment(@PathVariable Long id) { - try{ + try { caracteristiqueBatimentService.deleteCaracteristiqueBatiment(id); return new ResponseEntity<>( - new ApiResponse<>(true,"CaracteristiqueBatiment supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "CaracteristiqueBatiment supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCaracteristiqueBatimentList() { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentList(), "Liste des Caracteristiques du batiment chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentList(), "Liste des Caracteristiques du batiment chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllCaracteristiqueBatimentPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentList(pageable), "Liste des Caracteristiques du batiment chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentList(pageable), "Liste des Caracteristiques du batiment chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getCaracteristiqueBatimentById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentById(id), "Caracteristique du batiment trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueBatimentService.getCaracteristiqueBatimentById(id), "Caracteristique du batiment trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueParcelleController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueParcelleController.java index 8b1e146..8d88a7f 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueParcelleController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueParcelleController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueParcelle; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueParcelleService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class CaracteristiqueParcelleController { private final CaracteristiqueParcelleService caracteristiqueParcelleService; + private static final Logger logger = LoggerFactory.getLogger(CaracteristiqueParcelleController.class); public CaracteristiqueParcelleController(CaracteristiqueParcelleService caracteristiqueParcelleService) { this.caracteristiqueParcelleService = caracteristiqueParcelleService; } @PostMapping("/create") - public ResponseEntity createCaracteristiqueParcelle(@RequestBody @Valid @Validated CaracteristiqueParcelle caracteristiqueParcelle) { - try{ + public ResponseEntity createCaracteristiqueParcelle(@RequestBody @Valid @Validated CaracteristiqueParcelle caracteristiqueParcelle) { + try { caracteristiqueParcelle = caracteristiqueParcelleService.createCaracteristiqueParcelle(caracteristiqueParcelle); return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueParcelle, "Caracteristique parcelle créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCaracteristiqueParcelle(@PathVariable Long id, @RequestBody CaracteristiqueParcelle caracteristiqueParcelle) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueParcelleService.updateCaracteristiqueParcelle(id, caracteristiqueParcelle), "Caracteristique parcelle mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCaracteristiqueParcelle(@PathVariable Long id) { - try{ + try { caracteristiqueParcelleService.deleteCaracteristiqueParcelle(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Caracteristique parcelle supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Caracteristique parcelle supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCaracteristiqueParcelleList() { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleList(), "Liste des Caracteristiques parcelles chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleList(), "Liste des Caracteristiques parcelles chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllCaracteristiqueParcellePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleList(pageable), "Liste des Caracteristiques parcelles chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleList(pageable), "Liste des Caracteristiques parcelles chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getCaracteristiqueParcelleById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleById(id), "Caracteristiques parcelles trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueParcelleService.getCaracteristiqueParcelleById(id), "Caracteristiques parcelles trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueUniteLogementController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueUniteLogementController.java index 0580044..e167708 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueUniteLogementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CaracteristiqueUniteLogementController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueUniteLogement; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueUniteLogementService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,150 @@ import org.springframework.web.bind.annotation.*; public class CaracteristiqueUniteLogementController { private final CaracteristiqueUniteLogementService caracteristiqueUniteLogementService; + private static final Logger logger = LoggerFactory.getLogger(CaracteristiqueUniteLogementController.class); public CaracteristiqueUniteLogementController(CaracteristiqueUniteLogementService caracteristiqueUniteLogementService) { this.caracteristiqueUniteLogementService = caracteristiqueUniteLogementService; } @PostMapping("/create") - public ResponseEntity createCaracteristiqueUniteLogement(@RequestBody @Valid @Validated CaracteristiqueUniteLogement caracteristiqueUniteLogement) { - try{ + public ResponseEntity createCaracteristiqueUniteLogement(@RequestBody @Valid @Validated CaracteristiqueUniteLogement caracteristiqueUniteLogement) { + try { caracteristiqueUniteLogement = caracteristiqueUniteLogementService.createCaracteristiqueUniteLogement(caracteristiqueUniteLogement); return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueUniteLogement, "Caracteristique Unite Logement créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCaracteristiqueUniteLogement(@PathVariable Long id, @RequestBody CaracteristiqueUniteLogement caracteristiqueUniteLogement) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueUniteLogementService.updateCaracteristiqueUniteLogement(id, caracteristiqueUniteLogement), "Caracteristique Unite Logement mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCaracteristiqueUniteLogement(@PathVariable Long id) { - try{ + try { caracteristiqueUniteLogementService.deleteCaracteristiqueUniteLogement(id); return new ResponseEntity<>( - new ApiResponse<>(true,"CaracteristiqueUniteLogement supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "CaracteristiqueUniteLogement supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCaracteristiqueUniteLogementList() { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementList(), "Liste des Caracteristiques Unite Logement chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementList(), "Liste des Caracteristiques Unite Logement chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllCaracteristiqueUniteLogementPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementList(pageable), "Liste des Caracteristiques Unite Logement chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementList(pageable), "Liste des Caracteristiques Unite Logement chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getCaracteristiqueUniteLogementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementById(id), "Caracteristique Unite Logement trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueUniteLogementService.getCaracteristiqueUniteLogementById(id), "Caracteristique Unite Logement trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteBatimentController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteBatimentController.java index 6f29dea..b971084 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteBatimentController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteBatimentController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.EnqueteBatimentService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,151 @@ import org.springframework.web.bind.annotation.*; public class EnqueteBatimentController { private final EnqueteBatimentService enqueteBatimentService; + private static final Logger logger = LoggerFactory.getLogger(EnqueteBatimentController.class); public EnqueteBatimentController(EnqueteBatimentService enqueteBatimentService) { this.enqueteBatimentService = enqueteBatimentService; } @PostMapping("/create") - public ResponseEntity createEnqueteBatiment(@RequestBody @Valid @Validated EnqueteBatiment enqueteBatiment) { - try{ + public ResponseEntity createEnqueteBatiment(@RequestBody @Valid @Validated EnqueteBatiment enqueteBatiment) { + try { enqueteBatiment = enqueteBatimentService.createEnqueteBatiment(enqueteBatiment); return new ResponseEntity<>( new ApiResponse<>(true, enqueteBatiment, "Enquete batiment créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateEnqueteBatiment(@PathVariable Long id, @RequestBody EnqueteBatiment enqueteBatiment) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteBatimentService.updateEnqueteBatiment(id, enqueteBatiment), "Enquete batiment mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteEnqueteBatiment(@PathVariable Long id) { - try{ + try { enqueteBatimentService.deleteEnqueteBatiment(id); return new ResponseEntity<>( - new ApiResponse<>(true,"EnqueteBatiment supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "EnqueteBatiment supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllEnqueteBatimentList() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentList(), "Liste des Enquetes batiments chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentList(), "Liste des Enquetes batiments chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllEnqueteBatimentPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentList(pageable), "Liste des Enquetes batiments chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentList(pageable), "Liste des Enquetes batiments chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getEnqueteBatimentById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentById(id), "Enquete batiment trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentById(id), "Enquete batiment trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteUniteLogementController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteUniteLogementController.java index b1abb8a..c347d2f 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteUniteLogementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/EnqueteUniteLogementController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.EnqueteUniteLogement; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.EnqueteUniteLogementService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,151 @@ import org.springframework.web.bind.annotation.*; public class EnqueteUniteLogementController { private final EnqueteUniteLogementService enqueteUniteLogementService; + private static final Logger logger = LoggerFactory.getLogger(EnqueteUniteLogementController.class); public EnqueteUniteLogementController(EnqueteUniteLogementService enqueteUniteLogementService) { this.enqueteUniteLogementService = enqueteUniteLogementService; } @PostMapping("/create") - public ResponseEntity createEnqueteUniteLogement(@RequestBody @Valid @Validated EnqueteUniteLogement enqueteUniteLogement) { - try{ + public ResponseEntity createEnqueteUniteLogement(@RequestBody @Valid @Validated EnqueteUniteLogement enqueteUniteLogement) { + try { enqueteUniteLogement = enqueteUniteLogementService.createEnqueteUniteLogement(enqueteUniteLogement); return new ResponseEntity<>( new ApiResponse<>(true, enqueteUniteLogement, "Enquete unite logement créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateEnqueteUniteLogement(@PathVariable Long id, @RequestBody EnqueteUniteLogement enqueteUniteLogement) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteUniteLogementService.updateEnqueteUniteLogement(id, enqueteUniteLogement), "Enquete unite logement mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteEnqueteUniteLogement(@PathVariable Long id) { - try{ + try { enqueteUniteLogementService.deleteEnqueteUniteLogement(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Enquete Unite Logement supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Enquete Unite Logement supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllEnqueteUniteLogementList() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementList(), "Liste des Enquetes des unites Logements chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementList(), "Liste des Enquetes des unites Logements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllEnqueteUniteLogementPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementList(pageable), "Liste des enquetes des unites de logements chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementList(pageable), "Liste des enquetes des unites de logements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getEnqueteUniteLogementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementById(id), "Enquete unite de logement trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementById(id), "Enquete unite de logement trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/UniteLogementController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/UniteLogementController.java index 9ee2121..0ff72fc 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/UniteLogementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/UniteLogementController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.UniteLogement; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.metier.UniteLogementService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,80 +28,151 @@ import org.springframework.web.bind.annotation.*; public class UniteLogementController { private final UniteLogementService enqueteUniteLogementService; + private static final Logger logger = LoggerFactory.getLogger(UniteLogementController.class); public UniteLogementController(UniteLogementService enqueteUniteLogementService) { this.enqueteUniteLogementService = enqueteUniteLogementService; } @PostMapping("/create") - public ResponseEntity createUniteLogement(@RequestBody @Valid @Validated UniteLogement enqueteUniteLogement) { - try{ + public ResponseEntity createUniteLogement(@RequestBody @Valid @Validated UniteLogement enqueteUniteLogement) { + try { enqueteUniteLogement = enqueteUniteLogementService.createUniteLogement(enqueteUniteLogement); return new ResponseEntity<>( new ApiResponse<>(true, enqueteUniteLogement, "Unite de logement créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateUniteLogement(@PathVariable Long id, @RequestBody UniteLogement enqueteUniteLogement) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, enqueteUniteLogementService.updateUniteLogement(id, enqueteUniteLogement), "Unite de logement mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteUniteLogement(@PathVariable Long id) { - try{ + try { enqueteUniteLogementService.deleteUniteLogement(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Unite Logement supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Unite Logement supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllUniteLogementList() { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementList(), "Liste des Enquetes des unites Logements chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementList(), "Liste des Enquetes des unites Logements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllUniteLogementPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementList(pageable), "Liste des enquetes des unites de logements chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementList(pageable), "Liste des enquetes des unites de logements chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getUniteLogementById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementById(id), "Unite de de logement trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementById(id), "Unite de de logement trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CampagneController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CampagneController.java index 4dd7912..6d719e9 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CampagneController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CampagneController.java @@ -2,12 +2,14 @@ package io.gmss.fiscad.controllers.rfu.parametre; import io.gmss.fiscad.entities.rfu.parametre.Campagne; import io.gmss.fiscad.enums.TypeCampagne; -import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.parametre.CampagneService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -15,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*; public class CampagneController { private final CampagneService campagneService; + private static final Logger logger = LoggerFactory.getLogger(CampagneController.class); public CampagneController(CampagneService campagneService) { this.campagneService = campagneService; @@ -32,90 +35,168 @@ public class CampagneController { @PostMapping("/create") - public ResponseEntity createCampagne(@RequestBody @Valid @Validated Campagne campagne) { - try{ + public ResponseEntity createCampagne(@RequestBody @Valid @Validated Campagne campagne) { + try { campagne = campagneService.createCampagne(campagne); return new ResponseEntity<>( new ApiResponse<>(true, campagne, "Campagne créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCampagne(@PathVariable Long id, @RequestBody Campagne campagne) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, campagneService.updateCampagne(id, campagne), "Campagne mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCampagner(@PathVariable Long id) { - try{ + try { campagneService.deleteCampagne(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Campagne supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Campagne supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCampagneList() { - return new ResponseEntity<>( - new ApiResponse<>(true, campagneService.getCampagneList(), "Liste des campagnes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, campagneService.getCampagneList(), "Liste des campagnes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllCampagnePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, campagneService.getCampagneList(pageable), "Liste des campagnes chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, campagneService.getCampagneList(pageable), "Liste des campagnes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getCampagneById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, campagneService.getCampagneById(id), "Campagne trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, campagneService.getCampagneById(id), "Campagne trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/type-campagne/{typeCampagne}") public ResponseEntity getCampagneByType(@PathVariable TypeCampagne typeCampagne) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, campagneService.getCampagnesByType(typeCampagne), "Liste des campagne par type chargée avec succès."), HttpStatus.OK ); - }catch (NotFoundException e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CaracteristiqueController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CaracteristiqueController.java index 958b19b..dad243b 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CaracteristiqueController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/CaracteristiqueController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.parametre; import io.gmss.fiscad.entities.rfu.parametre.Caracteristique; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.parametre.CaracteristiqueService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,80 +27,152 @@ import org.springframework.web.bind.annotation.*; public class CaracteristiqueController { private final CaracteristiqueService caracteristiqueService; + private static final Logger logger = LoggerFactory.getLogger(CaracteristiqueController.class); public CaracteristiqueController(CaracteristiqueService caracteristiqueService) { this.caracteristiqueService = caracteristiqueService; } @PostMapping("/create") - public ResponseEntity createCaracteristique(@RequestBody @Valid @Validated Caracteristique caracteristique) { - try{ + public ResponseEntity createCaracteristique(@RequestBody @Valid @Validated Caracteristique caracteristique) { + try { caracteristique = caracteristiqueService.createCaracteristique(caracteristique); return new ResponseEntity<>( new ApiResponse<>(true, caracteristique, "Caracteristique créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateCaracteristique(@PathVariable Long id, @RequestBody Caracteristique caracteristique) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, caracteristiqueService.updateCaracteristique(id, caracteristique), "Caracteristique mise à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteCaracteristique(@PathVariable Long id) { - try{ + try { caracteristiqueService.deleteCaracteristique(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Caracteristique supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Caracteristique supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllCaracteristiqueList() { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueList(), "Liste des caractéristiques chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueList(), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllCaracteristiquePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueList(pageable), "Liste des caractéristiques chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueList(pageable), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getCaracteristiqueById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueById(id), "Caracteristique trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, caracteristiqueService.getCaracteristiqueById(id), "Caracteristique trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/EquipeController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/EquipeController.java index beb8dfa..19b941a 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/EquipeController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/EquipeController.java @@ -1,12 +1,15 @@ package io.gmss.fiscad.controllers.rfu.parametre; import io.gmss.fiscad.entities.rfu.parametre.Equipe; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.parametre.EquipeService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.request.EquipePayload; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,7 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,6 +27,7 @@ import org.springframework.web.bind.annotation.*; public class EquipeController { private final EquipeService equipeService; + private static final Logger logger = LoggerFactory.getLogger(EquipeController.class); public EquipeController(EquipeService equipeService) { this.equipeService = equipeService; @@ -31,75 +35,145 @@ public class EquipeController { @PostMapping("/create") - public ResponseEntity createEquipe(@RequestBody @Valid @Validated EquipePayload equipePayload) { - try{ + public ResponseEntity createEquipe(@RequestBody @Valid @Validated EquipePayload equipePayload) { + try { Equipe equipe = equipeService.createEquipe(equipePayload); return new ResponseEntity<>( new ApiResponse<>(true, equipe, "Equipe créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateEquipe(@PathVariable Long id, @RequestBody EquipePayload equipePayload) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, equipeService.updateEquipe(id, equipePayload), "Equipe mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteEquiper(@PathVariable Long id) { - try{ + try { equipeService.deleteEquipe(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Equipe supprimée avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Equipe supprimée avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllEquipeList() { - return new ResponseEntity<>( - new ApiResponse<>(true, equipeService.getEquipeList(), "Liste des equipes chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, equipeService.getEquipeList(), "Liste des equipes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllEquipePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, equipeService.getEquipeList(pageable), "Liste des equipes chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, equipeService.getEquipeList(pageable), "Liste des equipes chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getEquipeById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, equipeService.getEquipeById(id), "Equipe trouvée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, equipeService.getEquipeById(id), "Equipe trouvée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/TypeCaracteristiqueController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/TypeCaracteristiqueController.java index 56e0df8..75c1150 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/TypeCaracteristiqueController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/parametre/TypeCaracteristiqueController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.rfu.parametre; import io.gmss.fiscad.entities.rfu.parametre.TypeCaracteristique; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.rfu.parametre.TypeCaracteristiqueService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -23,80 +27,151 @@ import org.springframework.web.bind.annotation.*; public class TypeCaracteristiqueController { private final TypeCaracteristiqueService typeCaracteristiqueService; + private static final Logger logger = LoggerFactory.getLogger(TypeCaracteristiqueController.class); public TypeCaracteristiqueController(TypeCaracteristiqueService typeCaracteristiqueService) { this.typeCaracteristiqueService = typeCaracteristiqueService; } @PostMapping("/create") - public ResponseEntity createTypeCaracteristique(@RequestBody @Valid @Validated TypeCaracteristique typeCaracteristique) { - try{ + public ResponseEntity createTypeCaracteristique(@RequestBody @Valid @Validated TypeCaracteristique typeCaracteristique) { + try { typeCaracteristique = typeCaracteristiqueService.createTypeCaracteristique(typeCaracteristique); return new ResponseEntity<>( new ApiResponse<>(true, typeCaracteristique, "Type de caracteristique créé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateTypeCaracteristique(@PathVariable Long id, @RequestBody TypeCaracteristique typeCaracteristique) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, typeCaracteristiqueService.updateTypeCaracteristique(id, typeCaracteristique), "Type caracteristique mis à jour avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteTypeCaracteristique(@PathVariable Long id) { - try{ + try { typeCaracteristiqueService.deleteTypeCaracteristique(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Type caracteristique supprimé avec succès."), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Type caracteristique supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAllTypeCaracteristiqueList() { - return new ResponseEntity<>( - new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueList(), "Liste des types caracteristiques chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueList(), "Liste des types caracteristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllTypeCaracteristiquePaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueList(pageable), "Liste des types caracteristiques chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueList(pageable), "Liste des types caracteristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getTypeCaracteristiqueById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueById(id), "Type caracteristique trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, typeCaracteristiqueService.getTypeCaracteristiqueById(id), "Type caracteristique trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/statistique/StatistiqueController.java b/src/main/java/io/gmss/fiscad/controllers/statistique/StatistiqueController.java index eb4eb2c..0390619 100644 --- a/src/main/java/io/gmss/fiscad/controllers/statistique/StatistiqueController.java +++ b/src/main/java/io/gmss/fiscad/controllers/statistique/StatistiqueController.java @@ -1,13 +1,17 @@ package io.gmss.fiscad.controllers.statistique; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.statistique.StatistiquesService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @RequestMapping(value = "api/statistique", produces = MediaType.APPLICATION_JSON_VALUE) @@ -15,40 +19,103 @@ import org.springframework.web.bind.annotation.*; @Tag(name = "Statistique") @CrossOrigin(origins = "*") public class StatistiqueController { - private final StatistiquesService statistiquesService ; + private final StatistiquesService statistiquesService; + + private static final Logger logger = LoggerFactory.getLogger(StatistiqueController.class); public StatistiqueController(StatistiquesService statistiquesService) { this.statistiquesService = statistiquesService; } + @GetMapping(path = "/user/enquete-par-statut") public ResponseEntity getStatistiquesParStatut() { - return new ResponseEntity<>( - new ApiResponse<>(true, statistiquesService.getStatEnqueteParStatut(), "Statistique des enquêtes par statut."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, statistiquesService.getStatEnqueteParStatut(), "Statistique des enquêtes par statut."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/enquete-par-arrondissement/{commune_id}") public ResponseEntity getStatistiquesParArrondissement(@PathVariable Long commune_id) { - return new ResponseEntity<>( - new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminDecoupage(commune_id), "Statistique des enquêtes par arrondissement."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminDecoupage(commune_id), "Statistique des enquêtes par arrondissement."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/user/enquete-par-structure") public ResponseEntity getStatistiquesParStructure() { - return new ResponseEntity<>( - new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminStructure(), "Statistique des enquêtes par structure."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminStructure(), "Statistique des enquêtes par structure."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/user/enquete-par-bloc") public ResponseEntity getStatistiquesParBloc() { - return new ResponseEntity<>( - new ApiResponse<>(true, statistiquesService.getStatBloc(), "Statistique des enquêtes par bloc."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, statistiquesService.getStatBloc(), "Statistique des enquêtes par bloc."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/controllers/synchronisation/RestaurationController.java b/src/main/java/io/gmss/fiscad/controllers/synchronisation/RestaurationController.java index 9b4ed6e..270662d 100644 --- a/src/main/java/io/gmss/fiscad/controllers/synchronisation/RestaurationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/synchronisation/RestaurationController.java @@ -1,13 +1,17 @@ package io.gmss.fiscad.controllers.synchronisation; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.synchronisation.RestaurationService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @RequestMapping(value = "api/restauration", produces = MediaType.APPLICATION_JSON_VALUE) @@ -17,107 +21,289 @@ import org.springframework.web.bind.annotation.*; public class RestaurationController { public final RestaurationService restaurationService; + private static final Logger logger = LoggerFactory.getLogger(RestaurationController.class); + public RestaurationController(RestaurationService restaurationService) { this.restaurationService = restaurationService; } @GetMapping(path = "/enquete/{terminalId}") public ResponseEntity getEnquetes(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getEnquete(terminalId), "liste des enquetes avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getEnquete(terminalId), "liste des enquetes avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/acteur-concerne/{terminalId}") public ResponseEntity getActeurConcerne(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getActeurConcernes(terminalId), "liste des acteurs concernés avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getActeurConcernes(terminalId), "liste des acteurs concernés avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/personne/{terminalId}") // ok public ResponseEntity getPersonnes(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getPersonne(terminalId), "liste des personnes avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getPersonne(terminalId), "liste des personnes avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/membre-groupe/{terminalId}") public ResponseEntity getMembrePersonnes(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getMembreGroupe(terminalId), "liste des membres groupe avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getMembreGroupe(terminalId), "liste des membres groupe avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/parcelle/{terminalId}") public ResponseEntity getParcelle(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getParcelle(terminalId), "liste des parcelle avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getParcelle(terminalId), "liste des parcelle avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/piece/{terminalId}") public ResponseEntity getPieces(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getPieces(terminalId), "liste des enquetes avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getPieces(terminalId), "liste des enquetes avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/upload/{terminalId}") public ResponseEntity getUpload(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getUpload(terminalId), "liste des enquetes avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getUpload(terminalId), "liste des enquetes avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/current-user-tpes") public ResponseEntity getCurrentUserTpe() { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getTpeListByCurrentUser(), "liste des enquetes avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getTpeListByCurrentUser(), "liste des enquetes avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/batiment/{terminalId}") public ResponseEntity getBatiments(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getBatiment(terminalId), "liste des batiments avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getBatiment(terminalId), "liste des batiments avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/enquete-batiment/{terminalId}") public ResponseEntity getEnqueteBatiment(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getEnqueteBatiment(terminalId), "liste des enquetes batiments avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getEnqueteBatiment(terminalId), "liste des enquetes batiments avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/caracteristique-batiment/{terminalId}") public ResponseEntity getCaracteristiqueBatiment(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getCaracateristiqueBatiment(terminalId), "liste des caractéristiques batiments avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getCaracateristiqueBatiment(terminalId), "liste des caractéristiques batiments avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping(path = "/caracteristique-unite-logement/{terminalId}") public ResponseEntity getCaracteristiqueUniteLogement(@PathVariable Long terminalId) { - return new ResponseEntity<>( - new ApiResponse<>(true, restaurationService.getCaracateristiqueUniteLogement(terminalId), "liste des caractéristiques des unités de logement avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, restaurationService.getCaracateristiqueUniteLogement(terminalId), "liste des caractéristiques des unités de logement avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } diff --git a/src/main/java/io/gmss/fiscad/controllers/synchronisation/SynchronisationController.java b/src/main/java/io/gmss/fiscad/controllers/synchronisation/SynchronisationController.java index d642ec1..ebe60f4 100644 --- a/src/main/java/io/gmss/fiscad/controllers/synchronisation/SynchronisationController.java +++ b/src/main/java/io/gmss/fiscad/controllers/synchronisation/SynchronisationController.java @@ -1,14 +1,18 @@ package io.gmss.fiscad.controllers.synchronisation; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.synchronisation.SynchronisationService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.request.*; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -20,6 +24,7 @@ import java.util.List; @CrossOrigin(origins = "*") public class SynchronisationController { private final SynchronisationService synchronisationService; + private static final Logger logger = LoggerFactory.getLogger(SynchronisationController.class); public SynchronisationController(SynchronisationService synchronisationService) { this.synchronisationService = synchronisationService; @@ -27,111 +32,281 @@ public class SynchronisationController { @GetMapping("/user-decoupage-territorial") public ResponseEntity getUserDecoupageTerritorial() { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.getDecoupageAdminUserConnecter(), "Liste des découpages territoriaux chargés avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.getDecoupageAdminUserConnecter(), "Liste des découpages territoriaux chargés avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/references") public ResponseEntity getAllReferences() { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.getReferencesSyncResponses(), "Liste des données de référence chargée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.getReferencesSyncResponses(), "Liste des données de référence chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/personnes") public ResponseEntity syncPersonne(@RequestBody List personnePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncPersonnes(personnePayLoads), "Liste des personnes synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncPersonnes(personnePayLoads), "Liste des personnes synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } + @PostMapping("/membre-groupe") public ResponseEntity syncMembreGroupe(@RequestBody List membreGroupePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncMembreGroupe(membreGroupePayLoads), "Liste des membres de groupes de personnes synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncMembreGroupe(membreGroupePayLoads), "Liste des membres de groupes de personnes synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } + @PostMapping("/enquete") public ResponseEntity syncEnquete(@RequestBody List enquetePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncEnquete(enquetePayLoads), "Liste des enquêtes synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncEnquete(enquetePayLoads), "Liste des enquêtes synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } + @PostMapping("/parcelle") public ResponseEntity syncParcelle(@RequestBody List parcellePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncParcelle(parcellePayLoads), "Liste des parceclles synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncParcelle(parcellePayLoads), "Liste des parceclles synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } + @PostMapping("/piece") public ResponseEntity syncPiece(@RequestBody List piecePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncPiece(piecePayLoads), "Liste des pièces synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncPiece(piecePayLoads), "Liste des pièces synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } + @PostMapping("/acteur-concerne") public ResponseEntity syncActeurConcerne(@RequestBody List piecePayLoads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncActeurConcerne(piecePayLoads), "Liste des acteurs concernes synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncActeurConcerne(piecePayLoads), "Liste des acteurs concernes synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } //@PostMapping("/files") @PostMapping(path = "/files") public ResponseEntity syncFiles(@RequestPart(required = true) MultipartFile file, - @RequestParam(required=false) Long idBackend, + @RequestParam(required = false) Long idBackend, @RequestParam Long externalKey, - @RequestParam(required=false) Long pieceId, - @RequestParam(required=false) Long membreGroupeId, - @RequestParam(required=false) Long terminalId, - @RequestParam(required=false) String name, - @RequestParam(required=false) String filePath, - @RequestParam(required=false) Long max_numero_piece_id, - @RequestParam(required=false) Long max_numero_upload_id, - @RequestParam(required=false) Long max_numero_acteur_concerne_id, - @RequestParam(required=false) Long enqueteId, - @RequestParam(required=false) Long enqueteBatimentId, - @RequestParam(required=false) Long enqueteUniteLogementId + @RequestParam(required = false) Long pieceId, + @RequestParam(required = false) Long membreGroupeId, + @RequestParam(required = false) Long terminalId, + @RequestParam(required = false) String name, + @RequestParam(required = false) String filePath, + @RequestParam(required = false) Long max_numero_piece_id, + @RequestParam(required = false) Long max_numero_upload_id, + @RequestParam(required = false) Long max_numero_acteur_concerne_id, + @RequestParam(required = false) Long enqueteId, + @RequestParam(required = false) Long enqueteBatimentId, + @RequestParam(required = false) Long enqueteUniteLogementId ) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncFiles(file, - idBackend, - externalKey, - pieceId, - membreGroupeId, - terminalId, - name, - filePath, - max_numero_piece_id, - max_numero_upload_id, - max_numero_acteur_concerne_id, - enqueteId, enqueteBatimentId, enqueteUniteLogementId), "Liste des fichiers synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncFiles(file, + idBackend, + externalKey, + pieceId, + membreGroupeId, + terminalId, + name, + filePath, + max_numero_piece_id, + max_numero_upload_id, + max_numero_acteur_concerne_id, + enqueteId, enqueteBatimentId, enqueteUniteLogementId), "Liste des fichiers synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/synchronise/all-enquete-data") public ResponseEntity syncAllEnqueteData(@ModelAttribute EnqueteAllDataPayload enqueteAllDataPayload) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncEnqueteAllData(enqueteAllDataPayload), "Les enquetes sont synchronisées avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncEnqueteAllData(enqueteAllDataPayload), "Les enquetes sont synchronisées avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/synchronise/enquete/confirme-from-mobile") public ResponseEntity syncAllEnqueteData(@RequestBody List batimentPaylaods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncBatiment(batimentPaylaods), "Synchronisation confirmée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncBatiment(batimentPaylaods), "Synchronisation confirmée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @@ -143,58 +318,163 @@ public class SynchronisationController { @PostMapping(path = "/batiment") public ResponseEntity syncBatiment(@RequestBody List batimentPaylaods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncBatiment(batimentPaylaods), "Liste des batiments synchronisées avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncBatiment(batimentPaylaods), "Liste des batiments synchronisées avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/unite-logement") public ResponseEntity syncUniteLogement(@RequestBody List uniteLogementPaylaods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncUniteLogement(uniteLogementPaylaods), "Liste des unités de logement synchronisées avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncUniteLogement(uniteLogementPaylaods), "Liste des unités de logement synchronisées avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/caracteristique-batiment") public ResponseEntity syncCaracteristiqueBatiment(@RequestBody List caracteristiqueBatimentPaylods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncCaracteristiqueBatiment(caracteristiqueBatimentPaylods), "Liste des caractéristiques des bâtiments synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncCaracteristiqueBatiment(caracteristiqueBatimentPaylods), "Liste des caractéristiques des bâtiments synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/caracteristique-parcelle") public ResponseEntity syncCaracteristiqueParcelle(@RequestBody List caracteristiqueParcellePaylods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncCaracteristiqueParcelle(caracteristiqueParcellePaylods), "Liste des caractéristiques des parcelles synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncCaracteristiqueParcelle(caracteristiqueParcellePaylods), "Liste des caractéristiques des parcelles synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping(path = "/caracteristique-unite-logement") public ResponseEntity syncCaracteristiqueUniteLogement(@RequestBody List caracteristiqueUniteLogementPaylods) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncCaracteristiqueUniteLogement(caracteristiqueUniteLogementPaylods), "Liste des caractéristiques des unités de logement synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncCaracteristiqueUniteLogement(caracteristiqueUniteLogementPaylods), "Liste des caractéristiques des unités de logement synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/enquete-batiment") public ResponseEntity syncEnqueteBatiment(@RequestBody List enqueteBatimentPayloads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncEnqueteBatiment(enqueteBatimentPayloads), "Liste des enquêtes des batiments synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncEnqueteBatiment(enqueteBatimentPayloads), "Liste des enquêtes des batiments synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @PostMapping("/enquete-unite-logement") public ResponseEntity syncEnqueteUniteLogement(@RequestBody List enqueteUniteLogementPayloads) { - return new ResponseEntity<>( - new ApiResponse<>(true, synchronisationService.syncEnqueteUniteLogement(enqueteUniteLogementPayloads), "Liste des enquêtes des unités de logement synchronisée avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, synchronisationService.syncEnqueteUniteLogement(enqueteUniteLogementPayloads), "Liste des enquêtes des unités de logement synchronisée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java b/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java index 754bddf..72220e6 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.controllers.user; import io.gmss.fiscad.entities.user.Role; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.UserRole; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.infocad.parametre.StructureService; import io.gmss.fiscad.interfaces.user.RoleService; import io.gmss.fiscad.interfaces.user.UserService; @@ -13,11 +14,14 @@ import io.gmss.fiscad.paylaods.UserRequest; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; import java.util.HashSet; import java.util.Set; @@ -32,6 +36,7 @@ public class AuthController { private final UserService userService; private final RoleService roleService; private final StructureService structureService; + private static final Logger logger = LoggerFactory.getLogger(UserController.class); public AuthController(UserService userService, RoleService roleService, StructureService structureService) { this.userService = userService; @@ -41,40 +46,47 @@ public class AuthController { @PostMapping(value = "/login") public ResponseEntity login(@RequestBody @Validated @Valid Login login) { - try{ + try { JwtAuthenticationResponse jwtAuthenticationResponse = userService.loginUser(login); - if(!jwtAuthenticationResponse.getToken().isEmpty()){ + if (!jwtAuthenticationResponse.getToken().isEmpty()) { User user = userService.getUserByUsername(login.getUsername()); - if(user.isResetPassword()){ + if (user.isResetPassword()) { return new ResponseEntity<>( new ApiResponse<>(false, jwtAuthenticationResponse, "Vous devez impérativement changer son mot de passe avant de pouvoir continuer toute action dans le logiciel infocad."), HttpStatus.OK ); - }else{ + } else { return new ResponseEntity<>( new ApiResponse<>(true, jwtAuthenticationResponse, "Authentification réussie avec succès."), HttpStatus.OK ); } - }else{ + } else { return new ResponseEntity<>( new ApiResponse<>(false, "Authentification échouée."), HttpStatus.OK ); } - }catch (Exception e){ - e.printStackTrace(); - return new ResponseEntity<>( - new ApiResponse(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PostMapping("/signup") public ResponseEntity createUser(@RequestBody @Valid @Validated UserRequest userRequest) { - try{ + try { User user = getUser(userRequest); user.setUsername(userRequest.getEmail()); user = userService.createUser(user, false); @@ -82,11 +94,19 @@ public class AuthController { new ApiResponse<>(true, user, "User created successully."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } diff --git a/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java b/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java index a027afb..bea393c 100644 --- a/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java @@ -4,6 +4,7 @@ package io.gmss.fiscad.controllers.user; import io.gmss.fiscad.entities.user.DemandeReinitialisationMP; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.UserRole; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.user.DemandeReinitialisationMPService; import io.gmss.fiscad.interfaces.user.RoleService; import io.gmss.fiscad.interfaces.user.UserService; @@ -13,12 +14,15 @@ import io.gmss.fiscad.security.CurrentUser; import io.gmss.fiscad.security.UserPrincipal; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @RequestMapping(value = "api/demande-reinitialisation-mp", produces = MediaType.APPLICATION_JSON_VALUE) @@ -28,6 +32,7 @@ import org.springframework.web.bind.annotation.*; public class DemandeReinitialisationMPController { private final DemandeReinitialisationMPService demandeReinitialisationMPService; + private static final Logger logger = LoggerFactory.getLogger(DemandeReinitialisationMPController.class); private final UserService userService; private final RoleService roleService; @@ -45,11 +50,19 @@ public class DemandeReinitialisationMPController { new ApiResponse<>(true, "DemandeReinitialisation MP créé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @@ -60,11 +73,19 @@ public class DemandeReinitialisationMPController { new ApiResponse<>(true, demandeReinitialisationMPService.updateDemandeReinitialisationMP(id, demandeReinitialisationMP), "DemandeReinitialisationMP mis à jour avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @@ -76,11 +97,19 @@ public class DemandeReinitialisationMPController { new ApiResponse<>(true, "Demande de Reinitialisation de mot de passe supprimé avec succès."), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @@ -90,24 +119,24 @@ public class DemandeReinitialisationMPController { User user = userPrincipal.getUser(); - if(user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))){ + if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { + return new ResponseEntity<>( + new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."), + HttpStatus.OK + ); + } else { + if (user.getStructure() == null) { return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."), + new ApiResponse<>(false, "Cet utilisateur n'est pas dans une structure; on ne peut donc pas afficher les demandes de réinitialisation de mot de passe."), + HttpStatus.OK + ); + } else { + return new ResponseEntity<>( + new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPNonTraiteList(user.getStructure()), "Liste des demande de Reinitialisation chargée avec succès."), HttpStatus.OK ); - }else{ - if (user.getStructure() == null) { - return new ResponseEntity<>( - new ApiResponse<>(false, "Cet utilisateur n'est pas dans une structure; on ne peut donc pas afficher les demandes de réinitialisation de mot de passe."), - HttpStatus.OK - ); - } else { - return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPNonTraiteList(user.getStructure()), "Liste des demande de Reinitialisation chargée avec succès."), - HttpStatus.OK - ); - } } + } // }else { // if (user.getStructure() == null) { // return new ResponseEntity<>( @@ -121,43 +150,98 @@ public class DemandeReinitialisationMPController { // ); // } // } + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); } catch (Exception e) { - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all-paged") public ResponseEntity getAllDemandeReinitialisationMPPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(pageable), "Liste des demandeReinitialisationMP chargée avec succès."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(pageable), "Liste des demandeReinitialisationMP chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/id/{id}") public ResponseEntity getDemandeReinitialisationMPById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPById(id), "DemandeReinitialisationMP trouvé avec succès."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPById(id), "DemandeReinitialisationMP trouvé avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/reset") public ResponseEntity traiterDemande(@RequestParam Long id, @RequestParam String password) { - DemandeReinitialisationMP demandeReinitialisationMP = demandeReinitialisationMPService.traiterDemandeReinitialisation(id, password); - return new ResponseEntity<>( - new ApiResponse<>(true, - new DemandeReinitialisationMPResponse( - userService.getUserResponseFromUser(demandeReinitialisationMP.getUser()), - demandeReinitialisationMP.getEtatDemande() - ), - "Traitement effectué avec succès."), - HttpStatus.OK - ); + try { + DemandeReinitialisationMP demandeReinitialisationMP = demandeReinitialisationMPService.traiterDemandeReinitialisation(id, password); + + return new ResponseEntity<>( + new ApiResponse<>(true, + new DemandeReinitialisationMPResponse( + userService.getUserResponseFromUser(demandeReinitialisationMP.getUser()), + demandeReinitialisationMP.getEtatDemande() + ), + "Traitement effectué avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/user/RoleController.java b/src/main/java/io/gmss/fiscad/controllers/user/RoleController.java index 1af7c20..27bd5c0 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/RoleController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/RoleController.java @@ -2,11 +2,14 @@ package io.gmss.fiscad.controllers.user; import io.gmss.fiscad.entities.user.Role; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.user.RoleService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; @@ -14,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -24,6 +28,7 @@ import org.springframework.web.bind.annotation.*; public class RoleController { private final RoleService roleService; + private static final Logger logger = LoggerFactory.getLogger(RoleController.class); public RoleController(RoleService roleService) { this.roleService = roleService; @@ -32,67 +37,122 @@ public class RoleController { @PostMapping("/create") public ResponseEntity createRole(@RequestBody @Valid @Validated Role role) { - try{ + try { role = roleService.createRole(role); return new ResponseEntity<>( new ApiResponse<>(true, role, "Role created successully."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateRole(@PathVariable Long id, @RequestBody Role role) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, roleService.updateRole(id, role), "Role updated successully."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteRole(@PathVariable Long id) { - try{ + try { roleService.deleteRole(id); return new ResponseEntity<>( - new ApiResponse<>(true,"Role deleted successully"), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "Role deleted successully"), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAll() { - return new ResponseEntity<>( - new ApiResponse<>(true, roleService.getRoleList(), "Liste des roles."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, roleService.getRoleList(), "Liste des roles."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-paged") public ResponseEntity getAllPaged(@RequestParam int pageNo, @RequestParam int pageSize) { - Pageable pageable = PageRequest.of(pageNo, pageSize); - return new ResponseEntity<>( - new ApiResponse<>(true, roleService.getRoleList(pageable), "Liste des roles."), - HttpStatus.OK - ); + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, roleService.getRoleList(pageable), "Liste des roles."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } } diff --git a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java index fdb5ed1..764b2d5 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.controllers.user; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.UserRole; +import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.user.UserService; import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.Login; @@ -11,12 +12,14 @@ import io.gmss.fiscad.security.UserPrincipal; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - +import org.springframework.web.client.HttpClientErrorException; @RestController @@ -27,6 +30,7 @@ import org.springframework.web.bind.annotation.*; public class UserController { private final UserService userService; + private static final Logger logger = LoggerFactory.getLogger(UserController.class); public UserController(UserService userService) { @@ -35,155 +39,241 @@ public class UserController { @PostMapping("/create") public ResponseEntity createUser(@RequestBody @Valid @Validated User user) { - try{ + try { user.setUsername(user.getEmail()); user = userService.createUser(user, true); return new ResponseEntity<>( new ApiResponse<>(true, user, "Utilisateur créé avec succès"), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PostMapping("/change-password") public ResponseEntity changeUserPassword(@RequestBody @Valid @Validated Login login) { - try{ + try { userService.updatePassword(login.getUsername(), login.getPassword()); return new ResponseEntity<>( new ApiResponse<>(true, "Votre mot de passe à été modifiée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PostMapping("/reset-password") public ResponseEntity resetUserPassword(@RequestBody @Valid @Validated Login login) { - try{ + try { User user = userService.resetPassword(login.getUsername(), login.getPassword()); return new ResponseEntity<>( new ApiResponse<>(true, user, "Votre mot de passe à été réinitialisée avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PostMapping("/validate-user-account") public ResponseEntity validateUserAccount(@RequestBody @Valid @Validated Login login) { - try{ + try { User user = userService.validateUserAccount(login.getUsername(), login.getUserRole()); return new ResponseEntity<>( new ApiResponse<>(true, user, "Cet utilisateur à été activé avec succès."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @PutMapping("/update/{id}") public ResponseEntity updateUser(@PathVariable Long id, @RequestBody User user) { - try{ + try { return new ResponseEntity<>( new ApiResponse<>(true, userService.updateUser(id, user), "User updated successully."), HttpStatus.OK ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), - HttpStatus.OK - ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } - @GetMapping ("/activate-or-not") + @GetMapping("/activate-or-not") public ResponseEntity acitvateOrNotUser(@RequestParam Long id) { - try{ + try { User user = userService.activateOrNotUser(id); String message = "Utilisateur activé avec succès"; - if(!user.isActive()) { + if (!user.isActive()) { message = "Utilisateur désactivé avec succès"; } return new ResponseEntity<>( - new ApiResponse<>(true, user , message), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, user, message), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @DeleteMapping("/delete/{id}") public ResponseEntity deleteUser(@PathVariable Long id) { - try{ + try { userService.deleteUser(id); return new ResponseEntity<>( - new ApiResponse<>(true,"User deleted successully"), - HttpStatus.OK - ); - }catch (Exception e){ - return new ResponseEntity<>( - new ApiResponse<>(false, e.getMessage()), + new ApiResponse<>(true, "User deleted successully"), HttpStatus.OK ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all") public ResponseEntity getAll(@CurrentUser UserPrincipal userPrincipal) { + try { - User user = userPrincipal.getUser(); + User user = userPrincipal.getUser(); - if(user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))){ - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getAllUserListResponse(), "Liste des utilisateurs chargée avec succès."), - HttpStatus.OK - ); - }else{ - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getListUserResponseByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), - HttpStatus.OK - ); + if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getAllUserListResponse(), "Liste des utilisateurs chargée avec succès."), + HttpStatus.OK + ); + } else { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getListUserResponseByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), + HttpStatus.OK + ); + } + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } @GetMapping("/all-by-structure") public ResponseEntity getAllByStructure(@CurrentUser UserPrincipal userPrincipal) { - - if(userPrincipal.getUser().getStructure() != null) { - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getListUserByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), - HttpStatus.OK - ); - }else{ - return new ResponseEntity<>( - new ApiResponse<>(false, "Impossible de trouver la structure indiquée."), - HttpStatus.OK - ); + try { + if (userPrincipal.getUser().getStructure() != null) { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getListUserByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), + HttpStatus.OK + ); + } else { + return new ResponseEntity<>( + new ApiResponse<>(false, "Impossible de trouver la structure indiquée."), + HttpStatus.OK + ); + } + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } + } // @GetMapping("/all-paged") @@ -197,26 +287,71 @@ public class UserController { @GetMapping("/id/{id}") public ResponseEntity getUserById(@PathVariable Long id) { - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getUserById(id), "User found."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getUserById(id), "User found."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/username/{username}") public ResponseEntity getUserByUsername(@PathVariable String username) { - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getUserByUsername(username), "User found."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getUserByUsername(username), "User found."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } @GetMapping("/all-by-role/{userrole}") public ResponseEntity getUserByUserRole(@PathVariable UserRole userrole) { - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getUserByProfil(userrole), "Users found."), - HttpStatus.OK - ); + try { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getUserByProfil(userrole), "Users found."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } } diff --git a/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java b/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java index a42bd8e..40b2dc3 100644 --- a/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java +++ b/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java @@ -32,7 +32,7 @@ public class Secteur extends BaseEntity implements Serializable { private Structure structure; //@JsonIgnore //@OneToMany(mappedBy = "secteur") - @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "secteur_id") private List secteurDecoupages; } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/ActeurConcerne.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/ActeurConcerne.java index 768a6ad..4208adb 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/ActeurConcerne.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/ActeurConcerne.java @@ -62,7 +62,7 @@ public class ActeurConcerne extends BaseEntity implements Serializable { ////////////////////////////// private Long blocId; @ColumnDefault("0") - private int haveDeclarant ; + private int haveDeclarant; private Long max_numero_acteur_concerne_id; diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java index e98e93d..e05f291 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java @@ -156,74 +156,77 @@ public class Enquete extends BaseEntity implements Serializable { private StatutEnregistrement statutEnregistrement; - public Long getTerminalId(){ - if(this.terminal!=null){ + public Long getTerminalId() { + if (this.terminal != null) { return this.terminal.getId(); - }else return null; + } else return null; } - - public String getNomPrenomEnqueteur(){ - if(this.user!=null){ - return this.user.getNom()+" "+this.user.getPrenom(); - }else return ""; + public String getNomPrenomEnqueteur() { + if (this.user != null) { + return this.user.getNom() + " " + this.user.getPrenom(); + } else return ""; } - public String getNomBloc(){ - if(this.bloc!=null){ + + public String getNomBloc() { + if (this.bloc != null) { return this.bloc.getNom(); - }else return ""; + } else return ""; } - public String getCodeBloc(){ - if(this.bloc!=null){ + public String getCodeBloc() { + if (this.bloc != null) { return this.bloc.getCote(); - }else return ""; + } else return ""; } - public String getDepartement(){ - if(this.bloc!=null){ - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + + public String getDepartement() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getCommune().getDepartement().getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getCommune(){ - if(this.bloc!=null){ - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + + public String getCommune() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getCommune().getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getArrondissement(){ - if(this.bloc!=null) { - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + public String getArrondissement() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getTypeDomaine(){ - if(this.parcelle!=null){ - NatureDomaine natureDomaine= this.parcelle.getNatureDomaine(); - if(natureDomaine!=null){ + + public String getTypeDomaine() { + if (this.parcelle != null) { + NatureDomaine natureDomaine = this.parcelle.getNatureDomaine(); + if (natureDomaine != null) { return natureDomaine.getTypeDomaine().getLibelle(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getTelEnqueteur(){ - if(this.user !=null){ + public String getTelEnqueteur() { + if (this.user != null) { return this.user.getTel(); - }else return ""; + } else return ""; } - public String getStructureEnqueteur(){ - if(this.user !=null){ + public String getStructureEnqueteur() { + if (this.user != null) { return this.user.getStructure().getNom(); - }else return ""; + } else return ""; } diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/EnqueteFiltreResponse.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/EnqueteFiltreResponse.java index 5aa0d00..ad71338 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/EnqueteFiltreResponse.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/EnqueteFiltreResponse.java @@ -5,9 +5,10 @@ import jakarta.persistence.Id; import lombok.Data; import java.time.LocalDate; + @Entity @Data -public class EnqueteFiltreResponse{ +public class EnqueteFiltreResponse { @Id private Long id; private String parcelleid; diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java index 7596c35..c7d02c9 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java @@ -45,7 +45,7 @@ public class Parcelle extends BaseEntity implements Serializable { @JsonIgnore @OneToMany(mappedBy = "parcelle") private List enquetes; -// @ManyToOne + // @ManyToOne // private SituationGeographique situationGeographique; @ManyToOne //private TypeDomaine typeDomaine; @@ -87,6 +87,4 @@ public class Parcelle extends BaseEntity implements Serializable { // private Point geometry32631; - - } diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/ParcelleGeom.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/ParcelleGeom.java index 8ccb0f1..16e4816 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/ParcelleGeom.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/ParcelleGeom.java @@ -1,12 +1,8 @@ package io.gmss.fiscad.entities.infocad.metier; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.gmss.fiscad.entities.BaseEntity; -import io.gmss.fiscad.entities.decoupage.Quartier; -import io.gmss.fiscad.entities.infocad.parametre.NatureDomaine; -import io.gmss.fiscad.entities.rfu.metier.Batiment; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; @@ -16,12 +12,10 @@ import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; import org.locationtech.jts.geom.MultiPolygon; -import org.locationtech.jts.geom.Point; import org.n52.jackson.datatype.jts.GeometryDeserializer; import org.n52.jackson.datatype.jts.GeometrySerializer; import java.io.Serializable; -import java.util.List; @EqualsAndHashCode(callSuper = true) @Entity @@ -42,24 +36,24 @@ public class ParcelleGeom extends BaseEntity implements Serializable { private String ilot; private String zone; private String p; - @Column(unique = true,nullable = true) + @Column(unique = true, nullable = true) private String nup; - @Column(unique = true,nullable = true) + @Column(unique = true, nullable = true) private String nupProvisoire; private String longitude; private String latitude; private String pointsPolygone; @ColumnDefault("0") - private int geomSrid; + private int geomSrid; @JsonSerialize(using = GeometrySerializer.class) @JsonDeserialize(contentUsing = GeometryDeserializer.class) - @Column(name = "geom",columnDefinition = "geometry(MultiPolygon,4326)") - private MultiPolygon geometry ; + @Column(name = "geom", columnDefinition = "geometry(MultiPolygon,4326)") + private MultiPolygon geometry; @JsonSerialize(using = GeometrySerializer.class) @JsonDeserialize(contentUsing = GeometryDeserializer.class) - @Column(name = "geom_32631",columnDefinition = "geometry(MultiPolygon,32631)") - private MultiPolygon geometry32631 ; + @Column(name = "geom_32631", columnDefinition = "geometry(MultiPolygon,32631)") + private MultiPolygon geometry32631; } diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Piece.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Piece.java index b76266a..599cfe2 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Piece.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Piece.java @@ -49,13 +49,13 @@ public class Piece extends BaseEntity implements Serializable { private Personne personne; @JsonIgnore @ManyToOne - private ActeurConcerne acteurConcerne ; + private ActeurConcerne acteurConcerne; @ManyToOne - private SourceDroit sourceDroit ; + private SourceDroit sourceDroit; @ManyToOne - private ModeAcquisition modeAcquisition ; + private ModeAcquisition modeAcquisition; @OneToMany(mappedBy = "piece") - private List uploads ; + private List uploads; @JsonIgnore @ManyToOne diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Upload.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Upload.java index 8ea4825..c54c5b1 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Upload.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Upload.java @@ -61,7 +61,7 @@ public class Upload extends BaseEntity implements Serializable { return url != null ? url.toLowerCase().startsWith("https") ? url : url.toLowerCase().replaceFirst("http", "https") : null; } - private String serverContext(){ + private String serverContext() { return ServletUriComponentsBuilder.fromCurrentContextPath() .path("/api/upload/downloadFile/") .toUriString(); diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/ModeAcquisition.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/ModeAcquisition.java index b07bbf7..f5c891f 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/ModeAcquisition.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/ModeAcquisition.java @@ -34,7 +34,7 @@ public class ModeAcquisition extends BaseEntity implements Serializable { @JsonIgnore @OneToMany(mappedBy = "modeAcquisition") //private List sourceDroitExerces; - private List pieces ; + private List pieces; @ManyToMany @JoinTable(name = "modeAcquisition_typePersonne", joinColumns = @JoinColumn(name = "mode_acquisition_id"), diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java index 6a38610..4cb53c5 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java @@ -84,6 +84,4 @@ public class Personne extends BaseEntity implements Serializable { private boolean synchronise; - - } diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/SourceDroit.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/SourceDroit.java index 83eaa6c..8403cc5 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/SourceDroit.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/SourceDroit.java @@ -48,7 +48,7 @@ public class SourceDroit extends BaseEntity implements Serializable { @JsonIgnore @OneToMany(mappedBy = "sourceDroit") //private List sourceDroitExerces; - private List pieces ; + private List pieces; @Column(columnDefinition = "boolean default false") private boolean titreFoncier; diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/TypeDomaine.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/TypeDomaine.java index 37e8dfd..0734af6 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/TypeDomaine.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/TypeDomaine.java @@ -29,7 +29,7 @@ public class TypeDomaine extends BaseEntity implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String libelle; -// @JsonIgnore + // @JsonIgnore // @OneToMany(mappedBy = "typeDomaine") // private List parcelles; @JsonIgnore diff --git a/src/main/java/io/gmss/fiscad/entities/rfu/parametre/Equipe.java b/src/main/java/io/gmss/fiscad/entities/rfu/parametre/Equipe.java index e6d6866..7c72c0e 100644 --- a/src/main/java/io/gmss/fiscad/entities/rfu/parametre/Equipe.java +++ b/src/main/java/io/gmss/fiscad/entities/rfu/parametre/Equipe.java @@ -31,10 +31,10 @@ public class Equipe extends BaseEntity implements Serializable { @ManyToOne private Bloc bloc; @ManyToOne - private Secteur secteur ; + private Secteur secteur; @ManyToOne private Campagne campagne; - @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "equipe_id") private List participers; diff --git a/src/main/java/io/gmss/fiscad/entities/user/User.java b/src/main/java/io/gmss/fiscad/entities/user/User.java index 0ec06e9..b29d1e8 100755 --- a/src/main/java/io/gmss/fiscad/entities/user/User.java +++ b/src/main/java/io/gmss/fiscad/entities/user/User.java @@ -62,7 +62,7 @@ public class User extends BaseEntity implements Serializable { private List participers; @JsonIgnore @OneToMany(mappedBy = "chefSecteur") - private List secteurs ; + private List secteurs; @Transient private Long idCampagneCourant; @@ -73,9 +73,9 @@ public class User extends BaseEntity implements Serializable { this.username = this.email; } - public boolean isAdmin(){ - for(Role r:this.roles ){ - if(r.getNom().equals(UserRole.ROLE_ADMIN)){ + public boolean isAdmin() { + for (Role r : this.roles) { + if (r.getNom().equals(UserRole.ROLE_ADMIN)) { return true; } } @@ -83,18 +83,18 @@ public class User extends BaseEntity implements Serializable { } - public Long getIdCampagneCourant(){ - for (Participer p:participers){ - if(p.getDateFin()==null){ + public Long getIdCampagneCourant() { + for (Participer p : participers) { + if (p.getDateFin() == null) { return p.getEquipe().getCampagne().getId(); } } return null; } - public Long getIdSecteurCourant(){ - for (Participer p:participers){ - if(p.getDateFin()==null){ + public Long getIdSecteurCourant() { + for (Participer p : participers) { + if (p.getDateFin() == null) { return p.getEquipe().getSecteur().getId(); } } diff --git a/src/main/java/io/gmss/fiscad/exceptions/BadRequestException.java b/src/main/java/io/gmss/fiscad/exceptions/BadRequestException.java index 783d3e9..a1e15f9 100755 --- a/src/main/java/io/gmss/fiscad/exceptions/BadRequestException.java +++ b/src/main/java/io/gmss/fiscad/exceptions/BadRequestException.java @@ -4,8 +4,8 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; @ResponseStatus(HttpStatus.BAD_REQUEST) -public class BadRequestException extends RuntimeException{ - public BadRequestException(String message){ +public class BadRequestException extends RuntimeException { + public BadRequestException(String message) { super(message); } } diff --git a/src/main/java/io/gmss/fiscad/exceptions/FileStorageException.java b/src/main/java/io/gmss/fiscad/exceptions/FileStorageException.java index 02aec19..e828304 100644 --- a/src/main/java/io/gmss/fiscad/exceptions/FileStorageException.java +++ b/src/main/java/io/gmss/fiscad/exceptions/FileStorageException.java @@ -1,4 +1,5 @@ package io.gmss.fiscad.exceptions; + public class FileStorageException extends RuntimeException { public FileStorageException(String message) { super(message); diff --git a/src/main/java/io/gmss/fiscad/exceptions/NotFoundException.java b/src/main/java/io/gmss/fiscad/exceptions/NotFoundException.java index 2b60b74..ab29451 100755 --- a/src/main/java/io/gmss/fiscad/exceptions/NotFoundException.java +++ b/src/main/java/io/gmss/fiscad/exceptions/NotFoundException.java @@ -4,8 +4,8 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; @ResponseStatus(HttpStatus.NOT_FOUND) -public class NotFoundException extends RuntimeException{ - public NotFoundException(String message){ +public class NotFoundException extends RuntimeException { + public NotFoundException(String message) { super(message); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java index b7a460c..f9739e7 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java @@ -27,29 +27,29 @@ public class ArrondissementServiceImpl implements ArrondissementService { @Override public Arrondissement createArrondissement(Arrondissement arrondissement) throws BadRequestException { - if(arrondissement.getId() != null ){ + if (arrondissement.getId() != null) { throw new BadRequestException("Impossible de créer un nouvel arrondissement ayant un id non null."); } - return arrondissementRepository.save(arrondissement); + return arrondissementRepository.save(arrondissement); } @Override public Arrondissement updateArrondissement(Long id, Arrondissement arrondissement) throws NotFoundException { - if(arrondissement.getId() == null ){ + if (arrondissement.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouvel arrondissement ayant un id null."); } - if(!arrondissementRepository.existsById(arrondissement.getId())){ + if (!arrondissementRepository.existsById(arrondissement.getId())) { throw new NotFoundException("Impossible de trouver l'arrondissement spécifié dans notre base de données."); } - return arrondissementRepository.save(arrondissement); + return arrondissementRepository.save(arrondissement); } @Override public void deleteArrondissement(Long id) throws NotFoundException { Optional arrondissementOptional = arrondissementRepository.findById(id); - if(arrondissementOptional.isPresent()){ + if (arrondissementOptional.isPresent()) { arrondissementRepository.deleteById(arrondissementOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver l'arrondissement spécifié dans notre base de données."); } } @@ -72,7 +72,7 @@ public class ArrondissementServiceImpl implements ArrondissementService { @Override public List getArrondissementByComune(Long communeId) { Optional communeOptional = communeService.getCommuneById(communeId); - if(communeOptional.isEmpty()){ + if (communeOptional.isEmpty()) { throw new NotFoundException("Impossible de trouver la commune spécifiée."); } return arrondissementRepository.findAllByCommune(communeOptional.get()); diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java index b21526a..ac75298 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java @@ -27,29 +27,29 @@ public class CommuneServiceImpl implements CommuneService { @Override public Commune createCommune(Commune commune) throws BadRequestException { - if(commune.getId() != null ){ + if (commune.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle commune ayant un id non null."); } - return communeRepository.save(commune); + return communeRepository.save(commune); } @Override public Commune updateCommune(Long id, Commune commune) throws NotFoundException { - if(commune.getId() == null ){ + if (commune.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle commune ayant un id null."); } - if(!communeRepository.existsById(commune.getId())){ + if (!communeRepository.existsById(commune.getId())) { throw new NotFoundException("Impossible de trouver la commune spécifiée dans notre base de données."); } - return communeRepository.save(commune); + return communeRepository.save(commune); } @Override public void deleteCommune(Long id) throws NotFoundException { Optional communeOptional = communeRepository.findById(id); - if(communeOptional.isPresent()){ + if (communeOptional.isPresent()) { communeRepository.deleteById(communeOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la commune spécifiée dans notre base de données."); } } @@ -68,7 +68,7 @@ public class CommuneServiceImpl implements CommuneService { @Override public List getCommunesByDepartement(Long departementId) { Optional departementOptional = departementService.getDepartementById(departementId); - if(departementOptional.isEmpty()){ + if (departementOptional.isEmpty()) { throw new NotFoundException("Impossible de trouver le département spécifié."); } return communeRepository.findAllByDepartement(departementOptional.get()); diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java index 1a0a3ff..605c48e 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java @@ -23,29 +23,29 @@ public class DepartementServiceImpl implements DepartementService { @Override public Departement createDepartement(Departement departement) throws BadRequestException { - if(departement.getId() != null ){ + if (departement.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau département ayant un id non null."); } - return departementRepository.save(departement); + return departementRepository.save(departement); } @Override public Departement updateDepartement(Long id, Departement departement) throws NotFoundException { - if(departement.getId() == null ){ + if (departement.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau département ayant un id null."); } - if(!departementRepository.existsById(departement.getId())){ + if (!departementRepository.existsById(departement.getId())) { throw new NotFoundException("Impossible de trouver le département spécifié dans notre base de données."); } - return departementRepository.save(departement); + return departementRepository.save(departement); } @Override public void deleteDepartement(Long id) throws NotFoundException { Optional departementOptional = departementRepository.findById(id); - if(departementOptional.isPresent()){ + if (departementOptional.isPresent()) { departementRepository.deleteById(departementOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le département spécifié dans notre base de données."); } } @@ -63,9 +63,9 @@ public class DepartementServiceImpl implements DepartementService { @Override public Optional getDepartementById(Long id) { - if(departementRepository.existsById(id)){ + if (departementRepository.existsById(id)) { return departementRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le département spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/NationaliteServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/NationaliteServiceImpl.java index ed5878e..94ec2d2 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/NationaliteServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/NationaliteServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class NationaliteServiceImpl implements NationaliteService { @@ -22,29 +23,29 @@ public class NationaliteServiceImpl implements NationaliteService { @Override public Nationalite createNationalite(Nationalite nationalite) throws BadRequestException { - if(nationalite.getId() != null ){ + if (nationalite.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle nationalité ayant un id non null."); } - return nationaliteRepository.save(nationalite); + return nationaliteRepository.save(nationalite); } @Override public Nationalite updateNationalite(Long id, Nationalite nationalite) throws NotFoundException { - if(nationalite.getId() == null ){ + if (nationalite.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle nationalité ayant un id null."); } - if(!nationaliteRepository.existsById(nationalite.getId())){ + if (!nationaliteRepository.existsById(nationalite.getId())) { throw new NotFoundException("Impossible de trouver la nationalité spécifiée dans notre base de données."); } - return nationaliteRepository.save(nationalite); + return nationaliteRepository.save(nationalite); } @Override public void deleteNationalite(Long id) throws NotFoundException { Optional nationaliteOptional = nationaliteRepository.findById(id); - if(nationaliteOptional.isPresent()){ + if (nationaliteOptional.isPresent()) { nationaliteRepository.deleteById(nationaliteOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nationalité spécifiée dans notre base de données."); } } @@ -62,9 +63,9 @@ public class NationaliteServiceImpl implements NationaliteService { @Override public Optional getNationaliteById(Long id) { - if(nationaliteRepository.existsById(id)){ + if (nationaliteRepository.existsById(id)) { return nationaliteRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nationalité spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java index 915f794..1ad326c 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java @@ -27,29 +27,29 @@ public class QuartierServiceImpl implements QuartierService { @Override public Quartier createQuartier(Quartier quartier) throws BadRequestException { - if(quartier.getId() != null ){ + if (quartier.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau quartier ayant un id non null."); } - return quartierRepository.save(quartier); + return quartierRepository.save(quartier); } @Override public Quartier updateQuartier(Long id, Quartier quartier) throws NotFoundException { - if(quartier.getId() == null ){ + if (quartier.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau quartier ayant un id null."); } - if(!quartierRepository.existsById(quartier.getId())){ + if (!quartierRepository.existsById(quartier.getId())) { throw new NotFoundException("Impossible de trouver le quartier spécifié dans notre base de données."); } - return quartierRepository.save(quartier); + return quartierRepository.save(quartier); } @Override public void deleteQuartier(Long id) throws NotFoundException { Optional quartierOptional = quartierRepository.findById(id); - if(quartierOptional.isPresent()){ + if (quartierOptional.isPresent()) { quartierRepository.deleteById(quartierOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le quartier spécifié dans notre base de données."); } } @@ -66,9 +66,9 @@ public class QuartierServiceImpl implements QuartierService { @Override public Optional getQuartierById(Long id) { - if(quartierRepository.existsById(id)){ + if (quartierRepository.existsById(id)) { return quartierRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le quartier spécifié dans la base de données."); } @@ -77,7 +77,7 @@ public class QuartierServiceImpl implements QuartierService { @Override public List getQuartierByArrondissement(Long arrondissementId) { Optional arrondissementOptional = arrondissementService.getArrondissementById(arrondissementId); - if(arrondissementOptional.isEmpty()){ + if (arrondissementOptional.isEmpty()) { throw new NotFoundException("Impossible de trouver l'arrondissement spécifié."); } return quartierRepository.getAllByArrondissement(arrondissementOptional.get()); diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java index f4c8673..ad102de 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java @@ -22,29 +22,29 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService { @Override public SecteurDecoupage createSecteurDecoupage(SecteurDecoupage secteurDecoupage) throws BadRequestException { - if(secteurDecoupage.getId() != null ){ + if (secteurDecoupage.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau secteur découpage ayant un id non null."); } - return secteurDecoupageRepository.save(secteurDecoupage); + return secteurDecoupageRepository.save(secteurDecoupage); } @Override public SecteurDecoupage updateSecteurDecoupage(Long id, SecteurDecoupage secteurDecoupage) throws NotFoundException { - if(secteurDecoupage.getId() == null ){ + if (secteurDecoupage.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau secteur découpage ayant un id null."); } - if(!secteurDecoupageRepository.existsById(secteurDecoupage.getId())){ + if (!secteurDecoupageRepository.existsById(secteurDecoupage.getId())) { throw new NotFoundException("Impossible de trouver le secteur découpage spécifié."); } - return secteurDecoupageRepository.save(secteurDecoupage); + return secteurDecoupageRepository.save(secteurDecoupage); } @Override public void deleteSecteurDecoupage(Long id) throws NotFoundException { Optional secteurDecoupageOptional = secteurDecoupageRepository.findById(id); - if(secteurDecoupageOptional.isPresent()){ + if (secteurDecoupageOptional.isPresent()) { secteurDecoupageRepository.deleteById(secteurDecoupageOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le secteur découpage spécifié."); } } @@ -60,7 +60,6 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService { } - @Override public Optional getSecteurDecoupageById(Long id) { return secteurDecoupageRepository.findById(id); diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java index d4c3f0f..addc289 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java @@ -41,37 +41,37 @@ public class SecteurServiceImpl implements SecteurService { @Override public Secteur createSecteur(SecteurPayload secteurPayload) throws BadRequestException { - if(secteurPayload.getId() != null ){ + if (secteurPayload.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau secteur ayant un id non null."); } - if(secteurPayload.getChefSecteurId()!=null && userRepository.existsById(secteurPayload.getChefSecteurId()) ) { + if (secteurPayload.getChefSecteurId() != null && userRepository.existsById(secteurPayload.getChefSecteurId())) { Secteur secteur = getSecteurFromPayload(secteurPayload); return secteurRepository.save(secteur); - }else{ + } else { throw new BadRequestException("Impossible de créer un nouveau secteur sans le chef le Chef Secteur."); } } private Secteur getSecteurFromPayload(SecteurPayload secteurPayload) { - Secteur secteur=new Secteur(); - Optional optionalUser=userRepository.findById(secteurPayload.getChefSecteurId()); + Secteur secteur = new Secteur(); + Optional optionalUser = userRepository.findById(secteurPayload.getChefSecteurId()); secteur.setChefSecteur(optionalUser.orElse(null)); - Optional optionalStructure=structureRepository.findById(secteurPayload.getStructureId()); + Optional optionalStructure = structureRepository.findById(secteurPayload.getStructureId()); secteur.setStructure(optionalStructure.orElse(null)); - List secteurDecoupageList=new ArrayList<>(); + List secteurDecoupageList = new ArrayList<>(); - for (SecteurDecoupagePayload sdp: secteurPayload.getSecteurDecoupages()){ - SecteurDecoupage sd=new SecteurDecoupage(); - if(sdp.getSecteurId()!=null && secteurRepository.existsById(sdp.getSecteurId()) ){ + for (SecteurDecoupagePayload sdp : secteurPayload.getSecteurDecoupages()) { + SecteurDecoupage sd = new SecteurDecoupage(); + if (sdp.getSecteurId() != null && secteurRepository.existsById(sdp.getSecteurId())) { sd.setSecteur(secteurRepository.findById(sdp.getSecteurId()).orElse(null)); } - if(sdp.getArrondissementId()!=null && arrondissementRepository.existsById(sdp.getArrondissementId()) ){ + if (sdp.getArrondissementId() != null && arrondissementRepository.existsById(sdp.getArrondissementId())) { sd.setArrondissement(arrondissementRepository.findById(sdp.getArrondissementId()).orElse(null)); } - if(sdp.getQuartierId()!=null && quartierRepository.existsById(sdp.getQuartierId()) ){ + if (sdp.getQuartierId() != null && quartierRepository.existsById(sdp.getQuartierId())) { sd.setQuartier(quartierRepository.findById(sdp.getQuartierId()).orElse(null)); } sd.setDateDebut(sdp.getDateDebut()); @@ -88,17 +88,17 @@ public class SecteurServiceImpl implements SecteurService { @Override public Secteur updateSecteur(Long id, SecteurPayload secteurPayload) throws NotFoundException { - if(secteurPayload.getId() == null ){ + if (secteurPayload.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau secteur ayant un id null."); } - if(!secteurRepository.existsById(secteurPayload.getId())){ + if (!secteurRepository.existsById(secteurPayload.getId())) { throw new NotFoundException("Impossible de trouver le secteur spécifié."); } - if(secteurPayload.getChefSecteurId()!=null && userRepository.existsById(secteurPayload.getChefSecteurId()) ) { + if (secteurPayload.getChefSecteurId() != null && userRepository.existsById(secteurPayload.getChefSecteurId())) { Secteur secteur = getSecteurFromPayload(secteurPayload); return secteurRepository.save(secteur); - }else{ + } else { throw new BadRequestException("Impossible de créer un nouveau secteur sans le chef le Chef Secteur."); } } @@ -106,9 +106,9 @@ public class SecteurServiceImpl implements SecteurService { @Override public void deleteSecteur(Long id) throws NotFoundException { Optional secteurOptional = secteurRepository.findById(id); - if(secteurOptional.isPresent()){ + if (secteurOptional.isPresent()) { secteurRepository.deleteById(secteurOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le secteur spécifié."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ActeurConcerneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ActeurConcerneServiceImpl.java index 97204bf..140680b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ActeurConcerneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ActeurConcerneServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service @RequiredArgsConstructor public class ActeurConcerneServiceImpl implements ActeurConcerneService { diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/CommentaireServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/CommentaireServiceImpl.java index acd6693..b078240 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/CommentaireServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/CommentaireServiceImpl.java @@ -25,35 +25,35 @@ public class CommentaireServiceImpl implements CommentaireService { @Override public Commentaire createCommentaire(Commentaire commentaire) throws BadRequestException { - if(commentaire.getId() != null ){ + if (commentaire.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau commentaire ayant un id non null."); } - return commentaireRepository.save(commentaire); + return commentaireRepository.save(commentaire); } @Override public Commentaire updateCommentaire(Long id, Commentaire commentaire) throws NotFoundException { - if(commentaire.getId() == null ){ + if (commentaire.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau commentaire ayant un id null."); } - if(!commentaireRepository.existsById(commentaire.getId())){ + if (!commentaireRepository.existsById(commentaire.getId())) { throw new NotFoundException("Impossible de trouver le commentaire spécifié dans notre base de données."); } - return commentaireRepository.save(commentaire); + return commentaireRepository.save(commentaire); } @Override public void deleteCommentaire(Long id) throws NotFoundException { Optional commentaireOptional = commentaireRepository.findById(id); - if(commentaireOptional.isPresent()){ + if (commentaireOptional.isPresent()) { commentaireRepository.deleteById(commentaireOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le commentaire spécifié dans notre base de données."); } } @Override - public List getCommentairesByEnqueteAndTerminal(Long idEnquete , Long terminalId) { + public List getCommentairesByEnqueteAndTerminal(Long idEnquete, Long terminalId) { return commentaireRepository.findAllByIdEnqueteAndTerminalId(idEnquete, terminalId); } @@ -90,7 +90,7 @@ public class CommentaireServiceImpl implements CommentaireService { @Override public boolean setCommentaireRead(Long id) { - if(commentaireRepository.existsById(id)){ + if (commentaireRepository.existsById(id)) { Commentaire commentaire = commentaireRepository.getById(id); commentaire.setLu(true); updateCommentaire(id, commentaire); @@ -113,11 +113,11 @@ public class CommentaireServiceImpl implements CommentaireService { @Override public List notifySynchronizedDoneFromMobile(List syncCommentaireRequests) { - if(syncCommentaireRequests != null || !syncCommentaireRequests.isEmpty()){ + if (syncCommentaireRequests != null || !syncCommentaireRequests.isEmpty()) { List commentaireResponses = new ArrayList<>(); syncCommentaireRequests.forEach(syncCommentaireRequest -> { Optional commentaireOptional = commentaireRepository.findById(syncCommentaireRequest.getIdBackend()); - if(commentaireOptional.isPresent()){ + if (commentaireOptional.isPresent()) { Commentaire commentaire = commentaireOptional.get(); commentaire.setExternalKey(syncCommentaireRequest.getExternalKey()); commentaire.setSynchronise(true); diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/EnqueteServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/EnqueteServiceImpl.java index f8a465d..c2adf7e 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/EnqueteServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/EnqueteServiceImpl.java @@ -68,19 +68,19 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public Enquete createEnquete(EnquetePayLoad enquetePayLoad) throws BadRequestException { - Optional optionalUser =userRepository.findById(enquetePayLoad.getUserId()); - if(!optionalUser.isPresent()){ + Optional optionalUser = userRepository.findById(enquetePayLoad.getUserId()); + if (!optionalUser.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec un enquêteur inexistant"); } - Optional optionalBloc =blocRepository.findById(enquetePayLoad.getBlocId()); - if(!optionalBloc.isPresent()){ + Optional optionalBloc = blocRepository.findById(enquetePayLoad.getBlocId()); + if (!optionalBloc.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec un bloc inexistant"); } - Optional optionalParcelle =parcelleRepository.findById(enquetePayLoad.getParcelleId()); - if(!optionalParcelle.isPresent()){ + Optional optionalParcelle = parcelleRepository.findById(enquetePayLoad.getParcelleId()); + if (!optionalParcelle.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec une parcelle inexistante"); } - Enquete enquete=new Enquete(); + Enquete enquete = new Enquete(); enquete.setDateEnquete(LocalDate.now()); enquete.setBloc(optionalBloc.get()); enquete.setUser(optionalUser.get()); @@ -98,9 +98,9 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public List getEnqueteCommuneArrondBlocFiltre(FiltreEnquetePayLoad filtreEnquetePayLoad) { - String condition=""; - Query query ; - String sql ="select distinct " + + String condition = ""; + Query query; + String sql = "select distinct " + " e.id," + " e.parcelle_id as parcelleId," + " c.id as communeId, " + @@ -138,80 +138,79 @@ public class EnqueteServiceImpl implements EnqueteService { " left join type_personne tp on tp.id=per.type_personne_id " + " where ac.role_acteur='PROPRIETAIRE' "; - if(filtreEnquetePayLoad.getCommuneId()!=null){ - condition+= " AND c.id = "+filtreEnquetePayLoad.getCommuneId(); + if (filtreEnquetePayLoad.getCommuneId() != null) { + condition += " AND c.id = " + filtreEnquetePayLoad.getCommuneId(); } - if(filtreEnquetePayLoad.getArrondissementId()!=null){ - condition+= " AND a.id = "+filtreEnquetePayLoad.getArrondissementId() ; + if (filtreEnquetePayLoad.getArrondissementId() != null) { + condition += " AND a.id = " + filtreEnquetePayLoad.getArrondissementId(); } - if(filtreEnquetePayLoad.getStructureId()!=null){ - condition+= " AND s.id = "+filtreEnquetePayLoad.getStructureId() ; + if (filtreEnquetePayLoad.getStructureId() != null) { + condition += " AND s.id = " + filtreEnquetePayLoad.getStructureId(); } - if(filtreEnquetePayLoad.getParcelleId()!=null){ - condition+= " AND p.id = "+filtreEnquetePayLoad.getParcelleId(); + if (filtreEnquetePayLoad.getParcelleId() != null) { + condition += " AND p.id = " + filtreEnquetePayLoad.getParcelleId(); } - if(filtreEnquetePayLoad.getBlocId()!=null){ - condition+= " AND b.id = "+filtreEnquetePayLoad.getBlocId() ; + if (filtreEnquetePayLoad.getBlocId() != null) { + condition += " AND b.id = " + filtreEnquetePayLoad.getBlocId(); } - if(filtreEnquetePayLoad.getNomPersonne()!=null){ - condition+= " AND per.nom_ou_sigle like '%"+filtreEnquetePayLoad.getNomPersonne() +"%'"; + if (filtreEnquetePayLoad.getNomPersonne() != null) { + condition += " AND per.nom_ou_sigle like '%" + filtreEnquetePayLoad.getNomPersonne() + "%'"; } - if(filtreEnquetePayLoad.getPrenomPersonne()!=null){ - condition+= " AND per.prenom_ou_raison_sociale like '%"+filtreEnquetePayLoad.getPrenomPersonne() +"%'"; + if (filtreEnquetePayLoad.getPrenomPersonne() != null) { + condition += " AND per.prenom_ou_raison_sociale like '%" + filtreEnquetePayLoad.getPrenomPersonne() + "%'"; } - if(filtreEnquetePayLoad.getNatureDomaneId()!=null){ - condition+= " AND nd.id = "+filtreEnquetePayLoad.getNatureDomaneId() ; + if (filtreEnquetePayLoad.getNatureDomaneId() != null) { + condition += " AND nd.id = " + filtreEnquetePayLoad.getNatureDomaneId(); } - if(filtreEnquetePayLoad.getTypeDomaineId()!=null){ - condition+= " AND td.id = "+filtreEnquetePayLoad.getTypeDomaineId() ; + if (filtreEnquetePayLoad.getTypeDomaineId() != null) { + condition += " AND td.id = " + filtreEnquetePayLoad.getTypeDomaineId(); } - if(filtreEnquetePayLoad.getTypePersonneId()!=null){ - condition+= " AND tp.id = "+filtreEnquetePayLoad.getTypePersonneId() ; + if (filtreEnquetePayLoad.getTypePersonneId() != null) { + condition += " AND tp.id = " + filtreEnquetePayLoad.getTypePersonneId(); } ///////////////// - if(filtreEnquetePayLoad.getEnqueteurId()!=null){ - condition+= " AND e.user_id = "+filtreEnquetePayLoad.getEnqueteurId() ; + if (filtreEnquetePayLoad.getEnqueteurId() != null) { + condition += " AND e.user_id = " + filtreEnquetePayLoad.getEnqueteurId(); } - if(filtreEnquetePayLoad.getStatutEnquete()!=null){ - condition+= " AND e.status_enquete = "+filtreEnquetePayLoad.getStatutEnquete() ; + if (filtreEnquetePayLoad.getStatutEnquete() != null) { + condition += " AND e.status_enquete = " + filtreEnquetePayLoad.getStatutEnquete(); } - if(filtreEnquetePayLoad.getLitige()!=null){ - condition+= " AND e.litige is "+filtreEnquetePayLoad.getLitige() ; + if (filtreEnquetePayLoad.getLitige() != null) { + condition += " AND e.litige is " + filtreEnquetePayLoad.getLitige(); } - System.out.println(condition); StringBuilder sb = new StringBuilder(sql).append(condition); query = em.createNativeQuery(sb.toString(), EnqueteFiltreResponse.class); List enqueteFiltreResponses = query.getResultList(); - return enqueteFiltreResponses ; + return enqueteFiltreResponses; } @Override public Enquete updateEnquete(EnquetePayLoad enquetePayLoad) throws NotFoundException { - if(enquetePayLoad.getIdBackend() == null ){ + if (enquetePayLoad.getIdBackend() == null) { throw new BadRequestException("Impossible de mettre à jour une enquête ayant un id null."); } - if(!enqueteRepository.existsById(enquetePayLoad.getIdBackend())){ + if (!enqueteRepository.existsById(enquetePayLoad.getIdBackend())) { throw new NotFoundException("Impossible de trouver l'enquête que vous désirez modifier."); } - Optional optionalUser =userRepository.findById(enquetePayLoad.getUserId()); - if(!optionalUser.isPresent()){ + Optional optionalUser = userRepository.findById(enquetePayLoad.getUserId()); + if (!optionalUser.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec un enquêteur inexistant"); } - Optional optionalBloc =blocRepository.findById(enquetePayLoad.getBlocId()); - if(!optionalBloc.isPresent()){ + Optional optionalBloc = blocRepository.findById(enquetePayLoad.getBlocId()); + if (!optionalBloc.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec un bloc inexistant"); } - Optional optionalParcelle =parcelleRepository.findById(enquetePayLoad.getParcelleId()); - if(!optionalParcelle.isPresent()){ + Optional optionalParcelle = parcelleRepository.findById(enquetePayLoad.getParcelleId()); + if (!optionalParcelle.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une enquête avec une parcelle inexistante"); } - Enquete enquete=enqueteRepository.findById(enquetePayLoad.getParcelleId()).get(); + Enquete enquete = enqueteRepository.findById(enquetePayLoad.getParcelleId()).get(); enquete.setBloc(optionalBloc.get()); enquete.setUser(optionalUser.get()); enquete.setParcelle(optionalParcelle.get()); @@ -225,9 +224,9 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public void deleteEnquete(Long id) throws NotFoundException { Optional optionalEnquete = enqueteRepository.findById(id); - if(optionalEnquete.isPresent()){ + if (optionalEnquete.isPresent()) { enqueteRepository.deleteById(optionalEnquete.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver l'enquête que vous désirez supprimer."); } } @@ -244,20 +243,20 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public Optional getEnqueteById(Long id) { - if(enqueteRepository.existsById(id)){ + if (enqueteRepository.existsById(id)) { return enqueteRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver l'enquête."); } } @Override public Enquete validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) { - if(enqueteTraitementPayLoad == null ){ + if (enqueteTraitementPayLoad == null) { throw new BadRequestException("Impossible de valider une enquête ayant un id null."); } - Optional optionalEnquete=enqueteRepository.findById(enqueteTraitementPayLoad.getIdBackend()); - if(!optionalEnquete.isPresent()){ + Optional optionalEnquete = enqueteRepository.findById(enqueteTraitementPayLoad.getIdBackend()); + if (!optionalEnquete.isPresent()) { throw new NotFoundException("Impossible de trouver l'enquête que vous désirez valider."); } optionalEnquete.get().setDateValidation(LocalDate.now()); @@ -268,11 +267,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public Enquete rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) { - if(enqueteTraitementPayLoad.getIdBackend() == null ){ + if (enqueteTraitementPayLoad.getIdBackend() == null) { throw new BadRequestException("Impossible de rejeter une enquête ayant un id null."); } - Optional optionalEnquete=enqueteRepository.findById(enqueteTraitementPayLoad.getIdBackend()); - if(!optionalEnquete.isPresent()){ + Optional optionalEnquete = enqueteRepository.findById(enqueteTraitementPayLoad.getIdBackend()); + if (!optionalEnquete.isPresent()) { throw new NotFoundException("Impossible de trouver l'enquête que vous désirez rejeter."); } optionalEnquete.get().setDateRejet(LocalDate.now()); @@ -286,11 +285,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public List validerEnquete(List enqueteTraitementPayLoads) { List enquetes = new ArrayList<>(); - try{ + try { for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) { enquetes.add(validerEnquete(enqueteTraitementPayLoad)); } - }catch (Exception e){ + } catch (Exception e) { enquetes.add(null); } return enquetes; @@ -299,11 +298,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public List rejeterEnquete(List enqueteTraitementPayLoads) { List enquetes = new ArrayList<>(); - try{ + try { for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) { enquetes.add(rejeterEnquete(enqueteTraitementPayLoad)); } - }catch (Exception e){ + } catch (Exception e) { enquetes.add(null); } return enquetes; @@ -311,11 +310,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public Enquete finaliserEnquete(Long enqueteId) { - if(enqueteId == null ){ + if (enqueteId == null) { throw new BadRequestException("Impossible de finaliser une enquête ayant un id null."); } - Optional optionalEnquete=enqueteRepository.findById(enqueteId); - if(!optionalEnquete.isPresent()){ + Optional optionalEnquete = enqueteRepository.findById(enqueteId); + if (!optionalEnquete.isPresent()) { throw new NotFoundException("Impossible de trouver l'enquête que vous désirez finaliser."); } optionalEnquete.get().setDateFinalisation(LocalDate.now()); @@ -325,11 +324,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public Enquete reglerLitigeEnquete(Long enqueteId) { - if(enqueteId == null ){ + if (enqueteId == null) { throw new BadRequestException("Impossible de régler le litige d'une enquête ayant un id null."); } - Optional optionalEnquete=enqueteRepository.findById(enqueteId); - if(!optionalEnquete.isPresent()){ + Optional optionalEnquete = enqueteRepository.findById(enqueteId); + if (!optionalEnquete.isPresent()) { throw new NotFoundException("Impossible de trouver l'enquête dont vous désirez régler le litige."); } optionalEnquete.get().setDateLitigeResolu(LocalDate.now()); @@ -341,11 +340,11 @@ public class EnqueteServiceImpl implements EnqueteService { @Override public UserDecoupageEnqResponses getDecoupageAdminUserConnecterAndStat() { - String userName=""; + String userName = ""; try { authentication = SecurityContextHolder.getContext().getAuthentication(); userName = authentication.getName(); - }catch (Exception e){ + } catch (Exception e) { return null; } @@ -357,14 +356,14 @@ public class EnqueteServiceImpl implements EnqueteService { System.out.println(user.isAdmin()); List communeEnqResponses = - user.isAdmin() ? communeRepository.getAdminCommuneEnqResponse():communeRepository.getCommuneEnqResponse(user.getStructure().getId()); + user.isAdmin() ? communeRepository.getAdminCommuneEnqResponse() : communeRepository.getCommuneEnqResponse(user.getStructure().getId()); List arrondissementEnqResponses = - user.isAdmin()? arrondissementRepository.getAdminArrondissementEnqResponse() : arrondissementRepository.getArrondissementEnqResponse(user.getStructure().getId()); + user.isAdmin() ? arrondissementRepository.getAdminArrondissementEnqResponse() : arrondissementRepository.getArrondissementEnqResponse(user.getStructure().getId()); List blocEnqResponses = - user.isAdmin() ? blocRepository.getAdminBlocEnqResponse(): blocRepository.getBlocEnqResponse(user.getStructure().getId()); + user.isAdmin() ? blocRepository.getAdminBlocEnqResponse() : blocRepository.getBlocEnqResponse(user.getStructure().getId()); UserDecoupageEnqResponses userDecoupageEnqResponses = new UserDecoupageEnqResponses(); userDecoupageEnqResponses.setCommunes(communeEnqResponses); @@ -383,33 +382,33 @@ public class EnqueteServiceImpl implements EnqueteService { FicheEnquetesResponse ficheEnquetesResponse = new FicheEnquetesResponse(); // classe payload de Enquete - if(optionalEnquete.isPresent()){ - ficheEnquetesResponse = modelMapper.map(optionalEnquete.get(), FicheEnquetesResponse.class); + if (optionalEnquete.isPresent()) { + ficheEnquetesResponse = modelMapper.map(optionalEnquete.get(), FicheEnquetesResponse.class); } List ficheActeurConcerneResponses = new ArrayList<>(); - if(!acteurConcernes.isEmpty()){ + if (!acteurConcernes.isEmpty()) { acteurConcernes.stream().forEach(acteurConcerne -> ficheActeurConcerneResponses.add(modelMapper.map(acteurConcerne, FicheActeurConcerneResponse.class))); } List caracteristiqueParcelles = caracteristiqueParcelleRepository.findAllByEnquete_Id(enqueteId); List caracteristiqueParcelleResponses = new ArrayList<>(); - if(!caracteristiqueParcelles.isEmpty()){ + if (!caracteristiqueParcelles.isEmpty()) { caracteristiqueParcelles.stream().forEach(caracteristiqueParcelle -> caracteristiqueParcelleResponses.add(modelMapper.map(caracteristiqueParcelle, FicheCaracteristiqueParcelleResponse.class))); } List enqueteBatimentResponses = new ArrayList<>(); List enqueteBatiments = enqueteBatimentRepository.findAllByEnquete_Id(enqueteId); - if(!enqueteBatiments.isEmpty()){ + if (!enqueteBatiments.isEmpty()) { enqueteBatiments.stream().forEach(enqueteBatiment -> enqueteBatimentResponses.add(modelMapper.map(enqueteBatiment, FicheEnqueteBatimentResponse.class))); } List enqueteUniteLogementResponses = new ArrayList<>(); List enqueteUniteLogements = enqueteUniteLogementRepository.findAllByEnquete_Id(enqueteId); - if(!enqueteUniteLogements.isEmpty()){ + if (!enqueteUniteLogements.isEmpty()) { enqueteUniteLogements.stream().forEach(enqueteUniteLogement -> enqueteUniteLogementResponses.add(modelMapper.map(enqueteUniteLogement, FicheEnqueteUniteLogementResponse.class))); } @@ -420,7 +419,7 @@ public class EnqueteServiceImpl implements EnqueteService { ficheEnqueteResponse.setEnquete(ficheEnquetesResponse); ficheEnqueteResponse.setActeurConcernes(ficheActeurConcerneResponses); - return ficheEnqueteResponse ; + return ficheEnqueteResponse; } @Override diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java index 7f88f0a..b559b2d 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java @@ -44,51 +44,51 @@ public class ParcelleServiceImpl implements ParcelleService { @Override public Parcelle createParcelle(ParcellePayLoad parcellePayLoad) throws BadRequestException { Optional optionalNatureDomaine = natureDomaineRepository.findById(parcellePayLoad.getNatureDomaineId()); - if(!optionalNatureDomaine.isPresent()){ + if (!optionalNatureDomaine.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec une nature de domaine inexistant"); } - Optional optionalQuartier =quartierRepository.findById(parcellePayLoad.getQuartierId()); - if(!optionalQuartier.isPresent()){ + Optional optionalQuartier = quartierRepository.findById(parcellePayLoad.getQuartierId()); + if (!optionalQuartier.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec un quartier/village inexistant"); } - Optional optionalSituationGeographique =situationGeographiqueRepository.findById(parcellePayLoad.getSituationGeographiqueId()); - if(!optionalSituationGeographique.isPresent()){ + Optional optionalSituationGeographique = situationGeographiqueRepository.findById(parcellePayLoad.getSituationGeographiqueId()); + if (!optionalSituationGeographique.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec une situation géographique inexistant"); } - Parcelle parcelle=getParcelle(parcellePayLoad, optionalSituationGeographique, optionalNatureDomaine); + Parcelle parcelle = getParcelle(parcellePayLoad, optionalSituationGeographique, optionalNatureDomaine); return parcelleRepository.save(parcelle); } @Override public Parcelle updateParcelle(ParcellePayLoad parcellePayLoad) throws NotFoundException { Optional optionalParcelle = parcelleRepository.findById(parcellePayLoad.getIdBackend()); - if(!optionalParcelle.isPresent()){ + if (!optionalParcelle.isPresent()) { throw new NotFoundException("Impossible de trouver la parcelle que vous désirer modifier"); } Optional optionalNatureDomaine = natureDomaineRepository.findById(parcellePayLoad.getNatureDomaineId()); - if(!optionalNatureDomaine.isPresent()){ + if (!optionalNatureDomaine.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec une nature de domaine inexistante"); } - Optional optionalQuartier =quartierRepository.findById(parcellePayLoad.getQuartierId()); - if(!optionalQuartier.isPresent()){ + Optional optionalQuartier = quartierRepository.findById(parcellePayLoad.getQuartierId()); + if (!optionalQuartier.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec un quartier/village inexistant"); } - Optional optionalSituationGeographique =situationGeographiqueRepository.findById(parcellePayLoad.getSituationGeographiqueId()); - if(!optionalSituationGeographique.isPresent()){ + Optional optionalSituationGeographique = situationGeographiqueRepository.findById(parcellePayLoad.getSituationGeographiqueId()); + if (!optionalSituationGeographique.isPresent()) { throw new BadRequestException("Impossible d'enregistrer une parcelle avec une situation géographique inexistant"); } - Parcelle parcelle=getParcelle(optionalParcelle.get(),parcellePayLoad,optionalSituationGeographique, optionalNatureDomaine); + Parcelle parcelle = getParcelle(optionalParcelle.get(), parcellePayLoad, optionalSituationGeographique, optionalNatureDomaine); return parcelleRepository.save(parcelle); } @Override public void deleteParcelle(Long id) throws NotFoundException { Optional optionalParcelle = parcelleRepository.findById(id); - if(optionalParcelle.isPresent()){ + if (optionalParcelle.isPresent()) { parcelleRepository.deleteById(optionalParcelle.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la parcelle que vous désirez supprimer."); } } @@ -105,15 +105,16 @@ public class ParcelleServiceImpl implements ParcelleService { @Override public Optional getParcelleById(Long id) { - if(parcelleRepository.existsById(id)){ + if (parcelleRepository.existsById(id)) { return parcelleRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver l'enquête."); } } - private Parcelle getParcelle(ParcellePayLoad parcellePayLoad, Optional optionalSituationGeographique, Optional optionalNatureDomaine) { - StringBuilder coordonnees =new StringBuilder(); - Parcelle parcelle=new Parcelle(); + + private Parcelle getParcelle(ParcellePayLoad parcellePayLoad, Optional optionalSituationGeographique, Optional optionalNatureDomaine) { + StringBuilder coordonnees = new StringBuilder(); + Parcelle parcelle = new Parcelle(); parcelle.setP(parcellePayLoad.getP()); parcelle.setI(parcellePayLoad.getI()); parcelle.setQ(parcellePayLoad.getQ()); @@ -145,8 +146,9 @@ public class ParcelleServiceImpl implements ParcelleService { // } return parcelle; } - private Parcelle getParcelle(Parcelle parcelle, ParcellePayLoad parcellePayLoad, Optional optionalSituationGeographique, Optional optionalNatureDomaine) { - StringBuilder coordonnees =new StringBuilder(); + + private Parcelle getParcelle(Parcelle parcelle, ParcellePayLoad parcellePayLoad, Optional optionalSituationGeographique, Optional optionalNatureDomaine) { + StringBuilder coordonnees = new StringBuilder(); parcelle.setP(parcellePayLoad.getP()); parcelle.setI(parcellePayLoad.getI()); parcelle.setQ(parcellePayLoad.getQ()); @@ -180,6 +182,4 @@ public class ParcelleServiceImpl implements ParcelleService { } - - } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/TpeServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/TpeServiceImpl.java index d9a0c14..c0e8c30 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/TpeServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/TpeServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class TpeServiceImpl implements TpeService { @@ -27,40 +28,40 @@ public class TpeServiceImpl implements TpeService { @Override public Tpe createTpe(Tpe tpe) throws BadRequestException { String codeEquipe; - do{ + do { codeEquipe = StringService.getCodeEquipe(); - }while (tpeRepository.existsDistinctByCodeEquipe(codeEquipe)); + } while (tpeRepository.existsDistinctByCodeEquipe(codeEquipe)); tpe.setCodeEquipe(codeEquipe); - if(tpe.getId() != null ){ + if (tpe.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau tpe ayant un id non null."); } - if(tpeRepository.existsDistinctByIdentifier(tpe.getIdentifier())){ + if (tpeRepository.existsDistinctByIdentifier(tpe.getIdentifier())) { return tpeRepository.findDistinctByIdentifier(tpe.getIdentifier()).get(); - }else{ - return tpeRepository.save(tpe); + } else { + return tpeRepository.save(tpe); } } @Override public Tpe updateTpe(Long id, Tpe tpe) throws NotFoundException { - if(tpe.getId() == null ){ + if (tpe.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau tpe ayant un id null."); } - if(!tpeRepository.existsById(tpe.getId())){ + if (!tpeRepository.existsById(tpe.getId())) { throw new NotFoundException("Impossible de trouver le tpe spécifié dans notre base de données."); } - return tpeRepository.save(tpe); + return tpeRepository.save(tpe); } @Override public void deleteTpe(Long id) throws NotFoundException { Optional tpeOptional = tpeRepository.findById(id); - if(tpeOptional.isPresent()){ + if (tpeOptional.isPresent()) { tpeRepository.deleteById(tpeOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le tpe spécifié dans notre base de données."); } } @@ -77,9 +78,9 @@ public class TpeServiceImpl implements TpeService { @Override public Optional getTpeById(Long id) { - if(tpeRepository.existsById(id)){ + if (tpeRepository.existsById(id)) { return tpeRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le tpe spécifié dans la base de données."); } @@ -87,18 +88,18 @@ public class TpeServiceImpl implements TpeService { @Override public Optional getTepByIdentifier(String identifier) { - if(tpeRepository.existsDistinctByIdentifier(identifier)){ + if (tpeRepository.existsDistinctByIdentifier(identifier)) { return tpeRepository.findDistinctByIdentifier(identifier); - }else{ + } else { throw new NotFoundException("Impossible de trouver le tpe lié à cette clé dans la base de données."); } } @Override public List getTpeListByModel(String model) { - if(model != null){ + if (model != null) { return tpeRepository.findAllByModel(model); - }else{ + } else { throw new BadRequestException("Vous devez spécifier le model du tpe."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java index f1b30b2..ba265b7 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java @@ -35,78 +35,78 @@ public class BlocServiceImpl implements BlocService { @Override public Bloc createBloc(Bloc bloc) throws BadRequestException { - if(bloc.getId() != null ){ + if (bloc.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau bloc ayant un id non null."); } String idBlocParArrondissement = getIdBlocParArrondissementValue(bloc); bloc.setIdBlocParArrondissement(idBlocParArrondissement); - if(bloc.getStructure() == null){ + if (bloc.getStructure() == null) { bloc.setCote(getCoteValue(bloc, idBlocParArrondissement, null)); - }else{ + } else { bloc.setCote(getCoteValue(bloc, idBlocParArrondissement, bloc.getStructure().getId())); } - if(bloc.getQuartier() != null){ + if (bloc.getQuartier() != null) { bloc.setCoteq(getCoteQuartierByCoteBloc(bloc.getCote(), bloc.getQuartier())); } - if(bloc.getSecteurDecoupage()!=null) { + if (bloc.getSecteurDecoupage() != null) { bloc.setSecteur(bloc.getSecteurDecoupage().getSecteur()); } - return blocRepository.save(bloc); + return blocRepository.save(bloc); } private String getCoteQuartierByCoteBloc(String cote, Quartier quartier) { - if(cote == null) { + if (cote == null) { throw new BadRequestException("Le bloc spécifié ne dispose pas encore de code."); - }else{ - return new StringBuilder().append(cote.substring(0,3)).append(quartier.getCode()).toString(); + } else { + return new StringBuilder().append(cote.substring(0, 3)).append(quartier.getCode()).toString(); } } private String getCoteValue(Bloc bloc, String idBlocParArrondissement, Long structure_id) { StringBuilder builder = new StringBuilder(); - if(structure_id == null){ + if (structure_id == null) { structure_id = blocRepository.getStructureId(bloc.getArrondissement().getId()); - if(structure_id == null){ + if (structure_id == null) { throw new NotFoundException("Aucune structure n'est associé à ce bloc. Il n'est donc pas possible d'enregistrer ce bloc. Vous devez donc attribué ce bloc à une structure."); } } Optional structureOptional = structureService.getStructureById(structure_id); - if(structureOptional.isPresent()){ + if (structureOptional.isPresent()) { builder.append(structureOptional.get().getCode()); builder.append(bloc.getArrondissement().getCode()); builder.append(idBlocParArrondissement); return builder.toString(); - }else { + } else { throw new NotFoundException("Impossible de trouver la structure associée à ce bloc"); } } private String getIdBlocParArrondissementValue(Bloc bloc) { - int a = countAllBlocByArrondissement(bloc.getArrondissement().getId()) + 1; + int a = countAllBlocByArrondissement(bloc.getArrondissement().getId()) + 1; return stringService.generateIntInTwoPositions(a); } @Override public Bloc updateBloc(Long id, Bloc bloc) throws NotFoundException { - if(bloc.getId() == null ){ + if (bloc.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau bloc ayant un id null."); } - if(!blocRepository.existsById(bloc.getId())){ + if (!blocRepository.existsById(bloc.getId())) { throw new NotFoundException("Impossible de trouver le bloc spécifié dans notre base de données."); } - return blocRepository.save(bloc); + return blocRepository.save(bloc); } @Override public void deleteBloc(Long id) throws NotFoundException { Optional blocOptional = blocRepository.findById(id); - if(blocOptional.isPresent()){ + if (blocOptional.isPresent()) { blocRepository.deleteById(blocOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le bloc spécifié dans notre base de données."); } } @@ -126,9 +126,9 @@ public class BlocServiceImpl implements BlocService { @Override public List getBlocsByStructure(Long idStructure) { - if(structureService.getStructureById(idStructure).isPresent()){ + if (structureService.getStructureById(idStructure).isPresent()) { return blocRepository.getBlocsByStructure(idStructure); - }else{ + } else { throw new NotFoundException("Impossible de trouver la structure spécifiée."); } } @@ -145,18 +145,18 @@ public class BlocServiceImpl implements BlocService { @Override public Optional getBlocById(Long id) { - if(blocRepository.existsById(id)){ + if (blocRepository.existsById(id)) { return blocRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le bloc spécifié dans la base de données."); } } @Override public int countAllBlocByArrondissement(Long idArrondissement) { - if(arrondissementService.getArrondissementById(idArrondissement).isPresent()){ + if (arrondissementService.getArrondissementById(idArrondissement).isPresent()) { return blocRepository.countAllBlocByArrondissement(idArrondissement); - }else{ + } else { throw new NotFoundException("Impossible de trouver l'arrondissement' spécifié dans la base de données."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ModeAcquisitionServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ModeAcquisitionServiceImpl.java index aabd48f..f460e06 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ModeAcquisitionServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ModeAcquisitionServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class ModeAcquisitionServiceImpl implements ModeAcquisitionService { @@ -22,29 +23,29 @@ public class ModeAcquisitionServiceImpl implements ModeAcquisitionService { @Override public ModeAcquisition createModeAcquisition(ModeAcquisition modeAcquisition) throws BadRequestException { - if(modeAcquisition.getId() != null ){ + if (modeAcquisition.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau mode d'acquisition ayant un id non null."); } - return modeAcquisitionRepository.save(modeAcquisition); + return modeAcquisitionRepository.save(modeAcquisition); } @Override public ModeAcquisition updateModeAcquisition(Long id, ModeAcquisition modeAcquisition) throws NotFoundException { - if(modeAcquisition.getId() == null ){ + if (modeAcquisition.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau mode d'acquisition ayant un id null."); } - if(!modeAcquisitionRepository.existsById(modeAcquisition.getId())){ + if (!modeAcquisitionRepository.existsById(modeAcquisition.getId())) { throw new NotFoundException("Impossible de trouver le mode d'acquisition spécifié dans notre base de données."); } - return modeAcquisitionRepository.save(modeAcquisition); + return modeAcquisitionRepository.save(modeAcquisition); } @Override public void deleteModeAcquisition(Long id) throws NotFoundException { Optional modeAcquisitionOptional = modeAcquisitionRepository.findById(id); - if(modeAcquisitionOptional.isPresent()){ + if (modeAcquisitionOptional.isPresent()) { modeAcquisitionRepository.deleteById(modeAcquisitionOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le mode d'acquisition spécifié dans notre base de données."); } } @@ -61,9 +62,9 @@ public class ModeAcquisitionServiceImpl implements ModeAcquisitionService { @Override public Optional getModeAcquisitionById(Long id) { - if(modeAcquisitionRepository.existsById(id)){ + if (modeAcquisitionRepository.existsById(id)) { return modeAcquisitionRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le mode d'acquisition spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/NatureDomaineServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/NatureDomaineServiceImpl.java index 79e6d7f..0015feb 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/NatureDomaineServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/NatureDomaineServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class NatureDomaineServiceImpl implements NatureDomaineService { @@ -22,29 +23,29 @@ public class NatureDomaineServiceImpl implements NatureDomaineService { @Override public NatureDomaine createNatureDomaine(NatureDomaine natureDomaine) throws BadRequestException { - if(natureDomaine.getId() != null ){ + if (natureDomaine.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle nature domaine ayant un id non null."); } - return natureDomaineRepository.save(natureDomaine); + return natureDomaineRepository.save(natureDomaine); } @Override public NatureDomaine updateNatureDomaine(Long id, NatureDomaine natureDomaine) throws NotFoundException { - if(natureDomaine.getId() == null ){ + if (natureDomaine.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle nature domaine ayant un id null."); } - if(!natureDomaineRepository.existsById(natureDomaine.getId())){ + if (!natureDomaineRepository.existsById(natureDomaine.getId())) { throw new NotFoundException("Impossible de trouver la nature domaine spécifiée dans notre base de données."); } - return natureDomaineRepository.save(natureDomaine); + return natureDomaineRepository.save(natureDomaine); } @Override public void deleteNatureDomaine(Long id) throws NotFoundException { Optional natureDomaineOptional = natureDomaineRepository.findById(id); - if(natureDomaineOptional.isPresent()){ + if (natureDomaineOptional.isPresent()) { natureDomaineRepository.deleteById(natureDomaineOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nature domaine spécifiée dans notre base de données."); } } @@ -61,9 +62,9 @@ public class NatureDomaineServiceImpl implements NatureDomaineService { @Override public Optional getNatureDomaineById(Long id) { - if(natureDomaineRepository.existsById(id)){ + if (natureDomaineRepository.existsById(id)) { return natureDomaineRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nature domaine spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/PositionRepresentationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/PositionRepresentationServiceImpl.java index aaf9d4d..8d833da 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/PositionRepresentationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/PositionRepresentationServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class PositionRepresentationServiceImpl implements PositionRepresentationService { @@ -22,29 +23,29 @@ public class PositionRepresentationServiceImpl implements PositionRepresentation @Override public PositionRepresentation createPositionRepresentation(PositionRepresentation positionRepresentation) throws BadRequestException { - if(positionRepresentation.getId() != null ){ + if (positionRepresentation.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle position de représentation ayant un id non null."); } - return positionRepresentationRepository.save(positionRepresentation); + return positionRepresentationRepository.save(positionRepresentation); } @Override public PositionRepresentation updatePositionRepresentation(Long id, PositionRepresentation positionRepresentation) throws NotFoundException { - if(positionRepresentation.getId() == null ){ + if (positionRepresentation.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle position de représentation ayant un id null."); } - if(!positionRepresentationRepository.existsById(positionRepresentation.getId())){ + if (!positionRepresentationRepository.existsById(positionRepresentation.getId())) { throw new NotFoundException("Impossible de trouver la position de représentation spécifiée dans notre base de données."); } - return positionRepresentationRepository.save(positionRepresentation); + return positionRepresentationRepository.save(positionRepresentation); } @Override public void deletePositionRepresentation(Long id) throws NotFoundException { Optional positionRepresentationOptional = positionRepresentationRepository.findById(id); - if(positionRepresentationOptional.isPresent()){ + if (positionRepresentationOptional.isPresent()) { positionRepresentationRepository.deleteById(positionRepresentationOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la position de représentation spécifiée dans notre base de données."); } } @@ -61,9 +62,9 @@ public class PositionRepresentationServiceImpl implements PositionRepresentation @Override public Optional getPositionRepresentationById(Long id) { - if(positionRepresentationRepository.existsById(id)){ + if (positionRepresentationRepository.existsById(id)) { return positionRepresentationRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la position de représentation spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ProfessionServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ProfessionServiceImpl.java index 14244b2..b875eee 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ProfessionServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/ProfessionServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class ProfessionServiceImpl implements ProfessionService { @@ -22,29 +23,29 @@ public class ProfessionServiceImpl implements ProfessionService { @Override public Profession createProfession(Profession profession) throws BadRequestException { - if(profession.getId() != null ){ + if (profession.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle profession ayant un id non null."); } - return professionRepository.save(profession); + return professionRepository.save(profession); } @Override public Profession updateProfession(Long id, Profession profession) throws NotFoundException { - if(profession.getId() == null ){ + if (profession.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle profession ayant un id null."); } - if(!professionRepository.existsById(profession.getId())){ + if (!professionRepository.existsById(profession.getId())) { throw new NotFoundException("Impossible de trouver la profession spécifiée dans notre base de données."); } - return professionRepository.save(profession); + return professionRepository.save(profession); } @Override public void deleteProfession(Long id) throws NotFoundException { Optional professionOptional = professionRepository.findById(id); - if(professionOptional.isPresent()){ + if (professionOptional.isPresent()) { professionRepository.deleteById(professionOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la profession spécifiée dans notre base de données."); } } @@ -61,9 +62,9 @@ public class ProfessionServiceImpl implements ProfessionService { @Override public Optional getProfessionById(Long id) { - if(professionRepository.existsById(id)){ + if (professionRepository.existsById(id)) { return professionRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la profession spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationGeographiqueServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationGeographiqueServiceImpl.java index e417837..4cc4644 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationGeographiqueServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationGeographiqueServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class SituationGeographiqueServiceImpl implements SituationGeographiqueService { @@ -22,29 +23,29 @@ public class SituationGeographiqueServiceImpl implements SituationGeographiqueSe @Override public SituationGeographique createSituationGeographique(SituationGeographique situationGeographique) throws BadRequestException { - if(situationGeographique.getId() != null ){ + if (situationGeographique.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle situation géographique ayant un id non null."); } - return situationGeographiqueRepository.save(situationGeographique); + return situationGeographiqueRepository.save(situationGeographique); } @Override public SituationGeographique updateSituationGeographique(Long id, SituationGeographique situationGeographique) throws NotFoundException { - if(situationGeographique.getId() == null ){ + if (situationGeographique.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle situation géographique ayant un id null."); } - if(!situationGeographiqueRepository.existsById(situationGeographique.getId())){ + if (!situationGeographiqueRepository.existsById(situationGeographique.getId())) { throw new NotFoundException("Impossible de trouver la situation géographique spécifiée dans notre base de données."); } - return situationGeographiqueRepository.save(situationGeographique); + return situationGeographiqueRepository.save(situationGeographique); } @Override public void deleteSituationGeographique(Long id) throws NotFoundException { Optional situationGeographiqueOptional = situationGeographiqueRepository.findById(id); - if(situationGeographiqueOptional.isPresent()){ + if (situationGeographiqueOptional.isPresent()) { situationGeographiqueRepository.deleteById(situationGeographiqueOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la situation géographique spécifiée dans notre base de données."); } } @@ -61,9 +62,9 @@ public class SituationGeographiqueServiceImpl implements SituationGeographiqueSe @Override public Optional getSituationGeographiqueById(Long id) { - if(situationGeographiqueRepository.existsById(id)){ + if (situationGeographiqueRepository.existsById(id)) { return situationGeographiqueRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la situation géographique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationMatrimonialeServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationMatrimonialeServiceImpl.java index 8e3c424..42d2706 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationMatrimonialeServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SituationMatrimonialeServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class SituationMatrimonialeServiceImpl implements SituationMatrimonialeService { @@ -22,29 +23,29 @@ public class SituationMatrimonialeServiceImpl implements SituationMatrimonialeSe @Override public SituationMatrimoniale createSituationMatrimoniale(SituationMatrimoniale situationMatrimoniale) throws BadRequestException { - if(situationMatrimoniale.getId() != null ){ + if (situationMatrimoniale.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle situation matrimoniale ayant un id non null."); } - return situationMatrimonialeRepository.save(situationMatrimoniale); + return situationMatrimonialeRepository.save(situationMatrimoniale); } @Override public SituationMatrimoniale updateSituationMatrimoniale(Long id, SituationMatrimoniale situationMatrimoniale) throws NotFoundException { - if(situationMatrimoniale.getId() == null ){ + if (situationMatrimoniale.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle situation matrimoniale ayant un id null."); } - if(!situationMatrimonialeRepository.existsById(situationMatrimoniale.getId())){ + if (!situationMatrimonialeRepository.existsById(situationMatrimoniale.getId())) { throw new NotFoundException("Impossible de trouver la situation matrimoniale spécifiée dans notre base de données."); } - return situationMatrimonialeRepository.save(situationMatrimoniale); + return situationMatrimonialeRepository.save(situationMatrimoniale); } @Override public void deleteSituationMatrimoniale(Long id) throws NotFoundException { Optional situationMatrimonialeOptional = situationMatrimonialeRepository.findById(id); - if(situationMatrimonialeOptional.isPresent()){ + if (situationMatrimonialeOptional.isPresent()) { situationMatrimonialeRepository.deleteById(situationMatrimonialeOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la situation matrimoniale spécifiée dans notre base de données."); } } @@ -61,9 +62,9 @@ public class SituationMatrimonialeServiceImpl implements SituationMatrimonialeSe @Override public Optional getSituationMatrimonialeById(Long id) { - if(situationMatrimonialeRepository.existsById(id)){ + if (situationMatrimonialeRepository.existsById(id)) { return situationMatrimonialeRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la situation matrimoniale spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SourceDroitServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SourceDroitServiceImpl.java index b178ded..5bedddc 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SourceDroitServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/SourceDroitServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class SourceDroitServiceImpl implements SourceDroitService { @@ -22,29 +23,29 @@ public class SourceDroitServiceImpl implements SourceDroitService { @Override public SourceDroit createSourceDroit(SourceDroit sourceDroit) throws BadRequestException { - if(sourceDroit.getId() != null ){ + if (sourceDroit.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle source de droit ayant un id non null."); } - return sourceDroitRepository.save(sourceDroit); + return sourceDroitRepository.save(sourceDroit); } @Override public SourceDroit updateSourceDroit(Long id, SourceDroit sourceDroit) throws NotFoundException { - if(sourceDroit.getId() == null ){ + if (sourceDroit.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle source de droit ayant un id null."); } - if(!sourceDroitRepository.existsById(sourceDroit.getId())){ + if (!sourceDroitRepository.existsById(sourceDroit.getId())) { throw new NotFoundException("Impossible de trouver la source de droit spécifiée dans notre base de données."); } - return sourceDroitRepository.save(sourceDroit); + return sourceDroitRepository.save(sourceDroit); } @Override public void deleteSourceDroit(Long id) throws NotFoundException { Optional sourceDroitOptional = sourceDroitRepository.findById(id); - if(sourceDroitOptional.isPresent()){ + if (sourceDroitOptional.isPresent()) { sourceDroitRepository.deleteById(sourceDroitOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la source de droit spécifiée dans notre base de données."); } } @@ -62,9 +63,9 @@ public class SourceDroitServiceImpl implements SourceDroitService { @Override public Optional getSourceDroitById(Long id) { - if(sourceDroitRepository.existsById(id)){ + if (sourceDroitRepository.existsById(id)) { return sourceDroitRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la source de droit spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/StructureServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/StructureServiceImpl.java index 130f81a..1c4ea0f 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/StructureServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/StructureServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class StructureServiceImpl implements StructureService { @@ -23,12 +24,12 @@ public class StructureServiceImpl implements StructureService { @Override public Structure createStructure(Structure structure) throws BadRequestException { - if(structure.getId() != null ){ + if (structure.getId() != null) { throw new BadRequestException("Impossible de créer une structure ayant un id non null."); } StringBuilder builder = new StringBuilder(); builder.append("C"); - builder.append(structureRepository.getLastRecordId()+1); + builder.append(structureRepository.getLastRecordId() + 1); structure.setCode(builder.toString()); return structureRepository.save(structure); } @@ -38,10 +39,10 @@ public class StructureServiceImpl implements StructureService { System.out.println("structure = " + structure); - if(structure.getId() == null ){ + if (structure.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une structure ayant un id null."); } - if(!structureRepository.existsById(structure.getId())){ + if (!structureRepository.existsById(structure.getId())) { throw new NotFoundException("Impossible de trouver la structure spécifiée dans notre base de données."); } structureRepository.save(structure); @@ -54,9 +55,9 @@ public class StructureServiceImpl implements StructureService { @Override public void deleteStructure(Long id) throws NotFoundException { Optional structureOptional = structureRepository.findById(id); - if(structureOptional.isPresent()){ + if (structureOptional.isPresent()) { structureRepository.deleteById(structureOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la structure spécifiée dans notre base de données."); } } @@ -78,9 +79,9 @@ public class StructureServiceImpl implements StructureService { @Override public Optional getStructureById(Long id) { - if(structureRepository.existsById(id)){ + if (structureRepository.existsById(id)) { return structureRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la structure spécifiée dans la base de données."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeContestationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeContestationServiceImpl.java index 99bc792..88647ca 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeContestationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeContestationServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class TypeContestationServiceImpl implements TypeContestationService { @@ -22,29 +23,29 @@ public class TypeContestationServiceImpl implements TypeContestationService { @Override public TypeContestation createTypeContestation(TypeContestation typeContestation) throws BadRequestException { - if(typeContestation.getId() != null ){ + if (typeContestation.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de contestation ayant un id non null."); } - return typeContestationRepository.save(typeContestation); + return typeContestationRepository.save(typeContestation); } @Override public TypeContestation updateTypeContestation(Long id, TypeContestation typeContestation) throws NotFoundException { - if(typeContestation.getId() == null ){ + if (typeContestation.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type de contestation ayant un id null."); } - if(!typeContestationRepository.existsById(typeContestation.getId())){ + if (!typeContestationRepository.existsById(typeContestation.getId())) { throw new NotFoundException("Impossible de trouver le type de contestation spécifié dans notre base de données."); } - return typeContestationRepository.save(typeContestation); + return typeContestationRepository.save(typeContestation); } @Override public void deleteTypeContestation(Long id) throws NotFoundException { Optional typeContestationOptional = typeContestationRepository.findById(id); - if(typeContestationOptional.isPresent()){ + if (typeContestationOptional.isPresent()) { typeContestationRepository.deleteById(typeContestationOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de contestation spécifié dans notre base de données."); } } @@ -61,9 +62,9 @@ public class TypeContestationServiceImpl implements TypeContestationService { @Override public Optional getTypeContestationById(Long id) { - if(typeContestationRepository.existsById(id)){ + if (typeContestationRepository.existsById(id)) { return typeContestationRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de contestation spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeDomaineServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeDomaineServiceImpl.java index 25cf9cb..07aba34 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeDomaineServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeDomaineServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class TypeDomaineServiceImpl implements TypeDomaineService { @@ -22,29 +23,29 @@ public class TypeDomaineServiceImpl implements TypeDomaineService { @Override public TypeDomaine createTypeDomaine(TypeDomaine typeDomaine) throws BadRequestException { - if(typeDomaine.getId() != null ){ + if (typeDomaine.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de domaine ayant un id non null."); } - return typeDomaineRepository.save(typeDomaine); + return typeDomaineRepository.save(typeDomaine); } @Override public TypeDomaine updateTypeDomaine(Long id, TypeDomaine typeDomaine) throws NotFoundException { - if(typeDomaine.getId() == null ){ + if (typeDomaine.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type de domaine ayant un id null."); } - if(!typeDomaineRepository.existsById(typeDomaine.getId())){ + if (!typeDomaineRepository.existsById(typeDomaine.getId())) { throw new NotFoundException("Impossible de trouver le type de domaine spécifié dans notre base de données."); } - return typeDomaineRepository.save(typeDomaine); + return typeDomaineRepository.save(typeDomaine); } @Override public void deleteTypeDomaine(Long id) throws NotFoundException { Optional typeDomaineOptional = typeDomaineRepository.findById(id); - if(typeDomaineOptional.isPresent()){ + if (typeDomaineOptional.isPresent()) { typeDomaineRepository.deleteById(typeDomaineOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de domaine spécifié dans notre base de données."); } } @@ -61,9 +62,9 @@ public class TypeDomaineServiceImpl implements TypeDomaineService { @Override public Optional getTypeDomaineById(Long id) { - if(typeDomaineRepository.existsById(id)){ + if (typeDomaineRepository.existsById(id)) { return typeDomaineRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de domaine spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePersonneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePersonneServiceImpl.java index c3fc09e..9f53e59 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePersonneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePersonneServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class TypePersonneServiceImpl implements TypePersonneService { @@ -22,29 +23,29 @@ public class TypePersonneServiceImpl implements TypePersonneService { @Override public TypePersonne createTypePersonne(TypePersonne typePersonne) throws BadRequestException { - if(typePersonne.getId() != null ){ + if (typePersonne.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de personne ayant un id non null."); } - return typePersonneRepository.save(typePersonne); + return typePersonneRepository.save(typePersonne); } @Override public TypePersonne updateTypePersonne(Long id, TypePersonne typePersonne) throws NotFoundException { - if(typePersonne.getId() == null ){ + if (typePersonne.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type de personne ayant un id null."); } - if(!typePersonneRepository.existsById(typePersonne.getId())){ + if (!typePersonneRepository.existsById(typePersonne.getId())) { throw new NotFoundException("Impossible de trouver le type de personne spécifié dans notre base de données."); } - return typePersonneRepository.save(typePersonne); + return typePersonneRepository.save(typePersonne); } @Override public void deleteTypePersonne(Long id) throws NotFoundException { Optional typePersonneOptional = typePersonneRepository.findById(id); - if(typePersonneOptional.isPresent()){ + if (typePersonneOptional.isPresent()) { typePersonneRepository.deleteById(typePersonneOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de personne spécifié dans notre base de données."); } } @@ -61,9 +62,9 @@ public class TypePersonneServiceImpl implements TypePersonneService { @Override public Optional getTypePersonneById(Long id) { - if(typePersonneRepository.existsById(id)){ + if (typePersonneRepository.existsById(id)) { return typePersonneRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de personne spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePieceServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePieceServiceImpl.java index edd6e3e..2f9af62 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePieceServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypePieceServiceImpl.java @@ -23,29 +23,29 @@ public class TypePieceServiceImpl implements TypePieceService { @Override public TypePiece createTypePiece(TypePiece typePiece) throws BadRequestException { - if(typePiece.getId() != null ){ + if (typePiece.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de pièce ayant un id non null."); } - return typePieceRepository.save(typePiece); + return typePieceRepository.save(typePiece); } @Override public TypePiece updateTypePiece(Long id, TypePiece typePiece) throws NotFoundException { - if(typePiece.getId() == null ){ + if (typePiece.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type de pièce ayant un id null."); } - if(!typePieceRepository.existsById(typePiece.getId())){ + if (!typePieceRepository.existsById(typePiece.getId())) { throw new NotFoundException("Impossible de trouver le type de pièce spécifié dans notre base de données."); } - return typePieceRepository.save(typePiece); + return typePieceRepository.save(typePiece); } @Override public void deleteTypePiece(Long id) throws NotFoundException { Optional typePieceOptional = typePieceRepository.findById(id); - if(typePieceOptional.isPresent()){ + if (typePieceOptional.isPresent()) { typePieceRepository.deleteById(typePieceOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de pièce spécifié dans notre base de données."); } } @@ -62,9 +62,9 @@ public class TypePieceServiceImpl implements TypePieceService { @Override public Optional getTypePieceById(Long id) { - if(typePieceRepository.existsById(id)){ + if (typePieceRepository.existsById(id)) { return typePieceRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de pièce spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeRepresentationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeRepresentationServiceImpl.java index c66bad7..ffb1898 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeRepresentationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/TypeRepresentationServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class TypeRepresentationServiceImpl implements TypeRepresentationService { @@ -22,29 +23,29 @@ public class TypeRepresentationServiceImpl implements TypeRepresentationService @Override public TypeRepresentation createTypeRepresentation(TypeRepresentation typeRepresentation) throws BadRequestException { - if(typeRepresentation.getId() != null ){ + if (typeRepresentation.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de représentation ayant un id non null."); } - return typeRepresentationRepository.save(typeRepresentation); + return typeRepresentationRepository.save(typeRepresentation); } @Override public TypeRepresentation updateTypeRepresentation(Long id, TypeRepresentation typeRepresentation) throws NotFoundException { - if(typeRepresentation.getId() == null ){ + if (typeRepresentation.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type de représentation ayant un id null."); } - if(!typeRepresentationRepository.existsById(typeRepresentation.getId())){ + if (!typeRepresentationRepository.existsById(typeRepresentation.getId())) { throw new NotFoundException("Impossible de trouver le type de représentation spécifié dans notre base de données."); } - return typeRepresentationRepository.save(typeRepresentation); + return typeRepresentationRepository.save(typeRepresentation); } @Override public void deleteTypeRepresentation(Long id) throws NotFoundException { Optional typeRepresentationOptional = typeRepresentationRepository.findById(id); - if(typeRepresentationOptional.isPresent()){ + if (typeRepresentationOptional.isPresent()) { typeRepresentationRepository.deleteById(typeRepresentationOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de représentation spécifié dans notre base de données."); } } @@ -61,9 +62,9 @@ public class TypeRepresentationServiceImpl implements TypeRepresentationService @Override public Optional getTypeRepresentationById(Long id) { - if(typeRepresentationRepository.existsById(id)){ + if (typeRepresentationRepository.existsById(id)) { return typeRepresentationRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type de représentation spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/notification/EmailServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/notification/EmailServiceImpl.java index 833b722..18a0237 100644 --- a/src/main/java/io/gmss/fiscad/implementations/notification/EmailServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/notification/EmailServiceImpl.java @@ -28,8 +28,7 @@ public class EmailServiceImpl implements EmailService { } // To send a simple email - public String sendSimpleMail(EmailDetails details) - { + public String sendSimpleMail(EmailDetails details) { // Try block to check for exceptions try { @@ -470,8 +469,7 @@ public class EmailServiceImpl implements EmailService { // To send an email with attachment public String - sendMailWithAttachment(EmailDetails details) - { + sendMailWithAttachment(EmailDetails details) { // Creating a mime message MimeMessage mimeMessage = javaMailSender.createMimeMessage(); diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java index 0896abc..5644fb9 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java @@ -23,29 +23,29 @@ public class BatimentServiceImpl implements BatimentService { @Override public Batiment createBatiment(Batiment batiment) throws BadRequestException { - if(batiment.getId() != null ){ + if (batiment.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau batiment ayant un id non null."); } - return batimentRepository.save(batiment); + return batimentRepository.save(batiment); } @Override public Batiment updateBatiment(Long id, Batiment batiment) throws NotFoundException { - if(batiment.getId() == null ){ + if (batiment.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau batiment ayant un id null."); } - if(!batimentRepository.existsById(batiment.getId())){ + if (!batimentRepository.existsById(batiment.getId())) { throw new NotFoundException("Impossible de trouver le batiment spécifié dans notre base de données."); } - return batimentRepository.save(batiment); + return batimentRepository.save(batiment); } @Override public void deleteBatiment(Long id) throws NotFoundException { Optional batimentOptional = batimentRepository.findById(id); - if(batimentOptional.isPresent()){ + if (batimentOptional.isPresent()) { batimentRepository.deleteById(batimentOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le batiment spécifié dans notre base de données."); } } @@ -63,9 +63,9 @@ public class BatimentServiceImpl implements BatimentService { @Override public Optional getBatimentById(Long id) { - if(batimentRepository.existsById(id)){ + if (batimentRepository.existsById(id)) { return batimentRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueBatimentServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueBatimentServiceImpl.java index 7a4ab21..9f3ef15 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueBatimentServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueBatimentServiceImpl.java @@ -23,29 +23,29 @@ public class CaracteristiqueBatimentServiceImpl implements CaracteristiqueBatime @Override public CaracteristiqueBatiment createCaracteristiqueBatiment(CaracteristiqueBatiment caracteristiqueBatiment) throws BadRequestException { - if(caracteristiqueBatiment.getId() != null ){ + if (caracteristiqueBatiment.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle caracteristique de batiment ayant un id non null."); } - return caracteristiqueBatimentRepository.save(caracteristiqueBatiment); + return caracteristiqueBatimentRepository.save(caracteristiqueBatiment); } @Override public CaracteristiqueBatiment updateCaracteristiqueBatiment(Long id, CaracteristiqueBatiment caracteristiqueBatiment) throws NotFoundException { - if(caracteristiqueBatiment.getId() == null ){ + if (caracteristiqueBatiment.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle caracteristique de batiment ayant un id null."); } - if(!caracteristiqueBatimentRepository.existsById(caracteristiqueBatiment.getId())){ + if (!caracteristiqueBatimentRepository.existsById(caracteristiqueBatiment.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique de batiment spécifié dans notre base de données."); } - return caracteristiqueBatimentRepository.save(caracteristiqueBatiment); + return caracteristiqueBatimentRepository.save(caracteristiqueBatiment); } @Override public void deleteCaracteristiqueBatiment(Long id) throws NotFoundException { Optional caracteristiqueBatimentOptional = caracteristiqueBatimentRepository.findById(id); - if(caracteristiqueBatimentOptional.isPresent()){ + if (caracteristiqueBatimentOptional.isPresent()) { caracteristiqueBatimentRepository.deleteById(caracteristiqueBatimentOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique de batiment spécifié dans notre base de données."); } } @@ -63,9 +63,9 @@ public class CaracteristiqueBatimentServiceImpl implements CaracteristiqueBatime @Override public Optional getCaracteristiqueBatimentById(Long id) { - if(caracteristiqueBatimentRepository.existsById(id)){ + if (caracteristiqueBatimentRepository.existsById(id)) { return caracteristiqueBatimentRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueParcelleServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueParcelleServiceImpl.java index 45e7c0e..33ca951 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueParcelleServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueParcelleServiceImpl.java @@ -23,29 +23,29 @@ public class CaracteristiqueParcelleServiceImpl implements CaracteristiqueParcel @Override public CaracteristiqueParcelle createCaracteristiqueParcelle(CaracteristiqueParcelle caracteristiqueParcelle) throws BadRequestException { - if(caracteristiqueParcelle.getId() != null ){ + if (caracteristiqueParcelle.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle caracteristique de parcelle ayant un id non null."); } - return caracteristiqueParcelleRepository.save(caracteristiqueParcelle); + return caracteristiqueParcelleRepository.save(caracteristiqueParcelle); } @Override public CaracteristiqueParcelle updateCaracteristiqueParcelle(Long id, CaracteristiqueParcelle caracteristiqueParcelle) throws NotFoundException { - if(caracteristiqueParcelle.getId() == null ){ + if (caracteristiqueParcelle.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle caracteristique de parcelle ayant un id null."); } - if(!caracteristiqueParcelleRepository.existsById(caracteristiqueParcelle.getId())){ + if (!caracteristiqueParcelleRepository.existsById(caracteristiqueParcelle.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique de parcelle spécifié dans notre base de données."); } - return caracteristiqueParcelleRepository.save(caracteristiqueParcelle); + return caracteristiqueParcelleRepository.save(caracteristiqueParcelle); } @Override public void deleteCaracteristiqueParcelle(Long id) throws NotFoundException { Optional caracteristiqueParcelleOptional = caracteristiqueParcelleRepository.findById(id); - if(caracteristiqueParcelleOptional.isPresent()){ + if (caracteristiqueParcelleOptional.isPresent()) { caracteristiqueParcelleRepository.deleteById(caracteristiqueParcelleOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique de parcelle spécifié dans notre base de données."); } } @@ -63,9 +63,9 @@ public class CaracteristiqueParcelleServiceImpl implements CaracteristiqueParcel @Override public Optional getCaracteristiqueParcelleById(Long id) { - if(caracteristiqueParcelleRepository.existsById(id)){ + if (caracteristiqueParcelleRepository.existsById(id)) { return caracteristiqueParcelleRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueUniteLogementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueUniteLogementServiceImpl.java index 46bea52..f52fe0b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueUniteLogementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CaracteristiqueUniteLogementServiceImpl.java @@ -23,29 +23,29 @@ public class CaracteristiqueUniteLogementServiceImpl implements CaracteristiqueU @Override public CaracteristiqueUniteLogement createCaracteristiqueUniteLogement(CaracteristiqueUniteLogement caracteristiqueUniteLogement) throws BadRequestException { - if(caracteristiqueUniteLogement.getId() != null ){ + if (caracteristiqueUniteLogement.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle caracteristique d'unité de logement ayant un id non null."); } - return caracteristiqueUniteLogementRepository.save(caracteristiqueUniteLogement); + return caracteristiqueUniteLogementRepository.save(caracteristiqueUniteLogement); } @Override public CaracteristiqueUniteLogement updateCaracteristiqueUniteLogement(Long id, CaracteristiqueUniteLogement caracteristiqueUniteLogement) throws NotFoundException { - if(caracteristiqueUniteLogement.getId() == null ){ + if (caracteristiqueUniteLogement.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle caracteristique d'unité de logement ayant un id null."); } - if(!caracteristiqueUniteLogementRepository.existsById(caracteristiqueUniteLogement.getId())){ + if (!caracteristiqueUniteLogementRepository.existsById(caracteristiqueUniteLogement.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique d'unité de logement spécifiée dans notre base de données."); } - return caracteristiqueUniteLogementRepository.save(caracteristiqueUniteLogement); + return caracteristiqueUniteLogementRepository.save(caracteristiqueUniteLogement); } @Override public void deleteCaracteristiqueUniteLogement(Long id) throws NotFoundException { Optional caracteristiqueUniteLogementOptional = caracteristiqueUniteLogementRepository.findById(id); - if(caracteristiqueUniteLogementOptional.isPresent()){ + if (caracteristiqueUniteLogementOptional.isPresent()) { caracteristiqueUniteLogementRepository.deleteById(caracteristiqueUniteLogementOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle caracteristique d'unité de logement spécifiée dans notre base de données."); } } @@ -63,9 +63,9 @@ public class CaracteristiqueUniteLogementServiceImpl implements CaracteristiqueU @Override public Optional getCaracteristiqueUniteLogementById(Long id) { - if(caracteristiqueUniteLogementRepository.existsById(id)){ + if (caracteristiqueUniteLogementRepository.existsById(id)) { return caracteristiqueUniteLogementRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caracteristique d'unité de logement spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteBatimentServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteBatimentServiceImpl.java index 6103200..c9fa7f8 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteBatimentServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteBatimentServiceImpl.java @@ -23,29 +23,29 @@ public class EnqueteBatimentServiceImpl implements EnqueteBatimentService { @Override public EnqueteBatiment createEnqueteBatiment(EnqueteBatiment enqueteBatiment) throws BadRequestException { - if(enqueteBatiment.getId() != null ){ + if (enqueteBatiment.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle enquete de batiment ayant un id non null."); } - return enqueteBatimentRepository.save(enqueteBatiment); + return enqueteBatimentRepository.save(enqueteBatiment); } @Override public EnqueteBatiment updateEnqueteBatiment(Long id, EnqueteBatiment enqueteBatiment) throws NotFoundException { - if(enqueteBatiment.getId() == null ){ + if (enqueteBatiment.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle enquete de batiment ayant un id null."); } - if(!enqueteBatimentRepository.existsById(enqueteBatiment.getId())){ + if (!enqueteBatimentRepository.existsById(enqueteBatiment.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle enquete de batiment spécifiée dans notre base de données."); } - return enqueteBatimentRepository.save(enqueteBatiment); + return enqueteBatimentRepository.save(enqueteBatiment); } @Override public void deleteEnqueteBatiment(Long id) throws NotFoundException { Optional enqueteBatimentOptional = enqueteBatimentRepository.findById(id); - if(enqueteBatimentOptional.isPresent()){ + if (enqueteBatimentOptional.isPresent()) { enqueteBatimentRepository.deleteById(enqueteBatimentOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle enquete de batiment spécifiée dans notre base de données."); } } @@ -63,9 +63,9 @@ public class EnqueteBatimentServiceImpl implements EnqueteBatimentService { @Override public Optional getEnqueteBatimentById(Long id) { - if(enqueteBatimentRepository.existsById(id)){ + if (enqueteBatimentRepository.existsById(id)) { return enqueteBatimentRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle enquete de batiment spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteUniteLogementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteUniteLogementServiceImpl.java index 9c71983..a76dcf0 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteUniteLogementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteUniteLogementServiceImpl.java @@ -23,29 +23,29 @@ public class EnqueteUniteLogementServiceImpl implements EnqueteUniteLogementServ @Override public EnqueteUniteLogement createEnqueteUniteLogement(EnqueteUniteLogement enqueteUniteLogement) throws BadRequestException { - if(enqueteUniteLogement.getId() != null ){ + if (enqueteUniteLogement.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle enquete de d'unité de logement ayant un id non null."); } - return enqueteUniteLogementRepository.save(enqueteUniteLogement); + return enqueteUniteLogementRepository.save(enqueteUniteLogement); } @Override public EnqueteUniteLogement updateEnqueteUniteLogement(Long id, EnqueteUniteLogement enqueteUniteLogement) throws NotFoundException { - if(enqueteUniteLogement.getId() == null ){ + if (enqueteUniteLogement.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle enquete d'unité de logement ayant un id null."); } - if(!enqueteUniteLogementRepository.existsById(enqueteUniteLogement.getId())){ + if (!enqueteUniteLogementRepository.existsById(enqueteUniteLogement.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle enquete d'unité de logement spécifiée dans notre base de données."); } - return enqueteUniteLogementRepository.save(enqueteUniteLogement); + return enqueteUniteLogementRepository.save(enqueteUniteLogement); } @Override public void deleteEnqueteUniteLogement(Long id) throws NotFoundException { Optional enqueteUniteLogementOptional = enqueteUniteLogementRepository.findById(id); - if(enqueteUniteLogementOptional.isPresent()){ + if (enqueteUniteLogementOptional.isPresent()) { enqueteUniteLogementRepository.deleteById(enqueteUniteLogementOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle enquete d'unité de logement spécifiée dans notre base de données."); } } @@ -63,9 +63,9 @@ public class EnqueteUniteLogementServiceImpl implements EnqueteUniteLogementServ @Override public Optional getEnqueteUniteLogementById(Long id) { - if(enqueteUniteLogementRepository.existsById(id)){ + if (enqueteUniteLogementRepository.existsById(id)) { return enqueteUniteLogementRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle enquete d'unité de logement spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/UniteLogementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/UniteLogementServiceImpl.java index 8558847..c55c19e 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/UniteLogementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/UniteLogementServiceImpl.java @@ -23,29 +23,29 @@ public class UniteLogementServiceImpl implements UniteLogementService { @Override public UniteLogement createUniteLogement(UniteLogement uniteLogement) throws BadRequestException { - if(uniteLogement.getId() != null ){ + if (uniteLogement.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle unité de logement ayant un id non null."); } - return uniteLogementRepository.save(uniteLogement); + return uniteLogementRepository.save(uniteLogement); } @Override public UniteLogement updateUniteLogement(Long id, UniteLogement uniteLogement) throws NotFoundException { - if(uniteLogement.getId() == null ){ + if (uniteLogement.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle unité de logement ayant un id null."); } - if(!uniteLogementRepository.existsById(uniteLogement.getId())){ + if (!uniteLogementRepository.existsById(uniteLogement.getId())) { throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans notre base de données."); } - return uniteLogementRepository.save(uniteLogement); + return uniteLogementRepository.save(uniteLogement); } @Override public void deleteUniteLogement(Long id) throws NotFoundException { Optional uniteLogementOptional = uniteLogementRepository.findById(id); - if(uniteLogementOptional.isPresent()){ + if (uniteLogementOptional.isPresent()) { uniteLogementRepository.deleteById(uniteLogementOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans notre base de données."); } } @@ -63,9 +63,9 @@ public class UniteLogementServiceImpl implements UniteLogementService { @Override public Optional getUniteLogementById(Long id) { - if(uniteLogementRepository.existsById(id)){ + if (uniteLogementRepository.existsById(id)) { return uniteLogementRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CampagneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CampagneServiceImpl.java index 59d7379..8951685 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CampagneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CampagneServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; + @Service public class CampagneServiceImpl implements CampagneService { private final CampagneRepository campagneRepository; @@ -22,29 +23,29 @@ public class CampagneServiceImpl implements CampagneService { @Override public Campagne createCampagne(Campagne campagne) throws BadRequestException { - if(campagne.getId() != null ){ + if (campagne.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle campgne ayant un id non null."); } - return campagneRepository.save(campagne); + return campagneRepository.save(campagne); } @Override public Campagne updateCampagne(Long id, Campagne campagne) throws NotFoundException { - if(campagne.getId() == null ){ + if (campagne.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle campagne ayant un id null."); } - if(!campagneRepository.existsById(campagne.getId())){ + if (!campagneRepository.existsById(campagne.getId())) { throw new NotFoundException("Impossible de trouver la campagne spécifiée dans notre base de données."); } - return campagneRepository.save(campagne); + return campagneRepository.save(campagne); } @Override public void deleteCampagne(Long id) throws NotFoundException { Optional campagneOptional = campagneRepository.findById(id); - if(campagneOptional.isPresent()){ + if (campagneOptional.isPresent()) { campagneRepository.deleteById(campagneOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la campagne spécifiée dans notre base de données."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CaracteristiqueServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CaracteristiqueServiceImpl.java index 957c9c0..c6c4f49 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CaracteristiqueServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/CaracteristiqueServiceImpl.java @@ -23,29 +23,29 @@ public class CaracteristiqueServiceImpl implements CaracteristiqueService { @Override public Caracteristique createCaracteristique(Caracteristique caracteristique) throws BadRequestException { - if(caracteristique.getId() != null ){ + if (caracteristique.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle caracteristique ayant un id non null."); } - return caracteristiqueRepository.save(caracteristique); + return caracteristiqueRepository.save(caracteristique); } @Override public Caracteristique updateCaracteristique(Long id, Caracteristique caracteristique) throws NotFoundException { - if(caracteristique.getId() == null ){ + if (caracteristique.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle caracteristique ayant un id null."); } - if(!caracteristiqueRepository.existsById(caracteristique.getId())){ + if (!caracteristiqueRepository.existsById(caracteristique.getId())) { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans notre base de données."); } - return caracteristiqueRepository.save(caracteristique); + return caracteristiqueRepository.save(caracteristique); } @Override public void deleteCaracteristique(Long id) throws NotFoundException { Optional caracteristiqueOptional = caracteristiqueRepository.findById(id); - if(caracteristiqueOptional.isPresent()){ + if (caracteristiqueOptional.isPresent()) { caracteristiqueRepository.deleteById(caracteristiqueOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans notre base de données."); } } @@ -63,9 +63,9 @@ public class CaracteristiqueServiceImpl implements CaracteristiqueService { @Override public Optional getCaracteristiqueById(Long id) { - if(caracteristiqueRepository.existsById(id)){ + if (caracteristiqueRepository.existsById(id)) { return caracteristiqueRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/EquipeServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/EquipeServiceImpl.java index bc4bc54..be5ebd8 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/EquipeServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/EquipeServiceImpl.java @@ -42,33 +42,33 @@ public class EquipeServiceImpl implements EquipeService { @Override public Equipe createEquipe(EquipePayload equipePayload) throws BadRequestException { - if(equipePayload.getId() != null ){ + if (equipePayload.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle equipe ayant un id non null."); } Equipe equipe = getEquipeFromPayload(equipePayload); - return equipeRepository.save(equipe); + return equipeRepository.save(equipe); } private Equipe getEquipeFromPayload(EquipePayload equipePayload) { - Equipe equipe=new Equipe(); - Optional optionalBloc=blocRepository.findById(equipePayload.getBlocId()); + Equipe equipe = new Equipe(); + Optional optionalBloc = blocRepository.findById(equipePayload.getBlocId()); equipe.setBloc(optionalBloc.orElse(null)); equipe.setId(equipePayload.getId()); equipe.setCode(equipePayload.getCode()); equipe.setNom(equipePayload.getNom()); - Optional optionalSecteur=secteurRepository.findById(equipePayload.getSecteurId()); + Optional optionalSecteur = secteurRepository.findById(equipePayload.getSecteurId()); equipe.setSecteur(optionalSecteur.orElse(null)); - Optional optionalCampagne=campagneRepository.findById(equipePayload.getCampagneId()); + Optional optionalCampagne = campagneRepository.findById(equipePayload.getCampagneId()); equipe.setCampagne(optionalCampagne.orElse(null)); - List participerList=new ArrayList<>(); + List participerList = new ArrayList<>(); - for (ParticiperPayload pp: equipePayload.getParticiperPayloads()){ - Participer part=new Participer(); - if(pp.getEquipeId()!=null && equipeRepository.existsById(pp.getEquipeId()) ){ + for (ParticiperPayload pp : equipePayload.getParticiperPayloads()) { + Participer part = new Participer(); + if (pp.getEquipeId() != null && equipeRepository.existsById(pp.getEquipeId())) { part.setEquipe(equipeRepository.findById(pp.getEquipeId()).orElse(null)); } - if(pp.getUserId()!=null && userRepository.existsById(pp.getUserId()) ){ + if (pp.getUserId() != null && userRepository.existsById(pp.getUserId())) { part.setUser(userRepository.findById(pp.getUserId()).orElse(null)); } part.setDateDebut(pp.getDateDebut()); @@ -82,22 +82,22 @@ public class EquipeServiceImpl implements EquipeService { @Override public Equipe updateEquipe(Long id, EquipePayload equipePayload) throws NotFoundException { - if(equipePayload.getId() == null ){ + if (equipePayload.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle equipe ayant un id null."); } - if(!equipeRepository.existsById(equipePayload.getId())){ + if (!equipeRepository.existsById(equipePayload.getId())) { throw new NotFoundException("Impossible de trouver la equipe spécifiée dans notre base de données."); } Equipe equipe = getEquipeFromPayload(equipePayload); - return equipeRepository.save(equipe); + return equipeRepository.save(equipe); } @Override public void deleteEquipe(Long id) throws NotFoundException { Optional equipeOptional = equipeRepository.findById(id); - if(equipeOptional.isPresent()){ + if (equipeOptional.isPresent()) { equipeRepository.deleteById(equipeOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la equipe spécifiée dans notre base de données."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/TypeCaracteristiqueServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/TypeCaracteristiqueServiceImpl.java index 7964042..5a8d66b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/TypeCaracteristiqueServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/parametre/TypeCaracteristiqueServiceImpl.java @@ -23,29 +23,29 @@ public class TypeCaracteristiqueServiceImpl implements TypeCaracteristiqueServic @Override public TypeCaracteristique createTypeCaracteristique(TypeCaracteristique typeCaracteristique) throws BadRequestException { - if(typeCaracteristique.getId() != null ){ + if (typeCaracteristique.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau type de caracteristique ayant un id non null."); } - return typeCaracteristiqueRepository.save(typeCaracteristique); + return typeCaracteristiqueRepository.save(typeCaracteristique); } @Override public TypeCaracteristique updateTypeCaracteristique(Long id, TypeCaracteristique typeCaracteristique) throws NotFoundException { - if(typeCaracteristique.getId() == null ){ + if (typeCaracteristique.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau type caracteristique ayant un id null."); } - if(!typeCaracteristiqueRepository.existsById(typeCaracteristique.getId())){ + if (!typeCaracteristiqueRepository.existsById(typeCaracteristique.getId())) { throw new NotFoundException("Impossible de trouver le type caractéristique spécifié dans notre base de données."); } - return typeCaracteristiqueRepository.save(typeCaracteristique); + return typeCaracteristiqueRepository.save(typeCaracteristique); } @Override public void deleteTypeCaracteristique(Long id) throws NotFoundException { Optional typeCaracteristiqueOptional = typeCaracteristiqueRepository.findById(id); - if(typeCaracteristiqueOptional.isPresent()){ + if (typeCaracteristiqueOptional.isPresent()) { typeCaracteristiqueRepository.deleteById(typeCaracteristiqueOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type caractéristique spécifié dans notre base de données."); } } @@ -63,9 +63,9 @@ public class TypeCaracteristiqueServiceImpl implements TypeCaracteristiqueServic @Override public Optional getTypeCaracteristiqueById(Long id) { - if(typeCaracteristiqueRepository.existsById(id)){ + if (typeCaracteristiqueRepository.existsById(id)) { return typeCaracteristiqueRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver le type caractéristique spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/synchronisation/RestaurationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/synchronisation/RestaurationServiceImpl.java index 95ea830..ea24f89 100644 --- a/src/main/java/io/gmss/fiscad/implementations/synchronisation/RestaurationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/synchronisation/RestaurationServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Base64; import java.util.List; + @Service @RequiredArgsConstructor public class RestaurationServiceImpl implements RestaurationService { @@ -72,18 +73,18 @@ public class RestaurationServiceImpl implements RestaurationService { @Override public List getMembreGroupe(Long terminaleId) { - return membreGroupeRepository.getMembreGroupeByTerminalId(terminaleId ); + return membreGroupeRepository.getMembreGroupeByTerminalId(terminaleId); } @Override public List getUpload(Long terminaleId) { List uploadPayLoads = uploadRepository.getUploadByTerminalId(terminaleId); - List uploadPayLoadsOut=new ArrayList<>(); + List uploadPayLoadsOut = new ArrayList<>(); uploadPayLoads.forEach(uploadPayLoad -> { - io.gmss.fiscad.paylaods.request.UploadPayLoad uploadPayLoadLocal=new io.gmss.fiscad.paylaods.request.UploadPayLoad(); + io.gmss.fiscad.paylaods.request.UploadPayLoad uploadPayLoadLocal = new io.gmss.fiscad.paylaods.request.UploadPayLoad(); uploadPayLoadLocal.setTerminalId(uploadPayLoad.getTerminalId()); - String inputStream= getUploadFile(uploadPayLoad); + String inputStream = getUploadFile(uploadPayLoad); uploadPayLoadLocal.setFileBase64(inputStream); uploadPayLoadLocal.setIdBackend(uploadPayLoad.getIdBackend()); uploadPayLoadLocal.setPieceId(uploadPayLoad.getPieceId()); @@ -142,10 +143,10 @@ public class RestaurationServiceImpl implements RestaurationService { try { Resource resource = fileStorageService.loadFileAsResource(uploadPayLoad.getFileBackendName()); - final var bytes =resource.getInputStream().readAllBytes(); + final var bytes = resource.getInputStream().readAllBytes(); return Base64.getEncoder().encodeToString(bytes); } catch (Exception e) { - System.out.println("ERREUR"+ e.getMessage()); + System.out.println("ERREUR" + e.getMessage()); //throw new RuntimeException(e); return null; } @@ -158,7 +159,7 @@ public class RestaurationServiceImpl implements RestaurationService { String userName = authentication.getName(); User user = userService.getUserByUsername(userName); return tpeRepository.getTpeByUserId(user.getId()); - }catch (Exception e){ + } catch (Exception e) { return new ArrayList<>(); } diff --git a/src/main/java/io/gmss/fiscad/implementations/synchronisation/StatistiquesServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/synchronisation/StatistiquesServiceImpl.java index 5edaa69..e8d548b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/synchronisation/StatistiquesServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/synchronisation/StatistiquesServiceImpl.java @@ -14,11 +14,13 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; + @Service public class StatistiquesServiceImpl implements StatistiquesService { private Authentication authentication; private final UserService userService; private final EnqueteRepository enqueteRepository; + public StatistiquesServiceImpl(UserService userService, EnqueteRepository enqueteRepository) { this.userService = userService; this.enqueteRepository = enqueteRepository; @@ -26,15 +28,15 @@ public class StatistiquesServiceImpl implements StatistiquesService { @Override public List getStatEnqueteParStatut() { - String userName=""; - List statEnqueteParStatutResponse=new ArrayList<>(); + String userName = ""; + List statEnqueteParStatutResponse = new ArrayList<>(); try { authentication = SecurityContextHolder.getContext().getAuthentication(); userName = authentication.getName(); User user = userService.getUserByUsername(userName); - statEnqueteParStatutResponse= user.isAdmin() ? enqueteRepository.getStatEnqueteParStatut() : enqueteRepository.getStatEnqueteParStatut(user.getId()); + statEnqueteParStatutResponse = user.isAdmin() ? enqueteRepository.getStatEnqueteParStatut() : enqueteRepository.getStatEnqueteParStatut(user.getId()); return statEnqueteParStatutResponse; - }catch (Exception e){ + } catch (Exception e) { return new ArrayList<>(); } } @@ -51,13 +53,13 @@ public class StatistiquesServiceImpl implements StatistiquesService { @Override public List getStatBloc() { - String userName=""; + String userName = ""; try { authentication = SecurityContextHolder.getContext().getAuthentication(); userName = authentication.getName(); User user = userService.getUserByUsername(userName); return enqueteRepository.getStatEnqueteParBloc(user.getId()); - }catch (Exception e){ + } catch (Exception e) { return new ArrayList<>(); } diff --git a/src/main/java/io/gmss/fiscad/implementations/synchronisation/SynchronisationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/synchronisation/SynchronisationServiceImpl.java index 8100abc..c78c947 100644 --- a/src/main/java/io/gmss/fiscad/implementations/synchronisation/SynchronisationServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/synchronisation/SynchronisationServiceImpl.java @@ -146,13 +146,13 @@ public class SynchronisationServiceImpl implements SynchronisationService { // List blocSyncResponses = // blocRepository.getBlocResponse(user.getStructure().getId()); - List blocSyncResponses=new ArrayList<>(); - if(user.getIdSecteurCourant()==null) { + List blocSyncResponses = new ArrayList<>(); + if (user.getIdSecteurCourant() == null) { blocSyncResponses = blocRepository.getBlocResponse(user.getStructure().getId()); - }else{ + } else { blocSyncResponses = - blocRepository.getBlocSecteurResponse(user.getStructure().getId(),user.getIdSecteurCourant()); + blocRepository.getBlocSecteurResponse(user.getStructure().getId(), user.getIdSecteurCourant()); } UserDecoupageSyncResponses userDecoupageSyncResponses = new UserDecoupageSyncResponses(); @@ -262,7 +262,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { Personne personne = new Personne(); SyncResponse syncResponse = new SyncResponse(); personnePayLoad.setSynchronise(true); - if (personnePayLoad.getIdBackend() != null && personnePayLoad.getIdBackend() != 0 ) { + if (personnePayLoad.getIdBackend() != null && personnePayLoad.getIdBackend() != 0) { Optional optionalPersonne = personneRepository.findById(personnePayLoad.getIdBackend()); if (!optionalPersonne.isPresent()) { personnePayLoad.setObservation("La clé interne est non valide : Enregistrement inexistant "); @@ -326,8 +326,8 @@ public class SynchronisationServiceImpl implements SynchronisationService { if (personnePayLoad.getTypePersonneId() != null) { Optional optionalTypePersonne = typePersonneRepository.findById(personnePayLoad.getTypePersonneId()); personne.setTypePersonne(optionalTypePersonne.orElse(null)); - }else{ - Optional optionalTypePersonne=typePersonneRepository.findFirstByCategorie(Categorie.PERSONNE_PHYSIQUE); + } else { + Optional optionalTypePersonne = typePersonneRepository.findFirstByCategorie(Categorie.PERSONNE_PHYSIQUE); personne.setTypePersonne(optionalTypePersonne.orElse(null)); } @@ -399,7 +399,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { syncResponses.add(syncResponse); return; } else { - Optional optionalPersonne = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresentanteId(),membreGroupePayLoad.getTerminalId()); + Optional optionalPersonne = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresentanteId(), membreGroupePayLoad.getTerminalId()); if (optionalPersonne.isEmpty()) { SyncResponse syncResponse = new SyncResponse(membreGroupePayLoad.getIdBackend(), membreGroupePayLoad.getExternalKey(), false, "La personne représentante précisée n'existe pas"); @@ -413,7 +413,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { syncResponses.add(syncResponse); return; } else { - Optional optionalPersonne = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresenteeId(),membreGroupePayLoad.getTerminalId()); + Optional optionalPersonne = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresenteeId(), membreGroupePayLoad.getTerminalId()); if (optionalPersonne.isEmpty()) { SyncResponse syncResponse = new SyncResponse(membreGroupePayLoad.getIdBackend(), membreGroupePayLoad.getExternalKey(), false, "La personne représentée précisée n'existe pas"); @@ -462,11 +462,11 @@ public class SynchronisationServiceImpl implements SynchronisationService { private MembreGroupe getMembreGroupeFromMembreGroupePayLoad(MembreGroupe membreGroupe, MembreGroupePayLoad membreGroupePayLoad) { if (membreGroupePayLoad.getPersonneRepresentanteId() != null) { - Optional optionalRepresentant = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresentanteId(),membreGroupePayLoad.getTerminalId()); + Optional optionalRepresentant = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresentanteId(), membreGroupePayLoad.getTerminalId()); membreGroupe.setPersonneRepresantante(optionalRepresentant.orElse(null)); } if (membreGroupePayLoad.getPersonneRepresenteeId() != null) { - Optional optionalRepresente = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresenteeId(),membreGroupePayLoad.getTerminalId()); + Optional optionalRepresente = personneRepository.findFirstByExternalKeyAndTerminal_Id(membreGroupePayLoad.getPersonneRepresenteeId(), membreGroupePayLoad.getTerminalId()); membreGroupe.setPersonneRepresantee(optionalRepresente.orElse(null)); } @@ -572,14 +572,14 @@ public class SynchronisationServiceImpl implements SynchronisationService { //récupération de l'enquete en base de donnéees enquete = optionalEnquete.get(); //verification du statut de l'enquete (Si le status est en_cours ou rejet alors mise à jour) - if(enquete.getStatusEnquete().equals(StatusEnquete.EN_COURS) || enquete.getStatusEnquete().equals(StatusEnquete.REJETE)){ + if (enquete.getStatusEnquete().equals(StatusEnquete.EN_COURS) || enquete.getStatusEnquete().equals(StatusEnquete.REJETE)) { // suppression des pièces, uploads et acteurs concernés deleteFromEnquete(enquetePayLoad.getIdBackend()); enquete = getEnqueteFromEnquetePayLoad(enquete, enquetePayLoad); enquete.setStatutEnregistrement(StatutEnregistrement.MISE_A_JOUR); enquete = enqueteRepository.save(enquete); enquetePayLoad.setIdBackend(enquete.getId()); - }else{ + } else { enquetePayLoad.setObservation("Le statut de cette enquête est déjà VALIDE. Une mise à jour sur cette enquête n'est donc plus possible."); } } @@ -607,19 +607,19 @@ public class SynchronisationServiceImpl implements SynchronisationService { } private void deleteFromEnquete(Long idBackend) { - try{ + try { uploadRepository.deleteUploadByEnqueteID(idBackend); - }catch (Exception e){ + } catch (Exception e) { } - try{ + try { pieceRepository.deletePieceByEnqueteId(idBackend); - }catch (Exception e){ + } catch (Exception e) { } - try{ + try { acteurConcerneRepository.deleteActeurConcerneByEnquete(idBackend); - }catch (Exception e){ + } catch (Exception e) { } } @@ -699,7 +699,6 @@ public class SynchronisationServiceImpl implements SynchronisationService { } - batiment.setNub(batimentPaylaod.getNub()); batiment.setCode(batimentPaylaod.getCode()); batiment.setDateConstruction(batimentPaylaod.getDateConstruction()); @@ -928,7 +927,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { } } if (piecePayLoad.getActeurConcerneId() != null) { - Optional optionalActeurConcerne = acteurConcerneRepository.findFirstByExternalKeyAndTerminal_Id(piecePayLoad.getActeurConcerneId(),piecePayLoad.getTerminalId()); + Optional optionalActeurConcerne = acteurConcerneRepository.findFirstByExternalKeyAndTerminal_Id(piecePayLoad.getActeurConcerneId(), piecePayLoad.getTerminalId()); if (optionalActeurConcerne.isEmpty()) { SyncResponse syncResponse = new SyncResponse(piecePayLoad.getIdBackend(), piecePayLoad.getExternalKey(), false, "L'acteur concerné précisé n'existe pas"); @@ -1192,16 +1191,16 @@ public class SynchronisationServiceImpl implements SynchronisationService { if ((uploadPayLoad.getPieceId() == null || uploadPayLoad.getPieceId() == 0) && (uploadPayLoad.getMembreGroupeId() == null || uploadPayLoad.getMembreGroupeId() == 0)) { - if((uploadPayLoad.getEnqueteBatimentId() == null || uploadPayLoad.getEnqueteBatimentId() == 0) && (uploadPayLoad.getEnqueteUniteLogementId() == null || uploadPayLoad.getEnqueteUniteLogementId() == 0)){ + if ((uploadPayLoad.getEnqueteBatimentId() == null || uploadPayLoad.getEnqueteBatimentId() == 0) && (uploadPayLoad.getEnqueteUniteLogementId() == null || uploadPayLoad.getEnqueteUniteLogementId() == 0)) { syncResponse = new SyncResponse(uploadPayLoad.getIdBackend(), uploadPayLoad.getExternalKey(), false, "La pièce, le membre groupe concernée, l'enquête batiment, l'enquête unité de logement n'est pas précisé"); return syncResponse; - }else{ + } else { Optional optionalEnqueteUniteLogement = null; - if(uploadPayLoad.getEnqueteUniteLogementId() != null && uploadPayLoad.getEnqueteUniteLogementId() != 0){ + if (uploadPayLoad.getEnqueteUniteLogementId() != null && uploadPayLoad.getEnqueteUniteLogementId() != 0) { optionalEnqueteUniteLogement = enqueteUniteLogementRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getEnqueteUniteLogementId(), uploadPayLoad.getTerminalId()); } - if(optionalEnqueteUniteLogement == null && optionalEnqueteUniteLogement.isEmpty()){ + if (optionalEnqueteUniteLogement == null && optionalEnqueteUniteLogement.isEmpty()) { syncResponse = new SyncResponse(uploadPayLoad.getIdBackend(), uploadPayLoad.getExternalKey(), false, "L'enquête de l'unité de logement précisée n'existe pas"); return syncResponse; @@ -1209,25 +1208,25 @@ public class SynchronisationServiceImpl implements SynchronisationService { Optional optionalEnqueteBatiment = null; - if(uploadPayLoad.getEnqueteBatimentId() != null && uploadPayLoad.getEnqueteBatimentId() != 0){ + if (uploadPayLoad.getEnqueteBatimentId() != null && uploadPayLoad.getEnqueteBatimentId() != 0) { optionalEnqueteBatiment = enqueteBatimentRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getEnqueteBatimentId(), uploadPayLoad.getTerminalId()); } - if(optionalEnqueteBatiment == null && optionalEnqueteBatiment.isEmpty()){ + if (optionalEnqueteBatiment == null && optionalEnqueteBatiment.isEmpty()) { syncResponse = new SyncResponse(uploadPayLoad.getIdBackend(), uploadPayLoad.getExternalKey(), false, "L'enquête bâtiment précisée n'existe pas"); return syncResponse; } } - }else{ + } else { Optional optionalPiece = null; if (uploadPayLoad.getPieceId() != null) { - optionalPiece = pieceRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getPieceId(),terminalId); + optionalPiece = pieceRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getPieceId(), terminalId); } Optional optionalMembreGroupe = null; if (uploadPayLoad.getMembreGroupeId() != null) { - optionalMembreGroupe = membreGroupeRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getMembreGroupeId(),terminalId); + optionalMembreGroupe = membreGroupeRepository.findFirstByExternalKeyAndTerminal_Id(uploadPayLoad.getMembreGroupeId(), terminalId); } - if((optionalMembreGroupe == null || optionalMembreGroupe.isEmpty()) && (optionalPiece == null || optionalPiece.isEmpty())) { + if ((optionalMembreGroupe == null || optionalMembreGroupe.isEmpty()) && (optionalPiece == null || optionalPiece.isEmpty())) { syncResponse = new SyncResponse(uploadPayLoad.getIdBackend(), uploadPayLoad.getExternalKey(), false, "La pièce ou le groupe précisée n'existe pas"); return syncResponse; @@ -1266,16 +1265,16 @@ public class SynchronisationServiceImpl implements SynchronisationService { @Override public List syncEnqueteFromMobile(List idEnquete) { - List syncResponses= new ArrayList<>(); - if (idEnquete==null){ + List syncResponses = new ArrayList<>(); + if (idEnquete == null) { return null; - }else{ + } else { idEnquete.forEach(aLong -> { Optional optionalEnquete = enqueteRepository.findById(aLong); - if(optionalEnquete.isPresent()){ + if (optionalEnquete.isPresent()) { optionalEnquete.get().setSynchronise(true); - Enquete enquete= enqueteRepository.save(optionalEnquete.get()); - SyncResponse syncResponse=new SyncResponse(); + Enquete enquete = enqueteRepository.save(optionalEnquete.get()); + SyncResponse syncResponse = new SyncResponse(); syncResponse.setSynchronise(enquete.isSynchronise()); syncResponse.setExternalKey(enquete.getExternalKey()); syncResponse.setIdBackend(enquete.getId()); @@ -1334,7 +1333,6 @@ public class SynchronisationServiceImpl implements SynchronisationService { } - @Override public List syncBatiment(List batimentPaylaods) { @@ -1412,7 +1410,6 @@ public class SynchronisationServiceImpl implements SynchronisationService { } - @Override public List syncUniteLogement(List uniteLogementPaylaods) { @@ -1529,9 +1526,9 @@ public class SynchronisationServiceImpl implements SynchronisationService { caracteristiqueBatimentPaylod.getExternalKey(), false, "L'enquête batiment précisée n'existe pas"); syncResponses.add(syncResponse); return; - }else { + } else { EnqueteBatiment enqueteBatiment = optionalEnqueteBatiment.get(); - if(enqueteBatiment.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)){ + if (enqueteBatiment.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)) { //suppression de toutes les caractéristiques liées à une enquête si l'enquete à pour statut d'enregistrement MAJ deleteAllCaracteristiqueBatimentFromEnqueteBatiment(enqueteBatiment); } @@ -1623,9 +1620,9 @@ public class SynchronisationServiceImpl implements SynchronisationService { caracteristiqueUniteLogementPaylod.getExternalKey(), false, "L'enquête de l'unité de logement précisée n'existe pas"); syncResponses.add(syncResponse); return; - }else{ + } else { EnqueteUniteLogement enqueteUniteLogement = optionalEnqueteUniteLogement.get(); - if(enqueteUniteLogement.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)){ + if (enqueteUniteLogement.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)) { //suppression de toutes les caractéristiques liées à une enquête si l'enquete à pour statut d'enregistrement MAJ deleteAllCaracteristiqueUniteLogementFromEnqueteUniteLogement(enqueteUniteLogement); } @@ -1679,7 +1676,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { @Override - public List syncCaracteristiqueParcelle(List caracteristiqueParcellePaylods) { + public List syncCaracteristiqueParcelle(List caracteristiqueParcellePaylods) { List syncResponses = new ArrayList<>(); if (caracteristiqueParcellePaylods == null) { @@ -1718,9 +1715,9 @@ public class SynchronisationServiceImpl implements SynchronisationService { caracteristiqueParcellePaylod.getExternalKey(), false, "L'enquête précisée n'existe pas"); syncResponses.add(syncResponse); return; - }else { + } else { Enquete enquete = optionalEnquete.get(); - if(enquete.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)){ + if (enquete.getStatutEnregistrement().equals(StatutEnregistrement.MISE_A_JOUR)) { //suppression de toutes les caractéristiques liées à une enquête si l'enquete à pour statut d'enregistrement MAJ deleteAllCaracteristiqueParcelleFromEnquete(enquete); } @@ -1773,7 +1770,6 @@ public class SynchronisationServiceImpl implements SynchronisationService { } - @Override public List syncEnqueteBatiment(List enqueteBatimentPayLoads) { List syncResponses = new ArrayList<>(); @@ -1870,14 +1866,14 @@ public class SynchronisationServiceImpl implements SynchronisationService { //récupération de l'enquete en base de donnéees enqueteBatiment = optionalEnqueteBatiment.get(); //verification du statut de l'enquete (Si le status est en_cours ou rejet alors mise à jour) - if(enqueteBatiment.getEnquete().getStatusEnquete().equals(StatusEnquete.EN_COURS) || enqueteBatiment.getEnquete().getStatusEnquete().equals(StatusEnquete.REJETE)){ + if (enqueteBatiment.getEnquete().getStatusEnquete().equals(StatusEnquete.EN_COURS) || enqueteBatiment.getEnquete().getStatusEnquete().equals(StatusEnquete.REJETE)) { // suppression des pièces, uploads et acteurs concernés deleteAllUploadFromEnqueteBatiment(enqueteBatiment); enqueteBatiment = getEnqueteBatimentFromEnqueteBatimentPayLoad(enqueteBatiment, enqueteBatimentPayload); enqueteBatiment.setStatutEnregistrement(StatutEnregistrement.MISE_A_JOUR); enqueteBatimentRepository.save(enqueteBatiment); enqueteBatimentPayload.setIdBackend(enqueteBatiment.getId()); - }else{ + } else { enqueteBatimentPayload.setObservation("Le statut de cette enquête est déjà VALIDE. Une mise à jour sur cette enquête n'est donc plus possible."); } } @@ -2000,7 +1996,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { //récupération de l'enquete en base de donnéees enqueteUniteLogement = optionalEnqueteUniteLogement.get(); //verification du statut de l'enquete (Si le status est en_cours ou rejet alors mise à jour) - if(enqueteUniteLogement.getEnquete().getStatusEnquete().equals(StatusEnquete.EN_COURS) || enqueteUniteLogement.getEnquete().getStatusEnquete().equals(StatusEnquete.REJETE)){ + if (enqueteUniteLogement.getEnquete().getStatusEnquete().equals(StatusEnquete.EN_COURS) || enqueteUniteLogement.getEnquete().getStatusEnquete().equals(StatusEnquete.REJETE)) { // suppression des pièces, uploads et acteurs concernés // TODO: 19/01/2025 S'assurer que la suppression des uploads est nécessaire et correcte deleteAllUploadFromEnqueteUniteLogement(enqueteUniteLogement); @@ -2008,7 +2004,7 @@ public class SynchronisationServiceImpl implements SynchronisationService { enqueteUniteLogement.setStatutEnregistrement(StatutEnregistrement.MISE_A_JOUR); enqueteUniteLogementRepository.save(enqueteUniteLogement); enqueteUniteLogementPayload.setIdBackend(enqueteUniteLogement.getId()); - }else{ + } else { enqueteUniteLogementPayload.setObservation("Le statut de cette enquête est déjà VALIDE. Une mise à jour sur cette enquête n'est donc plus possible."); } } @@ -2112,10 +2108,10 @@ public class SynchronisationServiceImpl implements SynchronisationService { enqueteBatiment.setExternalKey(enqueteBatimentPayload.getExternalKey()); - if (enqueteBatimentPayload.getPersonneId() != null) { + if (enqueteBatimentPayload.getPersonneId() != null) { Optional optionalPersonne = personneRepository.findFirstByExternalKeyAndTerminal_Id(enqueteBatimentPayload.getPersonneId(), enqueteBatimentPayload.getTerminalId()); enqueteBatiment.setPersonne(optionalPersonne.orElse(null)); - } + } if (enqueteBatimentPayload.getBatimentId() != null) { Optional optionalBatiment = batimentRepository.findFirstByExternalKeyAndTerminal_Id(enqueteBatimentPayload.getBatimentId(), enqueteBatimentPayload.getTerminalId()); diff --git a/src/main/java/io/gmss/fiscad/implementations/user/DemandeReinitialisationMPServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/DemandeReinitialisationMPServiceImpl.java index ae8d404..59e5853 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/DemandeReinitialisationMPServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/DemandeReinitialisationMPServiceImpl.java @@ -37,29 +37,29 @@ public class DemandeReinitialisationMPServiceImpl implements DemandeReinitialisa demandeReinitialisationMP.setUser(user); demandeReinitialisationMP.setEtatDemande(EtatDemande.NON_TRAITE); - if(demandeReinitialisationMP.getId() != null ){ + if (demandeReinitialisationMP.getId() != null) { throw new BadRequestException("Impossible de créer une nouvelle demande de reinitialisation de mot de passe ayant un id non null."); } - return demandeReinitialisationMPRepository.save(demandeReinitialisationMP); + return demandeReinitialisationMPRepository.save(demandeReinitialisationMP); } @Override public DemandeReinitialisationMP updateDemandeReinitialisationMP(Long id, DemandeReinitialisationMP demandeReinitialisationMP) throws NotFoundException { - if(demandeReinitialisationMP.getId() == null ){ + if (demandeReinitialisationMP.getId() == null) { throw new BadRequestException("Impossible de mettre à jour une nouvelle demande de reinitialisation de mot de passe ayant un id null."); } - if(!demandeReinitialisationMPRepository.existsById(demandeReinitialisationMP.getId())){ + if (!demandeReinitialisationMPRepository.existsById(demandeReinitialisationMP.getId())) { throw new NotFoundException("Impossible de trouver la demande de reinitialisation de mot de passe spécifiée dans notre base de données."); } - return demandeReinitialisationMPRepository.save(demandeReinitialisationMP); + return demandeReinitialisationMPRepository.save(demandeReinitialisationMP); } @Override public void deleteDemandeReinitialisationMP(Long id) throws NotFoundException { Optional demandeReinitialisationMPOptional = demandeReinitialisationMPRepository.findById(id); - if(demandeReinitialisationMPOptional.isPresent()){ + if (demandeReinitialisationMPOptional.isPresent()) { demandeReinitialisationMPRepository.deleteById(demandeReinitialisationMPOptional.get().getId()); - }else{ + } else { throw new NotFoundException("Impossible de trouver la demande de reinitialisation de mot de passe spécifiée dans notre base de données."); } } @@ -81,9 +81,9 @@ public class DemandeReinitialisationMPServiceImpl implements DemandeReinitialisa @Override public Optional getDemandeReinitialisationMPById(Long id) { - if(demandeReinitialisationMPRepository.existsById(id)){ + if (demandeReinitialisationMPRepository.existsById(id)) { return demandeReinitialisationMPRepository.findById(id); - }else{ + } else { throw new NotFoundException("Impossible de trouver la demande de reinitialisation de mot de passe spécifiée dans la base de données."); } @@ -92,13 +92,13 @@ public class DemandeReinitialisationMPServiceImpl implements DemandeReinitialisa @Override public DemandeReinitialisationMP traiterDemandeReinitialisation(Long id, String password) { Optional demandeReinitialisationMPOptional = getDemandeReinitialisationMPById(id); - if(demandeReinitialisationMPOptional.isPresent()){ + if (demandeReinitialisationMPOptional.isPresent()) { DemandeReinitialisationMP demandeReinitialisationMP = demandeReinitialisationMPOptional.get(); User user = demandeReinitialisationMP.getUser(); userService.resetPassword(user.getUsername(), password); demandeReinitialisationMP.setEtatDemande(EtatDemande.TRAITE); return demandeReinitialisationMPRepository.save(demandeReinitialisationMP); - }else{ + } else { throw new NotFoundException("La demande de réinitialisation du mot de passe n'est pas trouvée."); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/user/RoleServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/RoleServiceImpl.java index 4ad923a..0b57df5 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/RoleServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/RoleServiceImpl.java @@ -24,10 +24,10 @@ public class RoleServiceImpl implements RoleService { @Override public Role createRole(Role role) throws BadRequestException { - if(role.getId() != null ){ + if (role.getId() != null) { throw new BadRequestException("A new role id to save must be null or empty."); } - return roleRepository.save(role); + return roleRepository.save(role); } @Override diff --git a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java index fb85c57..694ee22 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java @@ -110,13 +110,13 @@ public class UserServiceImpl implements UserService { if (user.getPassword() == null || user.getPassword().isBlank()) { user.setPassword(user1.getPassword()); - }else{ + } else { user.setPassword(passwordEncoder.encode(user.getPassword())); } - if(user.getEmail() == null || user.getEmail().isEmpty()){ + if (user.getEmail() == null || user.getEmail().isEmpty()) { user.setEmail(user1.getEmail()); - }else { + } else { user.setEmail(user.getEmail()); } user.setResetPassword(user1.isResetPassword()); @@ -164,9 +164,9 @@ public class UserServiceImpl implements UserService { Set roleSet = new HashSet<>(); roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); Optional structureOptional = structureService.getStructureById(structureId); - if(structureOptional.isPresent()){ + if (structureOptional.isPresent()) { return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet); - }else { + } else { throw new NotFoundException("Impossible de trouver la structure spécifiée."); } } @@ -176,9 +176,9 @@ public class UserServiceImpl implements UserService { Set roleSet = new HashSet<>(); roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); Optional structureOptional = structureService.getStructureById(structureId); - if(structureOptional.isPresent()){ - return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet); - }else { + if (structureOptional.isPresent()) { + return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet); + } else { throw new NotFoundException("Impossible de trouver la structure spécifiée."); } } @@ -230,11 +230,11 @@ public class UserServiceImpl implements UserService { @Override public User activateOrNotUser(Long id) { User user = getUserById(id); - if(user.isActive()){ + if (user.isActive()) { user.setActive(false); } - if(!user.isActive()){ + if (!user.isActive()) { user.setActive(true); } return userRepository.save(user); diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java index 000091e..08523bd 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java @@ -12,10 +12,15 @@ import java.util.Optional; public interface ArrondissementService { Arrondissement createArrondissement(Arrondissement arrondissement) throws BadRequestException; + Arrondissement updateArrondissement(Long id, Arrondissement arrondissement) throws NotFoundException; + void deleteArrondissement(Long id) throws NotFoundException; + Page getArrondissementList(Pageable pageable); + List getArrondissementList(); + Optional getArrondissementById(Long id); List getArrondissementByComune(Long communeId); diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java index e6d4756..b0b9161 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java @@ -12,10 +12,16 @@ import java.util.Optional; public interface CommuneService { Commune createCommune(Commune commune) throws BadRequestException; + Commune updateCommune(Long id, Commune commune) throws NotFoundException; + void deleteCommune(Long id) throws NotFoundException; + Page getCommuneList(Pageable pageable); + List getCommuneList(); + List getCommunesByDepartement(Long departementId); + Optional getCommuneById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java index e7659ce..cd9bbbc 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface DepartementService { Departement createDepartement(Departement departement) throws BadRequestException; + Departement updateDepartement(Long id, Departement departement) throws NotFoundException; + void deleteDepartement(Long id) throws NotFoundException; + Page getDepartementList(Pageable pageable); + List getDepartementList(); + Optional getDepartementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/NationaliteService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/NationaliteService.java index 3b2091c..d317011 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/NationaliteService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/NationaliteService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface NationaliteService { Nationalite createNationalite(Nationalite nationalite) throws BadRequestException; + Nationalite updateNationalite(Long id, Nationalite nationalite) throws NotFoundException; + void deleteNationalite(Long id) throws NotFoundException; + Page getNationaliteList(Pageable pageable); + List getNationaliteList(); + Optional getNationaliteById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java index e383456..9a89d20 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java @@ -12,10 +12,16 @@ import java.util.Optional; public interface QuartierService { Quartier createQuartier(Quartier quartier) throws BadRequestException; + Quartier updateQuartier(Long id, Quartier quartier) throws NotFoundException; + void deleteQuartier(Long id) throws NotFoundException; + Page getQuartierList(Pageable pageable); + List getQuartierList(); + Optional getQuartierById(Long id); + List getQuartierByArrondissement(Long arrondissementId); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java index 5b5e103..1ae6caf 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java @@ -12,9 +12,13 @@ import java.util.Optional; public interface SecteurDecoupageService { SecteurDecoupage createSecteurDecoupage(SecteurDecoupage secteurDecoupage) throws BadRequestException; + SecteurDecoupage updateSecteurDecoupage(Long id, SecteurDecoupage secteurDecoupage) throws NotFoundException; + void deleteSecteurDecoupage(Long id) throws NotFoundException; + Page getSecteurDecoupageList(Pageable pageable); + List getSecteurDecoupageList(); Optional getSecteurDecoupageById(Long id); diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java index 35dd427..b3dec14 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java @@ -13,10 +13,15 @@ import java.util.Optional; public interface SecteurService { Secteur createSecteur(SecteurPayload secteur) throws BadRequestException; + Secteur updateSecteur(Long id, SecteurPayload secteur) throws NotFoundException; + void deleteSecteur(Long id) throws NotFoundException; + Page getSecteurList(Pageable pageable); + List getSecteurList(); + List getSecteurListUneStruture(Long structureId); Optional getSecteurById(Long id); diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ActeurConcerneService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ActeurConcerneService.java index 0af7aee..b1300e5 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ActeurConcerneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ActeurConcerneService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface ActeurConcerneService { ActeurConcerne createActeurConcerne(ActeurConcerne acteurConcerne) throws BadRequestException; + ActeurConcerne updateActeurConcerne(Long id, ActeurConcerne acteurConcerne) throws NotFoundException; + void deleteActeurConcerne(Long id) throws NotFoundException; + Page getActeurConcerneList(Pageable pageable); + List getActeurConcerneList(); + Optional getActeurConcerneById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/CommentaireService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/CommentaireService.java index 4aace64..231c5e3 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/CommentaireService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/CommentaireService.java @@ -13,15 +13,25 @@ import java.util.Optional; public interface CommentaireService { Commentaire createCommentaire(Commentaire commentaire) throws BadRequestException; + Commentaire updateCommentaire(Long id, Commentaire commentaire) throws NotFoundException; + void deleteCommentaire(Long id) throws NotFoundException; + List getCommentairesByEnqueteAndTerminal(Long idEnquete, Long terminalId); + List getCommentairesByEnqueteAndLu(Long idEnquete, boolean lu); + List getCommentairesByOrigineAndStateReadAndTerminalId(Origine origine, boolean lu, Long terminalId); + List getCommentairesByOrigineAndStateSynchronizedAndTerminalId(Origine origine, boolean synchronise, Long terminalId); + Optional getCommentaireByNup(String nup); + List getCommentaireList(); + Optional getCommentaireById(Long id); + boolean setCommentaireRead(Long id); List saveAllCommentairesFromMobile(List commentaires); diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/EnqueteService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/EnqueteService.java index 9180130..46a1f18 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/EnqueteService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/EnqueteService.java @@ -20,23 +20,38 @@ import java.util.Optional; public interface EnqueteService { Enquete createEnquete(EnquetePayLoad enquetePayLoad) throws BadRequestException; + Enquete updateEnquete(EnquetePayLoad enquetePayLoad) throws NotFoundException; + void deleteEnquete(Long id) throws NotFoundException; + Page getEnqueteList(Pageable pageable); + List getEnqueteList(); + List getEnqueteCommuneArrondBloc(); - List getEnqueteCommuneArrondBlocFiltre(FiltreEnquetePayLoad filtreEnquetePayLoad ); + + List getEnqueteCommuneArrondBlocFiltre(FiltreEnquetePayLoad filtreEnquetePayLoad); + Optional getEnqueteById(Long id); + Enquete validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad); + Enquete rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad); + List validerEnquete(List enqueteTraitementPayLoads); + List rejeterEnquete(List enqueteTraitementPayLoads); + Enquete finaliserEnquete(Long enqueteId); + Enquete reglerLitigeEnquete(Long enqueteId); + public UserDecoupageEnqResponses getDecoupageAdminUserConnecterAndStat(); + public FicheEnqueteResponse getFicheEnquete(Long EnqueteId); + public List getEnqueteValideNonSynch(Long terminalId); - } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/MembreGroupeService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/MembreGroupeService.java index 6816250..4bc12a6 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/MembreGroupeService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/MembreGroupeService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface MembreGroupeService { MembreGroupe createMembreGroupe(MembreGroupe membreGroupe) throws BadRequestException; + MembreGroupe updateMembreGroupe(Long id, MembreGroupe membreGroupe) throws NotFoundException; + void deleteMembreGroupe(Long id) throws NotFoundException; + Page getMembreGroupeList(Pageable pageable); + List getMembreGroupeList(); + Optional getMembreGroupeById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java index 587df2c..26bce7a 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java @@ -14,9 +14,14 @@ public interface ParcelleService { Parcelle createParcelle(ParcellePayLoad parcellePayLoad) throws BadRequestException; + Parcelle updateParcelle(ParcellePayLoad parcellePayLoad) throws NotFoundException; + void deleteParcelle(Long id) throws NotFoundException; + Page getParcelleList(Pageable pageable); + List getParcelleList(); + Optional getParcelleById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PieceService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PieceService.java index 9e6385a..8e4c116 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PieceService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PieceService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface PieceService { Piece createPiece(Piece piece) throws BadRequestException; + Piece updatePiece(Long id, Piece piece) throws NotFoundException; + void deletePiece(Long id) throws NotFoundException; + Page getPieceList(Pageable pageable); + List getPieceList(); + Optional getPieceById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/TpeService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/TpeService.java index ffcaf6a..dba5829 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/TpeService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/TpeService.java @@ -12,12 +12,20 @@ import java.util.Optional; public interface TpeService { Tpe createTpe(Tpe tpe) throws BadRequestException; + Tpe updateTpe(Long id, Tpe tpe) throws NotFoundException; + void deleteTpe(Long id) throws NotFoundException; + Page getTpeList(Pageable pageable); + List getTpeList(); + Optional getTpeById(Long id); + Optional getTepByIdentifier(String identifier); + List getTpeListByModel(String model); + List getTpeListByUserId(Long userId); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/BlocService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/BlocService.java index 3ec92fb..603977e 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/BlocService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/BlocService.java @@ -12,13 +12,21 @@ import java.util.Optional; public interface BlocService { Bloc createBloc(Bloc bloc) throws BadRequestException; + Bloc updateBloc(Long id, Bloc bloc) throws NotFoundException; + void deleteBloc(Long id) throws NotFoundException; + Page getBlocList(Pageable pageable); + List getBlocsByArrondissement(Long idArrondissement); + List getBlocsByStructure(Long idStructure); + List getBlocsBySecteur(Long idSecteur); + List getBlocList(); + Optional getBlocById(Long id); int countAllBlocByArrondissement(Long idArrondissement); diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ModeAcquisitionService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ModeAcquisitionService.java index e045bee..d0ec657 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ModeAcquisitionService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ModeAcquisitionService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface ModeAcquisitionService { ModeAcquisition createModeAcquisition(ModeAcquisition modeAcquisition) throws BadRequestException; + ModeAcquisition updateModeAcquisition(Long id, ModeAcquisition modeAcquisition) throws NotFoundException; + void deleteModeAcquisition(Long id) throws NotFoundException; + Page getModeAcquisitionList(Pageable pageable); + List getModeAcquisitionList(); + Optional getModeAcquisitionById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/NatureDomaineService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/NatureDomaineService.java index 9880c1b..8cbbd09 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/NatureDomaineService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/NatureDomaineService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface NatureDomaineService { NatureDomaine createNatureDomaine(NatureDomaine natureDomaine) throws BadRequestException; + NatureDomaine updateNatureDomaine(Long id, NatureDomaine natureDomaine) throws NotFoundException; + void deleteNatureDomaine(Long id) throws NotFoundException; + Page getNatureDomaineList(Pageable pageable); + List getNatureDomaineList(); + Optional getNatureDomaineById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PersonneService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PersonneService.java index c876929..3e06f6d 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PersonneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PersonneService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface PersonneService { Personne createPersonne(Personne personne) throws BadRequestException; + Personne updatePersonne(Long id, Personne personne) throws NotFoundException; + void deletePersonne(Long id) throws NotFoundException; + Page getPersonneList(Pageable pageable); + List getPersonneList(); + Optional getPersonneById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PositionRepresentationService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PositionRepresentationService.java index 95eb61c..cc122f0 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PositionRepresentationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/PositionRepresentationService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface PositionRepresentationService { PositionRepresentation createPositionRepresentation(PositionRepresentation positionRepresentation) throws BadRequestException; + PositionRepresentation updatePositionRepresentation(Long id, PositionRepresentation positionRepresentation) throws NotFoundException; + void deletePositionRepresentation(Long id) throws NotFoundException; + Page getPositionRepresentationList(Pageable pageable); + List getPositionRepresentationList(); + Optional getPositionRepresentationById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ProfessionService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ProfessionService.java index 9ac83d8..ff2fc76 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ProfessionService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/ProfessionService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface ProfessionService { Profession createProfession(Profession profession) throws BadRequestException; + Profession updateProfession(Long id, Profession profession) throws NotFoundException; + void deleteProfession(Long id) throws NotFoundException; + Page getProfessionList(Pageable pageable); + List getProfessionList(); + Optional getProfessionById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationGeographiqueService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationGeographiqueService.java index c32a12c..a6c08bd 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationGeographiqueService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationGeographiqueService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface SituationGeographiqueService { SituationGeographique createSituationGeographique(SituationGeographique situationGeographique) throws BadRequestException; + SituationGeographique updateSituationGeographique(Long id, SituationGeographique situationGeographique) throws NotFoundException; + void deleteSituationGeographique(Long id) throws NotFoundException; + Page getSituationGeographiqueList(Pageable pageable); + List getSituationGeographiqueList(); + Optional getSituationGeographiqueById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationMatrimonialeService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationMatrimonialeService.java index 3773a6a..fc13952 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationMatrimonialeService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SituationMatrimonialeService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface SituationMatrimonialeService { SituationMatrimoniale createSituationMatrimoniale(SituationMatrimoniale situationMatrimoniale) throws BadRequestException; + SituationMatrimoniale updateSituationMatrimoniale(Long id, SituationMatrimoniale situationMatrimoniale) throws NotFoundException; + void deleteSituationMatrimoniale(Long id) throws NotFoundException; + Page getSituationMatrimonialeList(Pageable pageable); + List getSituationMatrimonialeList(); + Optional getSituationMatrimonialeById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitExerceService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitExerceService.java index d77fbf1..f8f0ac7 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitExerceService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitExerceService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface SourceDroitExerceService { SourceDroitExerce createSourceDroitExerce(SourceDroitExerce sourceDroitExerce) throws BadRequestException; + SourceDroitExerce updateSourceDroitExerce(Long id, SourceDroitExerce sourceDroitExerce) throws NotFoundException; + void deleteSourceDroitExerce(Long id) throws NotFoundException; + Page getSourceDroitExerceList(Pageable pageable); + List getSourceDroitExerceList(); + Optional getSourceDroitExerceById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitService.java index 6ed63a6..3453aec 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/SourceDroitService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface SourceDroitService { SourceDroit createSourceDroit(SourceDroit sourceDroit) throws BadRequestException; + SourceDroit updateSourceDroit(Long id, SourceDroit sourceDroit) throws NotFoundException; + void deleteSourceDroit(Long id) throws NotFoundException; + Page getSourceDroitList(Pageable pageable); + List getSourceDroitList(); + Optional getSourceDroitById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/StructureService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/StructureService.java index 98abdfc..48de499 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/StructureService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/StructureService.java @@ -13,10 +13,16 @@ import java.util.Optional; public interface StructureService { Structure createStructure(Structure structure) throws BadRequestException; + Structure updateStructure(Long id, Structure structure) throws NotFoundException; + void deleteStructure(Long id) throws NotFoundException; + Page getStructureList(Pageable pageable); + List getStructureList(); + List getStructuresByArrondissement(Long arrondissementID); + Optional getStructureById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeContestationService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeContestationService.java index 9013bd9..f85f621 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeContestationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeContestationService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypeContestationService { TypeContestation createTypeContestation(TypeContestation typeContestation) throws BadRequestException; + TypeContestation updateTypeContestation(Long id, TypeContestation typeContestation) throws NotFoundException; + void deleteTypeContestation(Long id) throws NotFoundException; + Page getTypeContestationList(Pageable pageable); + List getTypeContestationList(); + Optional getTypeContestationById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeDomaineService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeDomaineService.java index d19040e..3fa8e1d 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeDomaineService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeDomaineService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypeDomaineService { TypeDomaine createTypeDomaine(TypeDomaine typeDomaine) throws BadRequestException; + TypeDomaine updateTypeDomaine(Long id, TypeDomaine typeDomaine) throws NotFoundException; + void deleteTypeDomaine(Long id) throws NotFoundException; + Page getTypeDomaineList(Pageable pageable); + List getTypeDomaineList(); + Optional getTypeDomaineById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePersonneService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePersonneService.java index a5f82fe..b09fa1a 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePersonneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePersonneService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypePersonneService { TypePersonne createTypePersonne(TypePersonne typePersonne) throws BadRequestException; + TypePersonne updateTypePersonne(Long id, TypePersonne typePersonne) throws NotFoundException; + void deleteTypePersonne(Long id) throws NotFoundException; + Page getTypePersonneList(Pageable pageable); + List getTypePersonneList(); + Optional getTypePersonneById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePieceService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePieceService.java index 07ed018..9ab0100 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePieceService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypePieceService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypePieceService { TypePiece createTypePiece(TypePiece typePiece) throws BadRequestException; + TypePiece updateTypePiece(Long id, TypePiece typePiece) throws NotFoundException; + void deleteTypePiece(Long id) throws NotFoundException; + Page getTypePieceList(Pageable pageable); + List getTypePieceList(); + Optional getTypePieceById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeRepresentationService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeRepresentationService.java index 0ee61fc..fb98289 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeRepresentationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/parametre/TypeRepresentationService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypeRepresentationService { TypeRepresentation createTypeRepresentation(TypeRepresentation typeRepresentation) throws BadRequestException; + TypeRepresentation updateTypeRepresentation(Long id, TypeRepresentation typeRepresentation) throws NotFoundException; + void deleteTypeRepresentation(Long id) throws NotFoundException; + Page getTypeRepresentationList(Pageable pageable); + List getTypeRepresentationList(); + Optional getTypeRepresentationById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/notification/EmailService.java b/src/main/java/io/gmss/fiscad/interfaces/notification/EmailService.java index 1b14295..5fde813 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/notification/EmailService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/notification/EmailService.java @@ -5,5 +5,6 @@ import io.gmss.fiscad.paylaods.EmailDetails; public interface EmailService { String sendSimpleMail(EmailDetails emailDetails); + String sendMailWithAttachment(EmailDetails emailDetails); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java index 3ac3817..0ee1d30 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface BatimentService { Batiment createBatiment(Batiment batiment) throws BadRequestException; + Batiment updateBatiment(Long id, Batiment batiment) throws NotFoundException; + void deleteBatiment(Long id) throws NotFoundException; + Page getBatimentList(Pageable pageable); + List getBatimentList(); + Optional getBatimentById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueBatimentService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueBatimentService.java index e941d49..1b008f0 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueBatimentService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueBatimentService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface CaracteristiqueBatimentService { CaracteristiqueBatiment createCaracteristiqueBatiment(CaracteristiqueBatiment caracteristiqueBatiment) throws BadRequestException; + CaracteristiqueBatiment updateCaracteristiqueBatiment(Long id, CaracteristiqueBatiment caracteristiqueBatiment) throws NotFoundException; + void deleteCaracteristiqueBatiment(Long id) throws NotFoundException; + Page getCaracteristiqueBatimentList(Pageable pageable); + List getCaracteristiqueBatimentList(); + Optional getCaracteristiqueBatimentById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueParcelleService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueParcelleService.java index d7f31cf..69cc46f 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueParcelleService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueParcelleService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface CaracteristiqueParcelleService { CaracteristiqueParcelle createCaracteristiqueParcelle(CaracteristiqueParcelle batiment) throws BadRequestException; + CaracteristiqueParcelle updateCaracteristiqueParcelle(Long id, CaracteristiqueParcelle batiment) throws NotFoundException; + void deleteCaracteristiqueParcelle(Long id) throws NotFoundException; + Page getCaracteristiqueParcelleList(Pageable pageable); + List getCaracteristiqueParcelleList(); + Optional getCaracteristiqueParcelleById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueUniteLogementService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueUniteLogementService.java index 1920997..10e9994 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueUniteLogementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CaracteristiqueUniteLogementService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface CaracteristiqueUniteLogementService { CaracteristiqueUniteLogement createCaracteristiqueUniteLogement(CaracteristiqueUniteLogement caracteristiqueUniteLogement) throws BadRequestException; + CaracteristiqueUniteLogement updateCaracteristiqueUniteLogement(Long id, CaracteristiqueUniteLogement caracteristiqueUniteLogement) throws NotFoundException; + void deleteCaracteristiqueUniteLogement(Long id) throws NotFoundException; + Page getCaracteristiqueUniteLogementList(Pageable pageable); + List getCaracteristiqueUniteLogementList(); + Optional getCaracteristiqueUniteLogementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteBatimentService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteBatimentService.java index 51b4a96..1562552 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteBatimentService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteBatimentService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface EnqueteBatimentService { EnqueteBatiment createEnqueteBatiment(EnqueteBatiment enqueteBatiment) throws BadRequestException; + EnqueteBatiment updateEnqueteBatiment(Long id, EnqueteBatiment enqueteBatiment) throws NotFoundException; + void deleteEnqueteBatiment(Long id) throws NotFoundException; + Page getEnqueteBatimentList(Pageable pageable); + List getEnqueteBatimentList(); + Optional getEnqueteBatimentById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteUniteLogementService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteUniteLogementService.java index b28668f..376c5cb 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteUniteLogementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/EnqueteUniteLogementService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface EnqueteUniteLogementService { EnqueteUniteLogement createEnqueteUniteLogement(EnqueteUniteLogement enqueteUniteLogement) throws BadRequestException; + EnqueteUniteLogement updateEnqueteUniteLogement(Long id, EnqueteUniteLogement enqueteUniteLogement) throws NotFoundException; + void deleteEnqueteUniteLogement(Long id) throws NotFoundException; + Page getEnqueteUniteLogementList(Pageable pageable); + List getEnqueteUniteLogementList(); + Optional getEnqueteUniteLogementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/UniteLogementService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/UniteLogementService.java index 46a3c8c..a262091 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/UniteLogementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/UniteLogementService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface UniteLogementService { UniteLogement createUniteLogement(UniteLogement uniteLogement) throws BadRequestException; + UniteLogement updateUniteLogement(Long id, UniteLogement uniteLogement) throws NotFoundException; + void deleteUniteLogement(Long id) throws NotFoundException; + Page getUniteLogementList(Pageable pageable); + List getUniteLogementList(); + Optional getUniteLogementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CampagneService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CampagneService.java index df2bd72..eafea52 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CampagneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CampagneService.java @@ -13,11 +13,17 @@ import java.util.Optional; public interface CampagneService { Campagne createCampagne(Campagne campagne) throws BadRequestException; + Campagne updateCampagne(Long id, Campagne campagne) throws NotFoundException; + void deleteCampagne(Long id) throws NotFoundException; + Page getCampagneList(Pageable pageable); + List getCampagneList(); + List getCampagnesByType(TypeCampagne typeCampagne); + Optional getCampagneById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CaracteristiqueService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CaracteristiqueService.java index ff6f5a3..854b014 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CaracteristiqueService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/CaracteristiqueService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface CaracteristiqueService { Caracteristique createCaracteristique(Caracteristique caracteristique) throws BadRequestException; + Caracteristique updateCaracteristique(Long id, Caracteristique caracteristique) throws NotFoundException; + void deleteCaracteristique(Long id) throws NotFoundException; + Page getCaracteristiqueList(Pageable pageable); + List getCaracteristiqueList(); + Optional getCaracteristiqueById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/EquipeService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/EquipeService.java index ec81ef2..bc47f69 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/EquipeService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/EquipeService.java @@ -13,10 +13,15 @@ import java.util.Optional; public interface EquipeService { Equipe createEquipe(EquipePayload equipePayload) throws BadRequestException; + Equipe updateEquipe(Long id, EquipePayload equipePayload) throws NotFoundException; + void deleteEquipe(Long id) throws NotFoundException; + Page getEquipeList(Pageable pageable); + List getEquipeList(); + Optional getEquipeById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/TypeCaracteristiqueService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/TypeCaracteristiqueService.java index 364f847..aa543f9 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/TypeCaracteristiqueService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/parametre/TypeCaracteristiqueService.java @@ -12,9 +12,14 @@ import java.util.Optional; public interface TypeCaracteristiqueService { TypeCaracteristique createTypeCaracteristique(TypeCaracteristique typeCaracteristique) throws BadRequestException; + TypeCaracteristique updateTypeCaracteristique(Long id, TypeCaracteristique typeCaracteristique) throws NotFoundException; + void deleteTypeCaracteristique(Long id) throws NotFoundException; + Page getTypeCaracteristiqueList(Pageable pageable); + List getTypeCaracteristiqueList(); + Optional getTypeCaracteristiqueById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/statistique/StatistiquesService.java b/src/main/java/io/gmss/fiscad/interfaces/statistique/StatistiquesService.java index 5b4126a..95185cc 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/statistique/StatistiquesService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/statistique/StatistiquesService.java @@ -9,8 +9,11 @@ import java.util.List; public interface StatistiquesService { List getStatEnqueteParStatut(); + List getStatEnqueteAdminDecoupage(Long idCommune); + List getStatEnqueteAdminStructure(); + List getStatBloc(); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/synchronisation/RestaurationService.java b/src/main/java/io/gmss/fiscad/interfaces/synchronisation/RestaurationService.java index 73a76fe..af5063d 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/synchronisation/RestaurationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/synchronisation/RestaurationService.java @@ -7,20 +7,32 @@ import java.util.List; public interface RestaurationService { - List getActeurConcernes(Long terminaleId) ; - List getEnquete(Long terminaleId) ; - List getPersonne(Long terminaleId) ; - List getParcelle(Long terminaleId) ; - List getPieces(Long terminaleId) ; - List getMembreGroupe(Long terminaleId) ; - List getUpload(Long terminaleId) ; + List getActeurConcernes(Long terminaleId); + + List getEnquete(Long terminaleId); + + List getPersonne(Long terminaleId); + + List getParcelle(Long terminaleId); + + List getPieces(Long terminaleId); + + List getMembreGroupe(Long terminaleId); + + List getUpload(Long terminaleId); List getBatiment(Long terminalId); + List getEnqueteBatiment(Long terminalId); + List getCaracateristiqueParcelle(Long terminalId); + List getCaracateristiqueBatiment(Long terminalId); + List getCaracateristiqueUniteLogement(Long terminalId); + List getEnqueteUniteLogement(Long terminalId); + List getUniteLogement(Long terminalId); public List getTpeListByCurrentUser(); diff --git a/src/main/java/io/gmss/fiscad/interfaces/synchronisation/SynchronisationService.java b/src/main/java/io/gmss/fiscad/interfaces/synchronisation/SynchronisationService.java index 606572d..33a9ae8 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/synchronisation/SynchronisationService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/synchronisation/SynchronisationService.java @@ -12,21 +12,37 @@ import java.util.List; public interface SynchronisationService { public UserDecoupageSyncResponses getDecoupageAdminUserConnecter(); + public ReferencesSyncResponses getReferencesSyncResponses(); + public SyncEnqueteAllDataResponse syncEnqueteAllData(EnqueteAllDataPayload enqueteAllDataPayload); + public List syncPersonnes(List personnePayLoads); + public List syncBatiment(List batimentPaylaods); + public List syncUniteLogement(List uniteLogementPaylaods); + public List syncCaracteristiqueBatiment(List caracteristiqueBatimentPaylods); + public List syncCaracteristiqueParcelle(List caracteristiqueParcellePaylods); + public List syncCaracteristiqueUniteLogement(List caracteristiqueUniteLogementPaylods); + public List syncMembreGroupe(List membreGroupePayLoads); + public List syncEnquete(List enquetePayLoads); + public List syncEnqueteBatiment(List enquetebatimentPayLoads); + public List syncEnqueteUniteLogement(List enqueteUniteLogementPayloads); + public List syncParcelle(List parcellePayLoads); + public List syncPiece(List piecePayLoads); + public List syncActeurConcerne(List acteurConcernePayLoads); + public SyncResponse syncFiles(MultipartFile file, Long idBackend, Long externalKey, @@ -41,7 +57,7 @@ public interface SynchronisationService { Long enqueteId, Long enqueteBatimentId, Long enqueteUniteLogementId - ); + ); public List syncEnqueteFromMobile(List idEnquete); diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/DemandeReinitialisationMPService.java b/src/main/java/io/gmss/fiscad/interfaces/user/DemandeReinitialisationMPService.java index 2a1796a..e9d9a49 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/user/DemandeReinitialisationMPService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/user/DemandeReinitialisationMPService.java @@ -13,11 +13,18 @@ import java.util.Optional; public interface DemandeReinitialisationMPService { DemandeReinitialisationMP createDemandeReinitialisationMP(String usernameOrEmail) throws BadRequestException; + DemandeReinitialisationMP updateDemandeReinitialisationMP(Long id, DemandeReinitialisationMP demandeReinitialisationMP) throws NotFoundException; + void deleteDemandeReinitialisationMP(Long id) throws NotFoundException; + Page getDemandeReinitialisationMPList(Pageable pageable); + List getDemandeReinitialisationMPList(); + List getDemandeReinitialisationMPNonTraiteList(Structure structure); + Optional getDemandeReinitialisationMPById(Long id); + DemandeReinitialisationMP traiterDemandeReinitialisation(Long id, String password); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/RoleService.java b/src/main/java/io/gmss/fiscad/interfaces/user/RoleService.java index 230e824..cc22547 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/user/RoleService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/user/RoleService.java @@ -13,11 +13,17 @@ import java.util.Optional; public interface RoleService { Role createRole(Role role) throws BadRequestException; + Role updateRole(Long id, Role role) throws NotFoundException; + void deleteRole(Long id) throws NotFoundException; + Page getRoleList(Pageable pageable); + List getRoleList(); + Optional getRoleById(Long id); + Optional getRoleByRoleName(UserRole userRole); boolean roleExistByRoleName(UserRole userRole); diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java b/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java index ff5116e..93037ad 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java @@ -15,17 +15,27 @@ import java.util.List; public interface UserService { User createUser(User user, boolean resetPassword); + JwtAuthenticationResponse loginUser(Login login); + User updateUser(Long id, User user); void updatePassword(String username, String pwd); + void deleteUser(Long id); + Page getUserList(Pageable pageable); + List getUserList(); + List getAllUserListResponse(); + List getActivatedUserListByStructure(Long structureId); + List getUserUnActivatedListByStructure(Long StructureId); + long countUser(); + User getUserById(Long id); User getUserByUsername(String username); @@ -39,6 +49,7 @@ public interface UserService { User validateUserAccount(String username, UserRole userRole); UserListByStructureResponse getListUserByStructure(Long structureId); + List getListUserResponseByStructure(Long structureId); UserResponse getUserResponseFromUser(User user); diff --git a/src/main/java/io/gmss/fiscad/paylaods/Critere.java b/src/main/java/io/gmss/fiscad/paylaods/Critere.java index fcd47db..1a19aa3 100755 --- a/src/main/java/io/gmss/fiscad/paylaods/Critere.java +++ b/src/main/java/io/gmss/fiscad/paylaods/Critere.java @@ -13,8 +13,8 @@ import java.util.Date; @NoArgsConstructor public class Critere { - private String search; - private StatusEnquete status; - private Date startDate; - private Date endDate; + private String search; + private StatusEnquete status; + private Date startDate; + private Date endDate; } diff --git a/src/main/java/io/gmss/fiscad/paylaods/JwtAuthenticationResponse.java b/src/main/java/io/gmss/fiscad/paylaods/JwtAuthenticationResponse.java index ae918c7..bf9609e 100755 --- a/src/main/java/io/gmss/fiscad/paylaods/JwtAuthenticationResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/JwtAuthenticationResponse.java @@ -10,25 +10,25 @@ import java.util.Date; @JsonAutoDetect public class JwtAuthenticationResponse { - private String token; + private String token; private String tokenType = "Bearer"; @Temporal(value = TemporalType.TIMESTAMP) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm a z") private Date expiryToken; public JwtAuthenticationResponse(String token, Date expiryToken) { - super(); - this.token = token; - this.expiryToken = expiryToken; - } + super(); + this.token = token; + this.expiryToken = expiryToken; + } - public String getToken() { - return token; - } + public String getToken() { + return token; + } - public void setToken(String token) { - this.token = token; - } + public void setToken(String token) { + this.token = token; + } public String getTokenType() { return tokenType; @@ -38,21 +38,20 @@ public class JwtAuthenticationResponse { this.tokenType = tokenType; } - /** - * @return the expiryToken - */ + /** + * @return the expiryToken + */ @JsonFormat(shape = JsonFormat.Shape.NUMBER) - public Date getExpiryToken() { - return expiryToken; - } + public Date getExpiryToken() { + return expiryToken; + } + + /** + * @param expiryToken the expiryToken to set + */ + public void setExpiryToken(Date expiryToken) { + this.expiryToken = expiryToken; + } + - /** - * @param expiryToken the expiryToken to set - */ - public void setExpiryToken(Date expiryToken) { - this.expiryToken = expiryToken; - } - - - } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/ActeurConcernePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/request/ActeurConcernePayLoad.java index 7e8dcfa..0c0ad63 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/ActeurConcernePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/ActeurConcernePayLoad.java @@ -28,8 +28,8 @@ public class ActeurConcernePayLoad { //////////////////////////////////// private Long blocId; @ColumnDefault("0") - private int haveDeclarant ; - private Long max_numero_acteur_concerne_id ; + private int haveDeclarant; + private Long max_numero_acteur_concerne_id; } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/EnqueteAllDataPayload.java b/src/main/java/io/gmss/fiscad/paylaods/request/EnqueteAllDataPayload.java index b363d37..6f334e4 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/EnqueteAllDataPayload.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/EnqueteAllDataPayload.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.paylaods.request; import lombok.Data; import java.util.List; + @Data public class EnqueteAllDataPayload { private List personnes; diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/EnquetePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/request/EnquetePayLoad.java index 9ae7e24..c4d4116 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/EnquetePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/EnquetePayLoad.java @@ -6,6 +6,7 @@ import jakarta.persistence.Enumerated; import lombok.Data; import java.time.LocalDate; + @Data public class EnquetePayLoad { private Long idBackend; diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/EquipePayload.java b/src/main/java/io/gmss/fiscad/paylaods/request/EquipePayload.java index 086aaef..1af41e0 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/EquipePayload.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/EquipePayload.java @@ -16,7 +16,7 @@ public class EquipePayload implements Serializable { private String code; private String nom; private Long blocId; - private Long secteurId ; + private Long secteurId; private Long campagneId; private List participerPayloads; } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/ParcellePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/request/ParcellePayLoad.java index a25c772..e992f67 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/ParcellePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/ParcellePayLoad.java @@ -1,6 +1,7 @@ package io.gmss.fiscad.paylaods.request; import lombok.Data; + @Data public class ParcellePayLoad { private Long idBackend; diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/ParticiperPayload.java b/src/main/java/io/gmss/fiscad/paylaods/request/ParticiperPayload.java index 74477ec..e8df1e9 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/ParticiperPayload.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/ParticiperPayload.java @@ -22,6 +22,6 @@ public class ParticiperPayload implements Serializable { @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) private LocalDate dateFin; - private Long equipeId ; + private Long equipeId; private Long userId; } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/SecteurPayload.java b/src/main/java/io/gmss/fiscad/paylaods/request/SecteurPayload.java index 959b271..f5a3c82 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/SecteurPayload.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/SecteurPayload.java @@ -11,10 +11,10 @@ import java.util.List; @NoArgsConstructor @AllArgsConstructor public class SecteurPayload implements Serializable { - private Long id ; - private String code ; - private String nom ; - private Long chefSecteurId ; - private Long structureId ; - private List secteurDecoupages ; + private Long id; + private String code; + private String nom; + private Long chefSecteurId; + private Long structureId; + private List secteurDecoupages; } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/UniteLogementPaylaod.java b/src/main/java/io/gmss/fiscad/paylaods/request/UniteLogementPaylaod.java index bdcf200..325344f 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/UniteLogementPaylaod.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/UniteLogementPaylaod.java @@ -1,6 +1,7 @@ package io.gmss.fiscad.paylaods.request; import lombok.Data; + @Data public class UniteLogementPaylaod { private Long idBackend; diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementEnqResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementEnqResponse.java index 7142a7b..a0bbd47 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementEnqResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementEnqResponse.java @@ -2,8 +2,12 @@ package io.gmss.fiscad.paylaods.response; public interface ArrondissementEnqResponse { public Long getId(); + public String getCode(); + public String getLibelle(); + public Long getCommuneId(); + public Long getNombreEnquete(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementSyncResponse.java index dd63b46..a5b9e0f 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/ArrondissementSyncResponse.java @@ -2,7 +2,10 @@ package io.gmss.fiscad.paylaods.response; public interface ArrondissementSyncResponse { public Long getId(); + public String getCode(); + public String getNom(); + public Long getCommuneId(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/BlocEnqResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/BlocEnqResponse.java index 67e2fcd..112e7c4 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/BlocEnqResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/BlocEnqResponse.java @@ -1,10 +1,14 @@ package io.gmss.fiscad.paylaods.response; public interface BlocEnqResponse { - public Long getId(); - public String getCote(); - public String getLibelle(); - public Long getArrondissementId(); - public Long getnombreEnquete(); + Long getId(); + + String getCote(); + + String getLibelle(); + + Long getArrondissementId(); + + Long getnombreEnquete(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/BlocSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/BlocSyncResponse.java index d77a0c1..e6a84a0 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/BlocSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/BlocSyncResponse.java @@ -1,9 +1,13 @@ package io.gmss.fiscad.paylaods.response; public interface BlocSyncResponse { - public Long getId(); - public String getCote(); - public String getNom(); - public Long getArrondissementId(); - public Long getQuartierId(); + Long getId(); + + String getCote(); + + String getNom(); + + Long getArrondissementId(); + + Long getQuartierId(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/CommuneEnqResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/CommuneEnqResponse.java index 976e3de..a35ef33 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/CommuneEnqResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/CommuneEnqResponse.java @@ -2,8 +2,11 @@ package io.gmss.fiscad.paylaods.response; public interface CommuneEnqResponse { public Long getId(); + public String getCode(); + public String getLibelle(); + public Long getNombreEnquete(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/CommuneSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/CommuneSyncResponse.java index 8bde1bf..b212e60 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/CommuneSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/CommuneSyncResponse.java @@ -2,7 +2,10 @@ package io.gmss.fiscad.paylaods.response; public interface CommuneSyncResponse { public Long getId(); + public String getCode(); + public String getNom(); + public Long getDepartementId(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/DepartementEnqResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/DepartementEnqResponse.java index 6711b7c..f3c4587 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/DepartementEnqResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/DepartementEnqResponse.java @@ -1,8 +1,10 @@ package io.gmss.fiscad.paylaods.response; public interface DepartementEnqResponse { - public Long getId(); - public String getCode(); - public String getNom(); + Long getId(); + + String getCode(); + + String getNom(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/DepartementSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/DepartementSyncResponse.java index 6beff2f..244f617 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/DepartementSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/DepartementSyncResponse.java @@ -2,6 +2,8 @@ package io.gmss.fiscad.paylaods.response; public interface DepartementSyncResponse { public Long getId(); + public String getCode(); + public String getNom(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteNonSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteNonSyncResponse.java index 2fd9ad4..084d8a9 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteNonSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteNonSyncResponse.java @@ -5,9 +5,13 @@ import io.gmss.fiscad.enums.StatusEnquete; public interface EnqueteNonSyncResponse { public Long getIdBackend(); + public Long getExternalKey(); + public StatusEnquete getStatusEnquete(); + public String getMotif(); + public Long getTerminalId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteResponse.java index b8a73f3..71e8b0e 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/EnqueteResponse.java @@ -9,32 +9,53 @@ import java.time.LocalDate; public interface EnqueteResponse { public Long getId(); + public String getParcelleId(); + public Long getCommuneId(); + public String getCommuneNom(); + public Long getArrondissementId(); + public String getArrondissementNom(); + public Long getBlocId(); + public String getBlocNom(); + public Long getStructureId(); + public String getStructureNom(); + public boolean getLitige(); + public String getStatusEnquete(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateFinalisation(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateValidation(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateSynchronisation(); + public String getNomSigle(); + public String getPrenomRaisonSociale(); + public String getTypePersonne(); + public String getTypeDomaine(); + public String getNatureDomaine(); + public String getNupProvisoire(); + public Long getTerminalId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/FicheEnqueteResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/FicheEnqueteResponse.java index 80a2e53..9c3ff83 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/FicheEnqueteResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/FicheEnqueteResponse.java @@ -15,7 +15,7 @@ public class FicheEnqueteResponse { //private Enquete enquete ; //private List acteurConcernes; - private FicheEnquetesResponse enquete ; + private FicheEnquetesResponse enquete; private List acteurConcernes; } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheActeurConcerneResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheActeurConcerneResponse.java index 5ef0c93..5a921c8 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheActeurConcerneResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheActeurConcerneResponse.java @@ -35,6 +35,6 @@ public class FicheActeurConcerneResponse { private boolean synchronise; ////////////////////////////// private Long blocId; - private int haveDeclarant ; + private int haveDeclarant; private Long max_numero_acteur_concerne_id; } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheEnquetesResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheEnquetesResponse.java index 7bb0d6b..7e0bd98 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheEnquetesResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/FicheResponse/FicheEnquetesResponse.java @@ -126,65 +126,69 @@ public class FicheEnquetesResponse { private List enquetesBatiments; private List enquetesUniteLogements; - public String getNomPrenomEnqueteur(){ - if(this.user!=null){ - return this.user.getNom()+" "+this.user.getPrenom(); - }else return ""; + public String getNomPrenomEnqueteur() { + if (this.user != null) { + return this.user.getNom() + " " + this.user.getPrenom(); + } else return ""; } - public String getNomBloc(){ - if(this.bloc!=null){ + + public String getNomBloc() { + if (this.bloc != null) { return this.bloc.getNom(); - }else return ""; + } else return ""; } - public String getCodeBloc(){ - if(this.bloc!=null){ + public String getCodeBloc() { + if (this.bloc != null) { return this.bloc.getCote(); - }else return ""; + } else return ""; } - public String getDepartement(){ - if(this.bloc!=null){ - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + + public String getDepartement() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getCommune().getDepartement().getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getCommune(){ - if(this.bloc!=null){ - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + + public String getCommune() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getCommune().getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getArrondissement(){ - if(this.bloc!=null) { - Arrondissement arrondissement= this.bloc.getArrondissement(); - if(arrondissement!=null){ + public String getArrondissement() { + if (this.bloc != null) { + Arrondissement arrondissement = this.bloc.getArrondissement(); + if (arrondissement != null) { return arrondissement.getNom(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getTypeDomaine(){ - if(this.parcelle!=null){ - NatureDomaine natureDomaine= this.parcelle.getNatureDomaine(); - if(natureDomaine!=null){ + + public String getTypeDomaine() { + if (this.parcelle != null) { + NatureDomaine natureDomaine = this.parcelle.getNatureDomaine(); + if (natureDomaine != null) { return natureDomaine.getTypeDomaine().getLibelle(); - }else return ""; - }else return ""; + } else return ""; + } else return ""; } - public String getTelEnqueteur(){ - if(this.user !=null){ + public String getTelEnqueteur() { + if (this.user != null) { return this.user.getTel(); - }else return ""; + } else return ""; } - public String getStructureEnqueteur(){ - if(this.user !=null){ + public String getStructureEnqueteur() { + if (this.user != null) { return this.user.getStructure().getNom(); - }else return ""; + } else return ""; } } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionSourceSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionSourceSyncResponse.java index 3b7aabd..7b70231 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionSourceSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionSourceSyncResponse.java @@ -2,7 +2,9 @@ package io.gmss.fiscad.paylaods.response; public interface ModesAcquisitionSourceSyncResponse { public Long getId(); + public String getLibelle(); + public Long getSourceId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionTypePersonneSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionTypePersonneSyncResponse.java index 86aba56..e3811d4 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionTypePersonneSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/ModesAcquisitionTypePersonneSyncResponse.java @@ -2,6 +2,8 @@ package io.gmss.fiscad.paylaods.response; public interface ModesAcquisitionTypePersonneSyncResponse { public Long getId(); + public String getLibelle(); + public Long getTypePersonneId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/NatureDomaineSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/NatureDomaineSyncResponse.java index 740cc50..9b839ab 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/NatureDomaineSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/NatureDomaineSyncResponse.java @@ -2,6 +2,7 @@ package io.gmss.fiscad.paylaods.response; public interface NatureDomaineSyncResponse { public Long getId(); + public String getLibelle(); public Long getTypeDomaineId(); diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/QuartierSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/QuartierSyncResponse.java index 8061186..f1e7c31 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/QuartierSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/QuartierSyncResponse.java @@ -2,7 +2,10 @@ package io.gmss.fiscad.paylaods.response; public interface QuartierSyncResponse { public Long getId(); + public String getCode(); + public String getNom(); + public Long getArrondissementId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/ReferencesSyncResponses.java b/src/main/java/io/gmss/fiscad/paylaods/response/ReferencesSyncResponses.java index 91cd040..39890ff 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/ReferencesSyncResponses.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/ReferencesSyncResponses.java @@ -7,21 +7,22 @@ import io.gmss.fiscad.entities.rfu.parametre.TypeCaracteristique; import lombok.Data; import java.util.List; + @Data public class ReferencesSyncResponses { - List typeRepresentationSyncResponses ; - List typePieceSyncResponses ; - List typePersonneSyncResponses ; - List typeDomaineSyncResponses ; - List typeContestationSyncResponses ; - List sourceDroitSyncResponses ; - List situationMatrimonialeSyncResponses ; - List professionSyncResponses ; - List positionRepresentationSyncResponses ; - List natureDomaineSyncResponses ; - List nationaliteSyncResponses ; - List modeAcquisitionSyncResponses ; - List situationSyncGeographiques ; + List typeRepresentationSyncResponses; + List typePieceSyncResponses; + List typePersonneSyncResponses; + List typeDomaineSyncResponses; + List typeContestationSyncResponses; + List sourceDroitSyncResponses; + List situationMatrimonialeSyncResponses; + List professionSyncResponses; + List positionRepresentationSyncResponses; + List natureDomaineSyncResponses; + List nationaliteSyncResponses; + List modeAcquisitionSyncResponses; + List situationSyncGeographiques; List modesAcquisitionSourceSyncResponses; List typePersonneNatureDomaineSyncResponses; List modesAcquisitionTypePersonneSyncResponses; diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/SourceDroitsSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/SourceDroitsSyncResponse.java index 5a7f075..d6d76ac 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/SourceDroitsSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/SourceDroitsSyncResponse.java @@ -2,11 +2,17 @@ package io.gmss.fiscad.paylaods.response; public interface SourceDroitsSyncResponse { public Long getId(); + public String getLibelle(); + public boolean isTitreFoncier(); + public String getTypeChamp(); + public int getTailleChampMin(); + public int getTailleChampMax(); + public boolean getTemoin(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminDecoupageResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminDecoupageResponse.java index 95055d7..fed0957 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminDecoupageResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminDecoupageResponse.java @@ -2,8 +2,12 @@ package io.gmss.fiscad.paylaods.response; public interface StatEnqueteAdminDecoupageResponse { public String getArrondissement(); + public Long getTotal(); + public Long getValide(); + public Long getRejet(); + public Long getSynchronise(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminStructureResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminStructureResponse.java index 0d50d08..741eb60 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminStructureResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteAdminStructureResponse.java @@ -2,8 +2,12 @@ package io.gmss.fiscad.paylaods.response; public interface StatEnqueteAdminStructureResponse { public String getStructure(); + public Long getTotal(); + public Long getValide(); + public Long getRejet(); + public Long getSynchronise(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParBlocResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParBlocResponse.java index 20ceb0f..c03765d 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParBlocResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParBlocResponse.java @@ -2,7 +2,10 @@ package io.gmss.fiscad.paylaods.response; public interface StatEnqueteParBlocResponse { public String getBloc(); + public Long getValide(); + public Long getRejet(); + public Long getSynchronise(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParStatutResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParStatutResponse.java index 4165231..b2f244a 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParStatutResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/StatEnqueteParStatutResponse.java @@ -2,5 +2,6 @@ package io.gmss.fiscad.paylaods.response; public interface StatEnqueteParStatutResponse { public String getStatutEnquete(); + public Long getNombre(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/StructureResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/StructureResponse.java index 0112bee..523de1f 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/StructureResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/StructureResponse.java @@ -2,10 +2,16 @@ package io.gmss.fiscad.paylaods.response; public interface StructureResponse { public Long getId(); + public String getCode(); + public String getNom(); + public String getRccm(); + public String getTel(); + public String getEmail(); + public String getAdresse(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/SyncEnqueteAllDataResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/SyncEnqueteAllDataResponse.java index c10dfb6..afa9732 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/SyncEnqueteAllDataResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/SyncEnqueteAllDataResponse.java @@ -7,10 +7,10 @@ import java.util.List; @Data public class SyncEnqueteAllDataResponse { private List personneSynResponses; - private List membreGroupeSynResponses; - private List parcelleSynResponses; - private List enqueteSynResponses; - private List acteurConcerneSynResponses; - private List pieceSynResponses; + private List membreGroupeSynResponses; + private List parcelleSynResponses; + private List enqueteSynResponses; + private List acteurConcerneSynResponses; + private List pieceSynResponses; } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/SyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/SyncResponse.java index 53a4d31..be508f5 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/SyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/SyncResponse.java @@ -8,12 +8,14 @@ public class SyncResponse { private Long externalKey; private boolean synchronise; private String observation; + public SyncResponse(Long idBackend, Long externalKey, boolean synchronise, String observation) { this.idBackend = idBackend; this.externalKey = externalKey; this.synchronise = synchronise; this.observation = observation; } + public SyncResponse() { } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/TypePersonneNatureDomaineSyncResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/TypePersonneNatureDomaineSyncResponse.java index a64414f..c054439 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/TypePersonneNatureDomaineSyncResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/TypePersonneNatureDomaineSyncResponse.java @@ -1,10 +1,13 @@ - package io.gmss.fiscad.paylaods.response; public interface TypePersonneNatureDomaineSyncResponse { public Long getId(); + public String getLibelle(); + public String isGroupeOuvert(); + public Long getNatureDomaineId(); + public Long getTypeContestationId(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/UserDecoupageSyncResponses.java b/src/main/java/io/gmss/fiscad/paylaods/response/UserDecoupageSyncResponses.java index d931235..f74db0a 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/UserDecoupageSyncResponses.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/UserDecoupageSyncResponses.java @@ -1,9 +1,9 @@ - package io.gmss.fiscad.paylaods.response; import lombok.Data; import java.util.List; + @Data public class UserDecoupageSyncResponses { public List departementSyncResponses; diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/report/BlocsParStructureResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/report/BlocsParStructureResponse.java index 3accf51..220e644 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/report/BlocsParStructureResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/report/BlocsParStructureResponse.java @@ -2,8 +2,12 @@ package io.gmss.fiscad.paylaods.response.report; public interface BlocsParStructureResponse { public String getCode(); + public String getNom(); + public String getArrondissement(); + public String getCommune(); + public String getDepartement(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/report/EnqueteParBlocResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/report/EnqueteParBlocResponse.java index 261287b..5a2abc0 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/report/EnqueteParBlocResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/report/EnqueteParBlocResponse.java @@ -2,12 +2,20 @@ package io.gmss.fiscad.paylaods.response.report; public interface EnqueteParBlocResponse { public String getNupProvisoire(); + public String getQuartier(); + public String getQ(); + public String getI(); + public String getP(); + public boolean getLitige(); + public String getNature(); + public String getNomProprietaire(); + public String getTelephone(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/report/ZoneInterventionParStructureResponse.java b/src/main/java/io/gmss/fiscad/paylaods/response/report/ZoneInterventionParStructureResponse.java index 3d251fe..e49fd47 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/report/ZoneInterventionParStructureResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/report/ZoneInterventionParStructureResponse.java @@ -2,7 +2,10 @@ package io.gmss.fiscad.paylaods.response.report; public interface ZoneInterventionParStructureResponse { public String getDepartement(); + public String getCommune(); + public String getArrondissement(); + public String getQuartier(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ActeurConcernePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ActeurConcernePayLoad.java index 1ac7c23..a16c616 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ActeurConcernePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ActeurConcernePayLoad.java @@ -8,22 +8,37 @@ import jakarta.persistence.Enumerated; public interface ActeurConcernePayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public float getPart(); + @Enumerated(EnumType.STRING) public TypeDroit getTypeDroit(); + public Long getEnqueteId(); + public Long getPositionRepresentationId(); + public Long getPersonneId(); + public Long getTypeRepresentationId(); + public Long getTypeContestationId(); + @Enumerated(EnumType.STRING) public RoleActeur getRoleActeur(); + public boolean getSynchronise(); + public String getObservation(); + public Long getTerminalId(); + public Long getBlocId(); - public int getHaveDeclarant() ; + + public int getHaveDeclarant(); + public Long getMax_numero_acteur_concerne_id(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/BatimentPayload.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/BatimentPayload.java index 8c0e8de..2f496b1 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/BatimentPayload.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/BatimentPayload.java @@ -9,10 +9,13 @@ import java.time.LocalDate; public interface BatimentPayload { public Long getIdBackend(); + public Long getExternalKey(); public String getNub(); + public String getCode(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateConstruction(); diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueBatimentPayLoads.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueBatimentPayLoads.java index f7d790a..4e81f56 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueBatimentPayLoads.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueBatimentPayLoads.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.paylaods.response.restoration; public interface CaracateristiqueBatimentPayLoads { public Long getIdBackend(); + public Long getExternalKey(); public Long getEnqueteBatimentId(); diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueParcellePayLoads.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueParcellePayLoads.java index 140046a..e2e982b 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueParcellePayLoads.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/CaracateristiqueParcellePayLoads.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.paylaods.response.restoration; public interface CaracateristiqueParcellePayLoads { public Long getIdBackend(); + public Long getExternalKey(); public Long getEnqueteId(); diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteBatimentPayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteBatimentPayLoad.java index d555ccc..97843ae 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteBatimentPayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteBatimentPayLoad.java @@ -8,31 +8,54 @@ import java.time.LocalDate; public interface EnqueteBatimentPayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public float getSurfaceAuSol(); + public String getAutreMenuisierie(); + public String getAutreMur(); + public boolean getSbee(); + public String getNumCompteurSbee(); + public boolean getSoneb(); + public String getNumCompteurSoneb(); + public int getNbreLotUnite(); + public int getNbreUniteLocation(); + public float getSurfaceLouee(); + public int getNbreMenage(); + public int getNbreHabitant(); + public float getValeurMensuelleLocation(); + public int getNbreMoisLocation(); + public String getAutreCaracteristiquePhysique(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateDebutExcemption(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateFinExcemption(); + public Long getPersonneId(); + public Long getBatimentId(); + public Long getEnqueteId(); + public Long getTerminalId(); + public Long getUserId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnquetePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnquetePayLoad.java index cb40f0a..fba6c98 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnquetePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnquetePayLoad.java @@ -11,47 +11,82 @@ import java.time.LocalDate; public interface EnquetePayLoad { public Long getIdBackend(); + public Long getExternalKey(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateEnquete(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateFinalisation(); + public boolean getLitige(); + public Long getUserId(); + public Long getParcelleId(); + public Long getBlocId(); + @Enumerated(EnumType.STRING) public StatusEnquete getStatusEnquete(); + public String getDescriptionMotifRejet(); + public String getObservationParticuliere(); + public String getObservation(); + public boolean getSynchronise(); + public Long getTerminalId(); + public Long getQuartierId(); + public Long getArrondissementId(); + public Long getCommuneId(); + public Long getDepartementId(); + public Long getNumeroProvisoir(); + public String getCodeParcelle(); + public String getNomProprietaireParcelle(); + public String getCodeEquipe(); + public String getNumeroTitreFoncier(); public String getNumEnterParcelle(); + public String getNumRue(); + public String getNomRue(); + public String getEmplacement(); + public float getAltitude(); + public float getPrecision(); + public int getNbreCoProprietaire(); + public int getNbreIndivisiaire(); + public String getAutreAdresse(); + public String getSurface(); + public int getNbreBatiment(); + public int getNbrePiscine(); + public LocalDate getDateDebutExcemption(); + public LocalDate getDateFinExcemption(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteUniteLogementPayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteUniteLogementPayLoad.java index fa312cb..cf88c3a 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteUniteLogementPayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/EnqueteUniteLogementPayLoad.java @@ -8,30 +8,51 @@ import java.time.LocalDate; public interface EnqueteUniteLogementPayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public float getSurface(); + public int getNbrePiece(); + public int getNbreHabitant(); + public int getNbreMenage(); + public boolean getEnLocation(); + public float getMontantMensuelLoyer(); + public int getNbreMoisEnLocation(); + public float getMontantLocatifAnnuelDeclare(); + public float getSurfaceLouee(); + public boolean getSbee(); + public boolean getSoneb(); + public String getNumCompteurSbee(); + public String getNumCompteurSoneb(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateDebutExcemption(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateFinExcemption(); + public Long getPersonneId(); + public Long getUniteLogementId(); + public Long getEnqueteId(); + public Long getTerminalId(); + public Long getUserId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/MembreGroupePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/MembreGroupePayLoad.java index e7368de..1753786 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/MembreGroupePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/MembreGroupePayLoad.java @@ -1,19 +1,30 @@ - package io.gmss.fiscad.paylaods.response.restoration; public interface MembreGroupePayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public Long getPersonneSecondaireId(); + public Long getPersonneId(); + public Long getPositionRepresentationId(); + public Long getTypeRepresentationId(); + public String getObservation(); + public boolean getSynchronise(); + public Long getTerminalId(); + public Long getEnqueteId(); + public Long getBlocId(); + public Long getMax_numero_piece_id(); + public Long getMax_numero_acteur_concerne_id(); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcellePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcellePayLoad.java index 8e90923..f62bd6c 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcellePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcellePayLoad.java @@ -2,23 +2,41 @@ package io.gmss.fiscad.paylaods.response.restoration; public interface ParcellePayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public String getQ(); + public String getNup(); + public String getNupProvisoire(); + public String getLongitude(); + public String getLatitude(); + public String getSituationGeographique(); + public Long getNatureDomaineId(); + public Long getQuartierId(); + public String getI(); + public String getP(); + public boolean getSynchronise(); + public String getObservation(); + public Long getTerminalId(); + public String getNumTitreFoncier(); + public Long getTypeDomaineId(); + public Long getNumeroProvisoire(); + public Long getBlocId(); //public int getGeomSrid(); diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PersonnePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PersonnePayLoad.java index 5b32b95..2a4230d 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PersonnePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PersonnePayLoad.java @@ -7,37 +7,68 @@ import jakarta.persistence.Enumerated; public interface PersonnePayLoad { public Long getIdBackend(); + public String getIfu(); + public Long getExternalKey(); + public String getNomOuSigle(); + public String getPrenomOuRaisonSociale(); + public String getNumRavip(); + public String getNpi(); + public String getDateNaissanceOuConsti(); + public String getLieuNaissance(); + public String getTel1(); + public String getTel2(); + public String getAdresse(); + @Enumerated(EnumType.STRING) public Categorie getCategorie(); + public Long getSituationMatrimonialeId(); + public Long getNationaliteId(); + public Long getTypePersonneId(); + public Long getProfessionId(); + public Long getCommuneId(); + public String getObservation(); + public boolean getSynchronise(); + public Long getTerminalId(); + public int getHaveRepresentant(); + public String getRavipQuestion(); + public String getAge(); + public String getNomJeuneFille(); + public String getNomMere(); + public String getPrenomMere(); + public String getIndicatifTel1(); + public String getIndicatifTel2(); + public String getSexe(); + public int getMustHaveRepresentant(); + public String getFilePath(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PiecePayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PiecePayLoad.java index f90b10c..dbedf81 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PiecePayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/PiecePayLoad.java @@ -9,24 +9,41 @@ import java.time.LocalDate; public interface PiecePayLoad { public Long getIdBackend(); + public Long getExternalKey(); + @JsonFormat(pattern = "dd-MM-yyyy") @JsonDeserialize(using = LocalDateDeserializer.class) public LocalDate getDateExpiration(); + public String getNumeroPiece(); + public String getUrl(); + public Long getTypePieceId(); + public Long getPersonneId(); + public Long getActeurConcerneId(); + public Long getMembreGroupeId(); + public Long getSourceDroitId(); + public Long getModeAcquisitionId(); + public boolean getSynchronise(); + public String getObservation(); + public Long getTerminalId(); + public Long getMax_numero_piece_id(); + public Long getMax_numero_acteur_concerne_id(); + public Long getEnqueteId(); + public Long getBlocId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UniteLogementPayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UniteLogementPayLoad.java index ee64df1..d857684 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UniteLogementPayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UniteLogementPayLoad.java @@ -3,11 +3,17 @@ package io.gmss.fiscad.paylaods.response.restoration; public interface UniteLogementPayLoad { public Long getIdBackend(); + public Long getExternalKey(); + public Long getTerminalId(); + public String getNul(); + public String getNumeroEtage(); + public String getCode(); + public Long getBatimentId(); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UploadPayLoad.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UploadPayLoad.java index 05cdaec..1603a64 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UploadPayLoad.java +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/UploadPayLoad.java @@ -4,20 +4,35 @@ import org.springframework.web.multipart.MultipartFile; public interface UploadPayLoad { public Long getIdBackend(); + public Long getExternalKey(); - public Long getPieceId(); + + public Long getPieceId(); + public String getObservation(); + public boolean getSynchronise(); + public MultipartFile getFile(); + public Long getMembreGroupeId(); + public Long getTerminalId(); + public String getName(); + public String getFilePath(); + public Long getMax_numero_piece_id(); + public Long getMax_numero_upload_id(); + public Long getMax_numero_acteur_concerne_id(); + public Long getEnqueteId(); + public Long getBlocId(); + public String getFileBackendName(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/CommuneRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/CommuneRepository.java index 2c6cb83..7c3d78d 100755 --- a/src/main/java/io/gmss/fiscad/repositories/decoupage/CommuneRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/CommuneRepository.java @@ -11,8 +11,9 @@ import java.util.List; public interface CommuneRepository extends JpaRepository { - @Query(value = "select id, code, nom, departement_id as departementid from commune ",nativeQuery = true) + @Query(value = "select id, code, nom, departement_id as departementid from commune ", nativeQuery = true) List getCommuneResponse(); + List findAllByDepartement(Departement departement); @Query(value = " Select T.id,T.code, T.libelle, sum(case when T.enqueteId is null then 0 else 1 end) as nombreEnquete " + @@ -22,15 +23,16 @@ public interface CommuneRepository extends JpaRepository { " left join bloc b on b.arrondissement_id=a.id " + " left join enquete e on e.bloc_id=b.id " + " where sa.structure_id = ?1 )T" + - " group by T.id,T.code, T.libelle",nativeQuery = true) + " group by T.id,T.code, T.libelle", nativeQuery = true) List getCommuneEnqResponse(Long structure_id); + @Query(value = " Select T.id,T.code, T.libelle, sum(case when T.enqueteId is null then 0 else 1 end) as nombreEnquete " + " From (select distinct c.id as id,c.code as code, c.nom as libelle, e.id as enqueteId from arrondissement a" + " left join arrondissements_structures sa on sa.arrondissement_id=a.id " + " left join commune c on c.id= a.commune_id " + " left join bloc b on b.arrondissement_id=a.id " + " left join enquete e on e.bloc_id=b.id)T " + - " group by T.id,T.code, T.libelle",nativeQuery = true) + " group by T.id,T.code, T.libelle", nativeQuery = true) List getAdminCommuneEnqResponse(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/DepartementRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/DepartementRepository.java index c4cf479..93e2aea 100755 --- a/src/main/java/io/gmss/fiscad/repositories/decoupage/DepartementRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/DepartementRepository.java @@ -11,7 +11,7 @@ import java.util.List; public interface DepartementRepository extends JpaRepository { @Query(value = "select id, code, nom from departement" + - " where departement.deleted is false ",nativeQuery = true) + " where departement.deleted is false ", nativeQuery = true) List getDepartementResponse(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/NationaliteRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/NationaliteRepository.java index b8bcb18..9f3426d 100755 --- a/src/main/java/io/gmss/fiscad/repositories/decoupage/NationaliteRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/NationaliteRepository.java @@ -8,5 +8,6 @@ import java.util.List; public interface NationaliteRepository extends JpaRepository { List findAllByOrderByLibelleAsc(); + List findAllByOrderByLibelleAsc(Pageable pageable); } diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/QuartierRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/QuartierRepository.java index 3feaac6..805c30d 100755 --- a/src/main/java/io/gmss/fiscad/repositories/decoupage/QuartierRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/QuartierRepository.java @@ -10,16 +10,17 @@ import java.util.List; public interface QuartierRepository extends JpaRepository { List getAllByArrondissement(Arrondissement arrondissement); + @Query(value = "select q.id,q.code, q.nom, a.id as arrondissementid from arrondissement a " + " left join quartier q on q.arrondissement_id=a.id " + " left join arrondissements_structures sa on sa.arrondissement_id=a.id" + - " where q.deleted is false and sa.structure_id = ?1 ",nativeQuery = true) + " where q.deleted is false and sa.structure_id = ?1 ", nativeQuery = true) List getQuartierResponse(Long structure_id); @Query(value = "select q.id,q.code, q.nom, a.id as arrondissementid from arrondissement a " + " left join quartier q on q.arrondissement_id=a.id " + " left join arrondissements_structures sa on sa.arrondissement_id=a.id" + - " where q.deleted is false ",nativeQuery = true) + " where q.deleted is false ", nativeQuery = true) List getAdminQuartierResponse(); diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ActeurConcerneRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ActeurConcerneRepository.java index 54a2358..3e61a4a 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ActeurConcerneRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ActeurConcerneRepository.java @@ -10,8 +10,10 @@ import java.util.Optional; public interface ActeurConcerneRepository extends JpaRepository { Optional findFirstByExternalKey(Long externalKey); + List findActeurConcerneByEnquete_Id(Long EnqueteId); - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long terminalId); + + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long terminalId); @Query(value = "delete from acteur_concerne ac where ac.id in (select ac.id from enquete e" + " inner join acteur_concerne ac on e.id = ac.enquete_id" + @@ -35,7 +37,7 @@ public interface ActeurConcerneRepository extends JpaRepository getActeurConcerneByTerminalId(Long terminalId); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/CommentaireRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/CommentaireRepository.java index ce5d029..e6fb3a9 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/CommentaireRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/CommentaireRepository.java @@ -9,9 +9,13 @@ import java.util.Optional; public interface CommentaireRepository extends JpaRepository { List findAllByIdEnqueteAndTerminalId(Long idEnquete, Long terminalId); + List findAllByOrigineAndLuAndTerminalId(Origine origine, boolean lu, Long terminalId); + List findAllByOrigineAndSynchroniseAndTerminalId(Origine origine, boolean synchronise, Long terminalId); + List findAllByIdEnqueteAndLu(Long idEnquete, boolean lu); + Optional getCommentaireByNupParcelle(String nup); Optional findCommentaireByExternalKey(Long externalKey); diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/EnqueteRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/EnqueteRepository.java index 01685de..ee81af1 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/EnqueteRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/EnqueteRepository.java @@ -47,7 +47,7 @@ public interface EnqueteRepository extends JpaRepository { " inner join personne per on per.id=ac.personne_id " + " left join type_personne tp on tp.id=per.type_personne_id " + " where e.deleted is false and ac.role_acteur='PROPRIETAIRE'" - ,nativeQuery = true) + , nativeQuery = true) List getEnqueteComArrondBloc(); @@ -62,7 +62,7 @@ public interface EnqueteRepository extends JpaRepository { " from enquete e " + " where e.deleted is false and e.synchronise is false " + " and e.terminal_id= ?1" - ,nativeQuery = true) + , nativeQuery = true) List getEnqueteValNonSync(Long terminalId); @Query(value = "select " + @@ -71,7 +71,7 @@ public interface EnqueteRepository extends JpaRepository { " from enquete e " + " where e.deleted is false " + " group by e.status_enquete" - ,nativeQuery = true) + , nativeQuery = true) List getStatEnqueteParStatut(); @Query(value = "select " + @@ -83,7 +83,7 @@ public interface EnqueteRepository extends JpaRepository { " inner join users u on u.structure_id=s.id " + " where e.deleted is false and u.id = ?1 " + " group by e.status_enquete " - ,nativeQuery = true) + , nativeQuery = true) List getStatEnqueteParStatut(Long userId); @Query(value = "select " + @@ -100,7 +100,7 @@ public interface EnqueteRepository extends JpaRepository { " right join users u on u.structure_id=s.id " + " where e.deleted is false and u.id = ?1 " + " group by b.cote " - ,nativeQuery = true) + , nativeQuery = true) List getStatEnqueteParBloc(Long idUser); @@ -117,8 +117,9 @@ public interface EnqueteRepository extends JpaRepository { " right join arrondissement a on a.id=b.arrondissement_id" + " where e.deleted is false and a.commune_id = ?1 " + " group by a.nom " - ,nativeQuery = true) + , nativeQuery = true) List getStatEnqueteParDecoupage(Long idCommune); + @Query(value = "select " + " s.nom as structure, " + " SUM(case when e.status_enquete='VALIDE' then 1 else 0 end) + " + @@ -132,10 +133,10 @@ public interface EnqueteRepository extends JpaRepository { " right join structure s on s.id=b.structure_id " + " where e.deleted is false " + " group by s.nom " - ,nativeQuery = true) + , nativeQuery = true) List getStatEnqueteParStructure(); - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long terminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long terminalId); List findAllByUser_Id(Long userId); diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/MembreGroupeRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/MembreGroupeRepository.java index 0d55bcd..70c45bb 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/MembreGroupeRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/MembreGroupeRepository.java @@ -9,8 +9,10 @@ import java.util.List; import java.util.Optional; public interface MembreGroupeRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long terminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long terminalId); + void deleteMembreGroupeByPersonneRepresantante_Id(Long personneRepresenteId); + @Query(value = "Select " + " mg.id as idBackend, " + " mg.external_key as externalKey, " + @@ -27,7 +29,7 @@ public interface MembreGroupeRepository extends JpaRepository getMembreGroupeByTerminalId(Long terminalId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java index db48151..348c6b0 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Optional; public interface ParcelleRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long TerminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); @Query(value = "Select " + " p.id as idBackend, " + @@ -34,7 +34,7 @@ public interface ParcelleRepository extends JpaRepository { " p.bloc_id as blocId " + // " p.geom_srid as geomSrid " + " From parcelle p " + - " where p.terminal_id = ?1",nativeQuery = true) + " where p.terminal_id = ?1", nativeQuery = true) List getParcellesByTerminalId(Long terminalId); diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/PieceRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/PieceRepository.java index 39a0fc8..9a7b618 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/PieceRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/PieceRepository.java @@ -9,7 +9,8 @@ import java.util.List; import java.util.Optional; public interface PieceRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long terminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long terminalId); + @Query(nativeQuery = true, value = "delete from piece p where p.id in (select p.id " + " from piece p inner join acteur_concerne a on a.id = p.acteur_concerne_id" + " inner join enquete e on e.id = a.enquete_id" + @@ -41,10 +42,9 @@ public interface PieceRepository extends JpaRepository { " p.bloc_id as blocId " + " from piece p left join personne pp on p.personne_id = pp.id left join acteur_concerne ac on ac.id = p.personne_id " + " where p.terminal_id = ?1" - ,nativeQuery = true) + , nativeQuery = true) List getPiecesByTerminalId(Long terminalId); - } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/TpeRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/TpeRepository.java index 1c48fd7..c6cf31a 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/TpeRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/TpeRepository.java @@ -11,6 +11,7 @@ import java.util.Optional; public interface TpeRepository extends JpaRepository { Optional findDistinctByIdentifier(String identifier); + List findAllByModel(String model); boolean existsDistinctByIdentifier(String identifier); @@ -21,7 +22,7 @@ public interface TpeRepository extends JpaRepository { @Query(value = "select distinct tpe.* " + "from tpe inner join enquete e on e.terminal_id=tpe.id " + - " where e.user_id = ?1",nativeQuery = true) + " where e.user_id = ?1", nativeQuery = true) List getTpeByUserId(Long userId); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/UploadRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/UploadRepository.java index 236ec6f..cd49827 100644 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/UploadRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/UploadRepository.java @@ -12,13 +12,16 @@ import java.util.List; public interface UploadRepository extends JpaRepository { void deleteUploadByPiece_Personne_Id(Long personneId); + //void deleteUploadByPiece_ActeurConcerne_Enquete_Id(Long enqueteId); @Query(nativeQuery = true, value = "delete from upload u where u.id in (select u.id from upload u" + " inner join piece p on p.id = u.piece_id" + " inner join acteur_concerne ac on ac.id = p.acteur_concerne_id" + " inner join enquete e on e.id = ac.enquete_id where e.id = ?1)") void deleteUploadByEnqueteID(Long enqueteId); + void deleteUploadByMembreGroupe_PersonneRepresantee_Id(Long personneRepresente); + @Query(value = "Select " + " u.id as idBackend, " + " u.external_key as externalKey, " + @@ -37,10 +40,11 @@ public interface UploadRepository extends JpaRepository { " u.file_name as fileBackendName " + " From upload u inner join public.piece p on p.id = u.piece_id" + " where u.terminal_id = ?1" - ,nativeQuery = true) + , nativeQuery = true) List getUploadByTerminalId(Long terminalId); void deleteAllByEnqueteBatiment(EnqueteBatiment enqueteBatiment); + void deleteAllByEnqueteUniteLogement(EnqueteUniteLogement enqueteUniteLogement); ///////////////////////////////// diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/BlocRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/BlocRepository.java index 9d1bd00..33a8e1e 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/BlocRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/BlocRepository.java @@ -13,25 +13,28 @@ import java.util.List; public interface BlocRepository extends JpaRepository { List findAllByStructure_Id(Long structureId); + List findAllBySecteur_Id(Long secteurId); + @Query(value = "select b.id, b.cote, b.nom, b.arrondissement_id as arrondissementid, b.quartier_id as quartierid " + " from bloc b" + - " where b.deleted is false and b.structure_id = ?1 ",nativeQuery = true) + " where b.deleted is false and b.structure_id = ?1 ", nativeQuery = true) List getBlocResponse(Long structure_id); @Query(value = "select b.id, b.cote, b.nom, b.arrondissement_id as arrondissementid, b.quartier_id as quartierid " + " from bloc b " + " inner join secteur_decoupage sd on cd.bloc_id=b.id " + - " where b.deleted is false and s.structure_id = ?1 and sd.secteur_id=?2",nativeQuery = true) - List getBlocSecteurResponse(Long structure_id,Long secteur_id); + " where b.deleted is false and s.structure_id = ?1 and sd.secteur_id=?2", nativeQuery = true) + List getBlocSecteurResponse(Long structure_id, Long secteur_id); @Query(value = " select b.id, b.cote as code, b.nom as nom , a.nom as arrondissement, c.nom as commune, d.nom as departement " + " from bloc b inner join arrondissement a on a.id=b.arrondissement_id" + " inner join commune c on c.id=a.commune_id " + " inner join departement d on d.id=c.departement_id " + - " where b.deleted is false and b.structure_id = ?1 ",nativeQuery = true) + " where b.deleted is false and b.structure_id = ?1 ", nativeQuery = true) List getBlocsParStructureResponse(Long structure_id); + List findAllByArrondissement(Arrondissement arrondissement); @Query(value = "select structure_id as id from arrondissements_structures " + @@ -53,7 +56,7 @@ public interface BlocRepository extends JpaRepository { " from arrondissement a" + " inner join bloc b on b.arrondissement_id=a.id " + " where b.deleted is false " + - " group by b.id, b.cote, b.nom, a.id ",nativeQuery = true) + " group by b.id, b.cote, b.nom, a.id ", nativeQuery = true) List getAdminBlocResponse(); @Query(value = "select T.blocId as id, T.cote, T.libelle, T.arrondissementid,sum(case when T.enqueteId is null then 0 else 1 end) as nombreEnquete " + @@ -63,8 +66,9 @@ public interface BlocRepository extends JpaRepository { " inner join bloc b on b.arrondissement_id=a.id " + " left join enquete e on e.bloc_id=b.id " + " where (b.deleted is false and e.deleted is false and a.deleted is false) and b.structure_id = ?1)T" + - " group by T.blocId, T.cote, T.libelle, T.arrondissementid ",nativeQuery = true) + " group by T.blocId, T.cote, T.libelle, T.arrondissementid ", nativeQuery = true) List getBlocEnqResponse(Long structure_id); + @Query(value = "select T.blocId as id, T.cote, T.libelle, T.arrondissementid, sum(case when T.enqueteId is null then 0 else 1 end) as nombreEnquete " + " from ( select distinct b.id as blocId, b.cote as cote, b.nom as libelle, a.id as arrondissementid, e.id as enqueteId " + " from arrondissement a" + @@ -72,7 +76,7 @@ public interface BlocRepository extends JpaRepository { " inner join bloc b on b.arrondissement_id=a.id " + " left join enquete e on e.bloc_id=b.id " + " where b.deleted is false ) T" + - " group by T.blocId, T.cote, T.libelle, T.arrondissementid ",nativeQuery = true) + " group by T.blocId, T.cote, T.libelle, T.arrondissementid ", nativeQuery = true) List getAdminBlocEnqResponse(); @@ -88,7 +92,7 @@ public interface BlocRepository extends JpaRepository { " inner join blocs_quartiers bq on bq.quartier_id=q.id " + " inner join bloc b on b.id=bq.bloc_id " + " inner join structure s on s.id=b.structure_id" + - " where e.delete is false and s.id = ?1 ",nativeQuery = true) + " where e.delete is false and s.id = ?1 ", nativeQuery = true) List getZoneInterventionParStructureResponse(Long structure_id); } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/ModeAcquisitionRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/ModeAcquisitionRepository.java index 9656245..ac979a0 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/ModeAcquisitionRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/ModeAcquisitionRepository.java @@ -11,6 +11,6 @@ public interface ModeAcquisitionRepository extends JpaRepository getModeAcquisitionTypePersonne(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/NatureDomaineRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/NatureDomaineRepository.java index db68cf4..b2e2321 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/NatureDomaineRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/NatureDomaineRepository.java @@ -11,13 +11,13 @@ import java.util.List; public interface NatureDomaineRepository extends JpaRepository { @Query(value = "select id, libelle, type_domaine_id as typedomaineid from nature_domaine " + - " where deleted is false ",nativeQuery = true) + " where deleted is false ", nativeQuery = true) List getNatureDomaineResponse(); @Query(value = "select tp.id as id, tp.groupe_ouvert as groupeOuvert, tp.libelle as libelle, ndtp.nature_domaine_id as natureDomaineId from type_personne tp " + " inner join nature_domaine_type_personne ndtp on ndtp.type_personne_id=tp.id " + - " where tp.deleted is false ",nativeQuery = true) + " where tp.deleted is false ", nativeQuery = true) List getTypePersonneNatureDomaineSyncResponse(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/PersonneRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/PersonneRepository.java index b08a853..56727af 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/PersonneRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/PersonneRepository.java @@ -9,7 +9,8 @@ import java.util.List; import java.util.Optional; public interface PersonneRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long TerminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); + @Query(value = "Select " + " p.id as idBackend, " + " p.ifu, " + @@ -45,7 +46,7 @@ public interface PersonneRepository extends JpaRepository { " p.must_have_representant as mustHaveRepresentant, " + " p.file_path as filePath " + " From personne p " + - " where p.terminal_id = ?1",nativeQuery = true) + " where p.terminal_id = ?1", nativeQuery = true) List getPersonnesByTerminalId(Long terminalId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/SourceDroitRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/SourceDroitRepository.java index f5460ea..0c25a6f 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/SourceDroitRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/SourceDroitRepository.java @@ -9,14 +9,14 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; public interface SourceDroitRepository extends JpaRepository { - @Query(value = "SELECT id, libelle, titre_foncier as titreFoncier, taille_champ_min as tailleChampMin, taille_champ_max as tailleChampMax, type_champ as typeChamp, temoin from source_droit where deleted is false",nativeQuery = true) + @Query(value = "SELECT id, libelle, titre_foncier as titreFoncier, taille_champ_min as tailleChampMin, taille_champ_max as tailleChampMax, type_champ as typeChamp, temoin from source_droit where deleted is false", nativeQuery = true) List getSourceDroitSyncResponse(); @Query(value = "SELECT distinct id,libelle, sdm.sources_droits_id as sourceid " + " from mode_acquisition ma " + " inner join sources_de_droits_modes_acquisitions sdm on sdm.modes_acquisitions_id=ma.id " + - " where ma.deleted is false ",nativeQuery = true) + " where ma.deleted is false ", nativeQuery = true) List getModeAcquitionSourceSyncResponse(); } diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/StructureRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/StructureRepository.java index b6ac16c..49bd415 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/StructureRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/parametre/StructureRepository.java @@ -16,6 +16,6 @@ public interface StructureRepository extends JpaRepository { @Query(value = "select s.id, s.code, s.nom, s.ifu, s.rccm, s.tel, s.email, s.adresse" + " from structure s inner join " + " arrondissements_structures sa on s.id = sa.structure_id and " + - " sa.arrondissement_id = ?1",nativeQuery = true) + " sa.arrondissement_id = ?1", nativeQuery = true) List getStructureByArrondissement(Long arrondissementId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/BatimentRepository.java b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/BatimentRepository.java index 044461b..d346d2f 100755 --- a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/BatimentRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/BatimentRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; public interface BatimentRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long TerminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); @Query(value = "SELECT " + " b.id as idBackend," + diff --git a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueParcelleRepository.java b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueParcelleRepository.java index 9ee90bd..cd5ea81 100755 --- a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueParcelleRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueParcelleRepository.java @@ -12,17 +12,18 @@ import java.util.List; public interface CaracteristiqueParcelleRepository extends JpaRepository { void deleteAllByEnquete(Enquete enquete); + List findAllByEnquete_Id(Long id); @Query(nativeQuery = true, - value = "select cp.id as idBackend, " + - "cp.external_key as externalKey, " + - "c.external_key as caracteristiqueId, " + - "e.external_key as enqueteId, " + - "cp.valeur as valeur " + - "from caracteristique_parcelle cp " + - "inner join caracteristique c on cp.caracteristique_id = c.id " + - "inner join enquete e on cp.enquete_id = e.id " + - "where cp.terminal_id = ?") + value = "select cp.id as idBackend, " + + "cp.external_key as externalKey, " + + "c.external_key as caracteristiqueId, " + + "e.external_key as enqueteId, " + + "cp.valeur as valeur " + + "from caracteristique_parcelle cp " + + "inner join caracteristique c on cp.caracteristique_id = c.id " + + "inner join enquete e on cp.enquete_id = e.id " + + "where cp.terminal_id = ?") List getCaracteristiqueParcelleByTerminalId(Long terminalId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueUniteLogementRepository.java b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueUniteLogementRepository.java index c84bce0..ee94b38 100755 --- a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueUniteLogementRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/CaracteristiqueUniteLogementRepository.java @@ -13,15 +13,15 @@ public interface CaracteristiqueUniteLogementRepository extends JpaRepository getCaracteristiqueUniteLogementByTerminalId(Long terminalId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/EnqueteBatimentRepository.java b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/EnqueteBatimentRepository.java index 57340e2..1b371e5 100755 --- a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/EnqueteBatimentRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/EnqueteBatimentRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; public interface EnqueteBatimentRepository extends JpaRepository { - Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey,Long TerminalId); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); List findAllByEnquete_Id(Long enqueteId); @@ -22,7 +22,7 @@ public interface EnqueteBatimentRepository extends JpaRepository { -Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); -List findAllByEnquete_Id(Long id); + Optional findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); -@Query(nativeQuery = true, -value = "select eul.id as idBackend, " + - "eul.terminal_id as terminalId, " + - "eul.external_key as externalKey, " + - "eul.surface as surface, " + - "eul.nbre_piece as nbrePiece, " + - "eul.nbre_habitant as nbreHabitant, " + - "eul.nbre_menage as nbreMenage, " + - "eul.en_location as enLocation, " + - "eul.montant_mensuel_loyer as montantMensuelLoyer, " + - "eul.nbre_mois_en_location as nbreMoisEnLocation, " + - "eul.montant_locatif_annuel_declare as montantLocatifAnnuelDeclare, " + - "eul.surface_louee as surfaceLouee, " + - "eul.sbee as sbee, " + - "eul.soneb as soneb, " + - "eul.num_compteur_sbee as numCompteurSbee, " + - "eul.num_compteur_soneb as numCompteurSoneb, " + - "eul.date_debut_excemption as dateDebutExcemption, " + - "eul.date_fin_excemption as dateFinExcemption, " + - "eul.personne_id as personneId, " + - "eul.unite_logement_id as uniteLogementId, " + - "eul.enquete_id as enqueteId, " + - "eul.user_id as userId " + - "from enquete_unite_logement eul " + - "inner join enquete e on e.id = eul.enquete_id " + - "inner join unite_logement ul on eul.unite_logement_id = ul.id " + - "inner join personne p on eul.personne_id = p.id " + - "where eul.terminal_id = ?1") -List getEnqueteUniteLogementByTerminalId(Long terminalId); + List findAllByEnquete_Id(Long id); + + @Query(nativeQuery = true, + value = "select eul.id as idBackend, " + + "eul.terminal_id as terminalId, " + + "eul.external_key as externalKey, " + + "eul.surface as surface, " + + "eul.nbre_piece as nbrePiece, " + + "eul.nbre_habitant as nbreHabitant, " + + "eul.nbre_menage as nbreMenage, " + + "eul.en_location as enLocation, " + + "eul.montant_mensuel_loyer as montantMensuelLoyer, " + + "eul.nbre_mois_en_location as nbreMoisEnLocation, " + + "eul.montant_locatif_annuel_declare as montantLocatifAnnuelDeclare, " + + "eul.surface_louee as surfaceLouee, " + + "eul.sbee as sbee, " + + "eul.soneb as soneb, " + + "eul.num_compteur_sbee as numCompteurSbee, " + + "eul.num_compteur_soneb as numCompteurSoneb, " + + "eul.date_debut_excemption as dateDebutExcemption, " + + "eul.date_fin_excemption as dateFinExcemption, " + + "eul.personne_id as personneId, " + + "eul.unite_logement_id as uniteLogementId, " + + "eul.enquete_id as enqueteId, " + + "eul.user_id as userId " + + "from enquete_unite_logement eul " + + "inner join enquete e on e.id = eul.enquete_id " + + "inner join unite_logement ul on eul.unite_logement_id = ul.id " + + "inner join personne p on eul.personne_id = p.id " + + "where eul.terminal_id = ?1") + List getEnqueteUniteLogementByTerminalId(Long terminalId); } diff --git a/src/main/java/io/gmss/fiscad/repositories/user/RoleRepository.java b/src/main/java/io/gmss/fiscad/repositories/user/RoleRepository.java index 342bf2e..9aeefde 100755 --- a/src/main/java/io/gmss/fiscad/repositories/user/RoleRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/user/RoleRepository.java @@ -8,8 +8,10 @@ import java.util.Optional; public interface RoleRepository extends JpaRepository { Optional findRoleById(Long id); + Optional findRoleByNom(UserRole nom); boolean existsByNom(UserRole userRole); + Role getRolesByNom(UserRole userRole); } diff --git a/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java b/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java index d67d1d6..20e06dc 100755 --- a/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java @@ -13,9 +13,12 @@ import java.util.Set; public interface UserRepository extends JpaRepository { Optional findByUsername(String username); + long countAllByUsernameIsNotNull(); List findAllByStructureAndRolesIn(Structure structure, Set roleSet); + List findAllByStructureAndRolesNotIn(Structure structure, Set roleSet); + List findAllByRolesContains(UserRole userRole); } diff --git a/src/main/java/io/gmss/fiscad/security/CustomUserDetailsService.java b/src/main/java/io/gmss/fiscad/security/CustomUserDetailsService.java index 33db96d..65f180d 100755 --- a/src/main/java/io/gmss/fiscad/security/CustomUserDetailsService.java +++ b/src/main/java/io/gmss/fiscad/security/CustomUserDetailsService.java @@ -13,29 +13,29 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { - + private final UserRepository userRepository; - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - - User user = userRepository.findByUsername(username) + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + + User user = userRepository.findByUsername(username) .orElseThrow(() -> new UsernameNotFoundException("User not found with username or email : " + username) + ); + + UserPrincipal userprincipal = UserPrincipal.create(user); + + System.out.println("userprincipal = " + userprincipal); + return userprincipal; + } + + public UserDetails loadUserById(Long id) throws UsernameNotFoundException { + User user = userRepository.findById(id).orElseThrow( + () -> new UsernameNotFoundException("User not found with id : " + id) ); - UserPrincipal userprincipal = UserPrincipal.create(user); - - System.out.println("userprincipal = " + userprincipal); - return userprincipal; - } - - public UserDetails loadUserById(Long id) throws UsernameNotFoundException{ - User user = userRepository.findById(id).orElseThrow( - () -> new UsernameNotFoundException("User not found with id : " + id) - ); - - return UserPrincipal.create(user); - } + return UserPrincipal.create(user); + } } diff --git a/src/main/java/io/gmss/fiscad/security/JwtAuthenticationEntryPoint.java b/src/main/java/io/gmss/fiscad/security/JwtAuthenticationEntryPoint.java index b75d802..7a7e03d 100755 --- a/src/main/java/io/gmss/fiscad/security/JwtAuthenticationEntryPoint.java +++ b/src/main/java/io/gmss/fiscad/security/JwtAuthenticationEntryPoint.java @@ -14,14 +14,14 @@ import java.io.IOException; @Component public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { - private static final Logger logger = LoggerFactory.getLogger(JwtAuthenticationEntryPoint.class); + private static final Logger logger = LoggerFactory.getLogger(JwtAuthenticationEntryPoint.class); - @Override - public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException authExcp) - throws IOException, ServletException { - logger.error("Responding with unauthorized error. Message - {}", authExcp.getMessage()); + @Override + public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException authExcp) + throws IOException, ServletException { + logger.error("Responding with unauthorized error. Message - {}", authExcp.getMessage()); httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Sorry, You're not authorized to access this resource."); - } + } } diff --git a/src/main/java/io/gmss/fiscad/security/JwtAuthenticationFilter.java b/src/main/java/io/gmss/fiscad/security/JwtAuthenticationFilter.java index c2eb8e8..44fcfa7 100755 --- a/src/main/java/io/gmss/fiscad/security/JwtAuthenticationFilter.java +++ b/src/main/java/io/gmss/fiscad/security/JwtAuthenticationFilter.java @@ -16,17 +16,17 @@ import java.io.IOException; public class JwtAuthenticationFilter extends OncePerRequestFilter { - @Autowired + @Autowired TokenAuthentificationProvider tokenProvider; @Autowired CustomUserDetailsService customUserDetailsService; - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException { - - String jwt = getJwtFromRequest(request); + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + + String jwt = getJwtFromRequest(request); if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) { String username = tokenProvider.getUsernameFromJWT(jwt); @@ -39,9 +39,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { } filterChain.doFilter(request, response); - } - - private String getJwtFromRequest(HttpServletRequest request) { + } + + private String getJwtFromRequest(HttpServletRequest request) { String bearerToken = request.getHeader("Authorization"); if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { return bearerToken.substring(7); diff --git a/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java b/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java index 4a847b2..36fef75 100755 --- a/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java +++ b/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java @@ -17,7 +17,7 @@ import java.util.*; @Component public class TokenAuthentificationProvider { - private static final Logger logger = LoggerFactory.getLogger(TokenAuthentificationProvider.class); + private static final Logger logger = LoggerFactory.getLogger(TokenAuthentificationProvider.class); @Value("${jwt.jwtSecret}") private String jwtSecret; @@ -35,7 +35,7 @@ public class TokenAuthentificationProvider { public JwtAuthenticationResponse generateToken(Authentication authentication) { return generateToken((UserPrincipal) authentication.getPrincipal()); } - + public JwtAuthenticationResponse generateToken(UserDetails userDetails) { Date now = new Date(); @@ -48,7 +48,7 @@ public class TokenAuthentificationProvider { User user = userRepository.findByUsername(userDetails.getUsername()).get(); claims.put("user", getUserResponseFromUser(user)); // JWT for authentication - String token = Jwts.builder() + String token = Jwts.builder() .setClaims(claims) .setSubject(userDetails.getUsername()) .setIssuedAt(new Date()) @@ -72,6 +72,7 @@ public class TokenAuthentificationProvider { user.getRoles(), user.getStructure()); } + public String getUsernameFromJWT(String token) { Claims claims = Jwts.parser() .setSigningKey(jwtSecret.getBytes()) diff --git a/src/main/java/io/gmss/fiscad/security/UserPrincipal.java b/src/main/java/io/gmss/fiscad/security/UserPrincipal.java index e9e0491..3b02e9f 100755 --- a/src/main/java/io/gmss/fiscad/security/UserPrincipal.java +++ b/src/main/java/io/gmss/fiscad/security/UserPrincipal.java @@ -12,23 +12,23 @@ import java.util.List; public class UserPrincipal implements UserDetails { - /** - * - */ - private static final long serialVersionUID = -8138269269174282199L; + /** + * + */ + private static final long serialVersionUID = -8138269269174282199L; - private User user; + private User user; private Collection authorities; public UserPrincipal(User user, Collection authorities) { this.user = user; this.authorities = authorities; } - + public static UserPrincipal create(User user) { - List authorities = new ArrayList<>(); - user.getRoles().forEach((role)-> - authorities.add(new SimpleGrantedAuthority(role.getNom().name())) + List authorities = new ArrayList<>(); + user.getRoles().forEach((role) -> + authorities.add(new SimpleGrantedAuthority(role.getNom().name())) ); return new UserPrincipal( user, @@ -57,7 +57,7 @@ public class UserPrincipal implements UserDetails { public String getPassword() { return user.getPassword(); } - + @Override public Collection getAuthorities() { return authorities; diff --git a/src/main/java/io/gmss/fiscad/service/FileStorageService.java b/src/main/java/io/gmss/fiscad/service/FileStorageService.java index b6f855e..a029345 100644 --- a/src/main/java/io/gmss/fiscad/service/FileStorageService.java +++ b/src/main/java/io/gmss/fiscad/service/FileStorageService.java @@ -23,6 +23,7 @@ import java.nio.file.StandardCopyOption; public class FileStorageService { private final Path fileStorageLocation; + @Autowired public FileStorageService(FileStorageProperties fileStorageProperties) { this.fileStorageLocation = Paths.get(fileStorageProperties.getUploadDir()) @@ -41,11 +42,11 @@ public class FileStorageService { String[] extension = fileName.split("\\."); - fileName = FileNameGenerator.generateString()+"."+extension[extension.length-1]; + fileName = FileNameGenerator.generateString() + "." + extension[extension.length - 1]; try { // Check if the file's name contains invalid characters - if(fileName.contains("..")) { + if (fileName.contains("..")) { throw new FileStorageException("Désolé! Le nom du fichier contient des caractères non autorisé " + fileName); } @@ -59,16 +60,16 @@ public class FileStorageService { } } - public boolean deleteFile(String fileName) throws IOException{ + public boolean deleteFile(String fileName) throws IOException { try { Path filePath = this.fileStorageLocation.resolve(fileName).normalize(); Resource resource = new UrlResource(filePath.toUri()); - if(resource.exists()) { + if (resource.exists()) { File file = resource.getFile(); - if(file.delete()){ + if (file.delete()) { System.out.println(file.getName() + " is deleted!"); - }else{ + } else { System.out.println("Delete operation is failed."); } } else { @@ -84,7 +85,7 @@ public class FileStorageService { try { Path filePath = this.fileStorageLocation.resolve(fileName).normalize(); Resource resource = new UrlResource(filePath.toUri()); - if(resource.exists()) { + if (resource.exists()) { return resource; } else { diff --git a/src/main/java/io/gmss/fiscad/service/GeometryService.java b/src/main/java/io/gmss/fiscad/service/GeometryService.java index 876d7fc..fa84f81 100644 --- a/src/main/java/io/gmss/fiscad/service/GeometryService.java +++ b/src/main/java/io/gmss/fiscad/service/GeometryService.java @@ -1,29 +1,22 @@ package io.gmss.fiscad.service; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.locationtech.jts.geom.*; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.PrecisionModel; import org.locationtech.jts.io.ParseException; import org.locationtech.jts.io.WKTReader; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.teiid.CommandContext; -import org.teiid.api.exception.query.FunctionExecutionException; -import org.teiid.core.types.GeometryType; -import org.teiid.geo.GeometryTransformUtils; -import org.teiid.query.function.GeometryUtils; import java.sql.SQLException; -import java.util.List; -import static org.teiid.geo.GeometryTransformUtils.lookupProj4Text; // @Service -public class GeometryService { +public class GeometryService { @Value("${infocad.geom.srid}") private String defaultSrid; -// @Autowired + + // @Autowired // private ParcelleService parcelleService; // @Autowired // private ParcelleGeomRepository parcelleGeomRepository; @@ -69,15 +62,15 @@ public class GeometryService { //// } //// } // - public MultiPolygon toGeometry(String wkt, int srid) throws SQLException { - if(wkt == null) { + public MultiPolygon toGeometry(String wkt, int srid) throws SQLException { + if (wkt == null) { return null; } try { - WKTReader wktReaderSRID = new WKTReader(new GeometryFactory(new PrecisionModel(),srid)); + WKTReader wktReaderSRID = new WKTReader(new GeometryFactory(new PrecisionModel(), srid)); - MultiPolygon multiPolygon = (MultiPolygon) wktReaderSRID.read(String.format("MULTIPOLYGON( ((%s)) )",wkt)); + MultiPolygon multiPolygon = (MultiPolygon) wktReaderSRID.read(String.format("MULTIPOLYGON( ((%s)) )", wkt)); // GeometryTransformUtils.transform(multiPolygon,srid); return multiPolygon; diff --git a/src/main/java/io/gmss/fiscad/service/ReportService.java b/src/main/java/io/gmss/fiscad/service/ReportService.java index 5d79c5c..83fcb7f 100644 --- a/src/main/java/io/gmss/fiscad/service/ReportService.java +++ b/src/main/java/io/gmss/fiscad/service/ReportService.java @@ -63,10 +63,10 @@ public class ReportService { public void printPDF(HttpServletResponse response, Map parameters, String jaspers, String fileName, List data) throws JRException, IOException { try { - parameters.put("logoGauche", getJaspersDir()+"/andf.png"); + parameters.put("logoGauche", getJaspersDir() + "/andf.png"); // parameters.put("logoArcep",imageDir+"/logo-arcep.png" ); - InputStream stream = getStream(getJaspersDir()+ jaspers); + InputStream stream = getStream(getJaspersDir() + jaspers); JRDataSource dataSource = new JRBeanCollectionDataSource(data, false); JasperPrint jasperPrint = JasperFillManager.fillReport(stream, parameters, dataSource); @@ -94,10 +94,10 @@ public class ReportService { ServletOutputStream servletOutputStream = response.getOutputStream(); //parameters.put("logoMEF", imageDir+"/logo_mef-transparent.png"); // parameters.put("logoArcep",imageDir+"/logo-arcep.png" ); - parameters.put("logoGauche", getJaspersDir()+"/andf.png"); + parameters.put("logoGauche", getJaspersDir() + "/andf.png"); // parameters.put("logoArcep",imageDir+"/logo-arcep.png" ); - InputStream stream = getStream(getJaspersDir()+ jaspers); + InputStream stream = getStream(getJaspersDir() + jaspers); JRDataSource dataSource = new JRBeanCollectionDataSource(data, false); JasperPrint jasperPrint = JasperFillManager.fillReport(stream, parameters, dataSource); @@ -137,18 +137,18 @@ public class ReportService { public void imprimerBlocsStructure(HttpServletResponse response, FormatRapport formatRapport, Long structureId) { try { - Optional optionalStructure= structureRepository.findById(structureId); + Optional optionalStructure = structureRepository.findById(structureId); if (!optionalStructure.isEmpty()) { - List blocs=blocRepository.getBlocsParStructureResponse(structureId); + List blocs = blocRepository.getBlocsParStructureResponse(structureId); Map parameters = new HashMap(); - parameters.put("structure",optionalStructure.get().getNom()); + parameters.put("structure", optionalStructure.get().getNom()); try { String jaspers = "/listBlocParStructure.jasper"; - if(formatRapport.equals(FormatRapport.PDF)){ + if (formatRapport.equals(FormatRapport.PDF)) { printPDF(response, parameters, jaspers, "blocs.pdf", blocs); } - if(formatRapport.equals(FormatRapport.XLS)){ + if (formatRapport.equals(FormatRapport.XLS)) { printXLSX(response, parameters, jaspers, "blocs.xlsx", blocs); } } catch (IOException e) { @@ -167,23 +167,23 @@ public class ReportService { public void imprimerEnqueteParBloc(HttpServletResponse response, FormatRapport formatRapport, Long blocId) { try { - Optional optionalBloc= blocRepository.findById(blocId); + Optional optionalBloc = blocRepository.findById(blocId); if (!optionalBloc.isEmpty()) { - Optional optionalStructure= structureRepository.findById(optionalBloc.get().getStructure().getId()); - Optional optionalArrondissement= arrondissementRepository.findById(optionalBloc.get().getArrondissement().getId()); - Optional optionalCommune= communeRepository.findById(optionalArrondissement.get().getCommune().getId()); - List enqueteParBlocResponses=enqueteRepository.getEnqueteByBloc(blocId, RoleActeur.PROPRIETAIRE.toString()); + Optional optionalStructure = structureRepository.findById(optionalBloc.get().getStructure().getId()); + Optional optionalArrondissement = arrondissementRepository.findById(optionalBloc.get().getArrondissement().getId()); + Optional optionalCommune = communeRepository.findById(optionalArrondissement.get().getCommune().getId()); + List enqueteParBlocResponses = enqueteRepository.getEnqueteByBloc(blocId, RoleActeur.PROPRIETAIRE.toString()); Map parameters = new HashMap(); - parameters.put("structure",optionalStructure.get().getNom()); - parameters.put("bloc",optionalBloc.get().getNom()); - parameters.put("commune",optionalCommune.get().getNom()); - parameters.put("arrondissement",optionalArrondissement.get().getNom()); + parameters.put("structure", optionalStructure.get().getNom()); + parameters.put("bloc", optionalBloc.get().getNom()); + parameters.put("commune", optionalCommune.get().getNom()); + parameters.put("arrondissement", optionalArrondissement.get().getNom()); try { String jaspers = "/listEnqueteParBloc.jasper"; - if(formatRapport.equals(FormatRapport.PDF)){ + if (formatRapport.equals(FormatRapport.PDF)) { printPDF(response, parameters, jaspers, "listEnqueteParBloc.pdf", enqueteParBlocResponses); } - if(formatRapport.equals(FormatRapport.XLS)){ + if (formatRapport.equals(FormatRapport.XLS)) { printXLSX(response, parameters, jaspers, "listEnqueteParBloc.xlsx", enqueteParBlocResponses); } } catch (IOException e) { @@ -201,18 +201,17 @@ public class ReportService { } - - public void imprimerEnqueteParFiltre(HttpServletResponse response, FiltreEnquetePayLoad filtreEnquetePayLoad,FormatRapport formatRapport) { + public void imprimerEnqueteParFiltre(HttpServletResponse response, FiltreEnquetePayLoad filtreEnquetePayLoad, FormatRapport formatRapport) { try { - List enqueteFiltreResponses=enqueteService.getEnqueteCommuneArrondBlocFiltre(filtreEnquetePayLoad); + List enqueteFiltreResponses = enqueteService.getEnqueteCommuneArrondBlocFiltre(filtreEnquetePayLoad); Map parameters = new HashMap(); try { String jaspers = "/listEnqueteParFiltre.jasper"; - if(formatRapport.equals(FormatRapport.PDF)){ + if (formatRapport.equals(FormatRapport.PDF)) { printPDF(response, parameters, jaspers, "listEnqueteParFiltre.pdf", enqueteFiltreResponses); } - if(formatRapport.equals(FormatRapport.XLS)){ + if (formatRapport.equals(FormatRapport.XLS)) { printXLSX(response, parameters, jaspers, "listEnqueteParFiltre.xlsx", enqueteFiltreResponses); } } catch (IOException e) { diff --git a/src/main/java/io/gmss/fiscad/service/StringManager.java b/src/main/java/io/gmss/fiscad/service/StringManager.java index 72a01f4..e59b68b 100644 --- a/src/main/java/io/gmss/fiscad/service/StringManager.java +++ b/src/main/java/io/gmss/fiscad/service/StringManager.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service; @Service public class StringManager { - public String deleteWhiteSpace(String in){ + public String deleteWhiteSpace(String in) { return in.replaceAll(" ", "").trim(); } diff --git a/src/main/java/io/gmss/fiscad/service/StringService.java b/src/main/java/io/gmss/fiscad/service/StringService.java index 4b6028f..bb03ff8 100644 --- a/src/main/java/io/gmss/fiscad/service/StringService.java +++ b/src/main/java/io/gmss/fiscad/service/StringService.java @@ -9,23 +9,24 @@ import java.util.UUID; @Service public class StringService { - public String getUniqueString(){ + public String getUniqueString() { UUID uuid = UUID.randomUUID(); String uuidAsString = uuid.toString(); return uuidAsString.replaceAll("-", ""); } - public static String getCodeEquipe(){ + + public static String getCodeEquipe() { UUID uuid = UUID.randomUUID(); String uuidAsString = uuid.toString(); - return uuidAsString.replaceAll("-", "").toUpperCase().substring(0,4); + return uuidAsString.replaceAll("-", "").toUpperCase().substring(0, 4); } - public String generateIntInTwoPositions(int input){ + public String generateIntInTwoPositions(int input) { NumberFormat formatter = new DecimalFormat("00"); return formatter.format(input); } - public String generateIntInThrePositions(int input){ + public String generateIntInThrePositions(int input) { NumberFormat formatter = new DecimalFormat("000"); return formatter.format(input); } diff --git a/src/main/java/io/gmss/fiscad/utils/FileNameGenerator.java b/src/main/java/io/gmss/fiscad/utils/FileNameGenerator.java index 784d009..4189e20 100644 --- a/src/main/java/io/gmss/fiscad/utils/FileNameGenerator.java +++ b/src/main/java/io/gmss/fiscad/utils/FileNameGenerator.java @@ -3,7 +3,6 @@ package io.gmss.fiscad.utils; import java.util.UUID; /** - * * @author AKPONA Christian */ public class FileNameGenerator { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3150157..46736af 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,20 +3,14 @@ spring.jpa.properties.hibernate.id.new_generator_mappings=false spring.datasource.url=jdbc:postgresql://vmi792116.contaboserver.net:5599/abomey_db spring.datasource.username=infocad_user spring.datasource.password=W5fwD({9*q53 - # LOCAL ENV # #spring.datasource.url=jdbc:postgresql://localhost:5432/fiscad #spring.datasource.username=fiscad #spring.datasource.password=fiscad - - #spring.datasource.url=jdbc:postgresql://192.168.1.107:5432/abomey_db #spring.datasource.username=infocad_user #spring.datasource.password=12345 - - - spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false spring.jpa.show-sql=true @@ -28,42 +22,29 @@ logging.file.name=fiscad.log logging.level.org.springframework.security=DEBUG app.sourcemind.env.defaultpassword=1234567890 app.sourcemind.env.resetlink=http://localhost:4200/reset-password/ - spring.mail.host=sandbox.smtp.mailtrap.io spring.mail.port=587 spring.mail.username=2a06b84a6b8abc spring.mail.password=654a7c7759506a spring.mail.auth=plain spring.mail.starttls.enable=true - spring.datasource.hikari.minimum-idle=2 spring.datasource.hikari.maximum-pool-size=10 spring.datasource.hikari.idle-timeout=120000 spring.datasource.hikari.connection-timeout=300000 spring.datasource.hikari.leak-detection-threshold=300000 - -file.upload_dir= ./uploads - -file.jasper-reports= ./jasperReport - +file.upload_dir=./uploads +file.jasper-reports=./jasperReport spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration spring.groovy.template.enabled=false spring.groovy.template.check-template-location=false - - #####Gestion de l'identifiant du systme de rfence spatiale########### - infocad.geom.srid=32631 infocad.geom.sridfixe=4326 - server.port=8282 - - # application.properties spring.mvc.contentnegotiation.favor-parameter=false spring.mvc.contentnegotiation.parameter-name=mediaType spring.mvc.contentnegotiation.ignore-unknown-path-extensions=true - - springdoc.swagger-ui.defaultModelsExpandDepth=-1 springdoc.swagger-ui.docExpansion=none \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 4b6483f..8bd5ea7 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -4,18 +4,18 @@ Swagger UI - - - - - + + + + + Test
- - - + + + \ No newline at end of file diff --git a/src/main/resources/static/swagger-custom.html b/src/main/resources/static/swagger-custom.html index bec2e95..528f677 100644 --- a/src/main/resources/static/swagger-custom.html +++ b/src/main/resources/static/swagger-custom.html @@ -9,8 +9,8 @@
- - - + + + \ No newline at end of file