Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bürokratt
Proof of Concepts
Initial chatbot 2020
chat-api
Commits
a1cd5a8c
Commit
a1cd5a8c
authored
Nov 27, 2020
by
henrik.prangel
Browse files
JUT-100 Add local elastic for dev env and change elastic service index methods to async
parent
5ad774aa
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/docker/elasticsearh.yml
0 → 100644
View file @
a1cd5a8c
version
:
'
2.2'
services
:
es01
:
image
:
docker.elastic.co/elasticsearch/elasticsearch:7.10.0
container_name
:
es01
environment
:
-
node.name=es01
-
cluster.name=es-docker-cluster
-
cluster.initial_master_nodes=es01
-
bootstrap.memory_lock=true
-
"
ES_JAVA_OPTS=-Xms512m
-Xmx512m"
ulimits
:
memlock
:
soft
:
-1
hard
:
-1
volumes
:
-
data01:/usr/share/elasticsearch/data
ports
:
-
9200:9200
networks
:
-
elastic
volumes
:
data01
:
driver
:
local
networks
:
elastic
:
driver
:
bridge
src/main/java/com/netgroup/riigibot/service/ChatService.java
View file @
a1cd5a8c
...
...
@@ -137,9 +137,7 @@ public class ChatService {
public
ChatDTO
createNewChatByMessage
(
MessageDTO
messageDTO
)
{
ChatDTO
newChat
=
new
ChatDTO
();
newChat
.
setSessionId
(
messageDTO
.
getSessionId
());
ChatDTO
savedChat
=
save
(
newChat
);
elasticService
.
indexChat
(
savedChat
);
return
savedChat
;
return
saveAndIndexChat
(
newChat
);
}
public
ChatDTO
getChatById
(
Long
chatId
)
{
...
...
@@ -153,8 +151,7 @@ public class ChatService {
public
void
updateChatWithMessageInformation
(
ChatDTO
chatDTO
,
MessageDTO
messageDTO
,
String
referer
)
{
chatDTO
.
setLastUserReferer
(
referer
);
chatDTO
.
setLastMessageId
(
messageDTO
.
getId
());
ChatDTO
savedChat
=
save
(
chatDTO
);
elasticService
.
indexChat
(
savedChat
);
saveAndIndexChat
(
chatDTO
);
}
public
ChatDTO
updateChatCommittedBotForCustomerService
(
ChatDTO
chatDTO
,
String
bot
)
{
...
...
@@ -166,23 +163,19 @@ public class ChatService {
public
ChatDTO
commitBotToChat
(
String
bot
,
ChatDTO
chatDTO
)
{
log
.
debug
(
"Committing bot {} to chat {}"
,
bot
,
chatDTO
.
getId
());
chatDTO
.
setCommittedBot
(
bot
);
ChatDTO
savedChat
=
save
(
chatDTO
);
elasticService
.
indexChat
(
savedChat
);
return
savedChat
;
return
saveAndIndexChat
(
chatDTO
);
}
public
void
commitAdminToChat
(
ChatDTO
chatDTO
,
Principal
principal
)
{
log
.
debug
(
"Committing admin {} to chat {}"
,
principal
.
getName
(),
chatDTO
.
getId
());
chatDTO
.
setCommittedAdmin
(
principal
.
getName
());
ChatDTO
savedChat
=
save
(
chatDTO
);
elasticService
.
indexChat
(
savedChat
);
saveAndIndexChat
(
chatDTO
);
}
public
void
updateChatNeedsCustomerServiceToTrue
(
ChatDTO
chatDTO
)
{
log
.
debug
(
"Setting needs-customer-service of chat {} to true"
,
chatDTO
.
getId
());
chatDTO
.
setNeedsCustomerService
(
true
);
ChatDTO
savedChat
=
save
(
chatDTO
);
elasticService
.
indexChat
(
savedChat
);
saveAndIndexChat
(
chatDTO
);
}
public
ChatDTO
getOrCreateChatForMessage
(
MessageDTO
userMessage
)
{
...
...
@@ -198,6 +191,10 @@ public class ChatService {
public
ChatDTO
endChat
(
ChatDTO
chatDTO
)
{
chatDTO
.
setEnded
(
Instant
.
now
());
return
saveAndIndexChat
(
chatDTO
);
}
private
ChatDTO
saveAndIndexChat
(
ChatDTO
chatDTO
)
{
ChatDTO
savedChat
=
save
(
chatDTO
);
elasticService
.
indexChat
(
savedChat
);
return
savedChat
;
...
...
src/main/java/com/netgroup/riigibot/service/ElasticService.java
View file @
a1cd5a8c
...
...
@@ -12,11 +12,15 @@ 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.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Controller
;
@Controller
public
class
ElasticService
{
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
ElasticService
.
class
);
private
final
ElasticMessageRepository
elasticMessageRepository
;
private
final
ElasticChatRepository
elasticChatRepository
;
private
final
ElasticMessageMapper
elasticMessageMapper
;
...
...
@@ -35,21 +39,33 @@ public class ElasticService {
this
.
elasticFeedbackRepository
=
elasticFeedbackRepository
;
}
public
MessageDTO
indexMessage
(
MessageDTO
messageDTO
)
{
ElasticMessage
message
=
elasticMessageMapper
.
toEntity
(
messageDTO
);
message
=
elasticMessageRepository
.
save
(
message
);
return
elasticMessageMapper
.
toDto
(
message
);
@Async
public
void
indexMessage
(
MessageDTO
messageDTO
)
{
try
{
ElasticMessage
message
=
elasticMessageMapper
.
toEntity
(
messageDTO
);
elasticMessageRepository
.
save
(
message
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Encountered error when indexing to elasticsearch: {}"
,
e
.
getMessage
());
}
}
public
ChatDTO
indexChat
(
ChatDTO
chatDTO
)
{
ElasticChat
chat
=
elasticChatMapper
.
toEntity
(
chatDTO
);
chat
=
elasticChatRepository
.
save
(
chat
);
return
elasticChatMapper
.
toDto
(
chat
);
@Async
public
void
indexChat
(
ChatDTO
chatDTO
)
{
try
{
ElasticChat
chat
=
elasticChatMapper
.
toEntity
(
chatDTO
);
elasticChatRepository
.
save
(
chat
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Encountered error when indexing to elasticsearch: {}"
,
e
.
getMessage
());
}
}
public
FeedbackDTO
indexFeedback
(
FeedbackDTO
feedbackDTO
)
{
ElasticFeedback
feedback
=
elasticFeedbackMapper
.
toEntity
(
feedbackDTO
);
feedback
=
elasticFeedbackRepository
.
save
(
feedback
);
return
elasticFeedbackMapper
.
toDto
(
feedback
);
@Async
public
void
indexFeedback
(
FeedbackDTO
feedbackDTO
)
{
try
{
ElasticFeedback
feedback
=
elasticFeedbackMapper
.
toEntity
(
feedbackDTO
);
elasticFeedbackRepository
.
save
(
feedback
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Encountered error when indexing to elasticsearch: {}"
,
e
.
getMessage
());
}
}
}
src/main/resources/config/application-dev.yml
View file @
a1cd5a8c
...
...
@@ -115,3 +115,5 @@ jhipster:
# ===================================================================
# application:
elasticsearch
:
endpoints
:
localhost
src/main/resources/config/application-prod.yml
View file @
a1cd5a8c
...
...
@@ -142,3 +142,5 @@ jhipster:
# application:
kafka
:
bootstrap-servers
:
10.1.15.25:9092
elasticsearch
:
endpoints
:
10.1.15.26
src/main/resources/config/application.yml
View file @
a1cd5a8c
...
...
@@ -175,5 +175,3 @@ kafka:
# ===================================================================
# application:
elasticsearch
:
endpoints
:
10.1.15.26
src/test/java/com/netgroup/riigibot/config/NoElasticSearchConfiguration.java
View file @
a1cd5a8c
...
...
@@ -6,7 +6,6 @@ import com.netgroup.riigibot.service.ElasticService;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.*;
@Configuration
...
...
@@ -17,9 +16,6 @@ public class NoElasticSearchConfiguration {
public
NoElasticSearchConfiguration
()
{
mockElasticService
=
mock
(
ElasticService
.
class
);
when
(
mockElasticService
.
indexChat
(
any
())).
thenReturn
(
null
);
when
(
mockElasticService
.
indexMessage
(
any
())).
thenReturn
(
null
);
mockElasticChatRepository
=
mock
(
ElasticChatRepository
.
class
);
mockElasticMessageRepository
=
mock
(
ElasticMessageRepository
.
class
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment