diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index 1a325d8..b6cda27 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -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; diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index 9547f07..faa7cb6 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -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 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 saveStakeholder(@RequestBody Stakeholder 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 stakeholder = new Stakeholder<>(stakeholderFull); + Stakeholder stakeholder = new Stakeholder<>(_stakeholder); Date date = new Date(); stakeholder.setUpdateDate(date); @@ -495,17 +497,17 @@ public class StakeholderController { List 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 oldStakeholder = stakeholderDAO.findById(stakeholderFull.getId()); + Stakeholder 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 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()")