Fixed.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.Label;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.MindmapLabel;
|
||||
import com.wisemapping.model.Account;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -9,18 +9,18 @@ import java.util.List;
|
||||
|
||||
public interface LabelManager {
|
||||
|
||||
void addLabel(@NotNull final Label label);
|
||||
void addLabel(@NotNull final MindmapLabel label);
|
||||
|
||||
void saveLabel(@NotNull final Label label);
|
||||
void saveLabel(@NotNull final MindmapLabel label);
|
||||
|
||||
@NotNull
|
||||
List<Label> getAllLabels(@NotNull final User user);
|
||||
List<MindmapLabel> getAllLabels(@NotNull final Account user);
|
||||
|
||||
@Nullable
|
||||
Label getLabelById(int id, @NotNull final User user);
|
||||
MindmapLabel getLabelById(int id, @NotNull final Account user);
|
||||
|
||||
@Nullable
|
||||
Label getLabelByTitle(@NotNull final String title, @NotNull final User user);
|
||||
MindmapLabel getLabelByTitle(@NotNull final String title, @NotNull final Account user);
|
||||
|
||||
void removeLabel(@NotNull final Label label);
|
||||
void removeLabel(@NotNull final MindmapLabel label);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.Label;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.MindmapLabel;
|
||||
import com.wisemapping.model.Account;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,51 +35,51 @@ public class LabelManagerImpl
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public void addLabel(@NotNull final Label label) {
|
||||
public void addLabel(@NotNull final MindmapLabel label) {
|
||||
saveLabel(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLabel(@NotNull final Label label) {
|
||||
public void saveLabel(@NotNull final MindmapLabel label) {
|
||||
entityManager.persist(label);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Label> getAllLabels(@NotNull final User user) {
|
||||
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where creator=:creatorId", Label.class);
|
||||
public List<MindmapLabel> getAllLabels(@NotNull final Account user) {
|
||||
final TypedQuery<MindmapLabel> query = entityManager.createQuery("from com.wisemapping.model.MindmapLabel wisemapping where creator=:creatorId", MindmapLabel.class);
|
||||
query.setParameter("creatorId", user);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelById(int id, @NotNull final User user) {
|
||||
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator", Label.class);
|
||||
public MindmapLabel getLabelById(int id, @NotNull final Account user) {
|
||||
final TypedQuery<MindmapLabel> query = entityManager.createQuery("from com.wisemapping.model.MindmapLabel wisemapping where id=:id and creator=:creator", MindmapLabel.class);
|
||||
query.setParameter("id", id);
|
||||
query.setParameter("creator", user);
|
||||
|
||||
final List<Label> resultList = query.getResultList();
|
||||
final List<MindmapLabel> resultList = query.getResultList();
|
||||
return getFirst(resultList);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
|
||||
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator", Label.class);
|
||||
public MindmapLabel getLabelByTitle(@NotNull String title, @NotNull final Account user) {
|
||||
final TypedQuery<MindmapLabel> query = entityManager.createQuery("from com.wisemapping.model.MindmapLabel wisemapping where title=:title and creator=:creator", MindmapLabel.class);
|
||||
query.setParameter("title", title);
|
||||
query.setParameter("creator", user);
|
||||
return query.getResultList().stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLabel(@NotNull Label label) {
|
||||
public void removeLabel(@NotNull MindmapLabel label) {
|
||||
entityManager.remove(label);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Label getFirst(final List<Label> labels) {
|
||||
Label result = null;
|
||||
private MindmapLabel getFirst(final List<MindmapLabel> labels) {
|
||||
MindmapLabel result = null;
|
||||
if (labels != null && !labels.isEmpty()) {
|
||||
result = labels.get(0);
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ public interface MindmapManager {
|
||||
@Nullable
|
||||
Mindmap getMindmapById(int mindmapId);
|
||||
|
||||
Mindmap getMindmapByTitle(final String name, final User user);
|
||||
Mindmap getMindmapByTitle(final String name, final Account user);
|
||||
|
||||
void addCollaborator(Collaborator collaborator);
|
||||
|
||||
void addMindmap(User user, Mindmap mindmap);
|
||||
void addMindmap(Account user, Mindmap mindmap);
|
||||
|
||||
void saveMindmap(Mindmap mindmap);
|
||||
|
||||
@@ -55,5 +55,5 @@ public interface MindmapManager {
|
||||
|
||||
void updateCollaboration(@NotNull Collaboration collaboration);
|
||||
|
||||
List<Mindmap> findMindmapByUser(User user);
|
||||
List<Mindmap> findMindmapByUser(Account user);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class MindmapManagerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mindmap> findMindmapByUser(@NotNull User user) {
|
||||
public List<Mindmap> findMindmapByUser(@NotNull Account user) {
|
||||
|
||||
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);
|
||||
@@ -123,7 +123,7 @@ public class MindmapManagerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mindmap getMindmapByTitle(final String title, final User user) {
|
||||
public Mindmap getMindmapByTitle(final String title, final Account user) {
|
||||
|
||||
final TypedQuery<Mindmap> query = entityManager.createQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator", Mindmap.class);
|
||||
query.setParameter("title", title);
|
||||
@@ -139,7 +139,7 @@ public class MindmapManagerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMindmap(User user, Mindmap mindMap) {
|
||||
public void addMindmap(Account user, Mindmap mindMap) {
|
||||
saveMindmap(mindMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,31 +20,31 @@ package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.AccessAuditory;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.Account;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserManager {
|
||||
|
||||
List<User> getAllUsers();
|
||||
List<Account> getAllUsers();
|
||||
|
||||
User getUserBy(String email);
|
||||
Account getUserBy(String email);
|
||||
|
||||
User getUserBy(int id);
|
||||
Account getUserBy(int id);
|
||||
|
||||
void createUser(User user);
|
||||
void createUser(Account user);
|
||||
|
||||
void auditLogin(@NotNull AccessAuditory accessAuditory);
|
||||
|
||||
void updateUser(User user);
|
||||
void updateUser(Account user);
|
||||
|
||||
User getUserByActivationCode(long code);
|
||||
Account getUserByActivationCode(long code);
|
||||
|
||||
Collaborator getCollaboratorBy(String email);
|
||||
|
||||
User createUser(User user, Collaborator col);
|
||||
Account createUser(Account user, Collaborator col);
|
||||
|
||||
void removeUser(@NotNull User user);
|
||||
void removeUser(@NotNull Account user);
|
||||
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ public class UserManagerImpl
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public List<User> getAllUsers() {
|
||||
return entityManager.createQuery("from com.wisemapping.model.User user", User.class).getResultList();
|
||||
public List<Account> getAllUsers() {
|
||||
return entityManager.createQuery("from com.wisemapping.model.Account user", Account.class).getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public User getUserBy(@NotNull final String email) {
|
||||
User user = null;
|
||||
public Account getUserBy(@NotNull final String email) {
|
||||
Account user = null;
|
||||
|
||||
TypedQuery<User> query = entityManager.createQuery("from com.wisemapping.model.User colaborator where email=:email", User.class);
|
||||
TypedQuery<Account> query = entityManager.createQuery("from com.wisemapping.model.Account colaborator where email=:email", Account.class);
|
||||
query.setParameter("email", email);
|
||||
|
||||
final List<User> users = query.getResultList();
|
||||
final List<Account> users = query.getResultList();
|
||||
if (users != null && !users.isEmpty()) {
|
||||
assert users.size() == 1 : "More than one user with the same email!";
|
||||
user = users.get(0);
|
||||
@@ -89,12 +89,12 @@ public class UserManagerImpl
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public User getUserBy(int id) {
|
||||
return entityManager.find(User.class, id);
|
||||
public Account getUserBy(int id) {
|
||||
return entityManager.find(Account.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUser(User user) {
|
||||
public void createUser(Account user) {
|
||||
assert user != null : "Trying to store a null user";
|
||||
if (!AuthenticationType.GOOGLE_OAUTH2.equals(user.getAuthenticationType())) {
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||
@@ -105,7 +105,7 @@ public class UserManagerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public User createUser(@NotNull User user, @NotNull Collaborator collaborator) {
|
||||
public Account createUser(@NotNull Account user, @NotNull Collaborator collaborator) {
|
||||
assert user != null : "Trying to store a null user";
|
||||
|
||||
// Migrate from previous temporal collab to new user ...
|
||||
@@ -128,7 +128,7 @@ public class UserManagerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(@NotNull final User user) {
|
||||
public void removeUser(@NotNull final Account user) {
|
||||
entityManager.remove(user);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class UserManagerImpl
|
||||
entityManager.persist(accessAuditory);
|
||||
}
|
||||
|
||||
public void updateUser(@NotNull User user) {
|
||||
public void updateUser(@NotNull Account user) {
|
||||
assert user != null : "user is null";
|
||||
|
||||
// Does the password need to be encrypted ?
|
||||
@@ -149,14 +149,14 @@ public class UserManagerImpl
|
||||
entityManager.merge(user);
|
||||
}
|
||||
|
||||
public User getUserByActivationCode(long code) {
|
||||
final User user;
|
||||
public Account getUserByActivationCode(long code) {
|
||||
final Account user;
|
||||
|
||||
final TypedQuery<User> query = entityManager.createQuery("from com.wisemapping.model.User user where " +
|
||||
"activationCode=:activationCode", User.class);
|
||||
final TypedQuery<Account> query = entityManager.createQuery("from com.wisemapping.model.User user where " +
|
||||
"activationCode=:activationCode", Account.class);
|
||||
query.setParameter("activationCode", code);
|
||||
|
||||
final List<User> users = query.getResultList();
|
||||
final List<Account> users = query.getResultList();
|
||||
if (users != null && !users.isEmpty()) {
|
||||
|
||||
assert users.size() == 1 : "More than one user with the same username!";
|
||||
|
||||
Reference in New Issue
Block a user