Project

General

Profile

« Previous | Next » 

Revision 61440

[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()".

View differences:

modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Indicator.java
44 44
        setWidth(defaultIndicator.getWidth());
45 45
        setHeight(defaultIndicator.getHeight());
46 46
        setTags(defaultIndicator.getTags());
47
        setVisibility(defaultIndicator.getVisibility());
47
        setVisibility(Visibility.RESTRICTED);
48 48
        setCreationDate(defaultIndicator.getCreationDate());
49 49
        setUpdateDate(defaultIndicator.getUpdateDate());
50 50
        setDefaultId(defaultIndicator.getId());
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java
44 44
    @Autowired
45 45
    private IndicatorDAO indicatorDAO;
46 46

  
47
    @Autowired
48
    private SectionController sectionController;
47 49

  
50
    @Autowired
51
    private StakeholderController stakeholderController;
52

  
48 53
    @PreAuthorize("isAuthenticated()")
54
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk", method = RequestMethod.POST)
55
    public Stakeholder saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
56
                                        @PathVariable("topicId") String topicId,
57
                                        @PathVariable("categoryId") String categoryId,
58
                                        @PathVariable("subcategoryId") String subcategoryId,
59
                                        @RequestBody List<Indicator> indicators) throws UnsupportedEncodingException {
60
        log.debug("save bulk indicators");
61
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
62

  
63
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
64

  
65
        Date date = new Date();
66

  
67
        createSectionsAndSaveBulk(date, indicators, stakeholder, topicId, categoryId, subcategoryId);
68
//        createSectionAndSaveBulk(date, "number", "Numbers imported from file", number_indicators, stakeholder, topicId, categoryId, subcategoryId);
69

  
70
        return stakeholderController.setFullEntities(stakeholder, rolesUtils.getRoles());
71
    }
72

  
73
    private void createSectionsAndSaveBulk(Date date, List<Indicator> new_indicators,
74
                                          Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) throws UnsupportedEncodingException {
75
        Section chart_section = null;
76
        Section number_section = null;
77

  
78
        List<String> chart_indicators = null;
79
        List<String> number_indicators = null;
80

  
81
        for(Indicator indicator : new_indicators) {
82
            if(indicator.getType().equals("chart")) {
83
                if(chart_section == null) {
84
                    chart_section = createSection(chart_section, "chart", "Charts imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
85
                    chart_indicators = chart_section.getIndicators();
86
                }
87
                saveIndicatorAndAddInSection(indicator, date, stakeholder, chart_section, chart_indicators);
88

  
89
            } else if(indicator.getType().equals("number")) {
90
                if(number_section == null) {
91
                    number_section = createSection(number_section, "number", "Numbers imported from file", date, stakeholder, topicId, categoryId, subcategoryId);
92
                    number_indicators = number_section.getIndicators();
93
                }
94
                saveIndicatorAndAddInSection(indicator, date, stakeholder, number_section, number_indicators);
95
            }
96
        }
97

  
98
        if(chart_section != null) {
99
            sectionDAO.save(chart_section);
100
        }
101
        if(number_section != null) {
102
            sectionDAO.save(number_section);
103
        }
104
    }
105

  
106
    private Section createSection(Section section, String type, String title, Date date,
107
                                  Stakeholder stakeholder, String topicId, String categoryId, String subcategoryId) {
108
        section = new Section<>();
109
        section.setType(type);
110
        section.setTitle(title);
111
        section.setStakeholderAlias(stakeholder.getAlias());
112
        section.setUpdateDate(date);
113
        section.setCreationDate(date);
114
        section.setIndicators(new ArrayList<>());
115
        sectionController.saveSection(stakeholder.getId(), topicId, categoryId, subcategoryId, "-1", section);
116

  
117
        return section;
118
    }
119

  
120
    private void saveIndicatorAndAddInSection(Indicator indicator, Date date, Stakeholder stakeholder, Section section, List<String> indicators) throws UnsupportedEncodingException {
121
        // indicator does not exist in DB
122
        indicator.setCreationDate(date);
123
        indicator.setUpdateDate(date);
124

  
125
        if (stakeholder.getDefaultId() == null) {   // this indicator belongs in default profile and it is new
126
            indicatorDAO.save(indicator);
127
            onSaveDefaultIndicator(indicator, section.getId());
128
        } else {    // this indicator belongs in a stakeholder's profile and it is new
129
            indicatorDAO.save(indicator);
130
        }
131

  
132
        indicators.add(indicator.getId());
133
        log.debug("Indicator saved!");
134
    }
135

  
136
    @PreAuthorize("isAuthenticated()")
49 137
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
50 138
    public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId,
51 139
                                   @PathVariable("topicId") String topicId,
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java
14 14
import org.springframework.web.bind.annotation.RequestMethod;
15 15
import org.springframework.web.bind.annotation.RestController;
16 16

  
17
import java.util.Date;
17 18
import java.util.HashMap;
18 19
import java.util.Map;
19 20

  
......
55 56
        response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
56 57
//        response.put("Define also", "monitorservice.mongodb.username, monitorservice.mongodb.password");
57 58

  
59
        response.put("Date of build", new Date().toString());
60

  
58 61
        return response;
59 62
    }
60 63
}

Also available in: Unified diff