From e36b0b8b52293ad5583eb94a531b707e1da2d0a6 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 24 Mar 2013 16:20:56 -0300 Subject: [PATCH] Handle exceptions. --- .../com/wisemapping/rest/AdminController.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java index c34281f1..3370dc8e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java @@ -131,40 +131,44 @@ public class AdminController extends BaseController { @ResponseStatus(value = HttpStatus.NO_CONTENT) @RequestMapping(method = RequestMethod.GET, value = "admin/database/purge") - public void purgeDB(@RequestParam(required = true) Integer muid, @RequestParam(required = true) Boolean apply) throws UnsupportedEncodingException, WiseMappingException { + public void purgeDB(@RequestParam(required = true) Integer muid, @RequestParam(required = true) Boolean apply) { for (int i = 0; i < muid; i++) { - System.out.println("looking for user:" + i); - User user; - try { - user = userService.getUserBy(i); - } catch (DataAccessException e) { - // User does not exit's continue ... - continue; - } + System.out.println("Looking for user:" + i); + User user = user = userService.getUserBy(i); - // Do not process admin accounts ... - if (user.getEmail().contains("wisemapping")) { - continue; - } + if (user != null) { + // Do not process admin accounts ... + if (user.getEmail().contains("wisemapping")) { + continue; + } - // Iterate over the list of maps ... - final List collaborations = mindmapService.findCollaborations(user); - for (Collaboration collaboration : collaborations) { - final Mindmap mindmap = collaboration.getMindMap(); - if (MindmapFilter.MY_MAPS.accept(mindmap, user)) { + try { + // Iterate over the list of maps ... + final List collaborations = mindmapService.findCollaborations(user); + for (Collaboration collaboration : collaborations) { + final Mindmap mindmap = collaboration.getMindMap(); + if (MindmapFilter.MY_MAPS.accept(mindmap, user)) { - final Calendar yearAgo = Calendar.getInstance(); - yearAgo.add(Calendar.MONTH, -18); - // The use has only two maps... When they have been modified .. - if (mindmap.getLastModificationTime().before(yearAgo) && !mindmap.isPublic()) { - if (isWelcomeMap(mindmap) || isSimpleMap(mindmap)) { - System.out.println("Purged map id:" + mindmap.getId() + ", userId:" + user.getId()); - if (apply) { - mindmapService.removeMindmap(mindmap, user); + final Calendar yearAgo = Calendar.getInstance(); + yearAgo.add(Calendar.MONTH, -18); + // The use has only two maps... When they have been modified .. + if (mindmap.getLastModificationTime().before(yearAgo) && !mindmap.isPublic()) { + if (isWelcomeMap(mindmap) || isSimpleMap(mindmap)) { + System.out.println("Purged map id:" + mindmap.getId() + ", userId:" + user.getId()); + if (apply) { + mindmapService.removeMindmap(mindmap, user); + } + } } } } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (WiseMappingException e) { + e.printStackTrace(); + } catch (RuntimeException e) { + e.printStackTrace(); } } }