mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-23 03:43:48 +01:00
Add purge to history...
This commit is contained in:
parent
0188e15a92
commit
f961ae578c
@ -66,4 +66,6 @@ public interface MindmapManager {
|
||||
public MindMapHistory getHistory(int historyId);
|
||||
|
||||
void updateCollaboration(@NotNull Collaboration collaboration);
|
||||
|
||||
void removeHistory(int mapId);
|
||||
}
|
||||
|
@ -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<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);
|
||||
|
@ -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<Collaboration> 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) {
|
||||
|
@ -67,4 +67,6 @@ public interface MindmapService {
|
||||
LockManager getLockManager();
|
||||
|
||||
boolean isAdmin(@Nullable User user);
|
||||
|
||||
void removeHistory(int mapId);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user