Mindmap loading is lazy.

This commit is contained in:
Paulo Gustavo Veiga 2013-03-30 01:09:28 -03:00
parent f5b4cc9ea7
commit fd021de86d
7 changed files with 59 additions and 54 deletions

View File

@ -84,16 +84,17 @@ public class MindmapManagerImpl
final List<MindMapHistory> historyList = hibernateCriteria.list(); final List<MindMapHistory> historyList = hibernateCriteria.list();
final Mindmap mindmapById = this.getMindmapById(mapId); final Mindmap mindmap = this.getMindmapById(mapId);
if (mindmap != null) {
final Calendar yearAgo = Calendar.getInstance(); final Calendar yearAgo = Calendar.getInstance();
yearAgo.add(Calendar.MONTH, -12); 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 ... // 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; int max = mindmap.getLastModificationTime().before(yearAgo) ? 10 : 25;
for (MindMapHistory history : historyList) { for (MindMapHistory history : historyList) {
byte[] zippedXml = history.getZippedXml(); byte[] zippedXml = history.getZippedXml();
if(new String(zippedXml).startsWith("<map")){ if (new String(zippedXml).startsWith("<map")) {
history.setZippedXml(ZipUtils.bytesToZip(zippedXml)); history.setZippedXml(ZipUtils.bytesToZip(zippedXml));
getHibernateTemplate().update(history); getHibernateTemplate().update(history);
} }
@ -105,6 +106,7 @@ public class MindmapManagerImpl
} }
} }
} }
}
@Override @Override
public List<Mindmap> search(MindMapCriteria criteria, int maxResult) { public List<Mindmap> search(MindMapCriteria criteria, int maxResult) {

View File

@ -57,7 +57,7 @@ public class FreemindExporter
private Map<String, Node> nodesMap = null; private Map<String, Node> nodesMap = null;
public void export(Mindmap map, OutputStream outputStream) throws ExportException { public void export(Mindmap map, OutputStream outputStream) throws ExportException {
export(map.getXml(), outputStream); export(map.getUnzipXml(), outputStream);
} }
public void export(byte[] xml, @NotNull OutputStream outputStream) throws ExportException { public void export(byte[] xml, @NotNull OutputStream outputStream) throws ExportException {

View File

@ -48,7 +48,7 @@ public class Mindmap {
private User creator; private User creator;
private String tags; private String tags;
private String title; private String title;
private byte[] xml; private byte[] zippedXml;
//~ Constructors ......................................................................................... //~ Constructors .........................................................................................
@ -57,32 +57,30 @@ public class Mindmap {
//~ Methods .............................................................................................. //~ Methods ..............................................................................................
public void setXml(byte[] xml) { public void setUnzipXml(@NotNull byte[] value) {
this.xml = xml;
}
public void setXmlStr(@NotNull String xml)
throws IOException {
this.xml = xml.getBytes(UTF_8);
}
public byte[] getXml() {
return xml;
}
public String getXmlStr() throws UnsupportedEncodingException {
String result = null;
if (this.xml != null) {
result = new String(this.xml, UTF_8);
}
return result;
}
public byte[] getZippedXml(){
byte[] result = this.xml;
if (result != null) {
try { try {
result = ZipUtils.bytesToZip(result); final byte[] zip = ZipUtils.bytesToZip(value);
this.setZippedXml(zip);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void setXmlStr(@NotNull String xml) {
try {
this.setUnzipXml(xml.getBytes(UTF_8));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
@NotNull
public byte[] getUnzipXml() {
byte[] result = new byte[]{};
if (zippedXml != null) {
try {
final byte[] zip = this.getZippedXml();
result = ZipUtils.zipToBytes(zip);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
@ -90,9 +88,18 @@ public class Mindmap {
return result; return result;
} }
public void setZippedXml(byte[] xml) @NotNull
throws IOException { public String getXmlStr() throws UnsupportedEncodingException {
this.xml = ZipUtils.zipToBytes(xml); return new String(this.getUnzipXml(), UTF_8);
}
@NotNull
public byte[] getZippedXml() {
return zippedXml;
}
public void setZippedXml(@NotNull byte[] value) {
this.zippedXml = value;
} }
public Set<Collaboration> getCollaborations() { public Set<Collaboration> getCollaborations() {
@ -143,6 +150,7 @@ public class Mindmap {
this.isPublic = isPublic; this.isPublic = isPublic;
} }
@NotNull
public Calendar getLastModificationTime() { public Calendar getLastModificationTime() {
return lastModificationTime; return lastModificationTime;
} }
@ -282,7 +290,7 @@ public class Mindmap {
final Mindmap result = new Mindmap(); final Mindmap result = new Mindmap();
result.setDescription(this.getDescription()); result.setDescription(this.getDescription());
result.setTitle(this.getTitle()); result.setTitle(this.getTitle());
result.setXml(this.getXml()); result.setUnzipXml(this.getUnzipXml());
result.setTags(this.getTags()); result.setTags(this.getTags());
return result; return result;

View File

@ -158,15 +158,10 @@ public class UserServiceImpl
final String mapXml = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/samples/tutorial.vm", model); final String mapXml = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/samples/tutorial.vm", model);
try {
result.setXmlStr(mapXml); result.setXmlStr(mapXml);
result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName); result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName);
result.setDescription(""); result.setDescription("");
} catch (IOException e) {
e.printStackTrace();
}
return result; return result;
} }

View File

@ -12,7 +12,7 @@
<property name="title"/> <property name="title"/>
<property name="public"/> <property name="public"/>
<property name="description"/> <property name="description"/>
<property name="zippedXml" column="XML"/> <property name="zippedXml" column="XML" lazy="true"/>
<property name="lastModificationTime" column="edition_date"/> <property name="lastModificationTime" column="edition_date"/>
<property name="creationTime" column="creation_date"/> <property name="creationTime" column="creation_date"/>
<property name="tags" column="tags"/> <property name="tags" column="tags"/>

View File

@ -47,7 +47,7 @@ public class ExportFreemindTest {
private Mindmap load(@NotNull File wisemap) throws IOException { private Mindmap load(@NotNull File wisemap) throws IOException {
final byte[] recContent = FileUtils.readFileToByteArray(wisemap); final byte[] recContent = FileUtils.readFileToByteArray(wisemap);
final Mindmap result = new Mindmap(); final Mindmap result = new Mindmap();
result.setXml(recContent); result.setUnzipXml(recContent);
return result; return result;
} }

View File

@ -45,7 +45,7 @@ public class ExportXsltBasedTest {
private Mindmap load(@NotNull File wisemap) throws IOException { private Mindmap load(@NotNull File wisemap) throws IOException {
final byte[] recContent = FileUtils.readFileToByteArray(wisemap); final byte[] recContent = FileUtils.readFileToByteArray(wisemap);
final Mindmap result = new Mindmap(); final Mindmap result = new Mindmap();
result.setXml(recContent); result.setUnzipXml(recContent);
return result; return result;
} }