Add compress fix.

This commit is contained in:
Paulo Gustavo Veiga 2013-03-29 15:44:49 -03:00
parent 3696e126e3
commit 4d46864388
7 changed files with 21 additions and 11 deletions

View File

@ -20,8 +20,8 @@ package com.wisemapping.dao;
import com.wisemapping.model.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.List;
public interface MindmapManager {
@ -67,5 +67,5 @@ public interface MindmapManager {
void updateCollaboration(@NotNull Collaboration collaboration);
void purgeHistory(int mapId);
void purgeHistory(int mapId) throws IOException;
}

View File

@ -19,6 +19,7 @@
package com.wisemapping.dao;
import com.wisemapping.model.*;
import com.wisemapping.util.ZipUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.hibernate.criterion.Restrictions;
@ -75,7 +76,7 @@ public class MindmapManagerImpl
}
@Override
public void purgeHistory(int mapId) {
public void purgeHistory(int mapId) throws IOException {
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
hibernateCriteria.add(Restrictions.eq("mindmapId", mapId));
hibernateCriteria.addOrder(Order.desc("creationTime"));
@ -89,6 +90,14 @@ public class MindmapManagerImpl
// 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;
for (MindMapHistory history : historyList) {
byte[] zippedXml = history.getZippedXml();
if(new String(zippedXml).startsWith("<map")){
history.setZippedXml(ZipUtils.bytesToZip(zippedXml));
getHibernateTemplate().update(history);
}
}
if (historyList.size() > max) {
for (int i = max; i < historyList.size(); i++) {
getHibernateTemplate().delete(historyList.get(i));

View File

@ -19,6 +19,7 @@
package com.wisemapping.model;
import com.wisemapping.util.ZipUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
@ -52,6 +53,7 @@ public class MindMapHistory {
this.mindmapId = id;
}
@NotNull
public Calendar getCreationTime() {
return creationTime;
}

View File

@ -19,10 +19,7 @@
package com.wisemapping.rest;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import com.wisemapping.model.*;
import com.wisemapping.rest.model.RestUser;
import com.wisemapping.service.MindmapService;
import com.wisemapping.service.UserService;
@ -176,13 +173,15 @@ public class AdminController extends BaseController {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (RuntimeException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@RequestMapping(method = RequestMethod.GET, value = "admin/database/purge/history")
public void purgeHistory(@RequestParam(required = true) Integer mapId) throws WiseMappingException, UnsupportedEncodingException {
public void purgeHistory(@RequestParam(required = true) Integer mapId) throws WiseMappingException, IOException {
mindmapService.purgeHistory(mapId);
}

View File

@ -68,5 +68,5 @@ public interface MindmapService {
boolean isAdmin(@Nullable User user);
void purgeHistory(int mapId);
void purgeHistory(int mapId) throws IOException;
}

View File

@ -83,7 +83,7 @@ public class MindmapServiceImpl
}
@Override
public void purgeHistory(int mapId) {
public void purgeHistory(int mapId) throws IOException {
mindmapManager.purgeHistory(mapId);
}

View File

@ -11,7 +11,7 @@
</id>
<property name="mindmapId" column="mindmap_id"/>
<property name="zippedXml" column="xml"/>
<property name="zippedXml" column="xml" lazy="true"/>
<property name="creationTime" column="creation_date"/>
<many-to-one name="editor" column="editor_id" unique="false" not-null="false" lazy="proxy"/>
</class>