Commit a6e802a1 authored by henrik.prangel's avatar henrik.prangel
Browse files

JUT-100 Add feedback and updated message indexing

parent 54fd5a4d
package com.netgroup.riigibot.domain.elastic;
import org.springframework.data.elasticsearch.annotations.Document;
import javax.persistence.*;
import java.time.Instant;
@Document(indexName = "chat_feedback", type = "")
public class ElasticFeedback {
@Id
private Long id;
private String value;
private String type;
private Instant created;
private Instant updated;
private Instant deleted;
private Long chatId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
public Instant getUpdated() {
return updated;
}
public void setUpdated(Instant updated) {
this.updated = updated;
}
public Instant getDeleted() {
return deleted;
}
public void setDeleted(Instant deleted) {
this.deleted = deleted;
}
public Long getChatId() {
return chatId;
}
public void setChatId(Long chatId) {
this.chatId = chatId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ElasticFeedback)) {
return false;
}
return id != null && id.equals(((ElasticFeedback) o).id);
}
@Override
public int hashCode() {
return 31;
}
}
package com.netgroup.riigibot.repository;
package com.netgroup.riigibot.repository.elastic;
import com.netgroup.riigibot.domain.elastic.ElasticChat;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
......
package com.netgroup.riigibot.repository.elastic;
import com.netgroup.riigibot.domain.elastic.ElasticFeedback;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ElasticFeedbackRepository extends ElasticsearchRepository<ElasticFeedback, Long> {
}
package com.netgroup.riigibot.repository;
package com.netgroup.riigibot.repository.elastic;
import com.netgroup.riigibot.domain.elastic.ElasticMessage;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
......
package com.netgroup.riigibot.service;
import com.netgroup.riigibot.repository.ElasticChatRepository;
import com.netgroup.riigibot.repository.ElasticMessageRepository;
import com.netgroup.riigibot.domain.elastic.ElasticFeedback;
import com.netgroup.riigibot.repository.elastic.ElasticChatRepository;
import com.netgroup.riigibot.repository.elastic.ElasticFeedbackRepository;
import com.netgroup.riigibot.repository.elastic.ElasticMessageRepository;
import com.netgroup.riigibot.domain.elastic.ElasticChat;
import com.netgroup.riigibot.domain.elastic.ElasticMessage;
import com.netgroup.riigibot.service.dto.ChatDTO;
import com.netgroup.riigibot.service.dto.FeedbackDTO;
import com.netgroup.riigibot.service.dto.MessageDTO;
import com.netgroup.riigibot.service.mapper.elastic.ElasticChatMapper;
import com.netgroup.riigibot.service.mapper.elastic.ElasticFeedbackMapper;
import com.netgroup.riigibot.service.mapper.elastic.ElasticMessageMapper;
import org.springframework.stereotype.Controller;
......@@ -17,13 +21,18 @@ public class ElasticService {
private final ElasticChatRepository elasticChatRepository;
private final ElasticMessageMapper elasticMessageMapper;
private final ElasticChatMapper elasticChatMapper;
private final ElasticFeedbackMapper elasticFeedbackMapper;
private final ElasticFeedbackRepository elasticFeedbackRepository;
public ElasticService(ElasticMessageRepository elasticMessageRepository, ElasticChatRepository elasticChatRepository,
ElasticMessageMapper elasticMessageMapper, ElasticChatMapper elasticChatMapper) {
ElasticMessageMapper elasticMessageMapper, ElasticChatMapper elasticChatMapper,
ElasticFeedbackMapper elasticFeedbackMapper, ElasticFeedbackRepository elasticFeedbackRepository) {
this.elasticMessageRepository = elasticMessageRepository;
this.elasticChatRepository = elasticChatRepository;
this.elasticMessageMapper = elasticMessageMapper;
this.elasticChatMapper = elasticChatMapper;
this.elasticFeedbackMapper = elasticFeedbackMapper;
this.elasticFeedbackRepository = elasticFeedbackRepository;
}
public MessageDTO indexMessage(MessageDTO messageDTO) {
......@@ -37,4 +46,10 @@ public class ElasticService {
chat = elasticChatRepository.save(chat);
return elasticChatMapper.toDto(chat);
}
public FeedbackDTO indexFeedback(FeedbackDTO feedbackDTO) {
ElasticFeedback feedback = elasticFeedbackMapper.toEntity(feedbackDTO);
feedback = elasticFeedbackRepository.save(feedback);
return elasticFeedbackMapper.toDto(feedback);
}
}
......@@ -129,7 +129,9 @@ public class MessageService {
MessageDTO messageDTO = findOne(messageId).orElseThrow(NoSuchElementException::new);
if (EnumUtils.isValidEnum(VoteValues.class, voteValue)) {
messageDTO.setVote(voteValue);
return save(messageDTO);
MessageDTO savedMessage = save(messageDTO);
elasticService.indexMessage(savedMessage);
return savedMessage;
} else {
throw new IllegalArgumentException("No such vote value exists:" + voteValue);
}
......
......@@ -13,7 +13,7 @@ public class MessageDTO implements Serializable {
private Long id;
@NotNull
@Size(max = 750)
@Size(max = 2000)
private String text;
@Size(max = 255)
......
package com.netgroup.riigibot.service.mapper.elastic;
import com.netgroup.riigibot.domain.elastic.ElasticFeedback;
import com.netgroup.riigibot.service.dto.FeedbackDTO;
import com.netgroup.riigibot.service.mapper.EntityMapper;
import org.mapstruct.Mapper;
/**
* Mapper for the entity {@link ElasticFeedback} and its DTO counterpart {@link FeedbackDTO}.
*/
@Mapper(componentModel = "spring", uses = {})
public interface ElasticFeedbackMapper extends EntityMapper<FeedbackDTO, ElasticFeedback> {
FeedbackDTO toDto(ElasticFeedback feedback);
ElasticFeedback toEntity(FeedbackDTO feedbackDTO);
}
package com.netgroup.riigibot.web.rest;
import com.netgroup.riigibot.service.ElasticService;
import com.netgroup.riigibot.service.FeedbackService;
import com.netgroup.riigibot.web.rest.errors.BadRequestAlertException;
import com.netgroup.riigibot.service.dto.FeedbackDTO;
......@@ -13,7 +14,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -39,8 +39,11 @@ public class FeedbackResource {
private final FeedbackService feedbackService;
public FeedbackResource(FeedbackService feedbackService) {
private final ElasticService elasticService;
public FeedbackResource(FeedbackService feedbackService, ElasticService elasticService) {
this.feedbackService = feedbackService;
this.elasticService = elasticService;
}
/**
......@@ -57,6 +60,7 @@ public class FeedbackResource {
throw new BadRequestAlertException("A new feedback cannot already have an ID", ENTITY_NAME, "idexists");
}
FeedbackDTO result = feedbackService.save(feedbackDTO);
elasticService.indexFeedback(result);
return ResponseEntity.created(new URI("/api/feedbacks/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString()))
.body(result);
......
......@@ -67,6 +67,7 @@ public class MessageResource {
throw new BadRequestAlertException("A new message cannot already have an ID", ENTITY_NAME, "idexists");
}
MessageDTO result = messageService.save(messageDTO);
elasticService.indexMessage(result);
return ResponseEntity
.created(new URI("/api/messages/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString()))
......@@ -89,6 +90,7 @@ public class MessageResource {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
MessageDTO result = messageService.save(messageDTO);
elasticService.indexMessage(result);
return ResponseEntity
.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, messageDTO.getId().toString()))
......
package com.netgroup.riigibot.config;
import com.netgroup.riigibot.repository.ElasticChatRepository;
import com.netgroup.riigibot.repository.ElasticMessageRepository;
import com.netgroup.riigibot.repository.elastic.ElasticChatRepository;
import com.netgroup.riigibot.repository.elastic.ElasticMessageRepository;
import com.netgroup.riigibot.service.ElasticService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment