Revision 57934
Added by Konstantina Galouni over 4 years ago
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java | ||
---|---|---|
563 | 563 |
SubCategory<String> subcategory = subCategoryDAO.findById(subcategoryId); |
564 | 564 |
if (subcategory != null) { |
565 | 565 |
if (category.getSubCategories().contains(subcategoryId)) { |
566 |
indicatorDAO.save(indicator); |
|
567 |
log.debug("Indicator toggled!"); |
|
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 |
} |
|
572 |
|
|
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 |
} |
|
568 | 580 |
} else { |
569 | 581 |
// 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);
|
|
582 |
throw new PathNotValidException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found in Category: "+categoryId);
|
|
571 | 583 |
} |
572 | 584 |
} else { |
573 | 585 |
// EXCEPTION - SubCategory not found |
574 |
throw new EntityNotFoundException("Reorder indicators: SubCategory with id: "+subcategoryId+" not found");
|
|
586 |
throw new EntityNotFoundException("Toggle indicators: SubCategory with id: "+subcategoryId+" not found");
|
|
575 | 587 |
} |
576 | 588 |
} else { |
577 | 589 |
// 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);
|
|
590 |
throw new PathNotValidException("Toggle indicators: Category with id: "+categoryId+" not found in Topic: "+topicId);
|
|
579 | 591 |
} |
580 | 592 |
} else { |
581 | 593 |
// EXCEPTION - Category not found |
582 |
throw new EntityNotFoundException("Reorder indicators: Category with id: "+categoryId+" not found");
|
|
594 |
throw new EntityNotFoundException("Toggle indicators: Category with id: "+categoryId+" not found");
|
|
583 | 595 |
} |
584 | 596 |
} else { |
585 | 597 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
586 |
throw new PathNotValidException("Reorder indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
|
598 |
throw new PathNotValidException("Toggle indicators: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId);
|
|
587 | 599 |
} |
588 | 600 |
} else { |
589 | 601 |
// EXCEPTION - Topic not found |
590 |
throw new EntityNotFoundException("Reorder indicators: Topic with id: "+topicId+" not found");
|
|
602 |
throw new EntityNotFoundException("Toggle indicators: Topic with id: "+topicId+" not found");
|
|
591 | 603 |
} |
592 | 604 |
} else { |
593 | 605 |
// EXCEPTION - Stakeholder not found |
594 |
throw new EntityNotFoundException("Reorder indicators: Stakeholder with id: "+stakeholderId+" not found");
|
|
606 |
throw new EntityNotFoundException("Toggle indicators: Stakeholder with id: "+stakeholderId+" not found");
|
|
595 | 607 |
} |
596 | 608 |
} |
597 | 609 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java | ||
---|---|---|
234 | 234 |
} |
235 | 235 |
return true; |
236 | 236 |
} |
237 |
|
|
238 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-status", method = RequestMethod.POST) |
|
239 |
public Boolean toggleCategoryStatus(@PathVariable("stakeholderId") String stakeholderId, |
|
240 |
@PathVariable("topicId") String topicId, |
|
241 |
@PathVariable("categoryId") String categoryId) { |
|
242 |
log.debug("toggle category status (isActive)"); |
|
243 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId); |
|
244 |
|
|
245 |
Category category = categoryDAO.findById(categoryId); |
|
246 |
if (category == null) { |
|
247 |
// EXCEPTION - Category not found |
|
248 |
throw new EntityNotFoundException("Toggle category status: Category with id: "+categoryId+" not found"); |
|
249 |
} |
|
250 |
category.setIsActive(!category.getIsActive()); |
|
251 |
|
|
252 |
this.toggleCategory(stakeholderId, topicId, category); |
|
253 |
|
|
254 |
return category.getIsActive(); |
|
255 |
} |
|
256 |
|
|
257 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/toggle-access", method = RequestMethod.POST) |
|
258 |
public Boolean toggleCategoryAccess(@PathVariable("stakeholderId") String stakeholderId, |
|
259 |
@PathVariable("topicId") String topicId, |
|
260 |
@PathVariable("categoryId") String categoryId) { |
|
261 |
log.debug("toggle category access (isPublic)"); |
|
262 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId); |
|
263 |
|
|
264 |
Category category = categoryDAO.findById(categoryId); |
|
265 |
if (category == null) { |
|
266 |
// EXCEPTION - Category not found |
|
267 |
throw new EntityNotFoundException("Toggle category access: Category with id: "+categoryId+" not found"); |
|
268 |
} |
|
269 |
category.setIsPublic(!category.getIsPublic()); |
|
270 |
|
|
271 |
this.toggleCategory(stakeholderId, topicId, category); |
|
272 |
|
|
273 |
return category.getIsPublic(); |
|
274 |
} |
|
275 |
|
|
276 |
public void toggleCategory(String stakeholderId, String topicId, Category category) { |
|
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 |
if (topic.getCategories().contains(category.getId())) { |
|
285 |
categoryDAO.save(category); |
|
286 |
log.debug("Category toggled!"); |
|
287 |
} else { |
|
288 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
289 |
throw new PathNotValidException("Toggle category: Category with id: "+category.getId()+" not found in Topic: "+topicId); |
|
290 |
} |
|
291 |
} else { |
|
292 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
293 |
throw new PathNotValidException("Toggle category: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
294 |
} |
|
295 |
} else { |
|
296 |
// EXCEPTION - Topic not found |
|
297 |
throw new EntityNotFoundException("Toggle category: Topic with id: "+topicId+" not found"); |
|
298 |
} |
|
299 |
} else { |
|
300 |
// EXCEPTION - Stakeholder not found |
|
301 |
throw new EntityNotFoundException("Toggle category: Stakeholder with id: "+stakeholderId+" not found"); |
|
302 |
} |
|
303 |
} |
|
237 | 304 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java | ||
---|---|---|
209 | 209 |
} |
210 | 210 |
return true; |
211 | 211 |
} |
212 |
|
|
213 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST) |
|
214 |
public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId, |
|
215 |
@PathVariable("topicId") String topicId) { |
|
216 |
log.debug("toggle topic status (isActive)"); |
|
217 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); |
|
218 |
|
|
219 |
Topic topic = topicDAO.findById(topicId); |
|
220 |
if (topic == null) { |
|
221 |
// EXCEPTION - Topic not found |
|
222 |
throw new EntityNotFoundException("Toggle topic status: Topic with id: "+topicId+" not found"); |
|
223 |
} |
|
224 |
topic.setIsActive(!topic.getIsActive()); |
|
225 |
|
|
226 |
this.toggleTopic(stakeholderId, topic); |
|
227 |
|
|
228 |
return topic.getIsActive(); |
|
229 |
} |
|
230 |
|
|
231 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-access", method = RequestMethod.POST) |
|
232 |
public Boolean toggleIndicatorAccess(@PathVariable("stakeholderId") String stakeholderId, |
|
233 |
@PathVariable("topicId") String topicId) { |
|
234 |
log.debug("toggle topic access (isPublic)"); |
|
235 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId); |
|
236 |
|
|
237 |
Topic topic = topicDAO.findById(topicId); |
|
238 |
if (topic == null) { |
|
239 |
// EXCEPTION - Topic not found |
|
240 |
throw new EntityNotFoundException("Toggle topic access: Topic with id: "+topicId+" not found"); |
|
241 |
} |
|
242 |
topic.setIsPublic(!topic.getIsPublic()); |
|
243 |
|
|
244 |
this.toggleTopic(stakeholderId, topic); |
|
245 |
|
|
246 |
return topic.getIsPublic(); |
|
247 |
} |
|
248 |
|
|
249 |
public void toggleTopic(String stakeholderId, Topic topic) { |
|
250 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
251 |
|
|
252 |
if (stakeholder != null) { |
|
253 |
if (stakeholder.getTopics().contains(topic.getId())) { |
|
254 |
topicDAO.save(topic); |
|
255 |
log.debug("Topic toggled!"); |
|
256 |
} else { |
|
257 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
258 |
throw new PathNotValidException("Toggle topic: Topic with id: "+topic.getId()+" not found in Stakeholder: "+stakeholderId); |
|
259 |
} |
|
260 |
} else { |
|
261 |
// EXCEPTION - Stakeholder not found |
|
262 |
throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found"); |
|
263 |
} |
|
264 |
} |
|
212 | 265 |
} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java | ||
---|---|---|
5 | 5 |
import eu.dnetlib.uoamonitorservice.dao.*; |
6 | 6 |
import eu.dnetlib.uoamonitorservice.entities.*; |
7 | 7 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
|
8 | 9 |
import org.apache.log4j.Logger; |
9 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
10 | 11 |
import org.springframework.web.bind.annotation.*; |
... | ... | |
303 | 304 |
} |
304 | 305 |
|
305 | 306 |
|
307 |
@RequestMapping(value = "/{stakeholderId}/toggle-status", method = RequestMethod.POST) |
|
308 |
public Boolean toggleStakeholderStatus(@PathVariable("stakeholderId") String stakeholderId) { |
|
309 |
log.debug("toggle indicator status (isActive)"); |
|
310 |
log.debug("Stakeholder: "+stakeholderId); |
|
311 |
|
|
312 |
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); |
|
313 |
if (stakeholder == null) { |
|
314 |
// EXCEPTION - Stakeholder not found |
|
315 |
throw new EntityNotFoundException("Toggle stakeholder status: Stakeholder with id: "+stakeholderId+" not found"); |
|
316 |
} |
|
317 |
stakeholder.setIsActive(!stakeholder.getIsActive()); |
|
318 |
|
|
319 |
stakeholderDAO.save(stakeholder); |
|
320 |
log.debug("Stakeholder toggled!"); |
|
321 |
|
|
322 |
return stakeholder.getIsActive(); |
|
323 |
} |
|
324 |
|
|
325 |
@RequestMapping(value = "/{stakeholderId}/toggle-access", method = RequestMethod.POST) |
|
326 |
public Boolean toggleStakeholderAccess(@PathVariable("stakeholderId") String stakeholderId) { |
|
327 |
log.debug("toggle indicator access (isPublic)"); |
|
328 |
log.debug("Stakeholder: "+stakeholderId); |
|
329 |
|
|
330 |
Stakeholder stakeholder = stakeholderDAO.findById(stakeholderId); |
|
331 |
if (stakeholder == null) { |
|
332 |
// EXCEPTION - Stakeholder not found |
|
333 |
throw new EntityNotFoundException("Toggle stakeholder access: Stakeholder with id: "+stakeholderId+" not found"); |
|
334 |
} |
|
335 |
stakeholder.setIsPublic(!stakeholder.getIsPublic()); |
|
336 |
|
|
337 |
stakeholderDAO.save(stakeholder); |
|
338 |
log.debug("Stakeholder toggled!"); |
|
339 |
|
|
340 |
return stakeholder.getIsPublic(); |
|
341 |
} |
|
342 |
|
|
343 |
|
|
306 | 344 |
// The following are not supposed to be used |
307 | 345 |
// @RequestMapping(value = "/stakeholder/dates", method = RequestMethod.GET) |
308 | 346 |
// public List<Date> getAllStakeholderDates() { |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java | ||
---|---|---|
252 | 252 |
return true; |
253 | 253 |
} |
254 | 254 |
|
255 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-status", method = RequestMethod.POST) |
|
256 |
public Boolean toggleSubCategoryStatus(@PathVariable("stakeholderId") String stakeholderId, |
|
257 |
@PathVariable("topicId") String topicId, |
|
258 |
@PathVariable("categoryId") String categoryId, |
|
259 |
@PathVariable("subcategoryId") String subcategoryId) { |
|
260 |
log.debug("toggle subCategory status (isActive)"); |
|
261 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
262 |
|
|
263 |
SubCategory subCategory = subCategoryDAO.findById(subcategoryId); |
|
264 |
if (subCategory == null) { |
|
265 |
// EXCEPTION - SubCategory not found |
|
266 |
throw new EntityNotFoundException("Toggle subCategory status: SubCategory with id: "+subcategoryId+" not found"); |
|
267 |
} |
|
268 |
subCategory.setIsActive(!subCategory.getIsActive()); |
|
269 |
|
|
270 |
this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); |
|
271 |
|
|
272 |
return subCategory.getIsActive(); |
|
273 |
} |
|
274 |
|
|
275 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/toggle-access", method = RequestMethod.POST) |
|
276 |
public Boolean toggleSubCategoryAccess(@PathVariable("stakeholderId") String stakeholderId, |
|
277 |
@PathVariable("topicId") String topicId, |
|
278 |
@PathVariable("categoryId") String categoryId, |
|
279 |
@PathVariable("subcategoryId") String subcategoryId) { |
|
280 |
log.debug("toggle subCategory access (isPublic)"); |
|
281 |
log.debug("Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId); |
|
282 |
|
|
283 |
SubCategory subCategory = subCategoryDAO.findById(subcategoryId); |
|
284 |
if (subCategory == null) { |
|
285 |
// EXCEPTION - SubCategory not found |
|
286 |
throw new EntityNotFoundException("Toggle subCategory access: SubCategory with id: "+subcategoryId+" not found"); |
|
287 |
} |
|
288 |
subCategory.setIsPublic(!subCategory.getIsPublic()); |
|
289 |
|
|
290 |
this.toggleSubCategory(stakeholderId, topicId, categoryId, subCategory); |
|
291 |
|
|
292 |
return subCategory.getIsPublic(); |
|
293 |
} |
|
294 |
|
|
295 |
public void toggleSubCategory(String stakeholderId, String topicId, String categoryId, SubCategory subcategory) { |
|
296 |
Stakeholder<String> stakeholder = stakeholderDAO.findById(stakeholderId); |
|
297 |
|
|
298 |
if (stakeholder != null) { |
|
299 |
|
|
300 |
Topic<String> topic = topicDAO.findById(topicId); |
|
301 |
if (topic != null) { |
|
302 |
if (stakeholder.getTopics().contains(topicId)) { |
|
303 |
|
|
304 |
Category<String> category = categoryDAO.findById(categoryId); |
|
305 |
if (category != null) { |
|
306 |
if (topic.getCategories().contains(categoryId)) { |
|
307 |
if (category.getSubCategories().contains(subcategory.getId())) { |
|
308 |
subCategoryDAO.save(subcategory); |
|
309 |
log.debug("SubCategory toggled!"); |
|
310 |
} else { |
|
311 |
// EXCEPTION - SubCategory not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); -> Category: category.getAlias(); |
|
312 |
throw new PathNotValidException("Toggle subCategory: SubCategory with id: "+subcategory.getId()+" not found in Category: "+categoryId); |
|
313 |
} |
|
314 |
} else { |
|
315 |
// EXCEPTION - Category not found in Stakeholder: stakeholder.getAlias(); -> Topic: topic.getAlias(); |
|
316 |
throw new PathNotValidException("Toggle subCategory: Category with id: "+categoryId+" not found in Topic: "+topicId); |
|
317 |
} |
|
318 |
} else { |
|
319 |
// EXCEPTION - Category not found |
|
320 |
throw new EntityNotFoundException("Toggle subCategory: Category with id: "+categoryId+" not found"); |
|
321 |
} |
|
322 |
} else { |
|
323 |
// EXCEPTION - Topic not found in Stakeholder: stakeholder.getAlias(); |
|
324 |
throw new PathNotValidException("Toggle subCategory: Topic with id: "+topicId+" not found in Stakeholder: "+stakeholderId); |
|
325 |
} |
|
326 |
} else { |
|
327 |
// EXCEPTION - Topic not found |
|
328 |
throw new EntityNotFoundException("Toggle subCategory: Topic with id: "+topicId+" not found"); |
|
329 |
} |
|
330 |
} else { |
|
331 |
// EXCEPTION - Stakeholder not found |
|
332 |
throw new EntityNotFoundException("Toggle subCategory: Stakeholder with id: "+stakeholderId+" not found"); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
255 | 336 |
} |
Also available in: Unified diff
StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java: toggle methods for status and access added.