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

View File

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