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

View File

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

View File

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

View File

@ -19,25 +19,31 @@
package com.wisemapping.dao;
import com.wisemapping.model.*;
import com.wisemapping.util.ZipUtils;
import jakarta.persistence.Query;
import jakarta.annotation.Resource;
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.Nullable;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
@Repository
public class MindmapManagerImpl
extends HibernateDaoSupport
implements MindmapManager {
@Resource
private SessionFactory sessionFactory;
@Override
public Collaborator findCollaborator(@NotNull final String email) {
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);
final List<Collaborator> collaborators = query.getResultList();
@ -50,139 +56,87 @@ public class MindmapManagerImpl
return collaborator;
}
@Override
public List<Mindmap> search(MindMapCriteria criteria) {
return search(criteria, -1);
private Session getSession() {
return sessionFactory.getCurrentSession();
}
@Override
public List<MindMapHistory> getHistoryFrom(int mindmapId) {
// final Criteria hibernateCriteria = currentSession().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 null;
final Session session = getSession();
final CriteriaBuilder cb = session.getCriteriaBuilder();
final CriteriaQuery<MindMapHistory> cr = cb.createQuery(MindMapHistory.class);
final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
final CriteriaQuery<MindMapHistory> select = cr.select(root)
.where(cb.equal(root.get("mindmapId"), mindmapId))
.orderBy(cb.desc(root.get("creationTime")));
return session.
createQuery(select)
.setMaxResults(30)
.getResultList();
}
@Override
public MindMapHistory getHistory(int historyId) {
return getHibernateTemplate().get(MindMapHistory.class, historyId);
final Session session = getSession();
return session.find(MindMapHistory.class, historyId);
}
@Override
public void updateCollaboration(@NotNull Collaboration collaboration) {
getHibernateTemplate().save(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));
}
}
}
final Session session = getSession();
session.persist(collaboration);
}
@Override
public List<Mindmap> findMindmapByUser(@NotNull User user) {
final Mindmap collaborator;
final Query query = currentSession()
.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 )");
final SelectionQuery<Mindmap> query = getSession()
.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);
query.setParameter("collabId", user.getId());
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
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);
return query.getResultList();
}
@Override
public void addCollaborator(@NotNull Collaborator collaborator) {
final Session session = getSession();
assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!";
getHibernateTemplate().save(collaborator);
session.persist(collaborator);
}
@Override
public void removeCollaboration(Collaboration collaboration) {
getHibernateTemplate().delete(collaboration);
final Session session = getSession();
session.remove(collaboration);
}
@Override
public void removeCollaborator(@NotNull Collaborator collaborator) {
getHibernateTemplate().delete(collaborator);
final Session session = getSession();
session.remove(collaborator);
}
@Override
@Nullable
public Mindmap getMindmapById(int id) {
return getHibernateTemplate().get(Mindmap.class, id);
final Session session = getSession();
return session.get(Mindmap.class, id);
}
@Override
public Mindmap getMindmapByTitle(final String title, final User user) {
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("creator", user);
@ -204,13 +158,13 @@ public class MindmapManagerImpl
@Override
public void saveMindmap(Mindmap mindMap) {
assert mindMap != null : "Save Mindmap: Mindmap is required!";
currentSession().save(mindMap);
getSession().persist(mindMap);
}
@Override
public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) {
assert mindMap != null : "Save Mindmap: Mindmap is required!";
getHibernateTemplate().saveOrUpdate(mindMap);
getSession().merge(mindMap);
if (saveHistory) {
saveHistory(mindMap);
}
@ -218,17 +172,21 @@ public class MindmapManagerImpl
@Override
public void removeMindmap(@NotNull final Mindmap mindmap) {
// // Delete history first ...
// final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class);
// hibernateCriteria.add(Restrictions.eq("mindmapId", mindmap.getId()));
// final List list = hibernateCriteria.list();
// getHibernateTemplate().deleteAll(list);
//
// // Remove collaborations ...
// mindmap.removedCollaboration(mindmap.getCollaborations());
//
// // Delete mindmap ....
// getHibernateTemplate().delete(mindmap);
// Delete history first ...
final Session session = getSession();
final CriteriaBuilder cb = session.getCriteriaBuilder();
final CriteriaDelete<MindMapHistory> cr = cb.createCriteriaDelete(MindMapHistory.class);
final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
final CriteriaDelete<MindMapHistory> deleteStatement = cr.where(cb.equal(root.get("mindmapId"), mindmap.getId()));
session.createMutationQuery(deleteStatement).executeUpdate();
// Remove collaborations ...
mindmap.removedCollaboration(mindmap.getCollaborations());
// Delete mindmap ....
getSession().remove(mindmap);
}
private void saveHistory(@NotNull final Mindmap mindMap) {
@ -238,6 +196,6 @@ public class MindmapManagerImpl
history.setCreationTime(Calendar.getInstance());
history.setEditor(mindMap.getLastEditor());
history.setMindmapId(mindMap.getId());
getHibernateTemplate().saveOrUpdate(history);
getSession().merge(history);
}
}

View File

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

View File

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

View File

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

View File

@ -64,4 +64,7 @@ OWNER_ROLE_CAN_NOT_BE_CHANGED=Роль владельца изменить не
ZOOM_TO_FIT=Увеличить, чтобы соответствовать
ZOOM_OUT=Уменьшить
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>
<!-- Hibernate Template Definition -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="mindmapSessionFactory"/>
</bean>
<bean id="txAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">

View File

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