From f961ae578c17177f4050c3405a3db89027ed6ffb Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 24 Mar 2013 22:49:55 -0300 Subject: [PATCH] Add purge to history... --- .../com/wisemapping/dao/MindmapManager.java | 2 ++ .../wisemapping/dao/MindmapManagerImpl.java | 23 +++++++++++++++++- .../com/wisemapping/rest/AdminController.java | 24 +++++++++++-------- .../wisemapping/service/MindmapService.java | 2 ++ .../service/MindmapServiceImpl.java | 5 ++++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java index 25c4815a..981d894e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java @@ -66,4 +66,6 @@ public interface MindmapManager { public MindMapHistory getHistory(int historyId); void updateCollaboration(@NotNull Collaboration collaboration); + + void removeHistory(int mapId); } diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java index 281e2fb4..112c3e83 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java @@ -57,9 +57,10 @@ public class MindmapManagerImpl final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class); hibernateCriteria.add(Restrictions.eq("mindmapId", mindmapId)); hibernateCriteria.addOrder(Order.desc("creationTime")); + // This line throws errors in some environments, so getting all history and taking firsts 10 records hibernateCriteria.setMaxResults(30); - return hibernateCriteria.list(); + return hibernateCriteria.list(); } @Override @@ -72,6 +73,26 @@ public class MindmapManagerImpl getHibernateTemplate().save(collaboration); } + /** + * Purge history map .... + * @param mapId + */ + @Override + public void removeHistory(int mapId) { + final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class); + hibernateCriteria.add(Restrictions.eq("mindmapId", mapId)); + hibernateCriteria.addOrder(Order.desc("creationTime")); + + final List historyList = hibernateCriteria.list(); + int i = 0; + for (MindMapHistory history : historyList) { + if (i > 20) { + getHibernateTemplate().delete(history); + } + i++; + } + } + @Override public List search(MindMapCriteria criteria, int maxResult) { final Criteria hibernateCriteria = getSession().createCriteria(Mindmap.class); 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 31fbdfff..3f385fff 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java @@ -137,13 +137,13 @@ public class AdminController extends BaseController { try { - System.out.println("Looking for user:" + i); - final User user = userService.getUserBy(i); - if (user != null) { - // Do not process admin accounts ... - if (user.getEmail().contains("wisemapping")) { - continue; - } + System.out.println("Looking for user:" + i); + final User user = userService.getUserBy(i); + 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) { @@ -151,11 +151,12 @@ public class AdminController extends BaseController { if (MindmapFilter.MY_MAPS.accept(mindmap, user)) { final Calendar yearAgo = Calendar.getInstance(); - yearAgo.add(Calendar.MONTH, -8); + yearAgo.add(Calendar.MONTH, -4); + // The use has only two maps... When they have been modified .. System.out.println("Checking map id:" + mindmap.getId()); if (mindmap.getLastModificationTime().before(yearAgo) && !mindmap.isPublic()) { - System.out.println("Old map. Is simple ?:" + mindmap.getId()); + System.out.println("Old map months map:" + mindmap.getId()); if (isWelcomeMap(mindmap) || isSimpleMap(mindmap)) { System.out.println("Purged map id:" + mindmap.getId() + ", userId:" + user.getId()); @@ -164,9 +165,12 @@ public class AdminController extends BaseController { } } } + + // Purge history ... + mindmapService.removeHistory(mindmap.getId()); } } - } + } } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (WiseMappingException e) { diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java index 55afa5f3..5682db95 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java @@ -67,4 +67,6 @@ public interface MindmapService { LockManager getLockManager(); boolean isAdmin(@Nullable User user); + + void removeHistory(int mapId); } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java index 08250564..2d9be71d 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -82,6 +82,11 @@ public class MindmapServiceImpl return user != null && user.getEmail() != null && user.getEmail().equals(adminUser); } + @Override + public void removeHistory(int mapId) { + mindmapManager.removeHistory(mapId); + } + @Override public Mindmap getMindmapByTitle(String title, User user) { return mindmapManager.getMindmapByTitle(title, user);