From fea8fa5a44472438665ad3621329320a5e06dcf4 Mon Sep 17 00:00:00 2001
From: Mirco Nasuti <mirco.nasuti@chuv.ch>
Date: Tue, 15 Mar 2016 14:02:37 +0100
Subject: [PATCH] bugfix : agreeNDA

---
 src/main/java/org/hbp/mip/MIPApplication.java      | 14 ++++++++++----
 .../java/org/hbp/mip/controllers/MiningApi.java    |  2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/hbp/mip/MIPApplication.java b/src/main/java/org/hbp/mip/MIPApplication.java
index 59516ca17..609d0c2c3 100644
--- a/src/main/java/org/hbp/mip/MIPApplication.java
+++ b/src/main/java/org/hbp/mip/MIPApplication.java
@@ -128,6 +128,11 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
         User user = new User(getUserInfos());
         try {
             session.beginTransaction();
+            Boolean agreeNDA = (Boolean) session
+                    .createQuery("SELECT agreeNDA FROM User WHERE username= :username")
+                    .setString("username", user.getUsername())
+                    .uniqueResult();
+            user.setAgreeNDA(agreeNDA);
             session.merge(user);
             session.getTransaction().commit();
         } catch (Exception e)
@@ -135,6 +140,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
             if(session.getTransaction() != null)
             {
                 session.getTransaction().rollback();
+                throw e;
             }
         }
 
@@ -183,15 +189,14 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
     }
 
     @RequestMapping(path = "/user", method = RequestMethod.POST)
-    public ResponseEntity<Void> postUser(Principal principal, HttpServletResponse response,
-                                         @ApiParam(value = "Has the user agreed on the NDA") @RequestParam(value = "agreeNDA", required = true) Boolean agreeNDA) {
-        ObjectMapper mapper = new ObjectMapper();
+    public ResponseEntity<Void> postUser(@ApiParam(value = "Has the user agreed on the NDA") @RequestParam(value = "agreeNDA", required = true) Boolean agreeNDA) {
+        String username = getUser().getUsername();
         Session session = HibernateUtil.getSessionFactory().getCurrentSession();
         try {
             session.beginTransaction();
             User user = (User) session
                     .createQuery("from User where username= :username")
-                    .setString("username", principal.getName())
+                    .setString("username", username)
                     .uniqueResult();
             if (user != null) {
                 user.setAgreeNDA(agreeNDA);
@@ -203,6 +208,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
             if(session.getTransaction() != null)
             {
                 session.getTransaction().rollback();
+                throw e;
             }
         }
 
diff --git a/src/main/java/org/hbp/mip/controllers/MiningApi.java b/src/main/java/org/hbp/mip/controllers/MiningApi.java
index 89f690272..fe7bbb6f5 100644
--- a/src/main/java/org/hbp/mip/controllers/MiningApi.java
+++ b/src/main/java/org/hbp/mip/controllers/MiningApi.java
@@ -31,7 +31,7 @@ public class MiningApi {
     @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") })
     @RequestMapping(method = RequestMethod.POST)
     public ResponseEntity<String> postMining(
-            @RequestBody @ApiParam(value = "Model to create", required = true) String query
+            @RequestBody @ApiParam(value = "Query for the data mining", required = true) String query
     ) throws Exception {
 
         StringBuilder results = new StringBuilder();
-- 
GitLab