This repository has been archived by the owner on Dec 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Refactored and added discarding logic #45
Open
mery25
wants to merge
6
commits into
scm-spain:master
Choose a base branch
from
mery25:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08fa57d
hello
mery25 0e8ea08
Added new endpoints. Added logic for the endpoints. Added new fiels o…
mery25 90377c7
Created Link entity. Added a list of links on the Tweet entity. Creat…
mery25 c08f5a9
Created TweetRepository, moved the persistence logic to the TweetRepo…
mery25 6d51a8e
separated the exceptions handling logic on a AdviceController. Create…
mery25 11a051e
Modified PatternExtractor, Created TextElementInserter with logic ex…
mery25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ build/ | |
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ | ||
.nb-gradle/ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
src/main/java/com/scmspain/configuration/TweetConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
package com.scmspain.configuration; | ||
|
||
import com.scmspain.controller.TweetController; | ||
import com.scmspain.services.TweetService; | ||
import org.springframework.boot.actuate.metrics.writer.MetricWriter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.persistence.EntityManager; | ||
import com.scmspain.controller.TweetController; | ||
import com.scmspain.repository.TweetRepository; | ||
import com.scmspain.services.TweetService; | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = "com.scmspain.exceptions") | ||
public class TweetConfiguration { | ||
@Bean | ||
public TweetService getTweetService(EntityManager entityManager, MetricWriter metricWriter) { | ||
return new TweetService(entityManager, metricWriter); | ||
public TweetService getTweetService(MetricWriter metricWriter, TweetRepository repository) { | ||
return new TweetService(metricWriter, repository); | ||
} | ||
|
||
@Bean | ||
public TweetController getTweetConfiguration(TweetService tweetService) { | ||
return new TweetController(tweetService); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/scmspain/controller/command/DiscardTweetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.scmspain.controller.command; | ||
|
||
public class DiscardTweetCommand { | ||
|
||
private Long tweetId; | ||
|
||
public Long getTweetId() { | ||
return tweetId; | ||
} | ||
|
||
public void setTweetId(Long tweetId) { | ||
this.tweetId = tweetId; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.scmspain.entities; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Link { | ||
|
||
public static final String REGEX_PATTERN = "\\b(http|https)://\\S+\\b"; | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String text; | ||
|
||
@Column(nullable = false) | ||
private int position; | ||
|
||
public Link() { | ||
} | ||
|
||
public Link(String text, int position) { | ||
super(); | ||
this.text = text; | ||
this.position = position; | ||
} | ||
|
||
public String getLinkText() { | ||
return text; | ||
} | ||
|
||
public int getPosition() { | ||
return position; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Link [linkText=" + text + ", position=" + position + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/scmspain/exceptions/CustomExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.scmspain.exceptions; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.validation.ConstraintViolationException; | ||
import javax.validation.ValidationException; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.context.request.WebRequest; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
import com.scmspain.controller.TweetController; | ||
import com.scmspain.exceptions.ExceptionResponse; | ||
import com.scmspain.exceptions.ResponseError; | ||
|
||
@EnableWebMvc | ||
@ControllerAdvice(assignableTypes = TweetController.class) | ||
public class CustomExceptionHandler { | ||
|
||
@ExceptionHandler(Exception.class) | ||
@ResponseBody | ||
public final ResponseEntity<ExceptionResponse> handleAllExceptions(Exception ex, WebRequest request) { | ||
ExceptionResponse exceptionResponse = new ExceptionResponse(ex.getMessage()); | ||
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@ExceptionHandler(ValidationException.class) | ||
@ResponseBody | ||
public final ResponseEntity<ExceptionResponse> invalidValidationException(ValidationException ex) { | ||
if (ex instanceof ConstraintViolationException) { | ||
List<ResponseError> errors = ((ConstraintViolationException) ex).getConstraintViolations().stream() | ||
.map(c -> new ResponseError("" + c.getPropertyPath(), c.getMessage())) | ||
.collect(Collectors.toList()); | ||
|
||
|
||
return new ResponseEntity<>(new ExceptionResponse("Invalid field(s)", errors), HttpStatus.BAD_REQUEST); | ||
} | ||
return new ResponseEntity<>(new ExceptionResponse(ex.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
@ExceptionHandler(TweetNotFoundException.class) | ||
@ResponseBody | ||
public final ResponseEntity<ExceptionResponse> invalidTweetNotFoundException(TweetNotFoundException ex) { | ||
return new ResponseEntity<>(new ExceptionResponse(ex.getMessage()), HttpStatus.NOT_FOUND); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is a bit complex, is it unit tested? Do you think should be in another class maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied same solution than for the PatternExtractor. Created a TextElementInsterter, which is a BiFunction that takes a list of TextElement and a String and returns a String. I have created test cases for TextElementInserter