Skip to content

Commit d9537b4

Browse files
Merge pull request #52 from Arquisoft/development
update stable version : update of last stable changes
2 parents e13d1c6 + 20f7e0c commit d9537b4

File tree

8 files changed

+78
-117
lines changed

8 files changed

+78
-117
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ local.properties
8282

8383
.idea/
8484
participants0.iml
85-
participants_i2b.iml
85+
participants_i2b.iml
86+
/.gradle/
87+
/build/

README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ Contributions to the project are welcomed and encouraged! Please see the [Contri
3333
These instructions give the most direct path to work with the project.
3434

3535
### System Requirements
36-
As the project is developed in java macOS, Windows and Linux distros are natively supported. Of course you will need the lastest jdk available. Also, depending on where are you going to run the database will need internet conection or MongoDB installed and running on your machine.
36+
As the project is developed in java macOS, Windows and Linux distributions are natively supported. Of course you will need the latest JDK available. Also, depending on where are you going to run the database, you will need internet connection or MongoDB installed and running on your machine.
3737

3838
#### Java Development Kit (JDK)
39-
A Java Development Kit (JDK) is a program development environment for writing Java applets and applications. It consists of a runtime environment that "sits on top" of the operating system layer as well as the tools and programming that developers need to compile, debug, and run applets and applications written in the Java language.
39+
A Java Development Kit (JDK) is a program development environment for writing Java applets and applications. It consists of a runtime environment that "sits on top" of the operating system layer as well as the tools and programming that developers need to compile, debug, and run applets and applications written in the Java programming language.
4040

41-
If you do not has the lastest stable version download you can download it [here](http://www.oracle.com/technetwork/java/javase/downloads).
41+
If you do not has the latest stable version download you can download it [here](http://www.oracle.com/technetwork/java/javase/downloads).
4242

4343
#### MongoDB
44-
This project uses MongoDB as the database. You can check how to use it on [MongoDB install](https://github.com/Arquisoft/participants_i2b/wiki/MongoDB). By defatult a dummy server is up and running, its configured at the file `applications.properties`. Change this configuration as needed, should not interfeer with the module itself.
44+
This project uses MongoDB as the database. You can check how to use it on [MongoDB install](https://github.com/Arquisoft/participants_i2b/wiki/MongoDB). By defatult a dummy server is up and running, it´s configured at the file `applications.properties`. Change this configuration as needed, should not interfeer with the module itself.
4545

4646
#### Jasypt
4747
This project uses Jasypt to encrypt the passwords. You don't need to download it as far as its dependency its imported from maven central, but you can check it [here](http://www.jasypt.org/).
@@ -95,15 +95,23 @@ user interface manually you'll have to introduce this document:
9595
"location" : "10N10W",
9696
"email" : "[email protected]",
9797
"kindCode" : "1",
98-
"id" : "00000000A",
98+
"id" : "45170000A",
9999
"password" : "khZZwjdhWwVbMdmOvz9eqBfKR1N6A+CdFBDM9c1dQduUnGewQyPRlBxB4Q6wT7Cq"
100100
}
101101
```
102102

103103
And as data use:
104-
- login: 00000000A
104+
- login: 45170000A
105105
- password: 4[[j[frVCUMJ>hU
106106
- Kind of agent: Person
107107

108108
If you have the data and the database running and the application still reports a 404 Not Found when it shouldn't
109109
try deleting the document and adding it again.
110+
111+
As an alternative, you can perform tests on the REST service by executing the next function in the command line:
112+
113+
```bash
114+
curl -H "Content-Type: application/json" -X POST -d '{"login":"45170000A","password":"4[[j[frVCUMJ>hU", "kind":1}' http://localhost:8080/user
115+
```
116+
117+
Take into account that the parameters passed in the function are the same as the previous JSON file, so they have to be synchronised.

pom.xml

+50-49
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>es.uniovi.asw</groupId>
7+
<artifactId>agents_i3a</artifactId>
78
<name>agents_i3a</name>
89
<version>0.0.1</version>
910

@@ -12,31 +13,31 @@
1213
<artifactId>spring-boot-starter-parent</artifactId>
1314
<version>1.4.3.RELEASE</version>
1415
</parent>
15-
16+
1617
<dependencies>
1718
<dependency>
18-
<groupId>com.github.computer-engineering-uniovi</groupId>
19-
<artifactId>swift</artifactId>
20-
<version>1.1</version>
19+
<groupId>com.github.computer-engineering-uniovi</groupId>
20+
<artifactId>swift</artifactId>
21+
<version>1.1</version>
2122
</dependency>
22-
23+
2324
<dependency>
2425
<groupId>org.springframework.boot</groupId>
2526
<artifactId>spring-boot-starter-web</artifactId>
2627
</dependency>
27-
28+
2829

2930
<dependency>
3031
<groupId>org.springframework.boot</groupId>
3132
<artifactId>spring-boot-starter-test</artifactId>
3233
<scope>test</scope>
3334
</dependency>
34-
35+
3536
<dependency>
36-
<groupId>org.springframework.test.htmlunit</groupId>
37-
<artifactId>spring-test-htmlunit</artifactId>
38-
<version>1.0.0.RC1</version>
39-
<scope>test</scope>
37+
<groupId>org.springframework.test.htmlunit</groupId>
38+
<artifactId>spring-test-htmlunit</artifactId>
39+
<version>1.0.0.RC1</version>
40+
<scope>test</scope>
4041
</dependency>
4142

4243
<dependency>
@@ -59,52 +60,52 @@
5960
<groupId>org.springframework.boot</groupId>
6061
<artifactId>spring-boot-test</artifactId>
6162
</dependency>
62-
63+
6364
<!-- Jasypt Depencency -->
6465
<dependency>
65-
<groupId>org.jasypt</groupId>
66-
<artifactId>jasypt</artifactId>
67-
<version>1.9.2</version>
68-
</dependency>
66+
<groupId>org.jasypt</groupId>
67+
<artifactId>jasypt</artifactId>
68+
<version>1.9.2</version>
69+
</dependency>
6970

7071
<!-- MongoDB Dependency -->
7172
<dependency>
7273
<groupId>org.springframework.boot</groupId>
7374
<artifactId>spring-boot-starter-data-mongodb</artifactId>
7475
</dependency>
7576

76-
<dependency>
77-
<groupId>org.glassfish.jersey.ext</groupId>
78-
<artifactId>jersey-spring3</artifactId>
79-
<exclusions>
80-
<exclusion>
81-
<groupId>org.springframework</groupId>
82-
<artifactId>spring</artifactId>
83-
</exclusion>
84-
<exclusion>
85-
<groupId>org.springframework</groupId>
86-
<artifactId>spring-core</artifactId>
87-
</exclusion>
88-
<exclusion>
89-
<groupId>org.springframework</groupId>
90-
<artifactId>spring-web</artifactId>
91-
</exclusion>
92-
<exclusion>
93-
<groupId>org.springframework</groupId>
94-
<artifactId>spring-beans</artifactId>
95-
</exclusion>
96-
<exclusion>
97-
<groupId>org.springframework</groupId>
98-
<artifactId>spring-context</artifactId>
99-
</exclusion>
100-
</exclusions>
101-
</dependency>
77+
<dependency>
78+
<groupId>org.glassfish.jersey.ext</groupId>
79+
<artifactId>jersey-spring3</artifactId>
80+
<exclusions>
81+
<exclusion>
82+
<groupId>org.springframework</groupId>
83+
<artifactId>spring</artifactId>
84+
</exclusion>
85+
<exclusion>
86+
<groupId>org.springframework</groupId>
87+
<artifactId>spring-core</artifactId>
88+
</exclusion>
89+
<exclusion>
90+
<groupId>org.springframework</groupId>
91+
<artifactId>spring-web</artifactId>
92+
</exclusion>
93+
<exclusion>
94+
<groupId>org.springframework</groupId>
95+
<artifactId>spring-beans</artifactId>
96+
</exclusion>
97+
<exclusion>
98+
<groupId>org.springframework</groupId>
99+
<artifactId>spring-context</artifactId>
100+
</exclusion>
101+
</exclusions>
102+
</dependency>
102103

103104
<!-- Apache commons-csv -->
104105
<dependency>
105-
<groupId>org.apache.commons</groupId>
106-
<artifactId>commons-csv</artifactId>
107-
<version>1.5</version>
106+
<groupId>org.apache.commons</groupId>
107+
<artifactId>commons-csv</artifactId>
108+
<version>1.5</version>
108109
</dependency>
109110

110111

@@ -143,7 +144,7 @@
143144
</executions>
144145
</plugin>
145146
</plugins>
146-
147+
147148
</build>
148149

149150
<reporting>
@@ -200,8 +201,8 @@
200201
<url>https://repo.spring.io/libs-release</url>
201202
</repository>
202203
<repository>
203-
<id>jitpack.io</id>
204-
<url>https://jitpack.io</url>
204+
<id>jitpack.io</id>
205+
<url>https://jitpack.io</url>
205206
</repository>
206207
</repositories>
207208

@@ -212,5 +213,5 @@
212213
</pluginRepository>
213214
</pluginRepositories>
214215

215-
<artifactId>agents_i3a</artifactId>
216+
216217
</project>

src/main/java/domain/Agent.java

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import org.springframework.data.annotation.Id;
1717
import org.springframework.data.mongodb.core.mapping.Document;
1818

19+
import com.fasterxml.jackson.annotation.JsonIgnore;
20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
22+
1923
import Foundation.CSVFile;
2024
import Foundation.URL;
2125

@@ -26,6 +30,7 @@
2630
* @since 06/02/2017
2731
*/
2832
@Document(collection = "users")
33+
@JsonPropertyOrder({ "name", "location", "email", "id", "kind", "kindCode" })
2934
public class Agent implements Comparable<Agent> {
3035

3136
@Id
@@ -108,6 +113,8 @@ public String getEmail() {
108113
/**
109114
* @return the password of the user.
110115
*/
116+
@JsonIgnore
117+
@JsonProperty(value = "user_password")
111118
public String getPassword() {
112119
return password;
113120
}

src/main/java/view/ParticipantsController.java

+1-29
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
*
1111
*/
1212
package view;
13-
14-
import javax.servlet.http.HttpSession;
15-
16-
import org.jasypt.util.password.StrongPasswordEncryptor;
1713
import org.springframework.stereotype.Controller;
1814
import org.springframework.ui.Model;
1915
import org.springframework.web.bind.annotation.GetMapping;
2016
import org.springframework.web.bind.annotation.ModelAttribute;
2117
import org.springframework.web.bind.annotation.RequestMapping;
2218
import org.springframework.web.bind.annotation.RequestMethod;
23-
import org.springframework.web.bind.annotation.RequestParam;
2419

2520
import domain.Agent;
2621
import domain.AgentLoginData;
@@ -52,7 +47,7 @@ public String getParticipantInfo(Model model) {
5247
// This method process an POST html request once fulfilled the login.html form
5348
// (clicking in the "Enter" button).
5449
@RequestMapping(value = "/userForm", method = RequestMethod.POST)
55-
public String showInfo(Model model, @ModelAttribute AgentLoginData data, HttpSession session) {
50+
public String showInfo(Model model, @ModelAttribute AgentLoginData data) {
5651
Agent user = participantsService.getParticipant(data.getLogin(), data.getPassword(), data.getKind());
5752
if (user == null) {
5853
throw new UserNotFoundException();
@@ -64,30 +59,7 @@ public String showInfo(Model model, @ModelAttribute AgentLoginData data, HttpSes
6459
model.addAttribute("id", user.getId());
6560
model.addAttribute("kindCode", user.getKindCode());
6661
model.addAttribute("user", user);
67-
session.setAttribute("user", user);
6862
return "data";
6963
}
7064
}
71-
72-
@RequestMapping(value = "/passMenu", method = RequestMethod.GET)
73-
public String showMenu(Model model) {
74-
// Just in case there must be more processing.
75-
return "changePassword";
76-
}
77-
78-
@RequestMapping(value = "/userChangePassword", method = RequestMethod.POST)
79-
public String changePassword(Model model, @RequestParam String password, @RequestParam String newPassword,
80-
@RequestParam String newPasswordConfirm, HttpSession session) {
81-
82-
Agent loggedUser = (Agent) session.getAttribute("user");
83-
84-
if (new StrongPasswordEncryptor().checkPassword(password, loggedUser.getPassword())
85-
&& newPassword.equals(newPasswordConfirm)) {
86-
87-
participantsService.updateInfo(loggedUser, newPassword);
88-
return "data";
89-
}
90-
return "changePassword";
91-
}
92-
9365
}

src/main/resources/templates/data.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<div class="container-fluid well span6">
2626

2727
<div class="col-md-6">
28-
<strong>Account information</strong>
28+
<h1><strong>Account information</strong></h1>
2929
<div class="table-responsive">
3030
<table class="table table-condensed table-responsive table-user-information">
3131
<tbody>
@@ -80,11 +80,12 @@
8080
<span th:text="${kind}" />
8181
</td>
8282
</tr>
83+
<tr><td></td><td></td></tr>
8384
</tbody>
8485
</table>
8586
</div>
8687
</div>
87-
<a class="btn btn-primary glyphicon glyphicon-cog " href="/passMenu">Change password</a>
88+
<!-- <a class="btn btn-primary glyphicon glyphicon-cog " href="/passMenu">Change password</a> -->
8889
</div>
8990

9091

src/test/java/domainTests/AgentTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.jasypt.util.password.StrongPasswordEncryptor;
1919
import org.junit.Before;
2020
import org.junit.Test;
21-
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter.DataWithMediaType;
2221

2322
import Foundation.CSVFile;
2423
import Foundation.URL;

src/test/java/viewTests/ParticipantsDataControllerTest.java

-29
Original file line numberDiff line numberDiff line change
@@ -143,33 +143,4 @@ public void testForIncorrectPassword() throws Exception {
143143
.content(payload.getBytes());
144144
mockMvc.perform(request).andDo(print()).andExpect(status().isNotFound());
145145
}
146-
147-
@Test
148-
public void testChangePassword() throws Exception {
149-
MockHttpSession session = new MockHttpSession();
150-
151-
// We check we have the proper credentials
152-
MockHttpServletRequestBuilder request = post("/userForm").session(session).param("login", maria.getId())
153-
.param("password", plainPassword).param("kind", Integer.toString(maria.getKindCode()));
154-
mockMvc.perform(request).andExpect(status().isOk());
155-
156-
// We change it
157-
request = post("/userChangePassword").session(session).param("password", plainPassword)
158-
.param("newPassword", "HOLA").param("newPasswordConfirm", "HOLA");
159-
mockMvc.perform(request).andExpect(status().isOk());
160-
161-
String payload = String.format(QUERY_STRING, maria.getId(), "HOLA", maria.getKindCode());
162-
163-
// We check password has changed
164-
request = post("/user").session(session).contentType(MediaType.APPLICATION_JSON).content(payload.getBytes());
165-
mockMvc.perform(request).andDo(print()).andExpect(status().isOk())
166-
.andExpect(jsonPath("$.name", is(maria.getName())))
167-
.andExpect(jsonPath("$.location", is(maria.getLocation())))
168-
.andExpect(jsonPath("$.email", is(maria.getEmail())))
169-
.andExpect(jsonPath("$.id", is(maria.getId())))
170-
.andExpect(jsonPath("$.kind", is(maria.getKind())))
171-
.andExpect(jsonPath("$.kindCode", is(maria.getKindCode())));
172-
173-
}
174-
175146
}

0 commit comments

Comments
 (0)