[Trunk | Monitor Service]: Updated methods "saveBulkIndicators()" and "createSectionsAndSaveBulk()" to import List<Section<Indicator>> instead of List<Indicator>.

This commit is contained in:
Konstantina Galouni 2022-09-08 23:34:25 +03:00
parent 44f52c36d9
commit cddb8a2de1
1 changed files with 31 additions and 31 deletions

View File

@ -9,13 +9,10 @@ import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.*;
@RestController
@ -56,7 +53,7 @@ public class IndicatorController {
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestBody List<Indicator> indicators) throws UnsupportedEncodingException {
@RequestBody List<Section<Indicator>> sections) throws UnsupportedEncodingException {
log.debug("save bulk indicators");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
@ -64,42 +61,45 @@ public class IndicatorController {
Date date = new Date();
createSectionsAndSaveBulk(date, indicators, stakeholder, topicId, categoryId, subcategoryId);
createSectionsAndSaveBulk(date, sections, stakeholder, topicId, categoryId, subcategoryId);
// createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId);
return stakeholderController.setFullEntities(stakeholder, rolesUtils.getRoles());
}
private void createSectionsAndSaveBulk(Date date, List<Indicator> new_indicators,
private void createSectionsAndSaveBulk(Date date, List<Section<Indicator>> old_sections,
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
Section chart_section = null;
Section number_section = null;
for(Section<Indicator> section : old_sections) {
Section chart_section = null;
Section number_section = null;
List<String> chart_indicators = null;
List<String> number_indicators = null;
List<String> chart_indicators = null;
List<String> number_indicators = null;
for(Indicator indicator : new_indicators) {
if(indicator.getType().equals("chart")) {
if(chart_section == null) {
chart_section = createSection(chart_section, "chart", "Charts imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
chart_indicators = chart_section.getIndicators();
}
saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators);
} else if(indicator.getType().equals("number")) {
if(number_section == null) {
number_section = createSection(number_section, "number", "Numbers imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
number_indicators = number_section.getIndicators();
}
saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators);
if(section.getType().equals("chart")) {
chart_section = createSection(chart_section, "chart", (section.getTitle() != null ? section.getTitle() : "Charts")+" imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
chart_indicators = chart_section.getIndicators();
} else if(section.getType().equals("number")) {
number_section = createSection(number_section, "number", (section.getTitle() != null ? section.getTitle() : "Numbers")+ " imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
number_indicators = number_section.getIndicators();
}
}
if(chart_section != null) {
sectionDAO.save(chart_section);
}
if(number_section != null) {
sectionDAO.save(number_section);
List<Indicator> indicators = section.getIndicators();
for (Indicator indicator : indicators) {
if (indicator.getType().equals("chart")) {
saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators);
} else if (indicator.getType().equals("number")) {
saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators);
}
}
if (chart_section != null) {
sectionDAO.save(chart_section);
}
if (number_section != null) {
sectionDAO.save(number_section);
}
}
}
@ -112,7 +112,7 @@ public class IndicatorController {
section.setUpdateDate(date);
section.setCreationDate(date);
section.setIndicators(new ArrayList<>());
sectionController.saveSection(stakeholder.getId(), topicId, categoryId, subcategoryId, "-1", section);
section = sectionController.saveSection(stakeholder.getId(), topicId, categoryId, subcategoryId, "-1", section);
return section;
}