From ba0cdf1ffcca144c8ac656af252d25c0ec62a901 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 17 Aug 2017 12:33:48 +0530 Subject: [PATCH 001/102] Junit and Mock Test Cases --- .../controllerTest/UserControllerTest.java | 109 ++++++++++++++++++ .../setup/StandaloneMvcTestViewResolver.java | 20 ++++ 2 files changed, 129 insertions(+) create mode 100644 src/test/java/com/visualpathit/account/controllerTest/UserControllerTest.java create mode 100644 src/test/java/com/visualpathit/account/setup/StandaloneMvcTestViewResolver.java diff --git a/src/test/java/com/visualpathit/account/controllerTest/UserControllerTest.java b/src/test/java/com/visualpathit/account/controllerTest/UserControllerTest.java new file mode 100644 index 0000000..3097f1a --- /dev/null +++ b/src/test/java/com/visualpathit/account/controllerTest/UserControllerTest.java @@ -0,0 +1,109 @@ +package com.visualpathit.account.controllerTest; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +import com.visualpathit.account.controller.UserController; +import com.visualpathit.account.model.User; +import com.visualpathit.account.service.UserService; +import com.visualpathit.account.setup.StandaloneMvcTestViewResolver; + + +public class UserControllerTest { + + @Mock + private UserService controllerSer; + @InjectMocks + private UserController controller; + private MockMvc mockMvc; + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + + /*InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/WEB-INF/views/"); + viewResolver.setSuffix(".jsp"); + */ + mockMvc = MockMvcBuilders.standaloneSetup(controller) + .setViewResolvers(new StandaloneMvcTestViewResolver()).build(); + } + + @Test + public void registrationTestforHappyFlow() throws Exception{ + User user = new User(); + mockMvc.perform(get("/registration")) + .andExpect(status().isOk()) + .andExpect(view().name("registration")) + .andExpect(forwardedUrl("registration")); + + } + @Test + public void registrationTestforNullValueHappyFlow() throws Exception{ + mockMvc.perform(get("/registration")) + .andExpect(status().isOk()) + .andExpect(view().name("registration")) + .andExpect(forwardedUrl("registration")); + + } + /*@Test + public void registrationTestforPostValueHappyFlow() throws Exception{ + String description =new String("Error String"); + UserValidator userValidator; + BindingResult bindingResult; + when(userValidator.validate(new User(),bindingResult)) + .thenThrow(bindingResult.hasErrors()); + mockMvc.perform(post("/registration").contentType(MediaType.APPLICATION_FORM_URLENCODED) + .param("userForm","userForm")) + + .andExpect(status().isOk()); + //.andExpect(view().name("redirect:/welcome")) + //.andExpect(forwardedUrl("redirect:/welcome")); + + }*/ + @Test + public void loginTestHappyFlow() throws Exception{ + String error = "Your username and password is invalid"; + mockMvc.perform(get("/login").param(error, error)) + .andExpect(status().isOk()) + .andExpect(view().name("login")) + .andExpect(forwardedUrl("login")); + + } + @Test + public void welcomeTestHappyFlow() throws Exception{ + mockMvc.perform(get("/welcome")) + .andExpect(status().isOk()) + .andExpect(view().name("welcome")) + .andExpect(forwardedUrl("welcome")); + + } + @Test + public void welcomeAfterDirectLoginTestHappyFlow() throws Exception{ + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(view().name("welcome")) + .andExpect(forwardedUrl("welcome")); + + } + @Test + public void indexTestHappyFlow() throws Exception{ + mockMvc.perform(get("/index")) + .andExpect(status().isOk()) + .andExpect(view().name("index_home")) + .andExpect(forwardedUrl("index_home")); + + } + +} diff --git a/src/test/java/com/visualpathit/account/setup/StandaloneMvcTestViewResolver.java b/src/test/java/com/visualpathit/account/setup/StandaloneMvcTestViewResolver.java new file mode 100644 index 0000000..f282b2a --- /dev/null +++ b/src/test/java/com/visualpathit/account/setup/StandaloneMvcTestViewResolver.java @@ -0,0 +1,20 @@ +package com.visualpathit.account.setup; + +import org.springframework.web.servlet.view.AbstractUrlBasedView; +import org.springframework.web.servlet.view.InternalResourceView; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +public class StandaloneMvcTestViewResolver extends InternalResourceViewResolver { + + public StandaloneMvcTestViewResolver() { + super(); + } + + @Override + protected AbstractUrlBasedView buildView(final String viewName) throws Exception { + final InternalResourceView view = (InternalResourceView) super.buildView(viewName); + // prevent checking for circular view paths + view.setPreventDispatchLoop(false); + return view; + } +} From ff63a8266c7c6e5c20844fa2a702e23a134b90e0 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 17 Aug 2017 13:41:33 +0530 Subject: [PATCH 002/102] Junit Test Cases for Models --- .../account/modelTest/RoleTest.java | 51 +++++++++++++++++++ .../account/modelTest/UserTest.java | 41 +++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/test/java/com/visualpathit/account/modelTest/RoleTest.java create mode 100644 src/test/java/com/visualpathit/account/modelTest/UserTest.java diff --git a/src/test/java/com/visualpathit/account/modelTest/RoleTest.java b/src/test/java/com/visualpathit/account/modelTest/RoleTest.java new file mode 100644 index 0000000..e8237b6 --- /dev/null +++ b/src/test/java/com/visualpathit/account/modelTest/RoleTest.java @@ -0,0 +1,51 @@ +package com.visualpathit.account.modelTest; + +import junit.framework.Assert; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.visualpathit.account.model.Role; +import com.visualpathit.account.model.User; + +/** {@author waheedk} !*/ +public class RoleTest { + + public static final Long EXPECTED_ID = 1L; + public static final String EXPECTED_USERNAME = "Wahidkhan74"; + public static final int EXPECTED_SIZE = 1; + private Role role; + @Before + public void setUp() throws Exception { + User user = new User(); + user.setId(1L); + user.setUsername("Wahidkhan74"); + user.setPassword("Wahidkhan74"); + user.setUserEmail("XXXXX@gmail.com"); + + Set users = new HashSet(); + users.add(user); + role = new Role(); + role.setId(1L); + role.setName("Wahidkhan74"); + role.setUsers(users);; + } + + @After + public void tearDown() throws Exception { + System.out.println("Test Completed"); + + } + + @Test + public void testUserDetailsHappyFlow() throws Exception { + Assert.assertEquals(EXPECTED_ID, role.getId()); + Assert.assertEquals(EXPECTED_USERNAME, role.getName()); + Assert.assertEquals(EXPECTED_SIZE,role.getUsers().size()); + + } +} \ No newline at end of file diff --git a/src/test/java/com/visualpathit/account/modelTest/UserTest.java b/src/test/java/com/visualpathit/account/modelTest/UserTest.java new file mode 100644 index 0000000..a8f2c4f --- /dev/null +++ b/src/test/java/com/visualpathit/account/modelTest/UserTest.java @@ -0,0 +1,41 @@ +package com.visualpathit.account.modelTest; + +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.visualpathit.account.model.User; + +/** {@author waheedk} !*/ +public class UserTest { + + public static final Long EXPECTED_ID = 1L; + public static final String EXPECTED_USERNAME = "Wahidkhan74"; + public static final String EXPECTED_PASSWD = "Wahidkhan74"; + public static final String EXPECTED_USEREMAIL = "XXXXX@gmail.com"; + private User user; + @Before + public void setUp() throws Exception { + user = new User(); + user.setId(1L); + user.setUsername("Wahidkhan74"); + user.setPassword("Wahidkhan74"); + user.setUserEmail("XXXXX@gmail.com"); + } + + @After + public void tearDown() throws Exception { + System.out.println("Test Completed"); + + } + + @Test + public void testUserDetailsHappyFlow() throws Exception { + Assert.assertEquals(EXPECTED_ID, user.getId()); + Assert.assertEquals(EXPECTED_USERNAME, user.getUsername()); + Assert.assertEquals(EXPECTED_PASSWD, user.getPassword()); + Assert.assertEquals(EXPECTED_USEREMAIL, user.getUserEmail()); + + } +} \ No newline at end of file From 884769066fd336a980f086530d5dc2ea5627a9a8 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 17 Aug 2017 13:54:40 +0530 Subject: [PATCH 003/102] Junit Test Cases for Models --- .../account/modelTest/RoleTest.java | 8 ++++---- .../account/modelTest/UserTest.java | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/visualpathit/account/modelTest/RoleTest.java b/src/test/java/com/visualpathit/account/modelTest/RoleTest.java index e8237b6..a5ff032 100644 --- a/src/test/java/com/visualpathit/account/modelTest/RoleTest.java +++ b/src/test/java/com/visualpathit/account/modelTest/RoleTest.java @@ -16,7 +16,7 @@ public class RoleTest { public static final Long EXPECTED_ID = 1L; - public static final String EXPECTED_USERNAME = "Wahidkhan74"; + public static final String EXPECTED_ROLENAME = "Admin"; public static final int EXPECTED_SIZE = 1; private Role role; @Before @@ -31,8 +31,8 @@ public void setUp() throws Exception { users.add(user); role = new Role(); role.setId(1L); - role.setName("Wahidkhan74"); - role.setUsers(users);; + role.setName("Admin"); + role.setUsers(users); } @After @@ -44,7 +44,7 @@ public void tearDown() throws Exception { @Test public void testUserDetailsHappyFlow() throws Exception { Assert.assertEquals(EXPECTED_ID, role.getId()); - Assert.assertEquals(EXPECTED_USERNAME, role.getName()); + Assert.assertEquals(EXPECTED_ROLENAME, role.getName()); Assert.assertEquals(EXPECTED_SIZE,role.getUsers().size()); } diff --git a/src/test/java/com/visualpathit/account/modelTest/UserTest.java b/src/test/java/com/visualpathit/account/modelTest/UserTest.java index a8f2c4f..df68dc8 100644 --- a/src/test/java/com/visualpathit/account/modelTest/UserTest.java +++ b/src/test/java/com/visualpathit/account/modelTest/UserTest.java @@ -1,27 +1,41 @@ package com.visualpathit.account.modelTest; import junit.framework.Assert; + +import java.util.HashSet; +import java.util.Set; + import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.visualpathit.account.model.Role; import com.visualpathit.account.model.User; /** {@author waheedk} !*/ public class UserTest { - public static final Long EXPECTED_ID = 1L; + public static final Long EXPECTED_ID = 1L; + public static final int EXPECTED_SIZE = 1; public static final String EXPECTED_USERNAME = "Wahidkhan74"; public static final String EXPECTED_PASSWD = "Wahidkhan74"; public static final String EXPECTED_USEREMAIL = "XXXXX@gmail.com"; private User user; @Before public void setUp() throws Exception { + + Role role = new Role(); + role.setId(1L); + role.setName("Admin"); + Set roles = new HashSet(); + roles.add(role); + user = new User(); user.setId(1L); user.setUsername("Wahidkhan74"); user.setPassword("Wahidkhan74"); user.setUserEmail("XXXXX@gmail.com"); + user.setRoles(roles); } @After @@ -36,6 +50,7 @@ public void testUserDetailsHappyFlow() throws Exception { Assert.assertEquals(EXPECTED_USERNAME, user.getUsername()); Assert.assertEquals(EXPECTED_PASSWD, user.getPassword()); Assert.assertEquals(EXPECTED_USEREMAIL, user.getUserEmail()); + Assert.assertEquals(EXPECTED_SIZE,user.getRoles().size()); } } \ No newline at end of file From 6c4904d0541ec133a40e1ac6198b35d6fc863d8b Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 24 Aug 2017 10:57:25 +0530 Subject: [PATCH 004/102] adding ansible playbook in vprofile-project --- ansible/vprofile.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ansible/vprofile.yml diff --git a/ansible/vprofile.yml b/ansible/vprofile.yml new file mode 100644 index 0000000..b04c6b7 --- /dev/null +++ b/ansible/vprofile.yml @@ -0,0 +1,39 @@ +--- +- hosts: tomcatservers + become: yes + + tasks: + + - name: Install EPEL-release + yum: name=epel-release state=present + + + - name: Install java_1.8 + yum: name=java-1.8.0-openjdk.x86_64 state=present + + - name: Install tomcat + yum: name=tomcat state=present + + + - name: Download latest VProfile.war file + get_url: url=http://:8081/nexus/content/repositories/VProfile-repo//{{time}}/{{build}}/{{gol_version}} dest=/tmp/ mode=755 + + - name: Stop tomcat service + service: name=tomcat state=stopped + + - name: Copy artifact to tomcat folder + shell: cp /tmp/{{gol_version}} /var/lib/tomcat/webapps + + - name: Delete link to existing gol version + file: path=/var/lib/tomcat/webapps/VProfile state=absent + + - name: Start tomcat service + service: name=tomcat state=started + - wait_for: path=/var/lib/tomcat/webapps/{{time}}-{{build}} + + - name: Link latest GOL version + file: src=/var/lib/tomcat/webapps/{{time}}-{{build}} dest=/var/lib/tomcat/webapps/VProfile state=link + + - name: Stop iptables + service: name=iptables state=stopped + From 2eae1a700127f77a06a9c82ad2e1ad86a3e7ab9b Mon Sep 17 00:00:00 2001 From: wkhanvisualpathit <30584908+wkhanvisualpathit@users.noreply.github.com> Date: Thu, 24 Aug 2017 11:35:37 +0530 Subject: [PATCH 005/102] updated vprofile.yml file for version change --- ansible/vprofile.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ansible/vprofile.yml b/ansible/vprofile.yml index b04c6b7..c8d6de6 100644 --- a/ansible/vprofile.yml +++ b/ansible/vprofile.yml @@ -1,7 +1,7 @@ --- - hosts: tomcatservers become: yes - + gather_facts: False tasks: - name: Install EPEL-release @@ -16,22 +16,22 @@ - name: Download latest VProfile.war file - get_url: url=http://:8081/nexus/content/repositories/VProfile-repo//{{time}}/{{build}}/{{gol_version}} dest=/tmp/ mode=755 + get_url: url=http://{{nexusip}}:8081/nexus/content/repositories/VProfile-repo/{{groupid}}/{{time}}/{{build}}/{{vprofile_version}} dest=/tmp/ mode=755 - name: Stop tomcat service service: name=tomcat state=stopped - name: Copy artifact to tomcat folder - shell: cp /tmp/{{gol_version}} /var/lib/tomcat/webapps + shell: cp /tmp/{{vprofile_version}} /var/lib/tomcat/webapps - - name: Delete link to existing gol version + - name: Delete link to existing vprofile version file: path=/var/lib/tomcat/webapps/VProfile state=absent - name: Start tomcat service service: name=tomcat state=started - wait_for: path=/var/lib/tomcat/webapps/{{time}}-{{build}} - - name: Link latest GOL version + - name: Link latest vprofile version file: src=/var/lib/tomcat/webapps/{{time}}-{{build}} dest=/var/lib/tomcat/webapps/VProfile state=link - name: Stop iptables From 5f45b41013745820ff8757439e0b727e49a37be1 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Mon, 28 Aug 2017 10:55:09 +0530 Subject: [PATCH 006/102] adding DB dump --- src/main/resources/accountsdb.sql | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/main/resources/accountsdb.sql diff --git a/src/main/resources/accountsdb.sql b/src/main/resources/accountsdb.sql new file mode 100644 index 0000000..d224d81 --- /dev/null +++ b/src/main/resources/accountsdb.sql @@ -0,0 +1,104 @@ +-- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) +-- +-- Host: localhost Database: accounts +-- ------------------------------------------------------ +-- Server version 5.7.18-0ubuntu0.16.10.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `role` +-- + +DROP TABLE IF EXISTS `role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `role` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `role` +-- + +LOCK TABLES `role` WRITE; +/*!40000 ALTER TABLE `role` DISABLE KEYS */; +INSERT INTO `role` VALUES (1,'ROLE_USER'); +/*!40000 ALTER TABLE `role` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `userEmail` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user` +-- + +LOCK TABLES `user` WRITE; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; +INSERT INTO `user` VALUES (4,'admin_vp','admin@visualpathit.com','$2a$11$DSEIKJNrgPjG.iCYUwErvOkREtC67mqzQ.ogkZbc/KOW1OPOpZfY6'); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user_role` +-- + +DROP TABLE IF EXISTS `user_role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user_role` ( + `user_id` int(11) NOT NULL, + `role_id` int(11) NOT NULL, + PRIMARY KEY (`user_id`,`role_id`), + KEY `fk_user_role_roleid_idx` (`role_id`), + CONSTRAINT `fk_user_role_roleid` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_user_role_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user_role` +-- + +LOCK TABLES `user_role` WRITE; +/*!40000 ALTER TABLE `user_role` DISABLE KEYS */; +INSERT INTO `user_role` VALUES (4,1); +/*!40000 ALTER TABLE `user_role` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-08-28 10:50:51 From 17f57b7c5b7d51c465d659410bb2431c64e236d8 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 14 Sep 2017 13:29:53 +0530 Subject: [PATCH 007/102] removing db.sql dump file --- src/main/resources/db.sql | 53 --------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 src/main/resources/db.sql diff --git a/src/main/resources/db.sql b/src/main/resources/db.sql deleted file mode 100644 index 0c073d1..0000000 --- a/src/main/resources/db.sql +++ /dev/null @@ -1,53 +0,0 @@ --- ---create a User with a password --- -CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; -GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; - -CREATE DATABASE IF NOT EXISTS `accounts`; -USE `accounts`; --- --- Table structure for table `role` --- - -DROP TABLE IF EXISTS `role`; -CREATE TABLE `role` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(45) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; - --- --- Dumping data for table `role` --- - -LOCK TABLES `role` WRITE; -INSERT INTO `role` VALUES (1,'ROLE_USER'); -UNLOCK TABLES; - --- --- Table structure for table `user` --- - -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `username` varchar(255) DEFAULT NULL, - `userEmail` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; - --- --- Table structure for table `user_role` --- - -DROP TABLE IF EXISTS `user_role`; -CREATE TABLE `user_role` ( - `user_id` int(11) NOT NULL, - `role_id` int(11) NOT NULL, - PRIMARY KEY (`user_id`,`role_id`), - KEY `fk_user_role_roleid_idx` (`role_id`), - CONSTRAINT `fk_user_role_roleid` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_user_role_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 17572c0390b8fe4a82478587da12d4d1a850eefb Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 24 Aug 2017 10:57:25 +0530 Subject: [PATCH 008/102] adding ansible playbook in vprofile-project --- ansible/vprofile.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ansible/vprofile.yml diff --git a/ansible/vprofile.yml b/ansible/vprofile.yml new file mode 100644 index 0000000..b04c6b7 --- /dev/null +++ b/ansible/vprofile.yml @@ -0,0 +1,39 @@ +--- +- hosts: tomcatservers + become: yes + + tasks: + + - name: Install EPEL-release + yum: name=epel-release state=present + + + - name: Install java_1.8 + yum: name=java-1.8.0-openjdk.x86_64 state=present + + - name: Install tomcat + yum: name=tomcat state=present + + + - name: Download latest VProfile.war file + get_url: url=http://:8081/nexus/content/repositories/VProfile-repo//{{time}}/{{build}}/{{gol_version}} dest=/tmp/ mode=755 + + - name: Stop tomcat service + service: name=tomcat state=stopped + + - name: Copy artifact to tomcat folder + shell: cp /tmp/{{gol_version}} /var/lib/tomcat/webapps + + - name: Delete link to existing gol version + file: path=/var/lib/tomcat/webapps/VProfile state=absent + + - name: Start tomcat service + service: name=tomcat state=started + - wait_for: path=/var/lib/tomcat/webapps/{{time}}-{{build}} + + - name: Link latest GOL version + file: src=/var/lib/tomcat/webapps/{{time}}-{{build}} dest=/var/lib/tomcat/webapps/VProfile state=link + + - name: Stop iptables + service: name=iptables state=stopped + From 8aa189c83b00932322d58cb26f78e6f1db706613 Mon Sep 17 00:00:00 2001 From: wkhanvisualpathit <30584908+wkhanvisualpathit@users.noreply.github.com> Date: Thu, 24 Aug 2017 11:35:37 +0530 Subject: [PATCH 009/102] updated vprofile.yml file for version change --- ansible/vprofile.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ansible/vprofile.yml b/ansible/vprofile.yml index b04c6b7..c8d6de6 100644 --- a/ansible/vprofile.yml +++ b/ansible/vprofile.yml @@ -1,7 +1,7 @@ --- - hosts: tomcatservers become: yes - + gather_facts: False tasks: - name: Install EPEL-release @@ -16,22 +16,22 @@ - name: Download latest VProfile.war file - get_url: url=http://:8081/nexus/content/repositories/VProfile-repo//{{time}}/{{build}}/{{gol_version}} dest=/tmp/ mode=755 + get_url: url=http://{{nexusip}}:8081/nexus/content/repositories/VProfile-repo/{{groupid}}/{{time}}/{{build}}/{{vprofile_version}} dest=/tmp/ mode=755 - name: Stop tomcat service service: name=tomcat state=stopped - name: Copy artifact to tomcat folder - shell: cp /tmp/{{gol_version}} /var/lib/tomcat/webapps + shell: cp /tmp/{{vprofile_version}} /var/lib/tomcat/webapps - - name: Delete link to existing gol version + - name: Delete link to existing vprofile version file: path=/var/lib/tomcat/webapps/VProfile state=absent - name: Start tomcat service service: name=tomcat state=started - wait_for: path=/var/lib/tomcat/webapps/{{time}}-{{build}} - - name: Link latest GOL version + - name: Link latest vprofile version file: src=/var/lib/tomcat/webapps/{{time}}-{{build}} dest=/var/lib/tomcat/webapps/VProfile state=link - name: Stop iptables From fd1099e5f5384acc15d8792782afe9974637d61b Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Mon, 28 Aug 2017 10:55:09 +0530 Subject: [PATCH 010/102] adding DB dump --- src/main/resources/accountsdb.sql | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/main/resources/accountsdb.sql diff --git a/src/main/resources/accountsdb.sql b/src/main/resources/accountsdb.sql new file mode 100644 index 0000000..d224d81 --- /dev/null +++ b/src/main/resources/accountsdb.sql @@ -0,0 +1,104 @@ +-- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) +-- +-- Host: localhost Database: accounts +-- ------------------------------------------------------ +-- Server version 5.7.18-0ubuntu0.16.10.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `role` +-- + +DROP TABLE IF EXISTS `role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `role` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `role` +-- + +LOCK TABLES `role` WRITE; +/*!40000 ALTER TABLE `role` DISABLE KEYS */; +INSERT INTO `role` VALUES (1,'ROLE_USER'); +/*!40000 ALTER TABLE `role` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `userEmail` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user` +-- + +LOCK TABLES `user` WRITE; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; +INSERT INTO `user` VALUES (4,'admin_vp','admin@visualpathit.com','$2a$11$DSEIKJNrgPjG.iCYUwErvOkREtC67mqzQ.ogkZbc/KOW1OPOpZfY6'); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user_role` +-- + +DROP TABLE IF EXISTS `user_role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user_role` ( + `user_id` int(11) NOT NULL, + `role_id` int(11) NOT NULL, + PRIMARY KEY (`user_id`,`role_id`), + KEY `fk_user_role_roleid_idx` (`role_id`), + CONSTRAINT `fk_user_role_roleid` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_user_role_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user_role` +-- + +LOCK TABLES `user_role` WRITE; +/*!40000 ALTER TABLE `user_role` DISABLE KEYS */; +INSERT INTO `user_role` VALUES (4,1); +/*!40000 ALTER TABLE `user_role` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-08-28 10:50:51 From a5ef338c2cae266ae9db10373416128becc12ea7 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Thu, 14 Sep 2017 13:29:53 +0530 Subject: [PATCH 011/102] removing db.sql dump file --- src/main/resources/db.sql | 53 --------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 src/main/resources/db.sql diff --git a/src/main/resources/db.sql b/src/main/resources/db.sql deleted file mode 100644 index 0c073d1..0000000 --- a/src/main/resources/db.sql +++ /dev/null @@ -1,53 +0,0 @@ --- ---create a User with a password --- -CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; -GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; - -CREATE DATABASE IF NOT EXISTS `accounts`; -USE `accounts`; --- --- Table structure for table `role` --- - -DROP TABLE IF EXISTS `role`; -CREATE TABLE `role` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(45) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; - --- --- Dumping data for table `role` --- - -LOCK TABLES `role` WRITE; -INSERT INTO `role` VALUES (1,'ROLE_USER'); -UNLOCK TABLES; - --- --- Table structure for table `user` --- - -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `username` varchar(255) DEFAULT NULL, - `userEmail` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; - --- --- Table structure for table `user_role` --- - -DROP TABLE IF EXISTS `user_role`; -CREATE TABLE `user_role` ( - `user_id` int(11) NOT NULL, - `role_id` int(11) NOT NULL, - PRIMARY KEY (`user_id`,`role_id`), - KEY `fk_user_role_roleid_idx` (`role_id`), - CONSTRAINT `fk_user_role_roleid` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_user_role_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 781b7c2fac0a1e57757ec78e7bf9b0909211e027 Mon Sep 17 00:00:00 2001 From: WKHAN <30584908+wkhanvisualpathit@users.noreply.github.com> Date: Thu, 14 Sep 2017 14:38:34 +0530 Subject: [PATCH 012/102] Updated README.md file for dump mention --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4548e6..f138fcb 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ MSQL DB Installation Steps for Linux ubuntu 14.04: - $ sudo apt-get install mysql-server Then look for the file : -- /src/main/resources/db.sql - -- db.sql file contents all step for DB table creation commands. +- /src/main/resources/accountsdb +- accountsdb.sql file is a mysql dump file.we have to import this dump to mysql db server +- > mysql -u -p accounts < accountsdb.sql From 02ff6c202d46efe0828da4f79400869705338018 Mon Sep 17 00:00:00 2001 From: WKHAN <30584908+wkhanvisualpathit@users.noreply.github.com> Date: Mon, 25 Sep 2017 17:13:44 +0530 Subject: [PATCH 013/102] updated pom.xml for change of version --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index da1aeb6..a134c2b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,6 @@ com.visualpathit VProfile war - 1.0 Visualpathit VProfile Webapp http://maven.apache.org From ad26e65755e23ab1275ffafd19798e36ee3ba1b5 Mon Sep 17 00:00:00 2001 From: Wahid Khan Date: Tue, 26 Sep 2017 13:45:12 +0530 Subject: [PATCH 014/102] change for artefact version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index da1aeb6..332e952 100644 --- a/pom.xml +++ b/pom.xml @@ -2,9 +2,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.visualpathit - VProfile + vprofile war - 1.0 + v1 Visualpathit VProfile Webapp http://maven.apache.org From 0132cb80a6ad7bc3d4d7c2d6794e1a2f077b2808 Mon Sep 17 00:00:00 2001 From: Waheed Khan Date: Sun, 3 Dec 2017 10:38:35 +0530 Subject: [PATCH 015/102] rabbitmq integration with vprofile --- pom.xml | 101 +++--- .../account/beans/Components.java | 76 +++++ .../controller/FileUploadController.java | 80 +++++ .../account/controller/UserController.java | 112 ++++++- .../com/visualpathit/account/model/User.java | 129 ++++++- .../account/repository/UserRepository.java | 5 + .../account/service/ConsumerService.java | 6 + .../account/service/ConsumerServiceImpl.java | 29 ++ .../account/service/ProducerService.java | 6 + .../account/service/ProducerServiceImpl.java | 56 ++++ .../account/service/UserService.java | 5 + .../account/service/UserServiceImpl.java | 10 + .../account/utils/MemcachedUtils.java | 134 ++++++++ .../account/utils/RabbitMqUtil.java | 30 ++ src/main/resources/application.properties | 15 + src/main/resources/db_backup.sql | 121 +++++++ src/main/webapp/WEB-INF/appconfig-mvc.xml | 6 + .../webapp/WEB-INF/appconfig-rabbitmq.xml | 28 ++ src/main/webapp/WEB-INF/appconfig-root.xml | 2 +- .../webapp/WEB-INF/appconfig-security.xml | 2 +- src/main/webapp/WEB-INF/views/rabbitmq.jsp | 12 + src/main/webapp/WEB-INF/views/upload.jsp | 56 ++++ src/main/webapp/WEB-INF/views/user.jsp | 121 +++++++ src/main/webapp/WEB-INF/views/userList.jsp | 51 +++ src/main/webapp/WEB-INF/views/userUpdate.jsp | 314 ++++++++++++++++++ src/main/webapp/WEB-INF/views/welcome.jsp | 47 ++- .../webapp/resources/Images/background.png | Bin 0 -> 862537 bytes .../webapp/resources/Images/user/giphy.gif | Bin 0 -> 2084709 bytes .../webapp/resources/Images/user/logo.png | Bin 0 -> 31675 bytes .../webapp/resources/Images/user/user.png | Bin 0 -> 18237 bytes .../webapp/resources/Images/user/user2.png | Bin 0 -> 32224 bytes .../webapp/resources/Images/user/user3.png | Bin 0 -> 19365 bytes target/classes/application.properties | 19 ++ .../account/beans/Components.class | Bin 0 -> 2508 bytes .../controller/FileUploadController.class | Bin 0 -> 3926 bytes .../account/controller/UserController.class | Bin 0 -> 7871 bytes .../com/visualpathit/account/model/Role.class | Bin 0 -> 1608 bytes .../com/visualpathit/account/model/User.class | Bin 0 -> 5972 bytes .../account/repository/RoleRepository.class | Bin 0 -> 357 bytes .../account/repository/UserRepository.class | Bin 0 -> 504 bytes .../account/service/ConsumerService.class | Bin 0 -> 178 bytes .../account/service/ConsumerServiceImpl.class | Bin 0 -> 1412 bytes .../account/service/ProducerService.class | Bin 0 -> 210 bytes .../account/service/ProducerServiceImpl.class | Bin 0 -> 3014 bytes .../account/service/SecurityService.class | Bin 0 -> 260 bytes .../account/service/SecurityServiceImpl.class | Bin 0 -> 3145 bytes .../service/UserDetailsServiceImpl.class | Bin 0 -> 2296 bytes .../account/service/UserService.class | Bin 0 -> 460 bytes .../account/service/UserServiceImpl.class | Bin 0 -> 2288 bytes .../account/utils/MemcachedUtils.class | Bin 0 -> 5165 bytes .../account/utils/RabbitMqUtil.class | Bin 0 -> 1088 bytes .../account/validator/UserValidator.class | Bin 0 -> 2211 bytes target/classes/db_backup.sql | 121 +++++++ target/classes/logback.xml | 24 ++ target/classes/validation.properties | 5 + .../web-resources/META-INF/MANIFEST.MF | 5 + .../com.visualpathit/vprofile/pom.properties | 7 + .../maven/com.visualpathit/vprofile/pom.xml | 165 +++++++++ .../account/controllerTest/SampleTest.class | Bin 0 -> 611 bytes .../controllerTest/UserControllerTest.class | Bin 0 -> 4366 bytes .../account/modelTest/RoleTest.class | Bin 0 -> 2350 bytes .../account/modelTest/UserTest.class | Bin 0 -> 2512 bytes .../setup/StandaloneMvcTestViewResolver.class | Bin 0 -> 885 bytes 63 files changed, 1822 insertions(+), 78 deletions(-) create mode 100644 src/main/java/com/visualpathit/account/beans/Components.java create mode 100644 src/main/java/com/visualpathit/account/controller/FileUploadController.java create mode 100644 src/main/java/com/visualpathit/account/service/ConsumerService.java create mode 100644 src/main/java/com/visualpathit/account/service/ConsumerServiceImpl.java create mode 100644 src/main/java/com/visualpathit/account/service/ProducerService.java create mode 100644 src/main/java/com/visualpathit/account/service/ProducerServiceImpl.java create mode 100644 src/main/java/com/visualpathit/account/utils/MemcachedUtils.java create mode 100644 src/main/java/com/visualpathit/account/utils/RabbitMqUtil.java create mode 100644 src/main/resources/db_backup.sql create mode 100644 src/main/webapp/WEB-INF/appconfig-rabbitmq.xml create mode 100644 src/main/webapp/WEB-INF/views/rabbitmq.jsp create mode 100644 src/main/webapp/WEB-INF/views/upload.jsp create mode 100644 src/main/webapp/WEB-INF/views/user.jsp create mode 100644 src/main/webapp/WEB-INF/views/userList.jsp create mode 100644 src/main/webapp/WEB-INF/views/userUpdate.jsp create mode 100644 src/main/webapp/resources/Images/background.png create mode 100644 src/main/webapp/resources/Images/user/giphy.gif create mode 100644 src/main/webapp/resources/Images/user/logo.png create mode 100644 src/main/webapp/resources/Images/user/user.png create mode 100644 src/main/webapp/resources/Images/user/user2.png create mode 100644 src/main/webapp/resources/Images/user/user3.png create mode 100644 target/classes/application.properties create mode 100644 target/classes/com/visualpathit/account/beans/Components.class create mode 100644 target/classes/com/visualpathit/account/controller/FileUploadController.class create mode 100644 target/classes/com/visualpathit/account/controller/UserController.class create mode 100644 target/classes/com/visualpathit/account/model/Role.class create mode 100644 target/classes/com/visualpathit/account/model/User.class create mode 100644 target/classes/com/visualpathit/account/repository/RoleRepository.class create mode 100644 target/classes/com/visualpathit/account/repository/UserRepository.class create mode 100644 target/classes/com/visualpathit/account/service/ConsumerService.class create mode 100644 target/classes/com/visualpathit/account/service/ConsumerServiceImpl.class create mode 100644 target/classes/com/visualpathit/account/service/ProducerService.class create mode 100644 target/classes/com/visualpathit/account/service/ProducerServiceImpl.class create mode 100644 target/classes/com/visualpathit/account/service/SecurityService.class create mode 100644 target/classes/com/visualpathit/account/service/SecurityServiceImpl.class create mode 100644 target/classes/com/visualpathit/account/service/UserDetailsServiceImpl.class create mode 100644 target/classes/com/visualpathit/account/service/UserService.class create mode 100644 target/classes/com/visualpathit/account/service/UserServiceImpl.class create mode 100644 target/classes/com/visualpathit/account/utils/MemcachedUtils.class create mode 100644 target/classes/com/visualpathit/account/utils/RabbitMqUtil.class create mode 100644 target/classes/com/visualpathit/account/validator/UserValidator.class create mode 100644 target/classes/db_backup.sql create mode 100644 target/classes/logback.xml create mode 100644 target/classes/validation.properties create mode 100644 target/m2e-wtp/web-resources/META-INF/MANIFEST.MF create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.visualpathit/vprofile/pom.properties create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.visualpathit/vprofile/pom.xml create mode 100644 target/test-classes/com/visualpathit/account/controllerTest/SampleTest.class create mode 100644 target/test-classes/com/visualpathit/account/controllerTest/UserControllerTest.class create mode 100644 target/test-classes/com/visualpathit/account/modelTest/RoleTest.class create mode 100644 target/test-classes/com/visualpathit/account/modelTest/UserTest.class create mode 100644 target/test-classes/com/visualpathit/account/setup/StandaloneMvcTestViewResolver.class diff --git a/pom.xml b/pom.xml index 332e952..dabf951 100644 --- a/pom.xml +++ b/pom.xml @@ -28,13 +28,13 @@ spring-web ${spring.version} - + org.springframework spring-webmvc ${spring.version} - + org.springframework.security spring-security-web @@ -90,36 +90,63 @@ test - org.mockito - mockito-core - 1.9.5 - test - - - org.springframework - spring-test - 3.2.3.RELEASE - test - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - + org.mockito + mockito-core + 1.9.5 + test + + + org.springframework + spring-test + 3.2.3.RELEASE + test + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + ch.qos.logback logback-classic ${logback.version} - org.hamcrest - hamcrest-all - 1.3 - test - + org.hamcrest + hamcrest-all + 1.3 + test + + + commons-fileupload + commons-fileupload + 1.3.1 + + + + net.spy + spymemcached + 2.12.3 + + + commons-io + commons-io + 2.4 + + + org.springframework.amqp + spring-rabbit + 1.7.1.RELEASE + + + + com.rabbitmq + amqp-client + 4.0.2 + - + org.eclipse.jetty @@ -132,29 +159,7 @@ - - - org.jacoco - jacoco-maven-plugin - 0.7.2.201409121644 - - - jacoco-initialize - process-resources - - prepare-agent - - - - jacoco-site - post-integration-test - - report - - - - + - diff --git a/src/main/java/com/visualpathit/account/beans/Components.java b/src/main/java/com/visualpathit/account/beans/Components.java new file mode 100644 index 0000000..3df64c0 --- /dev/null +++ b/src/main/java/com/visualpathit/account/beans/Components.java @@ -0,0 +1,76 @@ +package com.visualpathit.account.beans; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class Components { + + @Value("${memcached.active.host}") + private String activeHost; + @Value("${memcached.active.port}") + private String activePort; + @Value("${memcached.standBy.host}") + private String standByHost; + @Value("${memcached.standBy.port}") + private String standByPort; + + @Value("${rabbitmq.address}") + private String rabbitMqHost; + @Value("${rabbitmq.port}") + private String rabbitMqPort; + @Value("${rabbitmq.username}") + private String rabbitMqUser; + @Value("${rabbitmq.password}") + private String rabbitMqPassword; + + + public String getActiveHost() { + return activeHost; + } + public String getActivePort() { + return activePort; + } + public String getStandByHost() { + return standByHost; + } + public String getStandByPort() { + return standByPort; + } + public void setActiveHost(String activeHost) { + this.activeHost = activeHost; + } + public void setActivePort(String activePort) { + this.activePort = activePort; + } + public void setStandByHost(String standByHost) { + this.standByHost = standByHost; + } + public void setStandByPort(String standByPort) { + this.standByPort = standByPort; + } + public String getRabbitMqHost() { + return rabbitMqHost; + } + public void setRabbitMqHost(String rabbitMqHost) { + this.rabbitMqHost = rabbitMqHost; + } + public String getRabbitMqPort() { + return rabbitMqPort; + } + public void setRabbitMqPort(String rabbitMqPort) { + this.rabbitMqPort = rabbitMqPort; + } + public String getRabbitMqUser() { + return rabbitMqUser; + } + public void setRabbitMqUser(String rabbitMqUser) { + this.rabbitMqUser = rabbitMqUser; + } + public String getRabbitMqPassword() { + return rabbitMqPassword; + } + public void setRabbitMqPassword(String rabbitMqPassword) { + this.rabbitMqPassword = rabbitMqPassword; + } +} diff --git a/src/main/java/com/visualpathit/account/controller/FileUploadController.java b/src/main/java/com/visualpathit/account/controller/FileUploadController.java new file mode 100644 index 0000000..0de040a --- /dev/null +++ b/src/main/java/com/visualpathit/account/controller/FileUploadController.java @@ -0,0 +1,80 @@ +package com.visualpathit.account.controller; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import com.visualpathit.account.model.User; +import com.visualpathit.account.service.UserService; + +@Controller +public class FileUploadController { + @Autowired + private UserService userService; + private static final Logger logger = LoggerFactory + .getLogger(FileUploadController.class); + + /** + * Upload single file using Spring Controller + */ + @RequestMapping(value = { "/upload"} , method = RequestMethod.GET) + public final String upload(final Model model) { + return "upload"; + } + @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) + public @ResponseBody + String uploadFileHandler(@RequestParam("name") String name,@RequestParam("userName") String userName, + @RequestParam("file") MultipartFile file) { + + System.out.println("Called the upload file :::" ); + if (!file.isEmpty()) { + try { + byte[] bytes = file.getBytes(); + + // Creating the directory to store file + String rootPath = System.getProperty("catalina.home"); + System.out.println("Path ::::" +rootPath); + File dir = new File(rootPath + File.separator + "tmpFiles"); + if (!dir.exists()) + dir.mkdirs(); + + // Create the file on server + File serverFile = new File(dir.getAbsolutePath() + + File.separator + name+".png"); + //image saving + User user = userService.findByUsername(userName); + user.setProfileImg(name +".png"); + user.setProfileImgPath(serverFile.getAbsolutePath()); + userService.save(user); + + BufferedOutputStream stream = new BufferedOutputStream( + new FileOutputStream(serverFile)); + stream.write(bytes); + stream.close(); + + logger.info("Server File Location=" + + serverFile.getAbsolutePath()); + + return "You successfully uploaded file=" + name +".png"; + } catch (Exception e) { + return "You failed to upload " + name +".png" + " => " + e.getMessage(); + } + } else { + return "You failed to upload " + name +".png" + + " because the file was empty."; + } + } + +} diff --git a/src/main/java/com/visualpathit/account/controller/UserController.java b/src/main/java/com/visualpathit/account/controller/UserController.java index 48845e9..53fd5f3 100644 --- a/src/main/java/com/visualpathit/account/controller/UserController.java +++ b/src/main/java/com/visualpathit/account/controller/UserController.java @@ -1,15 +1,21 @@ package com.visualpathit.account.controller; import com.visualpathit.account.model.User; +import com.visualpathit.account.service.ProducerService; import com.visualpathit.account.service.SecurityService; import com.visualpathit.account.service.UserService; +import com.visualpathit.account.utils.MemcachedUtils; import com.visualpathit.account.validator.UserValidator; +import java.util.List; +import java.util.UUID; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /**{@author waheedk}*/ @@ -24,12 +30,20 @@ public class UserController { @Autowired private UserValidator userValidator; + @Autowired + private ProducerService producerService; + /** {@inheritDoc} */ @RequestMapping(value = "/registration", method = RequestMethod.GET) public final String registration(final Model model) { model.addAttribute("userForm", new User()); - - return "registration"; + if(!producerService.produceMessage("registration").isEmpty()) { + System.out.println("Response via rabbitmq ::"); + return "registration"; + }else { + return "registration"; + } + } /** {@inheritDoc} */ @RequestMapping(value = "/registration", method = RequestMethod.POST) @@ -68,4 +82,98 @@ public final String welcome(final Model model) { public final String indexHome(final Model model) { return "index_home"; } + @RequestMapping(value = "/users", method = RequestMethod.GET) + public String getAllUsers(Model model) + { + + List users = userService.getList(); + //JSONObject jsonObject + System.out.println("All User Data:::" + users); + model.addAttribute("users", users); + return "userList"; + } + + @RequestMapping(value = "/users/{id}", method = RequestMethod.GET) + public String getOneUser(@PathVariable(value="id") String id,Model model) + { + String Result =""; + try{ + if( id != null && MemcachedUtils.memcachedGetData(id)!= null){ + User userData = MemcachedUtils.memcachedGetData(id); + Result ="Data is From Chache"; + System.out.println("--------------------------------------------"); + System.out.println("Data is From Chache !!"); + System.out.println("--------------------------------------------"); + System.out.println("Father ::: "+userData.getFatherName()); + model.addAttribute("user", userData); + model.addAttribute("Result", Result); + } + else{ + User user = userService.findById(Long.parseLong(id)); + Result = MemcachedUtils.memcachedSetData(user,id); + if(Result == null ){ + Result ="Memcached Connection Failure !!"; + } + System.out.println("--------------------------------------------"); + System.out.println("Data is From Database"); + System.out.println("--------------------------------------------"); + System.out.println("Result ::: "+ Result); + model.addAttribute("user", user); + model.addAttribute("Result", Result); + } + } catch (Exception e) { + System.out.println( e.getMessage() ); + } + return "user"; + } + + /** {@inheritDoc} */ + @RequestMapping(value = { "/user/{username}"} , method = RequestMethod.GET) + public final String userUpdate(@PathVariable(value="username") String username,final Model model) { + User user = userService.findByUsername(username); + System.out.println("User Data:::" + user); + model.addAttribute("user", user); + return "userUpdate"; + } + @RequestMapping(value = { "/user/{username}"} , method = RequestMethod.POST) + public final String userUpdateProfile(@PathVariable(value="username") String username,final @ModelAttribute("user") User userForm,final Model model) { + User user = userService.findByUsername(username); + user.setUsername(userForm.getUsername()); + user.setUserEmail(userForm.getUserEmail()); + user.setDateOfBirth(userForm.getDateOfBirth()); + user.setFatherName(userForm.getFatherName()); + user.setMotherName(userForm.getMotherName()); + user.setGender(userForm.getGender()); + user.setLanguage(userForm.getLanguage()); + user.setMaritalStatus(userForm.getMaritalStatus()); + user.setNationality(userForm.getNationality()); + user.setPermanentAddress(userForm.getPermanentAddress()); + user.setTempAddress(userForm.getTempAddress()); + user.setPhoneNumber(userForm.getPhoneNumber()); + user.setSecondaryPhoneNumber(userForm.getSecondaryPhoneNumber()); + user.setPrimaryOccupation(userForm.getPrimaryOccupation()); + user.setSecondaryOccupation(userForm.getSecondaryOccupation()); + user.setSkills(userForm.getSkills()); + user.setWorkingExperience(userForm.getWorkingExperience()); + userService.save(user); + /*model.addAttribute("user", user);*/ + return "welcome"; + } + + @RequestMapping(value={"/user/rabbit"}, method={RequestMethod.GET}) + public String rabbitmqSetUp() { + System.out.println("Rabbit mq method is callled!!!"); + for (int i = 0; i < 20; i++) { + producerService.produceMessage(generateString()); + } + return "rabbitmq"; + } + + private static String generateString() { + String uuid = UUID.randomUUID().toString(); + return "uuid = " + uuid; + } + + + } diff --git a/src/main/java/com/visualpathit/account/model/User.java b/src/main/java/com/visualpathit/account/model/User.java index 917c4c9..e6680d3 100644 --- a/src/main/java/com/visualpathit/account/model/User.java +++ b/src/main/java/com/visualpathit/account/model/User.java @@ -2,11 +2,13 @@ import javax.persistence.*; + +import java.io.Serializable; import java.util.Set; /**{@author waheedk} !*/ @Entity @Table(name = "user") -public class User { +public class User implements Serializable { /** the id field !*/ private Long id; /** the user name field !*/ @@ -17,6 +19,27 @@ public class User { private String userEmail; /** the passwordConfirm field !*/ private String passwordConfirm; + /** the profileImg field !*/ + private String profileImg; + /** the profileImgPath field !*/ + private String profileImgPath; + private String dateOfBirth; + private String fatherName; + private String motherName; + private String gender; + private String maritalStatus; + private String permanentAddress; + private String tempAddress; + private String primaryOccupation; + private String secondaryOccupation; + private String skills; + private String phoneNumber; + private String secondaryPhoneNumber; + private String nationality; + private String language; + private String workingExperience; + + /** the roles field !*/ private Set roles; /** {@inheritDoc}} !*/ @@ -85,4 +108,108 @@ public Set getRoles() { public final void setRoles(final Set roles) { this.roles = roles; } + public String getProfileImg() { + return profileImg; + } + public void setProfileImg(String profileImg) { + this.profileImg = profileImg; + } + public String getProfileImgPath() { + return profileImgPath; + } + public void setProfileImgPath(String profileImgPath) { + this.profileImgPath = profileImgPath; + } + public String getDateOfBirth() { + return dateOfBirth; + } + public void setDateOfBirth(String dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + public String getFatherName() { + return fatherName; + } + public void setFatherName(String fatherName) { + this.fatherName = fatherName; + } + public String getMotherName() { + return motherName; + } + public void setMotherName(String motherName) { + this.motherName = motherName; + } + public String getGender() { + return gender; + } + public void setGender(String gender) { + this.gender = gender; + } + public String getMaritalStatus() { + return maritalStatus; + } + public void setMaritalStatus(String maritalStatus) { + this.maritalStatus = maritalStatus; + } + public String getPermanentAddress() { + return permanentAddress; + } + public void setPermanentAddress(String permanentAddress) { + this.permanentAddress = permanentAddress; + } + public String getTempAddress() { + return tempAddress; + } + public void setTempAddress(String tempAddress) { + this.tempAddress = tempAddress; + } + public String getPrimaryOccupation() { + return primaryOccupation; + } + public void setPrimaryOccupation(String primaryOccupation) { + this.primaryOccupation = primaryOccupation; + } + public String getSecondaryOccupation() { + return secondaryOccupation; + } + public void setSecondaryOccupation(String secondaryOccupation) { + this.secondaryOccupation = secondaryOccupation; + } + public String getSkills() { + return skills; + } + public void setSkills(String skills) { + this.skills = skills; + } + public String getPhoneNumber() { + return phoneNumber; + } + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + public String getSecondaryPhoneNumber() { + return secondaryPhoneNumber; + } + public void setSecondaryPhoneNumber(String secondaryPhoneNumber) { + this.secondaryPhoneNumber = secondaryPhoneNumber; + } + public String getNationality() { + return nationality; + } + public void setNationality(String nationality) { + this.nationality = nationality; + } + public String getLanguage() { + return language; + } + public void setLanguage(String language) { + this.language = language; + } + public String getWorkingExperience() { + return workingExperience; + } + public void setWorkingExperience(String workingExperience) { + this.workingExperience = workingExperience; + } + + } diff --git a/src/main/java/com/visualpathit/account/repository/UserRepository.java b/src/main/java/com/visualpathit/account/repository/UserRepository.java index 45f6df0..149b656 100644 --- a/src/main/java/com/visualpathit/account/repository/UserRepository.java +++ b/src/main/java/com/visualpathit/account/repository/UserRepository.java @@ -1,9 +1,14 @@ package com.visualpathit.account.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import com.visualpathit.account.model.User; public interface UserRepository extends JpaRepository { User findByUsername(String username); + User findById(long id); + /*public void updateUser(User user)*/; + } diff --git a/src/main/java/com/visualpathit/account/service/ConsumerService.java b/src/main/java/com/visualpathit/account/service/ConsumerService.java new file mode 100644 index 0000000..a638bf0 --- /dev/null +++ b/src/main/java/com/visualpathit/account/service/ConsumerService.java @@ -0,0 +1,6 @@ +package com.visualpathit.account.service; + +public interface ConsumerService { + + void consumerMessage(byte[] data); +} diff --git a/src/main/java/com/visualpathit/account/service/ConsumerServiceImpl.java b/src/main/java/com/visualpathit/account/service/ConsumerServiceImpl.java new file mode 100644 index 0000000..ecbd1b6 --- /dev/null +++ b/src/main/java/com/visualpathit/account/service/ConsumerServiceImpl.java @@ -0,0 +1,29 @@ +package com.visualpathit.account.service; + +import org.springframework.amqp.core.ExchangeTypes; +import org.springframework.amqp.rabbit.annotation.Exchange; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.QueueBinding; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Service; + +@Service +public class ConsumerServiceImpl implements ConsumerService { + + /** + The name of the exchange. + */ + private static final String EXCHANGE_NAME = "messages"; + + /** + * The function that consumes messages from the broker(RabbitMQ) + * @param data + */ + @Override + @RabbitListener(bindings = @QueueBinding( value = @Queue(), + exchange = @Exchange(value = EXCHANGE_NAME, type = ExchangeTypes.FANOUT))) + public void consumerMessage(byte[] data) { + String consumedMessage = new String(data); + System.out.println(" [x] Consumed '" + consumedMessage + "'"); + } +} diff --git a/src/main/java/com/visualpathit/account/service/ProducerService.java b/src/main/java/com/visualpathit/account/service/ProducerService.java new file mode 100644 index 0000000..ac89af2 --- /dev/null +++ b/src/main/java/com/visualpathit/account/service/ProducerService.java @@ -0,0 +1,6 @@ +package com.visualpathit.account.service; + +public interface ProducerService { + + public String produceMessage(String message); +} diff --git a/src/main/java/com/visualpathit/account/service/ProducerServiceImpl.java b/src/main/java/com/visualpathit/account/service/ProducerServiceImpl.java new file mode 100644 index 0000000..46970e6 --- /dev/null +++ b/src/main/java/com/visualpathit/account/service/ProducerServiceImpl.java @@ -0,0 +1,56 @@ +package com.visualpathit.account.service; + +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; +import com.visualpathit.account.utils.RabbitMqUtil; + +import org.springframework.stereotype.Service; +import com.rabbitmq.client.Channel; + +import java.io.IOException; +import java.util.concurrent.TimeoutException; + +@Service +public class ProducerServiceImpl implements ProducerService { + + /** + * The name of the Exchange + */ + private static final String EXCHANGE_NAME = "messages"; + + /** + * This method publishes a message + * @param message + */ + @Override + public String produceMessage(String message) { + try { + ConnectionFactory factory = new ConnectionFactory(); + /** + * System.out.println("Rabitmq host: ::" + RabbitMqUtil.getRabbitMqHost()); + * System.out.println("Rabitmq port: ::" + RabbitMqUtil.getRabbitMqPort()); + * System.out.println("Rabitmq user: ::" + RabbitMqUtil.getRabbitMqUser()); + * System.out.println("Rabitmq password: ::" + RabbitMqUtil.getRabbitMqPassword()); + **/ + factory.setHost(RabbitMqUtil.getRabbitMqHost()); + factory.setPort(Integer.parseInt(RabbitMqUtil.getRabbitMqPort())); + factory.setUsername(RabbitMqUtil.getRabbitMqUser()); + factory.setPassword(RabbitMqUtil.getRabbitMqPassword()); + Connection connection = factory.newConnection(); + System.out.println("Connection open status"+connection.isOpen()); + Channel channel = connection.createChannel(); + channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); + channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes()); + System.out.println(" [x] Sent '" + message + "'"); + channel.close(); + connection.close(); + } catch (IOException io) { + System.out.println("IOException"); + io.printStackTrace(); + } catch (TimeoutException toe) { + System.out.println("TimeoutException : " + toe.getMessage()); + toe.printStackTrace(); + } + return "response"; + } +} diff --git a/src/main/java/com/visualpathit/account/service/UserService.java b/src/main/java/com/visualpathit/account/service/UserService.java index 6fc0cc9..b4f55bb 100644 --- a/src/main/java/com/visualpathit/account/service/UserService.java +++ b/src/main/java/com/visualpathit/account/service/UserService.java @@ -1,5 +1,7 @@ package com.visualpathit.account.service; +import java.util.List; + import com.visualpathit.account.model.User; /** {@author waheedk}!*/ @@ -8,4 +10,7 @@ public interface UserService { void save(User user); /** {@inheritDoc}} !*/ User findByUsername(String username); + User findById(long id); + /*public void updateUser(User user);*/ + public List getList(); } diff --git a/src/main/java/com/visualpathit/account/service/UserServiceImpl.java b/src/main/java/com/visualpathit/account/service/UserServiceImpl.java index bf63b5d..31e0a53 100644 --- a/src/main/java/com/visualpathit/account/service/UserServiceImpl.java +++ b/src/main/java/com/visualpathit/account/service/UserServiceImpl.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import java.util.HashSet; +import java.util.List; /** {@author waheedk}!*/ @Service @@ -34,4 +35,13 @@ public void save(final User user) { public User findByUsername(final String username) { return userRepository.findByUsername(username); } + + @Override + public List getList() { + return userRepository.findAll(); + } + @Override + public User findById(long id){ + return userRepository.findOne(id); + } } diff --git a/src/main/java/com/visualpathit/account/utils/MemcachedUtils.java b/src/main/java/com/visualpathit/account/utils/MemcachedUtils.java new file mode 100644 index 0000000..98e5391 --- /dev/null +++ b/src/main/java/com/visualpathit/account/utils/MemcachedUtils.java @@ -0,0 +1,134 @@ +package com.visualpathit.account.utils; + +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.concurrent.Future; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.visualpathit.account.beans.Components; +import com.visualpathit.account.model.User; + +import net.spy.memcached.MemcachedClient; +@Service +public class MemcachedUtils { + + private static Components object; + @Autowired + public void setComponents(Components object){ + MemcachedUtils.object = object; + } + public static String memcachedSetData(User user,String key){ + String Result = ""; + int expireTime = 900; + try{ + MemcachedClient mactiveClient = memcachedConnection(); + System.out.println("--------------------------------------------"); + System.out.println("Client is ::"+ mactiveClient.getStats()); + System.out.println("--------------------------------------------"); + Future future = mactiveClient.set(key,expireTime, user); + System.out.println("set status:" + future.get()); + Result =" Data is From DB and Data Inserted In Cache !!"; + mactiveClient.shutdown(); + + + } catch (Exception e) { + System.out.println( e.getMessage() ); + } + return Result; + } + public static User memcachedGetData(String key){ + String Result = ""; + User userData = null; + try{ + MemcachedClient mclient = memcachedConnection(); + System.out.println("--------------------------------------------"); + System.out.println("Client Status :: "+mclient.getStats()); + System.out.println("--------------------------------------------"); + userData = (User) mclient.get(key); + System.out.println("user value in cache - " + mclient.get(key)); + Result =" Data Retrieval From Cache !!"; + System.out.println(Result); + mclient.shutdown(); + + } catch (Exception e) { + System.out.println( e.getMessage() ); + } + return userData; + } + public static MemcachedClient memcachedConnection(){ + MemcachedClient mcconn = null; + boolean active = true; + String key="pid"; + String port = ""; + String activeHost =object.getActiveHost(); + String activePort =object.getActivePort(); + try{ + if(!activeHost.isEmpty() && !activePort.isEmpty() && active){ + mcconn = new MemcachedClient(new InetSocketAddress(activeHost,Integer.parseInt(activePort))); + for(SocketAddress innerKey:mcconn.getStats().keySet()){ + System.out.println("Connection SocketAddress ::" + innerKey); + //System.out.println("Connection port ::" + mcconn.getStats().get(innerKey).get(key)); + port = mcconn.getStats().get(innerKey).get(key); + } + if(port == null){ + System.out.println("Port::"+ port); + mcconn.shutdown(); + System.out.println("--------------------------------------------"); + System.out.println("Connection Failure By Active Host ::" + activeHost); + System.out.println("--------------------------------------------"); + mcconn = null; + active =false; + return mcconn = standByMemcachedConn(); + } + if(!port.isEmpty()){ + System.out.println("--------------------------------------------"); + System.out.println("Connection to server sucessfull for active Host ::"+activeHost); + System.out.println("--------------------------------------------"); + active =true; + return mcconn; + } + }else if(!activeHost.isEmpty() && !activePort.isEmpty() && !active){ + return mcconn = standByMemcachedConn(); + }else { + System.out.println("--------------------------------------------"); + System.out.println("Connection to Failure Due to Incorrect or Empty Host:: "); + System.out.println("--------------------------------------------"); + } + } + catch (Exception e) { + System.out.println( e.getMessage() ); + } + return mcconn; + } + public static MemcachedClient standByMemcachedConn(){ + MemcachedClient mcconn = null; + String port = ""; + String key="pid"; + String standByHost = object.getStandByHost(); + String standByPort = object.getStandByPort(); + try{ + if(!standByHost.isEmpty() && !standByPort.isEmpty() && mcconn == null && port.isEmpty()){ + mcconn = new MemcachedClient(new InetSocketAddress(standByHost,Integer.parseInt(standByPort))); + for(SocketAddress innerKey:mcconn.getStats().keySet()){ + port = mcconn.getStats().get(innerKey).get(key); + } + if(!port.isEmpty()){ + System.out.println("--------------------------------------------"); + System.out.println("Connection to server sucessful by StandBy Host::" + standByHost); + System.out.println("--------------------------------------------"); + return mcconn; + }else { + mcconn.shutdown(); + System.out.println("--------------------------------------------"); + System.out.println("Connection Failure By StandBy Host ::" +standByHost); + System.out.println("--------------------------------------------"); + } + } + }catch (Exception e) { + System.out.println( e.getMessage() ); + } + return mcconn; + } +} diff --git a/src/main/java/com/visualpathit/account/utils/RabbitMqUtil.java b/src/main/java/com/visualpathit/account/utils/RabbitMqUtil.java new file mode 100644 index 0000000..cbef391 --- /dev/null +++ b/src/main/java/com/visualpathit/account/utils/RabbitMqUtil.java @@ -0,0 +1,30 @@ +package com.visualpathit.account.utils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.visualpathit.account.beans.Components; + +@Service +public class RabbitMqUtil { + private static Components object; + + public RabbitMqUtil() {} + + @Autowired + public void setComponents(Components object) { + RabbitMqUtil.object = object; + } + + public static String getRabbitMqHost() { return object.getRabbitMqHost(); } + + public static String getRabbitMqPort() { + return object.getRabbitMqPort(); + } + + public static String getRabbitMqUser() { return object.getRabbitMqUser(); } + + public static String getRabbitMqPassword() { + return object.getRabbitMqPassword(); + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ef8b5a8..423874f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,19 @@ +#JDBC Configutation for Database Connection jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/accounts?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull jdbc.username=newuser jdbc.password=password + +#Memcached Configuration For Active and StandBy Host +#For Active Host +memcached.active.host=127.0.0.1 +memcached.active.port=11211 +#For StandBy Host +memcached.standBy.host=127.0.0.2 +memcached.standBy.port=11211 + +#RabbitMq Configuration +rabbitmq.address=18.220.62.126 +rabbitmq.port=5672 +rabbitmq.username=test +rabbitmq.password=test \ No newline at end of file diff --git a/src/main/resources/db_backup.sql b/src/main/resources/db_backup.sql new file mode 100644 index 0000000..856af2e --- /dev/null +++ b/src/main/resources/db_backup.sql @@ -0,0 +1,121 @@ +-- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) +-- +-- Host: localhost Database: accounts +-- ------------------------------------------------------ +-- Server version 5.7.18-0ubuntu0.16.10.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `role` +-- + +DROP TABLE IF EXISTS `role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `role` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `role` +-- + +LOCK TABLES `role` WRITE; +/*!40000 ALTER TABLE `role` DISABLE KEYS */; +INSERT INTO `role` VALUES (1,'ROLE_USER'); +/*!40000 ALTER TABLE `role` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `userEmail` varchar(255) DEFAULT NULL, + `profileImg` varchar(255) DEFAULT NULL, + `profileImgPath` varchar(255) DEFAULT NULL, + `dateOfBirth` varchar(255) DEFAULT NULL, + `fatherName` varchar(255) DEFAULT NULL, + `motherName` varchar(255) DEFAULT NULL, + `gender` varchar(255) DEFAULT NULL, + `maritalStatus` varchar(255) DEFAULT NULL, + `permanentAddress` varchar(255) DEFAULT NULL, + `tempAddress` varchar(255) DEFAULT NULL, + `primaryOccupation` varchar(255) DEFAULT NULL, + `secondaryOccupation` varchar(255) DEFAULT NULL, + `skills` varchar(255) DEFAULT NULL, + `phoneNumber` varchar(255) DEFAULT NULL, + `secondaryPhoneNumber` varchar(255) DEFAULT NULL, + `nationality` varchar(255) DEFAULT NULL, + `language` varchar(255) DEFAULT NULL, + `workingExperience` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user` +-- + +LOCK TABLES `user` WRITE; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; +INSERT INTO `user` VALUES (4,'admin_vp','admin_vp@vp.com',NULL,NULL,'28/03/1994','M Khan','R Khan','male','unMarried','Ameerpet,Hyderabad','Ameerpet,Hyderabad','Software Engineer','Software Engineer','Java HTML CSS ','9960862529','9960862529','India','english','2 ','$2a$11$enwqb8vLp6TNRuSQwuJs9.p.0RsBVmvJYAsLq.g883Ly87YCiaxKi'),(5,'admin_vp2','admin@visualpathit.com',NULL,NULL,'28/03/1994','M Khan','R Khan','male','unMarried','Ameerpet,Hyderabad','Ameerpet,Hyderabad','Software Engineer','Software Engineer','Java HTML CSS ','9960862529','9960862529','India','english','12','$2a$11$Yflhl432jiLZQqr0DBcQKuJ.bxhZlR1YDFilK3SKeFX/WIulEsW2q'),(6,'admin_vp3','admin@visualpathit.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'$2a$11$PDx0mSd5lf22zP4ulURwp.jVP.AG.wUO94MY72j1FRogs/FcadNCa'); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `user_role` +-- + +DROP TABLE IF EXISTS `user_role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `user_role` ( + `user_id` int(11) NOT NULL, + `role_id` int(11) NOT NULL, + PRIMARY KEY (`user_id`,`role_id`), + KEY `fk_user_role_roleid_idx` (`role_id`), + CONSTRAINT `fk_user_role_roleid` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_user_role_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `user_role` +-- + +LOCK TABLES `user_role` WRITE; +/*!40000 ALTER TABLE `user_role` DISABLE KEYS */; +INSERT INTO `user_role` VALUES (4,1),(5,1),(6,1); +/*!40000 ALTER TABLE `user_role` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-10-24 15:03:57 diff --git a/src/main/webapp/WEB-INF/appconfig-mvc.xml b/src/main/webapp/WEB-INF/appconfig-mvc.xml index 7646030..58f404d 100644 --- a/src/main/webapp/WEB-INF/appconfig-mvc.xml +++ b/src/main/webapp/WEB-INF/appconfig-mvc.xml @@ -23,4 +23,10 @@ .jsp + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml b/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml new file mode 100644 index 0000000..989faec --- /dev/null +++ b/src/main/webapp/WEB-INF/appconfig-rabbitmq.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/appconfig-root.xml b/src/main/webapp/WEB-INF/appconfig-root.xml index 091d394..064cc5e 100644 --- a/src/main/webapp/WEB-INF/appconfig-root.xml +++ b/src/main/webapp/WEB-INF/appconfig-root.xml @@ -9,7 +9,7 @@ - + diff --git a/src/main/webapp/WEB-INF/appconfig-security.xml b/src/main/webapp/WEB-INF/appconfig-security.xml index f0a6abb..3b08f50 100644 --- a/src/main/webapp/WEB-INF/appconfig-security.xml +++ b/src/main/webapp/WEB-INF/appconfig-security.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security.xsd"> + http://www.springframework.org/schema/security/spring-security.xsd" > diff --git a/src/main/webapp/WEB-INF/views/rabbitmq.jsp b/src/main/webapp/WEB-INF/views/rabbitmq.jsp new file mode 100644 index 0000000..e4770a9 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/rabbitmq.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Insert title here + + +

Rabbitmq initiated

+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/upload.jsp b/src/main/webapp/WEB-INF/views/upload.jsp new file mode 100644 index 0000000..3e52f83 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/upload.jsp @@ -0,0 +1,56 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ page session="false" %> + + + +Upload File Request Page + + + + + + +
+
+

Upload Image

+
+ ${pageContext.request.userPrincipal.name}
+
+ + +
+
+ + +
+
+ + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/user.jsp b/src/main/webapp/WEB-INF/views/user.jsp new file mode 100644 index 0000000..8cd47c7 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/user.jsp @@ -0,0 +1,121 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + +UserData + + + + + + + +
+
+

${{Result}} Back

+

User Primary Details

+ + + + + + + + + + + + + + + + + +
IdNameFather's NameMother's NameEmailPhone Number
+ + + + + + + + + + + +
+

User Extra Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Date Of BirthGenderMarital StatusPermanent AddressTemporary AddressPrimary OccupationSecondary OccupationSkillsSecondary PhoneNumberNationalityLanguageWorking Experience
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/userList.jsp b/src/main/webapp/WEB-INF/views/userList.jsp new file mode 100644 index 0000000..88fe013 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/userList.jsp @@ -0,0 +1,51 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + allUser + + + + + + + +
+
+

Users List

+ + + + + + + + + + + + +
User NameUser Id
+ + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/userUpdate.jsp b/src/main/webapp/WEB-INF/views/userUpdate.jsp new file mode 100644 index 0000000..7ae3816 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/userUpdate.jsp @@ -0,0 +1,314 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + + + + + + + + + + + update user + + + + + + + + + +
+
+
+ +
+ +
+ + Name : +
+
+
+ +
+ +
+
+
+
+
+ + Email : +
+
+
+ +
+ +
+
+
+
+
+ + Date Of Birth : +
+
+
+ +
+ +
+
+
+
+
+ + Father's Name : +
+
+
+ +
+ +
+
+
+
+
+ + Mother's Name : +
+
+
+ +
+ +
+
+
+
+
+ + Gender +
+ + + Male + + + + Female + + + + Other + +
+
+
+
+ + Marital Status: +
+ + + Married + + + + Unmarried + +
+
+
+ +
+ + Permanent Address : +
+
+
+ +
+ +
+
+
+
+
+ + Temporary Address : +
+
+
+ +
+ +
+
+
+
+
+ + Primary Occupation : +
+
+
+ +
+ +
+
+
+
+
+ + Secondary Occupation : +
+
+
+ +
+ +
+
+
+
+
+ + Skills : +
+
+
+ +
+ +
+
+
+
+
+ + Phone Number : +
+
+
+ +
+ +
+
+
+
+
+ + Secondary PhoneNumber : +
+
+
+ +
+ +
+
+
+
+
+ + Nationality : +
+
+
+ +
+ +
+
+
+
+
+ + Mother Tongue +
+ + + English + + + + Spanish + + + + German + + + + Hindi + + + + Other + +
+
+
+
+ + Work Experience : +
+
+
+ +
+ +
+
+
+
+
+ +
+ + Cancel +
+
+
+
+
+
+
+ + + + diff --git a/src/main/webapp/WEB-INF/views/welcome.jsp b/src/main/webapp/WEB-INF/views/welcome.jsp index ca611d6..3cf3a5e 100644 --- a/src/main/webapp/WEB-INF/views/welcome.jsp +++ b/src/main/webapp/WEB-INF/views/welcome.jsp @@ -7,10 +7,10 @@ Welcome - + - + @@ -26,7 +26,7 @@ class="icon-bar"> - Brand + Brand VisualPath VP* Network @@ -41,7 +41,7 @@