Project

General

Profile

« Previous | Next » 

Revision 57964

[Trunk | Monitor Service]:
1. Section entity level added. Hierarchy changed from: Stakeholder > Topic > Category > SubCategory > Indicator to: Stakeholder > Topic > Category > SubCategory > Section > Indicator.
2. Section.java & SectionDAO.java & MongoDBSectionDAO.java & SectionController.java: New entity 'Section', DAOs for Section, Controller for section added.
3. In all controllers fix hierarchy of model to include Section.
4. SubCategoryController.java & IndicatorController.java: Helper method 'checkForExceptions()' added (instead of checking in every method separately).

View differences:

StakeholderController.java
32 32
    private SubCategoryDAO subCategoryDAO;
33 33

  
34 34
    @Autowired
35
    private SectionDAO sectionDAO;
36

  
37
    @Autowired
35 38
    private IndicatorDAO indicatorDAO;
36 39

  
37 40
    @Autowired
38 41
    private TopicController topicController;
39 42

  
40 43
    @RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
41
    public Stakeholder<Topic<Category<SubCategory<Indicator>>>> buildFullStakeholder(@RequestBody Stakeholder<Topic<Category<SubCategory<Indicator>>>> stakeholderFull) {
44
    public Stakeholder<Topic<Category<SubCategory<Section<Indicator>>>>> buildFullStakeholder(@RequestBody Stakeholder<Topic<Category<SubCategory<Section<Indicator>>>>> stakeholderFull) {
42 45
        log.debug("build stakeholder");
43 46
        log.debug("Alias: "+stakeholderFull.getAlias());
44 47

  
45 48
        Stakeholder<String> stakeholder = new Stakeholder<>(stakeholderFull);
46 49

  
47 50
        List<String> topics = new ArrayList<>();
48
        List<Topic<Category<SubCategory<Indicator>>>> topicsFull = new ArrayList<>();
51
        List<Topic<Category<SubCategory<Section<Indicator>>>>> topicsFull = new ArrayList<>();
49 52
        for(Topic topic : stakeholderFull.getTopics()) {
50
            Topic<Category<SubCategory<Indicator>>> topicFull = topicController.buildTopic(topic);
53
            Topic<Category<SubCategory<Section<Indicator>>>> topicFull = topicController.buildTopic(topic);
51 54
            topicsFull.add(topicFull);
52 55
            topics.add(topicFull.getId());
53 56
        }
......
98 101
                        // EXCEPTION - SubCategory not found
99 102
                        throw new EntityNotFoundException("Get stakeholder: SubCategory with id: "+subCategoryId+" not found (subCategory exists in category: "+categoryId+")");
100 103
                    }
101
                    SubCategory subCategoryFull = new SubCategory<Indicator>(subCategory);
104
                    SubCategory subCategoryFull = new SubCategory<Section<Indicator>>(subCategory);
102 105

  
103
                    List<Indicator> charts = new ArrayList<>();
104
                    for(String indicatorId : subCategory.getCharts()) {
105
                        Indicator indicator = indicatorDAO.findById(indicatorId);
106
                        if(indicator == null) {
107
                            // EXCEPTION - Indicator not found
108
                            throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
109
                        }
110
                        charts.add(indicator);
106
                    List<Section> sectionsCharts = new ArrayList<>();
107

  
108
                    for(String sectionId : subCategory.getCharts()) {
109
                        sectionsCharts.add(getSectionFull(sectionId, subCategoryId));
111 110
                    }
112
                    subCategoryFull.setCharts(charts);
111
                    subCategoryFull.setCharts(sectionsCharts);
113 112

  
114
                    List<Indicator> numbers = new ArrayList<>();
115
                    for(String indicatorId : subCategory.getNumbers()) {
116
                        Indicator indicator = indicatorDAO.findById(indicatorId);
117
                        if(indicator == null) {
118
                            // EXCEPTION - Indicator not found
119
                            throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
120
                        }
121
                        numbers.add(indicator);
113
                    List<Section> sectionsNumbers = new ArrayList<>();
114

  
115
                    for(String sectionId : subCategory.getNumbers()) {
116
                        sectionsNumbers.add(getSectionFull(sectionId, subCategoryId));
122 117
                    }
123
                    subCategoryFull.setNumbers(numbers);
118
                    subCategoryFull.setNumbers(sectionsNumbers);
124 119

  
120
//                    List<Indicator> charts = new ArrayList<>();
121
//                    for(String indicatorId : subCategory.getCharts()) {
122
//                        Indicator indicator = indicatorDAO.findById(indicatorId);
123
//                        if(indicator == null) {
124
//                            // EXCEPTION - Indicator not found
125
//                            throw new EntityNotFoundException("Get stakeholder: Indicator with id: "+indicatorId+" not found (indicator exists in subCategory: "+subCategoryId+")");
126
//                        }
127
//                        charts.add(indicator);
128
//                    }
129
//                    subCategoryFull.setCharts(charts);
130
//
131
//                    List<Indicator> numbers = new ArrayList<>();
132
//                    for (String indicatorId : subCategory.getNumbers()) {
133
//                        Indicator indicator = indicatorDAO.findById(indicatorId);
134
//                        if (indicator == null) {
135
//                            // EXCEPTION - Indicator not found
136
//                            throw new EntityNotFoundException("Get stakeholder: Indicator with id: " + indicatorId + " not found (indicator exists in subCategory: " + subCategoryId + ")");
137
//                        }
138
//                        numbers.add(indicator);
139
//                    }
140
//                    subCategoryFull.setNumbers(numbers);
141

  
125 142
                    subCategories.add(subCategoryFull);
126 143
                }
127 144

  
......
137 154
        return stakeholderFull;
138 155
    }
139 156

  
157
    private Section getSectionFull(String sectionId, String subCategoryId) {
158
        Section<String> section = sectionDAO.findById(sectionId);
159
        if (section == null) {
160
            // EXCEPTION - Section not found
161
            throw new EntityNotFoundException("Get stakeholder: Section with id: " + sectionId + " not found (section exists in subCategory: " + subCategoryId + ")");
162
        }
163
        Section sectionFull = new Section<Indicator>(section);
164

  
165
        List<Indicator> indicators = new ArrayList<>();
166
        for (String indicatorId : section.getIndicators()) {
167
            Indicator indicator = indicatorDAO.findById(indicatorId);
168
            if (indicator == null) {
169
                // EXCEPTION - Indicator not found
170
                throw new EntityNotFoundException("Get stakeholder: Indicator with id: " + indicatorId + " not found (indicator exists in section: " + sectionId + ")");
171
            }
172
            indicators.add(indicator);
173
        }
174
        sectionFull.setIndicators(indicators);
175

  
176
        return sectionFull;
177
    }
178

  
140 179
    @RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
141 180
    public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) {
142 181
        log.debug("get all stakeholders" + (type != null ? " with type: "+type : ""));
......
275 314
                            throw new EntityNotFoundException("Delete stakeholder: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
276 315
                        }
277 316

  
278
                        for (String chartId : subcategory.getCharts()) {
279
                            indicatorDAO.delete(chartId);
317
                        for(String chartSectionId : subcategory.getCharts()) {
318
                            Section<String> chartSection = sectionDAO.findById(chartSectionId);
319
                            if (chartSection == null) {
320
                                // EXCEPTION - Section not found
321
                                throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
322
                            }
323

  
324
                            for (String chartId : chartSection.getIndicators()) {
325
                                indicatorDAO.delete(chartId);
326
                            }
327
                            subcategory.setCharts(null);
328
                            sectionDAO.delete(chartSectionId);
280 329
                        }
281
                        subcategory.setCharts(null);
282 330

  
283
                        for (String numberId : subcategory.getNumbers()) {
284
                            indicatorDAO.delete(numberId);
331
                        for(String numberSectionId : subcategory.getNumbers()) {
332
                            Section<String> numberSection = sectionDAO.findById(numberSectionId);
333
                            if (numberSection == null) {
334
                                // EXCEPTION - Section not found
335
                                throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
336
                            }
337

  
338
                            for (String numberId : numberSection.getIndicators()) {
339
                                indicatorDAO.delete(numberId);
340
                            }
341
                            subcategory.setNumbers(null);
342
                            sectionDAO.delete(numberSectionId);
285 343
                        }
286
                        subcategory.setNumbers(null);
287 344

  
288 345
                        subCategoryDAO.delete(subCategoryId);
289 346
                    }
......
306 363

  
307 364
    @RequestMapping(value = "/{stakeholderId}/toggle-status", method = RequestMethod.POST)
308 365
    public Boolean toggleStakeholderStatus(@PathVariable("stakeholderId") String stakeholderId) {
309
        log.debug("toggle indicator status (isActive)");
366
        log.debug("toggle stakeholder status (isActive)");
310 367
        log.debug("Stakeholder: "+stakeholderId);
311 368

  
312 369
        Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);
......
324 381

  
325 382
    @RequestMapping(value = "/{stakeholderId}/toggle-access", method = RequestMethod.POST)
326 383
    public Boolean toggleStakeholderAccess(@PathVariable("stakeholderId") String stakeholderId) {
327
        log.debug("toggle indicator access (isPublic)");
384
        log.debug("toggle stakeholder access (isPublic)");
328 385
        log.debug("Stakeholder: "+stakeholderId);
329 386

  
330 387
        Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId);

Also available in: Unified diff