added Co Author
This commit is contained in:
@ -19,9 +19,7 @@ import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@ -138,24 +136,29 @@ public class MockController {
|
||||
// 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");
|
||||
|
||||
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");
|
||||
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");
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ public class ResearchController {
|
||||
}
|
||||
|
||||
/** post updates to the research
|
||||
* in the updates, the coAuthors have to be referenced by their ids
|
||||
*
|
||||
*/
|
||||
@PatchMapping("/research/{id}")
|
||||
@ -152,81 +153,6 @@ public class ResearchController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/////////////
|
||||
// Co-authors Part
|
||||
|
||||
/** get all the co-authors in a research
|
||||
*
|
||||
* @param id the research id
|
||||
* @return all the co-authors associated with the research
|
||||
*/
|
||||
@GetMapping("/research/{id}/co-authors")
|
||||
public ResponseEntity<Iterable<ResearcherDTO>> getCoAuthors(@PathVariable long id){
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
|
||||
if (research == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
Iterable<Researcher> researchers= researchesServ.getCoAuthors(research);
|
||||
ArrayList<ResearcherDTO> toReturn = new ArrayList<>();
|
||||
|
||||
for (Researcher researcher: researchers){
|
||||
toReturn.add(ResearcherDTO.construct(researcher));
|
||||
}
|
||||
return new ResponseEntity<>(toReturn,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** post co-authors to the research
|
||||
*
|
||||
* @param token the Authorization header
|
||||
* @param researchersId the co-authors ids
|
||||
* @param id the research id
|
||||
* @return the added researchers
|
||||
*/
|
||||
@PostMapping("/research/{id}/co-authors")
|
||||
public ResponseEntity<Iterable<ResearcherDTO>> postCoAuthor(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Iterable<Long> researchersId,
|
||||
@PathVariable long id)
|
||||
{
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
if (research == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin}, token) || research.getAuthor() != researchesServ.getResearcherByUser(authServ.getUserFromToken(token)))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
if (!researchesServ.saveCoAuthors(researchersId,research))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
ArrayList<ResearcherDTO> toReturn = new ArrayList<>();
|
||||
for (Long reId: researchersId){
|
||||
toReturn.add(ResearcherDTO.construct(researchesServ.getResearcherById(reId)));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(toReturn,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** deletes the co-author with *coAuthorId* from the research with the *researchId*
|
||||
*/
|
||||
@DeleteMapping("/research/{researchId}/co-author/{coAuthorId}")
|
||||
public ResponseEntity<String> deleteCoAuthor(@RequestHeader("Authorization") String token,
|
||||
@PathVariable long researchId,
|
||||
@PathVariable long coAuthorId)
|
||||
{
|
||||
Research research = researchesServ.getResearchById(researchId);
|
||||
Researcher coAuthor = researchesServ.getResearcherById(coAuthorId);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin}, token) || research.getAuthor() != researchesServ.getResearcherByUser(authServ.getUserFromToken(token)))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
if (coAuthor == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (!researchesServ.deleteCoAuthor(research, coAuthor))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
//views part
|
||||
@PostMapping("/addview/cdn/{url}")
|
||||
|
Reference in New Issue
Block a user