56 Commits

Author SHA1 Message Date
801ecb3817 Merge branch 'main' into fix_cache
All checks were successful
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 46s
CI / build (push) Successful in 11s
Format / formatting (pull_request) Successful in 6s
2025-04-06 20:56:22 +02:00
cc89d4c79f fix: reverted previous commit, cache juste does not work
Some checks are pending
Format / formatting (push) Waiting to run
Build / build (push) Waiting to run
CI / build (push) Waiting to run
Format / formatting (pull_request) Successful in 6s
2025-04-06 20:55:35 +02:00
adf9a93e2e Merge pull request 'feat: enabled graddle cache. Subsequent actions should be fasters' (#7) from fix_cache into main
Some checks failed
CI / build (push) Waiting to run
Format / formatting (push) Successful in 5s
Build / build (push) Has been cancelled
Reviewed-on: #7
2025-04-06 20:41:13 +02:00
37d8bcc719 feat: enabled graddle cache. Subsequent actions should be fasters
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Has been cancelled
CI / build (push) Successful in 12s
Format / formatting (pull_request) Successful in 6s
2025-04-06 20:39:45 +02:00
ead11215ba Merge pull request 'backend-api' (#6) from backend-api into main
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 38s
CI / build (push) Successful in 10s
Reviewed-on: #6
Reviewed-by: Theo <tlelez@enseirb-matmeca.fr>
Reviewed-by: adnane <adnane.alami@bordeaux-inp.fr>
Reviewed-by: mohamed_maoulainine <mohamed_maoulainine.maoulainine@bordeaux-inp.fr>
2025-03-26 19:04:08 +01:00
137bc84c21 Merge branch 'backend-api' of ssh://gitea.piair.dev:2222/piair/MyINPulse into backend-api
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 38s
CI / build (push) Successful in 10s
Format / formatting (pull_request) Successful in 5s
2025-03-19 12:06:00 +01:00
3c61fdca93 feat: finished implementing apiService functions 2025-03-19 12:05:56 +01:00
5ee3755548 feat: added new tests and fixed few issues
All checks were successful
Format / formatting (push) Successful in 7s
Build / build (push) Successful in 38s
CI / build (push) Successful in 12s
2025-03-19 12:05:01 +01:00
52511dd4c4 fix: Makefile now run everything needed to build the app 2025-03-19 10:42:46 +01:00
84b70f8f38 fix: sometimes, project administrators may be null. Fixing nullPointerException
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 37s
CI / build (push) Successful in 11s
2025-03-17 09:18:21 +01:00
834d68949c fix: tabulation error
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Failing after 39s
CI / build (push) Successful in 11s
2025-03-17 09:08:33 +01:00
fea8687664 feat: now running tests
All checks were successful
Format / formatting (push) Successful in 6s
CI / build (push) Successful in 10s
2025-03-17 09:05:24 +01:00
c94d3654ce fix: updating foreign keys when adding new entity to the db
All checks were successful
Format / formatting (push) Successful in 7s
Build / build (push) Successful in 31s
CI / build (push) Successful in 11s
2025-03-15 15:23:18 +01:00
d5c89bf8f4 fix: spelling
All checks were successful
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 27s
CI / build (push) Successful in 11s
2025-03-12 12:25:26 +01:00
78c72bdd72 fix: linter
Some checks failed
Format / formatting (push) Failing after 5s
Build / build (push) Successful in 27s
CI / build (push) Successful in 10s
2025-03-12 12:23:27 +01:00
307c7e700b merge
Some checks failed
Format / formatting (push) Failing after 5s
Build / build (push) Successful in 27s
CI / build (push) Successful in 10s
2025-03-12 12:19:35 +01:00
8d486dce89 feat: continued implementing adminApiService 2025-03-12 12:16:01 +01:00
653f923693 fix: bugfix
All checks were successful
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 27s
CI / build (push) Successful in 11s
2025-03-12 12:08:49 +01:00
64da3c9ab0 feat: tests on AdminApiService 2025-03-12 12:07:48 +01:00
419ceec1bc feat: switched from String to ProjectDecisionValues
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 28s
CI / build (push) Successful in 11s
2025-03-12 10:25:19 +01:00
e011a5534e feat: switched from String to ProjectDecisionValues
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 30s
CI / build (push) Successful in 15s
2025-03-12 10:21:08 +01:00
ef964c4d35 fix: removed id + renamed mainEmail to primaryEmail everywhere
All checks were successful
Format / formatting (push) Successful in 8s
Build / build (push) Successful in 28s
CI / build (push) Successful in 11s
2025-03-11 13:02:17 +01:00
5608b12f84 fix: removed id + renamed mainEmail to primaryEmail everywhere 2025-03-11 13:01:53 +01:00
467babab79 fix: removed id + renamed mainEmail to primaryEmail everywhere 2025-03-11 13:01:28 +01:00
a2e2395cc2 feat: added new tests and coverage report 2025-03-11 13:00:38 +01:00
e3393c8834 test
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 28s
CI / build (push) Successful in 10s
2025-03-09 21:20:20 +01:00
5f8fe4a374 feat: precommit hook for google java format 2025-03-09 21:19:00 +01:00
c5e7736a16 fix: wtf does idea do ?? Why d methods move ? fixed linter again...
All checks were successful
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 27s
CI / build (push) Successful in 10s
2025-03-09 21:10:25 +01:00
04589392cb fix: removed debug logging
Some checks failed
Format / formatting (push) Failing after 6s
Build / build (push) Successful in 29s
CI / build (push) Successful in 11s
2025-03-09 21:07:29 +01:00
1106cf8478 feat: added tests. 2025-03-09 21:06:31 +01:00
215d80ad70 fix: removed contradictive @NotNull preventing to add data to database. 2025-03-09 21:04:52 +01:00
dded62c25a fix: take latest implementation of logging module + imported inmemory database for testing 2025-03-09 20:22:20 +01:00
3de7ebe2b1 fix: remoed debug logging 2025-03-09 20:21:32 +01:00
8153496a0f feat: implemented database for testing purposes
All checks were successful
Format / formatting (push) Successful in 7s
Build / build (push) Successful in 28s
CI / build (push) Successful in 11s
2025-03-04 18:42:14 +01:00
861e7495a7 fix: re-enabled cache to drastically reduce action time. This should be fixed later
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 27s
CI / build (push) Successful in 10s
2025-03-01 01:00:52 +01:00
d78e43f7e0 fix: improved the workflow
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Has been cancelled
CI / build (push) Successful in 11s
2025-03-01 00:58:50 +01:00
3ca97cf378 fix: improved the workflow
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 28s
CI / build (push) Successful in 12s
2025-03-01 00:57:34 +01:00
e6a8d98d63 fix: improved the workflow
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Failing after 34s
CI / build (push) Successful in 11s
2025-02-28 12:20:48 +01:00
8894fea6d4 fix: improved the workflow
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Failing after 18s
CI / build (push) Successful in 10s
2025-02-28 12:20:05 +01:00
236bb0d167 fix: improved the workflow
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Failing after 6s
CI / build (push) Successful in 11s
2025-02-28 12:18:36 +01:00
d4dcc95d9b fix: removed cache to speed up things
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Failing after 14s
CI / build (push) Successful in 11s
2025-02-28 12:16:43 +01:00
dc843299eb fix: action create the gradlew wrapper
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Failing after 4m49s
CI / build (push) Successful in 11s
2025-02-28 12:10:13 +01:00
f3eaf8fe34 fix: action create the gradlew wrapper
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Failing after 4m46s
CI / build (push) Successful in 11s
2025-02-28 12:04:11 +01:00
628c61fb8b feat: pipeline should now test if the project builds
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Failing after 5m49s
CI / build (push) Successful in 10s
2025-02-28 11:55:43 +01:00
4880f3829c I don't get it, how does it keeps failing with the formatter installed... time to create pre-commit hook I guess
All checks were successful
Format / formatting (push) Successful in 6s
CI / build (push) Successful in 10s
2025-02-28 11:47:45 +01:00
80b2d087e4 feat: implemented date filtration and a utils service to prevent code ducplication
Some checks failed
Format / formatting (push) Failing after 7s
CI / build (push) Successful in 11s
2025-02-28 11:45:55 +01:00
b5c03798fc fix: formatter now follow the same logic as idea, see https://github.com/google/google-java-format/issues/566
All checks were successful
Format / formatting (push) Successful in 5s
CI / build (push) Successful in 10s
2025-02-26 18:55:45 +01:00
1d970ce5f5 feat: continued to implement SharedApiService (if linter fails i don't understand)
Some checks failed
Format / formatting (push) Failing after 6s
CI / build (push) Successful in 11s
2025-02-26 18:33:09 +01:00
f9de5ed6bf feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation
Some checks failed
Format / formatting (push) Failing after 6s
CI / build (push) Successful in 11s
2025-02-26 17:35:52 +01:00
e75a5c9d2c fix: linter ??? pls idea be better
All checks were successful
Format / formatting (push) Successful in 5s
CI / build (push) Successful in 12s
2025-02-26 15:57:03 +01:00
5c3b2b138d feat: renamex title to sectionId and added a new shared API call
Some checks failed
Format / formatting (push) Failing after 5s
CI / build (push) Successful in 11s
2025-02-26 15:55:33 +01:00
8d4dc7916d feat: added most of shared API calls
Some checks failed
Format / formatting (push) Failing after 5s
CI / build (push) Successful in 10s
2025-02-26 15:31:02 +01:00
1a6db7c953 feat: added color in logs
All checks were successful
Format / formatting (push) Successful in 6s
CI / build (push) Successful in 11s
2025-02-26 15:29:55 +01:00
3890aed158 Merge branch 'backend-api' of ssh://gitea.piair.dev:2222/piair/MyINPulse into backend-api
All checks were successful
Format / formatting (push) Successful in 5s
CI / build (push) Successful in 11s
2025-02-26 14:51:52 +01:00
dd5ca2cbd7 feat: entrepreneur api and api service 2025-02-26 14:51:02 +01:00
024deeba41 fix: linter - how did this append ?
All checks were successful
Format / formatting (push) Successful in 6s
CI / build (push) Successful in 10s
2025-02-26 14:30:58 +01:00
51 changed files with 1582 additions and 391 deletions

View File

@ -15,4 +15,4 @@ jobs:
- uses: axel-op/googlejavaformat-action@v3 - uses: axel-op/googlejavaformat-action@v3
with: with:
args: "--set-exit-if-changed --skip-sorting-imports --aosp -n" args: "--set-exit-if-changed --skip-sorting-imports --skip-reflowing-long-strings --aosp -n"

View File

@ -0,0 +1,33 @@
name: Build
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Load .env file
uses: xom9ikk/dotenv@v2.3.0
with:
path: ./config/
mode: dev
load-mode: strict
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-disabled: true # Once the code has been pushed once in main, this should be reenabled.
- name: init gradle
working-directory: ./MyINPulse-back/
run: ./gradlew build # todo: run test, currently fail because no database is present

View File

@ -19,8 +19,14 @@ front/MyINPulse-front/.installed:
vite: ./front/MyINPulse-front/.installed vite: ./front/MyINPulse-front/.installed
keycloak: ./keycloak/.installed
dev-front: clean vite keycloak/.installed:
@echo "running one time install"
@cd keycloak/CAS && sudo sh build.sh
@touch ./keycloak/.installed
dev-front: clean vite keycloak
@cp config/frontdev.env front/MyINPulse-front/.env @cp config/frontdev.env front/MyINPulse-front/.env
@cp config/frontdev.env .env @cp config/frontdev.env .env
@cp config/frontdev.env MyINPulse-back/.env @cp config/frontdev.env MyINPulse-back/.env
@ -28,7 +34,7 @@ dev-front: clean vite
@docker compose up -d --build @docker compose up -d --build
@cd ./front/MyINPulse-front/ && npm run dev @cd ./front/MyINPulse-front/ && npm run dev
prod: clean prod: clean keycloak
@cp config/prod.env front/MyINPulse-front/.env @cp config/prod.env front/MyINPulse-front/.env
@cp config/prod.env .env @cp config/prod.env .env
@cp config/prod.env .env @cp config/prod.env .env
@ -37,7 +43,7 @@ prod: clean
dev-back: dev-back: keycloak
@cp config/backdev.env front/MyINPulse-front/.env @cp config/backdev.env front/MyINPulse-front/.env
@cp config/backdev.env .env @cp config/backdev.env .env
@cp config/backdev.env MyINPulse-back/.env @cp config/backdev.env MyINPulse-back/.env
@ -46,7 +52,7 @@ dev-back:
@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
@echo "./gradlew bootRun --args='--server.port=8081'" @echo "./gradlew bootRun --args='--server.port=8081'"
dev: clean vite dev: clean vite keycloak
@cp config/dev.env front/MyINPulse-front/.env @cp config/dev.env front/MyINPulse-front/.env
@cp config/dev.env .env @cp config/dev.env .env
@cp config/dev.env MyINPulse-back/.env @cp config/dev.env MyINPulse-back/.env
@ -55,3 +61,13 @@ dev: clean vite
@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
@echo "./gradlew bootRun --args='--server.port=8081'" @echo "./gradlew bootRun --args='--server.port=8081'"
@cd ./front/MyINPulse-front/ && npm run dev & @cd ./front/MyINPulse-front/ && npm run dev &
test-back: clean keycloak
@cp config/dev.env front/MyINPulse-front/.env
@cp config/dev.env .env
@cp config/dev.env MyINPulse-back/.env
@cp config/dev.docker-compose.yaml docker-compose.yaml
@docker compose up -d --build
@echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)'
@cd ./MyINPulse-back/ && ./gradlew test && ./gradlew jacocoTestReport
@firefox ./MyINPulse-back/build/jacocoHtml/index.html

View File

@ -2,6 +2,7 @@ plugins {
id 'java' id 'java'
id 'org.springframework.boot' version '3.4.2' id 'org.springframework.boot' version '3.4.2'
id 'io.spring.dependency-management' version '1.1.7' id 'io.spring.dependency-management' version '1.1.7'
id 'jacoco'
} }
group = 'enseirb' group = 'enseirb'
@ -23,13 +24,36 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.16.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.16.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
implementation 'org.postgresql:postgresql' implementation 'org.postgresql:postgresql'
implementation group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
} }
tasks.named('test') { tasks.named('test') {
useJUnitPlatform() useJUnitPlatform()
} }
test {
finalizedBy jacocoTestReport // report is always generated after tests run
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
jacoco {
toolVersion = "0.8.12"
reportsDirectory = layout.buildDirectory.dir('customJacocoReportDir')
}

View File

@ -81,7 +81,7 @@ public class AdminApi {
*/ */
@PostMapping("/admin/appoitements/report/{appointmentId}") @PostMapping("/admin/appoitements/report/{appointmentId}")
public void createAppointmentReport( public void createAppointmentReport(
@PathVariable String appointmentId, @PathVariable long appointmentId,
@RequestBody Report report, @RequestBody Report report,
@AuthenticationPrincipal Jwt principal) { @AuthenticationPrincipal Jwt principal) {
adminApiService.createAppointmentReport( adminApiService.createAppointmentReport(

View File

@ -1,6 +1,6 @@
package enseirb.myinpulse.controller; package enseirb.myinpulse.controller;
import enseirb.myinpulse.model.LCSection; import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.service.EntrepreneurApiService; import enseirb.myinpulse.service.EntrepreneurApiService;
@ -29,12 +29,12 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@PutMapping("/entrepreneur/lcsection/modify/{sectionId}") @PutMapping("/entrepreneur/lcsection/modify/{sectionId}")
public void editLCSection( public void editSectionCell(
@PathVariable String sectionId, @PathVariable Long sectionId,
@RequestBody LCSection section, @RequestBody SectionCell sectionCell,
@AuthenticationPrincipal Jwt principal) { @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.editLCSection( entrepreneurApiService.editSectionCell(
sectionId, section, principal.getClaimAsString("email")); sectionId, sectionCell, principal.getClaimAsString("email"));
} }
/** /**
@ -45,9 +45,9 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}")
public void removeLCSection( public void removeSectionCell(
@PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) { @PathVariable Long sectionId, @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email")); entrepreneurApiService.removeSectionCell(sectionId, principal.getClaimAsString("email"));
} }
/** /**
@ -57,13 +57,10 @@ public class EntrepreneurApi {
* *
* @return status code * @return status code
*/ */
@PostMapping("/entrepreneur/lcsection/add/{sectionId}") @PostMapping("/entrepreneur/lcsection/add") // remove id from doc aswell
public void addLCSection( public void addLCSection(
@PathVariable String sectionId, @RequestBody SectionCell sectionCell, @AuthenticationPrincipal Jwt principal) {
@RequestBody LCSection section, entrepreneurApiService.addSectionCell(sectionCell, principal.getClaimAsString("email"));
@AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.addLCSection(
sectionId, section, principal.getClaimAsString("email"));
} }
/** /**

View File

@ -1,5 +1,7 @@
package enseirb.myinpulse.controller; package enseirb.myinpulse.controller;
import com.itextpdf.text.DocumentException;
import enseirb.myinpulse.model.*; import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.SharedApiService; import enseirb.myinpulse.service.SharedApiService;
@ -9,6 +11,9 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.net.URISyntaxException;
@SpringBootApplication @SpringBootApplication
@RestController @RestController
public class SharedApi { public class SharedApi {
@ -21,22 +26,18 @@ public class SharedApi {
} }
/** /**
* TODO: It does not looks like a good id to have the title and the date in the url. What even * Endpoint used to get the data inside the lean canvas
* TODO: is the title btw ? if this is the LC section, wouldn't it be better to use an ID ?
* TODO: choose return type, cf comment in LCSection
*
* <p>Endpoint used to get the data inside the lean canvas
* *
* @return a list of lean canvas sections * @return a list of lean canvas sections
*/ */
@GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") @GetMapping("/shared/project/lcsection/{projectId}/{sectionId}/{date}")
public Iterable<SectionCell> getLCSection( public Iterable<SectionCell> getLCSection(
@PathVariable("projectId") String projectId, @PathVariable("projectId") Long projectId,
@PathVariable("title") String title, @PathVariable("sectionId") Long sectionId,
@PathVariable("date") String date, @PathVariable("date") String date,
@AuthenticationPrincipal Jwt principal) { @AuthenticationPrincipal Jwt principal) {
return sharedApiService.getLCSection( return sharedApiService.getSectionCells(
projectId, title, date, principal.getClaimAsString("email")); projectId, sectionId, date, principal.getClaimAsString("email"));
} }
/** /**
@ -54,10 +55,10 @@ public class SharedApi {
/** /**
* Endpoint used to get the administrator of a project. * Endpoint used to get the administrator of a project.
* *
* @return a list of all project managed by the current admin user * @return the admin of a project
*/ */
@GetMapping("/shared/projects/admin/{projectId}") @GetMapping("/shared/projects/admin/{projectId}")
public Iterable<Administrator> getAdminByProjectId( public Administrator getAdminByProjectId(
@PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) {
return sharedApiService.getAdminByProjectId(projectId, principal.getClaimAsString("email")); return sharedApiService.getAdminByProjectId(projectId, principal.getClaimAsString("email"));
} }
@ -82,7 +83,15 @@ public class SharedApi {
@GetMapping("/shared/projects/appointments/report/{appointmentId}") @GetMapping("/shared/projects/appointments/report/{appointmentId}")
public void getPDFReport( public void getPDFReport(
@PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) { @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); try {
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
} catch (DocumentException e) {
System.out.println(e + "Document exception");
} catch (URISyntaxException e) {
System.out.println(e + "Error with URI");
} catch (IOException e) {
System.out.println(e + "Failed to access file");
}
} }
/** /**

View File

@ -13,14 +13,14 @@ import java.util.List;
public class Administrator extends User { public class Administrator extends User {
@OneToMany(mappedBy = "projectAdministrator", fetch = FetchType.LAZY, orphanRemoval = true) @OneToMany(mappedBy = "projectAdministrator", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Project> listProject = new ArrayList<>(); private final List<Project> listProject = new ArrayList<>();
/*@OneToMany(mappedBy = "administratorSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) /*@OneToMany(mappedBy = "administratorSectionCell", fetch = FetchType.LAZY, orphanRemoval = true)
private List<SectionCell> listSectionCell = new ArrayList<>();*/ private List<SectionCell> listSectionCell = new ArrayList<>();*/
// should now be useless // should now be useless
@OneToMany(mappedBy = "administratorAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) @OneToMany(mappedBy = "administratorAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Annotation> listAnnotation = new ArrayList<>(); private final List<Annotation> listAnnotation = new ArrayList<>();
/*@OneToMany(mappedBy = "administratorAppointment", fetch = FetchType.LAZY, orphanRemoval = true) /*@OneToMany(mappedBy = "administratorAppointment", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<Appointment> listAppointment = new ArrayList<>();*/ private final List<Appointment> listAppointment = new ArrayList<>();*/
@ -32,12 +32,35 @@ public class Administrator extends User {
public Administrator() {} public Administrator() {}
public Administrator( public Administrator(
Long idUser,
String userSurname, String userSurname,
String username, String username,
String mainMail, String primaryMail,
String secondaryMail, String secondaryMail,
String phoneNumber) { String phoneNumber) {
super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); super(null, userSurname, username, primaryMail, secondaryMail, phoneNumber);
}
public List<Project> getListProject() {
return listProject;
}
public void updateListProject(Project project) {
listProject.add(project);
}
public List<Annotation> getListAnnotation() {
return listAnnotation;
}
public void updateListAnnotation(Annotation annotation) {
listAnnotation.add(annotation);
}
public MakeAppointment getMakeAppointment() {
return makeAppointment;
}
public void setMakeAppointment(MakeAppointment makeAppointment) {
this.makeAppointment = makeAppointment;
} }
} }

View File

@ -1,14 +1,12 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
@Entity @Entity
@Table(name = "annotation") @Table(name = "annotation")
public class Annotation { public class Annotation {
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idAnnotation; private Long idAnnotation;
@ -33,7 +31,31 @@ public class Annotation {
return comment; return comment;
} }
public void setCommentary(String comment) { public void setComment(String comment) {
this.comment = comment; this.comment = comment;
} }
public Long getIdAnnotation() {
return idAnnotation;
}
public void setIdAnnotation(Long idAnnotation) {
this.idAnnotation = idAnnotation;
}
public SectionCell getSectionCellAnnotation() {
return sectionCellAnnotation;
}
public void setSectionCellAnnotation(SectionCell sectionCellAnnotation) {
this.sectionCellAnnotation = sectionCellAnnotation;
}
public Administrator getAdministratorAnnotation() {
return administratorAnnotation;
}
public void setAdministratorAnnotation(Administrator administratorAnnotation) {
this.administratorAnnotation = administratorAnnotation;
}
} }

View File

@ -1,7 +1,6 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
@ -17,9 +16,6 @@ public class Appointment {
new ArrayList<>(); */ new ArrayList<>(); */
// should now be useless // should now be useless
@OneToMany(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<Report> listReport = new ArrayList<>();
@ManyToMany( @ManyToMany(
fetch = FetchType.LAZY, fetch = FetchType.LAZY,
cascade = {CascadeType.ALL}) cascade = {CascadeType.ALL})
@ -29,8 +25,10 @@ public class Appointment {
inverseJoinColumns = @JoinColumn(name = "idSectionCell")) inverseJoinColumns = @JoinColumn(name = "idSectionCell"))
List<SectionCell> listSectionCell = new ArrayList<>(); List<SectionCell> listSectionCell = new ArrayList<>();
@OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true)
private Report report;
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idAppointment; private Long idAppointment;
@ -109,4 +107,20 @@ public class Appointment {
public void setAppointmentSubject(String appointmentSubject) { public void setAppointmentSubject(String appointmentSubject) {
this.appointmentSubject = appointmentSubject; this.appointmentSubject = appointmentSubject;
} }
public List<SectionCell> getAppointmentListSectionCell() {
return listSectionCell;
}
public void updateListSectionCell(SectionCell sectionCell) {
listSectionCell.add(sectionCell);
}
public Report getAppointmentReport() {
return report;
}
public void setAppointmentReport(Report report) {
this.report = report;
}
} }

View File

@ -1,8 +0,0 @@
package enseirb.myinpulse.model;
public class DelAppointment {
int validated;
int[] akserId;
int[] destId;
String date; // TODO: date type ?
}

View File

@ -1,7 +0,0 @@
package enseirb.myinpulse.model;
public class DelProject {
int projectId;
String projectName;
String projectDescription;
}

View File

@ -1,6 +0,0 @@
package enseirb.myinpulse.model;
public class DelReport {
int projectId;
String reportContent;
}

View File

@ -37,21 +37,42 @@ public class Entrepreneur extends User {
public Entrepreneur() {} public Entrepreneur() {}
public Entrepreneur( public Entrepreneur(
Long idUser,
String userSurname, String userSurname,
String username, String username,
String mainMail, String primaryMail,
String secondaryMail, String secondaryMail,
String phoneNumber, String phoneNumber,
String school, String school,
String course, String course,
boolean sneeStatus) { boolean sneeStatus) {
super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); super(userSurname, username, primaryMail, secondaryMail, phoneNumber);
this.school = school; this.school = school;
this.course = course; this.course = course;
this.sneeStatus = sneeStatus; this.sneeStatus = sneeStatus;
} }
public Entrepreneur(
Long idUser,
String userSurname,
String userName,
String primaryMail,
String secondaryMail,
String phoneNumber,
String school,
String course,
boolean sneeStatus,
Project projectParticipation,
Project projectProposed,
MakeAppointment makeAppointment) {
super(idUser, userSurname, userName, primaryMail, secondaryMail, phoneNumber);
this.school = school;
this.course = course;
this.sneeStatus = sneeStatus;
this.projectParticipation = projectParticipation;
this.projectProposed = projectProposed;
this.makeAppointment = makeAppointment;
}
public String getSchool() { public String getSchool() {
return school; return school;
} }
@ -75,4 +96,28 @@ public class Entrepreneur extends User {
public void setSneeStatus(boolean statusSnee) { public void setSneeStatus(boolean statusSnee) {
this.sneeStatus = sneeStatus; this.sneeStatus = sneeStatus;
} }
public Project getProjectParticipation() {
return projectParticipation;
}
public void setProjectParticipation(Project projectParticipation) {
this.projectParticipation = projectParticipation;
}
public Project getProjectProposed() {
return projectProposed;
}
public void setProjectProposed(Project projectProposed) {
this.projectProposed = projectProposed;
}
public MakeAppointment getMakeAppointment() {
return makeAppointment;
}
public void setMakeAppointment(MakeAppointment makeAppointment) {
this.makeAppointment = makeAppointment;
}
} }

View File

@ -1,7 +0,0 @@
package enseirb.myinpulse.model;
// TODO: is this redundant with the Section class from the database ?
// TODO: In the one hand it represent the same data, and on the other it should be much lighter.
// TODO: btw why does a LC section have an administrator ?
public class LCSection {}

View File

@ -1,14 +1,12 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
@Entity @Entity
@Table(name = "make_appointment") @Table(name = "make_appointment")
public class MakeAppointment { public class MakeAppointment {
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idMakeAppointment; private Long idMakeAppointment;

View File

@ -1,7 +1,6 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,37 +12,58 @@ public class Project {
@OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true) @OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<Entrepreneur> listEntrepreneurParticipation = new ArrayList<>(); private final List<Entrepreneur> listEntrepreneurParticipation = new ArrayList<>();
@OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) @OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<SectionCell> listSectionCell = new ArrayList<>(); private final List<SectionCell> listSectionCell = new ArrayList<>();
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idProject; private Long idProject;
@Column(length = 255) @Column(length = 255)
private String projectName; private String projectName;
private byte[] logo; private byte[] logo;
private LocalDate creationDate; private LocalDate creationDate;
@Column(length = 255)
private String projectStatus; @Column private ProjectDecisionValue projectStatus;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAdministrator") @JoinColumn(name = "idAdministrator")
private Administrator projectAdministrator; private Administrator projectAdministrator;
@OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true) @OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true)
private Entrepreneur entrepreneurProposed; private Entrepreneur entrepreneurProposed;
public Project() {} public Project() {}
public Project( public Project(
Long idProject,
String projectName, String projectName,
byte[] logo, byte[] logo,
LocalDate creationDate, LocalDate creationDate,
String projectStatus) { ProjectDecisionValue projectStatus,
this.idProject = idProject; Administrator projectAdministrator) {
this.projectName = projectName;
this.logo = logo;
this.creationDate = creationDate;
// this.projectStatus = (long) projectStatus.ordinal();
this.projectStatus = projectStatus;
this.projectAdministrator = projectAdministrator;
}
public Project(
String projectName,
byte[] logo,
LocalDate creationDate,
ProjectDecisionValue projectStatus,
Administrator projectAdministrator,
Entrepreneur entrepreneurProposed) {
this.projectName = projectName; this.projectName = projectName;
this.logo = logo; this.logo = logo;
this.creationDate = creationDate; this.creationDate = creationDate;
this.projectStatus = projectStatus; this.projectStatus = projectStatus;
this.projectAdministrator = projectAdministrator;
this.entrepreneurProposed = entrepreneurProposed;
} }
public Long getIdProject() { public Long getIdProject() {
@ -78,15 +98,43 @@ public class Project {
this.creationDate = creationDate; this.creationDate = creationDate;
} }
public String getProjectStatus() { public ProjectDecisionValue getProjectStatus() {
return projectStatus; return projectStatus;
} }
public void setProjectStatus(String projectStatus) { public void setProjectStatus(ProjectDecisionValue projectStatus) {
this.projectStatus = projectStatus; this.projectStatus = projectStatus;
} }
public void setAdministrator(Administrator administrator) { public List<Entrepreneur> getListEntrepreneurParticipation() {
this.projectAdministrator = administrator; return listEntrepreneurParticipation;
}
public void updateListEntrepreneurParticipation(Entrepreneur projectParticipant) {
listEntrepreneurParticipation.add(projectParticipant);
}
public List<SectionCell> getListSectionCell() {
return listSectionCell;
}
public void updateListSectionCell(SectionCell projectSectionCell) {
listSectionCell.add(projectSectionCell);
}
public Administrator getProjectAdministrator() {
return projectAdministrator;
}
public void setProjectAdministrator(Administrator projectAdministrator) {
this.projectAdministrator = projectAdministrator;
}
public Entrepreneur getEntrepreneurProposed() {
return entrepreneurProposed;
}
public void setEntrepreneurProposed(Entrepreneur entrepreneurProposed) {
this.entrepreneurProposed = entrepreneurProposed;
} }
} }

View File

@ -4,4 +4,22 @@ public class ProjectDecision {
public long projectId; public long projectId;
public long adminId; public long adminId;
public long isAccepted; public long isAccepted;
public ProjectDecision(long projectId, long adminId, long isAccepted) {
this.projectId = projectId;
this.adminId = adminId;
this.isAccepted = isAccepted;
}
@Override
public String toString() {
return "ProjectDecision{"
+ "projectId="
+ projectId
+ ", adminId="
+ adminId
+ ", isAccepted="
+ isAccepted
+ '}';
}
} }

View File

@ -0,0 +1,9 @@
package enseirb.myinpulse.model;
public enum ProjectDecisionValue {
PENDING,
ACTIVE,
ENDED,
ABORTED,
REJECTED,
}

View File

@ -4,20 +4,18 @@ import jakarta.persistence.*;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
@Entity @Entity
@Table(name = "report") @Table(name = "report")
public class Report { public class Report {
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idReport; private Long idReport;
private String reportContent; private String reportContent;
@ManyToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAppointment") @JoinColumn(name = "idAppointment")
private Appointment appointmentReport; private Appointment appointmentReport;
@ -28,6 +26,10 @@ public class Report {
this.reportContent = reportContent; this.reportContent = reportContent;
} }
public Long getIdReport() {
return idReport;
}
public String getReportContent() { public String getReportContent() {
return reportContent; return reportContent;
} }
@ -35,4 +37,12 @@ public class Report {
public void setReportContent(String reportContent) { public void setReportContent(String reportContent) {
this.reportContent = reportContent; this.reportContent = reportContent;
} }
public Appointment getAppointmentReport() {
return appointmentReport;
}
public void setAppointmentReport(Appointment appointmentReport) {
this.appointmentReport = appointmentReport;
}
} }

View File

@ -1,7 +1,6 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -11,44 +10,42 @@ import java.util.List;
@Table(name = "section_cell") @Table(name = "section_cell")
public class SectionCell { public class SectionCell {
@ManyToMany(mappedBy = "listSectionCell")
private final List<Appointment> listAppointment = new ArrayList<>();
@OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<Annotation> listAnnotation = new ArrayList<>();
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idSectionCell; private Long idSectionCell;
@Column(length = 255) @Column() private long sectionId;
private String title;
private String contentSectionCell; private String contentSectionCell;
/*@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAdministrator")
private Administrator administratorSectionCell;*/
// should now be useless
private LocalDateTime modificationDate; private LocalDateTime modificationDate;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idProject") @JoinColumn(name = "idProject")
private Project projectSectionCell; private Project projectSectionCell;
/*@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAdministrator")
private Administrator administratorSectionCell;*/
// should now be useless
@ManyToMany(mappedBy = "listSectionCell")
private List<Appointment> appointment = new ArrayList<>();
@OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Annotation> listAnnotation = new ArrayList<>();
public SectionCell() {} public SectionCell() {}
public SectionCell( public SectionCell(
Long idSectionCell, Long idSectionCell,
String title, Long sectionId,
String contentSectionCell, String contentSectionCell,
LocalDateTime modificationDate) { LocalDateTime modificationDate,
Project projectSectionCell) {
this.idSectionCell = idSectionCell; this.idSectionCell = idSectionCell;
this.title = title; this.sectionId = sectionId;
this.contentSectionCell = contentSectionCell; this.contentSectionCell = contentSectionCell;
this.modificationDate = modificationDate; this.modificationDate = modificationDate;
this.projectSectionCell = projectSectionCell;
} }
public Long getIdSectionCell() { public Long getIdSectionCell() {
@ -59,12 +56,12 @@ public class SectionCell {
this.idSectionCell = idSectionCell; this.idSectionCell = idSectionCell;
} }
public String getTitle() { public Long getSectionId() {
return title; return sectionId;
} }
public void setTitle(String title) { public void setSectionId(Long sectionId) {
this.title = title; this.sectionId = sectionId;
} }
public String getContentSectionCell() { public String getContentSectionCell() {
@ -82,4 +79,32 @@ public class SectionCell {
public void setModificationDate(LocalDateTime modificationDate) { public void setModificationDate(LocalDateTime modificationDate) {
this.modificationDate = modificationDate; this.modificationDate = modificationDate;
} }
public Project getProjectSectionCell() {
return projectSectionCell;
}
public List<Appointment> getAppointmentSectionCell() {
return listAppointment;
}
public void updateAppointmentSectionCell(Appointment appointment) {
listAppointment.add(appointment);
}
public List<Annotation> getListAnnotation() {
return listAnnotation;
}
public void updateListAnnotation(Annotation annotation) {
listAnnotation.add(annotation);
}
public void setSectionId(long sectionId) {
this.sectionId = sectionId;
}
public void setProjectSectionCell(Project projectSectionCell) {
this.projectSectionCell = projectSectionCell;
}
} }

View File

@ -1,7 +1,6 @@
package enseirb.myinpulse.model; package enseirb.myinpulse.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
@Entity @Entity
@Table(name = "user_inpulse") @Table(name = "user_inpulse")
@ -9,7 +8,6 @@ import jakarta.validation.constraints.NotNull;
public class User { public class User {
@Id @Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idUser; private Long idUser;
@ -30,6 +28,8 @@ public class User {
public User() {} public User() {}
// TODO: this should be removed as we shouldn't be able to chose the ID. Leaving it for
// compatibility purposes, as soon as it's not used anymore, delete it
public User( public User(
Long idUser, Long idUser,
String userSurname, String userSurname,
@ -45,6 +45,19 @@ public class User {
this.phoneNumber = phoneNumber; this.phoneNumber = phoneNumber;
} }
public User(
String userSurname,
String userName,
String primaryMail,
String secondaryMail,
String phoneNumber) {
this.userSurname = userSurname;
this.userName = userName;
this.primaryMail = primaryMail;
this.secondaryMail = secondaryMail;
this.phoneNumber = phoneNumber;
}
public Long getIdUser() { public Long getIdUser() {
return idUser; return idUser;
} }
@ -73,8 +86,8 @@ public class User {
return primaryMail; return primaryMail;
} }
public void setPrimaryMail(String mainMail) { public void setPrimaryMail(String primaryMail) {
this.primaryMail = mainMail; this.primaryMail = primaryMail;
} }
public String getSecondaryMail() { public String getSecondaryMail() {

View File

@ -5,10 +5,13 @@ import enseirb.myinpulse.model.Administrator;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import java.util.Optional;
@RepositoryRestResource @RepositoryRestResource
public interface AdministratorRepository extends JpaRepository<Administrator, Long> { public interface AdministratorRepository extends JpaRepository<Administrator, Long> {
/* @Query("SELECT a from Administrators a") /* @Query("SELECT a from Administrators a")
Administrator findAllAdministrator(); */ Administrator findAllAdministrator(); */
Optional<Administrator> findByPrimaryMail(String PrimaryMail);
} }

View File

@ -1,6 +1,7 @@
package enseirb.myinpulse.repository; package enseirb.myinpulse.repository;
import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@ -8,6 +9,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource @RepositoryRestResource
public interface EntrepreneurRepository extends JpaRepository<Entrepreneur, Long> { public interface EntrepreneurRepository extends JpaRepository<Entrepreneur, Long> {
Iterable<Entrepreneur> getEntrepreneurByProjectParticipation(Project project);
/* @Query("SELECT e from Entrepreneur e") /* @Query("SELECT e from Entrepreneur e")
Entrepreneur findAllEntrepreneurl(); */ Entrepreneur findAllEntrepreneurl(); */

View File

@ -2,13 +2,18 @@ package enseirb.myinpulse.repository;
import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.ProjectDecisionValue;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import java.util.Optional;
@RepositoryRestResource @RepositoryRestResource
public interface ProjectRepository extends JpaRepository<Project, Long> { public interface ProjectRepository extends JpaRepository<Project, Long> {
Iterable<Project> findByProjectAdministrator(Administrator administrator); Iterable<Project> findByProjectAdministrator(Administrator administrator);
Iterable<Project> findByProjectStatus(String status); Iterable<Project> findByProjectStatus(ProjectDecisionValue status);
Optional<Project> findByProjectName(String projectName);
} }

View File

@ -6,4 +6,4 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource @RepositoryRestResource
public interface ReportRepository extends JpaRepository<Report, Integer> {} public interface ReportRepository extends JpaRepository<Report, Long> {}

View File

@ -1,9 +1,18 @@
package enseirb.myinpulse.repository; package enseirb.myinpulse.repository;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.model.SectionCell;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import java.time.LocalDateTime;
@RepositoryRestResource @RepositoryRestResource
public interface SectionCellRepository extends JpaRepository<SectionCell, Long> {} public interface SectionCellRepository extends JpaRepository<SectionCell, Long> {
Iterable<SectionCell> findByProjectSectionCellAndSectionId(Project project, long sectionId);
Iterable<SectionCell> findByProjectSectionCellAndSectionIdAndModificationDateBefore(
Project project, long sectionId, LocalDateTime date);
}

View File

@ -1,68 +1,162 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.*; import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
import enseirb.myinpulse.service.database.AdministratorService; import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.UserService;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import java.util.ArrayList;
import java.util.List;
@Service @Service
public class AdminApiService { public class AdminApiService {
protected static final Logger logger = LogManager.getLogger();
private final ProjectService projectService; private final ProjectService projectService;
private final UserService userService; private final UserService userService;
private final AdministratorService administratorService; private final AdministratorService administratorService;
private final UtilsService utilsService;
private final AppointmentService appointmentService;
private final ReportService reportService;
private final SectionCellService sectionCellService;
@Autowired @Autowired
AdminApiService( AdminApiService(
ProjectService projectService, ProjectService projectService,
UserService userService, UserService userService,
AdministratorService administratorService) { AdministratorService administratorService,
UtilsService utilsService,
AppointmentService appointmentService,
ReportService reportService,
SectionCellService sectionCellService) {
this.projectService = projectService; this.projectService = projectService;
this.userService = userService; this.userService = userService;
this.administratorService = administratorService; this.administratorService = administratorService;
this.utilsService = utilsService;
this.appointmentService = appointmentService;
this.reportService = reportService;
this.sectionCellService = sectionCellService;
} }
// TODO: test // TODO: check if tests are sufficient - peer verification required
public Iterable<Project> getProjectsOfAdmin(String email) { public Iterable<Project> getProjectsOfAdmin(String mail) {
return projectService.getProjectsByAdminId( return projectService.getProjectsByAdminId(
administratorService.getAdministratorById( administratorService.getAdministratorById(
this.userService.getIdUserByEmail(email))); this.userService.getUserByEmail(mail).getIdUser()));
} }
// TODO public Iterable<Appointment> getUpcomingAppointments(String mail) {
public Iterable<Appointment> getUpcomingAppointments(String email) { logger.info("User {} check their upcoming appointments", mail);
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); User user = this.userService.getUserByEmail(mail);
List<Appointment> appointments = new ArrayList<>();
if (user instanceof Administrator) {
List<Project> projects = new ArrayList<>(((Administrator) user).getListProject());
projects.forEach(
project -> {
project.getListSectionCell()
.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService
.getAppointmentsBySectionCellId(
sectionCell
.getIdSectionCell()));
});
});
}
if (user instanceof Entrepreneur) {
Project project = ((Entrepreneur) user).getProjectParticipation();
project.getListSectionCell()
.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService.getAppointmentsBySectionCellId(
sectionCell.getIdSectionCell()));
});
}
return appointments;
} }
// TODO: test // TODO: check if tests are sufficient - peer verification required
public Iterable<Project> getPendingProjects() { public Iterable<Project> getPendingProjects() {
return this.projectService.getPendingProjects(); return this.projectService.getPendingProjects();
} }
// TODO: test // TODO: check if tests are sufficient - peer verification required
public void validateProject(ProjectDecision decision) { public void validateProject(ProjectDecision decision) {
projectService.updateProject( projectService.updateProject(
decision.projectId, decision.projectId,
null, null,
null, null,
null, null,
"ACTIVE", (decision.isAccepted == 1) ? ACTIVE : REJECTED,
this.administratorService.getAdministratorById(decision.projectId)); this.administratorService.getAdministratorById(decision.adminId));
} }
// TODO: solve todo + test // TODO: check if tests are sufficient - peer verification required
public void addNewProject(Project project) { public void addNewProject(Project project) {
projectService.addNewProject(project); // TODO: how can the user know the ID ? project.setIdProject(null);
// We remove the ID from the request to be sure that it will be auto generated
try {
this.projectService.getProjectByName(project.getProjectName(), true);
throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
} catch (ResponseStatusException e) {
if (e.getStatusCode() == HttpStatus.CONFLICT) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
}
}
Project newProject = projectService.addNewProject(project);
if (project.getProjectAdministrator() != null) {
newProject.getProjectAdministrator().updateListProject(newProject);
}
if (newProject.getEntrepreneurProposed() != null) {
Entrepreneur proposed = newProject.getEntrepreneurProposed();
proposed.setProjectProposed(newProject);
proposed.setProjectParticipation(newProject);
}
newProject
.getListEntrepreneurParticipation()
.forEach(
participation -> {
participation.setProjectParticipation(newProject);
});
newProject
.getListSectionCell()
.forEach(
sectionCell -> {
sectionCell.setProjectSectionCell(newProject);
});
} }
// TODO public void createAppointmentReport(long appointmentId, Report report, String mail) {
public void createAppointmentReport(String appointmentId, Report report, String email) { long projectId =
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentListSectionCell()
.getFirst()
.getProjectSectionCell()
.getIdProject();
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to add an report for appointment {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info("User {} added a report for appointment {}", mail, projectId);
Report addedReport = this.reportService.addNewReport(report);
addedReport.setAppointmentReport(this.appointmentService.getAppointmentById(appointmentId));
this.appointmentService.getAppointmentById(appointmentId).setAppointmentReport(addedReport);
} }
// TODO: test // TODO: test

View File

@ -1,29 +1,135 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.LCSection; import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.SectionCellService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
@Service @Service
public class EntrepreneurApiService { public class EntrepreneurApiService {
public void editLCSection(String sectionId, LCSection section, String mail) { protected static final Logger logger = LogManager.getLogger();
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
private final SectionCellService sectionCellService;
private final ProjectService projectService;
private final UtilsService utilsService;
@Autowired
EntrepreneurApiService(
SectionCellService sectionCellService,
ProjectService projectService,
UtilsService utilsService) {
this.sectionCellService = sectionCellService;
this.projectService = projectService;
this.utilsService = utilsService;
} }
public void removeLCSection(String sectionId, String mail) { public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (editSectionCell == null) {
System.err.println("Trying to edit unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCellId))) {
logger.warn(
"User {} tried to edit section cells {} of the project {} but is not allowed to.",
mail,
sectionCellId,
this.sectionCellService.getProjectId(sectionCellId));
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} edited section cell {} of the project with id {}",
mail,
sectionCellId,
this.sectionCellService.getProjectId(sectionCellId));
sectionCellService.updateSectionCell(
sectionCellId,
sectionCell.getSectionId(),
sectionCell.getContentSectionCell(),
sectionCell.getModificationDate());
} }
public void addLCSection(String sectionId, LCSection section, String mail) { public void removeSectionCell(Long sectionCellId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (editSectionCell == null) {
System.err.println("Trying to remove unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCellId))) {
logger.warn(
"User {} tried to remove section cells {} of the project {} but is not allowed to.",
mail,
sectionCellId,
this.sectionCellService.getSectionCellById(sectionCellId));
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} removed section cell {} of the project with id {}",
mail,
sectionCellId,
this.sectionCellService.getProjectId(sectionCellId));
sectionCellService.removeSectionCellById(sectionCellId);
}
public void addSectionCell(SectionCell sectionCell, String mail) {
if (sectionCell == null) {
System.err.println("Trying to create an empty section cell");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
}
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
logger.warn(
"User {} tried to add a section cell to the project {} but is not allowed to.",
mail,
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} added a new section cell {} to the project with id {}",
mail,
sectionCell.getIdSectionCell(),
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
SectionCell newSectionCell = sectionCellService.addNewSectionCell(sectionCell);
newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell);
newSectionCell
.getAppointmentSectionCell()
.forEach(
appointment -> {
appointment.updateListSectionCell(newSectionCell);
});
newSectionCell
.getListAnnotation()
.forEach(
annotation -> {
annotation.setSectionCellAnnotation(newSectionCell);
});
} }
public void requestNewProject(Project project, String mail) { public void requestNewProject(Project project, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); if (project == null) {
logger.error("Trying to request the creation of a null project");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide");
}
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
project.setProjectStatus(PENDING);
projectService.addNewProject(project);
} }
} }

View File

@ -1,36 +1,252 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.*; import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@Service @Service
public class SharedApiService { public class SharedApiService {
public Iterable<SectionCell> getLCSection( protected static final Logger logger = LogManager.getLogger();
String projectId, String title, String date, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); private final ProjectService projectService;
private final EntrepreneurService entrepreneurService;
private final SectionCellService sectionCellService;
private final AppointmentService appointmentService;
private final UtilsService utilsService;
@Autowired
SharedApiService(
ProjectService projectService,
EntrepreneurService entrepreneurService,
SectionCellService sectionCellService,
AppointmentService appointmentService,
UtilsService utilsService) {
this.projectService = projectService;
this.entrepreneurService = entrepreneurService;
this.sectionCellService = sectionCellService;
this.appointmentService = appointmentService;
this.utilsService = utilsService;
} }
public Iterable<Entrepreneur> getEntrepreneursByProjectId(int projectId, String mail) { // TODO filter this with date
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); public Iterable<SectionCell> getSectionCells(
long projectId, long sectionId, String date, String mail) {
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check section cells of the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dateTime = LocalDateTime.parse(date, formatter);
Project project = this.projectService.getProjectById(projectId);
return this.sectionCellService.getSectionCellsByProjectAndSectionIdBeforeDate(
project, sectionId, dateTime);
} }
public Iterable<Administrator> getAdminByProjectId(int projectId, String mail) { // TODO: test
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check the member of the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
Project project = this.projectService.getProjectById(projectId);
return this.entrepreneurService.GetEntrepreneurByProject(project);
} }
public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) { // TODO: test
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); public Administrator getAdminByProjectId(long projectId, String mail) {
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check the admin of the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
Project project = this.projectService.getProjectById(projectId);
return project.getProjectAdministrator();
} }
public void getPDFReport(int appointmentId, String mail) { public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check the appointments related to the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} tried to check the appointments related to the project {}",
mail,
projectId);
Iterable<SectionCell> sectionCells =
this.sectionCellService.getSectionCellsByProject(
projectService.getProjectById(projectId),
2L); // sectionId useless in this function ?
List<Appointment> appointments = new ArrayList<Appointment>();
sectionCells.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService.getAppointmentsBySectionCellId(
sectionCell.getIdSectionCell()));
});
return appointments;
}
public void getPDFReport(long appointmentId, String mail)
throws DocumentException, URISyntaxException, IOException {
long projectId =
this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentListSectionCell()
.getFirst()
.getProjectSectionCell()
.getIdProject();
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to generate the PDF report {} related to the appointment {} but is not allowed to.",
mail,
this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentReport()
.getIdReport(),
appointmentId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} generated the PDF report related to appointment {}", mail, appointmentId);
String reportContent =
this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentReport()
.getReportContent();
// PDF generation
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("Report" + appointmentId + ".pdf"));
document.open();
Paragraph title =
new Paragraph(
new Phrase(
"Compte Rendu - Réunion du "
+ this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentDate()
.toString(),
FontFactory.getFont(
FontFactory.HELVETICA,
20,
Font.BOLDITALIC,
BaseColor.BLACK)));
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
Font subsection =
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.UNDERLINE, BaseColor.DARK_GRAY);
Font body = FontFactory.getFont(FontFactory.COURIER, 12, BaseColor.BLACK);
String[] split = reportContent.split(" ");
String tmp = "";
int counter = 1;
for (String s : split) {
if (s.equals("//")) {
Chunk chunk = new Chunk(tmp, body);
document.add(chunk);
document.add(new Paragraph("\n"));
tmp = "";
Paragraph paragraph = new Paragraph("Point n°" + counter + " : ", subsection);
document.add(paragraph);
document.add(new Paragraph("\n"));
counter++;
} else {
tmp = tmp.concat(s + " ");
}
}
Chunk chunk = new Chunk(tmp, body);
document.add(chunk);
document.add(new Paragraph("\n"));
document.close();
// Replace uri with website address
Files.copy(
new URI(
"http://localhost:8080/shared/projects/appointments/report/"
+ appointmentId)
.toURL()
.openStream(),
Paths.get("Report" + appointmentId + ".pdf"),
StandardCopyOption.REPLACE_EXISTING);
// delete file, we don't want to stock all reports on the server
File file = new File("Report" + appointmentId + ".pdf");
if (!file.delete()) {
logger.warn("Failed to delete report {}", file.getAbsolutePath());
}
} }
public void createAppointmentRequest(Appointment appointment, String mail) { public void createAppointmentRequest(Appointment appointment, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); long projectId =
appointment
.getAppointmentListSectionCell()
.getFirst()
.getProjectSectionCell()
.getIdProject();
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to create for the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info("User {} tried to create an appointment for project {}", mail, projectId);
Appointment newAppointment = this.appointmentService.addNewAppointment(appointment);
newAppointment
.getAppointmentListSectionCell()
.forEach(
sectionCell -> {
sectionCell.updateAppointmentSectionCell(newAppointment);
});
newAppointment.getAppointmentReport().setAppointmentReport(newAppointment);
} }
} }

View File

@ -0,0 +1,62 @@
package enseirb.myinpulse.service;
import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.User;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
@Service
public class UtilsService {
protected static final Logger logger = LogManager.getLogger();
private final UserService userService;
private final ProjectService projectService;
private final EntrepreneurService entrepreneurService;
private final AdministratorService administratorService;
@Autowired
UtilsService(
ProjectService projectService,
UserService userService,
EntrepreneurService entrepreneurService,
AdministratorService administratorService) {
this.userService = userService;
this.projectService = projectService;
this.entrepreneurService = entrepreneurService;
this.administratorService = administratorService;
}
// TODO: test?
public Boolean isAllowedToCheckProject(String mail, long projectId) {
if (isAnAdmin(mail)) {
return true;
}
User user = this.userService.getUserByEmail(mail);
Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser());
Project project = this.projectService.getProjectById(projectId);
return entrepreneur.getProjectParticipation() == project;
}
// TODO: test
Boolean isAnAdmin(String mail) {
try {
long userId = this.userService.getUserByEmail(mail).getIdUser();
Administrator a = this.administratorService.getAdministratorById(userId);
return true;
} catch (ResponseStatusException e) {
logger.info(e);
return false;
}
}
}

View File

@ -37,7 +37,24 @@ public class AdministratorService {
return administrator.get(); return administrator.get();
} }
public Administrator getAdministratorByPrimaryMain(String primaryMail) {
Optional<Administrator> administrator =
this.administratorRepository.findByPrimaryMail(primaryMail);
if (administrator.isEmpty()) {
logger.error("No administrator found with the mail {}", primaryMail);
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas");
}
return administrator.get();
}
public Administrator addAdministrator(Administrator administrator) { public Administrator addAdministrator(Administrator administrator) {
return this.administratorRepository.save(administrator); return this.administratorRepository.save(administrator);
} }
/*
public Administrator getAdministratorByProject(Project project) {
r
}
*/
} }

View File

@ -0,0 +1,61 @@
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Annotation;
import enseirb.myinpulse.repository.AnnotationRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.util.Optional;
@Service
public class AnnotationService {
protected static final Logger logger = LogManager.getLogger();
private final AnnotationRepository annotationRepository;
@Autowired
AnnotationService(AnnotationRepository annotationRepository) {
this.annotationRepository = annotationRepository;
}
public Iterable<Annotation> getAllAnnotations() {
return annotationRepository.findAll();
}
public Annotation getAnnotationById(Long id) {
Optional<Annotation> annotation = annotationRepository.findById(id);
if (annotation.isEmpty()) {
logger.error("getAnnotationById : No annotation found with id {}", id);
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette annotation n'existe pas");
}
return annotation.get();
}
public Annotation addNewAnnotation(Annotation annotation) {
return this.annotationRepository.save(annotation);
}
public void deleteAnnotationById(Long id) {
this.annotationRepository.deleteById(id);
}
public Annotation updateAnnotation(Long id, String comment) {
Optional<Annotation> annotation = annotationRepository.findById(id);
if (annotation.isEmpty()) {
logger.error("updateAnnotation : No annotation found with id {}", id);
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette annotation n'existe pas");
}
if (comment != null) {
annotation.get().setComment(comment);
}
return this.annotationRepository.save(annotation.get());
}
}

View File

@ -1,69 +1,79 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Appointment; import enseirb.myinpulse.model.Appointment;
import enseirb.myinpulse.repository.AppointmentRepository; import enseirb.myinpulse.repository.AppointmentRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.logging.log4j.LogManager;
import org.springframework.http.HttpStatus; import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.server.ResponseStatusException; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.time.LocalDate; import org.springframework.web.server.ResponseStatusException;
import java.time.LocalTime;
import java.util.Optional; import java.time.LocalDate;
import java.time.LocalTime;
@RestController import java.util.Optional;
public class AppointmentController {
@Service
@Autowired AppointmentRepository appointmentRepository; public class AppointmentService {
@GetMapping("/Appointment") private static final Logger logger = LogManager.getLogger(AppointmentService.class);
@ResponseBody
public Iterable<Appointment> allAppointments() { private AppointmentRepository appointmentRepository;
return this.appointmentRepository.findAll();
} @Autowired
AppointmentService(AppointmentRepository appointmentRepository) {
@GetMapping("/Appointment/{id}") this.appointmentRepository = appointmentRepository;
public Appointment getAppointmentById(@PathVariable Long id) { }
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
if (appointment.isEmpty()) { public Iterable<Appointment> getallAppointments() {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); return this.appointmentRepository.findAll();
} }
return appointment.get();
} public Appointment getAppointmentById(Long id) {
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
@PostMapping("/Appointment") if (appointment.isEmpty()) {
public Appointment addAppointment(@RequestBody Appointment appointment) { logger.error("getAppointmentById : No appointment found with id {}", id);
return this.appointmentRepository.save(appointment); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
} }
return appointment.get();
@PostMapping("/Appointment/{id}") }
public Appointment updateAppointment(
@PathVariable Long id, public Appointment addNewAppointment(Appointment appointment) {
LocalDate appointmentDate, return this.appointmentRepository.save(appointment);
LocalTime appointmentTime, }
LocalTime appointmentDuration,
String appointmentPlace, public void deleteAppointmentById(Long id) {
String appointmentSubject) { this.appointmentRepository.deleteById(id);
Optional<Appointment> appointment = this.appointmentRepository.findById(id); }
if (appointment.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); public Appointment updateAppointment(
} Long id,
if (appointmentDate != null) { LocalDate appointmentDate,
appointment.get().setAppointmentDate(appointmentDate); LocalTime appointmentTime,
} LocalTime appointmentDuration,
if (appointmentTime != null) { String appointmentPlace,
appointment.get().setAppointmentTime(appointmentTime); String appointmentSubject) {
} Optional<Appointment> appointment = this.appointmentRepository.findById(id);
if (appointmentDuration != null) { if (appointment.isEmpty()) {
appointment.get().setAppointmentDuration(appointmentDuration); logger.error("updateAppointment : No appointment found with id {}", id);
} throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
if (appointmentPlace != null) { }
appointment.get().setAppointmentPlace(appointmentPlace); if (appointmentDate != null) {
} appointment.get().setAppointmentDate(appointmentDate);
if (appointmentSubject != null) { }
appointment.get().setAppointmentSubject(appointmentSubject); if (appointmentTime != null) {
} appointment.get().setAppointmentTime(appointmentTime);
return this.appointmentRepository.save(appointment.get()); }
} if (appointmentDuration != null) {
} appointment.get().setAppointmentDuration(appointmentDuration);
}
if (appointmentPlace != null) {
appointment.get().setAppointmentPlace(appointmentPlace);
}
if (appointmentSubject != null) {
appointment.get().setAppointmentSubject(appointmentSubject);
}
return this.appointmentRepository.save(appointment.get());
}
}

View File

@ -1,46 +1,51 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.repository.EntrepreneurRepository; import enseirb.myinpulse.repository.EntrepreneurRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import java.util.Optional; import java.util.Optional;
@RestController @Service
public class EntrepreneurController { public class EntrepreneurService {
@Autowired EntrepreneurRepository entrepreneurRepository; protected static final Logger logger = LogManager.getLogger();
@GetMapping("/Entrepreneur") private final EntrepreneurRepository entrepreneurRepository;
@ResponseBody
public Iterable<Entrepreneur> allEntrepreneurs() { EntrepreneurService(EntrepreneurRepository entrepreneurRepository) {
this.entrepreneurRepository = entrepreneurRepository;
}
public Iterable<Entrepreneur> getAllEntrepreneurs() {
return this.entrepreneurRepository.findAll(); return this.entrepreneurRepository.findAll();
} }
@GetMapping("/Entrepreneur/{id}") public Entrepreneur getEntrepreneurById(Long id) {
public Entrepreneur getEntrepreneurById(@PathVariable Long id) {
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id); Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
if (entrepreneur.isEmpty()) { if (entrepreneur.isEmpty()) {
logger.error("getEntrepreneurById : No entrepreneur found with id {}", id);
throw new ResponseStatusException( throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
} }
return entrepreneur.get(); return entrepreneur.get();
} }
@PostMapping("/Entrepreneur") public Entrepreneur addEntrepreneur(Entrepreneur entrepreneur) {
public Entrepreneur addEntrepreneur(@RequestBody Entrepreneur entrepreneur) {
return this.entrepreneurRepository.save(entrepreneur); return this.entrepreneurRepository.save(entrepreneur);
} }
@PostMapping("/Entrepreneur/{id}")
public Entrepreneur updateEntrepreneur( public Entrepreneur updateEntrepreneur(
@PathVariable Long id, String school, String course, Boolean sneeStatus) { Long id, String school, String course, Boolean sneeStatus) {
Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id); Optional<Entrepreneur> entrepreneur = entrepreneurRepository.findById(id);
if (entrepreneur.isEmpty()) { if (entrepreneur.isEmpty()) {
logger.error("updateEntrepreneur : No entrepreneur found with id {}", id);
throw new ResponseStatusException( throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas");
} }
@ -55,4 +60,8 @@ public class EntrepreneurController {
} }
return this.entrepreneurRepository.save(entrepreneur.get()); return this.entrepreneurRepository.save(entrepreneur.get());
} }
public Iterable<Entrepreneur> GetEntrepreneurByProject(Project project) {
return this.entrepreneurRepository.getEntrepreneurByProjectParticipation(project);
}
} }

View File

@ -1,7 +1,10 @@
package enseirb.myinpulse.service.database; package enseirb.myinpulse.service.database;
import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING;
import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.ProjectDecisionValue;
import enseirb.myinpulse.repository.ProjectRepository; import enseirb.myinpulse.repository.ProjectRepository;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -34,7 +37,7 @@ public class ProjectService {
public Project getProjectById(Long id) { public Project getProjectById(Long id) {
Optional<Project> project = this.projectRepository.findById(id); Optional<Project> project = this.projectRepository.findById(id);
if (project.isEmpty()) { if (project.isEmpty()) {
System.err.println("Project with id " + id + " not found"); logger.error("No project found with id {}", id);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
} }
return project.get(); return project.get();
@ -54,7 +57,7 @@ public class ProjectService {
String projectName, String projectName,
byte[] logo, byte[] logo,
LocalDate creationDate, LocalDate creationDate,
String projectStatus, ProjectDecisionValue projectStatus,
Administrator administrator) { Administrator administrator) {
Optional<Project> project = this.projectRepository.findById(id); Optional<Project> project = this.projectRepository.findById(id);
@ -76,16 +79,19 @@ public class ProjectService {
} }
if (projectStatus != null) { if (projectStatus != null) {
// TODO: check if this is really useful
/*
if (!validateStatus(projectStatus)) { if (!validateStatus(projectStatus)) {
System.err.println("updateProjectStatus: Invalid status " + projectStatus); logger.error("updateProjectStatus: Invalid status {}", projectStatus);
throw new ResponseStatusException( throw new ResponseStatusException(
HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté"); HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté");
} }
*/
project.get().setProjectStatus(projectStatus); project.get().setProjectStatus(projectStatus);
} }
if (administrator != null) { if (administrator != null) {
project.get().setAdministrator(administrator); project.get().setProjectAdministrator(administrator);
} }
return this.projectRepository.save(project.get()); return this.projectRepository.save(project.get());
@ -96,10 +102,23 @@ public class ProjectService {
} }
public Iterable<Project> getPendingProjects() { public Iterable<Project> getPendingProjects() {
return this.projectRepository.findByProjectStatus("PENDING"); return this.projectRepository.findByProjectStatus(PENDING);
} }
public void deleteProjectById(Long id) { public void deleteProjectById(Long id) {
this.projectRepository.deleteById(id); this.projectRepository.deleteById(id);
} }
public Project getProjectByName(String name, boolean noerror) {
Optional<Project> project = this.projectRepository.findByProjectName(name);
if (project.isEmpty()) {
if (noerror) logger.error("No project found with name {}", name);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
}
return project.get();
}
public Project getProjectByName(String name) {
return getProjectByName(name, false);
}
} }

View File

@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Report; import enseirb.myinpulse.model.Report;
import enseirb.myinpulse.repository.ReportRepository; import enseirb.myinpulse.repository.ReportRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -12,6 +14,9 @@ import java.util.Optional;
@Service @Service
public class ReportService { public class ReportService {
protected static final Logger logger = LogManager.getLogger();
private final ReportRepository reportRepository; private final ReportRepository reportRepository;
@Autowired @Autowired
@ -19,16 +24,37 @@ public class ReportService {
this.reportRepository = reportRepository; this.reportRepository = reportRepository;
} }
Report getReportById(int id) { public Iterable<Report> getAllReports() {
Optional<Report> report = reportRepository.findById(id); return this.reportRepository.findAll();
}
public Report getReportById(Long id) {
Optional<Report> report = this.reportRepository.findById(id);
if (report.isEmpty()) { if (report.isEmpty()) {
logger.error("getReportById : No report found with id {}", id);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas");
} }
return report.get(); return report.get();
} }
// TODO: do some validation // TODO: do some validation
void saveReport(Report report) { public Report addNewReport(Report report) {
reportRepository.save(report); return this.reportRepository.save(report);
}
public void deleteReportById(Long id) {
this.reportRepository.deleteById(id);
}
public Report updateReport(Long id, String reportContent) {
Optional<Report> report = this.reportRepository.findById(id);
if (report.isEmpty()) {
logger.error("updateReport : No report found with id {}", id);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas");
}
if (reportContent != null) {
report.get().setReportContent(reportContent);
}
return this.reportRepository.save(report.get());
} }
} }

View File

@ -0,0 +1,93 @@
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Appointment;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.repository.SectionCellRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@Service
public class SectionCellService {
protected static final Logger logger = LogManager.getLogger();
private final SectionCellRepository sectionCellRepository;
@Autowired
SectionCellService(SectionCellRepository sectionCellRepository) {
this.sectionCellRepository = sectionCellRepository;
}
public Iterable<SectionCell> getAllSectionCells() {
return this.sectionCellRepository.findAll();
}
public SectionCell getSectionCellById(Long id) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
logger.error("getSectionCellById : No sectionCell found with id {}", id);
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
return sectionCell.get();
}
public SectionCell addNewSectionCell(SectionCell sectionCell) {
return this.sectionCellRepository.save(sectionCell);
}
public void removeSectionCellById(Long id) {
this.sectionCellRepository.deleteById(id);
}
public SectionCell updateSectionCell(
Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
logger.error("updateSectionCell : No sectionCell found with id {}", id);
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (sectionId != null) {
sectionCell.get().setSectionId(sectionId);
}
if (contentSectionCell != null) {
sectionCell.get().setContentSectionCell(contentSectionCell);
}
if (modificationDate != null) {
sectionCell.get().setModificationDate(modificationDate);
}
return this.sectionCellRepository.save(sectionCell.get());
}
public Iterable<SectionCell> getSectionCellsByProject(Project project, Long sectionId) {
return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId);
}
public Long getProjectId(Long sectionCellId) {
SectionCell sectionCell = getSectionCellById(sectionCellId);
Project sectionProject = sectionCell.getProjectSectionCell();
return sectionProject.getIdProject();
}
public List<Appointment> getAppointmentsBySectionCellId(Long sectionCellId) {
SectionCell sectionCell = getSectionCellById(sectionCellId);
return sectionCell.getAppointmentSectionCell();
}
public Iterable<SectionCell> getSectionCellsByProjectAndSectionIdBeforeDate(
Project project, long sectionId, LocalDateTime date) {
return sectionCellRepository.findByProjectSectionCellAndSectionIdAndModificationDateBefore(
project, sectionId, date);
}
}

View File

@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.User; import enseirb.myinpulse.model.User;
import enseirb.myinpulse.repository.UserRepository; import enseirb.myinpulse.repository.UserRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -14,6 +16,9 @@ import java.util.Optional;
@Service @Service
public class UserService { public class UserService {
protected static final Logger logger = LogManager.getLogger();
private final UserRepository userRepository; private final UserRepository userRepository;
@Autowired @Autowired
@ -26,15 +31,14 @@ public class UserService {
} }
// TODO // TODO
public long getIdUserByEmail(String email) { public User getUserByEmail(String email) {
Optional<User> opt_user = this.userRepository.findByPrimaryMail(email); Optional<User> opt_user = this.userRepository.findByPrimaryMail(email);
if (opt_user.isEmpty()) { if (opt_user.isEmpty()) {
System.err.println("Couldn't find user with email " + email); logger.error("getUserByEmail : No user found with email {}", email);
throw new ResponseStatusException(HttpStatus.NOT_FOUND); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
} }
User user = opt_user.get(); return opt_user.get();
return user.getIdUser();
} }
public Iterable<User> allUsers() { public Iterable<User> allUsers() {
@ -49,11 +53,12 @@ public class UserService {
@PathVariable Long id, @PathVariable Long id,
String userSurname, String userSurname,
String userName, String userName,
String mainMail, String primaryMail,
String secondaryMail, String secondaryMail,
String phoneNumber) { String phoneNumber) {
Optional<User> user = userRepository.findById(id); Optional<User> user = userRepository.findById(id);
if (user.isEmpty()) { if (user.isEmpty()) {
logger.error("updateUser : No user found with id {}", id);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
} }
if (userName != null) { if (userName != null) {
@ -62,8 +67,8 @@ public class UserService {
if (userSurname != null) { if (userSurname != null) {
user.get().setUserSurname(userSurname); user.get().setUserSurname(userSurname);
} }
if (mainMail != null) { if (primaryMail != null) {
user.get().setPrimaryMail(mainMail); user.get().setPrimaryMail(primaryMail);
} }
if (secondaryMail != null) { if (secondaryMail != null) {
user.get().setSecondaryMail(secondaryMail); user.get().setSecondaryMail(secondaryMail);

View File

@ -1,43 +0,0 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
import org.springframework.web.bind.annotation.*;
@RestController
public class ReportController {
/*
private final ReportRepository reportRepository;
@Autowired
public ReportController(ReportRepository reportRepository) {
this.reportRepository = reportRepository;
}
@GetMapping("/Report")
@ResponseBody
public Iterable<Report> allReports() {
System.out.println("\n\n");
System.out.println(ReportRepository);
System.out.println("\n\n");
return this.reportRepository.findAll();
}
@PostMapping("/Report")
public Report addReport(@RequestBody Report report) {
return this.reportRepository.save(report);
}
@PostMapping("/Report/{id}")
public Report updateProject(@PathVariable Long id, String reportContent) {
Optional<Report> report = this.reportRepository.findById(id);
if (report.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas");
}
if (reportContent != null) {
report.get().setReportContent(reportContent);
}
return this.reportRepository.save(report.get());
}
*/
}

View File

@ -1,62 +0,0 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.repository.SectionCellRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.Optional;
@RestController
public class SectionCellController {
@Autowired SectionCellRepository sectionCellRepository;
@GetMapping("/SectionCell")
@ResponseBody
public Iterable<SectionCell> allSectionCells() {
return this.sectionCellRepository.findAll();
}
@GetMapping("/SectionCell/{id}")
public SectionCell getSectionCellById(@PathVariable Long id) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
return sectionCell.get();
}
@PostMapping("/SectionCell")
public SectionCell addSectionCell(@RequestBody SectionCell sectionCell) {
return this.sectionCellRepository.save(sectionCell);
}
@PostMapping("/SectionCell/{id}")
public SectionCell updateSectionCell(
@PathVariable Long id,
String title,
String contentSectionCell,
LocalDateTime modificationDate) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (title != null) {
sectionCell.get().setTitle(title);
}
if (contentSectionCell != null) {
sectionCell.get().setContentSectionCell(contentSectionCell);
}
if (modificationDate != null) {
sectionCell.get().setModificationDate(modificationDate);
}
return this.sectionCellRepository.save(sectionCell.get());
}
}

View File

@ -1,8 +1,8 @@
spring.application.name=myinpulse spring.application.name=myinpulse
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test
logging.level.org.springframework.security=DEBUG
spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB} spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB}
spring.datasource.username=${BACKEND_USER} spring.datasource.username=${BACKEND_USER}
spring.datasource.password=${BACKEND_PASSWORD} spring.datasource.password=${BACKEND_PASSWORD}
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n

View File

@ -1,2 +1,2 @@
DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE;
DROP TABLE IF EXISTS administrator, project, user_inpulse, entrepreneur, section_cell, appointment, make_appointment, report, annotation, concern CASCADE; DROP TABLE IF EXISTS administrator, project, user_inpulse, entrepreneur, section_cell, appointment, make_appointment, report, annotation, concern CASCADE;

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,224 @@
package enseirb.myinpulse;
import static enseirb.myinpulse.model.ProjectDecisionValue.*;
import static org.junit.jupiter.api.Assertions.*;
import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.ProjectDecision;
import enseirb.myinpulse.service.AdminApiService;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
@Transactional
public class AdminApiServiceTest {
private static long administratorid;
private static Administrator administrator;
private static Entrepreneur entrepreneur;
@Autowired private AdminApiService adminApiService;
@Autowired private ProjectService projectService;
@BeforeAll
static void setup(
@Autowired AdministratorService administratorService,
@Autowired ProjectService projectService,
@Autowired EntrepreneurService entrepreneurService) {
administratorService.addAdministrator(
new Administrator(
"admin",
"admin",
"testAdminEmpty@example.com",
"testAdmin@example.com",
""));
administrator =
administratorService.addAdministrator(
new Administrator(
"admin2",
"admin2",
"testAdminFull@example.com",
"testAdmin@example.com",
""));
administratorid = administrator.getIdUser();
entrepreneur =
new Entrepreneur(
"JeSuisUnEntrepreneurDeCompet",
"EtUé",
"Entrepreneur@inpulse.com",
"mail2",
"phone",
"Ensimag nan jdeconne ENSEIRB (-matmeca mais on s'en fout)",
"info ofc",
false);
entrepreneurService.addEntrepreneur(entrepreneur);
projectService.addNewProject(
new Project(
"sampleProjectAdminApiService",
null,
LocalDate.now(),
ACTIVE,
administratorService.getAdministratorByPrimaryMain(
"testAdminFull@example.com")));
}
private <T> List<T> IterableToList(Iterable<T> iterable) {
List<T> l = new ArrayList<>();
iterable.forEach(l::add);
return l;
}
@Test
void getProjectOfAdminIsEmpty() {
Iterable<Project> projects =
adminApiService.getProjectsOfAdmin("testAdminEmpty@example.com");
assertEquals(0, IterableToList(projects).size());
}
@Test
void getProjectOfInexistantAdminFails() {
String nonExistentAdminEmail = "testInexistantAdmin@example.com";
assertThrows(
ResponseStatusException.class,
() -> {
adminApiService.getProjectsOfAdmin(nonExistentAdminEmail);
});
}
@Test
void getProjectOfAdminNotEmpty() {
Iterable<Project> projects =
adminApiService.getProjectsOfAdmin("testAdminFull@example.com");
List<Project> l = IterableToList(projects);
assertEquals(1, l.size());
Project p = l.getFirst();
assertEquals(p.getProjectName(), "sampleProjectAdminApiService");
}
@Test
void getPendingProjectsEmpty() {
assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size());
}
@Test
void getPendingProjectsNotEmpty() {
this.projectService.addNewProject(
new Project(
"PendingProjectAdminApiService1", null, LocalDate.now(), PENDING, null));
this.projectService.addNewProject(
new Project(
"PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null));
Iterable<Project> pendingProjects = this.adminApiService.getPendingProjects();
List<Project> pendingProjectsList = IterableToList(pendingProjects);
assertEquals(2, pendingProjectsList.size());
assertTrue(
List.of("PendingProjectAdminApiService1", "PendingProjectAdminApiService2")
.contains(pendingProjectsList.getFirst().getProjectName()));
assertTrue(
List.of("PendingProjectAdminApiService1", "PendingProjectAdminApiService2")
.contains(pendingProjectsList.getLast().getProjectName()));
}
@Test
void validateInexistantProject() {
ProjectDecision d = new ProjectDecision(-1, 0, 1);
assertThrows(ResponseStatusException.class, () -> this.adminApiService.validateProject(d));
}
@Test
void validateExistantProject() {
Project p =
new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null);
this.projectService.addNewProject(p);
assertEquals(PENDING, p.getProjectStatus());
ProjectDecision d = new ProjectDecision(p.getIdProject(), administratorid, 1);
this.adminApiService.validateProject(d);
assertEquals(ACTIVE, p.getProjectStatus());
// Check if the project was really updated in the database
assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size());
}
@Test
void refuseExistantProject() {
Project p =
new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null);
this.projectService.addNewProject(p);
assertEquals(PENDING, p.getProjectStatus());
ProjectDecision d = new ProjectDecision(p.getIdProject(), administratorid, 0);
this.adminApiService.validateProject(d);
assertEquals(REJECTED, p.getProjectStatus());
// Check if the project was really updated in the database
assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size());
}
@Test
void addProject() {
assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size());
Project p1 =
new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null);
this.adminApiService.addNewProject(p1);
assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size());
}
@Test
void addProjectToAdmin() {
assertEquals(0, administrator.getListProject().size());
Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, administrator);
this.adminApiService.addNewProject(p1);
assertEquals(1, administrator.getListProject().size());
}
@Test
void addProjectToUser() {
assertNull(entrepreneur.getProjectParticipation());
Project p1 =
new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, entrepreneur);
this.adminApiService.addNewProject(p1);
assertEquals(p1, entrepreneur.getProjectParticipation());
}
@Test
void addProjectWithManyUsers() {
Entrepreneur e1 = new Entrepreneur();
Entrepreneur e2 = new Entrepreneur();
Entrepreneur e3 = new Entrepreneur();
assertNull(e1.getProjectParticipation());
assertNull(e2.getProjectParticipation());
assertNull(e3.getProjectParticipation());
Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, null);
p1.updateListEntrepreneurParticipation(e1);
p1.updateListEntrepreneurParticipation(e2);
p1.updateListEntrepreneurParticipation(e3);
this.adminApiService.addNewProject(p1);
assertEquals(p1, e1.getProjectParticipation());
assertEquals(p1, e2.getProjectParticipation());
assertEquals(p1, e3.getProjectParticipation());
}
@Test
void addDuplicateProject() {
Project p1 =
new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null);
Project p2 =
new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null);
this.adminApiService.addNewProject(p1);
assertThrows(ResponseStatusException.class, () -> this.adminApiService.addNewProject(p2));
}
}

View File

@ -1,5 +1,6 @@
package enseirb.myinpulse; package enseirb.myinpulse;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -7,5 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
class MyinpulseApplicationTests { class MyinpulseApplicationTests {
@Test @Test
@DisplayName("contextLoad => Test if the context can load, i.e. the application can start")
void contextLoads() {} void contextLoads() {}
} }

View File

@ -0,0 +1,10 @@
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa
spring.sql.init.mode=never
spring.application.name=myinpulse-test
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test
spring.jpa.hibernate.ddl-auto=update
logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n

22
config/.env.dev Normal file
View File

@ -0,0 +1,22 @@
POSTGRES_DB=postgres_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres_db_user_password
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=admin
KEYCLOAK_HOSTNAME=localhost
KEYCLOAK_DB=keycloak_db
KEYCLOAK_USER=keycloak_db_user
KEYCLOAK_PASSWORD=keycloak_db_user_password
BACKEND_DB=backend_db
BACKEND_USER=backend_db_user
BACKEND_PASSWORD=backend_db_user_password
DATABASE_URL=localhost:5433
VITE_KEYCLOAK_URL=http://localhost:7080
VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev
VITE_KEYCLOAK_REALM=test
VITE_APP_URL=http://localhost:5173
VITE_BACKEND_URL=http://localhost:8081/

12
documentation/Doc.txt Normal file
View File

@ -0,0 +1,12 @@
Format des comptes rendus de réunion :
Texte organisé par bullet point, chaque bullet point est séparé par "//" pour pouvoir être correctement généré.
Exemple :
Le texte "// blablabla // oui bonjour"
donne le résultat
Point n°1 :
blablabla
Point n°2 :
oui bonjour

2
hooks/README.md Normal file
View File

@ -0,0 +1,2 @@
# Useful hooks in this project
To use, just add the content of the wanted hook in `.git/hook/pre-commit`. You may need to use `chmod +x pre-commit`

24
hooks/google-java-format Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Path to the Google Java Formatter JAR
FORMATTER_JAR="$HOME/.local/share/java/google-java-format.jar"
# Download the Google Java Formatter JAR if it doesn't exist
if [ ! -f "$FORMATTER_JAR" ]; then
echo "Downloading Google Java Formatter..."
mkdir -p "$(dirname "$FORMATTER_JAR")"
curl -L -o "$FORMATTER_JAR" https://github.com/google/google-java-format/releases/download/v1.20.0/google-java-format-1.20.0-all-deps.jar
fi
# Format all staged Java files
STAGED_JAVA_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "\.java$")
if [ -n "$STAGED_JAVA_FILES" ]; then
echo "Formatting Java files..."
java -jar "$FORMATTER_JAR" --skip-sorting-imports --skip-reflowing-long-strings --aosp --replace $STAGED_JAVA_FILES
# Re-stage the formatted files
git add $STAGED_JAVA_FILES
fi
exit 0