[Trunk | Monitor Service]:

1. MonitorServiceCheckDeployController.java: In method "checkEverything()" (/health_check/advanced), added "Date of build" field with current date.
2. Indicator.java: In method "copyFromDefault()" set visibility of new indicator to "RESTRICTED" (instead of copying the default indicator's visibility).
3. IndicatorController.java: [NEW] Bulk add for indicators (imported from file) - get charts and numbers in a list and create chart and number sections to put them.
	a. Added API call  method "saveBulkIndicators()" (POST /{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk).
	b. Added helper methods "createSectionsAndSaveBulk()", "createSection()", "saveIndicatorAndAddInSection()".
This commit is contained in:
Konstantina Galouni 2021-07-21 09:46:49 +00:00
parent 44e325ddc7
commit 7d4273bea4
3 changed files with 92 additions and 1 deletions

View File

@ -44,6 +44,94 @@ public class IndicatorController {
@Autowired
private IndicatorDAO indicatorDAO;
@Autowired
private SectionController sectionController;
@Autowired
private StakeholderController stakeholderController;
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk", method = RequestMethod.POST)
public Stakeholder saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestBody List<Indicator> indicators) throws UnsupportedEncodingException {
log.debug("save bulk indicators");
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
Date date = new Date();
createSectionsAndSaveBulk(date, indicators, 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,
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
Section chart_section = null;
Section number_section = 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(chart_section != null) {
sectionDAO.save(chart_section);
}
if(number_section != null) {
sectionDAO.save(number_section);
}
}
private Section createSection(Section section, String type, String title, Date date,
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) {
section = new Section<>();
section.setType(type);
section.setTitle(title);
section.setStakeholderAlias(stakeholder.getAlias());
section.setUpdateDate(date);
section.setCreationDate(date);
section.setIndicators(new ArrayList<>());
sectionController.saveSection(stakeholder.getId(), topicId, categoryId, subcategoryId, "-1", section);
return section;
}
private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, 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());
} else { // this indicator belongs in a stakeholder's profile and it is new
indicatorDAO.save(indicator);
}
indicators.add(indicator.getId());
log.debug("Indicator saved!");
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)

View File

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -55,6 +56,8 @@ public class MonitorServiceCheckDeployController {
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
// response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
response.put("Date of build", new Date().toString());
return response;
}
}

View File

@ -44,7 +44,7 @@ public class Indicator {
setWidth(defaultIndicator.getWidth());
setHeight(defaultIndicator.getHeight());
setTags(defaultIndicator.getTags());
setVisibility(defaultIndicator.getVisibility());
setVisibility(Visibility.RESTRICTED);
setCreationDate(defaultIndicator.getCreationDate());
setUpdateDate(defaultIndicator.getUpdateDate());
setDefaultId(defaultIndicator.getId());