1
0
forked from PGL/Clyde

added all endPoints

This commit is contained in:
2024-04-12 01:56:18 +02:00
parent 4720669c2c
commit 17cb969160
6 changed files with 169 additions and 12 deletions

View File

@ -6,12 +6,10 @@ import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchCoAuthorsR
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.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.Tables.ScientificPublications.*;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
@ -46,11 +44,14 @@ public class ResearchesService {
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.Admin || user.getRole() == Role.Secretary ||
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
@ -123,4 +124,57 @@ public class ResearchesService {
public void deleteResearcher(Researcher researcher) {
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()){
switch (entry.getKey()){
case "orcidId":
researcher.setOrcidId((String) entry.getValue());
break;
case "domain":
researcher.setDomain((String) entry.getValue());
break;
case "site":
researcher.setSite((String) entry.getValue());
break;
}
}
researcherRepo.save(researcher);
}
}