├── src ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── com │ │ └── myjobalert │ │ └── demo │ │ ├── UserServiceInterface.java │ │ ├── JobServiceInterface.java │ │ ├── User.java │ │ ├── JobApplication.java │ │ ├── Job.java │ │ ├── UserService.java │ │ ├── DemoApplication.java │ │ └── JobService.java └── test │ └── java │ └── com │ └── myjobalert │ └── demo │ └── DemoApplicationTests.java ├── README.md ├── pom.xml └── .gitignore /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/java/com/myjobalert/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/UserServiceInterface.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import java.util.List; 4 | 5 | public interface UserServiceInterface { 6 | public List getAllUsers(); 7 | 8 | User addUser(String userId, 9 | String userName, 10 | String userEmail); 11 | 12 | User updateUser(User userToUpdate) throws Exception; 13 | 14 | boolean deleteUser(String id) throws Exception; 15 | 16 | User getUser(String id); 17 | } -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/JobServiceInterface.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import java.util.List; 4 | 5 | public interface JobServiceInterface { 6 | 7 | List getAllJobs(); 8 | 9 | Job addJob(String jobId, 10 | String jobTitle, 11 | String jobCompany, 12 | String jobUrl, 13 | String jobCategory, 14 | String jobEmploymentType); 15 | 16 | Job updateJob(Job jobToUpdate) throws Exception; 17 | 18 | 19 | boolean deleteJob(String id) throws Exception; 20 | 21 | Job getJob(String id); 22 | 23 | List searchJob(String searchInput); 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # job-alert 2 | ## Introduction 3 | **JobAlert** is a platform on which you can create job search alerts of your dream company so that you receive a notification when these positions are posted and where you keep track of all your application progress. Try it out and secure a spot today. 4 | 5 | ## Team 6 | * Supervisor: @[Prof. Langel](https://github.com/blangel) 7 | * Student: @[googlr](https://github.com/googlr) 8 | 9 | ## Platform, Framework & Tools 10 | * [ply](https://github.com/blangel/ply) 11 | * [DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.html) 12 | * [Dropwizard](https://www.dropwizard.io/1.3.5/docs/) 13 | -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/User.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | 4 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 5 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 6 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore; 7 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 8 | 9 | 10 | @DynamoDBTable(tableName="User") 11 | public class User { 12 | private String userId; 13 | private String userName; 14 | private String userEmail; 15 | 16 | public User(){} 17 | 18 | public User(String userId, String userName, String userEmail) { 19 | this.userId = userId; 20 | this.userName = userName; 21 | this.userEmail = userEmail; 22 | } 23 | 24 | @DynamoDBHashKey(attributeName="userId") 25 | public String getUserId(){ 26 | return userId; 27 | } 28 | public void setUserId(String userId) { this.userId = userId; } 29 | 30 | @DynamoDBAttribute(attributeName="userName") 31 | public String getUserName(){ 32 | return userName; 33 | } 34 | 35 | public void setUserName(String userName){ 36 | this.userName = userName; 37 | //update the database 38 | } 39 | 40 | @DynamoDBAttribute(attributeName="userEmail") 41 | public String getUserEmail(){ 42 | return userEmail; 43 | } 44 | 45 | public void setUserEmail(String userEmail){ 46 | //validate newEmailAddress; 47 | // to-do 48 | 49 | this.userEmail = userEmail; 50 | //update the database 51 | } 52 | 53 | @DynamoDBIgnore 54 | @Override 55 | public String toString() { 56 | return "User {" + 57 | "userId=" + userId + 58 | ", userName='" + userName + '\'' + 59 | ", userEmail='" + userEmail + '\'' + 60 | '}'; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.myjobalert 7 | demo 8 | 0.0.1-SNAPSHOT 9 | war 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-tomcat 41 | provided 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | com.amazonaws 52 | aws-java-sdk 53 | 1.11.327 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-actuator 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/JobApplication.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import java.util.Date; 4 | 5 | public class JobApplication { 6 | private Job jobApplied; 7 | private User applicant; 8 | private Date applicationDate; 9 | private String applicationProgress; // progress ( submitted, underReview, OA, PhoneInterview, onSite ) + Date 10 | private String applicationStatus; // expired or not, may hide expired application 11 | 12 | public JobApplication( Job jobApplied, 13 | User applicant, 14 | Date applicationDate, 15 | String applicationProgress, 16 | String applicationStatus ) { 17 | this.jobApplied = jobApplied; 18 | this.applicant = applicant; 19 | this.applicationDate = applicationDate; 20 | this.applicationProgress = applicationProgress; 21 | this.applicationStatus = applicationStatus; 22 | } 23 | 24 | public Job getJobApplied(){ 25 | return jobApplied; 26 | } 27 | 28 | public void setJobApplied(Job jobApplied){ 29 | this.jobApplied = jobApplied; 30 | } 31 | 32 | public User getApplicant(){ 33 | return applicant; 34 | } 35 | 36 | public void setApplicant(User applicant){ 37 | this.applicant = applicant; 38 | } 39 | 40 | public Date getApplicationDate(){ 41 | return applicationDate; 42 | } 43 | 44 | public void setApplicationDate(Date applicationDate){ 45 | this.applicationDate = applicationDate; 46 | } 47 | 48 | public String getApplicationProgress(){ 49 | return applicationProgress; 50 | } 51 | 52 | public void setApplicationProgress(String applicationProgress){ 53 | this.applicationProgress = applicationProgress; 54 | } 55 | 56 | public String getApplicationStatus(){ 57 | return applicationStatus; 58 | } 59 | 60 | public void setApplicationStatus(String applicationStatus){ 61 | this.applicationStatus = applicationStatus; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "JobApplication {" + 67 | "jobApplied=" + jobApplied + 68 | ", applicant='" + applicant + '\'' + 69 | ", applicationDate='" + applicationDate + '\'' + 70 | ", applicationProgress='" + applicationProgress + '\'' + 71 | ", applicationStatus='" + applicationStatus + '\'' + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .mvn/ 2 | mvnw 3 | mvnw.cmd 4 | 5 | # 6 | *.DS_Store 7 | 8 | # 9 | target/ 10 | 11 | # Compiled class file 12 | *.class 13 | 14 | # Log file 15 | *.log 16 | 17 | # BlueJ files 18 | *.ctxt 19 | 20 | # Mobile Tools for Java (J2ME) 21 | .mtj.tmp/ 22 | 23 | # Package Files # 24 | *.jar 25 | *.war 26 | *.nar 27 | *.ear 28 | *.zip 29 | *.tar.gz 30 | *.rar 31 | 32 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 33 | hs_err_pid* 34 | 35 | 36 | 37 | 38 | # Created by https://www.gitignore.io/api/intellij 39 | 40 | ### Intellij ### 41 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 42 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 43 | 44 | # User-specific stuff 45 | .idea/**/workspace.xml 46 | .idea/**/tasks.xml 47 | .idea/**/usage.statistics.xml 48 | .idea/**/dictionaries 49 | .idea/**/shelf 50 | 51 | # Sensitive or high-churn files 52 | .idea/**/dataSources/ 53 | .idea/**/dataSources.ids 54 | .idea/**/dataSources.local.xml 55 | .idea/**/sqlDataSources.xml 56 | .idea/**/dynamic.xml 57 | .idea/**/uiDesigner.xml 58 | .idea/**/dbnavigator.xml 59 | 60 | # Gradle 61 | .idea/**/gradle.xml 62 | .idea/**/libraries 63 | 64 | # Gradle and Maven with auto-import 65 | # When using Gradle or Maven with auto-import, you should exclude module files, 66 | # since they will be recreated, and may cause churn. Uncomment if using 67 | # auto-import. 68 | # .idea/modules.xml 69 | # .idea/*.iml 70 | # .idea/modules 71 | 72 | # CMake 73 | cmake-build-*/ 74 | 75 | # Mongo Explorer plugin 76 | .idea/**/mongoSettings.xml 77 | 78 | # File-based project format 79 | *.iws 80 | 81 | # IntelliJ 82 | out/ 83 | 84 | # mpeltonen/sbt-idea plugin 85 | .idea_modules/ 86 | 87 | # JIRA plugin 88 | atlassian-ide-plugin.xml 89 | 90 | # Cursive Clojure plugin 91 | .idea/replstate.xml 92 | 93 | # Crashlytics plugin (for Android Studio and IntelliJ) 94 | com_crashlytics_export_strings.xml 95 | crashlytics.properties 96 | crashlytics-build.properties 97 | fabric.properties 98 | 99 | # Editor-based Rest Client 100 | .idea/httpRequests 101 | 102 | ### Intellij Patch ### 103 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 104 | 105 | *.iml 106 | modules.xml 107 | .idea/misc.xml 108 | *.ipr 109 | 110 | # Sonarlint plugin 111 | .idea/sonarlint 112 | 113 | 114 | # End of https://www.gitignore.io/api/intellij 115 | 116 | 117 | 118 | 119 | 120 | /target/ 121 | !.mvn/wrapper/maven-wrapper.jar 122 | 123 | ### STS ### 124 | .apt_generated 125 | .classpath 126 | .factorypath 127 | .project 128 | .settings 129 | .springBeans 130 | .sts4-cache 131 | 132 | ### IntelliJ IDEA ### 133 | .idea 134 | *.iws 135 | *.iml 136 | *.ipr 137 | 138 | ### NetBeans ### 139 | /nbproject/private/ 140 | /build/ 141 | /nbbuild/ 142 | /dist/ 143 | /nbdist/ 144 | /.nb-gradle/ -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/Job.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import java.util.Date; 4 | 5 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 6 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 7 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore; 8 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 9 | 10 | @DynamoDBTable(tableName="Job") 11 | public class Job { 12 | private String jobId; 13 | private String jobTitle; 14 | private String jobCompany; // ORGANIZATION NAME 15 | private String jobUrl; 16 | 17 | private String jobCategory; // AREA OF HIRE/INDUSTRY 18 | private String jobEmploymentType; 19 | 20 | // to-be added 21 | // EMPLOYMENT VISA SPONSORSHIP 22 | // DESIRED CLASS LEVEL/DEGREE LEVEL 23 | // private String jobLocation City, State, Country 24 | // private String jobStatus; //filled, closed, open, etc 25 | 26 | private Date jobPostDate; 27 | 28 | public Job(){} 29 | 30 | public Job(String jobId, String jobTitle, String jobCompany, String jobUrl, String jobCategory, String jobEmploymentType) { 31 | this.jobId = jobId; 32 | this.jobTitle = jobTitle; 33 | this.jobCompany = jobCompany; 34 | this.jobUrl = jobUrl; 35 | 36 | this.jobCategory = jobCategory; 37 | this.jobEmploymentType = jobEmploymentType; 38 | 39 | this.jobPostDate = new Date(); 40 | } 41 | 42 | @DynamoDBHashKey(attributeName="jobId") 43 | public String getJobId(){ 44 | return this.jobId; 45 | } 46 | public void setJobId(String jobId) { this.jobId = jobId; } 47 | 48 | @DynamoDBAttribute(attributeName="jobTitle") 49 | public String getJobTitle(){ 50 | return this.jobTitle; 51 | } 52 | 53 | public void setJobTitle(String jobTitle){ 54 | this.jobTitle = jobTitle; 55 | } 56 | 57 | @DynamoDBAttribute(attributeName="jobCompany") 58 | public String getJobCompany(){ 59 | return this.jobCompany; 60 | } 61 | 62 | public void setJobCompany(String jobCompany){ 63 | this.jobCompany = jobCompany; 64 | } 65 | 66 | @DynamoDBAttribute(attributeName="jobUrl") 67 | public String getjobUrl(){ 68 | return this.jobUrl; 69 | } 70 | 71 | public void setjobUrl(String jobUrl){ 72 | this.jobUrl = jobUrl; 73 | } 74 | 75 | @DynamoDBAttribute(attributeName="jobCategory") 76 | public String getJobCategory(){ 77 | return this.jobCategory; 78 | } 79 | 80 | public void setJobCategory(String jobCategory){ 81 | this.jobCategory = jobCategory; 82 | } 83 | 84 | @DynamoDBAttribute(attributeName="jobEmploymentType") 85 | public String getJobEmploymentType(){ 86 | return this.jobEmploymentType; 87 | } 88 | 89 | public void setJobEmploymentType(String jobEmploymentType){ 90 | this.jobEmploymentType = jobEmploymentType; 91 | } 92 | 93 | @DynamoDBAttribute(attributeName="jobPostDate") 94 | public Date getJobPostDate(){ 95 | return this.jobPostDate; 96 | } 97 | 98 | public void setJobPostDate(Date jobPostDate){ 99 | this.jobPostDate = jobPostDate; 100 | } 101 | 102 | 103 | 104 | //to-do 105 | // @Override 106 | // toString() 107 | // hashCode() 108 | 109 | @DynamoDBIgnore 110 | @Override 111 | public String toString(){ 112 | return "Job {" + 113 | "jobId=" + jobId + 114 | ", jobTitle='" + jobTitle + '\'' + 115 | ", jobCompany='" + jobCompany + '\'' + 116 | ", jobUrl='" + jobUrl + '\'' + 117 | ", jobCategory='" + jobCategory + '\'' + 118 | ", jobEmploymentType='" + jobEmploymentType + '\'' + 119 | ", jobPostDate='" + jobPostDate + '\'' + 120 | '}'; 121 | } 122 | 123 | 124 | } -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/UserService.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | 10 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 11 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; 12 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 13 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 14 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 15 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; 16 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey; 17 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression; 18 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 19 | import com.amazonaws.services.dynamodbv2.model.AttributeValue; 20 | 21 | 22 | import com.amazonaws.client.builder.AwsClientBuilder; 23 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 24 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; 25 | import com.amazonaws.services.dynamodbv2.document.DynamoDB; 26 | import com.amazonaws.services.dynamodbv2.document.PrimaryKey; 27 | import com.amazonaws.services.dynamodbv2.document.Table; 28 | import com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec; 29 | import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; 30 | 31 | import java.util.List; 32 | 33 | @RestController 34 | @RequestMapping(value="/rest/user") 35 | class UserService implements UserServiceInterface { 36 | @RequestMapping(value="/",method = RequestMethod.GET) 37 | public List getAllUsers(){ 38 | List userList = DemoApplication.dynamoDBMapper.scan(User.class, new DynamoDBScanExpression()); 39 | 40 | return userList; 41 | } 42 | 43 | @RequestMapping(value="/add",method = RequestMethod.POST) 44 | public User addUser(@RequestParam(value="userId") String userId, 45 | @RequestParam(value="userName") String userName, 46 | @RequestParam(value="userEmail") String userEmail){ 47 | //,@RequestParam(value="subject",defaultValue = "unknown") String subject){ 48 | 49 | User userToAdd=new User(userId, userName, userEmail); 50 | // DemoApplication.hmUser.put(new Long(userToAdd.getUserId()),userToAdd); 51 | DemoApplication.dynamoDBMapper.save(userToAdd); 52 | return userToAdd; 53 | } 54 | 55 | @RequestMapping(value="/update",method = RequestMethod.PUT) 56 | public User updateUser(@RequestBody User userToUpdate) throws Exception { 57 | 58 | User userToBeUpdated = DemoApplication.dynamoDBMapper.load( userToUpdate ); 59 | if( userToBeUpdated != null ){ 60 | DemoApplication.dynamoDBMapper.save( userToUpdate ); 61 | }else{ 62 | throw new Exception("User "+userToUpdate.getUserId()+" does not exists"); 63 | } 64 | 65 | return userToUpdate; 66 | } 67 | 68 | 69 | @RequestMapping(value="/delete/{id}",method = RequestMethod.DELETE) 70 | public boolean deleteUser(@PathVariable String id) throws Exception { 71 | 72 | DynamoDB dynamoDB = new DynamoDB(DemoApplication.dynamoDBClient); 73 | 74 | Table table = dynamoDB.getTable("User"); 75 | 76 | DeleteItemSpec deleteItemSpec = new DeleteItemSpec() 77 | .withPrimaryKey(new PrimaryKey("userId", id )); 78 | // Conditional delete 79 | 80 | try { 81 | System.out.println("Attempting a conditional delete..."); 82 | table.deleteItem(deleteItemSpec); 83 | System.out.println("DeleteItem succeeded"); 84 | return true; 85 | } 86 | catch (Exception e) { 87 | System.err.println("Unable to delete item: %s" + id ); 88 | System.err.println(e.getMessage()); 89 | return false; 90 | } 91 | 92 | } 93 | 94 | @RequestMapping(value="/{id}",method = RequestMethod.GET) 95 | public User getUser(@PathVariable String id){ 96 | 97 | // return value could be null 98 | return DemoApplication.dynamoDBMapper.load(User.class, id); 99 | } 100 | } -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import com.amazonaws.AmazonServiceException; 4 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 5 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; 6 | import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; 7 | import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; 8 | import com.amazonaws.services.dynamodbv2.model.CreateTableResult; 9 | import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; 10 | import com.amazonaws.services.dynamodbv2.model.KeyType; 11 | import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; 12 | import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType; 13 | 14 | 15 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 16 | 17 | import org.springframework.boot.SpringApplication; 18 | import org.springframework.boot.autoconfigure.SpringBootApplication; 19 | import java.util.HashMap; 20 | import java.util.Date; 21 | 22 | 23 | @SpringBootApplication 24 | public class DemoApplication { 25 | private String getUniqueJobId(){ 26 | //to-do 27 | return "to-do"; 28 | } 29 | 30 | // public static HashMap hmJob; 31 | // public static HashMap hmUser; 32 | 33 | 34 | public static AmazonDynamoDB dynamoDBClient; 35 | public static DynamoDBMapper dynamoDBMapper; 36 | 37 | public DemoApplication(){ 38 | //this.dynamoDBClient = AmazonDynamoDBClientBuilder.defaultClient(); 39 | //this.dynamoDBMapper = new DynamoDBMapper(dynamoDBClient); 40 | 41 | } 42 | 43 | private void createTableInDynamoDB(Class classT){ 44 | //final AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder.defaultClient(); 45 | 46 | //DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient); 47 | 48 | try { 49 | CreateTableRequest req = dynamoDBMapper.generateCreateTableRequest(classT); 50 | // Table provision throughput is still required since it cannot be specified in your POJO 51 | req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L)); 52 | // Fire off the CreateTableRequest using the low-level client 53 | CreateTableResult result = dynamoDBClient.createTable(req); 54 | 55 | System.out.println(result.getTableDescription().getTableName()); 56 | } catch (AmazonServiceException e) { 57 | System.err.println(e.getErrorMessage()); 58 | System.exit(1); 59 | } 60 | 61 | System.out.println("Create Table: %s.\n"); 62 | } 63 | 64 | private void deleteTableInDynamoDB(String tableName){ 65 | try { 66 | dynamoDBClient.deleteTable(tableName); 67 | } catch (AmazonServiceException e) { 68 | System.err.println(e.getErrorMessage()); 69 | System.exit(1); 70 | } 71 | } 72 | 73 | private void loadSampleDateIntoDynamoDB(){ 74 | Job firstJobInstance = new Job("0000000001", 75 | "Data Scientist/Quantitative Analyst, Engineering, University Graduate", 76 | "Google", 77 | "https://careers.google.com/jobs#!t=jo&jid=/google/data-scientist-quantitative-analyst-1600-amphitheatre-pkwy-mountain-view-ca-2495140088&", 78 | "Software Engineering", 79 | "Full-Time" 80 | ); 81 | 82 | Job secondJobInstance = new Job("0000000002", 83 | "Research Scientist, Google Brain (United States)", 84 | "Google", 85 | "https://careers.google.com/jobs#!t=jo&jid=/google/research-scientist-google-brain-united-76-9th-ave-new-york-ny-10011-usa-2144790060&", 86 | "Software Engineering", 87 | "Full-Time" 88 | ); 89 | 90 | Job thirdJobInstance = new Job("0000000003", 91 | "Technical Program Manager, University Graduate", 92 | "Google", 93 | "https://careers.google.com/jobs#!t=jo&jid=/google/technical-program-manager-university-1600-amphitheatre-pkwy-mountain-view-ca-3631710107&", 94 | "Technical Infrastructure", 95 | "Full-Time" 96 | ); 97 | 98 | dynamoDBMapper.save(firstJobInstance); 99 | dynamoDBMapper.save(secondJobInstance); 100 | dynamoDBMapper.save(thirdJobInstance); 101 | 102 | 103 | User firstUserInstance = new User("0000000001", 104 | "googlr", 105 | "googlr@gmail.com" 106 | ); 107 | 108 | User secondUserInstance = new User("0000000002", 109 | "Kaira", 110 | "kaira.Knightley@gmail.com" 111 | ); 112 | 113 | dynamoDBMapper.save(firstUserInstance); 114 | dynamoDBMapper.save(secondUserInstance); 115 | } 116 | 117 | public static void main(String[] args) { 118 | 119 | dynamoDBClient = AmazonDynamoDBClientBuilder.defaultClient(); 120 | dynamoDBMapper = new DynamoDBMapper(dynamoDBClient); 121 | 122 | SpringApplication.run(DemoApplication.class, args); 123 | 124 | // DemoApplication demoApplication = new DemoApplication(); 125 | // Create User Table 126 | // Create Job Table 127 | //demoApplication.createTableInDynamoDB(User.class); 128 | //demoApplication.createTableInDynamoDB(Job.class); 129 | 130 | // Load Sample data into DynamoDB 131 | // demoApplication.loadSampleDateIntoDynamoDB(); 132 | 133 | // Create User Table 134 | // Create Job Table 135 | //demoApplication.deleteTableInDynamoDB("User"); 136 | //demoApplication.deleteTableInDynamoDB("Job"); 137 | 138 | 139 | 140 | 141 | // hmJob = new HashMap(); 142 | // hmJob.put(new Long(firstJobInstance.getJobId()),firstJobInstance); 143 | // hmJob.put(new Long(secondJobInstance.getJobId()),secondJobInstance); 144 | // hmJob.put(new Long(thirdJobInstance.getJobId()),thirdJobInstance); 145 | 146 | 147 | 148 | 149 | 150 | // hmUser = new HashMap(); 151 | // hmUser.put(new Long(firstUserInstance.getUserId()),firstUserInstance); 152 | // hmUser.put(new Long(secondUserInstance.getUserId()),secondUserInstance); 153 | } 154 | } -------------------------------------------------------------------------------- /src/main/java/com/myjobalert/demo/JobService.java: -------------------------------------------------------------------------------- 1 | package com.myjobalert.demo; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | 10 | 11 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 12 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; 13 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 14 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 15 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 16 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; 17 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey; 18 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression; 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 20 | import com.amazonaws.services.dynamodbv2.model.AttributeValue; 21 | 22 | 23 | import com.amazonaws.client.builder.AwsClientBuilder; 24 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 25 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; 26 | import com.amazonaws.services.dynamodbv2.document.DynamoDB; 27 | import com.amazonaws.services.dynamodbv2.document.PrimaryKey; 28 | import com.amazonaws.services.dynamodbv2.document.Table; 29 | import com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec; 30 | import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; 31 | 32 | import java.util.*; 33 | 34 | @RestController 35 | @RequestMapping(value="/rest/job") 36 | class JobService implements JobServiceInterface { 37 | 38 | @RequestMapping(value="/",method = RequestMethod.GET) 39 | public List getAllJobs(){ 40 | List jobList = DemoApplication.dynamoDBMapper.scan(Job.class, new DynamoDBScanExpression()); 41 | 42 | return jobList; 43 | } 44 | 45 | @RequestMapping(value="/add",method = RequestMethod.POST) 46 | public Job addJob(@RequestParam(value="jobId") String jobId, 47 | @RequestParam(value="jobTitle") String jobTitle, 48 | @RequestParam(value="jobCompany") String jobCompany, 49 | @RequestParam(value="jobUrl") String jobUrl, 50 | @RequestParam(value="jobCategory") String jobCategory, 51 | @RequestParam(value="jobEmploymentType") String jobEmploymentType){ 52 | 53 | Job jobToAdd = new Job(jobId, jobTitle, jobCompany, jobUrl, jobCategory, jobEmploymentType); 54 | // DemoApplication.hmJob.put(new Long(jobToAdd.getJobId()),jobToAdd); 55 | DemoApplication.dynamoDBMapper.save(jobToAdd); 56 | return jobToAdd; 57 | } 58 | 59 | @RequestMapping(value="/update",method = RequestMethod.PUT) 60 | public Job updateJob(@RequestBody Job jobToUpdate) throws Exception { 61 | 62 | Job jobToBeUpdated = DemoApplication.dynamoDBMapper.load( jobToUpdate ); 63 | if( jobToBeUpdated != null ){ 64 | DemoApplication.dynamoDBMapper.save( jobToUpdate ); 65 | 66 | // if(DemoApplication.hmJob.containsKey(new Long(jobToUpdate.getJobId()))){ 67 | // DemoApplication.hmJob.put(new Long(jobToUpdate.getJobId()),jobToUpdate); 68 | } else { 69 | throw new Exception("Job "+ jobToUpdate.getJobId() + " does not exists"); 70 | } 71 | 72 | return jobToBeUpdated; 73 | } 74 | 75 | 76 | @RequestMapping(value="/delete/{id}",method = RequestMethod.DELETE) 77 | public boolean deleteJob(@PathVariable String id) throws Exception { 78 | 79 | DynamoDB dynamoDB = new DynamoDB(DemoApplication.dynamoDBClient); 80 | 81 | Table table = dynamoDB.getTable("Job"); 82 | 83 | DeleteItemSpec deleteItemSpec = new DeleteItemSpec() 84 | .withPrimaryKey(new PrimaryKey("jobId", id )); 85 | // Conditional delete 86 | 87 | try { 88 | System.out.println("Attempting a conditional delete..."); 89 | table.deleteItem(deleteItemSpec); 90 | System.out.println("DeleteItem succeeded"); 91 | return true; 92 | } 93 | catch (Exception e) { 94 | System.err.println("Unable to delete item: %s" + id ); 95 | System.err.println(e.getMessage()); 96 | return false; 97 | } 98 | } 99 | 100 | @RequestMapping(value="/{id}",method = RequestMethod.GET) 101 | public Job getJob(@PathVariable String id){ 102 | return DemoApplication.dynamoDBMapper.load(Job.class, id); 103 | } 104 | 105 | 106 | @RequestMapping(value="/search",method = RequestMethod.POST) 107 | public List searchJob(@RequestParam(value="searchInput") String searchInput ) { 108 | 109 | String[] keywords = searchInput.trim().split(" "); 110 | Set searchResult = new HashSet<>(); 111 | 112 | for( String keyword : keywords ){ 113 | Map eav = new HashMap(); 114 | eav.put(":keyword", new AttributeValue().withS(keyword)); 115 | 116 | DynamoDBScanExpression scanExpression = new DynamoDBScanExpression() 117 | .withFilterExpression("contains(jobId, :keyword) or contains(jobTitle, :keyword) or contains(jobCompany, :keyword) or contains(jobUrl, :keyword) or contains(jobCategory, :keyword) or contains(jobEmploymentType, :keyword)") 118 | .withExpressionAttributeValues(eav); 119 | // List scanResult = mapper.scan(Book.class, scanExpression); 120 | // DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression() 121 | // .withFilterExpression("contains(jobId, :keyword) or contains(jobTitle, :keyword) or contains(jobCompany, :keyword) or contains(jobUrl, :keyword) or contains(jobCategory, :keyword) or contains(jobEmploymentType, :keyword)") 122 | // .withExpressionAttributeValues(eav); 123 | 124 | List latestResults = DemoApplication.dynamoDBMapper.scan(Job.class, scanExpression); 125 | searchResult.addAll( latestResults ); 126 | } 127 | 128 | List searchResultList = new LinkedList(); 129 | searchResultList.addAll(searchResult); 130 | 131 | return searchResultList; 132 | } 133 | } --------------------------------------------------------------------------------