diff --git a/BackOfficeSystem/pom.xml b/BackOfficeSystem/pom.xml index 89c7893..2994883 100644 --- a/BackOfficeSystem/pom.xml +++ b/BackOfficeSystem/pom.xml @@ -1,5 +1,5 @@ - 4.0.0 diff --git a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/RequestFilter.java b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/RequestFilter.java index 21d29e6..1f584a4 100644 --- a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/RequestFilter.java +++ b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/RequestFilter.java @@ -15,7 +15,7 @@ public class RequestFilter implements Filter { private static final String BACKOFFICE_URL = "http://localhost:4200"; // URL private static final String ONLINEBANKING_URL = "http://localhost:4201"; // OTHER URL - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) { + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) { HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; diff --git a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/SecurityConfig.java b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/SecurityConfig.java index 10e576f..f30502b 100644 --- a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/SecurityConfig.java +++ b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/config/SecurityConfig.java @@ -20,6 +20,8 @@ import org.springframework.security.web.util.matcher.OrRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; +import java.io.IOException; + @Configuration @EnableWebSecurity @@ -27,10 +29,17 @@ @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { + private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher( + new AntPathRequestMatcher("/accounts/**") + ); + AuthenticationProvider provider; @Autowired private UserSecurityService userSecurityService; - AuthenticationProvider provider; + public SecurityConfig(final AuthenticationProvider authenticationProvider) { + super(); + this.provider = authenticationProvider; + } @Bean public PasswordEncoder passwordEncoder() { @@ -47,22 +56,13 @@ public boolean matches(CharSequence charSequence, String s) { }; } - private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher( - new AntPathRequestMatcher("/accounts/**") - ); - - @Bean - AuthenticationFilter authenticationFilter() throws Exception { + AuthenticationFilter authenticationFilter() { final AuthenticationFilter filter = new AuthenticationFilter(PROTECTED_URLS); - filter.setAuthenticationManager(authenticationManager()); - return filter; - } - +// filter.setAuthenticationManager(authenticationManager()); + throw new StackOverflowError(); +// return filter; - public SecurityConfig(final AuthenticationProvider authenticationProvider) { - super(); - this.provider = authenticationProvider; } @Override diff --git a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/controller/AdminLoginController.java b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/controller/AdminLoginController.java index de0d39f..9b61ef3 100644 --- a/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/controller/AdminLoginController.java +++ b/BackOfficeSystem/src/main/java/com/banking/BackOfficeSystem/controller/AdminLoginController.java @@ -10,11 +10,10 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import sun.misc.BASE64Decoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; +import java.util.Base64; import java.util.UUID; @@ -26,20 +25,13 @@ public class AdminLoginController { AdminDao adminDao; @PostMapping("/secured/token") - public ResponseEntity generateToken(@RequestHeader("Authorization") String authString, HttpServletRequest rs, HttpServletResponse res) throws Exception { + public ResponseEntity generateToken(@RequestHeader("Authorization") String authString) throws Exception { System.out.println(authString); String decodedAuth = ""; String[] authParts = authString.split("\\s+"); String authInfo = authParts[1]; byte[] bytes = null; - try { - bytes = new BASE64Decoder().decodeBuffer(authInfo); - } catch (IOException e) { - e.printStackTrace(); - // TODO Auto-generated catch block - return new ResponseEntity<>("BAD REQUEST", new HttpHeaders(), HttpStatus.BAD_REQUEST); - - } + bytes = Base64.getDecoder().decode(authInfo); decodedAuth = new String(bytes); System.out.println(decodedAuth); diff --git a/BackOfficeSystem/src/main/resources/application.properties b/BackOfficeSystem/src/main/resources/application.properties index dab19e5..9ebc0d4 100644 --- a/BackOfficeSystem/src/main/resources/application.properties +++ b/BackOfficeSystem/src/main/resources/application.properties @@ -1,8 +1,8 @@ server.port=8080 spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/HdfcBank1 +spring.datasource.url=jdbc:postgresql://localhost:5432/hdfcbank1 spring.datasource.username=postgres -spring.datasource.password=root +spring.datasource.password=1234 #spring.datasource.schema = dev spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.show-sql=true diff --git a/BankData/.mvn/wrapper/MavenWrapperDownloader.java b/BankData/.mvn/wrapper/MavenWrapperDownloader.java index e76d1f3..a45eb6b 100644 --- a/BankData/.mvn/wrapper/MavenWrapperDownloader.java +++ b/BankData/.mvn/wrapper/MavenWrapperDownloader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import java.net.*; import java.io.*; import java.nio.channels.*; @@ -25,7 +26,7 @@ public class MavenWrapperDownloader { * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; /** * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to @@ -54,7 +55,7 @@ public static void main(String args[]) { // wrapperUrl parameter. File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { + if (mavenWrapperPropertyFile.exists()) { FileInputStream mavenWrapperPropertyFileInputStream = null; try { mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); @@ -65,7 +66,7 @@ public static void main(String args[]) { System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); } finally { try { - if(mavenWrapperPropertyFileInputStream != null) { + if (mavenWrapperPropertyFileInputStream != null) { mavenWrapperPropertyFileInputStream.close(); } } catch (IOException e) { @@ -76,8 +77,8 @@ public static void main(String args[]) { System.out.println("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } diff --git a/BankData/pom.xml b/BankData/pom.xml index 9b61b9f..3ec9793 100644 --- a/BankData/pom.xml +++ b/BankData/pom.xml @@ -1,117 +1,117 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - com.common - BankData - 0.0.1-SNAPSHOT - BankData - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - org.springframework.boot - spring-boot-starter-web - - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.batch - spring-batch-test - test - - - org.springframework.security - spring-security-test - test - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.postgresql - postgresql - runtime - - - - - org.apache.commons - commons-lang3 - 3.9 - - - - - com.fasterxml.uuid - java-uuid-generator - 4.0.1 - - - - - javax.servlet - servlet-api - 2.5 - provided - - - - javax.ws.rs - javax.ws.rs-api - 2.1.1 - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.6.RELEASE + + + com.common + BankData + 0.0.1-SNAPSHOT + BankData + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.batch + spring-batch-test + test + + + org.springframework.security + spring-security-test + test + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + + + + + org.apache.commons + commons-lang3 + 3.9 + + + + + com.fasterxml.uuid + java-uuid-generator + 4.0.1 + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/BankData/src/main/java/com/common/BankData/BankDataApplication.java b/BankData/src/main/java/com/common/BankData/BankDataApplication.java index 521c8cc..4dabd9d 100644 --- a/BankData/src/main/java/com/common/BankData/BankDataApplication.java +++ b/BankData/src/main/java/com/common/BankData/BankDataApplication.java @@ -12,8 +12,8 @@ @EnableTransactionManagement public class BankDataApplication { - public static void main(String[] args) { - SpringApplication.run(BankDataApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(BankDataApplication.class, args); + } } diff --git a/BankData/src/main/java/com/common/BankData/dao/AccountDao.java b/BankData/src/main/java/com/common/BankData/dao/AccountDao.java index 6d597e6..8bfdaa8 100644 --- a/BankData/src/main/java/com/common/BankData/dao/AccountDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/AccountDao.java @@ -3,7 +3,6 @@ import com.common.BankData.entity.Account; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -11,13 +10,10 @@ @Repository @Transactional -public interface AccountDao extends JpaRepository { +public interface AccountDao extends JpaRepository { List findByAccountStatus(Integer status); Account findByAccountId(long number); - - - } diff --git a/BankData/src/main/java/com/common/BankData/dao/AdminDao.java b/BankData/src/main/java/com/common/BankData/dao/AdminDao.java index fad3433..bae2b05 100644 --- a/BankData/src/main/java/com/common/BankData/dao/AdminDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/AdminDao.java @@ -3,11 +3,11 @@ import com.common.BankData.entity.Admin; import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @Repository -public interface AdminDao extends CrudRepository { +public interface AdminDao extends CrudRepository { Admin findByUserName(String username); + Admin findByToken(String token); } diff --git a/BankData/src/main/java/com/common/BankData/dao/CustomerDao.java b/BankData/src/main/java/com/common/BankData/dao/CustomerDao.java index 0c10fff..24d561d 100644 --- a/BankData/src/main/java/com/common/BankData/dao/CustomerDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/CustomerDao.java @@ -9,10 +9,12 @@ @Service public interface CustomerDao extends JpaRepository { Customer findByUserNameContainingIgnoreCase(String username); + Customer findByUserId(long userId); + Customer findByToken(String token); - @Query(value = "SELECT nextval('username')", nativeQuery = + @Query(value = "SELECT nextval('hibernate_sequence')", nativeQuery = true) Long getNextCustomerId(); diff --git a/BankData/src/main/java/com/common/BankData/dao/OtherBankAccountDao.java b/BankData/src/main/java/com/common/BankData/dao/OtherBankAccountDao.java index ee8620f..5c89446 100644 --- a/BankData/src/main/java/com/common/BankData/dao/OtherBankAccountDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/OtherBankAccountDao.java @@ -3,5 +3,5 @@ import com.common.BankData.entity.OtherAccount; import org.springframework.data.jpa.repository.JpaRepository; -public interface OtherBankAccountDao extends JpaRepository { +public interface OtherBankAccountDao extends JpaRepository { } diff --git a/BankData/src/main/java/com/common/BankData/dao/ScheduleDao.java b/BankData/src/main/java/com/common/BankData/dao/ScheduleDao.java index 52b8ddc..b96c23c 100644 --- a/BankData/src/main/java/com/common/BankData/dao/ScheduleDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/ScheduleDao.java @@ -4,13 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @Repository @Transactional -public interface ScheduleDao extends JpaRepository { +public interface ScheduleDao extends JpaRepository { // @Modifying @@ -18,11 +17,11 @@ public interface ScheduleDao extends JpaRepository { // @Query(value="delete from schedule c where c.scheduleid = ?1") // void deleteBySchedule_id(int schedule_id); -// @Modifying + // @Modifying // @Transactional @Modifying @Transactional - @Query(value="delete from schedule c where c.scheduleid = ?1") + @Query(value = "delete from schedule c where c.scheduleid = ?1") int removeByScheduleid(int scheduledid); // @Override diff --git a/BankData/src/main/java/com/common/BankData/dao/TransferDao.java b/BankData/src/main/java/com/common/BankData/dao/TransferDao.java index 5c2447f..53a6515 100644 --- a/BankData/src/main/java/com/common/BankData/dao/TransferDao.java +++ b/BankData/src/main/java/com/common/BankData/dao/TransferDao.java @@ -8,8 +8,9 @@ @Repository public interface TransferDao extends JpaRepository { - // List findByAccountId(long accountId); + // List findByAccountId(long accountId); Set findByAccountId(long accountId); + Set findByRecipientAccountNo(long accountId); // List findByRecipientAccountNo(long accountId); } diff --git a/BankData/src/main/java/com/common/BankData/entity/Account.java b/BankData/src/main/java/com/common/BankData/entity/Account.java index d98338a..36af236 100644 --- a/BankData/src/main/java/com/common/BankData/entity/Account.java +++ b/BankData/src/main/java/com/common/BankData/entity/Account.java @@ -1,19 +1,13 @@ package com.common.BankData.entity; import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; import com.sun.istack.Nullable; import org.hibernate.annotations.ColumnDefault; -import org.hibernate.annotations.Generated; -import org.hibernate.annotations.GenerationTime; import javax.persistence.*; -import javax.validation.constraints.Null; import javax.ws.rs.DefaultValue; import java.sql.Date; -import java.util.List; @Entity //@JsonIgnoreProperties(ignoreUnknown = true) @@ -39,8 +33,8 @@ // private double balance=0.0f; @ColumnDefault("0.0") - @Column(name="balance") - private double balance=0.0f; + @Column(name = "balance") + private double balance = 0.0f; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") private Date date; @@ -49,8 +43,8 @@ @DefaultValue("0") private int accountStatus; - @OneToOne(cascade=CascadeType.ALL) - @JoinColumn(name="proofid") + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "proofid") @JsonManagedReference private Proof proof; @@ -60,6 +54,27 @@ @ManyToOne private Customer customer; + @Nullable + private long accountId; + private String remarks; + + public Account(long id, String bankIfsc, String firstName, String lastName, double balance, Date date, int accountStatus, Proof proof, Customer customer, long accountId, String remarks) { + this.id = id; + this.bankIfsc = bankIfsc; + this.firstName = firstName; + this.lastName = lastName; + this.balance = balance; + this.date = date; + this.accountStatus = accountStatus; + this.proof = proof; + this.customer = customer; + this.accountId = accountId; + this.remarks = remarks; + } + + + public Account() { + } public Customer getCustomer() { return customer; @@ -69,14 +84,6 @@ public void setCustomer(Customer customer) { this.customer = customer; } - @Nullable - private long accountId; - - - - - private String remarks; - public long getPhoneNo() { return phoneNo; } @@ -102,16 +109,6 @@ public void setAccountId(long accountId) { } - public String getBankIfsc() { - return bankIfsc; - } - - public void setBankIfsc(String bankIfsc) { - this.bankIfsc = bankIfsc; - } - - - // public List getPrimaryTransactionList() { // return primaryTransactionList; // } @@ -120,6 +117,14 @@ public void setBankIfsc(String bankIfsc) { // this.primaryTransactionList = primaryTransactionList; // } + public String getBankIfsc() { + return bankIfsc; + } + + public void setBankIfsc(String bankIfsc) { + this.bankIfsc = bankIfsc; + } + public double getBalance() { return balance; } @@ -160,7 +165,6 @@ public void setLastName(String lastName) { this.lastName = lastName; } - public Date getDate() { return date; } @@ -169,33 +173,16 @@ public void setDate(Date date) { this.date = date; } - public String getRemarks() { - return remarks; - } - - public void setRemarks(String remarks) { - this.remarks = remarks; - } - // public void setAge(int age) { // this.age = age; // } - public Account(long id, String bankIfsc, String firstName, String lastName, double balance, Date date, int accountStatus, Proof proof, Customer customer, long accountId, String remarks) { - this.id = id; - this.bankIfsc = bankIfsc; - this.firstName = firstName; - this.lastName = lastName; - this.balance = balance; - this.date = date; - this.accountStatus = accountStatus; - this.proof = proof; - this.customer = customer; - this.accountId = accountId; - this.remarks = remarks; + public String getRemarks() { + return remarks; } - public Account() { + public void setRemarks(String remarks) { + this.remarks = remarks; } } diff --git a/BankData/src/main/java/com/common/BankData/entity/Admin.java b/BankData/src/main/java/com/common/BankData/entity/Admin.java index 0a21e26..87a503c 100644 --- a/BankData/src/main/java/com/common/BankData/entity/Admin.java +++ b/BankData/src/main/java/com/common/BankData/entity/Admin.java @@ -1,51 +1,42 @@ package com.common.BankData.entity; - - import com.common.BankData.entity.security.Role; -import com.fasterxml.jackson.annotation.JsonIgnore; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; import javax.persistence.*; -import javax.persistence.GeneratedValue; import java.util.List; @Entity -public class Admin{ +public class Admin { + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinTable(name = "adminRole", joinColumns = @JoinColumn(name = "adminid"), inverseJoinColumns = @JoinColumn(name = "roleid")) + public List adminRole; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long adminId; - - @Column(name="adminName") + @Column(name = "adminName") private String adminName; - private String userName; - - public Admin() { - - } - - @OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER) - @JoinTable(name = "adminRole", joinColumns = @JoinColumn(name = "adminid"), inverseJoinColumns = @JoinColumn(name = "roleid")) - public List adminRole; - -// @OneToMany(mappedBy = "admin", cascade=CascadeType.ALL,fetch = FetchType.EAGER) + private String userName; + // @OneToMany(mappedBy = "admin", cascade=CascadeType.ALL,fetch = FetchType.EAGER) // @JsonIgnore // public List adminRole; private String passwordHash; private String bankIFSC; -private String token; + private String token; + public Admin() { + + } + public Admin(Admin o) { - this.adminId=o.adminId; - this.adminName=o.adminName; - this.adminRole=o.adminRole; - this.userName=o.userName; - this.bankIFSC=o.bankIFSC; - this.passwordHash=o.passwordHash; - this.token=o.token; + this.adminId = o.adminId; + this.adminName = o.adminName; + this.adminRole = o.adminRole; + this.userName = o.userName; + this.bankIFSC = o.bankIFSC; + this.passwordHash = o.passwordHash; + this.token = o.token; } @@ -69,6 +60,10 @@ public String getAdminName() { return adminName; } + public void setAdminName(String adminName) { + this.adminName = adminName; + } + public List getAdminRole() { return adminRole; } @@ -77,10 +72,6 @@ public void setAdminRole(List adminRole) { this.adminRole = adminRole; } - public void setAdminName(String adminName) { - this.adminName = adminName; - } - public String getUserName() { return userName; } @@ -122,5 +113,4 @@ public void setBankIFSC(String bankIFSC) { // } - } diff --git a/BankData/src/main/java/com/common/BankData/entity/CustomAdminDetails.java b/BankData/src/main/java/com/common/BankData/entity/CustomAdminDetails.java index 5aeefdc..ff66787 100644 --- a/BankData/src/main/java/com/common/BankData/entity/CustomAdminDetails.java +++ b/BankData/src/main/java/com/common/BankData/entity/CustomAdminDetails.java @@ -6,14 +6,11 @@ import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; import java.util.stream.Collectors; public class CustomAdminDetails extends Admin implements UserDetails { - public CustomAdminDetails(final Admin admins) - { + public CustomAdminDetails(final Admin admins) { super(admins); } @@ -22,44 +19,44 @@ public Collection getAuthorities() { System.out.println("getAuthorities"); -return getAdminRole() - .stream() - .map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName())) - .collect(Collectors.toList()); + return getAdminRole() + .stream() + .map(role -> new SimpleGrantedAuthority("ROLE_" + role.getRoleName())) + .collect(Collectors.toList()); // Set authorities = new HashSet<>(); // adminRole.forEach(ur -> authorities.add(new SimpleGrantedAuthority("ROLE_"+ur.getRoleName()))); // return authorities; // return null; -} + } -@Override -public String getPassword() { -return getPasswordHash(); -} + @Override + public String getPassword() { + return getPasswordHash(); + } -@Override -public String getUsername() { -return getUserName(); -} + @Override + public String getUsername() { + return getUserName(); + } -@Override -public boolean isAccountNonExpired() { -return true; -} + @Override + public boolean isAccountNonExpired() { + return true; + } -@Override -public boolean isAccountNonLocked() { -return true; -} + @Override + public boolean isAccountNonLocked() { + return true; + } -@Override -public boolean isCredentialsNonExpired() { -return true; -} + @Override + public boolean isCredentialsNonExpired() { + return true; + } -@Override -public boolean isEnabled() { -return true; -} + @Override + public boolean isEnabled() { + return true; + } } diff --git a/BankData/src/main/java/com/common/BankData/entity/CustomCustomerDetails.java b/BankData/src/main/java/com/common/BankData/entity/CustomCustomerDetails.java index 8a939fa..1778430 100644 --- a/BankData/src/main/java/com/common/BankData/entity/CustomCustomerDetails.java +++ b/BankData/src/main/java/com/common/BankData/entity/CustomCustomerDetails.java @@ -2,16 +2,13 @@ import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; -import java.util.stream.Collectors; public class CustomCustomerDetails extends Customer implements UserDetails { - public CustomCustomerDetails(final Customer customers) - { + public CustomCustomerDetails(final Customer customers) { super(customers); } @@ -30,35 +27,35 @@ public Collection getAuthorities() { // return authorities; // return null; return null; -} + } -@Override -public String getPassword() { -return getPassword(); -} + @Override + public String getPassword() { + return getPassword(); + } -@Override -public String getUsername() { -return getUserName(); -} + @Override + public String getUsername() { + return getUserName(); + } -@Override -public boolean isAccountNonExpired() { -return true; -} + @Override + public boolean isAccountNonExpired() { + return true; + } -@Override -public boolean isAccountNonLocked() { -return true; -} + @Override + public boolean isAccountNonLocked() { + return true; + } -@Override -public boolean isCredentialsNonExpired() { -return true; -} + @Override + public boolean isCredentialsNonExpired() { + return true; + } -@Override -public boolean isEnabled() { -return true; -} + @Override + public boolean isEnabled() { + return true; + } } diff --git a/BankData/src/main/java/com/common/BankData/entity/Customer.java b/BankData/src/main/java/com/common/BankData/entity/Customer.java index 0301064..4de7664 100644 --- a/BankData/src/main/java/com/common/BankData/entity/Customer.java +++ b/BankData/src/main/java/com/common/BankData/entity/Customer.java @@ -3,18 +3,17 @@ import org.hibernate.annotations.ColumnDefault; import javax.persistence.*; -import java.security.AccessControlContext; import java.util.Set; @Entity public class Customer { @Id - @GeneratedValue(strategy = GenerationType.AUTO ) + @GeneratedValue(strategy = GenerationType.AUTO) private long customerId; private String customerName; -// private long accountId; - private String userName; + // private long accountId; + private String userName; private String password; @ColumnDefault("0") @@ -27,14 +26,13 @@ public class Customer { private String token; public Customer(final Customer o) { - this.customerId=o.customerId; - this.customerName=o.customerName; - this.userName=o.userName; - this.password=o.password; - this.token=o.token; - // this.accountId=o.accountId; - this.accounts=o.accounts; - + this.customerId = o.customerId; + this.customerName = o.customerName; + this.userName = o.userName; + this.password = o.password; + this.token = o.token; + // this.accountId=o.accountId; + this.accounts = o.accounts; } @@ -43,7 +41,7 @@ public Customer(final Customer o) { public Customer() { } - public Customer(long customerId, String customerName, String userName, String password, Set accounts, String token,long userId) { + public Customer(long customerId, String customerName, String userName, String password, Set accounts, String token, long userId) { this.customerId = customerId; this.customerName = customerName; this.userName = userName; @@ -52,14 +50,15 @@ public Customer(long customerId, String customerName, String userName, String pa this.token = token; this.userId = userId; } + //this constructor is used to create a new Customer, when the account of that particular user is approved - public Customer(String customerName, String userName, String password, Set accounts, String token,long userId) { + public Customer(String customerName, String userName, String password, Set accounts, String token, long userId) { this.customerName = customerName; this.userName = userName; this.password = password; this.accounts = accounts; this.token = token; - this.userId=userId; + this.userId = userId; } public long getUserId() { diff --git a/BankData/src/main/java/com/common/BankData/entity/OtherAccount.java b/BankData/src/main/java/com/common/BankData/entity/OtherAccount.java index a97c689..ec4739b 100644 --- a/BankData/src/main/java/com/common/BankData/entity/OtherAccount.java +++ b/BankData/src/main/java/com/common/BankData/entity/OtherAccount.java @@ -1,7 +1,6 @@ package com.common.BankData.entity; import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonManagedReference; import com.sun.istack.Nullable; import javax.persistence.*; @@ -23,8 +22,8 @@ public class OtherAccount { // private int age=0; //@DefaultValue("0.0") - @Column(name="balance") - private double balance=0.0f; + @Column(name = "balance") + private double balance = 0.0f; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") private Date date; @@ -40,6 +39,15 @@ public class OtherAccount { @ManyToOne private Customer customer; + @Nullable + private long accountId; + private String remarks; + + public OtherAccount(double balance, Date date, long accountId) { + this.balance = balance; + this.date = date; + this.accountId = accountId; + } public Customer getCustomer() { return customer; @@ -49,11 +57,6 @@ public void setCustomer(Customer customer) { this.customer = customer; } - @Nullable - private long accountId; - - private String remarks; - public long getId() { return id; } @@ -70,7 +73,6 @@ public void setAccountId(long accountId) { this.accountId = accountId; } - public String getBankIfsc() { return bankIfsc; } @@ -79,12 +81,6 @@ public void setBankIfsc(String bankIfsc) { this.bankIfsc = bankIfsc; } - public OtherAccount(double balance, Date date, long accountId) { - this.balance = balance; - this.date = date; - this.accountId = accountId; - } - // public List getPrimaryTransactionList() { // return primaryTransactionList; // } diff --git a/BankData/src/main/java/com/common/BankData/entity/PrimaryTransaction.java b/BankData/src/main/java/com/common/BankData/entity/PrimaryTransaction.java index aacb934..c28c723 100644 --- a/BankData/src/main/java/com/common/BankData/entity/PrimaryTransaction.java +++ b/BankData/src/main/java/com/common/BankData/entity/PrimaryTransaction.java @@ -8,132 +8,120 @@ @Entity public class PrimaryTransaction { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private Date date; - - @Column(name = "local_date_time", columnDefinition = "TIMESTAMP") - private LocalDateTime localDateTime; - - public void setId(long id) { - this.id = id; - } - - public LocalDateTime getLocalDateTime() { - return localDateTime; - } - - public void setLocalDateTime(LocalDateTime localDateTime) { - this.localDateTime = localDateTime; - } - - private String description; - - private String type; - private String status; - private double amount; - @Transient - private BigDecimal availableBalance; - - private String recipientName; - private long recipientAccountNo; - @Transient - private long phoneNo; - - - - - - - private long accountId; - - - public long getRecipientAccountNo() { - return recipientAccountNo; - } - - public void setRecipientAccountNo(long recipientAccountNo) { - this.recipientAccountNo = recipientAccountNo; - } + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private Date date; + + @Column(name = "local_date_time", columnDefinition = "TIMESTAMP") + private LocalDateTime localDateTime; + private String description; + private String type; + private String status; + private double amount; + @Transient + private BigDecimal availableBalance; + private String recipientName; + private long recipientAccountNo; + @Transient + private long phoneNo; + private long accountId; + public PrimaryTransaction() { + + } + public PrimaryTransaction(Date date, String description, String status, double amount, String recipientName, long recipientAccountNo, long accountId, LocalDateTime localDateTime, String type) { + this.date = date; + this.description = description; + this.status = status; + this.amount = amount; + this.recipientName = recipientName; + this.recipientAccountNo = recipientAccountNo; + this.accountId = accountId; + this.localDateTime = localDateTime; + this.type = type; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public long getRecipientAccountNo() { + return recipientAccountNo; + } // @ManyToOne // @JoinColumn(name = "primary_account_id") // @Transient // private Account primaryAccount; - public PrimaryTransaction() { - - } + public void setRecipientAccountNo(long recipientAccountNo) { + this.recipientAccountNo = recipientAccountNo; + } - public PrimaryTransaction(Date date, String description, String status, double amount, String recipientName, long recipientAccountNo, long accountId, LocalDateTime localDateTime, String type) { - this.date = date; - this.description = description; - this.status = status; - this.amount = amount; - this.recipientName = recipientName; - this.recipientAccountNo = recipientAccountNo; - this.accountId = accountId; - this.localDateTime=localDateTime; - this.type=type; - } + public Long getId() { + return id; + } - public Long getId() { - return id; - } + public void setId(long id) { + this.id = id; + } - public void setId(Long id) { - this.id = id; - } + public void setId(Long id) { + this.id = id; + } - public Date getDate() { - return date; - } + public Date getDate() { + return date; + } - public void setDate(Date date) { - this.date = date; - } + public void setDate(Date date) { + this.date = date; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } - public String getStatus() { - return status; - } + public String getStatus() { + return status; + } - public void setStatus(String status) { - this.status = status; - } + public void setStatus(String status) { + this.status = status; + } - public double getAmount() { - return amount; - } + public double getAmount() { + return amount; + } - public void setAmount(double amount) { - this.amount = amount; - } + public void setAmount(double amount) { + this.amount = amount; + } - public BigDecimal getAvailableBalance() { - return availableBalance; - } + public BigDecimal getAvailableBalance() { + return availableBalance; + } - public void setAvailableBalance(BigDecimal availableBalance) { - this.availableBalance = availableBalance; - } + public void setAvailableBalance(BigDecimal availableBalance) { + this.availableBalance = availableBalance; + } // public Account getPrimaryAccount() { // return primaryAccount; @@ -143,28 +131,28 @@ public void setAvailableBalance(BigDecimal availableBalance) { // this.primaryAccount = primaryAccount; // } - public String getRecipientName() { - return recipientName; - } + public String getRecipientName() { + return recipientName; + } - public void setRecipientName(String recipientName) { - this.recipientName = recipientName; - } + public void setRecipientName(String recipientName) { + this.recipientName = recipientName; + } - public long getPhoneNo() { - return phoneNo; - } + public long getPhoneNo() { + return phoneNo; + } - public void setPhoneNo(long phoneNo) { - this.phoneNo = phoneNo; - } + public void setPhoneNo(long phoneNo) { + this.phoneNo = phoneNo; + } - public long getAccountId() { - return accountId; - } + public long getAccountId() { + return accountId; + } - public void setAccountId(long accountId) { - this.accountId = accountId; - } + public void setAccountId(long accountId) { + this.accountId = accountId; + } } diff --git a/BankData/src/main/java/com/common/BankData/entity/Proof.java b/BankData/src/main/java/com/common/BankData/entity/Proof.java index 1198d50..9b5383d 100644 --- a/BankData/src/main/java/com/common/BankData/entity/Proof.java +++ b/BankData/src/main/java/com/common/BankData/entity/Proof.java @@ -1,9 +1,6 @@ package com.common.BankData.entity; import com.fasterxml.jackson.annotation.JsonBackReference; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import net.bytebuddy.dynamic.loading.InjectionClassLoader; import javax.persistence.*; import java.sql.Date; @@ -11,8 +8,7 @@ @Entity //@JsonIgnoreProperties(ignoreUnknown = true) -public class Proof -{ +public class Proof { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -26,6 +22,7 @@ public class Proof @OneToOne(mappedBy = "proof") @JsonBackReference private Account acc; + private int age; public Account getAcc() { return acc; @@ -35,8 +32,6 @@ public void setAcc(Account acc) { this.acc = acc; } - private int age; - public int getProofId() { return proofId; } diff --git a/BankData/src/main/java/com/common/BankData/entity/Schedule.java b/BankData/src/main/java/com/common/BankData/entity/Schedule.java index 27a2484..3a1dc55 100644 --- a/BankData/src/main/java/com/common/BankData/entity/Schedule.java +++ b/BankData/src/main/java/com/common/BankData/entity/Schedule.java @@ -1,13 +1,10 @@ package com.common.BankData.entity; -import com.sun.istack.Nullable; - import javax.persistence.*; -import java.time.*; import java.util.Date; -@Entity(name="schedule") +@Entity(name = "schedule") public class Schedule { @Id @@ -16,10 +13,27 @@ public class Schedule { private Date dates; private long recipientAccountNo; private String status; - private String recipientName; + private String recipientName; private double amount; private String schedule_type; + private String type; + @Column(nullable = true) + private long accountId; + + public Schedule() { + } + + public Schedule(int scheduleid, Date dates, long recipientAccountNo, String status, String recipientName, double amount, String type, long accountId) { + this.scheduleid = scheduleid; + this.dates = dates; + this.recipientAccountNo = recipientAccountNo; + this.status = status; + this.recipientName = recipientName; + this.amount = amount; + this.type = type; + this.accountId = accountId; + } public String getSchedule_type() { return schedule_type; @@ -29,11 +43,6 @@ public void setSchedule_type(String schedule_type) { this.schedule_type = schedule_type; } - private String type; - - public Schedule() { - } - public String getType() { return type; } @@ -41,8 +50,6 @@ public String getType() { public void setType(String type) { this.type = type; } - @Column(nullable = true) - private long accountId; public long getAccountId() { return accountId; @@ -52,17 +59,6 @@ public void setAccountId(long accountId) { this.accountId = accountId; } - public Schedule(int scheduleid, Date dates, long recipientAccountNo, String status, String recipientName, double amount, String type, long accountId) { - this.scheduleid = scheduleid; - this.dates = dates; - this.recipientAccountNo = recipientAccountNo; - this.status = status; - this.recipientName = recipientName; - this.amount = amount; - this.type = type; - this.accountId = accountId; - } - public Date getDates() { return dates; } diff --git a/BankData/src/main/java/com/common/BankData/entity/ScheduleList.java b/BankData/src/main/java/com/common/BankData/entity/ScheduleList.java index c4d71a0..50f5590 100644 --- a/BankData/src/main/java/com/common/BankData/entity/ScheduleList.java +++ b/BankData/src/main/java/com/common/BankData/entity/ScheduleList.java @@ -1,21 +1,16 @@ package com.common.BankData.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToMany; import java.util.List; -import java.util.Set; //@Entity public class ScheduleList { - // @Id + // @Column(name = "schedule") +// @OneToMany + List schedule; + // @Id private int id; - - - public int getId() { return id; } @@ -24,10 +19,6 @@ public void setId(int id) { this.id = id; } -// @Column(name = "schedule") -// @OneToMany - List schedule; - public List getSchedule() { return schedule; } diff --git a/BankData/src/main/java/com/common/BankData/entity/security/AdminRole.java b/BankData/src/main/java/com/common/BankData/entity/security/AdminRole.java index 50613b0..47a9f39 100644 --- a/BankData/src/main/java/com/common/BankData/entity/security/AdminRole.java +++ b/BankData/src/main/java/com/common/BankData/entity/security/AdminRole.java @@ -1,9 +1,6 @@ package com.common.BankData.entity.security; - -import javax.persistence.*; - // ////@Entity ////@Table diff --git a/BankData/src/main/java/com/common/BankData/entity/security/Role.java b/BankData/src/main/java/com/common/BankData/entity/security/Role.java index dcce1a2..e53a8d8 100644 --- a/BankData/src/main/java/com/common/BankData/entity/security/Role.java +++ b/BankData/src/main/java/com/common/BankData/entity/security/Role.java @@ -1,8 +1,9 @@ package com.common.BankData.entity.security; -import javax.persistence.*; -import java.util.HashSet; -import java.util.Set; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; @Entity public class Role { diff --git a/BankData/src/main/java/com/common/BankData/service/AdminService.java b/BankData/src/main/java/com/common/BankData/service/AdminService.java index 5bcbb1a..4d9af2a 100644 --- a/BankData/src/main/java/com/common/BankData/service/AdminService.java +++ b/BankData/src/main/java/com/common/BankData/service/AdminService.java @@ -12,7 +12,7 @@ public class AdminService { AdminDao adminDao; public Admin findByToken(String token) { - Admin admin= adminDao.findByToken(token); + Admin admin = adminDao.findByToken(token); return admin; } } diff --git a/BankData/src/main/java/com/common/BankData/service/AuthenticationProvider.java b/BankData/src/main/java/com/common/BankData/service/AuthenticationProvider.java index 15cac40..28540d4 100644 --- a/BankData/src/main/java/com/common/BankData/service/AuthenticationProvider.java +++ b/BankData/src/main/java/com/common/BankData/service/AuthenticationProvider.java @@ -1,7 +1,6 @@ package com.common.BankData.service; - import com.common.BankData.dao.CustomerDao; import com.common.BankData.entity.CustomCustomerDetails; import com.common.BankData.entity.Customer; @@ -27,10 +26,9 @@ protected void additionalAuthenticationChecks(UserDetails userDetails, UsernameP @Override protected UserDetails retrieveUser(String userName, UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken) { Object token = usernamePasswordAuthenticationToken.getCredentials(); - Customer ud= customerDao.findByToken(token.toString()); - if(ud==null) - { - throw new UsernameNotFoundException("Cannot find user with authentication token=" + token); + Customer ud = customerDao.findByToken(token.toString()); + if (ud == null) { + throw new UsernameNotFoundException("Cannot find user with authentication token=" + token); } return new CustomCustomerDetails(ud); } diff --git a/BankData/src/main/java/com/common/BankData/service/SmsService.java b/BankData/src/main/java/com/common/BankData/service/SmsService.java index de21699..1417730 100644 --- a/BankData/src/main/java/com/common/BankData/service/SmsService.java +++ b/BankData/src/main/java/com/common/BankData/service/SmsService.java @@ -1,53 +1,47 @@ package com.common.BankData.service; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import javax.net.ssl.HttpsURLConnection; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; -import java.net.URLEncoder; import java.util.Random; @Component public class SmsService { - public static void sendSms(long username,String number,String password) - { - try - { + public static void sendSms(long username, String number, String password) { + try { - String apiKey="Your API Key here"; - String sendId="FSTSMS"; + String apiKey = "5cWbOSFdP2G2nSXaz4aK6dFCey2AUP3rRsLoAChwRBh1Gddi9vUJK7N56SIN"; + String sendId = "FSTSMS"; - String language="english"; - String route="qt"; + String language = "english"; + String route = "qt"; - String myUrl="https://www.fast2sms.com/dev/bulk?authorization="+apiKey+"&sender_id="+sendId+"&language="+language+"&route="+route+"&numbers="+number+"&message="+27480+"&variables={AA}|{BB}&variables_values="+username+ '|'+password; - //sending get request using java.. + String myUrl = "https://www.fast2sms.com/dev/bulk?authorization=" + apiKey + "&sender_id=" + sendId + "&language=" + language + "&route=" + route + "&numbers=" + number + "&message=" + 27480 + "&variables={AA}|{BB}&variables_values=" + username + '|' + password; + //sending get request using java.. - URL url=new URL(myUrl); - HttpsURLConnection con=(HttpsURLConnection)url.openConnection(); + URL url = new URL(myUrl); + HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty("cache-control", "no-cache"); System.out.println("Wait.............."); - int code=con.getResponseCode(); + int code = con.getResponseCode(); - System.out.println("Response code : "+code); + System.out.println("Response code : " + code); - StringBuffer response=new StringBuffer(); + StringBuffer response = new StringBuffer(); - BufferedReader br=new BufferedReader(new InputStreamReader(con.getInputStream())); + BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); - while(true) - { - String line=br.readLine(); - if(line==null) - { + while (true) { + String line = br.readLine(); + if (line == null) { break; } response.append(line); @@ -56,7 +50,7 @@ public static void sendSms(long username,String number,String password) System.out.println(response); - }catch (Exception e) { + } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } @@ -77,7 +71,7 @@ public static char[] generatePassword(int length) { password[2] = specialCharacters.charAt(random.nextInt(specialCharacters.length())); password[3] = numbers.charAt(random.nextInt(numbers.length())); - for(int i = 4; i< length ; i++) { + for (int i = 4; i < length; i++) { password[i] = combinedChars.charAt(random.nextInt(combinedChars.length())); } return password; diff --git a/BankData/src/main/java/com/common/BankData/service/TransferService.java b/BankData/src/main/java/com/common/BankData/service/TransferService.java index 87a8245..07a99c2 100644 --- a/BankData/src/main/java/com/common/BankData/service/TransferService.java +++ b/BankData/src/main/java/com/common/BankData/service/TransferService.java @@ -12,11 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.ObjectUtils; - -import javax.persistence.PersistenceUnit; -import javax.transaction.TransactionScoped; import java.time.Clock; import java.time.Instant; import java.time.LocalDateTime; @@ -37,9 +33,6 @@ public class TransferService { ScheduleDao scheduleDao; - - - @Transactional public Boolean addMoneyToRecipient(Account recipientAccount, Account primaryAccount, double amount, PrimaryTransaction transaction) throws Exception { @@ -58,10 +51,10 @@ public Boolean addMoneyToRecipient(Account recipientAccount, Account primaryAcco Date d = new Date(); Instant instant = Instant.now(); - LocalDateTime ld=LocalDateTime.now(Clock.systemUTC()); + LocalDateTime ld = LocalDateTime.now(Clock.systemUTC()); PrimaryTransaction pt = new PrimaryTransaction(d, transaction.getDescription(), "completed", transaction.getAmount(), - transaction.getRecipientName(), transaction.getRecipientAccountNo(), transaction.getAccountId(),ld,transaction.getType()); + transaction.getRecipientName(), transaction.getRecipientAccountNo(), transaction.getAccountId(), ld, transaction.getType()); transferDao.save(pt); return true; @@ -73,7 +66,7 @@ public Boolean addMoneyToRecipient(Account recipientAccount, Account primaryAcco return false; } - @Transactional + @Transactional public Boolean addMoneyToRecipientOfAnotherBank(OtherAccount recipientAccount, Account primaryAccount, double amount, PrimaryTransaction transaction) throws Exception { @@ -91,10 +84,10 @@ public Boolean addMoneyToRecipientOfAnotherBank(OtherAccount recipientAccount, A Date d = new Date(); Instant instant = Instant.now(); - LocalDateTime ld=LocalDateTime.now(Clock.systemUTC()); + LocalDateTime ld = LocalDateTime.now(Clock.systemUTC()); PrimaryTransaction pt = new PrimaryTransaction(d, transaction.getDescription(), "completed", transaction.getAmount(), - transaction.getRecipientName(), transaction.getRecipientAccountNo(), transaction.getAccountId(),ld,transaction.getType()); + transaction.getRecipientName(), transaction.getRecipientAccountNo(), transaction.getAccountId(), ld, transaction.getType()); transferDao.save(pt); return true; @@ -107,11 +100,11 @@ public Boolean addMoneyToRecipientOfAnotherBank(OtherAccount recipientAccount, A } public Set getTransactionHistoryByAccountID(long accountId) { - List transactionList=new ArrayList<>(); - Set trans=new HashSet<>(); - Set trans1=new HashSet<>(); - trans=transferDao.findByAccountId(accountId); - trans1=transferDao.findByRecipientAccountNo(accountId); + List transactionList = new ArrayList<>(); + Set trans = new HashSet<>(); + Set trans1 = new HashSet<>(); + trans = transferDao.findByAccountId(accountId); + trans1 = transferDao.findByRecipientAccountNo(accountId); trans.addAll(trans1); // transactionList=transferDao.findByAccountId(accountId); @@ -133,12 +126,11 @@ public Set getTransactionHistoryByAccountID(long accountId) return trans; - } public void deleteASchedule(Schedule sd) { - int a=scheduleDao.removeByScheduleid(sd.getScheduleid()); + int a = scheduleDao.removeByScheduleid(sd.getScheduleid()); } } diff --git a/BankData/src/main/java/com/common/BankData/service/UserSecurityService.java b/BankData/src/main/java/com/common/BankData/service/UserSecurityService.java index e8d5aa0..01825dc 100644 --- a/BankData/src/main/java/com/common/BankData/service/UserSecurityService.java +++ b/BankData/src/main/java/com/common/BankData/service/UserSecurityService.java @@ -15,19 +15,21 @@ @Service public class UserSecurityService implements UserDetailsService { - /** The application logger */ - private static final Logger LOG = LoggerFactory.getLogger(UserSecurityService.class); + /** + * The application logger + */ + private static final Logger LOG = LoggerFactory.getLogger(UserSecurityService.class); - @Autowired - private CustomerDao customerDao; + @Autowired + private CustomerDao customerDao; - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - Customer user = customerDao.findByUserNameContainingIgnoreCase(username); - if (user == null) { - LOG.warn("Username {} not found", username); - throw new UsernameNotFoundException("Username " + username + " not found"); - } - return new CustomCustomerDetails(user); - } + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + Customer user = customerDao.findByUserNameContainingIgnoreCase(username); + if (user == null) { + LOG.warn("Username {} not found", username); + throw new UsernameNotFoundException("Username " + username + " not found"); + } + return new CustomCustomerDetails(user); + } } diff --git a/BankData/src/main/resources/application.properties b/BankData/src/main/resources/application.properties index 6b0c790..65a2661 100644 --- a/BankData/src/main/resources/application.properties +++ b/BankData/src/main/resources/application.properties @@ -1,7 +1,7 @@ spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/HdfcBank1 +spring.datasource.url=jdbc:postgresql://localhost:5432/hdfcbank1 spring.datasource.username=postgres -spring.datasource.password=root +spring.datasource.password=1234 #spring.datasource.schema = dev spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.show-sql=true diff --git a/BankData/src/test/java/com/common/BankData/BankDataApplicationTests.java b/BankData/src/test/java/com/common/BankData/BankDataApplicationTests.java index 7cb6dda..312a979 100644 --- a/BankData/src/test/java/com/common/BankData/BankDataApplicationTests.java +++ b/BankData/src/test/java/com/common/BankData/BankDataApplicationTests.java @@ -6,8 +6,8 @@ @SpringBootTest class BankDataApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } } diff --git a/OnlineBanking/.mvn/wrapper/MavenWrapperDownloader.java b/OnlineBanking/.mvn/wrapper/MavenWrapperDownloader.java index e76d1f3..a45eb6b 100644 --- a/OnlineBanking/.mvn/wrapper/MavenWrapperDownloader.java +++ b/OnlineBanking/.mvn/wrapper/MavenWrapperDownloader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import java.net.*; import java.io.*; import java.nio.channels.*; @@ -25,7 +26,7 @@ public class MavenWrapperDownloader { * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; /** * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to @@ -54,7 +55,7 @@ public static void main(String args[]) { // wrapperUrl parameter. File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { + if (mavenWrapperPropertyFile.exists()) { FileInputStream mavenWrapperPropertyFileInputStream = null; try { mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); @@ -65,7 +66,7 @@ public static void main(String args[]) { System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); } finally { try { - if(mavenWrapperPropertyFileInputStream != null) { + if (mavenWrapperPropertyFileInputStream != null) { mavenWrapperPropertyFileInputStream.close(); } } catch (IOException e) { @@ -76,8 +77,8 @@ public static void main(String args[]) { System.out.println("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } diff --git a/OnlineBanking/pom.xml b/OnlineBanking/pom.xml index 1ede98f..40d3ea2 100644 --- a/OnlineBanking/pom.xml +++ b/OnlineBanking/pom.xml @@ -1,142 +1,142 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - com.banking - OnlineBanking - 0.0.1-SNAPSHOT - OnlineBanking - Demo project for Spring Boot + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.6.RELEASE + + + com.banking + OnlineBanking + 0.0.1-SNAPSHOT + OnlineBanking + Demo project for Spring Boot - - 1.8 - + + 1.8 + - - - org.liquibase - liquibase-core - - - com.common - 0.0.1-SNAPSHOT - BankData - - - org.springframework.boot - spring-boot-starter-batch - + + + org.liquibase + liquibase-core + + + com.common + 0.0.1-SNAPSHOT + BankData + + + org.springframework.boot + spring-boot-starter-batch + - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-web - - - com.google.code.gson - gson - test - + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + com.google.code.gson + gson + test + - - org.springframework.batch - spring-batch-test - test - - - org.springframework.security - spring-security-test - test - + + org.springframework.batch + spring-batch-test + test + + + org.springframework.security + spring-security-test + test + - - org.springframework.boot - spring-boot-starter-data-jpa - + + org.springframework.boot + spring-boot-starter-data-jpa + - - org.postgresql - postgresql - runtime - + + org.postgresql + postgresql + runtime + - - - org.apache.commons - commons-lang3 - 3.9 - + + + org.apache.commons + commons-lang3 + 3.9 + - - - com.fasterxml.uuid - java-uuid-generator - 4.0.1 - + + + com.fasterxml.uuid + java-uuid-generator + 4.0.1 + - - - javax.servlet - servlet-api - 2.5 - provided - - - - javax.ws.rs - javax.ws.rs-api - 2.1.1 - - - - org.springframework.boot - spring-boot-starter-test - test - + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.banking + BackOfficeSystem + 0.0.1-SNAPSHOT + test + com.banking BackOfficeSystem 0.0.1-SNAPSHOT test - - com.banking - BackOfficeSystem - 0.0.1-SNAPSHOT - test - - - org.liquibase - liquibase-maven-plugin - 3.4.1 - - + + org.liquibase + liquibase-maven-plugin + 3.4.1 + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.liquibase - liquibase-maven-plugin - 3.4.1 - - src/main/resources/liquibase.properties - - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.liquibase + liquibase-maven-plugin + 3.4.1 + + src/main/resources/liquibase.properties + + + + diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/OnlineBankingApplication.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/OnlineBankingApplication.java index d7123e1..a6be7d3 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/OnlineBankingApplication.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/OnlineBankingApplication.java @@ -14,8 +14,8 @@ @Import({XConfiguration.class, BankDataApplication.class}) public class OnlineBankingApplication { - public static void main(String[] args) { - SpringApplication.run(OnlineBankingApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(OnlineBankingApplication.class, args); + } } diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/Test.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/Test.java new file mode 100644 index 0000000..3807fa8 --- /dev/null +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/Test.java @@ -0,0 +1,31 @@ +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +UTI Nifty 50 Index Fund - Direct Plan +Mirae Asset ELSS Tax Saver Fund (formerly Mirae Asset Tax Saver Fund ) - Direct Plan +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth +Axis ELSS Tax Saver Fund - Direct Growth diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/AuthenticationFilter.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/AuthenticationFilter.java index 4303d2e..e7de147 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/AuthenticationFilter.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/AuthenticationFilter.java @@ -30,8 +30,8 @@ public Authentication attemptAuthentication(HttpServletRequest httpServletReques throw new NullPointerException(); } - String token= httpServletRequest.getHeader("AUTHORIZATION"); - token= StringUtils.removeStart(token, "Bearer").trim(); + String token = httpServletRequest.getHeader("AUTHORIZATION"); + token = StringUtils.removeStart(token, "Bearer").trim(); Authentication requestAuthentication = new UsernamePasswordAuthenticationToken(token, token); return getAuthenticationManager().authenticate(requestAuthentication); diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/RequestFilter.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/RequestFilter.java index 20fb815..147a3c8 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/RequestFilter.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/RequestFilter.java @@ -19,12 +19,11 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; - if (BACKOFFICE_URL.equals(request.getHeader("Origin"))) { - response.setHeader("Access-Control-Allow-Origin", BACKOFFICE_URL); - } else if (ONLINEBANKING_URL.equals(request.getHeader("Origin"))) { - response.setHeader("Access-Control-Allow-Origin", ONLINEBANKING_URL); - } - + if (BACKOFFICE_URL.equals(request.getHeader("Origin"))) { + response.setHeader("Access-Control-Allow-Origin", BACKOFFICE_URL); + } else if (ONLINEBANKING_URL.equals(request.getHeader("Origin"))) { + response.setHeader("Access-Control-Allow-Origin", ONLINEBANKING_URL); + } // response.setHeader("Access-Control-Allow-Origin", "http://localhost:8082"); //8081 @@ -37,7 +36,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) if (!(request.getMethod().equalsIgnoreCase("OPTIONS"))) { try { chain.doFilter(req, res); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } } else { @@ -51,8 +50,10 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) } - public void init(FilterConfig filterConfig) {} + public void init(FilterConfig filterConfig) { + } - public void destroy() {} + public void destroy() { + } } diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/SecurityConfig.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/SecurityConfig.java index 43ade5c..d8f458e 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/SecurityConfig.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/config/SecurityConfig.java @@ -1,7 +1,6 @@ package com.banking.OnlineBanking.config; - import com.common.BankData.dao.CustomerDao; import com.common.BankData.service.AuthenticationProvider; import com.common.BankData.service.UserSecurityService; @@ -16,7 +15,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.authentication.AnonymousAuthenticationFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.OrRequestMatcher; @@ -25,40 +23,19 @@ @Configuration @EnableWebSecurity @EnableJpaRepositories(basePackageClasses = CustomerDao.class) -@EnableGlobalMethodSecurity(prePostEnabled=true) +@EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { - @Autowired - private UserSecurityService userSecurityService; - - AuthenticationProvider provider; - -// @Bean -// public PasswordEncoder passwordEncoder() { -// return new PasswordEncoder(){ -// @Override -// public String encode(CharSequence charSequence) { -// return charSequence.toString(); -// } -// @Override -// public boolean matches(CharSequence chaarSequence, String s) { -// return encode(charSequence).equals(s); -// } -// }; -// } - private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher( new AntPathRequestMatcher("/accounts/**") ); - - private static final String[] PUBLIC_MATCHERS = { "/webjars/**", "/css/**", "/js/**", "/images/**", "/", - // "/login", + // "/login", "/about/**", "/contact/**", "/error/**/*", @@ -66,6 +43,28 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/signup" }; +// @Bean +// public PasswordEncoder passwordEncoder() { +// return new PasswordEncoder(){ +// @Override +// public String encode(CharSequence charSequence) { +// return charSequence.toString(); +// } +// @Override +// public boolean matches(CharSequence chaarSequence, String s) { +// return encode(charSequence).equals(s); +// } +// }; +// } + AuthenticationProvider provider; + @Autowired + private UserSecurityService userSecurityService; + + public SecurityConfig(final AuthenticationProvider authenticationProvider) { + super(); + this.provider = authenticationProvider; + } + @Bean AuthenticationFilter authenticationFilter() throws Exception { final AuthenticationFilter filter = new AuthenticationFilter(PROTECTED_URLS); @@ -73,12 +72,6 @@ AuthenticationFilter authenticationFilter() throws Exception { return filter; } - - public SecurityConfig(final AuthenticationProvider authenticationProvider) { - super(); - this.provider = authenticationProvider; - } - @Override protected void configure(final AuthenticationManagerBuilder auth) { auth.authenticationProvider(provider); @@ -86,7 +79,7 @@ protected void configure(final AuthenticationManagerBuilder auth) { @Override public void configure(final WebSecurity webSecurity) { - webSecurity.ignoring().antMatchers("/login/**"); + webSecurity.ignoring().antMatchers("/login/**"); webSecurity.ignoring().antMatchers("**/secured/**"); } @@ -96,7 +89,7 @@ protected void configure(HttpSecurity http) throws Exception { http.sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() + .and() .authenticationProvider(provider) .addFilterBefore(authenticationFilter(), AnonymousAuthenticationFilter.class) .authorizeRequests() @@ -109,10 +102,9 @@ protected void configure(HttpSecurity http) throws Exception { } - @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - // auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder()); + // auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder()); } } \ No newline at end of file diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerController.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerController.java index 38e7002..837a37a 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerController.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerController.java @@ -1,17 +1,14 @@ package com.banking.OnlineBanking.controller; -import com.common.BankData.dao.AccountDao; import com.common.BankData.dao.ScheduleDao; -import com.common.BankData.entity.PrimaryTransaction; import com.common.BankData.entity.Schedule; import com.common.BankData.entity.ScheduleList; - import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/customers") @@ -19,21 +16,16 @@ public class CustomerController { @Autowired - ScheduleDao scheduleDao; + ScheduleDao scheduleDao; @PostMapping("/scheduleTransaction") - public void scheduleJob(@RequestBody ScheduleList scheduleList) - { - for (Schedule schedule: scheduleList.getSchedule()) { - schedule.setStatus("scheduled"); + public void scheduleJob(@RequestBody ScheduleList scheduleList) { + for (Schedule schedule : scheduleList.getSchedule()) { + schedule.setStatus("scheduled"); scheduleDao.save(schedule); } } - - - - } diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerLoginControlller.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerLoginControlller.java index 8e5874d..567eb91 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerLoginControlller.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/CustomerLoginControlller.java @@ -6,15 +6,14 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import sun.misc.BASE64Decoder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; +import java.util.Base64; import java.util.UUID; @RequestMapping("/login/customer/api") @@ -46,42 +45,30 @@ public ResponseEntity generateToken(@RequestHeader("Authorization") String authS // // System.out.println(header); // - String decodedAuth = ""; + String decodedAuth = ""; // String[] authParts = header.split("\\s+"); String authInfo = authParts[1]; byte[] bytes = null; - try { - bytes = new BASE64Decoder().decodeBuffer(authInfo); - } catch (IOException e) { - e.printStackTrace(); - // TODO Auto-generated catch block - return new ResponseEntity<>("BAD REQUEST",new HttpHeaders(), HttpStatus.BAD_REQUEST); - - } + bytes = Base64.getDecoder().decode(authInfo); decodedAuth = new String(bytes); String username = decodedAuth.split(":")[0]; long userId = Long.parseLong(username); String enteredPassword = decodedAuth.split(":")[1]; - username=username.toLowerCase(); + username = username.toLowerCase(); Customer customer = customerDao.findByUserId(userId); - if(customer==null) - { + if (customer == null) { System.out.println("customer is null"); - return new ResponseEntity<>("Username not found",new HttpHeaders(),HttpStatus.UNAUTHORIZED); - } - else - { - if(customer.getPassword().equals(enteredPassword)){ + return new ResponseEntity<>("Username not found", new HttpHeaders(), HttpStatus.UNAUTHORIZED); + } else { + if (customer.getPassword().equals(enteredPassword)) { String token = UUID.randomUUID().toString(); customer.setToken(token); customerDao.save(customer); return ResponseEntity.ok(customer); - } - else - { - return new ResponseEntity<>("Username or password is Wrong",new HttpHeaders(),HttpStatus.UNAUTHORIZED); + } else { + return new ResponseEntity<>("Username or password is Wrong", new HttpHeaders(), HttpStatus.UNAUTHORIZED); } } } diff --git a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/TransferController.java b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/TransferController.java index bce301f..d534894 100644 --- a/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/TransferController.java +++ b/OnlineBanking/src/main/java/com/banking/OnlineBanking/controller/TransferController.java @@ -7,14 +7,10 @@ import com.common.BankData.entity.PrimaryTransaction; import com.common.BankData.service.TransferService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/OnlineBanking/src/main/resources/application.properties b/OnlineBanking/src/main/resources/application.properties index 87e7fe2..2b5f69b 100644 --- a/OnlineBanking/src/main/resources/application.properties +++ b/OnlineBanking/src/main/resources/application.properties @@ -4,15 +4,15 @@ spring.liquibase.enabled=false spring.liquibase.change-log=classpath:db/changelog/sample.changeLog.xml #liquibase.change-log=classpath:db/changelog/sample.changelog.xml server.port=8081 -spring.datasource.url=jdbc:postgresql://localhost:5432/HdfcBank1 +spring.datasource.url=jdbc:postgresql://localhost:5432/hdfcbank1 spring.datasource.username=postgres -spring.datasource.password=root +spring.datasource.password=1234 #spring.datasource.schema = dev -spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL9Dialect +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl diff --git a/OnlineBanking/src/main/resources/db/changelog/liquibase-outputChangeLog.xml b/OnlineBanking/src/main/resources/db/changelog/liquibase-outputChangeLog.xml index 02896e5..eaa8bf6 100644 --- a/OnlineBanking/src/main/resources/db/changelog/liquibase-outputChangeLog.xml +++ b/OnlineBanking/src/main/resources/db/changelog/liquibase-outputChangeLog.xml @@ -1,5 +1,7 @@ - + @@ -173,21 +175,39 @@ - + - + - + - + - + - + diff --git a/OnlineBanking/src/main/resources/db/changelog/sample.changeLog.xml b/OnlineBanking/src/main/resources/db/changelog/sample.changeLog.xml index 02896e5..e84ba02 100644 --- a/OnlineBanking/src/main/resources/db/changelog/sample.changeLog.xml +++ b/OnlineBanking/src/main/resources/db/changelog/sample.changeLog.xml @@ -1,5 +1,7 @@ - + @@ -15,6 +17,10 @@ + + + + @@ -173,21 +179,39 @@ - + - + - + - + - + - + diff --git a/OnlineBanking/src/main/resources/liquibase.properties b/OnlineBanking/src/main/resources/liquibase.properties index fd12f45..5aa1178 100644 --- a/OnlineBanking/src/main/resources/liquibase.properties +++ b/OnlineBanking/src/main/resources/liquibase.properties @@ -27,42 +27,31 @@ changeLogFile=src/main/resources/sample.changelog.xml diffTypes=data driver=org.postgresql.Driver # Enter the URL of the source database -url=jdbc:postgresql://localhost:5432/HdfcBank1 +url=jdbc:postgresql://localhost:5432/hdfcbank1 liquibase.change-log=classpath:liquibase-changeLog.xml outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml - # Enter the username for your source database. -username: postgres - +username:postgres # Enter the password for your source database. -password: root - - - +password:root #### Target Database Information #### ## The target database is the database you want to use to compare to your source database. - # Enter URL for the target database #referenceUrl: jdbc:postgresql://localhost:5432/HdfcBank2 - # Enter the username for your target database #referenceUsername: postgres - # Enter the password for your target database #referencePassword: root - #### Liquibase Pro Key Information #### # Enter your Liquibase Pro key here. # If you don't have one, visit https://download.liquibase.org/liquibase-pro-trial-request-form/ to start a free trial! # liquibaseProLicenseKey: - # Logging Configuration # logLevel controls the amount of logging information generated. If not set, the default logLevel is INFO. # Valid values, from least amount of logging to most, are: # OFF, ERROR, WARN, INFO, DEBUG, TRACE, ALL # If you are having problems, setting the logLevel to DEBUG and re-running the command can be helpful. # logLevel: DEBUG - # The logFile property controls where logging messages are sent. If this is not set, then logging messages are # displayed on the console. If this is set, then messages will be sent to a file with the given name. # logFile: liquibase.log \ No newline at end of file diff --git a/OnlineBanking/src/main/resources/sample.changeLog.xml b/OnlineBanking/src/main/resources/sample.changeLog.xml index 02896e5..eaa8bf6 100644 --- a/OnlineBanking/src/main/resources/sample.changeLog.xml +++ b/OnlineBanking/src/main/resources/sample.changeLog.xml @@ -1,5 +1,7 @@ - + @@ -173,21 +175,39 @@ - + - + - + - + - + - + diff --git a/OnlineBanking/src/test/java/com/banking/OnlineBanking/TestUtils.java b/OnlineBanking/src/test/java/com/banking/OnlineBanking/TestUtils.java index d9edcae..2f4085e 100644 --- a/OnlineBanking/src/test/java/com/banking/OnlineBanking/TestUtils.java +++ b/OnlineBanking/src/test/java/com/banking/OnlineBanking/TestUtils.java @@ -1,35 +1,31 @@ package com.banking.OnlineBanking; import com.google.gson.Gson; - import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import java.sql.Date; import java.util.List; /** - * * @author bytesTree * @see BytesTree - * */ public class TestUtils { - @SuppressWarnings("rawtypes") - public static List jsonToList(String json, TypeToken token) { - Gson gson = new Gson(); - return gson.fromJson(json, token.getType()); - } + @SuppressWarnings("rawtypes") + public static List jsonToList(String json, TypeToken token) { + Gson gson = new Gson(); + return gson.fromJson(json, token.getType()); + } - public static String objectToJson(Object obj) { - Gson gson = new Gson(); - return gson.toJson(obj); - } + public static String objectToJson(Object obj) { + Gson gson = new Gson(); + return gson.toJson(obj); + } - public static T jsonToObject(String json, Class classOf) { - Gson gson= new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); + public static T jsonToObject(String json, Class classOf) { + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); - return gson.fromJson(json, classOf); - } + return gson.fromJson(json, classOf); + } } diff --git a/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/CustomerLoginControlllerTest.java b/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/CustomerLoginControlllerTest.java index 47f1bb8..bad2f9c 100644 --- a/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/CustomerLoginControlllerTest.java +++ b/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/CustomerLoginControlllerTest.java @@ -1,60 +1,33 @@ package com.banking.OnlineBanking.controller; import com.banking.OnlineBanking.OnlineBankingApplication; -import com.banking.OnlineBanking.TestUtils; import com.common.BankData.dao.*; -import com.common.BankData.entity.Account; -import com.common.BankData.entity.Admin; import com.common.BankData.entity.Customer; -import com.common.BankData.entity.PrimaryTransaction; import com.common.BankData.service.AuthenticationProvider; import com.common.BankData.service.TransferService; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.reflect.TypeToken; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.http.HttpHeaders; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; import javax.servlet.annotation.MultipartConfig; -import java.net.URI; -import java.net.URISyntaxException; -import java.sql.Date; -import java.util.List; -import java.util.Set; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; //@RunWith(SpringRunner.class) //@SpringBootTest @@ -73,7 +46,7 @@ // "spring.jpa.hibernate.ddl-auto=validate" //}) @RunWith(SpringRunner.class) -@WebMvcTest(value = CustomerLoginControlller.class, excludeAutoConfiguration = {SecurityAutoConfiguration.class, BootstrapWith.class}) +@WebMvcTest(value = CustomerLoginControlller.class, excludeAutoConfiguration = {SecurityAutoConfiguration.class, BootstrapWith.class}) //@WebMvcTest(CustomerLoginControlller.class) @EnableAutoConfiguration @MultipartConfig @@ -81,8 +54,8 @@ public class CustomerLoginControlllerTest { - @Autowired - private MockMvc mockMvc; + @MockBean + AuthenticationProvider authenticationProvider; // @Before // public void setUp(){ @@ -97,38 +70,24 @@ public class CustomerLoginControlllerTest { // @Autowired // private MockMvc mockMvc; - - @MockBean - AuthenticationProvider authenticationProvider; - - - - @MockBean Customer customer; - @MockBean AccountDao accountDao; - @MockBean TransferService transferService; - @MockBean CustomerDao customerDao; - @MockBean TransferDao transferDao; - @MockBean OtherBankAccountDao otherBankAccountDao; - @MockBean ScheduleDao scheduleDao; - - @MockBean AdminDao adminDao; - + @Autowired + private MockMvc mockMvc; // @Mock @@ -137,7 +96,13 @@ public class CustomerLoginControlllerTest { // @InjectMocks // CustomerLoginControlller customerLoginControlller; - + public static String asJsonString(final Object obj) { + try { + return new ObjectMapper().writeValueAsString(obj); + } catch (Exception e) { + throw new RuntimeException(e); + } + } @Before public void setup() { @@ -150,54 +115,37 @@ public void setup() { } - - @After public void tearDown() throws Exception { } - - public static String asJsonString(final Object obj) { - try { - return new ObjectMapper().writeValueAsString(obj); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - - - - - - @Test public void testGenerateToken() throws Exception { CustomerDao customerDao = mock(CustomerDao.class); - Customer customer= new Customer(1,"Saurabh", "Saurabh", "Fnb@2021" ,null, "c6e336bf-5cb4-4c7d-9d80-dcc66738973a",0) ; - when(customerDao.findByUserNameContainingIgnoreCase("Saurabh")).thenReturn(customer); + Customer customer = new Customer(1, "Saurabh", "Saurabh", "Fnb@2021", null, "c6e336bf-5cb4-4c7d-9d80-dcc66738973a", 0); + when(customerDao.findByUserNameContainingIgnoreCase("Saurabh")).thenReturn(customer); - // mock(customerDao); + // mock(customerDao); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic U2F1cmFiaDpGbmJAMjAyMQ=="); // MockHttpServletRequest request = new MockHttpServletRequest(); // request.addHeader("x-real-ip","127.0.0.1"); - String header="Authorization:" +"Basic c2F1cmFiaDpGbmJAMjAyMQ=="; - MvcResult result= mockMvc.perform( MockMvcRequestBuilders - .post("/login/customer/api/secured/token").header("Authorization", "Basic c2F1cmFiaDpGbmJAMjAyMQ==") - // .header("Authorization", "Basic c2F1cmFiaDpGbmJAMjAyMQ==") - ).andReturn(); + String header = "Authorization:" + "Basic c2F1cmFiaDpGbmJAMjAyMQ=="; + MvcResult result = mockMvc.perform(MockMvcRequestBuilders + .post("/login/customer/api/secured/token").header("Authorization", "Basic c2F1cmFiaDpGbmJAMjAyMQ==") + // .header("Authorization", "Basic c2F1cmFiaDpGbmJAMjAyMQ==") + ).andReturn(); int status = result.getResponse().getStatus(); // assertEquals("Incorrect Response Status", HttpStatus.OK.value(), status); // verify that service method was called once - // verify(customerDao).findByUserNameContainingIgnoreCase(any(String.class)); + // verify(customerDao).findByUserNameContainingIgnoreCase(any(String.class)); - // Customer customer1 = TestUtils.jsonToObject(result.getResponse().getContentAsString(), Customer.class); + // Customer customer1 = TestUtils.jsonToObject(result.getResponse().getContentAsString(), Customer.class); assertEquals("Fnb@2021", customer.getPassword()); } diff --git a/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/TransferControllerTest.java b/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/TransferControllerTest.java index 13eea59..9c87efd 100644 --- a/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/TransferControllerTest.java +++ b/OnlineBanking/src/test/java/com/banking/OnlineBanking/controller/TransferControllerTest.java @@ -1,10 +1,8 @@ package com.banking.OnlineBanking.controller; import com.banking.OnlineBanking.TestUtils; -import com.banking.OnlineBanking.config.SecurityConfig; import com.common.BankData.dao.*; import com.common.BankData.entity.Account; -import com.common.BankData.entity.Customer; import com.common.BankData.entity.PrimaryTransaction; import com.common.BankData.service.AdminService; import com.common.BankData.service.AuthenticationProvider; @@ -17,9 +15,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.MockBeans; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; @@ -29,13 +24,12 @@ import javax.servlet.annotation.MultipartConfig; import java.sql.Date; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -46,9 +40,7 @@ @MultipartConfig public class TransferControllerTest { - @Autowired - private MockMvc mockMvc; - + private final String URL = "/transfer/balance/"; @MockBean AuthenticationProvider authenticationProvider; @@ -78,9 +70,8 @@ public class TransferControllerTest { @MockBean AdminService adminService; - - - private final String URL = "/transfer/balance/"; + @Autowired + private MockMvc mockMvc; public static String asJsonString(final Object obj) { try { @@ -105,11 +96,11 @@ public void betweenAccounts() throws Exception { // execute MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(URLTransactionList).header("Authorization", "") - .content(asJsonString( - e1 - )) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .content(asJsonString( + e1 + )) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andReturn(); // verify diff --git a/README.md b/README.md index 46dc456..9da5a9f 100644 --- a/README.md +++ b/README.md @@ -2,29 +2,30 @@ ## Accounting System - Technology Used: Java, Spring, Spring Batch, Spring Security, PostgreSQL, Microservices, Maven, JUnit, Liquibase,Fast2SMS - Functionalities: -⦁ Spring: Forms the Outline of Whole project. - -⦁ Spring Security: Basic Authentication mechanism on login and Token Based Authentication for every subsequent call from the User Interface. +⦁ Spring: Forms the Outline of Whole project. -⦁ Junit: Unit Testing and Integration Testing available for Online Customer System. +⦁ Spring Security: Basic Authentication mechanism on login and Token Based Authentication for every subsequent call from +the User Interface. -⦁ Spring Batch: As there are scenarios where payments needs to be done on any scheduled date and multiple Transaction to be done in a single day(Eg. payment of Salaries), I have used Spring batch to ease up the Stress on the application environment. +⦁ Junit: Unit Testing and Integration Testing available for Online Customer System. -⦁ Liquibase: Used for Managing database Entries. +⦁ Spring Batch: As there are scenarios where payments needs to be done on any scheduled date and multiple Transaction to +be done in a single day(Eg. payment of Salaries), I have used Spring batch to ease up the Stress on the application +environment. +⦁ Liquibase: Used for Managing database Entries. Working of Every Module: ## Backoffice System: -1. Admin would have two roles -Capturer and Authoriser. +1. Admin would have two roles -Capturer and Authoriser. + ```bash a. Capturer would be responsible for feeding the details of prospect customer into the System, @@ -40,9 +41,9 @@ Working of Every Module: which needs to be manually entered into the database at this point of time. ``` - - ## BankData: - + +## BankData: + ```bash 1. BankData is a jar which which is used in other three projects. @@ -52,11 +53,11 @@ Working of Every Module: BankData is based on following DRY(Do not repeat Yourself) principle. ``` - - ## OnlineBanking: - - 1. This Module is for Customer Facing Application. In this Customer would be able to perform many functions.Eg. - + +## OnlineBanking: + +1. This Module is for Customer Facing Application. In this Customer would be able to perform many functions.Eg. + a. Login into their own account using credentials received through SMS. b. Check the Balance on their Account. @@ -64,9 +65,9 @@ Working of Every Module: c. View Transaction History on all the Transaction Done till the current date. d. Schedule a Transaction(Future-Dated) - - ## TransactionScheduling: - + +## TransactionScheduling: + ``` 1. This Module is a Spring Batch Application which runs in the background, @@ -76,5 +77,5 @@ Working of Every Module: write the transaction log to the database. ``` - - Thank You! + +Thank You! diff --git a/TransactionScheduling1/.mvn/wrapper/MavenWrapperDownloader.java b/TransactionScheduling1/.mvn/wrapper/MavenWrapperDownloader.java index e76d1f3..a45eb6b 100644 --- a/TransactionScheduling1/.mvn/wrapper/MavenWrapperDownloader.java +++ b/TransactionScheduling1/.mvn/wrapper/MavenWrapperDownloader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import java.net.*; import java.io.*; import java.nio.channels.*; @@ -25,7 +26,7 @@ public class MavenWrapperDownloader { * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; /** * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to @@ -54,7 +55,7 @@ public static void main(String args[]) { // wrapperUrl parameter. File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { + if (mavenWrapperPropertyFile.exists()) { FileInputStream mavenWrapperPropertyFileInputStream = null; try { mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); @@ -65,7 +66,7 @@ public static void main(String args[]) { System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); } finally { try { - if(mavenWrapperPropertyFileInputStream != null) { + if (mavenWrapperPropertyFileInputStream != null) { mavenWrapperPropertyFileInputStream.close(); } } catch (IOException e) { @@ -76,8 +77,8 @@ public static void main(String args[]) { System.out.println("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { System.out.println( "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } diff --git a/TransactionScheduling1/pom.xml b/TransactionScheduling1/pom.xml index 0ca98ee..c41bbf9 100644 --- a/TransactionScheduling1/pom.xml +++ b/TransactionScheduling1/pom.xml @@ -1,67 +1,67 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - com.batch - TransactionScheduling - 0.0.1-SNAPSHOT - TransactionScheduling - Demo project for Spring Boot + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.6.RELEASE + + + com.batch + TransactionScheduling + 0.0.1-SNAPSHOT + TransactionScheduling + Demo project for Spring Boot - - 1.8 - + + 1.8 + - - - org.springframework.boot - spring-boot-starter-batch - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-batch + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.springframework.batch - spring-batch-test - test - - - com.common - 0.0.1-SNAPSHOT - BankData - - + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.springframework.batch + spring-batch-test + test + + + com.common + 0.0.1-SNAPSHOT + BankData + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/Controller/SchedulerController.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/Controller/SchedulerController.java index 153f745..5791f6a 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/Controller/SchedulerController.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/Controller/SchedulerController.java @@ -6,7 +6,6 @@ import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRestartException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -18,22 +17,20 @@ @RequestMapping("/schedule") public class SchedulerController { - @Autowired - private JobLauncher jobLauncher; - @Autowired Job loadJob; + @Autowired + private JobLauncher jobLauncher; @GetMapping("sf") - public String sf() - { + public String sf() { return "helo"; } /* @Autowired Job exportUserJob ;*/ -// @Scheduled(fixedRate = 20000) + // @Scheduled(fixedRate = 20000) @GetMapping("/hello") public BatchStatus load() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { @@ -44,7 +41,6 @@ public BatchStatus load() throws JobParametersInvalidException, JobExecutionAlre JobExecution jobExecution = jobLauncher.run(loadJob, parameters); - System.out.println("Batch is Running..."); while (jobExecution.isRunning()) { } diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/TransactionSchedulingApplication.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/TransactionSchedulingApplication.java index 41eb0e3..6b329d0 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/TransactionSchedulingApplication.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/TransactionSchedulingApplication.java @@ -4,11 +4,8 @@ import com.common.BankData.dao.XConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Import; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication(exclude = {SecurityAutoConfiguration.class}) @@ -16,8 +13,8 @@ @EnableScheduling public class TransactionSchedulingApplication { - public static void main(String[] args) { - SpringApplication.run(TransactionSchedulingApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(TransactionSchedulingApplication.class, args); + } } diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/BatchConfiguration.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/BatchConfiguration.java index c05a2af..30d9881 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/BatchConfiguration.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/BatchConfiguration.java @@ -1,7 +1,6 @@ package com.batch.TransactionScheduling.config; - import com.common.BankData.entity.Schedule; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; @@ -19,28 +18,21 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.annotation.Order; -import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.transaction.annotation.Transactional; import javax.sql.DataSource; -import javax.ws.rs.Produces; import java.beans.PropertyVetoException; import java.sql.ResultSet; import java.sql.SQLException; - import java.util.Date; @Configuration @EnableBatchProcessing -public class BatchConfiguration extends DefaultBatchConfigurer { - +public class BatchConfiguration extends DefaultBatchConfigurer { // @Autowired @@ -59,27 +51,23 @@ public class BatchConfiguration extends DefaultBatchConfigurer { // return dataSource; // } - @Override - protected JobRepository createJobRepository() throws Exception { - MapJobRepositoryFactoryBean factoryBean = new MapJobRepositoryFactoryBean(); - factoryBean.afterPropertiesSet(); - return factoryBean.getObject(); - } - @Autowired public JobBuilderFactory jobBuilderFactory; - @Autowired public StepBuilderFactory stepBuilderFactory; - -@Autowired -DataSource datasource; - - - + @Autowired + DataSource datasource; @Autowired JpaTransactionManager trxm; + @Autowired + DBWriter dbWriter; + @Override + protected JobRepository createJobRepository() throws Exception { + MapJobRepositoryFactoryBean factoryBean = new MapJobRepositoryFactoryBean(); + factoryBean.afterPropertiesSet(); + return factoryBean.getObject(); + } @Bean public JdbcCursorItemReader reader() throws PropertyVetoException { @@ -92,53 +80,29 @@ public JdbcCursorItemReader reader() throws PropertyVetoException { return reader; } - - public class UserRowMapper implements RowMapper{ - - @Override - public Schedule mapRow(ResultSet rs, int rowNum) throws SQLException { - Schedule schedule = new Schedule(); - schedule.setScheduleid(rs.getInt("scheduleid")); - schedule.setAccountId(rs.getLong("accountid")); - schedule.setAmount(rs.getFloat("amount")); - schedule.setDates(rs.getDate("dates")); - schedule.setRecipientAccountNo(rs.getLong("recipientaccountno")); - schedule.setRecipientName((rs.getString("recipientName"))); - schedule.setStatus(rs.getString("status")); - schedule.setType(rs.getString("type")); - - return schedule; - } - - } - @Bean - public UserItemProcessor processor(){ + public UserItemProcessor processor() { return new UserItemProcessor(); } - @Autowired - DBWriter dbWriter; - @Bean - public FlatFileItemWriter writer(){ + public FlatFileItemWriter writer() { FlatFileItemWriter writer = new FlatFileItemWriter(); writer.setResource(new ClassPathResource("users.csv")); writer.setLineAggregator(new DelimitedLineAggregator() {{ setDelimiter(","); setFieldExtractor(new BeanWrapperFieldExtractor() {{ - setNames(new String[] { "id", "name" }); + setNames(new String[]{"id", "name"}); }}); }}); return writer; } - @Bean public Step step1() throws PropertyVetoException { - return stepBuilderFactory.get("step1").transactionManager(trxm). chunk(10) + return stepBuilderFactory.get("step1").transactionManager(trxm).chunk(10) .reader(reader()) .processor(processor()) .writer(dbWriter) @@ -155,4 +119,23 @@ public Job exportUserJob() throws PropertyVetoException { .build(); } + public class UserRowMapper implements RowMapper { + + @Override + public Schedule mapRow(ResultSet rs, int rowNum) throws SQLException { + Schedule schedule = new Schedule(); + schedule.setScheduleid(rs.getInt("scheduleid")); + schedule.setAccountId(rs.getLong("accountid")); + schedule.setAmount(rs.getFloat("amount")); + schedule.setDates(rs.getDate("dates")); + schedule.setRecipientAccountNo(rs.getLong("recipientaccountno")); + schedule.setRecipientName((rs.getString("recipientName"))); + schedule.setStatus(rs.getString("status")); + schedule.setType(rs.getString("type")); + + return schedule; + } + + } + } \ No newline at end of file diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/DBWriter.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/DBWriter.java index 4e2e5d4..3109ff2 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/DBWriter.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/DBWriter.java @@ -2,7 +2,6 @@ import com.common.BankData.dao.AccountDao; - import com.common.BankData.dao.ScheduleDao; import com.common.BankData.entity.Account; import com.common.BankData.entity.PrimaryTransaction; @@ -12,10 +11,9 @@ import org.springframework.batch.item.ItemWriter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -36,7 +34,7 @@ public class DBWriter implements ItemWriter { @Override - @Transactional + @Transactional(propagation = Propagation.REQUIRED) public void write(List list) throws Exception { List ad = (List) list; Date today = new Date(); diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/UserItemProcessor.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/UserItemProcessor.java index 160d40f..269c5f5 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/UserItemProcessor.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/config/UserItemProcessor.java @@ -1,7 +1,6 @@ package com.batch.TransactionScheduling.config; - import com.common.BankData.entity.Schedule; import org.springframework.batch.item.ItemProcessor; diff --git a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/service/CronService.java b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/service/CronService.java index 7610960..8ef5798 100644 --- a/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/service/CronService.java +++ b/TransactionScheduling1/src/main/java/com/batch/TransactionScheduling/service/CronService.java @@ -9,21 +9,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import java.util.Date; import java.util.HashMap; -import java.util.List; import java.util.Map; @Service public class CronService { - @Autowired - private JobLauncher jobLauncher; - @Autowired Job loadJob; + @Autowired + private JobLauncher jobLauncher; @Scheduled(fixedRate = 60000) public BatchStatus load() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { diff --git a/TransactionScheduling1/src/main/resources/application.properties b/TransactionScheduling1/src/main/resources/application.properties index 5f60edc..aba8624 100644 --- a/TransactionScheduling1/src/main/resources/application.properties +++ b/TransactionScheduling1/src/main/resources/application.properties @@ -1,20 +1,19 @@ server.port=8082 #security.basic.enable: false #security.ignored=/** - hibernate.temp.use_jdbc_metadata_defaults=false spring.batch.initialize-schema=never spring.datasource.driver-class-name=org.postgresql.Driver spring.batch.job.enabled=false -spring.datasource.url=jdbc:postgresql://localhost:5432/HdfcBank1 +spring.datasource.url=jdbc:postgresql://localhost:5432/hdfcbank1 spring.datasource.username=postgres -spring.datasource.password=root +spring.datasource.password=1234 #spring.datasource.schema = dev spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL9Dialect +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl diff --git a/TransactionScheduling1/src/test/java/com/batch/TransactionScheduling/TransactionSchedulingApplicationTests.java b/TransactionScheduling1/src/test/java/com/batch/TransactionScheduling/TransactionSchedulingApplicationTests.java index 87357f8..015f0b2 100644 --- a/TransactionScheduling1/src/test/java/com/batch/TransactionScheduling/TransactionSchedulingApplicationTests.java +++ b/TransactionScheduling1/src/test/java/com/batch/TransactionScheduling/TransactionSchedulingApplicationTests.java @@ -6,8 +6,8 @@ @SpringBootTest class TransactionSchedulingApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } }