[Monitor Service | master]: Indicator.java: In method "copyFromDefault()", get visibility as parameter and set the visibility of the new-copied indicator accordingly | IndicatorController.java: When creating indicators copied from a new default indicator, set the visibility of each new indicator same as of its parent subcategory.

This commit is contained in:
Konstantina Galouni 2023-07-03 10:42:46 +03:00
parent 0184da8a8e
commit 09b8d2188f
2 changed files with 35 additions and 19 deletions

View File

@ -88,10 +88,10 @@ public class IndicatorController {
List<Indicator> indicators = section.getIndicators(); List<Indicator> indicators = section.getIndicators();
for (Indicator indicator : indicators) { for (Indicator indicator : indicators) {
if (indicator.getType().equals("chart")) { if (indicator.getType().equals("chart")) {
saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators); saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, chart_section, chart_indicators);
} else if (indicator.getType().equals("number")) { } else if (indicator.getType().equals("number")) {
saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators); saveIndicatorAndAddInSection(indicator, date, stakeholder, subcategoryId, number_section, number_indicators);
} }
} }
@ -118,14 +118,18 @@ public class IndicatorController {
return section; return section;
} }
private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List<String> indicators) throws UnsupportedEncodingException { // private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List<String> indicators) throws UnsupportedEncodingException {
// saveIndicatorAndAddInSection(indicator, date, stakeholder, section, indicators);
// }
private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, String subcategoryId, Section section, List<String> indicators) throws UnsupportedEncodingException {
// indicator does not exist in DB // indicator does not exist in DB
indicator.setCreationDate(date); indicator.setCreationDate(date);
indicator.setUpdateDate(date); indicator.setUpdateDate(date);
if (stakeholder.getDefaultId() == null) { // this indicator belongs in default profile and it is new if (stakeholder.getDefaultId() == null) { // this indicator belongs in default profile and it is new
indicatorDAO.save(indicator); indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, section.getId()); onSaveDefaultIndicator(indicator, section, subcategoryId);
} else { // this indicator belongs in a stakeholder's profile and it is new } else { // this indicator belongs in a stakeholder's profile and it is new
indicatorDAO.save(indicator); indicatorDAO.save(indicator);
} }
@ -168,7 +172,7 @@ public class IndicatorController {
if(stakeholder.getDefaultId() == null) { if(stakeholder.getDefaultId() == null) {
if(indicatorId == null) { if(indicatorId == null) {
indicatorDAO.save(indicator); indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, sectionId); onSaveDefaultIndicator(indicator, section, subcategoryId);
} }
else { else {
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator); onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
@ -190,26 +194,38 @@ public class IndicatorController {
return indicator; return indicator;
} }
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) throws UnsupportedEncodingException { public void onSaveDefaultIndicator(Indicator indicator, Section defaultSection, String defaultSubcategoryId) throws UnsupportedEncodingException {
log.debug("On save default indicator"); log.debug("On save default indicator");
// new indicator in default profile - add it on profiles of the same type // new indicator in default profile - add it on profiles of the same type
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId); List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
for (SubCategory subCategory : subCategories) {
for (Section section : sections) { List<String> sections = null;
Indicator indicatorNew = new Indicator(); if(defaultSection.getType().equals("chart")) {
indicatorNew.copyFromDefault(indicator); sections = subCategory.getCharts();
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { } else {
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias()); sections = subCategory.getNumbers();
parameterMapping(indicatorPath, stakeholder);
} }
indicatorDAO.save(indicatorNew); for (String sectionId : sections) {
Section section = sectionDAO.findById(sectionId);
if(section.getDefaultId().equals(defaultSection.getId())) {
Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator, subCategory.getVisibility());
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
parameterMapping(indicatorPath, stakeholder);
}
List<String> indicators = section.getIndicators(); indicatorDAO.save(indicatorNew);
indicators.add(indicatorNew.getId());
sectionDAO.save(section); List<String> indicators = section.getIndicators();
indicators.add(indicatorNew.getId());
sectionDAO.save(section);
}
}
} }
} }

View File

@ -36,7 +36,7 @@ public class Indicator {
private String defaultId; private String defaultId;
private List<IndicatorPath> indicatorPaths; private List<IndicatorPath> indicatorPaths;
public void copyFromDefault(Indicator defaultIndicator) { public void copyFromDefault(Indicator defaultIndicator, Visibility visibility) {
setName(defaultIndicator.getName()); setName(defaultIndicator.getName());
setDescription(defaultIndicator.getDescription()); setDescription(defaultIndicator.getDescription());
setAdditionalDescription(defaultIndicator.getAdditionalDescription()); setAdditionalDescription(defaultIndicator.getAdditionalDescription());
@ -44,7 +44,7 @@ public class Indicator {
setWidth(defaultIndicator.getWidth()); setWidth(defaultIndicator.getWidth());
setHeight(defaultIndicator.getHeight()); setHeight(defaultIndicator.getHeight());
setTags(defaultIndicator.getTags()); setTags(defaultIndicator.getTags());
setVisibility(Visibility.RESTRICTED); setVisibility(visibility);
setCreationDate(defaultIndicator.getCreationDate()); setCreationDate(defaultIndicator.getCreationDate());
setUpdateDate(defaultIndicator.getUpdateDate()); setUpdateDate(defaultIndicator.getUpdateDate());
setDefaultId(defaultIndicator.getId()); setDefaultId(defaultIndicator.getId());