-
Notifications
You must be signed in to change notification settings - Fork 0
Issue 81 create client personal data service #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChirkinaTanya
wants to merge
5
commits into
develop
Choose a base branch
from
Issue_81_create_client_personal_data_service
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11e15bc
Issue #81 added interface PersonalDataService and common features of …
ChirkinaTanya 223391b
Merge branch 'develop' into Issue_81_create_client_personal_data_service
ChirkinaTanya 76232ae
Issue #81 added getBySerialNumber method in PassportDao and PassportD…
ChirkinaTanya 95901dd
Merge branch 'develop' into Issue_81_create_client_personal_data_service
ChirkinaTanya 8ff01cb
Issue #81 created changeDrivingLicence method which contains createDr…
ChirkinaTanya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
src/main/java/com/ifmo/epampractice/serviceimpl/PersonalDataServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| package com.ifmo.epampractice.serviceimpl; | ||
|
|
||
| import com.ifmo.epampractice.dao.DrivingLicenseDao; | ||
| import com.ifmo.epampractice.dao.PassportDao; | ||
| import com.ifmo.epampractice.dao.UsersDao; | ||
| import com.ifmo.epampractice.entity.DrivingLicenseEntity; | ||
| import com.ifmo.epampractice.entity.PassportEntity; | ||
| import com.ifmo.epampractice.entity.UsersEntity; | ||
| import com.ifmo.epampractice.services.PasswordHashService; | ||
| import com.ifmo.epampractice.services.PersonalDataService; | ||
| import com.ifmo.epampractice.security.SecureString; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public class PersonalDataServiceImpl implements PersonalDataService { | ||
|
|
||
| private UsersDao usersDao; | ||
| private PassportDao passportDao; | ||
| private DrivingLicenseDao drivingLicenseDao; | ||
| private PasswordHashService passwordHashService; | ||
|
|
||
| public PersonalDataServiceImpl(UsersDao usersDao, PassportDao passportDao, PasswordHashService passwordHashService){ | ||
| this.usersDao = usersDao; | ||
| this.passportDao = passportDao; | ||
| this.drivingLicenseDao = drivingLicenseDao; | ||
| this.passwordHashService = passwordHashService; | ||
| } | ||
|
|
||
| @Override | ||
| public PassportEntity changePassport(int userId, String issueCountry, String issuer, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber) { | ||
| UsersEntity usersEntity = usersDao.get(userId); | ||
| PassportEntity passportEntity = passportDao.get(usersEntity.getPassId()); | ||
| if (usersEntity == null){ | ||
| throw new RuntimeException(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to write some kind of message |
||
| } | ||
| if (passportEntity == null){ | ||
| return createPassport(usersEntity, issueCountry, issuer, issueDate, expirationDate, serialNumber); | ||
| } | ||
| else { | ||
| return updatePassport(passportEntity, issueCountry, issuer, issueDate, expirationDate, serialNumber); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. long lines and too many empty lines |
||
|
|
||
| @Override | ||
| public DrivingLicenseEntity changeDrivingLicence(int userId, LocalDate issueDate, LocalDate expirationDate, | ||
| String serialNumber) { | ||
|
|
||
| UsersEntity usersEntity = usersDao.get(userId); | ||
| DrivingLicenseEntity drivingLicenseEntity = drivingLicenseDao.get(usersEntity.getDrivingLicenseId()); | ||
| if (usersEntity == null){ | ||
| throw new RuntimeException(); | ||
| } | ||
| if (drivingLicenseEntity == null){ | ||
| return createDrivingLicense(usersEntity, issueDate, expirationDate, serialNumber); | ||
| } | ||
| else { | ||
| return updateDrivingLicense(drivingLicenseEntity, issueDate, expirationDate, serialNumber); | ||
| } | ||
| //need method to validate data | ||
| //return drivingLicenceEntity | ||
| } | ||
|
|
||
| @Override | ||
| public UsersEntity changeUserData(int id, String email, SecureString password, String name, | ||
| String contactPhone, String address) { | ||
| UsersEntity usersEntity = usersDao.get(id); | ||
| validateUserData(email, password, name, contactPhone, address); | ||
| usersEntity.setEmail(email); | ||
| String passwordHash = passwordHashService.getHash(password); | ||
| usersEntity.setPasswordHash(passwordHash); | ||
| usersEntity.setName(name); | ||
| usersEntity.setContactPhone(contactPhone); | ||
| usersEntity.setAddress(address); | ||
| usersDao.update(usersEntity); | ||
| return usersEntity; | ||
| } | ||
|
|
||
| private PassportEntity createPassport(UsersEntity usersEntity, String issueCountry, String issuer, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber){ | ||
| validatePassport(issueCountry, issuer, issueDate, expirationDate, serialNumber); | ||
|
|
||
| PassportEntity passportEntity = new PassportEntity(0, issueCountry, issuer, issueDate, expirationDate, | ||
| serialNumber); | ||
| passportDao.save(passportEntity); | ||
| passportEntity = passportDao.getBySerialNumber(passportEntity.getSerialNumber()); | ||
| usersEntity.setPassId(passportEntity.getId()); | ||
| usersDao.update(usersEntity); | ||
| return passportEntity; | ||
| } | ||
| private PassportEntity updatePassport(PassportEntity passportEntity, String issueCountry, String issuer, | ||
| LocalDate issueDate, LocalDate expirationDate, String serialNumber){ | ||
| validatePassport(issueCountry, issuer, issueDate, expirationDate, serialNumber); | ||
| passportEntity.setIssueCountry(issueCountry); | ||
| passportEntity.setIssuer(issuer); | ||
| passportEntity.setIssueDate(issueDate); | ||
| passportEntity.setExpirationDate(expirationDate); | ||
| passportEntity.setSerialNumber(serialNumber); | ||
| passportDao.update(passportEntity); | ||
| return passportEntity; | ||
| } | ||
|
|
||
| private DrivingLicenseEntity createDrivingLicense(UsersEntity usersEntity, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber){ | ||
| validateDrivingLicense(issueDate, expirationDate, serialNumber); | ||
| DrivingLicenseEntity drivingLicenseEntity = new DrivingLicenseEntity(0, issueDate, expirationDate, | ||
| serialNumber); | ||
| drivingLicenseDao.save(drivingLicenseEntity); | ||
| drivingLicenseEntity = drivingLicenseDao.getBySerialNumber(drivingLicenseEntity.getSerialNumber()); | ||
| usersEntity.setDrivingLicenseId(drivingLicenseEntity.getId()); | ||
| usersDao.update(usersEntity); | ||
| return drivingLicenseEntity; | ||
| } | ||
|
|
||
| private DrivingLicenseEntity updateDrivingLicense (DrivingLicenseEntity drivingLicenseEntity, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber){ | ||
| validateDrivingLicense(issueDate, expirationDate, serialNumber); | ||
| drivingLicenseEntity.setIssueDate(issueDate); | ||
| drivingLicenseEntity.setExpirationDate(expirationDate); | ||
| drivingLicenseEntity.setSerialNumber(serialNumber); | ||
| drivingLicenseDao.update(drivingLicenseEntity); | ||
| return drivingLicenseEntity; | ||
| } | ||
|
|
||
|
|
||
| private static final String PHONE_REGEX = "[\\d\\s\\(\\)\\+]+"; | ||
|
|
||
| private void validateUserData(String email, SecureString password, String name, | ||
| String phone, String address) throws RuntimeException { | ||
| if (email == null || email.length() == 0) { | ||
| throw new RuntimeException("Email not specified."); | ||
| } | ||
| if (password == null) { | ||
| throw new RuntimeException("Password is not specified."); | ||
| } | ||
| if (name == null || name.length() == 0) { | ||
| throw new RuntimeException("Name is not specified."); | ||
| } | ||
| if (phone == null || phone.length() == 0) { | ||
| throw new RuntimeException("Phone number is not specified."); | ||
| } | ||
| if (!phone.matches(PHONE_REGEX)) { | ||
| throw new RuntimeException("Phone number may only contain digits, spaces, parentheses and '+' sign."); | ||
| } | ||
| if (address == null || address.length() == 0) { | ||
| throw new RuntimeException("Address is not specified."); | ||
| } | ||
| } | ||
| private void validatePassport (String issueCountry, String issuer, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber) throws RuntimeException { | ||
| if (issueCountry == null || issueCountry.length() == 0) { | ||
| throw new RuntimeException("IssueCountry not specified."); | ||
| } | ||
| if (issuer == null || issuer.length() == 0) { | ||
| throw new RuntimeException("Issuer is not specified."); | ||
| } | ||
| if (issueDate == null) { | ||
| throw new RuntimeException("IssueDate date is not specified."); | ||
| } | ||
| if (expirationDate == null) { | ||
| throw new RuntimeException("ExpirationDate date is not specified."); | ||
| } | ||
| if (serialNumber == null || serialNumber.length() == 0) { | ||
| throw new RuntimeException("SerialNumber number is not specified."); | ||
| } | ||
| } | ||
|
|
||
| private void validateDrivingLicense(LocalDate issueDate, LocalDate expirationDate, String serialNumber){ | ||
| if (issueDate == null) { | ||
| throw new RuntimeException("IssueDate date is not specified."); | ||
| } | ||
| if (expirationDate == null) { | ||
| throw new RuntimeException("ExpirationDate date is not specified."); | ||
| } | ||
| if (serialNumber == null || serialNumber.length() == 0) { | ||
| throw new RuntimeException("SerialNumber number is not specified."); | ||
| } | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/main/java/com/ifmo/epampractice/services/PersonalDataService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.ifmo.epampractice.services; | ||
|
|
||
| import com.ifmo.epampractice.entity.DrivingLicenseEntity; | ||
| import com.ifmo.epampractice.entity.PassportEntity; | ||
| import com.ifmo.epampractice.entity.UsersEntity; | ||
| import com.ifmo.epampractice.enums.UserRole; | ||
| import com.ifmo.epampractice.security.SecureString; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public interface PersonalDataService { | ||
| public PassportEntity changePassport (int userId, String issueCountry, String issuer, LocalDate issueDate, | ||
| LocalDate expirationDate, String serialNumber); | ||
| public DrivingLicenseEntity changeDrivingLicence (int userId, LocalDate issueDate, LocalDate expirationDate, | ||
| String serialNumber); | ||
| public UsersEntity changeUserData(int id, String email, SecureString password, String name, | ||
| String contactPhone, String address); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long line