aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/web/server')
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java
index c2d9f72..663f0e4 100644
--- a/src/org/traccar/web/server/model/DataServiceImpl.java
+++ b/src/org/traccar/web/server/model/DataServiceImpl.java
@@ -147,6 +147,41 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
}
@Override
+ public List<User> getUsers() {
+ List<User> users = new LinkedList<User>();
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ try {
+ users.addAll(entityManager.createQuery("SELECT x FROM User x", User.class).getResultList());
+ return users;
+ } finally {
+ entityManager.close();
+ }
+ }
+
+ @Override
+ public User addUser(User user) {
+ User currentUser = getUser();
+ if (currentUser.getAdmin()) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ try {
+ entityManager.getTransaction().begin();
+ try {
+ entityManager.persist(user);
+ entityManager.getTransaction().commit();
+ return user;
+ } catch (RuntimeException e) {
+ entityManager.getTransaction().rollback();
+ throw e;
+ }
+ } finally {
+ entityManager.close();
+ }
+ } else {
+ throw new SecurityException();
+ }
+ }
+
+ @Override
public User updateUser(User user) {
User currentUser = getUser();
if (currentUser.getAdmin() || (currentUser.getId() == user.getId() && !user.getAdmin())) {
@@ -181,6 +216,30 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
}
}
+ @Override
+ public User removeUser(User user) {
+ User currentUser = getUser();
+ if (currentUser.getAdmin()) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ try {
+ entityManager.getTransaction().begin();
+ try {
+ user = entityManager.merge(user);
+ entityManager.remove(user);
+ entityManager.getTransaction().commit();
+ return user;
+ } catch (RuntimeException e) {
+ entityManager.getTransaction().rollback();
+ throw e;
+ }
+ } finally {
+ entityManager.close();
+ }
+ } else {
+ throw new SecurityException();
+ }
+ }
+
private void createUser(User user) {
EntityManager entityManager = entityManagerFactory.createEntityManager();
try {