Merge branch 'develop' into feature/springboot

This commit is contained in:
Paulo Gustavo Veiga 2023-10-29 22:37:43 -07:00
commit 7a6d1c1280
12 changed files with 247 additions and 314 deletions

View File

@ -96,5 +96,5 @@ After credential was created, Google will show you the clientId and clientSecret
## License ## License
The source code is Licensed under the WiseMapping Open License, Version 1.0 (the “License”); The source code is Licensed under the WiseMapping Open License, Version 1.0 (the “License”);
You may obtain a copy of the License at: [https://bitbucket.org/wisemapping/wisemapping-open-source/src/develop/license.md](https://bitbucket.org/wisemapping/wisemapping-open-source/src/develop/license.md) You may obtain a copy of the License at: [https://bitbucket.org/wisemapping/wisemapping-open-source/src/develop/license.md](https://bitbucket.org/wisemapping/wisemapping-open-source/src/develop/LICENSE.md)

View File

@ -2,24 +2,19 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>wise-webapp</artifactId> <artifactId>wise-webapp</artifactId>
<packaging>war</packaging>
<name>WiseMapping Webapp</name> <name>WiseMapping Webapp</name>
<url>http://www.wisemapping.org</url> <url>http://www.wisemapping.org</url>
<version>5.1.0-SNAPSHOT</version>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.wisemapping</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>wisemapping</artifactId>
<version>3.1.2</version> <relativePath>../pom.xml</relativePath>
<version>5.1.0-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>
<com.wisemapping.version>5.1.0-SNAPSHOT</com.wisemapping.version> <org.springframework.version>6.0.13</org.springframework.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<org.springframework.version>6.0.11</org.springframework.version>
<org.springframework.addons>6.1.2</org.springframework.addons> <org.springframework.addons>6.1.2</org.springframework.addons>
<hibernate.version>6.2.6.Final</hibernate.version>
<hibernate-validator.version>6.0.21.Final</hibernate-validator.version>
<spring-security-taglibs.version>6.0.2</spring-security-taglibs.version> <spring-security-taglibs.version>6.0.2</spring-security-taglibs.version>
</properties> </properties>
@ -36,27 +31,6 @@
<version>1.7</version> <version>1.7</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
@ -69,33 +43,39 @@
<version>12.0</version> <version>12.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-messaging</artifactId>--> <artifactId>spring-webmvc</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- </dependency>--> <scope>compile</scope>
<!-- <dependency>--> </dependency>
<!-- <groupId>org.springframework</groupId>--> <dependency>
<!-- <artifactId>spring-websocket</artifactId>--> <groupId>org.springframework</groupId>
<!-- <version>${org.springframework.version}</version>--> <artifactId>spring-messaging</artifactId>
<!-- </dependency>--> <version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.5.4</version> <version>42.5.4</version>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-beans</artifactId>--> <artifactId>spring-beans</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-tx</artifactId>--> <artifactId>spring-tx</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId> <artifactId>spring-security-taglibs</artifactId>
@ -104,14 +84,14 @@
<!-- Hibernate --> <!-- Hibernate -->
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId> <artifactId>hibernate-core</artifactId>
<version>5.6.15.Final</version> <version>6.1.7.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>jakarta.xml.bind</groupId> <groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId> <artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version> <version>4.0.1</version>
</dependency> </dependency>
<!-- Hibernate Validator --> <!-- Hibernate Validator -->
@ -121,72 +101,78 @@
<version>8.0.1.Final</version> <version>8.0.1.Final</version>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-orm</artifactId>--> <artifactId>spring-orm</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-context</artifactId>--> <artifactId>spring-context</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-web</artifactId>--> <artifactId>spring-web</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-oxm</artifactId>--> <artifactId>spring-oxm</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-context-support</artifactId>--> <artifactId>spring-context-support</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework.data</groupId>--> <groupId>org.springframework.data</groupId>
<!-- <artifactId>spring-data-jpa</artifactId>--> <artifactId>spring-data-jpa</artifactId>
<!-- <version>3.1.0</version>--> <version>3.1.0</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-test</artifactId>--> <artifactId>spring-test</artifactId>
<!-- <version>6.0.6</version>--> <version>6.0.6</version>
<!-- <scope>test</scope>--> <scope>test</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>spring-aop</artifactId>--> <artifactId>spring-aop</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.version}</version>
<!-- <scope>runtime</scope>--> <scope>runtime</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework.security</groupId>--> <groupId>org.springframework.security</groupId>
<!-- <artifactId>spring-security-core</artifactId>--> <artifactId>spring-security-web</artifactId>
<!-- <version>${org.springframework.addons}</version>--> <version>${org.springframework.addons}</version>
<!-- <scope>compile</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework</groupId>--> <groupId>org.springframework.security</groupId>
<!-- <artifactId>spring-jdbc</artifactId>--> <artifactId>spring-security-core</artifactId>
<!-- <version>${org.springframework.version}</version>--> <version>${org.springframework.addons}</version>
<!-- <scope>runtime</scope>--> <scope>compile</scope>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>aopalliance</groupId>--> <groupId>org.springframework</groupId>
<!-- <artifactId>aopalliance</artifactId>--> <artifactId>spring-jdbc</artifactId>
<!-- <version>1.0</version>--> <version>${org.springframework.version}</version>
<!-- <scope>compile</scope>--> <scope>runtime</scope>
<!-- </dependency>--> </dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>jakarta.mail</groupId> <groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId> <artifactId>jakarta.mail-api</artifactId>
@ -197,26 +183,16 @@
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version> <version>8.1.0</version>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.apache.commons</groupId>--> <groupId>org.apache.commons</groupId>
<!-- <artifactId>commons-dbcp2</artifactId>--> <artifactId>commons-dbcp2</artifactId>
<!-- <version>2.9.0</version>--> <version>2.9.0</version>
<!-- </dependency>--> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.angus</groupId> <groupId>org.eclipse.angus</groupId>
<artifactId>jakarta.mail</artifactId> <artifactId>jakarta.mail</artifactId>
<version>2.0.2</version> <version>2.0.2</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.hibernate</groupId>-->
<!-- <artifactId>hibernate-ehcache</artifactId>-->
<!-- <version>5.6.15.Final</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.cache</groupId>-->
<!-- <artifactId>cache-api</artifactId>-->
<!-- <version>1.1.1</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
@ -305,9 +281,10 @@
<dependency> <dependency>
<groupId>org.hsqldb</groupId> <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
<version>2.7.2</version> <version>2.7.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<executions> <executions>
<execution> <execution>
<id>drop-schemas</id> <id>drop-schemas</id>
@ -419,8 +396,6 @@
</webResources> </webResources>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>

View File

@ -19,14 +19,21 @@ package com.wisemapping.dao;
import com.wisemapping.model.Label; import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import jakarta.annotation.Resource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.SelectionQuery;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
public class LabelManagerImpl extends HibernateDaoSupport @Repository
public class LabelManagerImpl
implements LabelManager { implements LabelManager {
@Resource
private SessionFactory sessionFactory;
@Override @Override
public void addLabel(@NotNull final Label label) { public void addLabel(@NotNull final Label label) {
@ -35,31 +42,37 @@ public class LabelManagerImpl extends HibernateDaoSupport
@Override @Override
public void saveLabel(@NotNull final Label label) { public void saveLabel(@NotNull final Label label) {
currentSession().save(label); getSession().persist(label);
}
private Session getSession() {
return sessionFactory.getCurrentSession();
} }
@NotNull @NotNull
@Override @Override
@SuppressWarnings("unchecked")
public List<Label> getAllLabels(@NotNull final User user) { public List<Label> getAllLabels(@NotNull final User user) {
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where creator_id=:creatorId"); final SelectionQuery<Label> query = getSession().createSelectionQuery("from com.wisemapping.model.Label wisemapping where creator=:creatorId", Label.class);
query.setParameter("creatorId", user.getId()); query.setParameter("creatorId", user);
return query.list(); return query.list();
} }
@Nullable @Nullable
@Override @Override
public Label getLabelById(int id, @NotNull final User user) { public Label getLabelById(int id, @NotNull final User user) {
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator"); final Session session = getSession();
final SelectionQuery<Label> query = session.createSelectionQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator", Label.class);
query.setParameter("id", id); query.setParameter("id", id);
query.setParameter("creator", user); query.setParameter("creator", user);
return getFirst(query.list());
final List<Label> resultList = query.getResultList();
return getFirst(resultList);
} }
@Nullable @Nullable
@Override @Override
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) { public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator"); final SelectionQuery<Label> query = getSession().createSelectionQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator", Label.class);
query.setParameter("title", title); query.setParameter("title", title);
query.setParameter("creator", user); query.setParameter("creator", user);
return getFirst(query.list()); return getFirst(query.list());
@ -67,10 +80,11 @@ public class LabelManagerImpl extends HibernateDaoSupport
@Override @Override
public void removeLabel(@NotNull Label label) { public void removeLabel(@NotNull Label label) {
getHibernateTemplate().delete(label); getSession().remove(label);
} }
@Nullable private Label getFirst(List<Label> labels) { @Nullable
private Label getFirst(final List<Label> labels) {
Label result = null; Label result = null;
if (labels != null && !labels.isEmpty()) { if (labels != null && !labels.isEmpty()) {
result = labels.get(0); result = labels.get(0);

View File

@ -50,17 +50,11 @@ public interface MindmapManager {
void removeCollaboration(Collaboration collaboration); void removeCollaboration(Collaboration collaboration);
List<Mindmap> search(MindMapCriteria criteria);
List<Mindmap> search(MindMapCriteria criteria, int maxResult);
List<MindMapHistory> getHistoryFrom(int mindmapId); List<MindMapHistory> getHistoryFrom(int mindmapId);
MindMapHistory getHistory(int historyId); MindMapHistory getHistory(int historyId);
void updateCollaboration(@NotNull Collaboration collaboration); void updateCollaboration(@NotNull Collaboration collaboration);
void purgeHistory(int mapId) throws IOException;
List<Mindmap> findMindmapByUser(User user); List<Mindmap> findMindmapByUser(User user);
} }

View File

@ -19,25 +19,31 @@
package com.wisemapping.dao; package com.wisemapping.dao;
import com.wisemapping.model.*; import com.wisemapping.model.*;
import com.wisemapping.util.ZipUtils; import jakarta.annotation.Resource;
import jakarta.persistence.Query; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.SelectionQuery;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.stereotype.Repository;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@Repository
public class MindmapManagerImpl public class MindmapManagerImpl
extends HibernateDaoSupport
implements MindmapManager { implements MindmapManager {
@Resource
private SessionFactory sessionFactory;
@Override @Override
public Collaborator findCollaborator(@NotNull final String email) { public Collaborator findCollaborator(@NotNull final String email) {
final Collaborator collaborator; final Collaborator collaborator;
Query query = currentSession().createQuery("from com.wisemapping.model.Collaborator collaborator where email=:email"); final SelectionQuery<Collaborator> query = getSession().createSelectionQuery("from com.wisemapping.model.Collaborator collaborator where email=:email", Collaborator.class);
query.setParameter("email", email); query.setParameter("email", email);
final List<Collaborator> collaborators = query.getResultList(); final List<Collaborator> collaborators = query.getResultList();
@ -50,139 +56,87 @@ public class MindmapManagerImpl
return collaborator; return collaborator;
} }
@Override private Session getSession() {
public List<Mindmap> search(MindMapCriteria criteria) { return sessionFactory.getCurrentSession();
return search(criteria, -1);
} }
@Override @Override
public List<MindMapHistory> getHistoryFrom(int mindmapId) { public List<MindMapHistory> getHistoryFrom(int mindmapId) {
// final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class); final Session session = getSession();
// hibernateCriteria.add(Restrictions.eq("mindmapId", mindmapId)); final CriteriaBuilder cb = session.getCriteriaBuilder();
// hibernateCriteria.addOrder(Order.desc("creationTime"));
// final CriteriaQuery<MindMapHistory> cr = cb.createQuery(MindMapHistory.class);
// // This line throws errors in some environments, so getting all history and taking firsts 10 records final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
// hibernateCriteria.setMaxResults(30);
// return hibernateCriteria.list(); final CriteriaQuery<MindMapHistory> select = cr.select(root)
return null; .where(cb.equal(root.get("mindmapId"), mindmapId))
.orderBy(cb.desc(root.get("creationTime")));
return session.
createQuery(select)
.setMaxResults(30)
.getResultList();
} }
@Override @Override
public MindMapHistory getHistory(int historyId) { public MindMapHistory getHistory(int historyId) {
return getHibernateTemplate().get(MindMapHistory.class, historyId); final Session session = getSession();
return session.find(MindMapHistory.class, historyId);
} }
@Override @Override
public void updateCollaboration(@NotNull Collaboration collaboration) { public void updateCollaboration(@NotNull Collaboration collaboration) {
getHibernateTemplate().save(collaboration); final Session session = getSession();
} session.persist(collaboration);
@Override
public void purgeHistory(int mapId) throws IOException {
// final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class);
// hibernateCriteria.add(Restrictions.eq("mindmapId", mapId));
// hibernateCriteria.addOrder(Order.desc("creationTime"));
final List<MindMapHistory> historyList = null;
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 = mindmap.getLastModificationTime().before(yearAgo) ? 10 : 25;
final HibernateTemplate hibernateTemplate = getHibernateTemplate();
for (MindMapHistory history : historyList) {
byte[] zippedXml = history.getZippedXml();
if (new String(zippedXml).startsWith("<map")) {
history.setZippedXml(ZipUtils.bytesToZip(zippedXml));
hibernateTemplate.update(history);
}
}
if (historyList.size() > max) {
for (int i = max; i < historyList.size(); i++) {
hibernateTemplate.delete(historyList.get(i));
}
}
}
} }
@Override @Override
public List<Mindmap> findMindmapByUser(@NotNull User user) { public List<Mindmap> findMindmapByUser(@NotNull User user) {
final Mindmap collaborator; final SelectionQuery<Mindmap> query = getSession()
final Query query = currentSession() .createSelectionQuery("from com.wisemapping.model.Mindmap m where m.id in (select c.mindMap.id from com.wisemapping.model.Collaboration as c where c.collaborator.id=:collabId )", Mindmap.class);
.createQuery("from com.wisemapping.model.Mindmap m where m.id in (select c.mindMap.id from com.wisemapping.model.Collaboration as c where c.collaborator.id=:collabId )");
query.setParameter("collabId", user.getId()); query.setParameter("collabId", user.getId());
return query.getResultList(); return query.getResultList();
} }
@Override
public List<Mindmap> search(MindMapCriteria criteria, int maxResult) {
// final Criteria hibernateCriteria = currentSession().createCriteria(Mindmap.class);
// //always search public maps
// hibernateCriteria.add(Restrictions.like("public", Boolean.TRUE));
//
// if (criteria != null) {
// final Junction junction;
// if (criteria.isOrCriteria()) {
// junction = Restrictions.disjunction();
// } else {
// junction = Restrictions.conjunction();
// }
//
// if (criteria.getTitle() != null && criteria.getTitle().length() > 0) {
// final SimpleExpression titleRestriction = Restrictions.like("title", "%" + criteria.getTitle() + "%");
// junction.add(titleRestriction);
// }
//
// if (criteria.getDescription() != null && criteria.getDescription().length() > 0) {
// final SimpleExpression descriptionRestriction = Restrictions.like("description", "%" + criteria.getDescription() + "%");
// junction.add(descriptionRestriction);
// }
// hibernateCriteria.add(junction);
// }
// return hibernateCriteria.list();
return null;
}
@Override @Override
public List<Collaboration> findCollaboration(final int collaboratorId) { public List<Collaboration> findCollaboration(final int collaboratorId) {
Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=:collaboratorId"); final SelectionQuery<Collaboration> query = getSession().createSelectionQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=:collaboratorId", Collaboration.class);
query.setParameter("collaboratorId", collaboratorId); query.setParameter("collaboratorId", collaboratorId);
return query.getResultList(); return query.getResultList();
} }
@Override @Override
public void addCollaborator(@NotNull Collaborator collaborator) { public void addCollaborator(@NotNull Collaborator collaborator) {
final Session session = getSession();
assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!"; assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!";
getHibernateTemplate().save(collaborator); session.persist(collaborator);
} }
@Override @Override
public void removeCollaboration(Collaboration collaboration) { public void removeCollaboration(Collaboration collaboration) {
getHibernateTemplate().delete(collaboration); final Session session = getSession();
session.remove(collaboration);
} }
@Override @Override
public void removeCollaborator(@NotNull Collaborator collaborator) { public void removeCollaborator(@NotNull Collaborator collaborator) {
getHibernateTemplate().delete(collaborator); final Session session = getSession();
session.remove(collaborator);
} }
@Override @Override
@Nullable @Nullable
public Mindmap getMindmapById(int id) { public Mindmap getMindmapById(int id) {
return getHibernateTemplate().get(Mindmap.class, id); final Session session = getSession();
return session.get(Mindmap.class, id);
} }
@Override @Override
public Mindmap getMindmapByTitle(final String title, final User user) { public Mindmap getMindmapByTitle(final String title, final User user) {
final Mindmap result; final Mindmap result;
Query query = currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator"); final SelectionQuery<Mindmap> query = getSession().createSelectionQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator", Mindmap.class);
query.setParameter("title", title); query.setParameter("title", title);
query.setParameter("creator", user); query.setParameter("creator", user);
@ -204,13 +158,13 @@ public class MindmapManagerImpl
@Override @Override
public void saveMindmap(Mindmap mindMap) { public void saveMindmap(Mindmap mindMap) {
assert mindMap != null : "Save Mindmap: Mindmap is required!"; assert mindMap != null : "Save Mindmap: Mindmap is required!";
currentSession().save(mindMap); getSession().persist(mindMap);
} }
@Override @Override
public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) { public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) {
assert mindMap != null : "Save Mindmap: Mindmap is required!"; assert mindMap != null : "Save Mindmap: Mindmap is required!";
getHibernateTemplate().saveOrUpdate(mindMap); getSession().merge(mindMap);
if (saveHistory) { if (saveHistory) {
saveHistory(mindMap); saveHistory(mindMap);
} }
@ -218,17 +172,21 @@ public class MindmapManagerImpl
@Override @Override
public void removeMindmap(@NotNull final Mindmap mindmap) { public void removeMindmap(@NotNull final Mindmap mindmap) {
// // Delete history first ... // Delete history first ...
// final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class); final Session session = getSession();
// hibernateCriteria.add(Restrictions.eq("mindmapId", mindmap.getId())); final CriteriaBuilder cb = session.getCriteriaBuilder();
// final List list = hibernateCriteria.list();
// getHibernateTemplate().deleteAll(list); final CriteriaDelete<MindMapHistory> cr = cb.createCriteriaDelete(MindMapHistory.class);
// final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
// // Remove collaborations ...
// mindmap.removedCollaboration(mindmap.getCollaborations()); final CriteriaDelete<MindMapHistory> deleteStatement = cr.where(cb.equal(root.get("mindmapId"), mindmap.getId()));
// session.createMutationQuery(deleteStatement).executeUpdate();
// // Delete mindmap ....
// getHibernateTemplate().delete(mindmap); // Remove collaborations ...
mindmap.removedCollaboration(mindmap.getCollaborations());
// Delete mindmap ....
getSession().remove(mindmap);
} }
private void saveHistory(@NotNull final Mindmap mindMap) { private void saveHistory(@NotNull final Mindmap mindMap) {
@ -238,6 +196,6 @@ public class MindmapManagerImpl
history.setCreationTime(Calendar.getInstance()); history.setCreationTime(Calendar.getInstance());
history.setEditor(mindMap.getLastEditor()); history.setEditor(mindMap.getLastEditor());
history.setMindmapId(mindMap.getId()); history.setMindmapId(mindMap.getId());
getHibernateTemplate().saveOrUpdate(history); getSession().merge(history);
} }
} }

View File

@ -18,27 +18,28 @@
package com.wisemapping.dao; package com.wisemapping.dao;
import com.wisemapping.model.AccessAuditory; import com.wisemapping.model.*;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.User;
import com.wisemapping.security.DefaultPasswordEncoderFactories; import com.wisemapping.security.DefaultPasswordEncoderFactories;
import com.wisemapping.security.LegacyPasswordEncoder; import com.wisemapping.security.LegacyPasswordEncoder;
import jakarta.annotation.Resource;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.SelectionQuery;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@Repository
public class UserManagerImpl public class UserManagerImpl
extends HibernateDaoSupport
implements UserManager { implements UserManager {
@Resource
private SessionFactory sessionFactory;
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@ -46,9 +47,12 @@ public class UserManagerImpl
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
} }
@SuppressWarnings("unchecked")
public List<User> getAllUsers() { public List<User> getAllUsers() {
return currentSession().createQuery("from com.wisemapping.model.User user").list(); return getSession().createSelectionQuery("from com.wisemapping.model.User user", User.class).getResultList();
}
private Session getSession() {
return sessionFactory.getCurrentSession();
} }
@ -57,10 +61,10 @@ public class UserManagerImpl
public User getUserBy(@NotNull final String email) { public User getUserBy(@NotNull final String email) {
User user = null; User user = null;
var query = currentSession().createQuery("from com.wisemapping.model.User colaborator where email=:email"); SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User colaborator where email=:email",User.class);
query.setParameter("email", email); query.setParameter("email", email);
final List<User> users = query.list(); final List<User> users = query.getResultList();
if (users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same email!"; assert users.size() == 1 : "More than one user with the same email!";
user = users.get(0); user = users.get(0);
@ -71,19 +75,20 @@ public class UserManagerImpl
@Override @Override
public Collaborator getCollaboratorBy(final String email) { public Collaborator getCollaboratorBy(final String email) {
final Collaborator cola; final Collaborator result;
var query = currentSession().createQuery("from com.wisemapping.model.Collaborator colaborator where " + Session session = getSession();
"email=:email"); final SelectionQuery<Collaborator> query = session.createSelectionQuery("from com.wisemapping.model.Collaborator colaborator where " +
"email=:email", Collaborator.class);
query.setParameter("email", email); query.setParameter("email", email);
final List<User> cols = query.list(); final List<Collaborator> cols = query.getResultList();
if (cols != null && !cols.isEmpty()) { if (cols != null && !cols.isEmpty()) {
assert cols.size() == 1 : "More than one colaborator with the same email!"; assert cols.size() == 1 : "More than one colaborator with the same email!";
cola = cols.get(0); result = cols.get(0);
} else { } else {
cola = null; result = null;
} }
return cola; return result;
} }
@Nullable @Nullable
@ -91,7 +96,7 @@ public class UserManagerImpl
public User getUserBy(int id) { public User getUserBy(int id) {
User user = null; User user = null;
try { try {
user = getHibernateTemplate().get(User.class, id); user = getSession().get(User.class, id);
} catch (ObjectNotFoundException e) { } catch (ObjectNotFoundException e) {
// Ignore ... // Ignore ...
} }
@ -106,7 +111,7 @@ public class UserManagerImpl
} else { } else {
user.setPassword(""); user.setPassword("");
} }
getHibernateTemplate().saveOrUpdate(user); getSession().persist(user);
} }
@Override @Override
@ -114,10 +119,10 @@ public class UserManagerImpl
assert user != null : "Trying to store a null user"; assert user != null : "Trying to store a null user";
// Migrate from previous temporal collab to new user ... // Migrate from previous temporal collab to new user ...
final HibernateTemplate template = getHibernateTemplate(); final Session session = getSession();
collaborator.setEmail(collaborator.getEmail() + "_toRemove"); collaborator.setEmail(collaborator.getEmail() + "_toRemove");
template.saveOrUpdate(collaborator); session.merge(collaborator);
template.flush(); session.flush();
// Save all new... // Save all new...
this.createUser(user); this.createUser(user);
@ -129,18 +134,18 @@ public class UserManagerImpl
} }
// Delete old user ... // Delete old user ...
template.delete(collaborator); session.remove(collaborator);
return user; return user;
} }
@Override @Override
public void removeUser(@NotNull final User user) { public void removeUser(@NotNull final User user) {
getHibernateTemplate().delete(user); getSession().remove(user);
} }
public void auditLogin(@NotNull AccessAuditory accessAuditory) { public void auditLogin(@NotNull AccessAuditory accessAuditory) {
assert accessAuditory != null : "accessAuditory is null"; assert accessAuditory != null : "accessAuditory is null";
getHibernateTemplate().save(accessAuditory); getSession().persist(accessAuditory);
} }
public void updateUser(@NotNull User user) { public void updateUser(@NotNull User user) {
@ -152,21 +157,21 @@ public class UserManagerImpl
user.setPassword(passwordEncoder.encode(user.getPassword())); user.setPassword(passwordEncoder.encode(user.getPassword()));
} }
getHibernateTemplate().update(user); getSession().merge(user);
} }
public User getUserByActivationCode(long code) { public User getUserByActivationCode(long code) {
final User user; final User user;
var query = currentSession().createQuery("from com.wisemapping.model.User user where " + final SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User user where " +
"activationCode=:activationCode"); "activationCode=:activationCode", User.class);
query.setParameter("activationCode", code); query.setParameter("activationCode", code);
final List users = query.list();
final List<User> users = query.getResultList();
if (users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same username!"; assert users.size() == 1 : "More than one user with the same username!";
user = (User) users.get(0); user = users.get(0);
} else { } else {
user = null; user = null;
} }

View File

@ -49,8 +49,6 @@ public interface MindmapService {
void removeMindmap(@NotNull final Mindmap mindmap, @NotNull final User user) throws WiseMappingException; void removeMindmap(@NotNull final Mindmap mindmap, @NotNull final User user) throws WiseMappingException;
List<Mindmap> search(MindMapCriteria criteria);
List<MindMapHistory> findMindmapHistory(int mindmapId); List<MindMapHistory> findMindmapHistory(int mindmapId);
boolean hasPermissions(@Nullable User user, Mindmap map, CollaborationRole allowedRole); boolean hasPermissions(@Nullable User user, Mindmap map, CollaborationRole allowedRole);

View File

@ -134,11 +134,6 @@ public class MindmapServiceImpl
mindmapManager.updateMindmap(mindMap, saveHistory); mindmapManager.updateMindmap(mindMap, saveHistory);
} }
@Override
public List<Mindmap> search(MindMapCriteria criteria) {
return mindmapManager.search(criteria);
}
@Override @Override
public void removeCollaboration(@NotNull Mindmap mindmap, @NotNull Collaboration collaboration) throws CollaborationException { public void removeCollaboration(@NotNull Mindmap mindmap, @NotNull Collaboration collaboration) throws CollaborationException {
// remove collaborator association // remove collaborator association

View File

@ -64,4 +64,7 @@ OWNER_ROLE_CAN_NOT_BE_CHANGED=Роль владельца изменить не
ZOOM_TO_FIT=Увеличить, чтобы соответствовать ZOOM_TO_FIT=Увеличить, чтобы соответствовать
ZOOM_OUT=Уменьшить ZOOM_OUT=Уменьшить
ZOOM_IN=Приблизить ZOOM_IN=Приблизить
PASSWORD_TOO_LONG=Password must be less than 40 characters. PASSWORD_TOO_LONG=Password must be less than 40 characters.
CHANGE_PASSWORD.EMAIL_SUBJECT=Your password has been reset
CHANGE_PASSWORD.EMAIL_TITLE=A temporal password has been generated
CHANGE_PASSWORD.EMAIL_BODY=<p>Someone, most likely you, requested a new password for your WiseMapping account. </p><p><strong>Here is your new password: {0} </strong></p><p>You can login clicking <a href="{1}/c/login">here</a>. We strongly encourage you to change the password as soon as possible.</p>

View File

@ -36,10 +36,6 @@
</bean> </bean>
<!-- Hibernate Template Definition --> <!-- Hibernate Template Definition -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="mindmapSessionFactory"/>
</bean>
<bean id="txAttributes" <bean id="txAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties"> <property name="properties">

View File

@ -6,17 +6,12 @@
http://www.springframework.org/schema/beans/spring-beans.xsd"> http://www.springframework.org/schema/beans/spring-beans.xsd">
<beans> <beans>
<bean id="userManager" class="com.wisemapping.dao.UserManagerImpl"> <bean id="userManager" class="com.wisemapping.dao.UserManagerImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"/>
<property name="encoder" ref="passwordEncoder"/> <property name="encoder" ref="passwordEncoder"/>
</bean> </bean>
<bean id="mindmapManager" class="com.wisemapping.dao.MindmapManagerImpl"> <bean id="mindmapManager" class="com.wisemapping.dao.MindmapManagerImpl"/>
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="labelManager" class="com.wisemapping.dao.LabelManagerImpl"> <bean id="labelManager" class="com.wisemapping.dao.LabelManagerImpl"/>
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
</beans> </beans>
</beans> </beans>