Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutksefpt committed Apr 24, 2020
1 parent 82e3142 commit 5f2a9a1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import capstone.lip.landinformationportal.business.repository.FeedbackRepository;
import capstone.lip.landinformationportal.business.service.Interface.IFeedbackService;
import capstone.lip.landinformationportal.business.validation.FeedbackValidation;
import capstone.lip.landinformationportal.common.constant.FeedbackStatusConstant;
import capstone.lip.landinformationportal.common.entity.Feedback;
import capstone.lip.landinformationportal.common.utils.EmailSender;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class FeedbackService implements IFeedbackService {
Expand Down Expand Up @@ -58,8 +61,8 @@ public boolean delete(Feedback feedback) {
@Override
public Feedback findById(Long id) {
try {
if(id == null){
return null;
if (id == null) {
return null;
}
Optional<Feedback> temp = feedbackRepository.findById(id);
if (temp.isPresent()) {
Expand All @@ -75,11 +78,16 @@ public Feedback findById(Long id) {

@Override
public long countByFeedbackStatus(String feedbackStatus) {

try {
return feedbackRepository.countByFeedbackStatus(feedbackStatus);
if (!feedbackStatus.equals(FeedbackStatusConstant.OPEN) && !feedbackStatus.equals(FeedbackStatusConstant.CLOSE)) {
return -1;
} else {
return feedbackRepository.countByFeedbackStatus(feedbackStatus);
}
} catch (Exception e) {
e.printStackTrace();
return 0;
return -1;
}

}
Expand All @@ -88,6 +96,9 @@ public long countByFeedbackStatus(String feedbackStatus) {
public boolean sendFeedbackReply(Feedback feedback) {
try {
FeedbackValidation validate = new FeedbackValidation();
if(!feedbackRepository.existsById(feedback.getFeedBackID())){
throw new Exception();
}
String error = validate.isValidFeedback(feedback);
if (error.isEmpty()) {
error = validate.isValidFeedbackReply(feedback);
Expand All @@ -113,7 +124,15 @@ public Page<Feedback> findByFeedbackStatus(String feedbackStatus, Pageable page)
if (!error.isEmpty()) {
throw new Exception(error);
}
return feedbackRepository.findByFeedbackStatus(feedbackStatus, page);
Page<Feedback> tempPage = feedbackRepository.findByFeedbackStatus(feedbackStatus, page);
List<Feedback> listTemp = tempPage.stream().map(x -> x).collect(Collectors.toList());
// List<Feedback> listTemp = (List<Feedback>) tempPage;
if(listTemp.isEmpty() || listTemp == null){
throw new Exception();
}
else
return tempPage;

} catch (Exception e) {
e.printStackTrace();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,55 @@
import capstone.lip.landinformationportal.common.constant.ValidateMessageCommon;
import capstone.lip.landinformationportal.common.entity.Feedback;

public class FeedbackValidation extends StringValidation{
public String isValidFeedback(Feedback feedback) {
if (feedback.getFeedbackTitle() == null || feedback.getFeedbackContent() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackTitle().isEmpty() || feedback.getFeedbackContent().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
String error= isSpecialCharOnly(feedback.getFeedbackTitle());
if (!error.isEmpty()) {
return error;
}
error = isValidStatus(feedback);
if (!error.isEmpty()) {
return error;
}
if (feedback.getUser() == null) {
return "User not found";
}
return "";
}
public String isValidFeedbackReply(Feedback feedback) {
if (feedback.getFeedbackAdminReply() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackAdminReply().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
return "";
}
public String isValidStatus(Feedback feedback) {
if (feedback.getFeedbackStatus() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackStatus().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
if (!feedback.getFeedbackStatus().equals(FeedbackStatusConstant.OPEN) && !feedback.getFeedbackStatus().equals(FeedbackStatusConstant.CLOSE)) {
return "Invalid status";
}
return "";
}
public class FeedbackValidation extends StringValidation {

public String isValidFeedback(Feedback feedback) {
if (feedback.getFeedBackID() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedBackID() <=0) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackTitle() == null || feedback.getFeedbackContent() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackTitle().isEmpty() || feedback.getFeedbackContent().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
String error = isSpecialCharOnly(feedback.getFeedbackTitle());
if (!error.isEmpty()) {
return error;
}
error = isValidStatus(feedback);
if (!error.isEmpty()) {
return error;
}
if (feedback.getUser() == null) {
return "User not found";
}
return "";
}

public String isValidFeedbackReply(Feedback feedback) {
if (feedback.getFeedbackAdminReply() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackAdminReply().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
return "";
}

public String isValidStatus(Feedback feedback) {
if (feedback.getFeedbackStatus() == null) {
return ValidateMessageCommon.NULL;
}
if (feedback.getFeedbackStatus().isEmpty()) {
return ValidateMessageCommon.EMPTY;
}
if (!feedback.getFeedbackStatus().equals(FeedbackStatusConstant.OPEN) && !feedback.getFeedbackStatus().equals(FeedbackStatusConstant.CLOSE)) {
return "Invalid status";
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class FeedbackServiceTest_2 extends AbstractFeedbackServiceTest {
@Test
public void FT_FS_2_01() {

boolean result = instance.delete(sampleFeedback
.setFeedBackID(NULL_NOT_EXISTED_ID));
boolean result = instance.delete(getSampleFeedback()
.setFeedBackID(NULL_ID));

testFail(result);
}
Expand Down

0 comments on commit 5f2a9a1

Please sign in to comment.