Merge branch 'master' of code-repo.d4science.org:MaDgIK/uoa-monitor-service
This commit is contained in:
commit
e7c32e0efc
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-monitor-service</artifactId>
|
<artifactId>uoa-monitor-service</artifactId>
|
||||||
<version>1.0.2-SNAPSHOT</version>
|
<version>1.0.3-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>uoa-monitor-service</name>
|
<name>uoa-monitor-service</name>
|
||||||
<scm>
|
<scm>
|
||||||
|
|
|
@ -9,13 +9,10 @@ import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -56,7 +53,7 @@ public class IndicatorController {
|
||||||
@PathVariable("topicId") String topicId,
|
@PathVariable("topicId") String topicId,
|
||||||
@PathVariable("categoryId") String categoryId,
|
@PathVariable("categoryId") String categoryId,
|
||||||
@PathVariable("subcategoryId") String subcategoryId,
|
@PathVariable("subcategoryId") String subcategoryId,
|
||||||
@RequestBody List<Indicator> indicators) throws UnsupportedEncodingException {
|
@RequestBody List<Section<Indicator>> sections) throws UnsupportedEncodingException {
|
||||||
log.debug("save bulk indicators");
|
log.debug("save bulk indicators");
|
||||||
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
|
||||||
|
|
||||||
|
@ -64,44 +61,47 @@ public class IndicatorController {
|
||||||
|
|
||||||
Date date = new Date();
|
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);
|
// createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId);
|
||||||
|
|
||||||
return stakeholderController.setFullEntities(stakeholder, rolesUtils.getRoles());
|
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 {
|
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
|
||||||
|
for(Section<Indicator> section : old_sections) {
|
||||||
Section chart_section = null;
|
Section chart_section = null;
|
||||||
Section number_section = null;
|
Section number_section = null;
|
||||||
|
|
||||||
List<String> chart_indicators = null;
|
List<String> chart_indicators = null;
|
||||||
List<String> number_indicators = null;
|
List<String> number_indicators = null;
|
||||||
|
|
||||||
for(Indicator indicator : new_indicators) {
|
if(section.getType().equals("chart")) {
|
||||||
if(indicator.getType().equals("chart")) {
|
chart_section = createSection(chart_section, "chart", (section.getTitle() != null ? section.getTitle() : "Charts")+" imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
|
||||||
if(chart_section == null) {
|
|
||||||
chart_section = createSection(chart_section, "chart", "Charts imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
|
|
||||||
chart_indicators = chart_section.getIndicators();
|
chart_indicators = chart_section.getIndicators();
|
||||||
}
|
} else if(section.getType().equals("number")) {
|
||||||
saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators);
|
number_section = createSection(number_section, "number", (section.getTitle() != null ? section.getTitle() : "Numbers")+ " imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
|
||||||
|
|
||||||
} 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();
|
number_indicators = number_section.getIndicators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chart_section != null) {
|
if (chart_section != null) {
|
||||||
sectionDAO.save(chart_section);
|
sectionDAO.save(chart_section);
|
||||||
}
|
}
|
||||||
if(number_section != null) {
|
if (number_section != null) {
|
||||||
sectionDAO.save(number_section);
|
sectionDAO.save(number_section);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Section createSection(Section section, String type, String title, Date date,
|
private Section createSection(Section section, String type, String title, Date date,
|
||||||
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) {
|
Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) {
|
||||||
|
@ -112,7 +112,7 @@ public class IndicatorController {
|
||||||
section.setUpdateDate(date);
|
section.setUpdateDate(date);
|
||||||
section.setCreationDate(date);
|
section.setCreationDate(date);
|
||||||
section.setIndicators(new ArrayList<>());
|
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;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue