Revision 57964
Added by Konstantina Galouni over 4 years ago
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.entities.Section; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface SectionDAO { |
|
8 |
List<Section> findAll(); |
|
9 |
List<Section> findByDefaultId(String DefaultId); |
|
10 |
|
|
11 |
Section findById(String Id); |
|
12 |
|
|
13 |
void delete(String Id); |
|
14 |
|
|
15 |
Section save(Section indicator); |
|
16 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/dao/MongoDBSectionDAO.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.dao; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.entities.Section; |
|
4 |
import org.springframework.data.mongodb.repository.MongoRepository; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface MongoDBSectionDAO extends SectionDAO, MongoRepository<Section, String> { |
|
9 |
List<Section> findAll(); |
|
10 |
List<Section> findByDefaultId(String DefaultId); |
|
11 |
|
|
12 |
Section findById(String Id); |
|
13 |
|
|
14 |
void delete(String Id); |
|
15 |
|
|
16 |
Section save(Section indicator); |
|
17 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/Section.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.entities; |
|
2 |
|
|
3 |
import com.fasterxml.jackson.annotation.JsonProperty; |
|
4 |
import org.springframework.data.annotation.Id; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
enum SectionType { |
|
9 |
// Do not rename or remove existring values. This may cause problems with already stored values in DB |
|
10 |
number, chart; |
|
11 |
} |
|
12 |
|
|
13 |
public class Section<StringOrIndicator> { |
|
14 |
@Id |
|
15 |
@JsonProperty("_id") |
|
16 |
private String id; |
|
17 |
|
|
18 |
private String title; |
|
19 |
private String defaultId; |
|
20 |
private String stakeholderAlias; |
|
21 |
private SectionType type; |
|
22 |
private List<StringOrIndicator> indicators; |
|
23 |
|
|
24 |
public Section() {} |
|
25 |
|
|
26 |
public Section(Section section) { |
|
27 |
id = section.getId(); |
|
28 |
title = section.getTitle(); |
|
29 |
defaultId = section.getDefaultId(); |
|
30 |
stakeholderAlias = section.getStakeholderAlias(); |
|
31 |
setType(section.getType()); |
|
32 |
} |
|
33 |
|
|
34 |
public void copyFromDefault(Section defaultSection) { |
|
35 |
setTitle(defaultSection.getTitle()); |
|
36 |
setType(defaultSection.getType()); |
|
37 |
setDefaultId(defaultSection.id); |
|
38 |
} |
|
39 |
|
|
40 |
public String getId() { |
|
41 |
return id; |
|
42 |
} |
|
43 |
|
|
44 |
public void setId(String id) { |
|
45 |
this.id = id; |
|
46 |
} |
|
47 |
|
|
48 |
public String getTitle() { |
|
49 |
return title; |
|
50 |
} |
|
51 |
|
|
52 |
public void setTitle(String title) { |
|
53 |
this.title = title; |
|
54 |
} |
|
55 |
|
|
56 |
public String getDefaultId() { |
|
57 |
return defaultId; |
|
58 |
} |
|
59 |
|
|
60 |
public void setDefaultId(String defaultId) { |
|
61 |
this.defaultId = defaultId; |
|
62 |
} |
|
63 |
|
|
64 |
public String getStakeholderAlias() { |
|
65 |
return stakeholderAlias; |
|
66 |
} |
|
67 |
|
|
68 |
public void setStakeholderAlias(String stakeholderAlias) { |
|
69 |
this.stakeholderAlias = stakeholderAlias; |
|
70 |
} |
|
71 |
|
|
72 |
public String getType() { |
|
73 |
if(type == null) { |
|
74 |
return null; |
|
75 |
} |
|
76 |
return type.name(); |
|
77 |
} |
|
78 |
|
|
79 |
public void setType(String type) { |
|
80 |
if(type == null) { |
|
81 |
this.type = null; |
|
82 |
} else { |
|
83 |
SectionType sectionType = SectionType.valueOf(type); |
|
84 |
this.type = sectionType; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
public List<StringOrIndicator> getIndicators() { |
|
89 |
return indicators; |
|
90 |
} |
|
91 |
|
|
92 |
public void setIndicators(List<StringOrIndicator> indicators) { |
|
93 |
this.indicators = indicators; |
|
94 |
} |
|
95 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/SubCategory.java | ||
---|---|---|
6 | 6 |
import java.util.ArrayList; |
7 | 7 |
import java.util.List; |
8 | 8 |
|
9 |
public class SubCategory<StringOrIndicator> {
|
|
9 |
public class SubCategory<StringOrSection> {
|
|
10 | 10 |
@Id |
11 | 11 |
@JsonProperty("_id") |
12 | 12 |
private String id; |
... | ... | |
17 | 17 |
private boolean isActive; |
18 | 18 |
private boolean isPublic; |
19 | 19 |
private String defaultId; |
20 |
private String stakeholderId; |
|
21 |
private List<StringOrIndicator> charts; |
|
22 |
private List<StringOrIndicator> numbers; |
|
20 |
private List<StringOrSection> charts; |
|
21 |
private List<StringOrSection> numbers; |
|
23 | 22 |
|
24 | 23 |
public SubCategory() {} |
25 | 24 |
public SubCategory(SubCategory subCategory) { |
... | ... | |
108 | 107 |
this.defaultId = defaultId; |
109 | 108 |
} |
110 | 109 |
|
111 |
public String getStakeholderId() { |
|
112 |
return stakeholderId; |
|
113 |
} |
|
114 |
|
|
115 |
public void setStakeholderId(String stakeholderId) { |
|
116 |
this.stakeholderId = stakeholderId; |
|
117 |
} |
|
118 |
|
|
119 |
public List<StringOrIndicator> getCharts() { |
|
110 |
public List<StringOrSection> getCharts() { |
|
120 | 111 |
return charts; |
121 | 112 |
} |
122 | 113 |
|
123 |
public void setCharts(List<StringOrIndicator> charts) {
|
|
114 |
public void setCharts(List<StringOrSection> charts) {
|
|
124 | 115 |
this.charts = charts; |
125 | 116 |
} |
126 | 117 |
|
127 |
public List<StringOrIndicator> getNumbers() {
|
|
118 |
public List<StringOrSection> getNumbers() {
|
|
128 | 119 |
return numbers; |
129 | 120 |
} |
130 | 121 |
|
131 |
public void setNumbers(List<StringOrIndicator> numbers) {
|
|
122 |
public void setNumbers(List<StringOrSection> numbers) {
|
|
132 | 123 |
this.numbers = numbers; |
133 | 124 |
} |
134 | 125 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
public class IndicatorPath { |
12 | 12 |
private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc} |
13 |
private String source; // for numbers is the service {statistics, search, metrics} for charts is the tool {stats-tool,old,metrics, fake}
|
|
13 |
private String source; // for numbers is the service {statistics, search, metrics} for charts is the tool {stats-tool,old,metrics, image}
|
|
14 | 14 |
private String url; |
15 | 15 |
private List<String> jsonPath; |
16 | 16 |
private String chartObject; |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java | ||
---|---|---|
10 | 10 |
import org.springframework.web.bind.annotation.*; |
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.Iterator; |
|
14 | 13 |
import java.util.List; |
15 | 14 |
import java.util.Map; |
16 | 15 |
|
... | ... | |
32 | 31 |
private SubCategoryDAO subCategoryDAO; |
33 | 32 |
|
34 | 33 |
@Autowired |
34 |
private SectionDAO sectionDAO; |
|
35 |
|
|
36 |
@Autowired |
|
35 | 37 |
private IndicatorDAO indicatorDAO; |
36 | 38 |
|
37 | 39 |
|
38 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save", method = RequestMethod.POST) |
|
40 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
|
|
39 | 41 |
public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId, |
40 | 42 |
@PathVariable("topicId") String topicId, |
41 | 43 |
@PathVariable("categoryId") String categoryId, |
42 | 44 |
@PathVariable("subcategoryId") String subcategoryId, |
45 |
@PathVariable("sectionId") String sectionId, |
|
43 | 46 |
@RequestBody Indicator indicator) { |
44 | 47 |
log.debug("save indicator"); |
45 |
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
48 |
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
46 | 49 |
|
47 |
// if(stakeholderId == null) { |
|
48 |
// // EXCEPTION - Parameter for Stakeholder is not accepted |
|
49 |
// } |
|
50 |
// if(topicId == null) { |
|
51 |
// // EXCEPTION - Parameter for Topic is not accepted |
|
52 |
// } |
|
53 |
// if(categoryId == null) { |
|
54 |
// // EXCEPTION - Parameter for Category is not accepted |
|
55 |
// } |
|
56 |
// if(subcategoryId == null) { |
|
57 |
// // EXCEPTION - Parameter for SubCategory is not accepted |
|
58 |
// } |
|
59 |
// if(indicator == null) { |
|
60 |
// // EXCEPTION - Parameter for Indicator is not accepted |
|
61 |
// } |
|
50 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
62 | 51 |
|
52 |
String indicatorId = indicator.getId(); |
|
53 |
indicatorDAO.save(indicator); |
|
54 |
|
|
63 | 55 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
56 |
// this indicator belongs in default profile and it is new or it is updated |
|
57 |
if(stakeholder.getDefaultId() == null) { |
|
58 |
if(indicatorId == null) { |
|
59 |
onSaveDefaultIndicator(indicator, sectionId); |
|
60 |
} |
|
61 |
else { |
|
62 |
onUpdateDefaultIndicator(indicator, stakeholder); |
|
63 |
} |
|
64 |
} |
|
64 | 65 |
|
65 |
if(stakeholder != null) {
|
|
66 |
List<String> indicators = section.getIndicators();
|
|
66 | 67 |
|
67 |
Topic<String> topic = topicDAO.findById(topicId); |
|
68 |
if(topic != null) { |
|
69 |
if(stakeholder.getTopics().contains(topicId)) { |
|
68 |
int index = indicators.indexOf(indicator.getId()); |
|
69 |
if (index == -1) { |
|
70 |
indicators.add(indicator.getId()); |
|
71 |
sectionDAO.save(section); |
|
72 |
log.debug("Indicator saved!"); |
|
73 |
} |
|
70 | 74 |
|
71 |
Category<String> category = categoryDAO.findById(categoryId); |
|
72 |
if(category != null) { |
|
73 |
if(topic.getCategories().contains(categoryId)) { |
|
74 |
|
|
75 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
76 |
if(subcategory != null) { |
|
77 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
78 |
String indicatorId = indicator.getId(); |
|
79 |
indicatorDAO.save(indicator); |
|
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 |
|
|
91 |
List<String> indicators = null; |
|
92 |
//if(indicator.hasType("chart")) { |
|
93 |
if(indicator.getType().equals("chart")) { |
|
94 |
indicators = subcategory.getCharts(); |
|
95 |
//} else if(indicator.hasType("number")) { |
|
96 |
} else if(indicator.getType().equals("number")) { |
|
97 |
indicators = subcategory.getNumbers(); |
|
98 |
} |
|
99 |
|
|
100 |
int index = indicators.indexOf(indicator.getId()); |
|
101 |
if (index == -1) { |
|
102 |
indicators.add(indicator.getId()); |
|
103 |
subCategoryDAO.save(subcategory); |
|
104 |
log.debug("Indicator saved!"); |
|
105 |
|
|
106 |
indicator.setId(indicator.getId()); |
|
107 |
} |
|
108 |
} else { |
|
109 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
110 |
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
111 |
} |
|
112 |
} else { |
|
113 |
// EXCEPTION - SubCategory not found |
|
114 |
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
115 |
} |
|
116 |
} else { |
|
117 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
118 |
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
119 |
} |
|
120 |
} else { |
|
121 |
// EXCEPTION - Category not found |
|
122 |
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found"); |
|
123 |
} |
|
124 |
} else { |
|
125 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
126 |
throw new PathNotValidException("Save indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
127 |
} |
|
128 |
} else { |
|
129 |
// EXCEPTION - Topic not found |
|
130 |
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"); |
|
131 |
} |
|
132 |
} else { |
|
133 |
// EXCEPTION - Stakeholder not found |
|
134 |
throw new EntityNotFoundException("Save indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
135 |
} |
|
136 | 75 |
return indicator; |
137 | 76 |
} |
138 | 77 |
|
139 |
public void onSaveDefaultIndicator(Indicator indicator, |
|
140 |
String defaultTopicId, String defaultCategoryId, |
|
141 |
String defaultSubcategoryId, Stakeholder defaultStakeholder) { |
|
78 |
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) { |
|
142 | 79 |
log.debug("On save default indicator"); |
143 | 80 |
|
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 | 81 |
// new indicator in default profile - add it on profiles of the same type |
194 |
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId);
|
|
82 |
List<Section> sections = sectionDAO.findByDefaultId(defaultSectionId);
|
|
195 | 83 |
|
196 |
for (SubCategory subCategory : subCategories) {
|
|
84 |
for (Section section : sections) {
|
|
197 | 85 |
Indicator indicatorNew = new Indicator(); |
198 | 86 |
indicatorNew.copyFromDefault(indicator); |
199 | 87 |
for (IndicatorPath indicatorPath : indicatorNew.getIndicatorPaths()) { |
200 |
Stakeholder stakeholder = stakeholderDAO.findById(subCategory.getStakeholderId());
|
|
88 |
Stakeholder stakeholder = stakeholderDAO.findByAlias(section.getStakeholderAlias());
|
|
201 | 89 |
parameterMapping(indicatorPath, stakeholder); |
202 | 90 |
} |
203 | 91 |
|
204 | 92 |
indicatorDAO.save(indicatorNew); |
205 | 93 |
|
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 |
} |
|
94 |
List<String> indicators = section.getIndicators(); |
|
212 | 95 |
indicators.add(indicatorNew.getId()); |
213 | 96 |
|
214 |
subCategoryDAO.save(subCategory);
|
|
97 |
sectionDAO.save(section);
|
|
215 | 98 |
} |
216 | 99 |
} |
217 | 100 |
|
... | ... | |
292 | 175 |
} |
293 | 176 |
} |
294 | 177 |
|
295 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/delete", method = RequestMethod.DELETE) |
|
178 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
|
|
296 | 179 |
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId, |
297 | 180 |
@PathVariable("topicId") String topicId, |
298 | 181 |
@PathVariable("categoryId") String categoryId, |
299 | 182 |
@PathVariable("subcategoryId") String subcategoryId, |
183 |
@PathVariable("sectionId") String sectionId, |
|
300 | 184 |
@PathVariable("indicatorId") String indicatorId) { |
301 | 185 |
log.debug("delete indicator"); |
302 |
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
186 |
log.debug("Id: "+indicatorId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
303 | 187 |
|
304 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
188 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
189 |
if(indicator != null) { |
|
190 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
305 | 191 |
|
306 |
if(stakeholder != null) {
|
|
192 |
List<String> indicators = section.getIndicators();
|
|
307 | 193 |
|
308 |
Topic<String> topic = topicDAO.findById(topicId); |
|
309 |
if(topic != null) { |
|
310 |
if(stakeholder.getTopics().contains(topicId)) { |
|
194 |
int index = indicators.indexOf(indicatorId); |
|
195 |
if (index != -1) { |
|
196 |
indicators.remove(index); |
|
197 |
sectionDAO.save(section); |
|
311 | 198 |
|
312 |
Category<String> category = categoryDAO.findById(categoryId); |
|
313 |
if(category != null) { |
|
314 |
if(topic.getCategories().contains(categoryId)) { |
|
315 |
|
|
316 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
317 |
if(subcategory != null) { |
|
318 |
if(category.getSubCategories().contains(subcategoryId)) { |
|
319 |
|
|
320 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
321 |
if(indicator != null) { |
|
322 |
List<String> indicators = null; |
|
323 |
if (indicator.getType().equals("chart")) { |
|
324 |
indicators = subcategory.getCharts(); |
|
325 |
} else if (indicator.getType().equals("number")) { |
|
326 |
indicators = subcategory.getNumbers(); |
|
327 |
} |
|
328 |
|
|
329 |
int index = indicators.indexOf(indicatorId); |
|
330 |
if (index != -1) { |
|
331 |
indicators.remove(index); |
|
332 |
subCategoryDAO.save(subcategory); |
|
333 |
|
|
334 |
indicatorDAO.delete(indicatorId); |
|
335 |
log.debug("Indicator deleted!"); |
|
336 |
} else { |
|
337 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
338 |
throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in SubCategory: "+subcategoryId); |
|
339 |
} |
|
340 |
} else { |
|
341 |
// EXCEPTION - Indicator not found |
|
342 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found"); |
|
343 |
} |
|
344 |
} else { |
|
345 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
346 |
throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
347 |
} |
|
348 |
} else { |
|
349 |
// EXCEPTION - SubCategory not found |
|
350 |
throw new EntityNotFoundException("Delete indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
351 |
} |
|
352 |
} else { |
|
353 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
354 |
throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
355 |
} |
|
356 |
} else { |
|
357 |
// EXCEPTION - Category not found |
|
358 |
throw new EntityNotFoundException("Delete indicator: Category with id: "+categoryId+" not found"); |
|
359 |
} |
|
360 |
} else { |
|
361 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
362 |
throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
363 |
} |
|
199 |
indicatorDAO.delete(indicatorId); |
|
200 |
log.debug("Indicator deleted!"); |
|
364 | 201 |
} else { |
365 |
// EXCEPTION - Topic not found
|
|
366 |
throw new EntityNotFoundException("Delete indicator: Topic with id: "+topicId+" not found");
|
|
202 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle();
|
|
203 |
throw new PathNotValidException("Delete indicator: Indicator with id: "+indicatorId+" not found in Sectiom: "+sectionId);
|
|
367 | 204 |
} |
368 | 205 |
} else { |
369 |
// EXCEPTION - Stakeholder not found
|
|
370 |
throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found");
|
|
206 |
// EXCEPTION - Indicator not found
|
|
207 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: "+indicatorId+" not found");
|
|
371 | 208 |
} |
372 | 209 |
return true; |
373 | 210 |
} |
374 | 211 |
|
375 |
@RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) |
|
376 |
public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { |
|
377 |
log.debug("delete all chart indicators of stakeholder"); |
|
378 |
log.debug("Stakeholder: "+stakeholderId); |
|
212 |
// @RequestMapping(value = "/{stakeholderId}/charts/delete", method = RequestMethod.DELETE) |
|
213 |
// public boolean deleteAllChartIndicators(@PathVariable("stakeholderId") String stakeholderId) { |
|
214 |
// log.debug("delete all chart indicators of stakeholder"); |
|
215 |
// log.debug("Stakeholder: "+stakeholderId); |
|
216 |
// |
|
217 |
// Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
218 |
// if(stakeholder != null) { |
|
219 |
// |
|
220 |
// for(String topicId : stakeholder.getTopics()) { |
|
221 |
// Topic<String> topic = topicDAO.findById(topicId); |
|
222 |
// if(topic != null) { |
|
223 |
// for(String categoryId : topic.getCategories()) { |
|
224 |
// Category<String> category = categoryDAO.findById(categoryId); |
|
225 |
// if(category != null) { |
|
226 |
// for(String subcategoryId : category.getSubCategories()) { |
|
227 |
// SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
228 |
// if(subcategory != null) { |
|
229 |
// |
|
230 |
// for(String sectionId : subcategory.getCharts()) { |
|
231 |
// Section<String> section = sectionDAO.findById(sectionId); |
|
232 |
// if (section != null) { |
|
233 |
// |
|
234 |
// List<String> indicators = section.getIndicators(); |
|
235 |
// Iterator<String> indicatorsIterator = section.getIndicators().iterator(); |
|
236 |
// |
|
237 |
// while (indicatorsIterator.hasNext()) { |
|
238 |
// String indicatorId = indicatorsIterator.next(); |
|
239 |
// Indicator indicator = indicatorDAO.findById(indicatorId); |
|
240 |
// if (indicator != null) { |
|
241 |
// int index = indicators.indexOf(indicatorId); |
|
242 |
// if (index != -1) { |
|
243 |
// indicatorsIterator.remove(); |
|
244 |
// //indicators.remove(index); |
|
245 |
// |
|
246 |
// indicatorDAO.delete(indicatorId); |
|
247 |
// log.debug("Indicator deleted!"); |
|
248 |
// } else { |
|
249 |
// // EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); -> Section: section.getTitle(); |
|
250 |
// throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in Section: " + sectionId); |
|
251 |
// } |
|
252 |
// } else { |
|
253 |
// // EXCEPTION - Indicator not found |
|
254 |
// throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found"); |
|
255 |
// } |
|
256 |
// } |
|
257 |
// sectionDAO.save(section); |
|
258 |
// } else { |
|
259 |
// // EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
260 |
// throw new PathNotValidException("Delete indicator: Section with id: " + sectionId + " not found in SubCategory: " + subcategoryId); |
|
261 |
// } |
|
262 |
// } |
|
263 |
// } else { |
|
264 |
// // EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
265 |
// throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
266 |
// } |
|
267 |
// } |
|
268 |
// } else { |
|
269 |
// // EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
270 |
// throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
271 |
// } |
|
272 |
// } |
|
273 |
// } else { |
|
274 |
// // EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
275 |
// throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
276 |
// } |
|
277 |
// } |
|
278 |
// } else { |
|
279 |
// // EXCEPTION - Stakeholder not found |
|
280 |
// throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
281 |
// } |
|
282 |
// return true; |
|
283 |
// } |
|
379 | 284 |
|
380 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
381 |
if(stakeholder != null) { |
|
382 |
|
|
383 |
for(String topicId : stakeholder.getTopics()) { |
|
384 |
Topic<String> topic = topicDAO.findById(topicId); |
|
385 |
if(topic != null) { |
|
386 |
for(String categoryId : topic.getCategories()) { |
|
387 |
Category<String> category = categoryDAO.findById(categoryId); |
|
388 |
if(category != null) { |
|
389 |
for(String subcategoryId : category.getSubCategories()) { |
|
390 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
391 |
if(subcategory != null) { |
|
392 |
|
|
393 |
List<String> indicators = subcategory.getCharts(); |
|
394 |
Iterator<String> indicatorsIterator = subcategory.getCharts().iterator(); |
|
395 |
|
|
396 |
while (indicatorsIterator.hasNext()) { |
|
397 |
String indicatorId = indicatorsIterator.next(); |
|
398 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
|
399 |
if (indicator != null) { |
|
400 |
int index = indicators.indexOf(indicatorId); |
|
401 |
if (index != -1) { |
|
402 |
indicatorsIterator.remove(); |
|
403 |
//indicators.remove(index); |
|
404 |
|
|
405 |
indicatorDAO.delete(indicatorId); |
|
406 |
log.debug("Indicator deleted!"); |
|
407 |
} else { |
|
408 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
409 |
throw new PathNotValidException("Delete indicator: Indicator with id: " + indicatorId + " not found in SubCategory: " + subcategoryId); |
|
410 |
} |
|
411 |
} else { |
|
412 |
// EXCEPTION - Indicator not found |
|
413 |
throw new EntityNotFoundException("Delete indicator: Indicator with id: " + indicatorId + " not found"); |
|
414 |
} |
|
415 |
} |
|
416 |
subCategoryDAO.save(subcategory); |
|
417 |
} else { |
|
418 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
419 |
throw new PathNotValidException("Delete indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
420 |
} |
|
421 |
} |
|
422 |
} else { |
|
423 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
424 |
throw new PathNotValidException("Delete indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
425 |
} |
|
426 |
} |
|
427 |
} else { |
|
428 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
429 |
throw new PathNotValidException("Delete indicator: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
430 |
} |
|
431 |
} |
|
432 |
} else { |
|
433 |
// EXCEPTION - Stakeholder not found |
|
434 |
throw new EntityNotFoundException("Delete indicator: Stakeholder with id: "+stakeholderId+" not found"); |
|
435 |
} |
|
436 |
return true; |
|
437 |
} |
|
438 |
|
|
439 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST) |
|
285 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{type}/reorder", method = RequestMethod.POST) |
|
440 | 286 |
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId, |
441 |
@PathVariable("topicId") String topicId, |
|
442 |
@PathVariable("categoryId") String categoryId, |
|
443 |
@PathVariable("subcategoryId") String subcategoryId, |
|
444 |
@PathVariable("type") String type, |
|
445 |
@RequestBody List<String> indicators) { |
|
287 |
@PathVariable("topicId") String topicId, |
|
288 |
@PathVariable("categoryId") String categoryId, |
|
289 |
@PathVariable("subcategoryId") String subcategoryId, |
|
290 |
@PathVariable("sectionId") String sectionId, |
|
291 |
@PathVariable("type") String type, |
|
292 |
@RequestBody List<String> indicators) { |
|
446 | 293 |
log.debug("reorder indicators of type: "+type); |
447 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
294 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
|
448 | 295 |
|
449 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId);
|
|
296 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, type);
|
|
450 | 297 |
|
451 |
if (stakeholder != null) {
|
|
298 |
section.setIndicators(indicators);
|
|
452 | 299 |
|
453 |
Topic<String> topic = topicDAO.findById(topicId); |
|
454 |
if (topic != null) { |
|
455 |
if (stakeholder.getTopics().contains(topicId)) { |
|
300 |
sectionDAO.save(section); |
|
301 |
log.debug("Indicators reordered!"); |
|
456 | 302 |
|
457 |
Category<String> category = categoryDAO.findById(categoryId); |
|
458 |
if (category != null) { |
|
459 |
if (topic.getCategories().contains(categoryId)) { |
|
460 |
|
|
461 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
462 |
if (subcategory != null) { |
|
463 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
464 |
if(type.equals("chart")) { |
|
465 |
subcategory.setCharts(indicators); |
|
466 |
} else if(type.equals("number")) { |
|
467 |
subcategory.setNumbers(indicators); |
|
468 |
} |
|
469 |
|
|
470 |
subCategoryDAO.save(subcategory); |
|
471 |
log.debug("Indicators reordered!"); |
|
472 |
} else { |
|
473 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
474 |
throw new PathNotValidException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
475 |
} |
|
476 |
} else { |
|
477 |
// EXCEPTION - SubCategory not found |
|
478 |
throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found"); |
|
479 |
} |
|
480 |
} else { |
|
481 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
482 |
throw new PathNotValidException("Reorder indicators: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
483 |
} |
|
484 |
} else { |
|
485 |
// EXCEPTION - Category not found |
|
486 |
throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found"); |
|
487 |
} |
|
488 |
} else { |
|
489 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
490 |
throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
491 |
} |
|
492 |
} else { |
|
493 |
// EXCEPTION - Topic not found |
|
494 |
throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found"); |
|
495 |
} |
|
496 |
} else { |
|
497 |
// EXCEPTION - Stakeholder not found |
|
498 |
throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found"); |
|
499 |
} |
|
500 |
|
|
501 | 303 |
List<Indicator> indicatorsFull = new ArrayList<>(); |
502 | 304 |
for(String indicatorId : indicators) { |
503 | 305 |
indicatorsFull.add(indicatorDAO.findById(indicatorId)); |
... | ... | |
505 | 307 |
return indicatorsFull; |
506 | 308 |
} |
507 | 309 |
|
508 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-status", method = RequestMethod.POST) |
|
310 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-status", method = RequestMethod.POST)
|
|
509 | 311 |
public Boolean toggleIndicatorStatus(@PathVariable("stakeholderId") String stakeholderId, |
510 | 312 |
@PathVariable("topicId") String topicId, |
511 | 313 |
@PathVariable("categoryId") String categoryId, |
512 | 314 |
@PathVariable("subcategoryId") String subcategoryId, |
315 |
@PathVariable("sectionId") String sectionId, |
|
513 | 316 |
@PathVariable("indicatorId") String indicatorId) { |
514 | 317 |
log.debug("toggle indicator status (isActive)"); |
515 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId); |
|
318 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
|
516 | 319 |
|
517 | 320 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
518 | 321 |
if (indicator == null) { |
... | ... | |
521 | 324 |
} |
522 | 325 |
indicator.setIsActive(!indicator.getIsActive()); |
523 | 326 |
|
524 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator); |
|
327 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
|
525 | 328 |
|
526 | 329 |
return indicator.getIsActive(); |
527 | 330 |
} |
528 | 331 |
|
529 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{indicatorId}/toggle-access", method = RequestMethod.POST) |
|
332 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/toggle-access", method = RequestMethod.POST)
|
|
530 | 333 |
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId, |
531 | 334 |
@PathVariable("topicId") String topicId, |
532 | 335 |
@PathVariable("categoryId") String categoryId, |
533 | 336 |
@PathVariable("subcategoryId") String subcategoryId, |
337 |
@PathVariable("sectionId") String sectionId, |
|
534 | 338 |
@PathVariable("indicatorId") String indicatorId) { |
535 | 339 |
log.debug("toggle indicator access (isPublic)"); |
536 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Indicator: "+indicatorId); |
|
340 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId+ " - Indicator: "+indicatorId);
|
|
537 | 341 |
|
538 | 342 |
Indicator indicator = indicatorDAO.findById(indicatorId); |
539 | 343 |
if (indicator == null) { |
... | ... | |
542 | 346 |
} |
543 | 347 |
indicator.setIsPublic(!indicator.getIsPublic()); |
544 | 348 |
|
545 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, indicator); |
|
349 |
this.toggleIndicator(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator);
|
|
546 | 350 |
|
547 | 351 |
return indicator.getIsPublic(); |
548 | 352 |
} |
549 | 353 |
|
550 |
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, Indicator indicator) { |
|
354 |
public void toggleIndicator(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, Indicator indicator) { |
|
355 |
Section<String> section = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId, sectionId, indicator.getType()); |
|
356 |
List<String> indicators = section.getIndicators(); |
|
357 |
|
|
358 |
if(indicators.contains(indicator.getId())) { |
|
359 |
indicatorDAO.save(indicator); |
|
360 |
log.debug("Indicator toggled!"); |
|
361 |
} else { |
|
362 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); -> Section: section.getTitle(); |
|
363 |
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in Section: "+sectionId); |
|
364 |
} |
|
365 |
|
|
366 |
} |
|
367 |
|
|
368 |
private Section checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId, String sectionId, String indicatorType) { |
|
369 |
|
|
551 | 370 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
552 | 371 |
|
553 |
if (stakeholder != null) { |
|
372 |
if(stakeholder == null) { |
|
373 |
// EXCEPTION - Stakeholder not found |
|
374 |
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); |
|
375 |
} |
|
554 | 376 |
|
555 |
Topic<String> topic = topicDAO.findById(topicId); |
|
556 |
if (topic != null) { |
|
557 |
if (stakeholder.getTopics().contains(topicId)) { |
|
377 |
Topic<String> topic = topicDAO.findById(topicId); |
|
378 |
if(topic == null) { |
|
379 |
// EXCEPTION - Topic not found |
|
380 |
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"); |
|
381 |
} |
|
558 | 382 |
|
559 |
Category<String> category = categoryDAO.findById(categoryId); |
|
560 |
if (category != null) { |
|
561 |
if (topic.getCategories().contains(categoryId)) { |
|
383 |
if(!stakeholder.getTopics().contains(topicId)) { |
|
384 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
385 |
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId); |
|
386 |
} |
|
562 | 387 |
|
563 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
564 |
if (subcategory != null) { |
|
565 |
if (category.getSubCategories().contains(subcategoryId)) { |
|
566 |
List<String> indicators = null; |
|
567 |
if(indicator.getType().equals("chart")) { |
|
568 |
indicators = subcategory.getCharts(); |
|
569 |
} else if(indicator.getType().equals("number")) { |
|
570 |
indicators = subcategory.getNumbers(); |
|
571 |
} |
|
388 |
Category<String> category = categoryDAO.findById(categoryId); |
|
389 |
if(category == null) { |
|
390 |
// EXCEPTION - Category not found |
|
391 |
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found"); |
|
392 |
} |
|
572 | 393 |
|
573 |
if(indicators.contains(indicator.getId())) { |
|
574 |
indicatorDAO.save(indicator); |
|
575 |
log.debug("Indicator toggled!"); |
|
576 |
} else { |
|
577 |
// EXCEPTION - Indicator not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); |
|
578 |
throw new PathNotValidException("Toggle indicators: Indicator with id: "+indicator.getId()+" not found in SubCategory: "+subcategoryId); |
|
579 |
} |
|
580 |
} else { |
|
581 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
582 |
throw new PathNotValidException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
583 |
} |
|
584 |
} else { |
|
585 |
// EXCEPTION - SubCategory not found |
|
586 |
throw new EntityNotFoundException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found"); |
|
587 |
} |
|
588 |
} else { |
|
589 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
590 |
throw new PathNotValidException("Toggle indicators: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
591 |
} |
|
592 |
} else { |
|
593 |
// EXCEPTION - Category not found |
|
594 |
throw new EntityNotFoundException("Toggle indicators: Category with id: "+categoryId+" not found"); |
|
595 |
} |
|
596 |
} else { |
|
597 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
598 |
throw new PathNotValidException("Toggle indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
599 |
} |
|
600 |
} else { |
|
601 |
// EXCEPTION - Topic not found |
|
602 |
throw new EntityNotFoundException("Toggle indicators: Topic with id: "+topicId+" not found"); |
|
394 |
if(!topic.getCategories().contains(categoryId)) { |
|
395 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
396 |
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
397 |
} |
|
398 |
|
|
399 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
400 |
if(subcategory == null) { |
|
401 |
// EXCEPTION - SubCategory not found |
|
402 |
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
403 |
} |
|
404 |
|
|
405 |
if (!category.getSubCategories().contains(subcategoryId)) { |
|
406 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
407 |
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
408 |
} |
|
409 |
|
|
410 |
Section<String> section = sectionDAO.findById(sectionId); |
|
411 |
if(section == null) { |
|
412 |
// EXCEPTION - Section not found |
|
413 |
throw new EntityNotFoundException("Save indicator: Section with id: "+sectionId+" not found"); |
|
414 |
} |
|
415 |
|
|
416 |
if(indicatorType.equals("chart")) { |
|
417 |
if (!subcategory.getCharts().contains(sectionId)) { |
|
418 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
419 |
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId); |
|
603 | 420 |
} |
604 |
} else { |
|
605 |
// EXCEPTION - Stakeholder not found |
|
606 |
throw new EntityNotFoundException("Toggle indicators: Stakeholder with id: "+stakeholderId+" not found"); |
|
421 |
} else if(indicatorType.equals("number")) { |
|
422 |
if (!subcategory.getNumbers().contains(sectionId)) { |
|
423 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
424 |
throw new PathNotValidException("Save indicator: SubCategory with id: " + subcategoryId + " not found in Category: " + categoryId); |
|
425 |
} |
|
607 | 426 |
} |
427 |
|
|
428 |
return section; |
|
608 | 429 |
} |
609 | 430 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java | ||
---|---|---|
29 | 29 |
private SubCategoryDAO subCategoryDAO; |
30 | 30 |
|
31 | 31 |
@Autowired |
32 |
private SectionDAO sectionDAO; |
|
33 |
|
|
34 |
@Autowired |
|
32 | 35 |
private IndicatorDAO indicatorDAO; |
33 | 36 |
|
34 | 37 |
@Autowired |
... | ... | |
39 | 42 |
|
40 | 43 |
List<String> subCategories = new ArrayList<>(); |
41 | 44 |
List<SubCategory> subCategoriesFull = new ArrayList<>(); |
42 |
for(SubCategory<Indicator> subCategory : categoryFull.getSubCategories()) {
|
|
43 |
SubCategory<Indicator> subcategoryFull = subCategoryController.buildSubCategory(subCategory);
|
|
45 |
for(SubCategory<Section<Indicator>> subCategory : categoryFull.getSubCategories()) {
|
|
46 |
SubCategory<Section<Indicator>> subcategoryFull = subCategoryController.buildSubCategory(subCategory);
|
|
44 | 47 |
subCategoriesFull.add(subcategoryFull); |
45 | 48 |
subCategories.add(subcategoryFull.getId()); |
46 | 49 |
} |
... | ... | |
192 | 195 |
// EXCEPTION - SubCategory not found |
193 | 196 |
throw new EntityNotFoundException("Delete category: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")"); |
194 | 197 |
} |
195 |
for(String chartId : subcategory.getCharts()) { |
|
196 |
indicatorDAO.delete(chartId); |
|
198 |
|
|
199 |
for(String chartSectionId : subcategory.getCharts()) { |
|
200 |
Section<String> chartSection = sectionDAO.findById(chartSectionId); |
|
201 |
if (chartSection == null) { |
|
202 |
// EXCEPTION - Section not found |
|
203 |
throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); |
|
204 |
} |
|
205 |
|
|
206 |
for (String chartId : chartSection.getIndicators()) { |
|
207 |
indicatorDAO.delete(chartId); |
|
208 |
} |
|
209 |
subcategory.setCharts(null); |
|
210 |
sectionDAO.delete(chartSectionId); |
|
197 | 211 |
} |
198 |
subcategory.setCharts(null); |
|
199 | 212 |
|
200 |
for(String numberId : subcategory.getNumbers()) { |
|
201 |
indicatorDAO.delete(numberId); |
|
213 |
for(String numberSectionId : subcategory.getNumbers()) { |
|
214 |
Section<String> numberSection = sectionDAO.findById(numberSectionId); |
|
215 |
if (numberSection == null) { |
|
216 |
// EXCEPTION - Section not found |
|
217 |
throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); |
|
218 |
} |
|
219 |
|
|
220 |
for (String numberId : numberSection.getIndicators()) { |
|
221 |
indicatorDAO.delete(numberId); |
|
222 |
} |
|
223 |
subcategory.setNumbers(null); |
|
224 |
sectionDAO.delete(numberSectionId); |
|
202 | 225 |
} |
203 |
subcategory.setNumbers(null); |
|
204 | 226 |
|
205 | 227 |
subCategoryDAO.delete(subCategoryId); |
206 | 228 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 | 3 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 |
import eu.dnetlib.uoamonitorservice.entities.Category; |
|
5 |
import eu.dnetlib.uoamonitorservice.entities.Stakeholder; |
|
6 |
import eu.dnetlib.uoamonitorservice.entities.SubCategory; |
|
7 |
import eu.dnetlib.uoamonitorservice.entities.Topic; |
|
4 |
import eu.dnetlib.uoamonitorservice.entities.*; |
|
8 | 5 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
9 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
10 | 7 |
import org.apache.log4j.Logger; |
... | ... | |
32 | 29 |
private SubCategoryDAO subCategoryDAO; |
33 | 30 |
|
34 | 31 |
@Autowired |
32 |
private SectionDAO sectionDAO; |
|
33 |
|
|
34 |
@Autowired |
|
35 | 35 |
private IndicatorDAO indicatorDAO; |
36 | 36 |
|
37 | 37 |
@Autowired |
... | ... | |
169 | 169 |
SubCategory<String> subcategory = subCategoryDAO.findById(subCategoryId); |
170 | 170 |
if (subcategory == null) { |
171 | 171 |
// EXCEPTION - SubCategory not found |
172 |
throw new EntityNotFoundException("Delete stakeholder: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
|
|
172 |
throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
|
|
173 | 173 |
} |
174 | 174 |
|
175 |
for (String chartId : subcategory.getCharts()) { |
|
176 |
indicatorDAO.delete(chartId); |
|
175 |
for(String chartSectionId : subcategory.getCharts()) { |
|
176 |
Section<String> chartSection = sectionDAO.findById(chartSectionId); |
|
177 |
if (chartSection == null) { |
|
178 |
// EXCEPTION - Section not found |
|
179 |
throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); |
|
180 |
} |
|
181 |
|
|
182 |
for (String chartId : chartSection.getIndicators()) { |
|
183 |
indicatorDAO.delete(chartId); |
|
184 |
} |
|
185 |
subcategory.setCharts(null); |
|
186 |
sectionDAO.delete(chartSectionId); |
|
177 | 187 |
} |
178 |
subcategory.setCharts(null); |
|
179 | 188 |
|
180 |
for (String numberId : subcategory.getNumbers()) { |
|
181 |
indicatorDAO.delete(numberId); |
|
189 |
for(String numberSectionId : subcategory.getNumbers()) { |
|
190 |
Section<String> numberSection = sectionDAO.findById(numberSectionId); |
|
191 |
if (numberSection == null) { |
|
192 |
// EXCEPTION - Section not found |
|
193 |
throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")"); |
|
194 |
} |
|
195 |
|
|
196 |
for (String numberId : numberSection.getIndicators()) { |
|
197 |
indicatorDAO.delete(numberId); |
|
198 |
} |
|
199 |
subcategory.setNumbers(null); |
|
200 |
sectionDAO.delete(numberSectionId); |
|
182 | 201 |
} |
183 |
subcategory.setNumbers(null); |
|
184 | 202 |
|
185 | 203 |
subCategoryDAO.delete(subCategoryId); |
186 | 204 |
} |
... | ... | |
229 | 247 |
} |
230 | 248 |
|
231 | 249 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-access", method = RequestMethod.POST) |
232 |
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId,
|
|
250 |
public Boolean toggleTopicAccess(@PathVariable("stakeholderId") String stakeholderId,
|
|
233 | 251 |
@PathVariable("topicId") String topicId) { |
234 | 252 |
log.debug("toggle topic access (isPublic)"); |
235 | 253 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.controllers; |
|
2 |
|
|
3 |
import eu.dnetlib.uoamonitorservice.dao.*; |
|
4 |
import eu.dnetlib.uoamonitorservice.entities.*; |
|
5 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
|
6 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
|
7 |
import org.apache.log4j.Logger; |
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
import org.springframework.web.bind.annotation.*; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
@RestController |
|
15 |
@CrossOrigin(origins = "*") |
|
16 |
public class SectionController { |
|
17 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
18 |
|
|
19 |
@Autowired |
|
20 |
private StakeholderDAO stakeholderDAO; |
|
21 |
|
|
22 |
@Autowired |
|
23 |
private TopicDAO topicDAO; |
|
24 |
|
|
25 |
@Autowired |
|
26 |
private CategoryDAO categoryDAO; |
|
27 |
|
|
28 |
@Autowired |
|
29 |
private SubCategoryDAO subCategoryDAO; |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private SectionDAO sectionDAO; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private IndicatorDAO indicatorDAO; |
|
36 |
|
|
37 |
public Section<Indicator> buildSection(Section<Indicator> sectionFull) { |
|
38 |
Section<String> section = new Section<>(sectionFull); |
|
39 |
|
|
40 |
List<String> indicators = new ArrayList<>(); |
|
41 |
List<Indicator> indicatorsFull = new ArrayList<>(); |
|
42 |
for(Indicator chart : sectionFull.getIndicators()) { |
|
43 |
Indicator chartSaved = indicatorDAO.save(chart); |
|
44 |
chart.setId(chartSaved.getId()); |
|
45 |
indicatorsFull.add(chart); |
|
46 |
indicators.add(chartSaved.getId()); |
|
47 |
} |
|
48 |
sectionFull.setIndicators(indicatorsFull); |
|
49 |
section.setIndicators(indicators); |
|
50 |
|
|
51 |
sectionDAO.save(section); |
|
52 |
|
|
53 |
sectionFull.setId(section.getId()); |
|
54 |
return sectionFull; |
|
55 |
} |
|
56 |
|
|
57 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save", method = RequestMethod.POST) |
|
58 |
public Section saveSection(@PathVariable("stakeholderId") String stakeholderId, |
|
59 |
@PathVariable("topicId") String topicId, |
|
60 |
@PathVariable("categoryId") String categoryId, |
|
61 |
@PathVariable("subcategoryId") String subcategoryId, |
|
62 |
@RequestBody Section<Indicator> sectionFull) { |
|
63 |
log.debug("save section"); |
|
64 |
log.debug("Name: "+sectionFull.getTitle() + " - Id: "+sectionFull.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
65 |
|
|
66 |
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); |
|
67 |
Section<String> section = new Section<>(sectionFull); |
|
68 |
|
|
69 |
String sectionId = sectionFull.getId(); |
|
70 |
List<String> indicators = new ArrayList<>(); |
|
71 |
for(Indicator indicator : sectionFull.getIndicators()) { |
|
72 |
indicators.add(indicator.getId()); |
|
73 |
} |
|
74 |
section.setIndicators(indicators); |
|
75 |
sectionDAO.save(section); |
|
76 |
|
|
77 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
78 |
// this section belongs in default profile and it is new or it is updated |
|
79 |
if(stakeholder.getDefaultId() == null) { |
|
80 |
if(sectionId == null) { |
|
81 |
onSaveDefaultSection(sectionFull, topicId, categoryId, subcategoryId, stakeholder); |
|
82 |
} |
|
83 |
else { |
|
84 |
onUpdateDefaultSection(sectionFull, stakeholder); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
List<String> sections = null; |
|
89 |
if(sectionFull.getType().equals("chart")) { |
|
90 |
sections = subCategory.getCharts(); |
|
91 |
} else if(sectionFull.getType().equals("number")) { |
|
92 |
sections = subCategory.getNumbers(); |
|
93 |
} |
|
94 |
|
|
95 |
int index = sections.indexOf(sectionFull.getId()); |
|
96 |
if (index == -1) { |
|
97 |
sections.add(sectionFull.getId()); |
|
98 |
subCategoryDAO.save(subCategory); |
|
99 |
log.debug("Section saved!"); |
|
100 |
|
|
101 |
sectionFull.setId(section.getId()); |
|
102 |
} |
|
103 |
|
|
104 |
return sectionFull; |
|
105 |
} |
|
106 |
|
|
107 |
public void onSaveDefaultSection(Section section, |
|
108 |
String defaultTopicId, String defaultCategoryId, |
|
109 |
String defaultSubcategoryId, Stakeholder defaultStakeholder) { |
|
110 |
log.debug("On save default section"); |
|
111 |
|
|
112 |
|
|
113 |
// new section in default profile - add it on profiles of the same type |
|
114 |
List<SubCategory> subCategories = subCategoryDAO.findByDefaultId(defaultSubcategoryId); |
|
115 |
|
|
116 |
for (SubCategory subCategory : subCategories) { |
|
117 |
Section sectionNew = new Section(); |
|
118 |
sectionNew.copyFromDefault(section); |
|
119 |
|
|
120 |
sectionDAO.save(sectionNew); |
|
121 |
|
|
122 |
List<String> sections = null; |
|
123 |
if (section.getType().equals("chart")) { |
|
124 |
sections = subCategory.getCharts(); |
|
125 |
} else if (section.getType().equals("number")) { |
|
126 |
sections = subCategory.getNumbers(); |
|
127 |
} |
|
128 |
sections.add(sectionNew.getId()); |
|
129 |
|
|
130 |
subCategoryDAO.save(subCategory); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
public void onUpdateDefaultSection(Section section, Stakeholder stakeholder) { |
|
135 |
log.debug("On update default section"); |
|
136 |
|
|
137 |
// section already exists - check if changed and update all sections based on it |
|
138 |
|
|
139 |
boolean changed = false; |
|
140 |
List<Section> sections = sectionDAO.findByDefaultId(section.getId()); |
|
141 |
|
|
142 |
for(Section sectionBasedOnDefault : sections) { |
|
143 |
if(section.getTitle() != null && !section.getTitle().equals(sectionBasedOnDefault.getTitle())) { |
|
144 |
changed = true; |
|
145 |
} |
|
146 |
|
|
147 |
if(!changed) { |
|
148 |
break; |
|
149 |
} |
|
150 |
|
|
151 |
sectionBasedOnDefault.setTitle(section.getTitle()); |
|
152 |
sectionDAO.save(sectionBasedOnDefault); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete", method = RequestMethod.DELETE) |
|
157 |
public boolean deleteSection(@PathVariable("stakeholderId") String stakeholderId, |
|
158 |
@PathVariable("topicId") String topicId, |
|
159 |
@PathVariable("categoryId") String categoryId, |
|
160 |
@PathVariable("subcategoryId") String subcategoryId, |
|
161 |
@PathVariable("sectionId") String sectionId) { |
|
162 |
log.debug("delete section"); |
|
163 |
log.debug("Id: "+sectionId + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
164 |
|
|
165 |
Section section = sectionDAO.findById(sectionId); |
|
166 |
if(section != null) { |
|
167 |
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); |
|
168 |
|
|
169 |
List<String> sections = null; |
|
170 |
if (section.getType().equals("chart")) { |
|
171 |
sections = subCategory.getCharts(); |
|
172 |
} else if (section.getType().equals("number")) { |
|
173 |
sections = subCategory.getNumbers(); |
|
174 |
} |
|
175 |
|
|
176 |
int index = sections.indexOf(sectionId); |
|
177 |
if (index != -1) { |
|
178 |
sections.remove(index); |
|
179 |
subCategoryDAO.save(subCategory); |
|
180 |
|
|
181 |
sectionDAO.delete(sectionId); |
|
182 |
log.debug("Section deleted!"); |
|
183 |
} else { |
|
184 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subcategory.getAlias(); |
|
185 |
throw new PathNotValidException("Delete section: Section with id: "+sectionId+" not found in SubCategory: "+subcategoryId); |
|
186 |
} |
|
187 |
} else { |
|
188 |
// EXCEPTION - Section not found |
|
189 |
throw new EntityNotFoundException("Delete section: Section with id: "+sectionId+" not found"); |
|
190 |
} |
|
191 |
return true; |
|
192 |
} |
|
193 |
|
|
194 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{type}/reorder", method = RequestMethod.POST) |
|
195 |
public List<Section> reorderSections(@PathVariable("stakeholderId") String stakeholderId, |
|
196 |
@PathVariable("topicId") String topicId, |
|
197 |
@PathVariable("categoryId") String categoryId, |
|
198 |
@PathVariable("subcategoryId") String subcategoryId, |
|
199 |
@PathVariable("type") String type, |
|
200 |
@RequestBody List<String> sections) { |
|
201 |
log.debug("reorder sections of type: "+type); |
|
202 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
203 |
|
|
204 |
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); |
|
205 |
|
|
206 |
if (type.equals("chart")) { |
|
207 |
subCategory.setCharts(sections); |
|
208 |
} else if (type.equals("number")) { |
|
209 |
subCategory.setNumbers(sections); |
|
210 |
} |
|
211 |
|
|
212 |
subCategoryDAO.save(subCategory); |
|
213 |
log.debug("Sections reordered!"); |
|
214 |
|
|
215 |
List<Section> sectionsFull = new ArrayList<>(); |
|
216 |
for(String sectionId : sections) { |
|
217 |
sectionsFull.add(sectionDAO.findById(sectionId)); |
|
218 |
} |
|
219 |
return sectionsFull; |
|
220 |
} |
|
221 |
|
|
222 |
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-status", method = RequestMethod.POST) |
|
223 |
// public Boolean toggleSectionStatus(@PathVariable("stakeholderId") String stakeholderId, |
|
224 |
// @PathVariable("topicId") String topicId, |
|
225 |
// @PathVariable("categoryId") String categoryId, |
|
226 |
// @PathVariable("subcategoryId") String subcategoryId, |
|
227 |
// @PathVariable("sectionId") String sectionId) { |
|
228 |
// log.debug("toggle section status (isActive)"); |
|
229 |
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId+ " - Section: "+sectionId); |
|
230 |
// |
|
231 |
// Section section = sectionDAO.findById(sectionId); |
|
232 |
// if (section == null) { |
|
233 |
// // EXCEPTION - Section not found |
|
234 |
// throw new EntityNotFoundException("Toggle section status: Section with id: "+sectionId+" not found"); |
|
235 |
// } |
|
236 |
// section.setIsActive(!section.getIsActive()); |
|
237 |
// |
|
238 |
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId, section); |
|
239 |
// |
|
240 |
// return section.getIsActive(); |
|
241 |
// } |
|
242 |
|
|
243 |
// @RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/toggle-access", method = RequestMethod.POST) |
|
244 |
// public Boolean toggleSectionAccess(@PathVariable("stakeholderId") String stakeholderId, |
|
245 |
// @PathVariable("topicId") String topicId, |
|
246 |
// @PathVariable("categoryId") String categoryId, |
|
247 |
// @PathVariable("subcategoryId") String subcategoryId, |
|
248 |
// @PathVariable("sectionId") String sectionId) { |
|
249 |
// log.debug("toggle section access (isPublic)"); |
|
250 |
// log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
251 |
// |
|
252 |
// Section section = sectionDAO.findById(sectionId); |
|
253 |
// if (section == null) { |
|
254 |
// // EXCEPTION - Section not found |
|
255 |
// throw new EntityNotFoundException("Toggle section access: Section with id: "+sectionId+" not found"); |
|
256 |
// } |
|
257 |
// section.setIsPublic(!section.getIsPublic()); |
|
258 |
// |
|
259 |
// this.toggleSection(stakeholderId, topicId, categoryId, subcategoryId); |
|
260 |
// |
|
261 |
// return section.getIsPublic(); |
|
262 |
// } |
|
263 |
|
|
264 |
public void toggleSection(String stakeholderId, String topicId, String categoryId, String subcategoryId, Section section) { |
|
265 |
SubCategory<String> subCategory = checkForExceptions(stakeholderId, topicId, categoryId, subcategoryId); |
|
266 |
|
|
267 |
List<String> sections = null; |
|
268 |
if (section.getType().equals("chart")) { |
|
269 |
sections = subCategory.getCharts(); |
|
270 |
} else if (section.getType().equals("number")) { |
|
271 |
sections = subCategory.getNumbers(); |
|
272 |
} |
|
273 |
|
|
274 |
if(sections.contains(section.getId())) { |
|
275 |
sectionDAO.save(section); |
|
276 |
log.debug("Section toggled!"); |
|
277 |
} else { |
|
278 |
// EXCEPTION - Section not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); -> SubCategory: subCategory.getAlias(); |
|
279 |
throw new PathNotValidException("Toggle section: Section with id: "+section.getId()+" not found in SubCategory: "+subcategoryId); |
|
280 |
} |
|
281 |
|
|
282 |
} |
|
283 |
|
|
284 |
private SubCategory checkForExceptions(String stakeholderId, String topicId, String categoryId, String subcategoryId) { |
|
285 |
|
|
286 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
287 |
|
|
288 |
if(stakeholder == null) { |
|
289 |
// EXCEPTION - Stakeholder not found |
|
290 |
throw new EntityNotFoundException("Save indicator: Stakeholder with id: " + stakeholderId + " not found"); |
|
291 |
} |
|
292 |
|
|
293 |
Topic<String> topic = topicDAO.findById(topicId); |
|
294 |
if(topic == null) { |
|
295 |
// EXCEPTION - Topic not found |
|
296 |
throw new EntityNotFoundException("Save indicator: Topic with id: "+topicId+" not found"); |
|
297 |
} |
|
298 |
|
|
299 |
if(!stakeholder.getTopics().contains(topicId)) { |
|
300 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
301 |
throw new PathNotValidException("Save indicator: Topic with id: " + topicId + " not found in Stakeholder: " + stakeholderId); |
|
302 |
} |
|
303 |
|
|
304 |
Category<String> category = categoryDAO.findById(categoryId); |
|
305 |
if(category == null) { |
|
306 |
// EXCEPTION - Category not found |
|
307 |
throw new EntityNotFoundException("Save indicator: Category with id: "+categoryId+" not found"); |
|
308 |
} |
|
309 |
|
|
310 |
if(!topic.getCategories().contains(categoryId)) { |
|
311 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
312 |
throw new PathNotValidException("Save indicator: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
313 |
} |
|
314 |
|
|
315 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
|
316 |
if(subcategory == null) { |
|
317 |
// EXCEPTION - SubCategory not found |
|
318 |
throw new EntityNotFoundException("Save indicator: SubCategory with id: "+subcategoryId+" not found"); |
|
319 |
} |
|
320 |
|
|
321 |
if (!category.getSubCategories().contains(subcategoryId)) { |
|
322 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
323 |
throw new PathNotValidException("Save indicator: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId); |
|
324 |
} |
|
325 |
|
|
326 |
return subcategory; |
|
327 |
} |
|
328 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/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<>(); |
Also available in: Unified diff
[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).