Project

General

Profile

« Previous | Next » 

Revision 58978

[Trunk | Monitor Service]:
1. Adding parameter in delete methods to delete or disconnect all profiles based on the default one that is being deleted (not for stakeholder).
2. In delete methods remove iterations (for deleting inner elements) and call "deleteTree()" method.

View differences:

TopicController.java
9 9
import org.springframework.web.bind.annotation.*;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Iterator;
12 13
import java.util.List;
13 14

  
14 15
@RestController
......
162 163

  
163 164
    @RequestMapping(value = "/{stakeholderId}/{topicId}/delete", method = RequestMethod.DELETE)
164 165
    public boolean deleteTopic(@PathVariable("stakeholderId") String stakeholderId,
165
                               @PathVariable("topicId") String topicId) {
166
                               @PathVariable("topicId") String topicId,
167
                               @RequestParam(required = false) String children) {
166 168
        log.debug("delete topic");
167 169
        log.debug("Id: "+topicId + " - Stakeholder: "+stakeholderId);
168 170

  
......
176 178
                List<String> topics = stakeholder.getTopics();
177 179
                int index = topics.indexOf(topicId);
178 180
                if(index != -1) {
179
                    for(String categoryId : topic.getCategories()) {
180
                        Category<String> category = categoryDAO.findById(categoryId);
181
                        if(category == null) {
182
                            // EXCEPTION - Category not found
183
                            throw new EntityNotFoundException("Delete topic: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
184
                        }
181
                    // this topic belongs in default profile
182
                    if(stakeholder.getDefaultId() == null && children != null) {
183
                        onDeleteDefaultTopic(topicId, stakeholderId, children);
184
                    }
185 185

  
186
                        for(String subCategoryId : category.getSubCategories()) {
187
                            SubCategory<String> subcategory = subCategoryDAO.findById(subCategoryId);
188
                            if (subcategory == null) {
189
                                // EXCEPTION - SubCategory not found
190
                                throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
191
                            }
186
//                    for(String categoryId : topic.getCategories()) {
187
//                        Category<String> category = categoryDAO.findById(categoryId);
188
//                        if(category == null) {
189
//                            // EXCEPTION - Category not found
190
//                            throw new EntityNotFoundException("Delete topic: Category with id: "+categoryId+" not found (category exists in topic: "+topicId+")");
191
//                        }
192
//
193
//                        for(String subCategoryId : category.getSubCategories()) {
194
//                            SubCategory<String> subcategory = subCategoryDAO.findById(subCategoryId);
195
//                            if (subcategory == null) {
196
//                                // EXCEPTION - SubCategory not found
197
//                                throw new EntityNotFoundException("Delete topic: SubCategory with id: "+subCategoryId+" not found (subcategory exists in category: "+categoryId+")");
198
//                            }
199
//
200
//                            for(String chartSectionId : subcategory.getCharts()) {
201
//                                Section<String> chartSection = sectionDAO.findById(chartSectionId);
202
//                                if (chartSection == null) {
203
//                                    // EXCEPTION - Section not found
204
//                                    throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
205
//                                }
206
//
207
//                                for (String chartId : chartSection.getIndicators()) {
208
//                                    indicatorDAO.delete(chartId);
209
//                                }
210
//                                subcategory.setCharts(null);
211
//                                sectionDAO.delete(chartSectionId);
212
//                            }
213
//
214
//                            for(String numberSectionId : subcategory.getNumbers()) {
215
//                                Section<String> numberSection = sectionDAO.findById(numberSectionId);
216
//                                if (numberSection == null) {
217
//                                    // EXCEPTION - Section not found
218
//                                    throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
219
//                                }
220
//
221
//                                for (String numberId : numberSection.getIndicators()) {
222
//                                    indicatorDAO.delete(numberId);
223
//                                }
224
//                                subcategory.setNumbers(null);
225
//                                sectionDAO.delete(numberSectionId);
226
//                            }
227
//
228
//                            subCategoryDAO.delete(subCategoryId);
229
//                        }
230
//                        category.setSubCategories(null);
231
//                        categoryDAO.delete(categoryId);
232
//                    }
233
                    categoryController.deleteTree(topic);
192 234

  
193
                            for(String chartSectionId : subcategory.getCharts()) {
194
                                Section<String> chartSection = sectionDAO.findById(chartSectionId);
195
                                if (chartSection == null) {
196
                                    // EXCEPTION - Section not found
197
                                    throw new EntityNotFoundException("Delete topic: Section with id: "+chartSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
198
                                }
199

  
200
                                for (String chartId : chartSection.getIndicators()) {
201
                                    indicatorDAO.delete(chartId);
202
                                }
203
                                subcategory.setCharts(null);
204
                                sectionDAO.delete(chartSectionId);
205
                            }
206

  
207
                            for(String numberSectionId : subcategory.getNumbers()) {
208
                                Section<String> numberSection = sectionDAO.findById(numberSectionId);
209
                                if (numberSection == null) {
210
                                    // EXCEPTION - Section not found
211
                                    throw new EntityNotFoundException("Delete topic: Section with id: "+numberSectionId+" not found (section exists in subcategory: "+subCategoryId+")");
212
                                }
213

  
214
                                for (String numberId : numberSection.getIndicators()) {
215
                                    indicatorDAO.delete(numberId);
216
                                }
217
                                subcategory.setNumbers(null);
218
                                sectionDAO.delete(numberSectionId);
219
                            }
220

  
221
                            subCategoryDAO.delete(subCategoryId);
222
                        }
223
                        category.setSubCategories(null);
224
                        categoryDAO.delete(categoryId);
225
                    }
226 235
                    topic.setCategories(null);
227 236

  
228 237
                    topics.remove(index);
......
246 255
        return true;
247 256
    }
248 257

  
258

  
259
    public boolean onDeleteDefaultTopic(String defaultTopicId, String defaultStakeholderId, String children) {
260
        if(children.equals("delete")) {
261
            List<Stakeholder> stakeholders = stakeholderDAO.findByDefaultId(defaultStakeholderId);
262
            List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
263

  
264
            for(Stakeholder stakeholder : stakeholders) {
265
                Iterator<Topic> topicsIterator = topics.iterator();
266
                while(topicsIterator.hasNext()) {
267
                    Topic topic = topicsIterator.next();
268

  
269
                    String topicId = topic.getId();
270

  
271
                    if(stakeholder.getTopics() != null && stakeholder.getTopics().contains(topicId)) {
272
                        topicsIterator.remove();
273

  
274
                        stakeholder.getTopics().remove(topicId);
275
                        stakeholderDAO.save(stakeholder);
276

  
277
                        categoryController.deleteTree(topic);
278

  
279
                        topicDAO.delete(topicId);
280
                        log.debug("Topic with id: "+topicId+" deleted!");
281

  
282
                        break;
283
                    }
284
                }
285
            }
286
        } else if(children.equals("disconnect")) {
287
            List<Topic> topics = topicDAO.findByDefaultId(defaultTopicId);
288
            for(Topic topic : topics) {
289
                categoryController.disConnectTree(topic);
290

  
291
                topic.setDefaultId(null);
292
                topicDAO.save(topic);
293

  
294
                log.debug("DefaultId for Topic with id: "+topic.getId()+" empty!");
295
            }
296
        }
297
        return true;
298
    }
299

  
249 300
    @RequestMapping(value = "/{stakeholderId}/{topicId}/toggle-status", method = RequestMethod.POST)
250 301
    public Boolean toggleTopicStatus(@PathVariable("stakeholderId") String stakeholderId,
251 302
                                     @PathVariable("topicId") String topicId) {
......
298 349
            throw new EntityNotFoundException("Toggle topic: Stakeholder with id: "+stakeholderId+" not found");
299 350
        }
300 351
    }
352

  
353
    public void deleteTree(Stakeholder stakeholder) {
354
        List<String> topics = stakeholder.getTopics();
355
        for(String topicId : topics) {
356
            Topic topic = topicDAO.findById(topicId);
357
            if (topic == null) {
358
                // EXCEPTION - Topic not found
359
                throw new EntityNotFoundException("Topic delete tree: Topic with id: "+topicId+" not found (topic exists in stakeholder: "+stakeholder.getId()+")");
360
            }
361

  
362
            categoryController.deleteTree(topic);
363

  
364
            topicDAO.delete(topicId);
365
        }
366
    }
301 367
}

Also available in: Unified diff