[Trunk | Monitor Service]:

1. StakeholderController.java: 
	a. Method "getMyRealStakeholders()" (/my-stakeholder) returns basic Stakeholder info (Topics are not full object anymore).
	b. Method "saveStakeholder()" (/save) gets basic or full object for Stakeholder and returns whatever format it received.
2. IndicatorController.java: [Bug fix] In method "onUpdateDefaultIndicator()" improve checks (there were missing cases, e.g. chartObject of previous-saved indicatorPath was null).
This commit is contained in:
Konstantina Galouni 2020-12-22 09:29:17 +00:00
parent 38a5a09d8a
commit d6901a49f7
2 changed files with 95 additions and 46 deletions

View File

@ -135,22 +135,39 @@ public class IndicatorController {
for(Indicator indicatorBasedOnDefault : indicators) {
changed = false;
if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
&& (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
// if(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName())
// && (oldIndicator.getName() == null || oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))) {
if((
(indicator.getName() == null && oldIndicator.getName() != null)
||
(indicator.getName() != null && !indicator.getName().equals(indicatorBasedOnDefault.getName()))
) && (
(oldIndicator.getName() == null && indicatorBasedOnDefault.getName() == null)
||
(oldIndicator.getName() != null && oldIndicator.getName().equals(indicatorBasedOnDefault.getName()))
)) {
indicatorBasedOnDefault.setName(indicator.getName());
changed = true;
}
if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())) {
if(indicator.getDescription() != null && !indicator.getDescription().equals(indicatorBasedOnDefault.getDescription())
|| indicator.getDescription() == null && indicatorBasedOnDefault.getDescription() != null) {
indicatorBasedOnDefault.setDescription(indicator.getDescription());
changed = true;
}
if(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription())
&& (oldIndicator.getAdditionalDescription() == null || oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))) {
// if(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription())
// && (oldIndicator.getAdditionalDescription() == null || oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))) {
if((
(indicator.getAdditionalDescription() == null && oldIndicator.getAdditionalDescription() != null)
||
(indicator.getAdditionalDescription() != null && !indicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
) && (
(oldIndicator.getAdditionalDescription() == null && indicatorBasedOnDefault.getAdditionalDescription() == null)
||
(oldIndicator.getAdditionalDescription() != null && oldIndicator.getAdditionalDescription().equals(indicatorBasedOnDefault.getAdditionalDescription()))
)) {
indicatorBasedOnDefault.setAdditionalDescription(indicator.getAdditionalDescription());
changed = true;
}
@ -179,36 +196,66 @@ public class IndicatorController {
// Check if there are changes in indicator path and update existing indicators if needed
log.debug("update indicator path: "+i + " (indicator id: "+indicatorBasedOnDefault.getId()+")");
if(indicatorPath.getType() != null
&& !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
&& (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
// if(indicatorPath.getType() != null
// && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())
// && (oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))) {
if((
(indicatorPath.getType() == null && oldIndicatorPath.getType() != null)
||
(indicatorPath.getType() != null && !indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
) && (
(oldIndicatorPath.getType() == null && indicatorPathBasedOnDefault.getType() == null)
||
(oldIndicatorPath.getType() != null && oldIndicatorPath.getType().equals(indicatorPathBasedOnDefault.getType()))
)) {
indicatorPathBasedOnDefault.setType(indicatorPath.getType());
changed = true; // parameter "type" needs to be changed as well
}
log.debug("After type check: "+changed);
if(indicatorPath.getSource() != null
&& !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
&& (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {
// if(indicatorPath.getSource() != null
// && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
// && (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {
if((
(indicatorPath.getSource() == null && oldIndicatorPath.getSource() != null)
||
(indicatorPath.getSource() != null && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
) && (
(oldIndicatorPath.getSource() == null && indicatorPathBasedOnDefault.getSource() == null)
||
(oldIndicatorPath.getSource() != null && oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))
)) {
indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
changed = true;
}
log.debug("After source check: "+changed);
if(indicatorPath.getUrl() != null
&& !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
&& (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
// if(indicatorPath.getUrl() != null
// && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())
// && (oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))) {
if((
(indicatorPath.getUrl() == null && oldIndicatorPath.getUrl() != null)
||
(indicatorPath.getUrl() != null && !indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
) && (
(oldIndicatorPath.getUrl() == null && indicatorPathBasedOnDefault.getUrl() == null)
||
(oldIndicatorPath.getUrl() != null && oldIndicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl()))
)) {
indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
changed = true;
}
log.debug("After url check: "+changed);
if(indicatorPath.getChartObject() != null
&& !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())
&& (oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))) {
if((
(indicatorPath.getChartObject() == null && oldIndicatorPath.getChartObject() != null)
||
(indicatorPath.getChartObject() != null && !indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
) && (
(oldIndicatorPath.getChartObject() == null && indicatorPathBasedOnDefault.getChartObject() == null)
||
(oldIndicatorPath.getChartObject() != null && oldIndicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject()))
)) {
indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
changed = true;

View File

@ -409,10 +409,11 @@ public class StakeholderController {
// if (roles.contains(authorizationService.PORTAL_ADMIN)) {
if (rolesUtils.isPortalAdmin(roles)) {
for(Stakeholder stakeholder : stakeholders) {
stakeholdersFull.add(this.setFullEntities(stakeholder, roles));
}
return stakeholdersFull;
// for(Stakeholder stakeholder : stakeholders) {
// stakeholdersFull.add(this.setFullEntities(stakeholder, roles));
// }
// return stakeholdersFull;
return stakeholders;
}
Iterator<Stakeholder> stakeholderIterator = stakeholders.iterator();
@ -423,16 +424,17 @@ public class StakeholderController {
// || roles.contains(authorizationService.manager(stakeholder.getType(), stakeholder.getAlias()))) {
if(rolesUtils.isCurator(roles, stakeholder.getType())
|| rolesUtils.isManager(roles, stakeholder.getType(), stakeholder.getAlias())) {
stakeholdersFull.add(this.setFullEntities(stakeholder, roles));
//stakeholdersFull.add(this.setFullEntities(stakeholder, roles));
continue;
} else {
stakeholderIterator.remove();
}
stakeholderIterator.remove();
}
}
// log.debug(new Date());
return stakeholdersFull;
return stakeholders;
}
@RequestMapping(value = "/stakeholder/{alias}", method = RequestMethod.GET)
@ -474,20 +476,20 @@ public class StakeholderController {
// @PreAuthorize("isAuthenticated()")
@PreAuthorize("hasAnyAuthority("
+ "@AuthorizationService.PORTAL_ADMIN, "
+ "@AuthorizationService.curator(#stakeholderFull.getType()), "
+ "@AuthorizationService.manager(#stakeholderFull.getType(), #stakeholderFull.getAlias()) "
+ "@AuthorizationService.curator(#_stakeholder.getType()), "
+ "@AuthorizationService.manager(#_stakeholder.getType(), #_stakeholder.getAlias()) "
+ ")")
@RequestMapping(value = "/save", method = RequestMethod.POST)
public Stakeholder<Topic> saveStakeholder(@RequestBody Stakeholder<Topic> stakeholderFull) {
public Stakeholder saveStakeholder(@RequestBody Stakeholder _stakeholder) {
log.debug("save stakeholder");
log.debug("Alias: "+stakeholderFull.getAlias() + " - Id: "+stakeholderFull.getId());
log.debug("Alias: "+_stakeholder.getAlias() + " - Id: "+_stakeholder.getId());
// if(stakeholderFull == null) {
// if(_stakeholder == null) {
// log.debug("stakeholder null");
// // EXCEPTION - Parameter for Stakeholder is not accepted
// }
Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
Stakeholder<String> stakeholder = new Stakeholder<>(_stakeholder);
Date date = new Date();
stakeholder.setUpdateDate(date);
@ -495,17 +497,17 @@ public class StakeholderController {
List<String> topics = new ArrayList<>();
// stakeholder does not exist in DB
if(stakeholderFull.getId() == null) {
if(_stakeholder.getId() == null) {
stakeholder.setCreationDate(date);
for(Topic topic : stakeholderFull.getTopics()) {
topics.add(topic.getId());
}
// for(Topic topic : _stakeholder.getTopics()) {
// topics.add(topic.getId());
// }
} else {
Stakeholder<String> oldStakeholder = stakeholderDAO.findById(stakeholderFull.getId());
Stakeholder<String> oldStakeholder = stakeholderDAO.findById(_stakeholder.getId());
if(oldStakeholder == null) {
// EXCEPTION - Stakeholder not found
throw new EntityNotFoundException("save stakeholder: Stakeholder with id: "+stakeholderFull.getId()+" not found");
throw new EntityNotFoundException("save stakeholder: Stakeholder with id: "+_stakeholder.getId()+" not found");
}
for(String topicId : oldStakeholder.getTopics()) {
Topic topic = topicDAO.findById(topicId);
@ -516,21 +518,21 @@ public class StakeholderController {
topics.add(topic.getId());
}
// stakeholder.setTopics(topics);
// stakeholderFull = this.setFullEntities(stakeholder, rolesUtils.getRoles());
// _stakeholder = this.setFullEntities(stakeholder, rolesUtils.getRoles());
}
stakeholder.setTopics(topics);
Stakeholder<String> stakeholderSaved = stakeholderDAO.save(stakeholder);
stakeholderFull.setId(stakeholderSaved.getId());
stakeholderFull.setCreationDate(stakeholderSaved.getCreationDate());
stakeholderFull.setUpdateDate(stakeholderSaved.getUpdateDate());
_stakeholder.setId(stakeholderSaved.getId());
_stakeholder.setCreationDate(stakeholderSaved.getCreationDate());
_stakeholder.setUpdateDate(stakeholderSaved.getUpdateDate());
topics = null;
stakeholder = null;
stakeholderSaved = null;
return stakeholderFull;
return _stakeholder;
}
@PreAuthorize("isAuthenticated()")