[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();
for (Indicator indicator : indicators) {
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")) {
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;
}
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.setCreationDate(date);
indicator.setUpdateDate(date);
if (stakeholder.getDefaultId() == null) { // this indicator belongs in default profile and it is new
indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, section.getId());
onSaveDefaultIndicator(indicator, section, subcategoryId);
} else { // this indicator belongs in a stakeholder's profile and it is new
indicatorDAO.save(indicator);
}
@ -168,7 +172,7 @@ public class IndicatorController {
if(stakeholder.getDefaultId() == null) {
if(indicatorId == null) {
indicatorDAO.save(indicator);
onSaveDefaultIndicator(indicator, sectionId);
onSaveDefaultIndicator(indicator, section, subcategoryId);
}
else {
onUpdateDefaultIndicator(indicator, stakeholder, oldIndicator);
@ -190,26 +194,38 @@ public class IndicatorController {
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");
// 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) {
Indicator indicatorNew = new Indicator();
indicatorNew.copyFromDefault(indicator);
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
parameterMapping(indicatorPath, stakeholder);
List<String> sections = null;
if(defaultSection.getType().equals("chart")) {
sections = subCategory.getCharts();
} else {
sections = subCategory.getNumbers();
}
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();
indicators.add(indicatorNew.getId());
indicatorDAO.save(indicatorNew);
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 List<IndicatorPath> indicatorPaths;
public void copyFromDefault(Indicator defaultIndicator) {
public void copyFromDefault(Indicator defaultIndicator, Visibility visibility) {
setName(defaultIndicator.getName());
setDescription(defaultIndicator.getDescription());
setAdditionalDescription(defaultIndicator.getAdditionalDescription());
@ -44,7 +44,7 @@ public class Indicator {
setWidth(defaultIndicator.getWidth());
setHeight(defaultIndicator.getHeight());
setTags(defaultIndicator.getTags());
setVisibility(Visibility.RESTRICTED);
setVisibility(visibility);
setCreationDate(defaultIndicator.getCreationDate());
setUpdateDate(defaultIndicator.getUpdateDate());
setDefaultId(defaultIndicator.getId());