mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Mindmap loading is lazy.
This commit is contained in:
parent
f5b4cc9ea7
commit
fd021de86d
@ -84,24 +84,26 @@ public class MindmapManagerImpl
|
||||
|
||||
final List<MindMapHistory> historyList = hibernateCriteria.list();
|
||||
|
||||
final Mindmap mindmapById = this.getMindmapById(mapId);
|
||||
final Calendar yearAgo = Calendar.getInstance();
|
||||
yearAgo.add(Calendar.MONTH, -12);
|
||||
final Mindmap mindmap = this.getMindmapById(mapId);
|
||||
if (mindmap != null) {
|
||||
final Calendar yearAgo = Calendar.getInstance();
|
||||
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 ...
|
||||
int max = mindmapById.getLastModificationTime().before(yearAgo) ? 10 : 25;
|
||||
// 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 = mindmap.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);
|
||||
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));
|
||||
if (historyList.size() > max) {
|
||||
for (int i = max; i < historyList.size(); i++) {
|
||||
getHibernateTemplate().delete(historyList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,7 +247,7 @@ public class MindmapManagerImpl
|
||||
getHibernateTemplate().delete(mindMap);
|
||||
}
|
||||
|
||||
private void saveHistory(@NotNull final Mindmap mindMap) {
|
||||
private void saveHistory(@NotNull final Mindmap mindMap) {
|
||||
final MindMapHistory history = new MindMapHistory();
|
||||
|
||||
history.setZippedXml(mindMap.getZippedXml());
|
||||
|
@ -57,7 +57,7 @@ public class FreemindExporter
|
||||
private Map<String, Node> nodesMap = null;
|
||||
|
||||
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 {
|
||||
|
@ -48,7 +48,7 @@ public class Mindmap {
|
||||
private User creator;
|
||||
private String tags;
|
||||
private String title;
|
||||
private byte[] xml;
|
||||
private byte[] zippedXml;
|
||||
|
||||
//~ Constructors .........................................................................................
|
||||
|
||||
@ -57,32 +57,30 @@ public class Mindmap {
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public void setXml(byte[] xml) {
|
||||
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);
|
||||
public void setUnzipXml(@NotNull byte[] value) {
|
||||
try {
|
||||
final byte[] zip = ZipUtils.bytesToZip(value);
|
||||
this.setZippedXml(zip);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] getZippedXml(){
|
||||
byte[] result = this.xml;
|
||||
if (result != null) {
|
||||
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 {
|
||||
result = ZipUtils.bytesToZip(result);
|
||||
final byte[] zip = this.getZippedXml();
|
||||
result = ZipUtils.zipToBytes(zip);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
@ -90,9 +88,18 @@ public class Mindmap {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setZippedXml(byte[] xml)
|
||||
throws IOException {
|
||||
this.xml = ZipUtils.zipToBytes(xml);
|
||||
@NotNull
|
||||
public String getXmlStr() throws UnsupportedEncodingException {
|
||||
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() {
|
||||
@ -143,6 +150,7 @@ public class Mindmap {
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Calendar getLastModificationTime() {
|
||||
return lastModificationTime;
|
||||
}
|
||||
@ -282,7 +290,7 @@ public class Mindmap {
|
||||
final Mindmap result = new Mindmap();
|
||||
result.setDescription(this.getDescription());
|
||||
result.setTitle(this.getTitle());
|
||||
result.setXml(this.getXml());
|
||||
result.setUnzipXml(this.getUnzipXml());
|
||||
result.setTags(this.getTags());
|
||||
|
||||
return result;
|
||||
|
@ -158,14 +158,9 @@ public class UserServiceImpl
|
||||
|
||||
final String mapXml = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/samples/tutorial.vm", model);
|
||||
|
||||
try {
|
||||
result.setXmlStr(mapXml);
|
||||
result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName);
|
||||
result.setDescription("");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
result.setXmlStr(mapXml);
|
||||
result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName);
|
||||
result.setDescription("");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
<property name="title"/>
|
||||
<property name="public"/>
|
||||
<property name="description"/>
|
||||
<property name="zippedXml" column="XML"/>
|
||||
<property name="zippedXml" column="XML" lazy="true"/>
|
||||
<property name="lastModificationTime" column="edition_date"/>
|
||||
<property name="creationTime" column="creation_date"/>
|
||||
<property name="tags" column="tags"/>
|
||||
|
@ -47,7 +47,7 @@ public class ExportFreemindTest {
|
||||
private Mindmap load(@NotNull File wisemap) throws IOException {
|
||||
final byte[] recContent = FileUtils.readFileToByteArray(wisemap);
|
||||
final Mindmap result = new Mindmap();
|
||||
result.setXml(recContent);
|
||||
result.setUnzipXml(recContent);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class ExportXsltBasedTest {
|
||||
private Mindmap load(@NotNull File wisemap) throws IOException {
|
||||
final byte[] recContent = FileUtils.readFileToByteArray(wisemap);
|
||||
final Mindmap result = new Mindmap();
|
||||
result.setXml(recContent);
|
||||
result.setUnzipXml(recContent);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user