Skip to content

Commit dbe367b

Browse files
committed
Merge branch 'master' into rapport
2 parents 38286da + 05d900f commit dbe367b

15 files changed

+92
-47
lines changed

Jenkinsfile

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
pipeline {
2+
23
agent any
4+
35
options {
46
disableConcurrentBuilds()
57
}
8+
9+
environment {
10+
SPRING_DATASOURCE_USERNAME = credentials('SPRING_DATASOURCE_USERNAME')
11+
SPRING_DATASOURCE_PASSWORD = credentials('SPRING_DATASOURCE_PASSWORD')
12+
}
13+
614
stages {
715

816
stage('Build') {
@@ -13,15 +21,15 @@
1321
}
1422
steps {
1523
echo 'Build'
16-
sh '(cd ./jamais404/; mvn clean package)'
24+
sh '(cd ./jamais404/; mvn clean package -Dspring.profiles.active=prod)'
1725
stash name: "app", includes: "**"
1826
}
1927
}
2028

2129
stage('SonarCloud') {
2230
steps {
2331
unstash "app"
24-
sh '(cd ./jamais404/; mvn sonar:sonar'
32+
sh '(cd ./jamais404/; mvn sonar:sonar -Dspring.profiles.active=prod'
2533
}
2634
}
2735

@@ -34,7 +42,7 @@
3442
steps {
3543
echo 'Test'
3644
unstash "app"
37-
sh '(cd ./jamais404/; mvn test)'
45+
sh '(cd ./jamais404/; mvn test -Dspring.profiles.active=prod)'
3846
}
3947
}
4048
}

jamais404/src/main/java/com/jamais404/Handle404Controller.java

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.jamais404;
22

33
import com.jamais404.model.*;
4+
import com.jamais404.tools.TimeStampTools;
45
import com.jamais404.auth.repository.*;
56

6-
import java.text.ParseException;
7-
import java.text.SimpleDateFormat;
8-
import java.util.Date;
7+
import java.sql.Timestamp;
98

109
import javax.servlet.RequestDispatcher;
1110
import javax.servlet.http.HttpServletRequest;
@@ -27,8 +26,8 @@ public class Handle404Controller implements ErrorController {
2726
private PageRepository pageRepository;
2827

2928
/**
30-
* Handles every route different from the ones registered in
31-
* the HomeController.
29+
* Handles every route different from the ones registered in the HomeController.
30+
*
3231
* @param model
3332
* @param request
3433
* @return
@@ -42,19 +41,13 @@ public String handleError(Model model, HttpServletRequest request, Authenticatio
4241
model.addAttribute("url", originalUri);
4342

4443
Page page = pageRepository.findByName(originalUri);
45-
46-
if (page != null)
47-
{
48-
String ownerUsername = page.getOwner().getUsername();
49-
String datetime = page.getDatetime().toString();
5044

51-
try {
52-
//FIXME
53-
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.'SSSZ'").parse(datetime);
54-
datetime = new SimpleDateFormat("dd/MM/yyyy, Ka").format(date);
55-
} catch (ParseException e) { }
45+
if (page != null) {
46+
String ownerUsername = page.getOwner().getUsername();
47+
Timestamp datetime = page.getDatetime();
48+
String StringDatetime = TimeStampTools.timeStampToString(datetime);
5649

57-
model.addAttribute("datetime", datetime);
50+
model.addAttribute("datetime", StringDatetime);
5851

5952
if (ownerUsername.equals(authentication.getName())) {
6053
model.addAttribute("username", "you");

jamais404/src/main/java/com/jamais404/HomeController.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import org.springframework.stereotype.Controller;
1010
import org.springframework.ui.Model;
11+
import org.springframework.web.bind.annotation.GetMapping;
1112
import org.springframework.web.bind.annotation.PostMapping;
12-
import org.springframework.web.bind.annotation.RequestMapping;
13-
import org.springframework.web.bind.annotation.RequestMethod;
1413
import org.springframework.web.bind.annotation.RequestParam;
1514
import org.springframework.web.servlet.ModelAndView;
1615
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +25,7 @@ public class HomeController {
2625
* Home page
2726
* @return
2827
*/
29-
@RequestMapping(value = "/")
28+
@GetMapping(value = "/")
3029
public String home(Model model, Authentication authentication) {
3130
model.addAttribute("active", authentication.getName());
3231

@@ -49,7 +48,7 @@ public ModelAndView search(@RequestParam String query, Authentication authentica
4948
* @param model
5049
* @return
5150
*/
52-
@RequestMapping(value = "/user")
51+
@GetMapping(value = "/user")
5352
public String user(Model model, @RequestParam String username, Authentication authentication) {
5453
model.addAttribute("active", authentication.getName());
5554

@@ -59,7 +58,7 @@ public String user(Model model, @RequestParam String username, Authentication au
5958
Set<String> pagesNames = user.getPages()
6059
.stream()
6160
.parallel()
62-
.map(p -> p.getName())
61+
.map(Page::getName)
6362
.collect(Collectors.toSet());
6463

6564
model.addAttribute("username", username);

jamais404/src/main/java/com/jamais404/Jamais404Application.java

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
//import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
65

76
@SpringBootApplication //(exclude = {SecurityAutoConfiguration.class })
87
public class Jamais404Application {

jamais404/src/main/java/com/jamais404/auth/repository/PageRepository.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.jamais404.auth.repository;
22

33
import com.jamais404.model.Page;
4-
import com.jamais404.model.User;
5-
6-
import org.hibernate.mapping.Set;
74
import org.springframework.data.repository.CrudRepository;
85

96
public interface PageRepository extends CrudRepository<Page, Integer> {

jamais404/src/main/java/com/jamais404/auth/service/SecurityServiceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void autoLogin(String username, String password) {
4141

4242
if (usernamePasswordAuthenticationToken.isAuthenticated()) {
4343
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
44-
logger.debug(String.format("Auto login %s successfully!", username));
44+
logger.debug("Auto login " + username + " successfully!");
4545
}
4646
}
4747
}

jamais404/src/main/java/com/jamais404/auth/validator/UserValidator.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
public class UserValidator implements Validator {
1717

1818
public static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
19+
private static final String NOT_EMPTY_STRING = "NotEmpty";
20+
private static final String EMAIL_STRING = "email";
21+
private static final String USERNAME_STRING = "username";
1922

2023
@Autowired
2124
private UserService userService;
@@ -28,28 +31,29 @@ public boolean supports(Class<?> aClass) {
2831
@Override
2932
public void validate(Object o, Errors errors) {
3033
User user = (User) o;
34+
3135

3236
// Email
33-
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "NotEmpty");
37+
ValidationUtils.rejectIfEmptyOrWhitespace(errors, EMAIL_STRING, NOT_EMPTY_STRING);
3438
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(user.getEmail());
3539
if (! matcher.find()) {
36-
errors.rejectValue("email", "Not a valid email address.");
40+
errors.rejectValue(EMAIL_STRING, "Not a valid email address.");
3741
}
3842
if (userService.findByEmail(user.getEmail()) != null) {
39-
errors.rejectValue("email", "Duplicate.userForm.email");
43+
errors.rejectValue(EMAIL_STRING, "Duplicate.userForm.email");
4044
}
4145

4246
// Username
43-
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
47+
ValidationUtils.rejectIfEmptyOrWhitespace(errors, USERNAME_STRING, NOT_EMPTY_STRING);
4448
if (user.getUsername().length() < 6 || user.getUsername().length() > 32) {
45-
errors.rejectValue("username", "Size.userForm.username");
49+
errors.rejectValue(USERNAME_STRING, "Size.userForm.username");
4650
}
4751
if (userService.findByUsername(user.getUsername()) != null) {
48-
errors.rejectValue("username", "Duplicate.userForm.username");
52+
errors.rejectValue(USERNAME_STRING, "Duplicate.userForm.username");
4953
}
5054

5155
// Password
52-
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
56+
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", NOT_EMPTY_STRING);
5357
if (user.getPassword().length() < 8 || user.getPassword().length() > 32) {
5458
errors.rejectValue("password", "Size.userForm.password");
5559
}

jamais404/src/main/java/com/jamais404/model/Comment.java

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class Comment {
4242

4343
// METHODS
4444

45-
public Comment() {}
46-
4745
public long getId() {
4846
return id;
4947
}

jamais404/src/main/java/com/jamais404/model/Page.java

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public class Page{
5050

5151
// METHODS
5252

53-
public Page() {}
54-
5553
public long getId(){
5654
return id;
5755
}

jamais404/src/main/java/com/jamais404/model/User.java

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class User {
4242
private Set<Page> ownedPages;
4343

4444
// METHODS
45-
public User() {}
4645

4746
public long getId(){
4847
return id;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.jamais404.tools;
2+
3+
import java.sql.Timestamp;
4+
import java.util.Calendar;
5+
6+
/**
7+
*
8+
*/
9+
public class TimeStampTools {
10+
11+
/**
12+
* Transform a timestamp in a String with a wanted format in order to display it
13+
* @param ts the timestamp
14+
* @return a String with the wanted format.
15+
* Example : 23.04.2020 at 14:34
16+
*/
17+
public static String timeStampToString(Timestamp ts){
18+
19+
long ts_time = ts.getTime();
20+
Calendar cal = Calendar.getInstance();
21+
cal.setTimeInMillis(ts_time);
22+
23+
int year = cal.get(Calendar.YEAR);
24+
int month = cal.get(Calendar.MONTH);
25+
int day = cal.get(Calendar.DAY_OF_MONTH);
26+
int hour = cal.get(Calendar.HOUR_OF_DAY);
27+
int minute = cal.get(Calendar.MINUTE);
28+
29+
StringBuilder sb = new StringBuilder();
30+
sb.append(day);
31+
sb.append(".");
32+
sb.append(month);
33+
sb.append(".");
34+
sb.append(year);
35+
sb.append(" at ");
36+
sb.append(hour);
37+
sb.append(":");
38+
sb.append(minute);
39+
40+
return sb.toString();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.datasource.url=jdbc:mysql://157.26.83.82:3306/spring_db_2020?&serverTimezone=UTC
2+
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
3+
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
4+
spring.jpa.generate-ddl=true
5+
spring.jpa.hibernate.ddl-auto = update
6+
server.port=8888
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
spring.datasource.url=jdbc:mysql://157.26.83.82:3306/spring_db_2020?&serverTimezone=UTC
1+
spring.datasource.url=jdbc:mysql://127.0.0.1:8889/jamais?&serverTimezone=UTC
22
spring.datasource.username=root
33
spring.datasource.password=root
44
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
55
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
66
spring.jpa.generate-ddl=true
77
spring.jpa.hibernate.ddl-auto = update
8-
server.port=80
8+
server.port=8081

jamais404/src/main/resources/desktop.ini

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.datasource.url=jdbc:mysql://157.26.83.82:3306/spring_db_2020?&serverTimezone=UTC
2+
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
3+
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
4+
spring.jpa.generate-ddl=true
5+
spring.jpa.hibernate.ddl-auto = update
6+
server.port=8888

0 commit comments

Comments
 (0)