Compare commits
58 Commits
e66fa33577
...
fix_cache
Author | SHA1 | Date | |
---|---|---|---|
801ecb3817 | |||
cc89d4c79f | |||
adf9a93e2e | |||
37d8bcc719 | |||
ead11215ba | |||
137bc84c21 | |||
3c61fdca93 | |||
5ee3755548 | |||
52511dd4c4 | |||
84b70f8f38 | |||
834d68949c | |||
fea8687664 | |||
c94d3654ce | |||
d5c89bf8f4 | |||
78c72bdd72 | |||
307c7e700b | |||
8d486dce89 | |||
653f923693 | |||
64da3c9ab0 | |||
419ceec1bc | |||
e011a5534e | |||
ef964c4d35 | |||
5608b12f84 | |||
467babab79 | |||
a2e2395cc2 | |||
e3393c8834 | |||
5f8fe4a374 | |||
c5e7736a16 | |||
04589392cb | |||
1106cf8478 | |||
215d80ad70 | |||
dded62c25a | |||
3de7ebe2b1 | |||
8153496a0f | |||
861e7495a7 | |||
d78e43f7e0 | |||
3ca97cf378 | |||
e6a8d98d63 | |||
8894fea6d4 | |||
236bb0d167 | |||
d4dcc95d9b | |||
dc843299eb | |||
f3eaf8fe34 | |||
628c61fb8b | |||
4880f3829c | |||
80b2d087e4 | |||
b5c03798fc | |||
1d970ce5f5 | |||
f9de5ed6bf | |||
e75a5c9d2c | |||
5c3b2b138d | |||
8d4dc7916d | |||
1a6db7c953 | |||
3890aed158 | |||
dd5ca2cbd7 | |||
024deeba41 | |||
1cebebf1a5 | |||
d8bc7cc9b6 |
@ -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"
|
||||||
|
33
.gitea/workflows/build-back.yaml
Normal file
33
.gitea/workflows/build-back.yaml
Normal 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
|
24
Makefile
24
Makefile
@ -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
|
||||||
|
@ -1,33 +1,59 @@
|
|||||||
plugins {
|
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'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion = JavaLanguageVersion.of(21)
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
|
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
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 'org.postgresql:postgresql'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
implementation 'org.postgresql:postgresql'
|
||||||
|
implementation group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.3'
|
||||||
|
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
testImplementation 'com.h2database:h2'
|
||||||
|
|
||||||
|
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')
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ public class AdminApi {
|
|||||||
* @return a list of all project managed by the current admin user
|
* @return a list of all project managed by the current admin user
|
||||||
*/
|
*/
|
||||||
@GetMapping("/admin/projects")
|
@GetMapping("/admin/projects")
|
||||||
public Iterable<Administrator> getProjects() {
|
public Iterable<Project> getProjects(@AuthenticationPrincipal Jwt principal) {
|
||||||
return adminApiService.getProjects();
|
return adminApiService.getProjectsOfAdmin(principal.getClaimAsString("email"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ public class AdminApi {
|
|||||||
/**
|
/**
|
||||||
* Endpoint used to make a decision about a project.
|
* Endpoint used to make a decision about a project.
|
||||||
*
|
*
|
||||||
* <p>The decision must contains the administrator
|
* <p>The decision must contain the administrator
|
||||||
*
|
*
|
||||||
* @return the status code of the request
|
* @return the status code of the request
|
||||||
*/
|
*/
|
||||||
@ -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(
|
||||||
@ -96,7 +96,7 @@ public class AdminApi {
|
|||||||
* @return the status code of the request
|
* @return the status code of the request
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/admin/projects/remove/{projectId}")
|
@DeleteMapping("/admin/projects/remove/{projectId}")
|
||||||
public void deleteProject(@PathVariable String projectId) {
|
public void deleteProject(@PathVariable long projectId) {
|
||||||
adminApiService.deleteProject(projectId);
|
adminApiService.deleteProject(projectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package enseirb.myinpulse.model;
|
|
||||||
|
|
||||||
public class DelAppointment {
|
|
||||||
int validated;
|
|
||||||
int[] akserId;
|
|
||||||
int[] destId;
|
|
||||||
String date; // TODO: date type ?
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package enseirb.myinpulse.model;
|
|
||||||
|
|
||||||
public class DelProject {
|
|
||||||
int projectId;
|
|
||||||
String projectName;
|
|
||||||
String projectDescription;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package enseirb.myinpulse.model;
|
|
||||||
|
|
||||||
public class DelReport {
|
|
||||||
int projectId;
|
|
||||||
String reportContent;
|
|
||||||
}
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {}
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -11,8 +10,13 @@ import java.util.List;
|
|||||||
@Table(name = "project")
|
@Table(name = "project")
|
||||||
public class Project {
|
public class Project {
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
|
private final List<Entrepreneur> listEntrepreneurParticipation = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
|
private final List<SectionCell> listSectionCell = new ArrayList<>();
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@NotNull
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long idProject;
|
private Long idProject;
|
||||||
|
|
||||||
@ -20,38 +24,46 @@ public class Project {
|
|||||||
private String projectName;
|
private String projectName;
|
||||||
|
|
||||||
private byte[] logo;
|
private byte[] logo;
|
||||||
|
|
||||||
private LocalDate creationDate;
|
private LocalDate creationDate;
|
||||||
|
|
||||||
@Column(length = 255)
|
@Column private ProjectDecisionValue projectStatus;
|
||||||
private String projectStatus;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "idAdministrator")
|
@JoinColumn(name = "idAdministrator")
|
||||||
private Administrator projectAdministrator;
|
private Administrator projectAdministrator;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true)
|
|
||||||
private List<Entrepreneur> listEntrepreneurParticipation = new ArrayList<>();
|
|
||||||
|
|
||||||
@OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true)
|
@OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true)
|
||||||
private Entrepreneur entrepreneurProposed;
|
private Entrepreneur entrepreneurProposed;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true)
|
|
||||||
private List<SectionCell> listSectionCell = new ArrayList<>();
|
|
||||||
|
|
||||||
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() {
|
||||||
@ -86,11 +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 List<Entrepreneur> getListEntrepreneurParticipation() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
package enseirb.myinpulse.model;
|
package enseirb.myinpulse.model;
|
||||||
|
|
||||||
public class ProjectDecision {
|
public class ProjectDecision {
|
||||||
int projectId;
|
public long projectId;
|
||||||
int adminId;
|
public long adminId;
|
||||||
int 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
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package enseirb.myinpulse.model;
|
||||||
|
|
||||||
|
public enum ProjectDecisionValue {
|
||||||
|
PENDING,
|
||||||
|
ACTIVE,
|
||||||
|
ENDED,
|
||||||
|
ABORTED,
|
||||||
|
REJECTED,
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ public class User {
|
|||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
@Column(length = 255)
|
@Column(length = 255)
|
||||||
private String mainMail;
|
private String primaryMail;
|
||||||
|
|
||||||
@Column(length = 255)
|
@Column(length = 255)
|
||||||
private String secondaryMail;
|
private String secondaryMail;
|
||||||
@ -30,17 +28,32 @@ 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,
|
||||||
String userName,
|
String userName,
|
||||||
String mainMail,
|
String primaryMail,
|
||||||
String secondaryMail,
|
String secondaryMail,
|
||||||
String phoneNumber) {
|
String phoneNumber) {
|
||||||
this.idUser = idUser;
|
this.idUser = idUser;
|
||||||
this.userSurname = userSurname;
|
this.userSurname = userSurname;
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.mainMail = mainMail;
|
this.primaryMail = primaryMail;
|
||||||
|
this.secondaryMail = secondaryMail;
|
||||||
|
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.secondaryMail = secondaryMail;
|
||||||
this.phoneNumber = phoneNumber;
|
this.phoneNumber = phoneNumber;
|
||||||
}
|
}
|
||||||
@ -69,12 +82,12 @@ public class User {
|
|||||||
userName = userName;
|
userName = userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMainMail() {
|
public String getPrimaryMail() {
|
||||||
return mainMail;
|
return primaryMail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMainMail(String mainMail) {
|
public void setPrimaryMail(String primaryMail) {
|
||||||
this.mainMail = mainMail;
|
this.primaryMail = primaryMail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSecondaryMail() {
|
public String getSecondaryMail() {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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(); */
|
||||||
|
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
package enseirb.myinpulse.repository;
|
package enseirb.myinpulse.repository;
|
||||||
|
|
||||||
|
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> findByProjectStatus(ProjectDecisionValue status);
|
||||||
|
|
||||||
|
Optional<Project> findByProjectName(String projectName);
|
||||||
|
}
|
||||||
|
@ -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> {}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
@ -5,8 +5,11 @@ import enseirb.myinpulse.model.User;
|
|||||||
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 UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
|
Optional<User> findByPrimaryMail(String email);
|
||||||
|
|
||||||
/* @Query("SELECT u from User u")
|
/* @Query("SELECT u from User u")
|
||||||
User findAllUser(); */
|
User findAllUser(); */
|
||||||
|
@ -1,45 +1,166 @@
|
|||||||
package enseirb.myinpulse.service;
|
package enseirb.myinpulse.service;
|
||||||
|
|
||||||
import enseirb.myinpulse.model.*;
|
import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
|
||||||
|
import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
|
||||||
|
|
||||||
|
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.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AdminApiService {
|
public class AdminApiService {
|
||||||
// TODO
|
|
||||||
public Iterable<Administrator> getProjects() {
|
protected static final Logger logger = LogManager.getLogger();
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AdministratorService administratorService;
|
||||||
|
private final UtilsService utilsService;
|
||||||
|
private final AppointmentService appointmentService;
|
||||||
|
private final ReportService reportService;
|
||||||
|
private final SectionCellService sectionCellService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AdminApiService(
|
||||||
|
ProjectService projectService,
|
||||||
|
UserService userService,
|
||||||
|
AdministratorService administratorService,
|
||||||
|
UtilsService utilsService,
|
||||||
|
AppointmentService appointmentService,
|
||||||
|
ReportService reportService,
|
||||||
|
SectionCellService sectionCellService) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.administratorService = administratorService;
|
||||||
|
this.utilsService = utilsService;
|
||||||
|
this.appointmentService = appointmentService;
|
||||||
|
this.reportService = reportService;
|
||||||
|
this.sectionCellService = sectionCellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO: check if tests are sufficient - peer verification required
|
||||||
public Iterable<Appointment> getUpcomingAppointments(String email) {
|
public Iterable<Project> getProjectsOfAdmin(String mail) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
return projectService.getProjectsByAdminId(
|
||||||
|
administratorService.getAdministratorById(
|
||||||
|
this.userService.getUserByEmail(mail).getIdUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
public Iterable<Appointment> getUpcomingAppointments(String mail) {
|
||||||
|
logger.info("User {} check their upcoming appointments", mail);
|
||||||
|
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: check if tests are sufficient - peer verification required
|
||||||
public Iterable<Project> getPendingProjects() {
|
public Iterable<Project> getPendingProjects() {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
return this.projectService.getPendingProjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO: check if tests are sufficient - peer verification required
|
||||||
public void validateProject(ProjectDecision decision) {
|
public void validateProject(ProjectDecision decision) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
projectService.updateProject(
|
||||||
|
decision.projectId,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
(decision.isAccepted == 1) ? ACTIVE : REJECTED,
|
||||||
|
this.administratorService.getAdministratorById(decision.adminId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO: check if tests are sufficient - peer verification required
|
||||||
public void addNewProject(Project project) {
|
public void addNewProject(Project project) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
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
|
// TODO: test
|
||||||
public void deleteProject(String projectId) {
|
public void deleteProject(long projectId) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
this.projectService.deleteProjectById(projectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package enseirb.myinpulse.service.database;
|
||||||
|
|
||||||
|
import enseirb.myinpulse.model.Administrator;
|
||||||
|
import enseirb.myinpulse.repository.AdministratorRepository;
|
||||||
|
|
||||||
|
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 AdministratorService {
|
||||||
|
protected static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
private final AdministratorRepository administratorRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AdministratorService(AdministratorRepository administratorRepository) {
|
||||||
|
this.administratorRepository = administratorRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Administrator> allAdministrators() {
|
||||||
|
return this.administratorRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Administrator getAdministratorById(long id) {
|
||||||
|
Optional<Administrator> administrator = this.administratorRepository.findById(id);
|
||||||
|
if (administrator.isEmpty()) {
|
||||||
|
logger.error("No administrator found with id {}", id);
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas");
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
return this.administratorRepository.save(administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public Administrator getAdministratorByProject(Project project) {
|
||||||
|
r
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +1,54 @@
|
|||||||
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.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.web.bind.annotation.*;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@Service
|
||||||
public class AppointmentController {
|
public class AppointmentService {
|
||||||
|
|
||||||
@Autowired AppointmentRepository appointmentRepository;
|
private static final Logger logger = LogManager.getLogger(AppointmentService.class);
|
||||||
|
|
||||||
@GetMapping("/Appointment")
|
private AppointmentRepository appointmentRepository;
|
||||||
@ResponseBody
|
|
||||||
public Iterable<Appointment> allAppointments() {
|
@Autowired
|
||||||
|
AppointmentService(AppointmentRepository appointmentRepository) {
|
||||||
|
this.appointmentRepository = appointmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Appointment> getallAppointments() {
|
||||||
return this.appointmentRepository.findAll();
|
return this.appointmentRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/Appointment/{id}")
|
public Appointment getAppointmentById(Long id) {
|
||||||
public Appointment getAppointmentById(@PathVariable Long id) {
|
|
||||||
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
|
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
|
||||||
if (appointment.isEmpty()) {
|
if (appointment.isEmpty()) {
|
||||||
|
logger.error("getAppointmentById : No appointment found with id {}", id);
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
||||||
}
|
}
|
||||||
return appointment.get();
|
return appointment.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Appointment")
|
public Appointment addNewAppointment(Appointment appointment) {
|
||||||
public Appointment addAppointment(@RequestBody Appointment appointment) {
|
|
||||||
return this.appointmentRepository.save(appointment);
|
return this.appointmentRepository.save(appointment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/Appointment/{id}")
|
public void deleteAppointmentById(Long id) {
|
||||||
|
this.appointmentRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Appointment updateAppointment(
|
public Appointment updateAppointment(
|
||||||
@PathVariable Long id,
|
Long id,
|
||||||
LocalDate appointmentDate,
|
LocalDate appointmentDate,
|
||||||
LocalTime appointmentTime,
|
LocalTime appointmentTime,
|
||||||
LocalTime appointmentDuration,
|
LocalTime appointmentDuration,
|
||||||
@ -47,6 +56,7 @@ public class AppointmentController {
|
|||||||
String appointmentSubject) {
|
String appointmentSubject) {
|
||||||
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
|
Optional<Appointment> appointment = this.appointmentRepository.findById(id);
|
||||||
if (appointment.isEmpty()) {
|
if (appointment.isEmpty()) {
|
||||||
|
logger.error("updateAppointment : No appointment found with id {}", id);
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas");
|
||||||
}
|
}
|
||||||
if (appointmentDate != null) {
|
if (appointmentDate != null) {
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,19 +1,28 @@
|
|||||||
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.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.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.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProjectService {
|
public class ProjectService {
|
||||||
|
|
||||||
|
protected static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -25,15 +34,19 @@ public class ProjectService {
|
|||||||
return this.projectRepository.findAll();
|
return this.projectRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: change error
|
|
||||||
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()) {
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<Project> getProjectsByAdminId(Administrator administrator) {
|
||||||
|
return this.projectRepository.findByProjectAdministrator(administrator);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: validation
|
// TODO: validation
|
||||||
public Project addNewProject(Project project) {
|
public Project addNewProject(Project project) {
|
||||||
return this.projectRepository.save(project);
|
return this.projectRepository.save(project);
|
||||||
@ -44,23 +57,68 @@ public class ProjectService {
|
|||||||
String projectName,
|
String projectName,
|
||||||
byte[] logo,
|
byte[] logo,
|
||||||
LocalDate creationDate,
|
LocalDate creationDate,
|
||||||
String projectStatus) {
|
ProjectDecisionValue projectStatus,
|
||||||
|
Administrator administrator) {
|
||||||
Optional<Project> project = this.projectRepository.findById(id);
|
Optional<Project> project = this.projectRepository.findById(id);
|
||||||
|
|
||||||
if (project.isEmpty()) {
|
if (project.isEmpty()) {
|
||||||
|
logger.error("Project with id {} not found.", id);
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectName != null) {
|
if (projectName != null) {
|
||||||
project.get().setProjectName(projectName);
|
project.get().setProjectName(projectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logo != null) {
|
if (logo != null) {
|
||||||
project.get().setLogo(logo);
|
project.get().setLogo(logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (creationDate != null) {
|
if (creationDate != null) {
|
||||||
project.get().setCreationDate(creationDate);
|
project.get().setCreationDate(creationDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectStatus != null) {
|
if (projectStatus != null) {
|
||||||
|
// TODO: check if this is really useful
|
||||||
|
/*
|
||||||
|
if (!validateStatus(projectStatus)) {
|
||||||
|
logger.error("updateProjectStatus: Invalid status {}", projectStatus);
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté");
|
||||||
|
}
|
||||||
|
*/
|
||||||
project.get().setProjectStatus(projectStatus);
|
project.get().setProjectStatus(projectStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (administrator != null) {
|
||||||
|
project.get().setProjectAdministrator(administrator);
|
||||||
|
}
|
||||||
|
|
||||||
return this.projectRepository.save(project.get());
|
return this.projectRepository.save(project.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean validateStatus(String status) {
|
||||||
|
return List.of("PENDING", "ACTIVE", "ENDED").contains(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Project> getPendingProjects() {
|
||||||
|
return this.projectRepository.findByProjectStatus(PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteProjectById(Long 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +1,64 @@
|
|||||||
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
|
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.web.bind.annotation.*;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@Service
|
||||||
public class UserController {
|
public class UserService {
|
||||||
|
|
||||||
@Autowired UserRepository userRepository;
|
protected static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UserService(UserRepository userRepository) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<User> getAllUsers() {
|
||||||
|
return this.userRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
public User getUserByEmail(String email) {
|
||||||
|
Optional<User> opt_user = this.userRepository.findByPrimaryMail(email);
|
||||||
|
|
||||||
|
if (opt_user.isEmpty()) {
|
||||||
|
logger.error("getUserByEmail : No user found with email {}", email);
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
|
||||||
|
}
|
||||||
|
return opt_user.get();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/User")
|
|
||||||
@ResponseBody
|
|
||||||
public Iterable<User> allUsers() {
|
public Iterable<User> allUsers() {
|
||||||
return this.userRepository.findAll();
|
return this.userRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/User/{id}")
|
|
||||||
public User getUserById(@PathVariable Long id) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
if (user.isEmpty()) {
|
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas");
|
|
||||||
}
|
|
||||||
return user.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/User")
|
|
||||||
public User addUser(@RequestBody User user) {
|
public User addUser(@RequestBody User user) {
|
||||||
return this.userRepository.save(user);
|
return this.userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/User/{id}")
|
|
||||||
public User updateUser(
|
public User updateUser(
|
||||||
@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) {
|
||||||
@ -53,8 +67,8 @@ public class UserController {
|
|||||||
if (userSurname != null) {
|
if (userSurname != null) {
|
||||||
user.get().setUserSurname(userSurname);
|
user.get().setUserSurname(userSurname);
|
||||||
}
|
}
|
||||||
if (mainMail != null) {
|
if (primaryMail != null) {
|
||||||
user.get().setMainMail(mainMail);
|
user.get().setPrimaryMail(primaryMail);
|
||||||
}
|
}
|
||||||
if (secondaryMail != null) {
|
if (secondaryMail != null) {
|
||||||
user.get().setSecondaryMail(secondaryMail);
|
user.get().setSecondaryMail(secondaryMail);
|
@ -1,38 +0,0 @@
|
|||||||
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
|
|
||||||
|
|
||||||
import enseirb.myinpulse.model.Administrator;
|
|
||||||
import enseirb.myinpulse.repository.AdministratorRepository;
|
|
||||||
|
|
||||||
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.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class AdministratorController {
|
|
||||||
|
|
||||||
@Autowired AdministratorRepository administratorRepository;
|
|
||||||
|
|
||||||
@GetMapping("/Administrator")
|
|
||||||
@ResponseBody
|
|
||||||
public Iterable<Administrator> allAdministrators() {
|
|
||||||
return this.administratorRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/Administrator/{id}")
|
|
||||||
public Administrator getAdministratorById(@PathVariable Long id) {
|
|
||||||
Optional<Administrator> administrator = this.administratorRepository.findById(id);
|
|
||||||
if (administrator.isEmpty()) {
|
|
||||||
throw new ResponseStatusException(
|
|
||||||
HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas");
|
|
||||||
}
|
|
||||||
return administrator.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/Administrateurs")
|
|
||||||
public Administrator addAdministrator(@RequestBody Administrator administrator) {
|
|
||||||
return this.administratorRepository.save(administrator);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
@ -8,7 +8,7 @@ SELECT setval('report_id_report_seq', 1, false);
|
|||||||
SELECT setval('section_cell_id_section_cell_seq', 1, false);
|
SELECT setval('section_cell_id_section_cell_seq', 1, false);
|
||||||
SELECT setval('user_inpulse_id_user_seq', 1, false);
|
SELECT setval('user_inpulse_id_user_seq', 1, false);
|
||||||
|
|
||||||
INSERT INTO user_inpulse (user_surname, user_name, main_mail, secondary_mail, phone_number)
|
INSERT INTO user_inpulse (user_surname, user_name, primary_mail, secondary_mail, phone_number)
|
||||||
VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'),
|
VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'),
|
||||||
('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'),
|
('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'),
|
||||||
('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'),
|
('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'),
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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() {}
|
||||||
}
|
}
|
||||||
|
10
MyINPulse-back/src/test/resources/application.properties
Normal file
10
MyINPulse-back/src/test/resources/application.properties
Normal 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
22
config/.env.dev
Normal 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
12
documentation/Doc.txt
Normal 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
2
hooks/README.md
Normal 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
24
hooks/google-java-format
Executable 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
|
Reference in New Issue
Block a user