fix: more tests working, still need fixes
This commit is contained in:
parent
55112c8508
commit
6029457735
@ -2,6 +2,9 @@ package enseirb.myinpulse.model;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Generated;
|
||||||
|
import org.hibernate.generator.EventType;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,6 +23,10 @@ public class SectionCell {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long idSectionCell;
|
private Long idSectionCell;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "serial")
|
||||||
|
@Generated(event = EventType.INSERT)
|
||||||
|
private Long idReference;
|
||||||
|
|
||||||
@Column() private long sectionId;
|
@Column() private long sectionId;
|
||||||
private String contentSectionCell;
|
private String contentSectionCell;
|
||||||
|
|
||||||
@ -56,6 +63,14 @@ public class SectionCell {
|
|||||||
this.idSectionCell = idSectionCell;
|
this.idSectionCell = idSectionCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getIdReference() {
|
||||||
|
return idReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdReference(Long idReference) {
|
||||||
|
this.idReference = idReference;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getSectionId() {
|
public Long getSectionId() {
|
||||||
return sectionId;
|
return sectionId;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ 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.LocalDateTime;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EntrepreneurApiService {
|
public class EntrepreneurApiService {
|
||||||
|
|
||||||
@ -64,7 +66,28 @@ public class EntrepreneurApiService {
|
|||||||
mail,
|
mail,
|
||||||
sectionCellId,
|
sectionCellId,
|
||||||
this.sectionCellService.getProjectId(sectionCellId));
|
this.sectionCellService.getProjectId(sectionCellId));
|
||||||
sectionCellService.updateSectionCell(sectionCellId, content, null, null, null);
|
SectionCell newSectionCell =
|
||||||
|
new SectionCell(
|
||||||
|
null,
|
||||||
|
sectionCell.getSectionId(),
|
||||||
|
content,
|
||||||
|
LocalDateTime.now(),
|
||||||
|
sectionCell.getProjectSectionCell());
|
||||||
|
newSectionCell.setIdReference(sectionCell.getIdReference());
|
||||||
|
sectionCell
|
||||||
|
.getAppointmentSectionCell()
|
||||||
|
.forEach(
|
||||||
|
appointment -> {
|
||||||
|
newSectionCell.updateAppointmentSectionCell(appointment);
|
||||||
|
});
|
||||||
|
sectionCell
|
||||||
|
.getListAnnotation()
|
||||||
|
.forEach(
|
||||||
|
annotation -> {
|
||||||
|
newSectionCell.updateListAnnotation(annotation);
|
||||||
|
});
|
||||||
|
this.addSectionCell(newSectionCell, mail);
|
||||||
|
// sectionCellService.updateSectionCell(sectionCellId, content, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSectionCell(Long sectionCellId, String mail) {
|
public void removeSectionCell(Long sectionCellId, String mail) {
|
||||||
@ -89,7 +112,12 @@ public class EntrepreneurApiService {
|
|||||||
mail,
|
mail,
|
||||||
sectionCellId,
|
sectionCellId,
|
||||||
this.sectionCellService.getProjectId(sectionCellId));
|
this.sectionCellService.getProjectId(sectionCellId));
|
||||||
sectionCellService.removeSectionCellById(sectionCellId);
|
SectionCell removedSectionCell = new SectionCell(null, -1L, "", LocalDateTime.now(), null);
|
||||||
|
removedSectionCell.setIdReference(editSectionCell.getIdReference());
|
||||||
|
sectionCellService.addNewSectionCell(removedSectionCell);
|
||||||
|
projectService.updateProjectListSectionCell(
|
||||||
|
sectionCellService.getProjectId(sectionCellId), removedSectionCell);
|
||||||
|
// sectionCellService.removeSectionCellById(sectionCellId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSectionCell(SectionCell sectionCell, String mail) {
|
public void addSectionCell(SectionCell sectionCell, String mail) {
|
||||||
@ -98,6 +126,11 @@ public class EntrepreneurApiService {
|
|||||||
throw new ResponseStatusException(
|
throw new ResponseStatusException(
|
||||||
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
|
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
|
||||||
}
|
}
|
||||||
|
if (sectionCell.getSectionId() == -1) {
|
||||||
|
System.err.println("Trying to create an illegal section cell");
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_REQUEST, "La cellule de section fournie n'est pas valide");
|
||||||
|
}
|
||||||
if (!utilsService.isAllowedToCheckProject(
|
if (!utilsService.isAllowedToCheckProject(
|
||||||
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
|
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
@ -112,7 +145,9 @@ public class EntrepreneurApiService {
|
|||||||
mail,
|
mail,
|
||||||
sectionCell.getIdSectionCell(),
|
sectionCell.getIdSectionCell(),
|
||||||
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
|
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
|
||||||
SectionCell newSectionCell = sectionCellService.addNewSectionCell(sectionCell);
|
SectionCell newSectionCell =
|
||||||
|
sectionCellService.addNewSectionCell(
|
||||||
|
sectionCell); // if here, logger fails cause id is null (not added yet)
|
||||||
newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell);
|
newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell);
|
||||||
newSectionCell
|
newSectionCell
|
||||||
.getAppointmentSectionCell()
|
.getAppointmentSectionCell()
|
||||||
@ -135,7 +170,14 @@ public class EntrepreneurApiService {
|
|||||||
}
|
}
|
||||||
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
|
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
|
||||||
project.setProjectStatus(PENDING);
|
project.setProjectStatus(PENDING);
|
||||||
|
project.setEntrepreneurProposed((Entrepreneur) this.userService.getUserByEmail(mail));
|
||||||
projectService.addNewProject(project);
|
projectService.addNewProject(project);
|
||||||
|
project.getProjectAdministrator().updateListProject(project);
|
||||||
|
project.getEntrepreneurProposed().setProjectProposed(project);
|
||||||
|
project.getListEntrepreneurParticipation()
|
||||||
|
.forEach(entrepreneur -> entrepreneur.setProjectParticipation(project));
|
||||||
|
project.getListSectionCell()
|
||||||
|
.forEach(sectionCell -> sectionCell.setProjectSectionCell(project));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAccount(Entrepreneur e) {
|
public void createAccount(Entrepreneur e) {
|
||||||
|
@ -25,6 +25,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SharedApiService {
|
public class SharedApiService {
|
||||||
@ -73,6 +74,45 @@ public class SharedApiService {
|
|||||||
project, sectionId, dateTime);
|
project, sectionId, dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve all up to date (for every sectionId) sectionCells of a project
|
||||||
|
public Iterable<SectionCell> getAllSectionCells(long projectId, 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
Project project = this.projectService.getProjectById(projectId);
|
||||||
|
List<SectionCell> allSectionCells = new ArrayList<SectionCell>();
|
||||||
|
project.getListSectionCell()
|
||||||
|
.forEach(
|
||||||
|
projectCell -> {
|
||||||
|
AtomicBoolean sameReferenceId =
|
||||||
|
new AtomicBoolean(false); // side effect lambdas
|
||||||
|
allSectionCells.forEach(
|
||||||
|
selectedCell -> {
|
||||||
|
if (projectCell
|
||||||
|
.getIdReference()
|
||||||
|
.equals(selectedCell.getIdReference())) {
|
||||||
|
sameReferenceId.set(true);
|
||||||
|
if (projectCell
|
||||||
|
.getModificationDate()
|
||||||
|
.isAfter(selectedCell.getModificationDate())) {
|
||||||
|
allSectionCells.remove(selectedCell);
|
||||||
|
allSectionCells.add(projectCell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!sameReferenceId.get()) {
|
||||||
|
allSectionCells.add(projectCell);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return allSectionCells;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
|
public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
|
||||||
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||||
|
@ -62,11 +62,7 @@ public class EntrepreneurService {
|
|||||||
|
|
||||||
public void updateEntrepreneurProjectParticipation(
|
public void updateEntrepreneurProjectParticipation(
|
||||||
long idEntrepreneur, Project projectParticipation) {
|
long idEntrepreneur, Project projectParticipation) {
|
||||||
System.out.println("expected");
|
|
||||||
System.out.println(getEntrepreneurById(idEntrepreneur));
|
|
||||||
Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur);
|
Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur);
|
||||||
System.out.println("test");
|
|
||||||
System.out.println(entrepreneur);
|
|
||||||
entrepreneur.setProjectParticipation(projectParticipation);
|
entrepreneur.setProjectParticipation(projectParticipation);
|
||||||
this.entrepreneurRepository.save(entrepreneur);
|
this.entrepreneurRepository.save(entrepreneur);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,12 @@ public class SectionCellService {
|
|||||||
this.sectionCellRepository.deleteById(id);
|
this.sectionCellRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateSectionCellReferenceId(Long idSectionCell, Long referenceId) {
|
||||||
|
SectionCell sectionCell = this.getSectionCellById(idSectionCell);
|
||||||
|
sectionCell.setIdReference(referenceId);
|
||||||
|
this.sectionCellRepository.save(sectionCell);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateSectionCellContent(long idSectionCell, String content) {
|
public void updateSectionCellContent(long idSectionCell, String content) {
|
||||||
SectionCell sectionCell = getSectionCellById(idSectionCell);
|
SectionCell sectionCell = getSectionCellById(idSectionCell);
|
||||||
sectionCell.setContentSectionCell(content);
|
sectionCell.setContentSectionCell(content);
|
||||||
|
@ -65,15 +65,9 @@ public class EntrepreneurApiServiceTest {
|
|||||||
project =
|
project =
|
||||||
projectService.addNewProject(
|
projectService.addNewProject(
|
||||||
new Project("Project", null, LocalDate.now(), ACTIVE, null, entrepreneur));
|
new Project("Project", null, LocalDate.now(), ACTIVE, null, entrepreneur));
|
||||||
// projectService.updateProjectEntrepreneurParticipation(project.getIdProject(),
|
|
||||||
// entrepreneur); proxy error because why not
|
|
||||||
entrepreneurService.updateEntrepreneurProjectProposed(entrepreneur.getIdUser(), project);
|
entrepreneurService.updateEntrepreneurProjectProposed(entrepreneur.getIdUser(), project);
|
||||||
entrepreneurService.updateEntrepreneurProjectParticipation(
|
entrepreneurService.updateEntrepreneurProjectParticipation(
|
||||||
entrepreneur.getIdUser(), project);
|
entrepreneur.getIdUser(), project);
|
||||||
System.out.println(("real"));
|
|
||||||
System.out.println(entrepreneur);
|
|
||||||
// System.out.println(entrepreneur.getProjectProposed());
|
|
||||||
// System.out.println(entrepreneur.getProjectParticipation());
|
|
||||||
SectionCell s1 =
|
SectionCell s1 =
|
||||||
sectionCellService.addNewSectionCell(
|
sectionCellService.addNewSectionCell(
|
||||||
new SectionCell(
|
new SectionCell(
|
||||||
@ -88,7 +82,7 @@ public class EntrepreneurApiServiceTest {
|
|||||||
new SectionCell(
|
new SectionCell(
|
||||||
null,
|
null,
|
||||||
3L,
|
3L,
|
||||||
"contenu très intéressant",
|
"contenu très intéressant2",
|
||||||
LocalDateTime.now(),
|
LocalDateTime.now(),
|
||||||
project));
|
project));
|
||||||
sectionCells2 = sectionCellService.getSectionCellsByProject(project, 2L);
|
sectionCells2 = sectionCellService.getSectionCellsByProject(project, 2L);
|
||||||
@ -104,13 +98,15 @@ public class EntrepreneurApiServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void editValidSectionCell() {
|
void editValidSectionCell() {
|
||||||
entrepreneurApiService.editSectionCell(
|
entrepreneurApiService.editSectionCell(
|
||||||
IterableToList(sectionCells2).getFirst().getIdSectionCell(),
|
IterableToList(sectionCells2).getLast().getIdSectionCell(),
|
||||||
"modified content",
|
"modified content",
|
||||||
"entrepreneur@mail.fr");
|
"entrepreneur@mail.fr");
|
||||||
// We get the data from the database again.
|
// We get the data from the database again.
|
||||||
SectionCell s =
|
SectionCell s =
|
||||||
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getFirst();
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
|
||||||
assertEquals("modified content", s.getContentSectionCell());
|
assertEquals("modified content", s.getContentSectionCell());
|
||||||
|
assertEquals(
|
||||||
|
2, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -120,6 +116,11 @@ public class EntrepreneurApiServiceTest {
|
|||||||
() ->
|
() ->
|
||||||
entrepreneurApiService.editSectionCell(
|
entrepreneurApiService.editSectionCell(
|
||||||
-1L, "should not be modified", "entrepreneur@mail.fr"));
|
-1L, "should not be modified", "entrepreneur@mail.fr"));
|
||||||
|
SectionCell s =
|
||||||
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
|
||||||
|
assertEquals("contenu très intéressant", s.getContentSectionCell());
|
||||||
|
assertEquals(
|
||||||
|
1, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -132,7 +133,7 @@ public class EntrepreneurApiServiceTest {
|
|||||||
"should not be modified",
|
"should not be modified",
|
||||||
"testentrepreneur@mail.fr"));
|
"testentrepreneur@mail.fr"));
|
||||||
SectionCell s =
|
SectionCell s =
|
||||||
IterableToList(sectionCellService.getSectionCellsByProject(project, 3L)).getFirst();
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getFirst();
|
||||||
|
|
||||||
assertEquals("contenu très intéressant", s.getContentSectionCell());
|
assertEquals("contenu très intéressant", s.getContentSectionCell());
|
||||||
}
|
}
|
||||||
@ -148,7 +149,10 @@ public class EntrepreneurApiServiceTest {
|
|||||||
entrepreneurApiService.removeSectionCell(
|
entrepreneurApiService.removeSectionCell(
|
||||||
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr");
|
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
1, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
tmpCell.getIdReference(),
|
||||||
|
IterableToList(sectionCellService.getSectionCellsByProject(project, -1L))
|
||||||
|
.getLast()
|
||||||
|
.getIdReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -156,5 +160,52 @@ public class EntrepreneurApiServiceTest {
|
|||||||
assertThrows(
|
assertThrows(
|
||||||
ResponseStatusException.class,
|
ResponseStatusException.class,
|
||||||
() -> entrepreneurApiService.removeSectionCell(-1L, "entrepreneur@mail.fr"));
|
() -> entrepreneurApiService.removeSectionCell(-1L, "entrepreneur@mail.fr"));
|
||||||
|
SectionCell s =
|
||||||
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getFirst();
|
||||||
|
|
||||||
|
assertEquals("contenu très intéressant", s.getContentSectionCell());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addValidSectionCell() {
|
||||||
|
SectionCell added =
|
||||||
|
sectionCellService.addNewSectionCell(
|
||||||
|
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project));
|
||||||
|
entrepreneurApiService.addSectionCell(added, "entrepreneur@mail.fr");
|
||||||
|
SectionCell s =
|
||||||
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
|
||||||
|
assertEquals("contenu ajouté", s.getContentSectionCell());
|
||||||
|
assertEquals(
|
||||||
|
2, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addSectionCellInvalidAccess() {
|
||||||
|
System.out.println(
|
||||||
|
"content : "
|
||||||
|
+ IterableToList(sectionCellService.getSectionCellsByProject(project, 2L))
|
||||||
|
.getLast()
|
||||||
|
.getContentSectionCell());
|
||||||
|
SectionCell added =
|
||||||
|
sectionCellService.addNewSectionCell(
|
||||||
|
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project));
|
||||||
|
assertThrows(
|
||||||
|
ResponseStatusException.class,
|
||||||
|
() -> entrepreneurApiService.addSectionCell(added, "fauxentrepreneur@mail.fr"));
|
||||||
|
SectionCell s =
|
||||||
|
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
|
||||||
|
assertEquals(
|
||||||
|
1, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
||||||
|
assertEquals("contenu très intéressant", s.getContentSectionCell());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addInvalidSectionCell() {
|
||||||
|
SectionCell added =
|
||||||
|
sectionCellService.addNewSectionCell(
|
||||||
|
new SectionCell(null, -1L, "contenu ajouté", LocalDateTime.now(), project));
|
||||||
|
assertThrows(
|
||||||
|
ResponseStatusException.class,
|
||||||
|
() -> entrepreneurApiService.addSectionCell(added, "entrepreneur@mail.fr"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user