commit
365a9726c1
|
@ -167,6 +167,15 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<version>1.4.187</version>
|
||||
</dependency>
|
||||
|
||||
<!-- postgresql -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.4-1201-jdbc41</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- web -->
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String, String> param = new LinkedMultiValueMap<String, String>();
|
||||
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 {
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -50,8 +50,42 @@ border-color: #ddd;
|
|||
</span>
|
||||
</div>
|
||||
<br/><br/>
|
||||
|
||||
<label class="col-sm-3">Submission Date</label>
|
||||
<br/>
|
||||
<hr/>
|
||||
<br/>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3">Resubmit If:</label>
|
||||
|
||||
<span class="col-sm-2">Votes didn't exceed </span>
|
||||
<span class="col-sm-1">
|
||||
<input type="number" class="form-control input-sm" th:value="${post.getMinScoreRequired()}" name="score" required="required"/>
|
||||
</span>
|
||||
|
||||
<span class="col-sm-3">within
|
||||
<select name="interval">
|
||||
<option value="0" th:selected="${post.getTimeInterval() == 0}">None</option>
|
||||
<option value="45" th:selected="${post.getTimeInterval() == 45}">45 minutes</option>
|
||||
<option value="60" th:selected="${post.getTimeInterval() == 60}">1 hour</option>
|
||||
<option value="120" th:selected="${post.getTimeInterval() == 120}">2 hours</option>
|
||||
</select>
|
||||
</span>
|
||||
|
||||
<span class="col-sm-3">try resubmitting
|
||||
<select name="attempt">
|
||||
<option value="0" th:selected="${post.getNoOfAttempts() == 0}">No</option>
|
||||
<option value="1" th:selected="${post.getNoOfAttempts() == 1}">1</option>
|
||||
<option value="2" th:selected="${post.getNoOfAttempts() == 2}">2</option>
|
||||
<option value="3" th:selected="${post.getNoOfAttempts() == 3}">3</option>
|
||||
<option value="4" th:selected="${post.getNoOfAttempts() == 4}">4</option>
|
||||
<option value="5" th:selected="${post.getNoOfAttempts() == 5}">5</option>
|
||||
</select>
|
||||
times.
|
||||
</span>
|
||||
|
||||
|
||||
</div>
|
||||
<br/><br/>
|
||||
<label class="col-sm-3">Submission Date (<span th:text="${#dates.format(#calendars.createToday(), 'z')}">UTC</span>)</label>
|
||||
<span class="col-sm-9"><input type="text" name="date" class="form-control" th:value="${dateValue}" readonly="readonly"/></span>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<th>Post title</th>
|
||||
<th>Submission Date</th>
|
||||
<th>Status</th>
|
||||
<th>Resubmit Attempts left</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -23,6 +24,8 @@
|
|||
<td th:text="${post.getTitle()}"></td>
|
||||
<td th:text="${#calendars.format(post.getSubmissionDate(),'dd MMMM yyyy HH:mm z')}"></td>
|
||||
<td th:text="${post.getSubmissionResponse()}"></td>
|
||||
<td th:if="${post.getNoOfAttempts() > 0}" th:text="${post.getNoOfAttempts()}"></td>
|
||||
<td th:unless="${post.getNoOfAttempts() > 0}">-</td>
|
||||
<td>
|
||||
<a th:href="@{/editPost/{id}(id=${post.getId()})}" class="btn btn-warning" >Edit</a>
|
||||
<a href="#" class="btn btn-danger" th:onclick="'javascript:confirmDelete(\'' +${post.getId()}+ '\') '">Delete</a>
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
<title>Schedule to Reddit</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" th:href="@{/resources/datetime-picker.css}"/>
|
||||
<link rel="stylesheet" th:href="@{/resources/autocomplete.css}"/>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
<script th:src="@{/resources/datetime-picker.js}"></script>
|
||||
<script th:src="@{/resources/validator.js}"></script>
|
||||
|
@ -39,15 +41,21 @@ border-color: #ddd;
|
|||
<br/><br/>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3">Subreddit</label>
|
||||
<span class="col-sm-9"><input name="sr" placeholder="Subreddit (e.g. kitten)" class="form-control" required="required" data-minlength="3"/></span>
|
||||
<span class="col-sm-9"><input id="sr" name="sr" placeholder="Subreddit (e.g. kitten)" class="form-control" required="required" data-minlength="3"/></span>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<div>
|
||||
<label class="col-sm-3">Send replies to my inbox</label> <span class="col-sm-9"><input type="checkbox" name="sendreplies" value="true"/></span>
|
||||
</div>
|
||||
<br/>
|
||||
<br/><br/>
|
||||
<div>
|
||||
<span class="col-sm-2"><a href="#" class="btn btn-default" onclick="checkIfAlreadySubmitted()">Check if already submitted</a></span>
|
||||
<span class="col-sm-1"></span>
|
||||
<span class="col-sm-9"><span id="checkResult" class="alert alert-info" style="display:none"></span></span>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<hr/>
|
||||
<br/>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3">Resubmit If:</label>
|
||||
|
||||
|
@ -81,7 +89,7 @@ border-color: #ddd;
|
|||
<br/><br/>
|
||||
|
||||
|
||||
<label class="col-sm-3">Submission Date</label>
|
||||
<label class="col-sm-3">Submission Date (<span th:text="${#dates.format(#calendars.createToday(), 'z')}">UTC</span>)</label>
|
||||
<span class="col-sm-9"><input type="text" name="date" class="form-control" readonly="readonly"/></span>
|
||||
<script type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
|
@ -98,5 +106,35 @@ border-color: #ddd;
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$(function() {
|
||||
$( "#sr" ).autocomplete({
|
||||
source: "subredditAutoComplete"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
/*<![CDATA[*/
|
||||
function checkIfAlreadySubmitted(){
|
||||
var url = $("input[name='url']").val();
|
||||
var sr = $("input[name='sr']").val();
|
||||
console.log(url);
|
||||
if(url.length >3 && sr.length > 3){
|
||||
$.post("checkIfAlreadySubmitted",{url: url, sr: sr}, function(data){
|
||||
var result = JSON.parse(data);
|
||||
if(result.length == 0){
|
||||
$("#checkResult").show().html("Not submitted before");
|
||||
}else{
|
||||
$("#checkResult").show().html('Already submitted <b><a target="_blank" href="http://www.reddit.com'+result[0].data.permalink+'">here</a></b>');
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
$("#checkResult").show().html("Too short url and/or subreddit");
|
||||
}
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
<title>Schedule to Reddit</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" th:href="@{/resources/autocomplete.css}"/>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
|
||||
<script th:src="@{/resources/validator.js}"></script>
|
||||
<style type="text/css">
|
||||
.btn.disabled{
|
||||
|
@ -36,11 +38,19 @@ border-color: #ddd;
|
|||
<br/><br/>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3">Subreddit</label>
|
||||
<span class="col-sm-9"><input name="sr" placeholder="Subreddit (e.g. kitten)" class="form-control" data-minlength="3" required="required"/></span>
|
||||
<span class="col-sm-9"><input id="sr" name="sr" placeholder="Subreddit (e.g. kitten)" class="form-control" data-minlength="3" required="required"/></span>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<div>
|
||||
<label class="col-sm-3">Send replies to my inbox</label> <span class="col-sm-9"><input type="checkbox" name="sendreplies" value="true"/></span>
|
||||
<label class="col-sm-3">Send replies to my inbox</label>
|
||||
<span class="col-sm-9"><input type="checkbox" name="sendreplies" value="true"/></span>
|
||||
</div>
|
||||
<br/>
|
||||
<br/>
|
||||
<div>
|
||||
<span class="col-sm-2"><a href="#" class="btn btn-default" onclick="checkIfAlreadySubmitted()">Check if already submitted</a></span>
|
||||
<span class="col-sm-1"></span>
|
||||
<span class=" col-sm-9"><span id="checkResult" class="alert alert-info" style="display:none"></span></span>
|
||||
</div>
|
||||
<br/><br/>
|
||||
|
||||
|
@ -62,8 +72,6 @@ border-color: #ddd;
|
|||
<div th:if="${session.PREDICTION_FEATURE.isActive()}">
|
||||
<button id="checkbtn" class="btn btn-default disabled" onclick="predicateResponse()">Predicate Response</button>
|
||||
<span id="prediction"></span>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
$("input").change(function() {
|
||||
|
@ -89,5 +97,35 @@ function predicateResponse(){
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function() {
|
||||
$( "#sr" ).autocomplete({
|
||||
source: "subredditAutoComplete"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
/*<![CDATA[*/
|
||||
function checkIfAlreadySubmitted(){
|
||||
var url = $("input[name='url']").val();
|
||||
var sr = $("input[name='sr']").val();
|
||||
console.log(url);
|
||||
if(url.length >3 && sr.length > 3){
|
||||
$.post("checkIfAlreadySubmitted",{url: url, sr: sr}, function(data){
|
||||
var result = JSON.parse(data);
|
||||
if(result.length == 0){
|
||||
$("#checkResult").show().html("Not submitted before");
|
||||
}else{
|
||||
$("#checkResult").show().html('Already submitted <b><a target="_blank" href="http://www.reddit.com'+result[0].data.permalink+'">here</a></b>');
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
$("#checkResult").show().html("Too short url and/or subreddit");
|
||||
}
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
.ui-autocomplete {
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
cursor: default;
|
||||
padding: 0;
|
||||
margin-top: 2px;
|
||||
list-style: none;
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #ccc
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.ui-autocomplete > li {
|
||||
padding: 3px 20px;
|
||||
}
|
||||
.ui-autocomplete > li.ui-state-focus {
|
||||
background-color: #DDD;
|
||||
}
|
||||
.ui-helper-hidden-accessible {
|
||||
display: none;
|
||||
}
|
Loading…
Reference in New Issue