aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server/model/DataServiceImpl.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-25 21:06:38 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-25 21:06:38 +1300
commitebcedc38812405ba1cd03c518317bcf0cd52f925 (patch)
tree2df884c0127218b1205bb5861ff7a048d6a54bff /src/org/traccar/web/server/model/DataServiceImpl.java
parentb26e487f3c65808d349c7a53c0ea2a3981b61bac (diff)
downloadtrackermap-web-ebcedc38812405ba1cd03c518317bcf0cd52f925.tar.gz
trackermap-web-ebcedc38812405ba1cd03c518317bcf0cd52f925.tar.bz2
trackermap-web-ebcedc38812405ba1cd03c518317bcf0cd52f925.zip
Added user management
Diffstat (limited to 'src/org/traccar/web/server/model/DataServiceImpl.java')
-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 c2d9f72e..663f0e4b 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 {