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); public MindMapHistory getHistory(int historyId);
void updateCollaboration(@NotNull Collaboration collaboration); void updateCollaboration(@NotNull Collaboration collaboration);
void removeHistory(int mapId);
} }

View File

@ -57,9 +57,10 @@ public class MindmapManagerImpl
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class); final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
hibernateCriteria.add(Restrictions.eq("mindmapId", mindmapId)); hibernateCriteria.add(Restrictions.eq("mindmapId", mindmapId));
hibernateCriteria.addOrder(Order.desc("creationTime")); hibernateCriteria.addOrder(Order.desc("creationTime"));
// This line throws errors in some environments, so getting all history and taking firsts 10 records // This line throws errors in some environments, so getting all history and taking firsts 10 records
hibernateCriteria.setMaxResults(30); hibernateCriteria.setMaxResults(30);
return hibernateCriteria.list(); return hibernateCriteria.list();
} }
@Override @Override
@ -72,6 +73,26 @@ public class MindmapManagerImpl
getHibernateTemplate().save(collaboration); 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 @Override
public List<Mindmap> search(MindMapCriteria criteria, int maxResult) { public List<Mindmap> search(MindMapCriteria criteria, int maxResult) {
final Criteria hibernateCriteria = getSession().createCriteria(Mindmap.class); final Criteria hibernateCriteria = getSession().createCriteria(Mindmap.class);

View File

@ -137,13 +137,13 @@ public class AdminController extends BaseController {
try { try {
System.out.println("Looking for user:" + i); System.out.println("Looking for user:" + i);
final User user = userService.getUserBy(i); final User user = userService.getUserBy(i);
if (user != null) { if (user != null) {
// Do not process admin accounts ... // Do not process admin accounts ...
if (user.getEmail().contains("wisemapping")) { if (user.getEmail().contains("wisemapping")) {
continue; continue;
} }
// Iterate over the list of maps ... // Iterate over the list of maps ...
final List<Collaboration> collaborations = mindmapService.findCollaborations(user); final List<Collaboration> collaborations = mindmapService.findCollaborations(user);
for (Collaboration collaboration : collaborations) { for (Collaboration collaboration : collaborations) {
@ -151,11 +151,12 @@ public class AdminController extends BaseController {
if (MindmapFilter.MY_MAPS.accept(mindmap, user)) { if (MindmapFilter.MY_MAPS.accept(mindmap, user)) {
final Calendar yearAgo = Calendar.getInstance(); 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 .. // The use has only two maps... When they have been modified ..
System.out.println("Checking map id:" + mindmap.getId()); System.out.println("Checking map id:" + mindmap.getId());
if (mindmap.getLastModificationTime().before(yearAgo) && !mindmap.isPublic()) { 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)) { if (isWelcomeMap(mindmap) || isSimpleMap(mindmap)) {
System.out.println("Purged map id:" + mindmap.getId() + ", userId:" + user.getId()); 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) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (WiseMappingException e) { } catch (WiseMappingException e) {

View File

@ -67,4 +67,6 @@ public interface MindmapService {
LockManager getLockManager(); LockManager getLockManager();
boolean isAdmin(@Nullable User user); 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); return user != null && user.getEmail() != null && user.getEmail().equals(adminUser);
} }
@Override
public void removeHistory(int mapId) {
mindmapManager.removeHistory(mapId);
}
@Override @Override
public Mindmap getMindmapByTitle(String title, User user) { public Mindmap getMindmapByTitle(String title, User user) {
return mindmapManager.getMindmapByTitle(title, user); return mindmapManager.getMindmapByTitle(title, user);