Merge pull request 'master' (#173) from Maxime/Clyde:master into master
All checks were successful
All checks were successful
Reviewed-on: #173
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
package ovh.herisson.Clyde.DTO.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchDTO.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Research format to return to front (without author's password)
|
||||
******************************************************/
|
||||
|
||||
import lombok.Data;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Access;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.PaperType;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class ResearchDTO {
|
||||
|
||||
private long id;
|
||||
private String title;
|
||||
private ResearcherDTO researcher;
|
||||
private final Set<ResearcherDTO> coAuthors;
|
||||
private Date releaseDate;
|
||||
private PaperType paperType;
|
||||
private String pdfLocation;
|
||||
private String bibTexLocation;
|
||||
private String language;
|
||||
private Access access;
|
||||
private String domain;
|
||||
private String summary;
|
||||
private long views;
|
||||
|
||||
private ResearchDTO(String title, ResearcherDTO researcherDTO, Date releaseDate, PaperType paperType, String pdfLocation, String language, Access access, String domain, String bibTexLocation, String summary, Set<Researcher> coAuthors, long id, long views) {
|
||||
this.title = title;
|
||||
this.researcher = researcherDTO;
|
||||
this.releaseDate = releaseDate;
|
||||
this.paperType = paperType;
|
||||
this.pdfLocation = pdfLocation;
|
||||
this.language = language;
|
||||
this.access = access;
|
||||
this.domain = domain;
|
||||
this.summary = summary;
|
||||
this.id = id;
|
||||
this.bibTexLocation = bibTexLocation;
|
||||
this.coAuthors = new HashSet<>();
|
||||
for (Researcher coAuthor: coAuthors) {
|
||||
this.coAuthors.add(ResearcherDTO.construct(coAuthor));
|
||||
}
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
|
||||
public static ResearchDTO construct(Research research){
|
||||
return new ResearchDTO(research.getTitle(), ResearcherDTO.construct(research.getAuthor()), research.getReleaseDate(),
|
||||
research.getPaperType(),research.getPdfLocation(),research.getLanguage(),research.getAccess(),
|
||||
research.getDomain(),research.getBibTexLocation(), research.getSummary(), research.getCoAuthors(),research.getId(), research.getViews());
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package ovh.herisson.Clyde.DTO.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherDTO.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Researcher Format to return to front (without user password)
|
||||
******************************************************/
|
||||
import lombok.Data;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ResearcherDTO {
|
||||
|
||||
private long id;
|
||||
private Map<String,Object> user;
|
||||
private String site;
|
||||
private String domain;
|
||||
private String orcidId;
|
||||
|
||||
|
||||
private ResearcherDTO(long id, Map<String ,Object> user, String site,String domain,String orcidId){
|
||||
this.domain = domain;
|
||||
this.orcidId = orcidId;
|
||||
this.site = site;
|
||||
this.user = user;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static ResearcherDTO construct(Researcher researcher){
|
||||
return new ResearcherDTO(researcher.getId(), ProtectionService.userWithoutPassword(researcher.getUser()),researcher.getSite(),
|
||||
researcher.getDomain(),researcher.getOrcidId());
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Applications;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
@ -20,7 +21,10 @@ public class ApplicationsController {
|
||||
|
||||
AuthenticatorService authServ;
|
||||
|
||||
public ApplicationsController(AuthenticatorService authServ){
|
||||
ResearchesService researchesServ;
|
||||
|
||||
public ApplicationsController(AuthenticatorService authServ, ResearchesService researchesServ){
|
||||
this.researchesServ = researchesServ;
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
@ -47,6 +51,7 @@ public class ApplicationsController {
|
||||
|
||||
//if unAuthed
|
||||
authorizedApps.add(Applications.Login);
|
||||
authorizedApps.add(Applications.ListResearches);
|
||||
authorizedApps.add(Applications.Schedule);
|
||||
|
||||
User user = authServ.getUserFromToken(token);
|
||||
@ -71,10 +76,15 @@ public class ApplicationsController {
|
||||
authorizedApps.add(Applications.Requests);
|
||||
authorizedApps.add(Applications.StudentsList);}
|
||||
|
||||
if (researchesServ.getResearcherByUser(user) != null)
|
||||
authorizedApps.add(Applications.ManageResearcherProfile);
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){
|
||||
authorizedApps.add(Applications.UsersList);
|
||||
authorizedApps.add(Applications.ManageSchedules);
|
||||
authorizedApps.add(Applications.LessonRequests);}
|
||||
authorizedApps.add(Applications.LessonRequests);
|
||||
authorizedApps.add(Applications.CreateUser);
|
||||
}
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.InscriptionService},token)){
|
||||
authorizedApps.add(Applications.Payments);}
|
||||
|
@ -7,17 +7,23 @@ import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository;
|
||||
import ovh.herisson.Clyde.Services.*;
|
||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Access;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.PaperType;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
|
||||
public class MockController {
|
||||
public final UserService userService;
|
||||
public final UserRepository userRepo;
|
||||
@ -36,14 +42,13 @@ public class MockController {
|
||||
public final LessonRequestService lessonRequestService;
|
||||
ArrayList<User> mockUsers;
|
||||
|
||||
public final ResearchesService researchesService;
|
||||
public final UserCurriculumRepository ucr;
|
||||
|
||||
public final MinervalRepository minervalRepository;
|
||||
|
||||
public final ScholarshipRequestRepository scholarshipRequestRepository;
|
||||
|
||||
|
||||
public final UnregisterRequestRepository uninscriptionRequestRepository;
|
||||
public MockController(UserService userService, UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository, UnregisterRequestRepository unregisterRequestRepository, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService, LessonRequestService lessonRequestService){
|
||||
public MockController(UserService userService, UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, ResearchesService researchesService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository, UnregisterRequestRepository unregisterRequestRepository, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService, LessonRequestService lessonRequestService){
|
||||
this.userService = userService;
|
||||
this.tokenRepo = tokenRepo;
|
||||
this.userRepo = userRepo;
|
||||
@ -53,6 +58,7 @@ public class MockController {
|
||||
this.courseService = courseService;
|
||||
this.externalCurriculumRepository = externalCurriculumRepository;
|
||||
this.inscriptionService = inscriptionService;
|
||||
this.researchesService = researchesService;
|
||||
this.lessonService = lessonService;
|
||||
this.scheduleService = scheduleService;
|
||||
this.scheduleLessonService = scheduleLessonService;
|
||||
@ -70,7 +76,8 @@ public class MockController {
|
||||
*/
|
||||
|
||||
@PostMapping("/mock")
|
||||
public void postMock(){
|
||||
public void postMock() {
|
||||
|
||||
|
||||
// user part
|
||||
User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,"admin");
|
||||
@ -87,9 +94,9 @@ public class MockController {
|
||||
ExternalCurriculum externalCurriculum = new ExternalCurriculum(null, "HEH", "Bachelier en ingénieur", "completed", 2015, 2017, null, joe);
|
||||
externalCurriculumRepository.save(externalCurriculum);
|
||||
|
||||
Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023);
|
||||
minervalRepository.save(minerval);
|
||||
// Course / Curriculum part
|
||||
Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023);
|
||||
minervalRepository.save(minerval);
|
||||
// Course / Curriculum part
|
||||
|
||||
Curriculum infoBab1 = new Curriculum(1,"info", false);
|
||||
Curriculum chemistryBab1 = new Curriculum(1,"chemistry", false);
|
||||
@ -121,13 +128,14 @@ public class MockController {
|
||||
Course psycho1 = new Course(21, "Neuroreaction of isolated brain cells",joke);
|
||||
Course commun = new Course(2, "cours commun",joke);
|
||||
|
||||
courseService.save(progra1);
|
||||
courseService.save(chemistry1);
|
||||
courseService.save(psycho1);
|
||||
courseService.save(commun);
|
||||
courseService.save(progra1);
|
||||
courseService.save(chemistry1);
|
||||
courseService.save(psycho1);
|
||||
courseService.save(commun);
|
||||
|
||||
ScholarshipRequest ssr1 = new ScholarshipRequest(joe, RequestState.Pending, 0, new Date(), "test", "test");
|
||||
scholarshipRequestRepository.save(ssr1);
|
||||
|
||||
ScholarshipRequest ssr1 = new ScholarshipRequest(joe, RequestState.Pending, 0, new Date(), "test", "test");
|
||||
scholarshipRequestRepository.save(ssr1);
|
||||
|
||||
CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
|
||||
CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));
|
||||
@ -136,12 +144,42 @@ public class MockController {
|
||||
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1));
|
||||
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1));
|
||||
|
||||
|
||||
InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 4,RequestState.Pending,"yes.png","password", null, new Date(), RequestState.Pending, null);
|
||||
|
||||
inscriptionService.save(inscriptionRequest);
|
||||
inscriptionService.save(inscriptionRequest);
|
||||
|
||||
///////////////////////////
|
||||
// extension Publications Scientifiques
|
||||
Researcher jojoResearcherAccount = new Researcher(jojo, "3363-22555-AB33-T", null, "IT");
|
||||
|
||||
Researcher joResearchAccount = new Researcher(joe,"N555-321213-BED-DD",null, "Physics");
|
||||
|
||||
|
||||
Researcher output = researchesService.saveResearcher(jojoResearcherAccount);
|
||||
Researcher joOutput = researchesService.saveResearcher(joResearchAccount);
|
||||
|
||||
Set<Researcher> coAuthor = new HashSet<>();
|
||||
coAuthor.add(joOutput);
|
||||
|
||||
Research jojoResearch = new Research("Graphs : Advanced Search Algorithms", output, new Date(0),
|
||||
PaperType.Article, "test.pdf", null, "english",
|
||||
Access.OpenSource, "IT", "This Article's title speaks for itself \n We'll discuss about advanced Graph search Algorithms",coAuthor);
|
||||
Research restrictedResearch = new Research("just another Name", output, new Date(1111111111),
|
||||
PaperType.Article, "restricted", null, "english",
|
||||
Access.Restricted, "Restricted", "This Article's title speaks for itself\n We'll discuss about advanced Graph search Algorithms", new HashSet<>());
|
||||
|
||||
Research privateResearch = new Research("the great Potato War", output, new Date(),
|
||||
PaperType.Article, "private", null, "english",
|
||||
Access.Private, "private", "This Article's title speaks for itself\n We'll discuss about advanced Graph search Algorithms",null);
|
||||
|
||||
|
||||
researchesService.saveResearch(restrictedResearch);
|
||||
researchesService.saveResearch(privateResearch);
|
||||
researchesService.saveResearch(jojoResearch);
|
||||
|
||||
|
||||
//Schedule part
|
||||
|
@ -0,0 +1,167 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* API class for the researches
|
||||
******************************************************/
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearchDTO;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearcherDTO;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class ResearchController {
|
||||
|
||||
|
||||
|
||||
private final ResearchesService researchesServ;
|
||||
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
/** Is accessible by anyone
|
||||
* but if the user doesn't have the permission to download the research
|
||||
* the return Research Download URL will be null
|
||||
*/
|
||||
@GetMapping("/research/{id}")
|
||||
public ResponseEntity<ResearchDTO> getResearch(@RequestHeader(value = "Authorization", required = false) String token, @PathVariable long id){
|
||||
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}// If the user doesn't have access to the document he can't download the pdf
|
||||
|
||||
return new ResponseEntity<>(ResearchDTO.construct(research), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token used to know if the user can download or not the research pdf
|
||||
* @return every research
|
||||
*/
|
||||
@GetMapping("/researches")
|
||||
public ResponseEntity<Iterable<ResearchDTO>> getResearches(@RequestHeader(value = "Authorization",required = false) String token){
|
||||
Iterable<Research> researches = researchesServ.getAllResearches();
|
||||
|
||||
ArrayList<ResearchDTO> toReturnResearches = new ArrayList<>();
|
||||
|
||||
for (Research research: researches){
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}
|
||||
toReturnResearches.add(ResearchDTO.construct(research));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/researches/{id}")
|
||||
public ResponseEntity<Iterable<ResearchDTO>> getResearchesFromResearcher(@RequestHeader(value = "Authorization",required = false) String token,
|
||||
@PathVariable Long id
|
||||
){
|
||||
Iterable<Research> researches = researchesServ.getResearchesByAuthor(id);
|
||||
if (researches == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
ArrayList<ResearchDTO> toReturnResearches = new ArrayList<>();
|
||||
|
||||
for (Research research: researches){
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}
|
||||
toReturnResearches.add(ResearchDTO.construct(research));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** post a new research
|
||||
*
|
||||
* @return the research saved
|
||||
*/
|
||||
@PostMapping("/research")
|
||||
public ResponseEntity<Research> postResearch(@RequestHeader("Authorization") String token, @RequestBody Research research){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin},token) &&
|
||||
researchesServ.getResearcherByUser(authServ.getUserFromToken(token)) == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
} // if the poster isn't a researcher
|
||||
|
||||
return new ResponseEntity<>(researchesServ.saveResearch(research), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** post updates to the research
|
||||
* in the updates, the coAuthors have to be referenced by their ids
|
||||
*
|
||||
*/
|
||||
@PatchMapping("/research/{id}")
|
||||
public ResponseEntity<String> patchResearch(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String,Object> updates,
|
||||
@PathVariable long id
|
||||
)
|
||||
{
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
Researcher researcher = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token) &&
|
||||
researcher != research.getAuthor()) {
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
researchesServ.modifyResearchData(research, updates);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** Only Admin, Secretary and author can delete a research
|
||||
*
|
||||
*/
|
||||
@DeleteMapping("/research/{id}")
|
||||
public ResponseEntity<String> deleteResearch(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
Researcher researcher = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin, Role.Secretary},token) &&
|
||||
researcher != research.getAuthor()){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
researchesServ.deleteResearch(research);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
///////
|
||||
//views part
|
||||
@PostMapping("/addview/cdn/{url}")
|
||||
public ResponseEntity<ResearchDTO> addView(@PathVariable String url){
|
||||
System.out.println(url);
|
||||
Research research = researchesServ.getResearchByUrl("cdn/" + url);
|
||||
if (research ==null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ResearchDTO.construct(researchesServ.addView(research)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* API class for the researchers
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearcherDTO;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class ResearcherController {
|
||||
|
||||
ResearchesService researchesServ;
|
||||
AuthenticatorService authServ;
|
||||
|
||||
|
||||
@GetMapping("/researcher/{id}")
|
||||
public ResponseEntity<ResearcherDTO> getResearcher(@PathVariable long id){
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(researcher),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Everyone can access every researcher Account
|
||||
* @return all the researchers accounts
|
||||
*/
|
||||
@GetMapping("/researchers")
|
||||
public ResponseEntity<Iterable<ResearcherDTO>> getAllResearchers(){
|
||||
Iterable<Researcher> researchers = researchesServ.getAllResearchers();
|
||||
ArrayList<ResearcherDTO> toReturnResearchersDTO = new ArrayList<>();
|
||||
for (Researcher researcher: researchers){
|
||||
toReturnResearchersDTO.add(ResearcherDTO.construct(researcher));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearchersDTO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/researcher")
|
||||
public ResponseEntity<ResearcherDTO> getSelf(@RequestHeader("Authorization") String token){
|
||||
|
||||
Researcher self = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (self ==null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(self), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/researcher")
|
||||
public ResponseEntity<ResearcherDTO> postResearcher(@RequestHeader("Authorization") String token, @RequestBody Researcher researcher){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token)){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
Researcher posted = researchesServ.saveResearcher(researcher);
|
||||
|
||||
if (posted == null) return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(posted), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/researcher/{id}")
|
||||
public ResponseEntity<ResearcherDTO> patchResearcher(@RequestHeader("Authorization") String token,
|
||||
@PathVariable long id,
|
||||
@RequestBody Map<String ,Object> updates){
|
||||
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin}, token)
|
||||
&& researcher.getId() != researchesServ.getResearcherByUser(authServ.getUserFromToken(token)).getId())
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
researchesServ.modifyResearcherData(researcher,updates);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(researcher),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/researcher/{id}")
|
||||
public ResponseEntity<String> deleteResearcher(@RequestHeader ("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
researchesServ.deleteResearcher(researchesServ.getResearcherById(id));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Api class for handling statistics
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.StatisticsService;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class StatController {
|
||||
|
||||
|
||||
private StatisticsService statServ;
|
||||
private ResearchesService researchesServ;
|
||||
|
||||
/** returns all the statistics in a 2D array
|
||||
*
|
||||
* @param id the researcher's id
|
||||
* @return all the stats in a 2D array
|
||||
*/
|
||||
@GetMapping("/stats/{id}")
|
||||
public ResponseEntity<Iterable<Iterable<Map<String, Integer>>>> getStat(@PathVariable Long id){
|
||||
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
Iterable<Iterable<Map<String,Integer>>> stats = statServ.generateStats(researcher);
|
||||
|
||||
if (stats == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(stats,HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
@ -86,19 +86,20 @@ public class UserController {
|
||||
* @return a string clarifying the issue (if there is any)
|
||||
*/
|
||||
@PatchMapping("/user/{id}")
|
||||
public ResponseEntity<String> patchUser(@RequestHeader("Authorization") String token,
|
||||
public ResponseEntity<Map<String,Object>> patchUser(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String,Object> updates,
|
||||
@PathVariable Long id) {
|
||||
|
||||
if (token == null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
User poster = authServ.getUserFromToken(token);
|
||||
if (poster == null) {return new UnauthorizedResponse<>("bad token");}
|
||||
if (poster == null) {return new UnauthorizedResponse<>(null);}
|
||||
|
||||
if (!userService.modifyData(id, updates, poster))
|
||||
return new UnauthorizedResponse<>("there was an issue with the updates requested");
|
||||
User modified = userService.modifyData(id,updates,poster);
|
||||
if (modified ==null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(null, HttpStatus.OK);
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(modified), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/teachers")
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseach table
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ResearchRepository extends CrudRepository<Research,Long> {
|
||||
|
||||
Research findById(long id);
|
||||
|
||||
Iterable<Research> findByAuthor(Researcher author);
|
||||
|
||||
@Query("select r from Research r where r.pdfLocation = ?1")
|
||||
Research findByPdfLocation(String url);
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseacher table
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
public interface ResearcherRepository extends CrudRepository<Researcher,Long> {
|
||||
Researcher findByUser(User user);
|
||||
|
||||
Researcher findById(long id);
|
||||
|
||||
@Query("select r from Research r where r.author = ?1")
|
||||
Iterable<Research> findAllByAuthorId(Researcher author);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatsRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseach table for making statistics
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface StatsRepository extends CrudRepository<Research,Long> {
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, sum(r.views) as y) from Research r group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> viewsByMonths();
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> viewsByYears();
|
||||
|
||||
|
||||
@Query("select new map(r.domain as label, sum(r.views) as y) from Research r group by r.domain")
|
||||
Iterable<Map<String ,Integer>> viewsByTopics();
|
||||
|
||||
|
||||
@Query("select new map(r.domain as label, count(distinct r.language) as y) from Research r group by r.domain")
|
||||
Iterable<Map<String ,Integer>> languageByTopics();
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(distinct r.language) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> languageByYears();
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, count(distinct r.language) as y) from Research r group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> languageByMonths();
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(distinct r) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> researchesByYears();
|
||||
|
||||
@Query("select new map(r.domain as label, count(distinct r) as y) from Research r group by r.domain")
|
||||
Iterable<Map<String ,Integer>> researchesByTopics();
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, count(distinct r) as y) from Research r group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> researchesByMonth();
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package ovh.herisson.Clyde.Services.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchesService.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Service for managing researcher and researches
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearcherRepository;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.*;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ResearchesService {
|
||||
|
||||
private final ResearcherRepository researcherRepo;
|
||||
private final ResearchRepository articleRepo;
|
||||
|
||||
|
||||
// researches Part
|
||||
public Research getResearchById(long id) {
|
||||
return articleRepo.findById(id);
|
||||
}
|
||||
|
||||
public Research getResearchByUrl(String url) {
|
||||
return articleRepo.findByPdfLocation(url);
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Research> getResearchesByAuthor(long authorId){
|
||||
Researcher researcher = researcherRepo.findById(authorId);
|
||||
if (researcher == null) return null;
|
||||
|
||||
return researcherRepo.findAllByAuthorId(researcher);
|
||||
}
|
||||
|
||||
public Research saveResearch(Research research) {
|
||||
return articleRepo.save(research);
|
||||
}
|
||||
|
||||
public void modifyResearchData(Research research, Map<String, Object> updates) {
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "title":
|
||||
research.setTitle((String) entry.getValue());
|
||||
break;
|
||||
case "paperType":
|
||||
research.setPaperType((PaperType) entry.getValue());
|
||||
break;
|
||||
case "language":
|
||||
research.setLanguage((String) entry.getValue());
|
||||
break;
|
||||
case "domain":
|
||||
research.setDomain((String) entry.getValue());
|
||||
break;
|
||||
case "summary":
|
||||
research.setSummary((String) entry.getValue());
|
||||
break;
|
||||
case "access":
|
||||
research.setAccess(Access.valueOf((String) entry.getValue()));
|
||||
break;
|
||||
case "coAuthors":
|
||||
Set<Researcher> set = new HashSet<>();
|
||||
|
||||
for (int id : (List<Integer>) entry.getValue()) {
|
||||
|
||||
Researcher r = researcherRepo.findById(id);
|
||||
if (r != null){
|
||||
set.add(r);
|
||||
}
|
||||
}
|
||||
research.setCoAuthors(set);
|
||||
break;
|
||||
}
|
||||
}
|
||||
articleRepo.save(research);
|
||||
}
|
||||
|
||||
public void deleteResearch(Research research) {
|
||||
articleRepo.delete(research);
|
||||
}
|
||||
|
||||
|
||||
// Researchers Part
|
||||
public Researcher getResearcherByUser(User user){
|
||||
return researcherRepo.findByUser(user);
|
||||
}
|
||||
|
||||
public Iterable<Research> getAllResearches() {
|
||||
return articleRepo.findAll();
|
||||
}
|
||||
|
||||
public Researcher saveResearcher(Researcher researcher) {
|
||||
|
||||
if (researcherRepo.findByUser(researcher.getUser()) != null) return null;
|
||||
return researcherRepo.save(researcher);
|
||||
}
|
||||
|
||||
public Iterable<Researcher> getAllResearchers() {
|
||||
return researcherRepo.findAll();
|
||||
}
|
||||
|
||||
public Researcher getResearcherById(long id) {
|
||||
return researcherRepo.findById(id);
|
||||
}
|
||||
|
||||
public void deleteResearcher(Researcher researcher) {
|
||||
articleRepo.findAll();
|
||||
for (Research r: articleRepo.findAll())
|
||||
{
|
||||
if (r.getCoAuthors().contains(researcher)){
|
||||
r.getCoAuthors().remove(researcher);
|
||||
articleRepo.save(r);
|
||||
}
|
||||
}
|
||||
researcherRepo.delete(researcher);
|
||||
}
|
||||
|
||||
public void modifyResearcherData(Researcher researcher, Map<String, Object> updates) {
|
||||
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "orcidId":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setOrcidId((String) entry.getValue());
|
||||
break;
|
||||
case "domain":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setDomain((String) entry.getValue());
|
||||
break;
|
||||
case "site":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setSite((String) entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
researcherRepo.save(researcher);
|
||||
}
|
||||
// Other stuff
|
||||
|
||||
public Research addView(Research research) {
|
||||
research.setViews(research.getViews()+1);
|
||||
return articleRepo.save(research);
|
||||
}
|
||||
|
||||
public boolean hasNoAccessTo(Research research, User user){
|
||||
if (research.getAccess() == Access.OpenSource) return false; // if the access is open source even non-users can see it
|
||||
if (user == null) return true; // else you need at least to be a user
|
||||
|
||||
if (user.getRole() == Role.Admin) return false;
|
||||
|
||||
|
||||
Researcher researcher = getResearcherByUser(user);
|
||||
if (researcher !=null ){
|
||||
if (research.getAuthor().getId() == researcher.getId())
|
||||
return false;
|
||||
|
||||
for (Researcher coAuthor: research.getCoAuthors()){
|
||||
if (coAuthor.getId() == researcher.getId())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return research.getAccess() != Access.Restricted || (user.getRole() != Role.Secretary &&
|
||||
user.getRole() != Role.Teacher && user.getRole() != Role.InscriptionService);
|
||||
// if the access is restricted only the staff member (above) can access the research
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package ovh.herisson.Clyde.Services.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatisticsService
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Service for managing statistics
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.StatsRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class StatisticsService {
|
||||
|
||||
|
||||
private ResearchRepository articleRepo;
|
||||
private StatsRepository statsRepo;
|
||||
|
||||
|
||||
public Iterable<Iterable<Map<String, Integer>>> generateStats(Researcher researcher){
|
||||
|
||||
Iterable<Research> researches = articleRepo.findByAuthor(researcher);
|
||||
|
||||
if (researches == null) return null;
|
||||
|
||||
|
||||
ArrayList<Iterable<Map<String,Integer>>> toReturn = new ArrayList<>();
|
||||
|
||||
toReturn.add(statsRepo.viewsByYears());
|
||||
toReturn.add(statsRepo.viewsByMonths());
|
||||
toReturn.add(statsRepo.viewsByTopics());
|
||||
|
||||
toReturn.add(statsRepo.researchesByYears());
|
||||
toReturn.add(statsRepo.researchesByMonth());
|
||||
toReturn.add(statsRepo.researchesByTopics());
|
||||
|
||||
toReturn.add(statsRepo.languageByYears());
|
||||
toReturn.add(statsRepo.languageByMonths());
|
||||
toReturn.add(statsRepo.languageByTopics());
|
||||
return toReturn;
|
||||
}
|
||||
}
|
@ -45,61 +45,55 @@ public class UserService {
|
||||
* @param targetId the id of the user to update
|
||||
* @return if the changes were done or not
|
||||
*/
|
||||
public boolean modifyData(long targetId, Map<String ,Object> updates, User poster){
|
||||
public User modifyData(long targetId, Map<String ,Object> updates, User poster){
|
||||
|
||||
User target = userRepo.findById(targetId);
|
||||
if (target == null)
|
||||
return false;
|
||||
return null;
|
||||
|
||||
if (poster.getRegNo().equals(target.getRegNo())){
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
if (!target.getRegNo().equals(poster.getRegNo()) && !(poster.getRole() == Role.Secretary) &&
|
||||
!(poster.getRole() == Role.Admin))
|
||||
return null;
|
||||
|
||||
switch (entry.getKey()){
|
||||
case "firstName":
|
||||
target.setFirstName((String) entry.getValue());
|
||||
break;
|
||||
case "lastName":
|
||||
target.setLastName((String) entry.getValue());
|
||||
break;
|
||||
case "email":
|
||||
target.setEmail((String) entry.getValue());
|
||||
break;
|
||||
case "address":
|
||||
target.setAddress((String) entry.getValue());
|
||||
break;
|
||||
case "country":
|
||||
target.setCountry((String) entry.getValue());
|
||||
break;
|
||||
case "birthDate":
|
||||
target.setBirthDate((Date) entry.getValue());
|
||||
break;
|
||||
case "profilePictureUrl":
|
||||
target.setProfilePictureUrl((String) entry.getValue());
|
||||
break;
|
||||
case "password":
|
||||
target.setPassword((String) entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
userRepo.save(target);
|
||||
return true;
|
||||
}
|
||||
// the secretary can change roles (for example if a student becomes a teacher)
|
||||
else if (poster.getRole() == Role.Secretary)
|
||||
{
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
|
||||
if ( entry.getKey().equals("role")) {
|
||||
|
||||
if (entry.getValue() == Role.Admin) {return false;}
|
||||
|
||||
target.setRole((Role) entry.getValue());
|
||||
userRepo.save(target);
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
System.out.println(entry.getValue());
|
||||
switch (entry.getKey()){
|
||||
case "firstName":
|
||||
target.setFirstName((String) entry.getValue());
|
||||
break;
|
||||
case "lastName":
|
||||
target.setLastName((String) entry.getValue());
|
||||
break;
|
||||
case "email":
|
||||
target.setEmail((String) entry.getValue());
|
||||
break;
|
||||
case "address":
|
||||
target.setAddress((String) entry.getValue());
|
||||
break;
|
||||
case "country":
|
||||
target.setCountry((String) entry.getValue());
|
||||
break;
|
||||
case "birthDate":
|
||||
target.setBirthDate((Date) entry.getValue());
|
||||
break;
|
||||
case "profilePictureUrl":
|
||||
target.setProfilePictureUrl((String) entry.getValue());
|
||||
break;
|
||||
case "password":
|
||||
target.setPassword((String) entry.getValue());
|
||||
break;
|
||||
case "role":
|
||||
//a user can't change his own role
|
||||
if (poster.getRole()==Role.Secretary || poster.getRole() == Role.Admin){
|
||||
Role wanted = Role.valueOf((String) entry.getValue());
|
||||
if (wanted == Role.Admin && poster.getRole() != Role.Admin)
|
||||
return null;
|
||||
target.setRole(wanted);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
userRepo.save(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,7 +8,6 @@ public enum Applications {
|
||||
// with any token
|
||||
Profile,
|
||||
|
||||
|
||||
// Students and higher authorization
|
||||
Msg,
|
||||
Forum,
|
||||
@ -27,6 +26,13 @@ public enum Applications {
|
||||
|
||||
// InscriptionService authorization
|
||||
Requests,
|
||||
StudentsList,
|
||||
// profile of a researcher
|
||||
ResearcherProfile,
|
||||
ManageResearcherProfile,
|
||||
|
||||
//the list of all researches (filterable)
|
||||
ListResearches,
|
||||
CreateUser,
|
||||
StudentsList,
|
||||
Payments
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package ovh.herisson.Clyde.Tables;
|
||||
public enum FileType {
|
||||
ProfilePicture,
|
||||
EducationCertificate,
|
||||
Research,
|
||||
ResearchBibTex,
|
||||
JustificationDocument,
|
||||
IdentityCard,
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package ovh.herisson.Clyde.Tables.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file Access.java
|
||||
* @author Maxime Bartha
|
||||
* @scope Extension Publications scientifiques
|
||||
*
|
||||
* Access Type for the Articles
|
||||
*
|
||||
******************************************************/
|
||||
public enum Access {
|
||||
OpenSource, // everyone can see
|
||||
Restricted, // only Researchers and Staff Members (secretary, teachers and Inscription Service)
|
||||
Private, // only authors and co-authors
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package ovh.herisson.Clyde.Tables.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file PaperType.java
|
||||
* @author Maxime Bartha
|
||||
* @scope Extension Publications scientifiques
|
||||
*
|
||||
* Type of the scientific paper
|
||||
*
|
||||
******************************************************/
|
||||
public enum PaperType {
|
||||
Article,
|
||||
Paper,
|
||||
Book,
|
||||
BookChapter,
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package ovh.herisson.Clyde.Tables.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file Research.java
|
||||
* @author Maxime Bartha
|
||||
* @scope Extension Publications scientifiques
|
||||
*
|
||||
* Research entity
|
||||
******************************************************/
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Research")
|
||||
public class Research {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name ="Researcher")
|
||||
private Researcher author;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Date releaseDate;
|
||||
|
||||
private PaperType paperType;
|
||||
|
||||
private String pdfLocation;
|
||||
|
||||
private String bibTexLocation;
|
||||
|
||||
private String language;
|
||||
|
||||
private Access access;
|
||||
|
||||
private String domain;
|
||||
|
||||
private String summary;
|
||||
|
||||
private int views;
|
||||
|
||||
@ManyToMany(cascade = {CascadeType.MERGE})
|
||||
@JoinTable(name = "ResearchCoAuhors",
|
||||
joinColumns = @JoinColumn(name = "research_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "researcher_id")
|
||||
)
|
||||
private Set<Researcher> coAuthors;
|
||||
|
||||
public Research(String title, Researcher author, Date releaseDate, PaperType paperType,
|
||||
String pdfLocation, String bibTexLocation, String language, Access access, String domain, String summary,Set<Researcher> coauthors){
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.releaseDate = releaseDate;
|
||||
this.paperType = paperType;
|
||||
this.pdfLocation = pdfLocation;
|
||||
this.bibTexLocation = bibTexLocation;
|
||||
this.language = language;
|
||||
this.access = access;
|
||||
this.domain = domain;
|
||||
this.summary = summary;
|
||||
this.coAuthors = coauthors;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package ovh.herisson.Clyde.Tables.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file Researcher.java
|
||||
* @author Maxime Bartha
|
||||
* @scope Extension Publications scientifiques
|
||||
*
|
||||
* Researcher entity
|
||||
******************************************************/
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Researcher")
|
||||
public class Researcher {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long id;
|
||||
@OneToOne
|
||||
private User user;
|
||||
private String orcidId;
|
||||
private String site;
|
||||
private String domain;
|
||||
|
||||
public Researcher(User user, String orcidId, String site, String domain){
|
||||
this.user = user;
|
||||
this.orcidId = orcidId;
|
||||
this.site = site;
|
||||
this.domain = domain;
|
||||
}
|
||||
}
|
@ -54,6 +54,7 @@ public class User {
|
||||
private List<Discussion> discussions;
|
||||
/////////////////////////////////
|
||||
|
||||
/////////////////////////////////
|
||||
public User(String lastName, String firstName, String email, String address,
|
||||
String country, Date birthDate, String profilePictureUrl, Role role, String password)
|
||||
{
|
||||
|
Reference in New Issue
Block a user