Project

General

Profile

« Previous | Next » 

Revision 57934

StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java: toggle methods for status and access added.

View differences:

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
}

Also available in: Unified diff