Fix getFullStakeholder by removing visibility authority.
This commit is contained in:
parent
a73db0e081
commit
4325e1fdb0
|
@ -1,12 +1,10 @@
|
||||||
package eu.dnetlib.uoamonitorservice.controllers;
|
package eu.dnetlib.uoamonitorservice.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.copy;
|
|
||||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||||
|
import eu.dnetlib.uoamonitorservice.dto.copy;
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||||
import eu.dnetlib.uoamonitorservice.service.CommonService;
|
import eu.dnetlib.uoamonitorservice.service.CommonService;
|
||||||
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
||||||
|
@ -17,7 +15,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin(origins = "*")
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder findByPath(String stakeholderId) {
|
public Stakeholder findByPath(String stakeholderId) {
|
||||||
if(stakeholderId.equals("-1")) {
|
if (stakeholderId.equals("-1")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
||||||
|
@ -81,29 +81,25 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
|
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
|
||||||
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
|
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||||
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
if (defaultStakeholder != null) {
|
||||||
if(defaultStakeholder != null) {
|
return new StakeholderFull(stakeholder,
|
||||||
return new StakeholderFull(stakeholder,
|
defaultStakeholder.getTopics().stream()
|
||||||
defaultStakeholder.getTopics().stream()
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
.collect(Collectors.toList()));
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new StakeholderFull(stakeholder,
|
|
||||||
stakeholder.getTopics().stream()
|
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return new StakeholderFull(stakeholder,
|
||||||
|
stakeholder.getTopics().stream()
|
||||||
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) {
|
public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) {
|
||||||
if(stakeholder.getDefaultId() == null) {
|
if (stakeholder.getDefaultId() == null) {
|
||||||
stakeholder.setCopy(false);
|
stakeholder.setCopy(false);
|
||||||
if(copyId == null) {
|
if (copyId == null) {
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
Stakeholder copyFrom = this.findByPath(copyId);
|
Stakeholder copyFrom = this.findByPath(copyId);
|
||||||
|
@ -111,9 +107,9 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
if(stakeholder.isCopy()) {
|
if (stakeholder.isCopy()) {
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
if(defaultStakeholder != null) {
|
if (defaultStakeholder != null) {
|
||||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,9 +127,9 @@ public class StakeholderService {
|
||||||
});
|
});
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
if (old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
if(defaultStakeholder != null) {
|
if (defaultStakeholder != null) {
|
||||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue