diff --git a/spring-security-oauth/pom.xml b/spring-security-oauth/pom.xml index c6056e72a0..910ca958a0 100644 --- a/spring-security-oauth/pom.xml +++ b/spring-security-oauth/pom.xml @@ -167,6 +167,15 @@ h2 1.4.187 + + + + + org.postgresql + postgresql + 9.4-1201-jdbc41 + + diff --git a/spring-security-oauth/src/main/java/org/baeldung/config/PersistenceJPAConfig.java b/spring-security-oauth/src/main/java/org/baeldung/config/PersistenceJPAConfig.java index 5cdb6c251f..48dde11627 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/config/PersistenceJPAConfig.java +++ b/spring-security-oauth/src/main/java/org/baeldung/config/PersistenceJPAConfig.java @@ -20,7 +20,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement -@PropertySource({ "classpath:persistence-${envTarget:prod}.properties" }) +@PropertySource({ "classpath:persistence-${envTarget:dev}.properties" }) @ComponentScan({ "org.baeldung.persistence" }) @EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao") public class PersistenceJPAConfig { diff --git a/spring-security-oauth/src/main/java/org/baeldung/persistence/model/User.java b/spring-security-oauth/src/main/java/org/baeldung/persistence/model/User.java index e3b5553922..00a09a36c4 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/persistence/model/User.java +++ b/spring-security-oauth/src/main/java/org/baeldung/persistence/model/User.java @@ -7,8 +7,10 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; @Entity +@Table(name = "APP_USER") public class User { @Id diff --git a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java index 585d235aea..b04cfb0828 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java +++ b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java @@ -142,6 +142,24 @@ public class RedditController { return (result == RedditClassifier.GOOD) ? "{Good Response}" : "{Bad response}"; } + @RequestMapping(value = "/checkIfAlreadySubmitted", method = RequestMethod.POST) + @ResponseBody + public String checkIfAlreadySubmitted(@RequestParam("url") final String url, @RequestParam("sr") final String sr) { + logger.info("check if already submitted"); + final JsonNode node = redditRestTemplate.getForObject("https://oauth.reddit.com/r/" + sr + "/search?q=url:" + url + "&restrict_sr=on", JsonNode.class); + logger.info(node.toString()); + return node.get("data").get("children").toString(); + } + + @RequestMapping(value = "/subredditAutoComplete") + @ResponseBody + public String subredditAutoComplete(@RequestParam("term") final String term) { + final MultiValueMap param = new LinkedMultiValueMap(); + param.add("query", term); + final JsonNode node = redditRestTemplate.postForObject("https://oauth.reddit.com//api/search_reddit_names", param, JsonNode.class); + return node.get("names").toString(); + } + // === post actions @RequestMapping(value = "/deletePost/{id}", method = RequestMethod.DELETE) @@ -164,6 +182,11 @@ public class RedditController { post.setTitle(formParams.get("title")); post.setSubreddit(formParams.get("sr")); post.setUrl(formParams.get("url")); + + post.setNoOfAttempts(Integer.parseInt(formParams.get("attempt"))); + post.setTimeInterval(Integer.parseInt(formParams.get("interval"))); + post.setMinScoreRequired(Integer.parseInt(formParams.get("score"))); + if (formParams.containsKey("sendreplies")) { post.setSendReplies(true); } else { diff --git a/spring-security-oauth/src/main/resources/persistence-dev.properties b/spring-security-oauth/src/main/resources/persistence-dev.properties new file mode 100644 index 0000000000..fe07bf298d --- /dev/null +++ b/spring-security-oauth/src/main/resources/persistence-dev.properties @@ -0,0 +1,10 @@ +################### DataSource Configuration ########################## +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/oauth_reddit?createDatabaseIfNotExist=true +jdbc.user=tutorialuser +jdbc.pass=tutorialmy5ql +init-db=false +################### Hibernate Configuration ########################## +hibernate.dialect=org.hibernate.dialect.MySQLDialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=update diff --git a/spring-security-oauth/src/main/resources/persistence-prod.properties b/spring-security-oauth/src/main/resources/persistence-production.properties similarity index 52% rename from spring-security-oauth/src/main/resources/persistence-prod.properties rename to spring-security-oauth/src/main/resources/persistence-production.properties index 856c4ce00c..8e61e06635 100644 --- a/spring-security-oauth/src/main/resources/persistence-prod.properties +++ b/spring-security-oauth/src/main/resources/persistence-production.properties @@ -1,10 +1,9 @@ ################### DataSource Configuration ########################## jdbc.driverClassName=org.postgresql.Driver -jdbc.url=jdbc:postgres://fkqrbxdwqbrzhv:Y83Axvgz5iC_tyRZQxI0KEmUEG@ec2-107-20-222-114.compute-1.amazonaws.com:5432/dfmoej36meltnj -jdbc.user=fkqrbxdwqbrzhv -jdbc.pass=Y83Axvgz5iC_tyRZQxI0KEmUEG - +jdbc.url=jdbc:postgresql://ec2-184-73-253-4.compute-1.amazonaws.com:5432/d3th4rkdb2g3p6?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory +jdbc.user=fhjspqyblvawvp +jdbc.pass=gRKGJbdHXslq0XgdI03j2Y4YoE ################### Hibernate Configuration ########################## hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect hibernate.show_sql=false -hibernate.hbm2ddl.auto=update +hibernate.hbm2ddl.auto=create-drop diff --git a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/editPostForm.jsp b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/editPostForm.jsp index 8a0f574c82..de3090844e 100755 --- a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/editPostForm.jsp +++ b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/editPostForm.jsp @@ -50,8 +50,42 @@ border-color: #ddd;

- - +
+
+
+
+ + + Votes didn't exceed + + + + + within    + + + + try resubmitting    + +    times. + + + +
+

+ + @@ -39,15 +41,21 @@ border-color: #ddd;

- +


-
+

+
+Check if already submitted + + +
+


-
+
@@ -81,7 +89,7 @@ border-color: #ddd;

- + + + \ No newline at end of file diff --git a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/submissionForm.jsp b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/submissionForm.jsp index a003186f73..bc613aaca9 100755 --- a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/submissionForm.jsp +++ b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/submissionForm.jsp @@ -3,7 +3,9 @@ Schedule to Reddit + +