GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — hotfix · vgalloy/computer-database@70a5de8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • binding/src/main/java/com/excilys/computerdatabase/dto
    • model
      • ComputerDto.java
    • validator
      • DateValidator.java
  • persistence/src/main
    • java/com/excilys/computerdatabase/persistence/dao
      • CommonDao.java
      • impl
        • CompanyDaoImpl.java
    • resources/script
      • 5-TEST_DB.sql
  • service/src/main/java/com/excilys/computerdatabase/service/services
    • CommonService.java
    • impl
      • CompanyServiceImpl.java
  • webapp/src/main
    • java/com/excilys/computerdatabase
      • controler
        • computer
          • ComputerAdd.java
          • ComputerControler.java
        • global
          • GlobalErrorHandler.java
      • page/creator/computer
        • AddPageCreator.java
    • resources/message
      • springMessage_en.properties
      • springMessage_fr.properties
    • webapp
      • WEB-INF
        • tags
          • commonHead.tag
        • views
          • company/view
            • dashboard.jsp
          • global/view
            • home.jsp
      • css
        • main.css
      • js
        • validator.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎binding/src/main/java/com/excilys/computerdatabase/dto/model/ComputerDto.java‎

Copy file name to clipboardExpand all lines: binding/src/main/java/com/excilys/computerdatabase/dto/model/ComputerDto.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public class ComputerDto implements Serializable {
2525
private String name;
2626

2727
/** The introduced. */
28-
@Date(message = "{error.invalid.introduced.date} {date.format}")
28+
@Date(message = "{error.invalid.introduced.date} {date.condition}")
2929
private String introduced;
3030

3131
/** The discontinued. */
32-
@Date(message = "{error.invalid.discontined.date} {date.format}")
32+
@Date(message = "{error.invalid.discontined.date} {date.condition}")
3333
private String discontinued;
3434

3535
/** The company id. */
Collapse file

‎binding/src/main/java/com/excilys/computerdatabase/dto/validator/DateValidator.java‎

Copy file name to clipboardExpand all lines: binding/src/main/java/com/excilys/computerdatabase/dto/validator/DateValidator.java
+30-16Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package com.excilys.computerdatabase.dto.validator;
66

7+
import java.time.LocalDateTime;
8+
import java.time.format.DateTimeFormatter;
79
import java.util.Locale;
810

911
import javax.validation.ConstraintValidator;
@@ -19,20 +21,27 @@
1921
*/
2022
@Component
2123
public class DateValidator implements ConstraintValidator<Date, String> {
22-
24+
2325
/** The message source. */
2426
@Autowired
2527
private MessageSource messageSource;
2628

27-
/* (non-Javadoc)
28-
* @see javax.validation.ConstraintValidator#initialize(java.lang.annotation.Annotation)
29+
/*
30+
* (non-Javadoc)
31+
*
32+
* @see
33+
* javax.validation.ConstraintValidator#initialize(java.lang.annotation.Annotation
34+
* )
2935
*/
3036
@Override
3137
public void initialize(Date constraintAnnotation) {
3238
}
3339

34-
/* (non-Javadoc)
35-
* @see javax.validation.ConstraintValidator#isValid(java.lang.Object, javax.validation.ConstraintValidatorContext)
40+
/*
41+
* (non-Javadoc)
42+
*
43+
* @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
44+
* javax.validation.ConstraintValidatorContext)
3645
*/
3746
@Override
3847
public boolean isValid(String value, ConstraintValidatorContext context) {
@@ -42,23 +51,29 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
4251
if (value.isEmpty()) {
4352
return true;
4453
}
45-
if (isCorrectDate(value, getPattern())) {
46-
return true;
47-
}
48-
return false;
54+
return isCorrectDate(value, getPattern());
4955
}
5056

5157
/**
5258
* Checks if is correct date.
5359
*
54-
* @param date the date
55-
* @param pattern the pattern
60+
* @param date
61+
* the date
62+
* @param pattern
63+
* the pattern
5664
* @return true, if is correct date
5765
*/
5866
private boolean isCorrectDate(String date, String pattern) {
59-
return org.apache.commons.validator.routines.DateValidator.getInstance().isValid(date, pattern);
67+
if (org.apache.commons.validator.routines.DateValidator.getInstance().isValid(date, pattern)) {
68+
LocalDateTime localDateTime = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(pattern));
69+
LocalDateTime localDateTimeAfter = LocalDateTime.parse("1970-01-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
70+
LocalDateTime localDateTimeBefore = LocalDateTime.parse("2038-01-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
71+
return localDateTime.isAfter(localDateTimeAfter) && localDateTime.isBefore(localDateTimeBefore);
72+
} else {
73+
return false;
74+
}
6075
}
61-
76+
6277
/**
6378
* Gets the pattern.
6479
*
@@ -67,10 +82,9 @@ private boolean isCorrectDate(String date, String pattern) {
6782
private String getPattern() {
6883
String str;
6984
Locale userLocale = LocaleContextHolder.getLocale();
70-
if(messageSource != null) {
85+
if (messageSource != null) {
7186
str = messageSource.getMessage("date.pattern", null, userLocale);
72-
}
73-
else {
87+
} else {
7488
str = "yyyy-MM-dd HH:mm:ss";
7589
}
7690
return str;
Collapse file

‎persistence/src/main/java/com/excilys/computerdatabase/persistence/dao/CommonDao.java‎

Copy file name to clipboardExpand all lines: persistence/src/main/java/com/excilys/computerdatabase/persistence/dao/CommonDao.java
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public interface CommonDao<T> {
2626
*
2727
* @param t the t
2828
*/
29-
public default void update(T t) {
30-
throw new UnsupportedOperationException();
31-
}
29+
public void update(T t);
3230

3331
/**
3432
* Gets the all.
@@ -59,7 +57,7 @@ public default void update(T t) {
5957
* Gets the by id.
6058
*
6159
* @param id the id
62-
* @return the by id
60+
* @return the object by id
6361
*/
6462
public T getById(Long id);
6563

Collapse file

‎persistence/src/main/java/com/excilys/computerdatabase/persistence/dao/impl/CompanyDaoImpl.java‎

Copy file name to clipboardExpand all lines: persistence/src/main/java/com/excilys/computerdatabase/persistence/dao/impl/CompanyDaoImpl.java
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class CompanyDaoImpl implements CompanyDao {
2929

3030
@Override
3131
public void create(Company t) {
32+
log.info("Company update : {}", t);
3233
Session session = sf.getCurrentSession();
3334
if (!Validator.isCompanyCorrect(t)) {
3435
log.warn(Validator.INVALID_COMPANY);
@@ -40,12 +41,14 @@ public void create(Company t) {
4041

4142
@Override
4243
public List<Company> getAll(SortCriteria sortCriteria) {
44+
log.info("Company getAll");
4345
Session session = sf.getCurrentSession();
4446
return session.createCriteria(Company.class).addOrder(Order.asc("name")).list();
4547
}
4648

4749
@Override
4850
public List<Company> getAll(Long from, Long to, SortCriteria sortCriteria) {
51+
log.info("Company update : {} to {}", from , to);
4952
Session session = sf.getCurrentSession();
5053
if (!Validator.isDateFromToCorrect(from, to)) {
5154
log.warn(Validator.INVALID_BOUND);
@@ -59,6 +62,7 @@ public List<Company> getAll(Long from, Long to, SortCriteria sortCriteria) {
5962

6063
@Override
6164
public Long getNumberOfElement() {
65+
log.info("Company getNumberOfElement");
6266
Session session = sf.getCurrentSession();
6367
return (Long) session.createCriteria(Company.class)
6468
.setProjection(Projections.rowCount())
@@ -68,6 +72,7 @@ public Long getNumberOfElement() {
6872

6973
@Override
7074
public void delete(Long id) {
75+
log.info("Company delete : {}", id);
7176
Session session = sf.getCurrentSession();
7277
if (!Validator.isIdCorrect(id)) {
7378
log.warn(Validator.INVALID_COMPANY_ID);
@@ -82,6 +87,7 @@ public void delete(Long id) {
8287

8388
@Override
8489
public Company getById(Long id) {
90+
log.info("Company getById : {}", id);
8591
Session session = sf.getCurrentSession();
8692
if (!Validator.isIdCorrect(id)) {
8793
log.warn(Validator.INVALID_COMPANY_ID);
@@ -90,4 +96,15 @@ public Company getById(Long id) {
9096
return (Company) session.get(Company.class, id);
9197
}
9298

99+
@Override
100+
public void update(Company t) {
101+
log.info("Company update : {}", t);
102+
Session session = sf.getCurrentSession();
103+
if (!Validator.isCompanyCorrect(t)) {
104+
log.warn(Validator.INVALID_COMPANY);
105+
throw new DaoException(Validator.INVALID_COMPANY);
106+
}
107+
session.merge(t);
108+
}
109+
93110
}
Collapse file

‎persistence/src/main/resources/script/5-TEST_DB.sql‎

Copy file name to clipboardExpand all lines: persistence/src/main/resources/script/5-TEST_DB.sql
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ constraint pk_authorities primary key (user_role_id));
3636
alter table computer add constraint fk_computer_company_1 foreign key (company_id) references company (id) on delete restrict on update restrict;
3737
create index ix_computer_company_1 on computer (company_id);
3838

39+
alter table authorities add constraint fk_authorities_users foreign key(username) references users(username) on delete CASCADE on update restrict;
40+
create index ix_role_username on authorities (username,role);
3941

40-
INSERT INTO users(username,password,enabled) VALUES ('admin','$2a$10$cwXZKDV44c3cFl0ac0QU0OyIMMkSuUC9gEifqDuwzmc8QSAVbhatS', TRUE);
41-
INSERT INTO users(username,password,enabled) VALUES ('user','$2a$10$H0eNB7HcZI0V049EetfGxu4hK07vZLCkaZkcQOv6/aZCGLI7TFSQW', TRUE);
42+
#INSERT INTO users(username,password,enabled) VALUES ('admin','$2a$10$cwXZKDV44c3cFl0ac0QU0OyIMMkSuUC9gEifqDuwzmc8QSAVbhatS', TRUE);
43+
#INSERT INTO users(username,password,enabled) VALUES ('user','$2a$10$H0eNB7HcZI0V049EetfGxu4hK07vZLCkaZkcQOv6/aZCGLI7TFSQW', TRUE);
4244
INSERT INTO users(username,password,enabled) VALUES ('all','$2a$10$UA.m4MEeB5dFfwtZZO.0B.a.dLJuzuB05gclWOjS/a9UiZ8dZI/2S', TRUE);
4345

4446

45-
INSERT INTO authorities (username, role) VALUES ('admin', 'ROLE_USER');
46-
INSERT INTO authorities (username, role) VALUES ('admin', 'ROLE_ADMIN');
47-
INSERT INTO authorities (username, role) VALUES ('user', 'ROLE_USER');
47+
#INSERT INTO authorities (username, role) VALUES ('admin', 'ROLE_USER');
48+
#INSERT INTO authorities (username, role) VALUES ('admin', 'ROLE_ADMIN');
49+
#INSERT INTO authorities (username, role) VALUES ('user', 'ROLE_USER');
4850
INSERT INTO authorities (username, role) VALUES ('all', 'ROLE_USER');
4951
INSERT INTO authorities (username, role) VALUES ('all', 'ROLE_ADMIN');
5052
INSERT INTO authorities (username, role) VALUES ('all', 'ROLE_SUPER_ADMIN');
Collapse file

‎service/src/main/java/com/excilys/computerdatabase/service/services/CommonService.java‎

Copy file name to clipboardExpand all lines: service/src/main/java/com/excilys/computerdatabase/service/services/CommonService.java
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ public default List<T> list(Long from, Long to) {
7979
*
8080
* @param t the t
8181
*/
82-
public default void update(T t) {
83-
throw new UnsupportedOperationException();
84-
}
82+
public void update(T t);
8583

8684
/**
8785
* Delete.
Collapse file

‎service/src/main/java/com/excilys/computerdatabase/service/services/impl/CompanyServiceImpl.java‎

Copy file name to clipboardExpand all lines: service/src/main/java/com/excilys/computerdatabase/service/services/impl/CompanyServiceImpl.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ private void deleteCompany(Long id) {
123123
companyDao.delete(id);
124124
}
125125

126+
@Override
127+
@Transactional(readOnly=false)
128+
public void update(Company t) {
129+
log.info("Company update : {}", t);
130+
if (!Validator.isCompanyCorrect(t)) {
131+
throw new ServiceException(Validator.INVALID_COMPANY);
132+
}
133+
companyDao.update(t);
134+
}
135+
126136
/**
127137
* Gets the company dao.
128138
*
Collapse file

‎webapp/src/main/java/com/excilys/computerdatabase/controler/computer/ComputerAdd.java‎

Copy file name to clipboardExpand all lines: webapp/src/main/java/com/excilys/computerdatabase/controler/computer/ComputerAdd.java
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
*/
44
package com.excilys.computerdatabase.controler.computer;
55

6+
import java.util.Locale;
7+
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.context.i18n.LocaleContextHolder;
912
import org.springframework.stereotype.Controller;
1013
import org.springframework.ui.Model;
1114
import org.springframework.web.bind.annotation.RequestMapping;
1215
import org.springframework.web.bind.annotation.RequestMethod;
1316
import org.springframework.web.bind.annotation.SessionAttributes;
1417

1518
import com.excilys.computerdatabase.controler.AbstractController;
19+
import com.excilys.computerdatabase.page.creator.AbstractPageCreator;
1620
import com.excilys.computerdatabase.page.creator.computer.AddPageCreator;
1721
import com.excilys.computerdatabase.page.model.ComputerPage;
1822
import com.excilys.computerdatabase.session.AddComputerSession;
@@ -49,6 +53,7 @@ private String getAddComputerPage(Model model) {
4953
ComputerPage page = addPageCreator.getPageFromGetRequest();
5054
if (addComputerSession.getComputerDto() != null) {
5155
page.setComputerDto(addComputerSession.getComputerDto());
56+
AbstractPageCreator.pageConverter(page, Locale.ENGLISH, LocaleContextHolder.getLocaleContext().getLocale());
5257
model.addAttribute("org.springframework.validation.BindingResult.addComputerDto", addComputerSession.getBindingResult());
5358
}
5459
model.addAttribute("page", page);
Collapse file

‎webapp/src/main/java/com/excilys/computerdatabase/controler/computer/ComputerControler.java‎

Copy file name to clipboardExpand all lines: webapp/src/main/java/com/excilys/computerdatabase/controler/computer/ComputerControler.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public String addComputer(@Valid @ModelAttribute("addComputerDto") ComputerDto c
8181
log.info("Servlet : [POST] computer-add {}", computerDto);
8282

8383
ComputerPage page = addPageCreator.getPageFromPostRequest(computerDto);
84-
addComputerSession.setComputerDto(page.getComputerDto());
85-
addComputerSession.setBindingResult(bindingResult);
8684

8785
if (bindingResult.hasErrors()) {
8886
log.info("Wrong input");
8987
return REDIRECT + COMPUTER + VIEW + ADD;
9088
} else {
9189
AbstractPageCreator.pageConverter(page, LocaleContextHolder.getLocaleContext().getLocale(), Locale.ENGLISH);
90+
addComputerSession.setComputerDto(page.getComputerDto());
91+
addComputerSession.setBindingResult(bindingResult);
9292
Computer computer = computerDtoMapper.mapToModel(page.getComputerDto());
9393
computerService.create(computer);
9494
log.info("Computer added : " + computer);
Collapse file

‎webapp/src/main/java/com/excilys/computerdatabase/controler/global/GlobalErrorHandler.java‎

Copy file name to clipboardExpand all lines: webapp/src/main/java/com/excilys/computerdatabase/controler/global/GlobalErrorHandler.java
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
*/
55
package com.excilys.computerdatabase.controler.global;
66

7+
import org.springframework.beans.factory.annotation.Autowired;
78
import org.springframework.http.HttpStatus;
89
import org.springframework.web.bind.annotation.ControllerAdvice;
910
import org.springframework.web.bind.annotation.ExceptionHandler;
1011
import org.springframework.web.bind.annotation.ResponseStatus;
1112
import org.springframework.web.servlet.ModelAndView;
1213

14+
import com.excilys.computerdatabase.session.AddComputerSession;
15+
1316
/**
1417
* The Class GlobalErrorHandler.
1518
*/
1619
@ControllerAdvice
1720
public class GlobalErrorHandler {
18-
21+
@Autowired
22+
private AddComputerSession addComputerSession;
1923
/**
2024
* Handler.
2125
*
@@ -25,6 +29,9 @@ public class GlobalErrorHandler {
2529
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
2630
@ExceptionHandler(Exception.class)
2731
public ModelAndView handler(Exception e) {
32+
e.printStackTrace();
33+
addComputerSession.setComputerDto(null);
34+
addComputerSession.setBindingResult(null);
2835
ModelAndView modelAndView = new ModelAndView("500");
2936
modelAndView.addObject("exception", e);
3037
return modelAndView;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.