added Co Author
This commit is contained in:
		@ -12,8 +12,11 @@ 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 {
 | 
			
		||||
@ -21,6 +24,7 @@ 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;
 | 
			
		||||
@ -31,7 +35,7 @@ public class ResearchDTO {
 | 
			
		||||
    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, long id,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;
 | 
			
		||||
@ -43,6 +47,10 @@ public class ResearchDTO {
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -50,6 +58,6 @@ public class ResearchDTO {
 | 
			
		||||
    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.getId(), research.getViews());
 | 
			
		||||
                research.getDomain(),research.getBibTexLocation(), research.getSummary(), research.getCoAuthors(),research.getId(), research.getViews());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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}")
 | 
			
		||||
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Course;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Curriculum;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ScientificPublications.ResearchCoAuthors;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
 | 
			
		||||
 | 
			
		||||
public interface ResearchCoAuthorsRepository extends CrudRepository<ResearchCoAuthors,Long> {
 | 
			
		||||
   @Query("select distinct rca.coAuthor from ResearchCoAuthors rca where rca.research = ?1")
 | 
			
		||||
   Iterable<Researcher> findResearchCoAuthors(Research research);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   @Query("select rca from ResearchCoAuthors rca where rca.research = ?1 and rca.coAuthor =?2")
 | 
			
		||||
  ResearchCoAuthors findResearchCoAuthors(Research research, Researcher researcher);
 | 
			
		||||
}
 | 
			
		||||
@ -2,47 +2,33 @@ package ovh.herisson.Clyde.Services.ScientificPublications;
 | 
			
		||||
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearchDTO;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchCoAuthorsRepository;
 | 
			
		||||
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.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@SuppressWarnings("unchecked")
 | 
			
		||||
public class ResearchesService {
 | 
			
		||||
 | 
			
		||||
    private final ResearcherRepository researcherRepo;
 | 
			
		||||
    private final ResearchCoAuthorsRepository researchCoAuthorsRepo;
 | 
			
		||||
    private final ResearchRepository articleRepo;
 | 
			
		||||
 | 
			
		||||
    // Researchers Part
 | 
			
		||||
    public Researcher getResearcherByUser(User user){
 | 
			
		||||
        return researcherRepo.findByUser(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isCoAuthor(Research research, Researcher researcher){
 | 
			
		||||
        Iterable<Researcher> coAuthors = researchCoAuthorsRepo.findResearchCoAuthors(research);
 | 
			
		||||
        for (Researcher coAuthor : coAuthors){
 | 
			
		||||
            if (researcher == coAuthor){
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // 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;
 | 
			
		||||
@ -50,29 +36,6 @@ public class ResearchesService {
 | 
			
		||||
        return researcherRepo.findAllByAuthorId(researcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
        if (research.getAccess() == Access.Restricted &&
 | 
			
		||||
                user.getRole() == Role.Secretary ||
 | 
			
		||||
                user.getRole() == Role.Teacher || user.getRole() == Role.InscriptionService)
 | 
			
		||||
            return false; // if the access is restricted only the staff member (above) can access the research
 | 
			
		||||
 | 
			
		||||
        Researcher researcher = getResearcherByUser(user);
 | 
			
		||||
 | 
			
		||||
        if (researcher==null)
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        return (research.getAccess() != Access.Private || research.getAuthor() != researcher) &&
 | 
			
		||||
                (research.getAccess() != Access.Private || !isCoAuthor(research, researcher));
 | 
			
		||||
        // if the researcher is the author or one of the co-authors of the research will return false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Research saveResearch(Research research) {
 | 
			
		||||
        return articleRepo.save(research);
 | 
			
		||||
    }
 | 
			
		||||
@ -98,6 +61,18 @@ public class ResearchesService {
 | 
			
		||||
                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);
 | 
			
		||||
@ -107,6 +82,12 @@ public class ResearchesService {
 | 
			
		||||
        articleRepo.delete(research);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Researchers Part
 | 
			
		||||
    public Researcher getResearcherByUser(User user){
 | 
			
		||||
        return researcherRepo.findByUser(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<Research> getAllResearches() {
 | 
			
		||||
        return articleRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
@ -129,41 +110,6 @@ public class ResearchesService {
 | 
			
		||||
       researcherRepo.delete(researcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean saveCoAuthors(Iterable<Long> researchersId, Research research) {
 | 
			
		||||
 | 
			
		||||
        if (researchersId == null) return false;
 | 
			
		||||
 | 
			
		||||
        ArrayList<Researcher> toAdd = new ArrayList<>();
 | 
			
		||||
        for (long researcherId : researchersId){
 | 
			
		||||
            Researcher researcher= researcherRepo.findById(researcherId);
 | 
			
		||||
            if (research== null){
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if (!toAdd.contains(researcher))
 | 
			
		||||
            {
 | 
			
		||||
                toAdd.add(researcher);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (Researcher researcher: toAdd){
 | 
			
		||||
            researchCoAuthorsRepo.save(new ResearchCoAuthors(researcher,research));
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<Researcher> getCoAuthors(Research research) {
 | 
			
		||||
        return researchCoAuthorsRepo.findResearchCoAuthors(research);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean deleteCoAuthor(Research research,Researcher coAuthor) {
 | 
			
		||||
        ResearchCoAuthors result = researchCoAuthorsRepo.findResearchCoAuthors(research,coAuthor);
 | 
			
		||||
 | 
			
		||||
        if (result ==null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        researchCoAuthorsRepo.delete(result);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void modifyResearcherData(Researcher researcher, Map<String, Object> updates) {
 | 
			
		||||
 | 
			
		||||
        for (Map.Entry<String, Object> entry : updates.entrySet()){
 | 
			
		||||
@ -185,12 +131,69 @@ public class ResearchesService {
 | 
			
		||||
        researcherRepo.save(researcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Research getResearchByUrl(String url) {
 | 
			
		||||
        return articleRepo.findByPdfLocation(url);
 | 
			
		||||
 | 
			
		||||
    //Co Author part
 | 
			
		||||
    public boolean saveCoAuthors(Iterable<Long> researchersId, Research research) {
 | 
			
		||||
 | 
			
		||||
        if (researchersId == null) return false;
 | 
			
		||||
 | 
			
		||||
        ArrayList<Researcher> toAdd = new ArrayList<>();
 | 
			
		||||
        for (long researcherId : researchersId){
 | 
			
		||||
            Researcher researcher= researcherRepo.findById(researcherId);
 | 
			
		||||
            if (researcher== null){
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if (!toAdd.contains(researcher))
 | 
			
		||||
            {
 | 
			
		||||
                toAdd.add(researcher);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        research.getCoAuthors().addAll(toAdd);
 | 
			
		||||
        articleRepo.save(research);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean deleteCoAuthor(Research research,Researcher coAuthor) {
 | 
			
		||||
 | 
			
		||||
        if (!research.getCoAuthors().contains(coAuthor))
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        research.getCoAuthors().remove(coAuthor);
 | 
			
		||||
        articleRepo.save(research);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (research.getAccess() == Access.Restricted && (
 | 
			
		||||
                user.getRole() == Role.Secretary ||
 | 
			
		||||
                user.getRole() == Role.Teacher || user.getRole() == Role.InscriptionService))
 | 
			
		||||
            return false; // if the access is restricted only the staff member (above) can access the research
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
        // if the researcher is the author or one of the co-authors of the research will return false
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,10 +16,14 @@ 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)
 | 
			
		||||
@ -51,8 +55,15 @@ public class Research {
 | 
			
		||||
 | 
			
		||||
    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){
 | 
			
		||||
                    String pdfLocation, String bibTexLocation, String language, Access access, String domain, String summary,Set<Researcher> coauthors){
 | 
			
		||||
        this.author = author;
 | 
			
		||||
        this.title = title;
 | 
			
		||||
        this.releaseDate = releaseDate;
 | 
			
		||||
@ -63,6 +74,7 @@ public class Research {
 | 
			
		||||
        this.access = access;
 | 
			
		||||
        this.domain = domain;
 | 
			
		||||
        this.summary = summary;
 | 
			
		||||
        this.coAuthors = coauthors;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,42 +0,0 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables.ScientificPublications;
 | 
			
		||||
 | 
			
		||||
/******************************************************
 | 
			
		||||
 * @file ResearchCoAuthors
 | 
			
		||||
 * @author Maxime Bartha
 | 
			
		||||
 * @scope Extension Publications scientifiques
 | 
			
		||||
 *
 | 
			
		||||
 * Co-Authors List entity (will be accessed by Articles)
 | 
			
		||||
 *
 | 
			
		||||
 ******************************************************/
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import lombok.Setter;
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
 | 
			
		||||
@Getter
 | 
			
		||||
@Setter
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@Entity
 | 
			
		||||
public class ResearchCoAuthors {
 | 
			
		||||
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    Long id;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @JoinColumn(name = "Researcher")
 | 
			
		||||
    private Researcher coAuthor;
 | 
			
		||||
 | 
			
		||||
    @ManyToOne(fetch = FetchType.EAGER)
 | 
			
		||||
    @OnDelete(action = OnDeleteAction.CASCADE)
 | 
			
		||||
    @JoinColumn(name = "Article")
 | 
			
		||||
    private Research research;
 | 
			
		||||
 | 
			
		||||
    public ResearchCoAuthors(Researcher coAuthor, Research research){
 | 
			
		||||
        this.coAuthor = coAuthor;
 | 
			
		||||
        this.research = research;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -20,6 +20,7 @@ import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
@Setter
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@Entity
 | 
			
		||||
@Table(name = "Researcher")
 | 
			
		||||
public class Researcher {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user