mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-15 11:07:57 +01:00
Remove hibernate template
This commit is contained in:
parent
946ef517d3
commit
be20a85c19
@ -13,10 +13,8 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
@ -86,8 +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>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
<version>4.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Hibernate Validator -->
|
<!-- Hibernate Validator -->
|
||||||
@ -130,12 +134,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-jpa</artifactId>
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
<version>2.6.1</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>5.3.15</version>
|
<version>6.0.6</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -189,16 +193,6 @@
|
|||||||
<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>
|
||||||
@ -362,27 +356,6 @@
|
|||||||
</profiles>
|
</profiles>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- <plugin>-->
|
|
||||||
<!-- <groupId>org.hibernate.orm.tooling</groupId>-->
|
|
||||||
<!-- <artifactId>hibernate-enhance-maven-plugin</artifactId>-->
|
|
||||||
<!-- <version>${hibernate.version}</version>-->
|
|
||||||
<!-- <executions>-->
|
|
||||||
<!-- <execution>-->
|
|
||||||
<!-- <phase>compile</phase>-->
|
|
||||||
<!-- <configuration>-->
|
|
||||||
<!-- <failOnError>true</failOnError>-->
|
|
||||||
<!-- <enableLazyInitialization>true</enableLazyInitialization>-->
|
|
||||||
<!-- <enableDirtyTracking>true</enableDirtyTracking>-->
|
|
||||||
<!-- <enableAssociationManagement>true</enableAssociationManagement>-->
|
|
||||||
<!-- <enableExtendedEnhancement>false</enableExtendedEnhancement>-->
|
|
||||||
<!-- <enableExtendedEnhancement>false</enableExtendedEnhancement>-->
|
|
||||||
<!-- </configuration>-->
|
|
||||||
<!-- <goals>-->
|
|
||||||
<!-- <goal>enhance</goal>-->
|
|
||||||
<!-- </goals>-->
|
|
||||||
<!-- </execution>-->
|
|
||||||
<!-- </executions>-->
|
|
||||||
<!-- </plugin>-->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
@ -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.Query;
|
||||||
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,22 +42,26 @@ 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().save(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Session getSession() {
|
||||||
|
return sessionFactory.getCurrentSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@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 Query query = getSession().createQuery("from com.wisemapping.model.Label wisemapping where creator=:creatorId");
|
||||||
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");
|
var query = getSession().createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator");
|
||||||
query.setParameter("id", id);
|
query.setParameter("id", id);
|
||||||
query.setParameter("creator", user);
|
query.setParameter("creator", user);
|
||||||
return getFirst(query.list());
|
return getFirst(query.list());
|
||||||
@ -59,7 +70,7 @@ public class LabelManagerImpl extends HibernateDaoSupport
|
|||||||
@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");
|
var query = getSession().createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator");
|
||||||
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 +78,11 @@ public class LabelManagerImpl extends HibernateDaoSupport
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeLabel(@NotNull Label label) {
|
public void removeLabel(@NotNull Label label) {
|
||||||
getHibernateTemplate().delete(label);
|
getSession().delete(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable private Label getFirst(List<Label> labels) {
|
@Nullable
|
||||||
|
private Label getFirst(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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -19,30 +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.Query;
|
||||||
import org.hibernate.Criteria;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import org.hibernate.criterion.Junction;
|
import jakarta.persistence.criteria.CriteriaDelete;
|
||||||
import org.hibernate.criterion.Order;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import jakarta.persistence.criteria.Root;
|
||||||
import org.hibernate.criterion.SimpleExpression;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
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");
|
Query query = getSession().createQuery("from com.wisemapping.model.Collaborator collaborator where email=:email");
|
||||||
query.setParameter("email", email);
|
query.setParameter("email", email);
|
||||||
|
|
||||||
final List<Collaborator> collaborators = query.getResultList();
|
final List<Collaborator> collaborators = query.getResultList();
|
||||||
@ -55,137 +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"));
|
|
||||||
|
|
||||||
// This line throws errors in some environments, so getting all history and taking firsts 10 records
|
final CriteriaQuery<MindMapHistory> cr = cb.createQuery(MindMapHistory.class);
|
||||||
hibernateCriteria.setMaxResults(30);
|
final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
|
||||||
return hibernateCriteria.list();
|
|
||||||
|
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
|
@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.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 = hibernateCriteria.list();
|
|
||||||
|
|
||||||
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 Query query = getSession()
|
||||||
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 )");
|
.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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");
|
Query query = getSession().createQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=:collaboratorId");
|
||||||
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.save(collaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCollaboration(Collaboration collaboration) {
|
public void removeCollaboration(Collaboration collaboration) {
|
||||||
getHibernateTemplate().delete(collaboration);
|
final Session session = getSession();
|
||||||
|
session.delete(collaboration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCollaborator(@NotNull Collaborator collaborator) {
|
public void removeCollaborator(@NotNull Collaborator collaborator) {
|
||||||
getHibernateTemplate().delete(collaborator);
|
final Session session = getSession();
|
||||||
|
session.delete(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");
|
Query query = getSession().createQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator");
|
||||||
query.setParameter("title", title);
|
query.setParameter("title", title);
|
||||||
query.setParameter("creator", user);
|
query.setParameter("creator", user);
|
||||||
|
|
||||||
@ -207,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().save(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().saveOrUpdate(mindMap);
|
||||||
if (saveHistory) {
|
if (saveHistory) {
|
||||||
saveHistory(mindMap);
|
saveHistory(mindMap);
|
||||||
}
|
}
|
||||||
@ -222,16 +173,20 @@ 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);
|
||||||
|
|
||||||
|
final CriteriaDelete<MindMapHistory> deleteStatement = cr.where(cb.equal(root.get("mindmapId"), mindmap.getId()));
|
||||||
|
session.createMutationQuery(deleteStatement).executeUpdate();
|
||||||
|
|
||||||
// Remove collaborations ...
|
// Remove collaborations ...
|
||||||
mindmap.removedCollaboration(mindmap.getCollaborations());
|
mindmap.removedCollaboration(mindmap.getCollaborations());
|
||||||
|
|
||||||
// Delete mindmap ....
|
// Delete mindmap ....
|
||||||
getHibernateTemplate().delete(mindmap);
|
getSession().delete(mindmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveHistory(@NotNull final Mindmap mindMap) {
|
private void saveHistory(@NotNull final Mindmap mindMap) {
|
||||||
@ -241,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().saveOrUpdate(history);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.Query;
|
||||||
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;
|
||||||
|
|
||||||
@ -48,7 +49,11 @@ public class UserManagerImpl
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<User> getAllUsers() {
|
public List<User> getAllUsers() {
|
||||||
return currentSession().createQuery("from com.wisemapping.model.User user").list();
|
return getSession().createQuery("from com.wisemapping.model.User user").list();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Session getSession() {
|
||||||
|
return sessionFactory.getCurrentSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +62,7 @@ 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");
|
var query = getSession().createQuery("from com.wisemapping.model.User colaborator where email=:email");
|
||||||
query.setParameter("email", email);
|
query.setParameter("email", email);
|
||||||
|
|
||||||
final List<User> users = query.list();
|
final List<User> users = query.list();
|
||||||
@ -72,7 +77,7 @@ public class UserManagerImpl
|
|||||||
@Override
|
@Override
|
||||||
public Collaborator getCollaboratorBy(final String email) {
|
public Collaborator getCollaboratorBy(final String email) {
|
||||||
final Collaborator cola;
|
final Collaborator cola;
|
||||||
var query = currentSession().createQuery("from com.wisemapping.model.Collaborator colaborator where " +
|
Query query = getSession().createQuery("from com.wisemapping.model.Collaborator colaborator where " +
|
||||||
"email=:email");
|
"email=:email");
|
||||||
query.setParameter("email", email);
|
query.setParameter("email", email);
|
||||||
|
|
||||||
@ -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().saveOrUpdate(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.saveOrUpdate(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.delete(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().delete(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().save(accessAuditory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateUser(@NotNull User user) {
|
public void updateUser(@NotNull User user) {
|
||||||
@ -152,13 +157,13 @@ public class UserManagerImpl
|
|||||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||||
}
|
}
|
||||||
|
|
||||||
getHibernateTemplate().update(user);
|
getSession().update(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 " +
|
var query = getSession().createQuery("from com.wisemapping.model.User user where " +
|
||||||
"activationCode=:activationCode");
|
"activationCode=:activationCode");
|
||||||
query.setParameter("activationCode", code);
|
query.setParameter("activationCode", code);
|
||||||
final List users = query.list();
|
final List users = query.list();
|
||||||
|
@ -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);
|
||||||
|
@ -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
|
||||||
|
@ -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">
|
||||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user