mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-22 03:33:47 +01:00
Compare commits
2 Commits
e1b517f657
...
2f32ef66e9
Author | SHA1 | Date | |
---|---|---|---|
|
2f32ef66e9 | ||
|
fbbc95fd59 |
@ -20,10 +20,13 @@ public class Application {
|
||||
public static void main(String[] args) {
|
||||
|
||||
new SpringApplicationBuilder()
|
||||
.parent(Application.class, MethodSecurityConfig.class).web(WebApplicationType.NONE)
|
||||
.child(MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET)
|
||||
// .sibling(RestAppConfig.class).web(WebApplicationType.SERVLET)
|
||||
.parent(Application.class, MethodSecurityConfig.class, HibernateConfig.class).web(WebApplicationType.NONE)
|
||||
.child(MvcAppConfig.class, MvcSecurityConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET)
|
||||
.sibling(RestAppConfig.class).web(WebApplicationType.SERVLET)
|
||||
.run(args);
|
||||
|
||||
// new SpringApplicationBuilder(Application.class, MethodSecurityConfig.class,MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET).run(args);
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -1,12 +1,16 @@
|
||||
package com.wisemapping.config;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaRepositories("com.wisemapping.model")
|
||||
@EnableAutoConfiguration
|
||||
@EnableJpaRepositories(basePackages={"com.wisemapping.dao"})
|
||||
@EntityScan(basePackageClasses= User.class)
|
||||
public class HibernateConfig {
|
||||
|
||||
// @Bean
|
||||
|
@ -19,10 +19,8 @@ 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 jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -34,7 +32,7 @@ import java.util.List;
|
||||
public class LabelManagerImpl
|
||||
implements LabelManager {
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public void addLabel(@NotNull final Label label) {
|
||||
@ -43,26 +41,21 @@ public class LabelManagerImpl
|
||||
|
||||
@Override
|
||||
public void saveLabel(@NotNull final Label label) {
|
||||
getSession().persist(label);
|
||||
}
|
||||
|
||||
private Session getSession() {
|
||||
return sessionFactory.getCurrentSession();
|
||||
entityManager.persist(label);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Label> getAllLabels(@NotNull final User user) {
|
||||
final SelectionQuery<Label> query = getSession().createSelectionQuery("from com.wisemapping.model.Label wisemapping where creator=:creatorId", Label.class);
|
||||
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where creator=:creatorId", Label.class);
|
||||
query.setParameter("creatorId", user);
|
||||
return query.list();
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelById(int id, @NotNull final User user) {
|
||||
final Session session = getSession();
|
||||
final SelectionQuery<Label> query = session.createSelectionQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator", Label.class);
|
||||
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator", Label.class);
|
||||
query.setParameter("id", id);
|
||||
query.setParameter("creator", user);
|
||||
|
||||
@ -73,15 +66,15 @@ public class LabelManagerImpl
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
|
||||
final SelectionQuery<Label> query = getSession().createSelectionQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator", Label.class);
|
||||
final TypedQuery<Label> query = entityManager.createQuery("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());
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLabel(@NotNull Label label) {
|
||||
getSession().remove(label);
|
||||
entityManager.remove(label);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -19,15 +19,12 @@
|
||||
package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
@ -41,15 +38,12 @@ public class MindmapManagerImpl
|
||||
implements MindmapManager {
|
||||
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public Collaborator findCollaborator(@NotNull final String email) {
|
||||
final Collaborator collaborator;
|
||||
final SelectionQuery<Collaborator> query = getSession().createSelectionQuery("from com.wisemapping.model.Collaborator collaborator where email=:email", Collaborator.class);
|
||||
final TypedQuery<Collaborator> query = entityManager.createQuery("from com.wisemapping.model.Collaborator collaborator where email=:email", Collaborator.class);
|
||||
query.setParameter("email", email);
|
||||
|
||||
final List<Collaborator> collaborators = query.getResultList();
|
||||
@ -62,14 +56,9 @@ public class MindmapManagerImpl
|
||||
return collaborator;
|
||||
}
|
||||
|
||||
private Session getSession() {
|
||||
return sessionFactory.getCurrentSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MindMapHistory> getHistoryFrom(int mindmapId) {
|
||||
final Session session = getSession();
|
||||
final CriteriaBuilder cb = session.getCriteriaBuilder();
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
|
||||
final CriteriaQuery<MindMapHistory> cr = cb.createQuery(MindMapHistory.class);
|
||||
final Root<MindMapHistory> root = cr.from(MindMapHistory.class);
|
||||
@ -78,7 +67,7 @@ public class MindmapManagerImpl
|
||||
.where(cb.equal(root.get("mindmapId"), mindmapId))
|
||||
.orderBy(cb.desc(root.get("creationTime")));
|
||||
|
||||
return session.
|
||||
return entityManager.
|
||||
createQuery(select)
|
||||
.setMaxResults(30)
|
||||
.getResultList();
|
||||
@ -86,21 +75,19 @@ public class MindmapManagerImpl
|
||||
|
||||
@Override
|
||||
public MindMapHistory getHistory(int historyId) {
|
||||
final Session session = getSession();
|
||||
return session.find(MindMapHistory.class, historyId);
|
||||
return entityManager.find(MindMapHistory.class, historyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCollaboration(@NotNull Collaboration collaboration) {
|
||||
final Session session = getSession();
|
||||
session.persist(collaboration);
|
||||
entityManager.persist(collaboration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mindmap> findMindmapByUser(@NotNull User user) {
|
||||
|
||||
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);
|
||||
final TypedQuery<Mindmap> query = entityManager
|
||||
.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 )", Mindmap.class);
|
||||
query.setParameter("collabId", user.getId());
|
||||
|
||||
return query.getResultList();
|
||||
@ -108,41 +95,37 @@ public class MindmapManagerImpl
|
||||
|
||||
@Override
|
||||
public List<Collaboration> findCollaboration(final int collaboratorId) {
|
||||
final SelectionQuery<Collaboration> query = getSession().createSelectionQuery("from com.wisemapping.model.Collaboration c where c.collaborator.id=:collaboratorId", Collaboration.class);
|
||||
final TypedQuery<Collaboration> query = entityManager.createQuery("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!";
|
||||
session.persist(collaborator);
|
||||
entityManager.persist(collaborator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCollaboration(Collaboration collaboration) {
|
||||
final Session session = getSession();
|
||||
session.remove(collaboration);
|
||||
entityManager.remove(collaboration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCollaborator(@NotNull Collaborator collaborator) {
|
||||
final Session session = getSession();
|
||||
session.remove(collaborator);
|
||||
entityManager.remove(collaborator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Mindmap getMindmapById(int id) {
|
||||
final Session session = getSession();
|
||||
return session.get(Mindmap.class, id);
|
||||
return entityManager.find(Mindmap.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mindmap getMindmapByTitle(final String title, final User user) {
|
||||
final Mindmap result;
|
||||
final SelectionQuery<Mindmap> query = getSession().createSelectionQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator", Mindmap.class);
|
||||
final TypedQuery<Mindmap> query = entityManager.createQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator", Mindmap.class);
|
||||
query.setParameter("title", title);
|
||||
query.setParameter("creator", user);
|
||||
|
||||
@ -164,13 +147,13 @@ public class MindmapManagerImpl
|
||||
@Override
|
||||
public void saveMindmap(Mindmap mindMap) {
|
||||
assert mindMap != null : "Save Mindmap: Mindmap is required!";
|
||||
getSession().persist(mindMap);
|
||||
entityManager.persist(mindMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) {
|
||||
assert mindMap != null : "Save Mindmap: Mindmap is required!";
|
||||
getSession().merge(mindMap);
|
||||
entityManager.merge(mindMap);
|
||||
if (saveHistory) {
|
||||
saveHistory(mindMap);
|
||||
}
|
||||
@ -179,20 +162,19 @@ public class MindmapManagerImpl
|
||||
@Override
|
||||
public void removeMindmap(@NotNull final Mindmap mindmap) {
|
||||
// Delete history first ...
|
||||
final Session session = getSession();
|
||||
final CriteriaBuilder cb = session.getCriteriaBuilder();
|
||||
final CriteriaBuilder cb = entityManager.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();
|
||||
entityManager.createQuery(deleteStatement).executeUpdate();
|
||||
|
||||
// Remove collaborations ...
|
||||
mindmap.removedCollaboration(mindmap.getCollaborations());
|
||||
|
||||
// Delete mindmap ....
|
||||
getSession().remove(mindmap);
|
||||
entityManager.remove(mindmap);
|
||||
}
|
||||
|
||||
private void saveHistory(@NotNull final Mindmap mindMap) {
|
||||
@ -202,6 +184,6 @@ public class MindmapManagerImpl
|
||||
history.setCreationTime(Calendar.getInstance());
|
||||
history.setEditor(mindMap.getLastEditor());
|
||||
history.setMindmapId(mindMap.getId());
|
||||
getSession().merge(history);
|
||||
entityManager.merge(history);
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,8 @@ package com.wisemapping.dao;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.security.DefaultPasswordEncoderFactories;
|
||||
import com.wisemapping.security.LegacyPasswordEncoder;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.query.SelectionQuery;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -41,30 +37,27 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
public class UserManagerImpl
|
||||
implements UserManager {
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private EntityManager entityManager;
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public UserManagerImpl() {
|
||||
}
|
||||
|
||||
public void setEncoder(PasswordEncoder passwordEncoder) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public List<User> getAllUsers() {
|
||||
return getSession().createSelectionQuery("from com.wisemapping.model.User user", User.class).getResultList();
|
||||
return entityManager.createQuery("from com.wisemapping.model.User user", User.class).getResultList();
|
||||
}
|
||||
|
||||
private Session getSession() {
|
||||
return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public User getUserBy(@NotNull final String email) {
|
||||
User user = null;
|
||||
|
||||
SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User colaborator where email=:email",User.class);
|
||||
TypedQuery<User> query = entityManager.createQuery("from com.wisemapping.model.User colaborator where email=:email", User.class);
|
||||
query.setParameter("email", email);
|
||||
|
||||
final List<User> users = query.getResultList();
|
||||
@ -79,8 +72,8 @@ public class UserManagerImpl
|
||||
@Override
|
||||
public Collaborator getCollaboratorBy(final String email) {
|
||||
final Collaborator result;
|
||||
Session session = getSession();
|
||||
final SelectionQuery<Collaborator> query = session.createSelectionQuery("from com.wisemapping.model.Collaborator colaborator where " +
|
||||
|
||||
final TypedQuery<Collaborator> query = entityManager.createQuery("from com.wisemapping.model.Collaborator colaborator where " +
|
||||
"email=:email", Collaborator.class);
|
||||
query.setParameter("email", email);
|
||||
|
||||
@ -97,13 +90,7 @@ public class UserManagerImpl
|
||||
@Nullable
|
||||
@Override
|
||||
public User getUserBy(int id) {
|
||||
User user = null;
|
||||
try {
|
||||
user = getSession().get(User.class, id);
|
||||
} catch (ObjectNotFoundException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
return user;
|
||||
return entityManager.find(User.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,7 +101,7 @@ public class UserManagerImpl
|
||||
} else {
|
||||
user.setPassword("");
|
||||
}
|
||||
getSession().persist(user);
|
||||
entityManager.persist(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,10 +109,9 @@ public class UserManagerImpl
|
||||
assert user != null : "Trying to store a null user";
|
||||
|
||||
// Migrate from previous temporal collab to new user ...
|
||||
final Session session = getSession();
|
||||
collaborator.setEmail(collaborator.getEmail() + "_toRemove");
|
||||
session.merge(collaborator);
|
||||
session.flush();
|
||||
entityManager.merge(collaborator);
|
||||
entityManager.flush();
|
||||
|
||||
// Save all new...
|
||||
this.createUser(user);
|
||||
@ -137,18 +123,18 @@ public class UserManagerImpl
|
||||
}
|
||||
|
||||
// Delete old user ...
|
||||
session.remove(collaborator);
|
||||
entityManager.remove(collaborator);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(@NotNull final User user) {
|
||||
getSession().remove(user);
|
||||
entityManager.remove(user);
|
||||
}
|
||||
|
||||
public void auditLogin(@NotNull AccessAuditory accessAuditory) {
|
||||
assert accessAuditory != null : "accessAuditory is null";
|
||||
getSession().persist(accessAuditory);
|
||||
entityManager.persist(accessAuditory);
|
||||
}
|
||||
|
||||
public void updateUser(@NotNull User user) {
|
||||
@ -160,13 +146,13 @@ public class UserManagerImpl
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||
}
|
||||
|
||||
getSession().merge(user);
|
||||
entityManager.merge(user);
|
||||
}
|
||||
|
||||
public User getUserByActivationCode(long code) {
|
||||
final User user;
|
||||
|
||||
final SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User user where " +
|
||||
final TypedQuery<User> query = entityManager.createQuery("from com.wisemapping.model.User user where " +
|
||||
"activationCode=:activationCode", User.class);
|
||||
query.setParameter("activationCode", code);
|
||||
|
||||
|
@ -3,15 +3,19 @@ Springboot Common
|
||||
##################################################################################
|
||||
|
||||
spring.datasource.initialize=true
|
||||
spring.jpa.open-in-view=true
|
||||
#spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
|
||||
spring.sql.init.mode=always
|
||||
spring.main.allow-circular-references=true
|
||||
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.properties.hibernate.current_session_context_class=thread
|
||||
spring.jpa.properties.hibernate.format_sql=true
|
||||
spring.sql.init.mode=always
|
||||
|
||||
logging.level.root=TRACE
|
||||
##################################################################################
|
||||
Log Level
|
||||
##################################################################################
|
||||
|
||||
logging.level.root=INFO
|
||||
logging.level.org.apache.tomcat=INFO
|
||||
|
||||
##################################################################################
|
||||
# Mail configuration. Must be configured to enable user registration confirmation.
|
||||
|
Loading…
Reference in New Issue
Block a user