Add purge to history...

This commit is contained in:
Paulo Gustavo Veiga 2013-03-24 22:49:55 -03:00
parent 0188e15a92
commit f961ae578c
5 changed files with 45 additions and 11 deletions

View File

@ -66,4 +66,6 @@ public interface MindmapManager {
public MindMapHistory getHistory(int historyId);
void updateCollaboration(@NotNull Collaboration collaboration);
void removeHistory(int mapId);
}

View File

@ -57,6 +57,7 @@ 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();
@ -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<MindMapHistory> historyList = hibernateCriteria.list();
int i = 0;
for (MindMapHistory history : historyList) {
if (i > 20) {
getHibernateTemplate().delete(history);
}
i++;
}
}
@Override
public List<Mindmap> search(MindMapCriteria criteria, int maxResult) {
final Criteria hibernateCriteria = getSession().createCriteria(Mindmap.class);

View File

@ -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,6 +165,9 @@ public class AdminController extends BaseController {
}
}
}
// Purge history ...
mindmapService.removeHistory(mindmap.getId());
}
}
}

View File

@ -67,4 +67,6 @@ public interface MindmapService {
LockManager getLockManager();
boolean isAdmin(@Nullable User user);
void removeHistory(int mapId);
}

View File

@ -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);