Project

General

Profile

« Previous | Next » 

Revision 57923

1. pom.xml: Add dependency for "uoa-help-texts-library" (will be renamed).
2. UoaMonitorServiceApplication.java: Add @PropertySource path used in dl170.
3. MongoConnection.java: @EnableMongoRepositories not only from: eu.dnetlib.uoamonitorservice.dao, but also: eu.dnetlib.uoahelptexts.dao.
4. GoogleConfig.java & MailConfig.java: [Deleted]: Functionality available on library project.
5. EmailController.java: [New]: Used for contact-us page in portal.
6. ExceptionsHandler.java & /controllers/: Add more and detailed logs.
7. Stakeholder.java:
a. Field 'logoUrl' added.
b. Method 'getType()' returns type.name() and 'setType()' gets String and converts it into StakeholderType.
8. Topic.java & Category.java & SubCategory.java & Indicator.java:
a. Field 'boolean isDefault' changed to 'String defaultId'.
b. Method copyFromDefault() added to create a clone from default entity (topic, category, subcategory, indicator).
9. Category.java & SubCategory.java: Field 'String description' added.
10. SubCategory.java: Field 'String stakeholderId' added | method createOverviewSubCategory(Category) added.
11. Indicator.java & IndicatorPath.java: Method 'getType()' returns type.name() and 'setType()' gets String and converts it into IndicatorType / IndicatorPathType.
12. IndicatorPath.java: Constructor and copy constructor added.
13. StakeholderDAO.java & MongoDBStakeholderDAO.java:
a. Method findByIsDefaultProfile() changed to: findByDefaultId() & findByDefaultIdNot().
b. Method findByIsDefaultProfileAndType() changed to: findByDefaultIdAndType() & findByDefaultIdNotAndType().
14. SubCategoryDAO.java & MongoDBSubCategoryDAO.java & IndicatorDAO.java & MongoDBSubCategoryDAO.java: Method 'findByDefaultId()' added.
15. StakeholderController.java: Handle creationDate and updateDate | Add more exceptional cases.
16. TopicController.java:
a. Helper method 'onSaveDefaultTopic()' added (save cloned topic on stakeholders based on this default Stakeholder).
b. Helper method 'onUpdateDefaultTopic()' added (update cloned topics based on this default topic).
17. CategoryController.java:
a. Remove 'subCategory.setIsDefault(true);' when a category is created.
b. Helper method 'onSaveDefaultCategory()' added (save cloned category on topics based on this default Topic).
c. Helper method 'onUpdateDefaultCategory()' added (update cloned categories based on this default category).
18. SubCategoryController.java:
a. Helper method 'onSaveDefaultSubCategory()' added (save cloned subCategory on topics based on this default Category).
b. Helper method 'onUpdateDefaultSubCategory()' added (update cloned subCategories based on this default subCategory).
19. IndicatorController.java:
a. Helper method 'onSaveDefaultIndicator()' added (save cloned indicator on subCategories based on this default SubCategory).
b. Helper method 'onUpdateDefaultIndicator()' added (update cloned indicators based on this default indicator).
c. Helper method 'parameterMapping()' added to map correct parameter values on parameters depending on stakeholder info.
d. Method 'toggleIndicatorStatus()' added to toggle 'isActive' field.
e. Method 'toggleIndicatorAccess()' added to toggle 'isPublic' field.
f. Helper method 'toggleIndicator()' added to update indicator when a field is toggled.

View differences:

IndicatorController.java
12 12
import java.util.ArrayList;
13 13
import java.util.Iterator;
14 14
import java.util.List;
15
import java.util.Map;
15 16

  
16 17
@RestController
17 18
@CrossOrigin(origins = "*")
......
41 42
                                   @PathVariable("subcategoryId") String subcategoryId,
42 43
                                   @RequestBody Indicator indicator) {
43 44
        log.debug("save indicator");
45
        log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
44 46

  
45 47
//        if(stakeholderId == null) {
46 48
//            // EXCEPTION - Parameter for Stakeholder is not accepted
......
73 75
                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
74 76
                            if(subcategory != null) {
75 77
                                if (category.getSubCategories().contains(subcategoryId)) {
76
                                    Indicator indicatorSaved = indicatorDAO.save(indicator);
78
                                    String indicatorId = indicator.getId();
79
                                    indicatorDAO.save(indicator);
77 80

  
81
                                    // this indicator belongs in default profile and it is new or it is updated
82
                                    if(stakeholder.getDefaultId() == null) {
83
                                        if(indicatorId == null) {
84
                                            onSaveDefaultIndicator(indicator, topicId, categoryId, subcategoryId, stakeholder);
85
                                        }
86
                                        else {
87
                                            onUpdateDefaultIndicator(indicator, stakeholder);
88
                                        }
89
                                    }
90

  
78 91
                                    List<String> indicators = null;
79 92
                                    //if(indicator.hasType("chart")) {
80 93
                                    if(indicator.getType().equals("chart")) {
......
84 97
                                        indicators = subcategory.getNumbers();
85 98
                                    }
86 99

  
87
                                    int index = indicators.indexOf(indicatorSaved.getId());
100
                                    int index = indicators.indexOf(indicator.getId());
88 101
                                    if (index == -1) {
89
                                        indicators.add(indicatorSaved.getId());
102
                                        indicators.add(indicator.getId());
90 103
                                        subCategoryDAO.save(subcategory);
91 104
                                        log.debug("Indicator saved!");
92 105

  
93
                                        indicator.setId(indicatorSaved.getId());
106
                                        indicator.setId(indicator.getId());
94 107
                                    }
95 108
                                } else {
96 109
                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
......
123 136
        return indicator;
124 137
    }
125 138

  
139
    public void onSaveDefaultIndicator(Indicator indicator,
140
                                       String defaultTopicId, String defaultCategoryId,
141
                                       String defaultSubcategoryId, Stakeholder defaultStakeholder) {
142
        log.debug("On save default indicator");
143

  
144
//        List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholder.getId());
145
//        for(Stakeholder stakeholder : stakeholders) {
146
//            List<String> topicIds = stakeholder.getTopics();
147
//            Topic topic = null;
148
//            for(String topicId : topicIds) {
149
//                topic = topicDAO.findById(topicId);
150
//                if(topic.getDefaultId().equals(defaultTopicId)) {
151
//                    break;
152
//                }
153
//            }
154
//
155
//            List<String> categoryIds = topic.getCategories();
156
//            Category category = null;
157
//            for(String categoryId : categoryIds) {
158
//                category = categoryDAO.findById(categoryId);
159
//                if(category.getDefaultId().equals(defaultCategoryId)) {
160
//                    break;
161
//                }
162
//            }
163
//
164
//            List<String> subCategoryIds = category.getSubCategories();
165
//            SubCategory subCategory = null;
166
//            for(String subCategoryId : subCategoryIds) {
167
//                subCategory = subCategoryDAO.findById(subCategoryId);
168
//                if(subCategory.getDefaultId().equals(defaultSubcategoryId)) {
169
//                    break;
170
//                }
171
//            }
172
//
173
//            Indicator indicatorNew = new Indicator(indicator);
174
//            //indicatorNew.setStakeholderId(defaultStakeholder.getId());
175
//            for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
176
//                parameterMapping(indicatorPath, stakeholder);
177
//            }
178
//
179
//            indicatorDAO.save(indicatorNew);
180
//
181
//            List<String> indicators = null;
182
//            if (indicator.getType().equals("chart")) {
183
//                indicators = subCategory.getCharts();
184
//            } else if (indicator.getType().equals("number")) {
185
//                indicators = subCategory.getNumbers();
186
//            }
187
//            indicators.add(indicatorNew.getId());
188
//
189
//            subCategoryDAO.save(subCategory);
190
//        }
191

  
192

  
193
        // new indicator in default profile - add it on profiles of the same type
194
        List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
195

  
196
        for (SubCategory subCategory : subCategories) {
197
            Indicator indicatorNew = new Indicator();
198
            indicatorNew.copyFromDefault(indicator);
199
            for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) {
200
                Stakeholder stakeholder = stakeholderDAO.findById(subCategory.getStakeholderId());
201
                parameterMapping(indicatorPath, stakeholder);
202
            }
203

  
204
            indicatorDAO.save(indicatorNew);
205

  
206
            List<String> indicators = null;
207
            if (indicator.getType().equals("chart")) {
208
                indicators = subCategory.getCharts();
209
            } else if (indicator.getType().equals("number")) {
210
                indicators = subCategory.getNumbers();
211
            }
212
            indicators.add(indicatorNew.getId());
213

  
214
            subCategoryDAO.save(subCategory);
215
        }
216
    }
217

  
218
    public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) {
219
        log.debug("On update default indicator");
220

  
221
        // indicator already exists - check if changed and update all indicators based on it
222

  
223
        boolean changed = false;
224
        List<Indicator> indicators = indicatorDAO.findByDefaultId(indicator.getId());
225

  
226
        for(Indicator indicatorBasedOnDefault : indicators) {
227
            int i = 0;
228
            List<IndicatorPath> indicatorPaths = indicatorBasedOnDefault.getIndicatorPaths();
229

  
230
            for (IndicatorPath indicatorPath : indicator.getIndicatorPaths()) {
231
                IndicatorPath indicatorPathBasedOnDefault = indicatorBasedOnDefault.getIndicatorPaths().get(i);
232

  
233
                if(indicatorPathBasedOnDefault == null) {
234
                    // Add new indicator path in existing indicators
235
                    IndicatorPath indicatorPathNew = new IndicatorPath(indicatorPath);
236
                    parameterMapping(indicatorPathNew, stakeholder);
237
                    indicatorPaths.add(indicatorPathNew);
238
                    changed = true;
239
                } else {
240
                    // Check if there are changes in indicator path and update existing indicators if needed
241
                    if(!indicatorPath.getType().equals(indicatorPathBasedOnDefault.getType())) {
242
                        indicatorPathBasedOnDefault.setType(indicatorPath.getType());
243
                        changed = true;
244
                    }
245
                    if(!indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())) {
246
                        indicatorPathBasedOnDefault.setSource(indicatorPath.getSource());
247
                        changed = true;
248
                    }
249
                    if(!indicatorPath.getUrl().equals(indicatorPathBasedOnDefault.getUrl())) {
250
                        indicatorPathBasedOnDefault.setUrl(indicatorPath.getUrl());
251
                        changed = true;
252
                    }
253
                    if(!indicatorPath.getChartObject().equals(indicatorPathBasedOnDefault.getChartObject())) {
254
                        indicatorPathBasedOnDefault.setChartObject(indicatorPath.getChartObject());
255
                        changed = true;
256
                    }
257
                    if(indicatorPath.getParameters().size() != indicatorPathBasedOnDefault.getParameters().size()) {
258
                        for (Map.Entry<String, String> parameter : indicatorPath.getParameters().entrySet()) {
259
                            if(!indicatorPathBasedOnDefault.getParameters().containsKey(parameter.getKey())) {
260
                                indicatorPathBasedOnDefault.getParameters().put(parameter.getKey(), parameter.getValue());
261
                            }
262
                        }
263
                        parameterMapping(indicatorPathBasedOnDefault, stakeholder);
264
                        changed = true;
265
                    }
266
                    int j=0;
267
                    for(String jsonString : indicatorPath.getJsonPath()) {
268
                        String jsonStringBasedOnDefault = indicatorPathBasedOnDefault.getJsonPath().get(j);
269
                        if(!jsonString.equals(jsonStringBasedOnDefault)) {
270
                            indicatorPathBasedOnDefault.getJsonPath().set(j, jsonString);
271
                            changed = true;
272
                        }
273
                        j++;
274
                    }
275
                }
276
                i++;
277
            }
278
            if(!changed) {
279
                break;
280
            }
281
            indicatorDAO.save(indicatorBasedOnDefault);
282
        }
283
    }
284

  
285
    public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) {
286
        if (indicatorPath.getParameters().containsKey("funder_name")) {
287
            indicatorPath.getParameters().put("funder_name", stakeholder.getIndex_name());
288
        } else if (indicatorPath.getParameters().containsKey("fsn")) {
289
            indicatorPath.getParameters().put("fsn", stakeholder.getIndex_name().toLowerCase());
290
        } else if (indicatorPath.getParameters().containsKey("funder_id")) {
291
            indicatorPath.getParameters().put("funder_id", stakeholder.getIndex_id());
292
        }
293
    }
294

  
126 295
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/delete", method = RequestMethod.DELETE)
127 296
    public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
128 297
                                   @PathVariable("topicId") String topicId,
......
130 299
                                   @PathVariable("subcategoryId") String subcategoryId,
131 300
                                   @PathVariable("indicatorId") String indicatorId) {
132 301
        log.debug("delete indicator");
302
        log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
133 303

  
134 304
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
135 305

  
......
204 374

  
205 375
    @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE)
206 376
    public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) {
207
        log.debug("delete indicator");
377
        log.debug("delete all chart indicators of stakeholder");
378
        log.debug("Stakeholder: "+stakeholderId);
208 379

  
209 380
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
210 381
        if(stakeholder != null) {
......
265 436
        return true;
266 437
    }
267 438

  
268
//    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
269
//    public boolean reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
270
//                                             @PathVariable("topicId") String topicId,
271
//                                             @PathVariable("categoryId") String categoryId,
272
//                                             @PathVariable("subcategoryId") String subcategoryId,
273
//                                             @PathVariable("type") String type,
274
//                                             @RequestBody List<Indicator> indicatorsFull) {
275
//        log.debug("reorder indicators");
276
//
277
//        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
278
//
279
//        if (stakeholder != null) {
280
//
281
//            Topic<String> topic = topicDAO.findById(topicId);
282
//            if (topic != null) {
283
//                if (stakeholder.getTopics().contains(topicId)) {
284
//
285
//                    Category<String> category = categoryDAO.findById(categoryId);
286
//                    if (category != null) {
287
//                        if (topic.getCategories().contains(categoryId)) {
288
//
289
//                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
290
//                            if (subcategory != null) {
291
//                                if (category.getSubCategories().contains(subcategoryId)) {
292
//
293
//                                    List<String> indicators = new ArrayList<>();
294
//                                    for(Indicator indicator : indicatorsFull) {
295
//                                        indicators.add(indicator.getId());
296
//                                    }
297
//
298
//                                    if(type.equals("chart")) {
299
//                                        subcategory.setCharts(indicators);
300
//                                    } else if(type.equals("number")) {
301
//                                        subcategory.setNumbers(indicators);
302
//                                    }
303
//
304
//                                    subCategoryDAO.save(subcategory);
305
//                                    indicators = null;
306
//                                    log.debug("Indicators reordered!");
307
//                                } else {
308
//                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
309
//                                    throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
310
//                                }
311
//                            } else {
312
//                                // EXCEPTION - SubCategory not found
313
//                                throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
314
//                            }
315
//                        } else {
316
//                            // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
317
//                            throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
318
//                        }
319
//                    } else {
320
//                        // EXCEPTION - Category not found
321
//                        throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
322
//                    }
323
//                } else {
324
//                    // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
325
//                    throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
326
//                }
327
//            } else {
328
//                // EXCEPTION - Topic not found
329
//                throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
330
//            }
331
//        } else {
332
//            // EXCEPTION - Stakeholder not found
333
//            throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
334
//        }
335
//        return true;
336
//    }
337

  
338 439
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST)
339 440
    public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
340 441
                                     @PathVariable("topicId") String topicId,
......
342 443
                                     @PathVariable("subcategoryId") String subcategoryId,
343 444
                                     @PathVariable("type") String type,
344 445
                                     @RequestBody List<String> indicators) {
345
        log.debug("reorder indicators");
446
        log.debug("reorder indicators of type: "+type);
447
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId);
346 448

  
347 449
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
348 450

  
......
402 504
        }
403 505
        return indicatorsFull;
404 506
    }
507

  
508
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
509
    public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId,
510
                                         @PathVariable("topicId") String topicId,
511
                                         @PathVariable("categoryId") String categoryId,
512
                                         @PathVariable("subcategoryId") String subcategoryId,
513
                                         @PathVariable("indicatorId") String indicatorId) {
514
        log.debug("toggle indicator status (isActive)");
515
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
516

  
517
        Indicator indicator = indicatorDAO.findById(indicatorId);
518
        if (indicator == null) {
519
            // EXCEPTION - Indicator not found
520
            throw new EntityNotFoundException("Toggle indicator status: Indicator with id: "+indicatorId+" not found");
521
        }
522
        indicator.setIsActive(!indicator.getIsActive());
523

  
524
        this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
525

  
526
        return indicator.getIsActive();
527
    }
528

  
529
    @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
530
    public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
531
                                         @PathVariable("topicId") String topicId,
532
                                         @PathVariable("categoryId") String categoryId,
533
                                         @PathVariable("subcategoryId") String subcategoryId,
534
                                         @PathVariable("indicatorId") String indicatorId) {
535
        log.debug("toggle indicator access (isPublic)");
536
        log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId);
537

  
538
        Indicator indicator = indicatorDAO.findById(indicatorId);
539
        if (indicator == null) {
540
            // EXCEPTION - Indicator not found
541
            throw new EntityNotFoundException("Toggle indicator access: Indicator with id: "+indicatorId+" not found");
542
        }
543
        indicator.setIsPublic(!indicator.getIsPublic());
544

  
545
        this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator);
546

  
547
        return indicator.getIsPublic();
548
    }
549

  
550
    public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, Indicator indicator) {
551
        Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
552

  
553
        if (stakeholder != null) {
554

  
555
            Topic<String> topic = topicDAO.findById(topicId);
556
            if (topic != null) {
557
                if (stakeholder.getTopics().contains(topicId)) {
558

  
559
                    Category<String> category = categoryDAO.findById(categoryId);
560
                    if (category != null) {
561
                        if (topic.getCategories().contains(categoryId)) {
562

  
563
                            SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId);
564
                            if (subcategory != null) {
565
                                if (category.getSubCategories().contains(subcategoryId)) {
566
                                    indicatorDAO.save(indicator);
567
                                    log.debug("Indicator toggled!");
568
                                } else {
569
                                    // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias();
570
                                    throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
571
                                }
572
                            } else {
573
                                // EXCEPTION - SubCategory not found
574
                                throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
575
                            }
576
                        } else {
577
                            // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias();
578
                            throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
579
                        }
580
                    } else {
581
                        // EXCEPTION - Category not found
582
                        throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
583
                    }
584
                } else {
585
                    // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias();
586
                    throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
587
                }
588
            } else {
589
                // EXCEPTION - Topic not found
590
                throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
591
            }
592
        } else {
593
            // EXCEPTION - Stakeholder not found
594
            throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
595
        }
596
    }
405 597
}

Also available in: Unified diff