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 981d894e..9889e1cb 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java @@ -67,5 +67,5 @@ public interface MindmapManager { void updateCollaboration(@NotNull Collaboration collaboration); - void removeHistory(int mapId); + void purgeHistory(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 112c3e83..b7f3e110 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java @@ -73,23 +73,25 @@ public class MindmapManagerImpl getHibernateTemplate().save(collaboration); } - /** - * Purge history map .... - * @param mapId - */ @Override - public void removeHistory(int mapId) { + public void purgeHistory(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); + + final Mindmap mindmapById = this.getMindmapById(mapId); + final Calendar yearAgo = Calendar.getInstance(); + yearAgo.add(Calendar.MONTH, -12); + + // If the map has not been modified in the last months, it means that I don't need to keep all the history ... + int max = mindmapById.getLastModificationTime().before(yearAgo) ? 10 : 25; + + if (historyList.size() > max) { + for (int i = max; i < historyList.size(); i++) { + getHibernateTemplate().delete(historyList.get(i)); } - i++; } } 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 681cbef1..bfebec21 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java @@ -29,7 +29,6 @@ import com.wisemapping.service.UserService; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.dao.DataAccessException; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -167,7 +166,7 @@ public class AdminController extends BaseController { } // Purge history ... - mindmapService.removeHistory(mindmap.getId()); + mindmapService.purgeHistory(mindmap.getId()); } } } @@ -185,7 +184,7 @@ public class AdminController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "admin/database/purge/history") public void purgeHistory(@RequestParam(required = true) Integer mapId) throws WiseMappingException, UnsupportedEncodingException { - mindmapService.removeHistory(mapId); + mindmapService.purgeHistory(mapId); } 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 5682db95..8a0c04b1 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java @@ -68,5 +68,5 @@ public interface MindmapService { boolean isAdmin(@Nullable User user); - void removeHistory(int mapId); + void purgeHistory(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 2d9be71d..70b2a83b 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -83,8 +83,8 @@ public class MindmapServiceImpl } @Override - public void removeHistory(int mapId) { - mindmapManager.removeHistory(mapId); + public void purgeHistory(int mapId) { + mindmapManager.purgeHistory(mapId); } @Override diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml index 4a5a7338..65ea911d 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml @@ -30,6 +30,7 @@ update* add* remove* + purge* revert* diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml index c8017226..0ba373f6 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml @@ -53,7 +53,7 @@ - +