Skip to content

afet-yonetim-sistemi/ays-be

Repository files navigation

AYS | Afet Yönetim Sistemi APIs Application Status

Tech Stack

Framework

  • Core
    • Spring
      • Spring Boot 3
      • Spring Boot Test (Junit)
      • Spring Boot Dev Tools
      • Spring Web
      • Spring Boot Actuator
      • Spring Doc Open API
      • Spring Security 6
      • Spring OAuth2 Client
      • Spring OAuth2 Resource Server
    • Spring Data
      • Spring Data JPA

3rd Party Dependencies

  • Lombok
  • Test Containers
  • Mapstruct
  • Easy Random
  • JSON Web Token
  • JSON Web Signature
  • Bouncy Castle

Database

  • MySQL

Database Migration Tool

  • Liquibase

Language

  • Java 17

Build Tool

  • Maven

Software Development Process

  • TDD
  • Agile Kanban
  • Jira

Version Control

  • Git
  • GitHub

APIs Interaction Platform

  • Postman

Application Pipeline

  • GitHub Actions


Getting Started


The project has been generated by Spring Initializer.

Instructions Before Building Project

⚠ Make sure NOT to push template-settings.xml at all times. ⚠

First of all, generate personal access token with this url : https://github.com/settings/tokens

  • Create one classic token
  • Make sure to give project, read:packages, repo scopes
  • Give it a name
  • Then click on "Generate Token"
  • In case of errors, please check [here](#Common Maven errors)

Before Running Locally On IDE

  1. If you don't want to replace your ~/m2/settings.xml file, use following command to build the project (go to the root folder of the application): mvn -gs template-settings.xml clean install -U
  2. If you have ~/m2/settings.xml file in your computer, skip the step without reading the after section. If you aren't using the ~/.m2/settings.xml file to actively, you can be back up it before creating the new settings.xml file, if you want. If you are using actively, after the perform step 3 you can manually merge the settings.xml file in the project with the ~/.m2/settings.xml file and skip step 2 and 4.
  3. While inside the project directory in the terminal; that is, when you are in the ~/afet-yonetim-sistemi/ays-be directory, run the command cp template-settings.xml settings.xml.
  4. In the settings.xml file within the project, replace the {YOUR_GITHUB_USERNAME} placeholder with your GitHub username and replace {YOUR_PERSONAL_GITHUB_ACCESS_TOKEN} with the access token value you created on GitHub as described in the instructions under the 'Instructions Before Building The Project' section.
  5. If the .m2 directory has not been created before, you can use the command mkdir ~/.m2 and then run the command cp settings.xml ~/.m2/settings.xml for copy the settings.xml file located in the project to the ~/.m2 directory.

Don't forget to enable Lombok pre-processing in your IDE!

Building The Project With Tests

./mvnw clean install

Building The Project Without Tests

./mvnw clean install -DskipTests

Running as Docker MySQL container

Before running the project, you need to run the following command to start the MySQL container:

docker compose up -d --build database

If you want to recreate the MySQL container, you can run the following command:

docker compose up --force-recreate -d --build database

If you want to stop the MySQL container, you can run the following command:

docker compose down -v database

Running As Docker Container

  1. While inside the project directory in the terminal; that is, when you are in the ~/afet-yonetim-sistemi/ays-be directory, run the command cp template-settings.xml settings.xml.
  2. In the settings.xml file within the project, replace the {YOUR_GITHUB_USERNAME} placeholder with your GitHub username and replace {YOUR_PERSONAL_GITHUB_ACCESS_TOKEN} with the access token value you created on GitHub as described in the instructions under the 'Instructions Before Building The Project' section.

Before running the project, you need to run the following command to start the project container:

docker compose up -d --build

If you want to recreate the project container, you can run the following command:

docker compose up --force-recreate -d --build 

If you want to stop the project container, you can run the following command:

docker compose down -v 


The project is managed by Jira. You can assign an issue from the Todo list and start working on it.


Project Documents

For other information, you can check Confluence Page.


Postman


Common Errors

1. Can't download the package from the private repo:

Error:

[ERROR] Failed to execute goal on project ays-be: Could not resolve dependencies for project org.ays:ays-be:jar: 1.1.0.MVP: Could not find artifact org.locationtech.jts:jts-core:jar:1.18.2 -> [Help 1]

Solution:

Make sure to create your github user token with the correct scopes

2. Can't build the project since it gets the following exception from bouncycasle:

Error:

[ERROR] error reading .../.m2/repository/org/bouncycastle/bcprov-jdk18on/1.78/bcprov-jdk18on-1.78.jar; zip file is empty
[ERROR] .../ays-be/src/main/java/org/ays/auth/service/AysInvalidTokenService.java:[1,1] cannot access org.ays.auth.service
ZipException opening "bcprov-jdk18on-1.78.jar": zip END header not found

Solution:

Make sure to remove bouncy castle from your .m2 folder then run mvn clean install again to download the packages.

3. Can't download the package from the private repo:

Error:

[ERROR] Failed to execute goal on project ays-be: Could not resolve dependencies for project org.ays:ays-be🫙1.1.0.MVP:
org.ays:ays-be-encryption-utility🫙1.0.2 was not found
in https://maven.pkg.github.com/afet-yonetim-sistemi/ays-be-encryption-utility during a previous attempt. This failure
was cached in the local repository and resolution is not reattempted until the update interval of github has elapsed
or updates are forced -> [Help 1]

Solution:

Use the following command to build the project: mvn clean install -U -DskipTests

4. Email Configuration Errors:

4.1 Running the project with the following error:

2024-07-13T12:13:21.244+03:00 WARN 5171 --- [on(2)-127.0.0.1] o.s.b.actuate.mail.MailHealthIndicator   : Mail health
check failed

jakarta.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8  https://support.google.com/mail/?p=BadCredentials 5b1f17b1804b1-427a5e9a809sm13702135e9.28 - gsmtp
at org.eclipse.angus.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:954) ~[jakarta.mail-2.0.3.jar:na]
     at org.eclipse.angus.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:865) ~[jakarta.mail-2.0.3.jar:na]
     at org.eclipse.angus.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:769) ~[jakarta.mail-2.0.3.jar:na]

4.2 Error while sending an email from the application:

 2024-07-13T12:13:23.028+03:00 ERROR 5171 --- [onPool-worker-1] o.a.c.service.impl.AysMailServiceImpl    : Received
 error while sending mail to [iletisim@afetyonetimsistemi.org] with EXAMPLE template

 org.springframework.mail.MailAuthenticationException: Authentication failed
 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:402) ~[spring-context-support-6.1.10.jar:6.1.10]
     at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:350) ~[spring-context-support-6.1.10.jar:6.1.10]

Solution:

If you don’t need to send an email, you can ignore these warnings.


If you need to send an email from the application;

Please review the documentation and use the Override configuration properties feature to override the default mail parameters with your own mail information. You can refer to this link for more details: https://www.jetbrains.com/help/idea/run-debug-configuration-spring-boot.html

5. Validation Failed Exception:

Error:

[ERROR] Validation Failed:
    2 changesets check sum
        db/changelog/changes/1-ays-ddl.xml::1-ays-ddl::ays was: 9:bc046153f5677aace14604c2c58c3442 but is now: 9:34f914e2fbb9a593ea3c725551f758ad
        db/changelog/changes/2-ays-dml.xml::2-ays-dml::ays was: 9:125d52ec3abeced458eb69767a39c443 but is now: 9:6e22314bcbe8286ee0eea2f049e16e26

Solution:

This problem is caused by the checksum values in the database not matching. The Override configuration properties section opens. Application parameters can be overridden specifically. If the AYS_LIQUIBASE_ENABLE_DROP_FIRST parameter in application.yml is defined here and given as true, the database is cleaned and recreated in the local environment. If this is not desired to be done every time the application is run, the parameter can only be disabled without deleting it. details: https://www.jetbrains.com/help/idea/run-debug-configuration-spring-boot.html#spring-boot


Project Infrastructure

🏛️ HexaLayered Architecture

Reference: HexaLayered Architecture

📦 Package Architecture