Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
baby-monitoring-spring-backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
R24-145
baby-monitoring-spring-backend
Commits
61df0ae6
Commit
61df0ae6
authored
Oct 20, 2024
by
Ishankha K.C
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/chamode_dev' into 'master'
Feature/chamode dev See merge request
!6
parents
045a2635
404837a9
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
235 additions
and
17 deletions
+235
-17
pom.xml
pom.xml
+6
-6
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/AppConfig.java
.../enterprises/babycarebackendservice/config/AppConfig.java
+1
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketClient.java
...prises/babycarebackendservice/config/WebSocketClient.java
+19
-2
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketConfig.java
...prises/babycarebackendservice/config/WebSocketConfig.java
+12
-2
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/Configs.java
...enterprises/babycarebackendservice/constants/Configs.java
+5
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/LogTypes.java
...nterprises/babycarebackendservice/constants/LogTypes.java
+7
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/TableNames.java
...erprises/babycarebackendservice/constants/TableNames.java
+1
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dao/ActivityLogDao.java
...nterprises/babycarebackendservice/dao/ActivityLogDao.java
+12
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/ActivityLogDto.java
...nterprises/babycarebackendservice/dto/ActivityLogDto.java
+17
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
...aluwa/enterprises/babycarebackendservice/dto/BabyDto.java
+2
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/mappers/ActivityLogMapper.java
...ses/babycarebackendservice/mappers/ActivityLogMapper.java
+16
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/model/ActivityLog.java
...enterprises/babycarebackendservice/model/ActivityLog.java
+21
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/ActivityLogController.java
...es/babycarebackendservice/rest/ActivityLogController.java
+30
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/ActivityLogService.java
...es/babycarebackendservice/service/ActivityLogService.java
+13
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/ActivityLogServiceImpl.java
...rebackendservice/service/impl/ActivityLogServiceImpl.java
+49
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
.../babycarebackendservice/service/impl/BabyServiceImpl.java
+24
-7
No files found.
pom.xml
View file @
61df0ae6
...
@@ -47,12 +47,12 @@
...
@@ -47,12 +47,12 @@
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
<dependency
>
<!-- <dependency>--
>
<groupId>
org.springframework.boot
</groupId
>
<!-- <groupId>org.springframework.boot</groupId>--
>
<artifactId>
spring-boot-devtools
</artifactId
>
<!-- <artifactId>spring-boot-devtools</artifactId>--
>
<scope>
runtime
</scope
>
<!-- <scope>runtime</scope>--
>
<optional>
true
</optional
>
<!-- <optional>true</optional>--
>
</dependency
>
<!-- </dependency>--
>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/AppConfig.java
View file @
61df0ae6
...
@@ -2,6 +2,7 @@ package com.kaluwa.enterprises.babycarebackendservice.config;
...
@@ -2,6 +2,7 @@ package com.kaluwa.enterprises.babycarebackendservice.config;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketClient.java
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.config
;
package
com.kaluwa.enterprises.babycarebackendservice.config
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
com.kaluwa.enterprises.babycarebackendservice.socketHandlers.EmotionPrediction
;
import
com.kaluwa.enterprises.babycarebackendservice.socketHandlers.EmotionPrediction
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.socket.BinaryMessage
;
import
org.springframework.web.socket.BinaryMessage
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.WebSocketSession
;
...
@@ -14,14 +18,17 @@ import java.util.concurrent.ScheduledExecutorService;
...
@@ -14,14 +18,17 @@ import java.util.concurrent.ScheduledExecutorService;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
config
.
WebSocketConfig
.
VideoFrameHandler
.
sendTextMessageToClient
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
config
.
WebSocketConfig
.
VideoFrameHandler
.
sendTextMessageToClient
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Configs
.
WEBSOCKET_URL
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
LogTypes
.
EMOTION
;
public
class
WebSocketClient
{
public
class
WebSocketClient
{
private
WebSocketSession
session
;
private
WebSocketSession
session
;
private
static
final
String
WEBSOCKET_URL
=
"ws://localhost:8000/ws/emotion"
;
private
static
final
ScheduledExecutorService
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
();
private
static
final
ScheduledExecutorService
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
();
private
ActivityLogService
activityLogService
;
public
WebSocketClient
()
{
public
WebSocketClient
(
ActivityLogService
activityLogService
)
{
this
.
activityLogService
=
activityLogService
;
connectToWebSocket
();
connectToWebSocket
();
}
}
...
@@ -77,6 +84,16 @@ public class WebSocketClient {
...
@@ -77,6 +84,16 @@ public class WebSocketClient {
EmotionPrediction
lastPrediction
=
predictions
[
predictions
.
length
-
1
];
EmotionPrediction
lastPrediction
=
predictions
[
predictions
.
length
-
1
];
// Now you can work with the last prediction
// Now you can work with the last prediction
System
.
out
.
println
(
"Last emotion prediction: "
+
lastPrediction
);
System
.
out
.
println
(
"Last emotion prediction: "
+
lastPrediction
);
// Save the last prediction to the database
if
(
lastPrediction
.
getEmotion
()
!=
null
&&
!
lastPrediction
.
getEmotion
().
isEmpty
())
{
ActivityLogDto
activityLogDto
=
new
ActivityLogDto
();
activityLogDto
.
setActivityLogType
(
EMOTION
);
activityLogDto
.
setActivityLogDescription
(
lastPrediction
.
getEmotion
());
webSocketClient
.
activityLogService
.
saveActivityLog
(
activityLogDto
);
}
// Send the last prediction to the client
sendTextMessageToClient
(
lastPrediction
);
sendTextMessageToClient
(
lastPrediction
);
}
}
}
}
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketConfig.java
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.config
;
package
com.kaluwa.enterprises.babycarebackendservice.config
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.kaluwa.enterprises.babycarebackendservice.dao.ActivityLogDao
;
import
com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
com.kaluwa.enterprises.babycarebackendservice.socketHandlers.EmotionPrediction
;
import
com.kaluwa.enterprises.babycarebackendservice.socketHandlers.EmotionPrediction
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.bytedeco.opencv.opencv_core.Algorithm
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.configurationprocessor.json.JSONStringer
;
import
org.springframework.boot.configurationprocessor.json.JSONStringer
;
...
@@ -25,6 +29,12 @@ import java.io.IOException;
...
@@ -25,6 +29,12 @@ import java.io.IOException;
@Slf4j
@Slf4j
public
class
WebSocketConfig
implements
WebSocketConfigurer
{
public
class
WebSocketConfig
implements
WebSocketConfigurer
{
private
final
ActivityLogService
activityLogService
;
public
WebSocketConfig
(
ActivityLogService
activityLogService
)
{
this
.
activityLogService
=
activityLogService
;
}
@Override
@Override
public
void
registerWebSocketHandlers
(
WebSocketHandlerRegistry
registry
)
{
public
void
registerWebSocketHandlers
(
WebSocketHandlerRegistry
registry
)
{
registry
.
addHandler
(
new
VideoFrameHandler
(),
"/emotional/video-process"
).
setAllowedOrigins
(
"*"
);
registry
.
addHandler
(
new
VideoFrameHandler
(),
"/emotional/video-process"
).
setAllowedOrigins
(
"*"
);
...
@@ -33,7 +43,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
...
@@ -33,7 +43,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Bean
@Bean
@Qualifier
(
"customWebsocketClient"
)
@Qualifier
(
"customWebsocketClient"
)
public
WebSocketClient
customWebSocketClient
()
{
public
WebSocketClient
customWebSocketClient
()
{
return
new
WebSocketClient
();
return
new
WebSocketClient
(
activityLogService
);
}
}
@Component
@Component
...
@@ -56,7 +66,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
...
@@ -56,7 +66,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
sendBinaryMessageToClient
(
binaryData
);
sendBinaryMessageToClient
(
binaryData
);
// Optionally, send a text message
// Optionally, send a text message
EmotionPrediction
emotionPrediction
=
new
EmotionPrediction
();
// E
xample
object
EmotionPrediction
emotionPrediction
=
new
EmotionPrediction
();
// E
mpty
object
sendTextMessageToClient
(
emotionPrediction
);
sendTextMessageToClient
(
emotionPrediction
);
}
}
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/Configs.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.constants
;
public
class
Configs
{
public
static
final
String
WEBSOCKET_URL
=
"ws://localhost:8000/ws/emotion"
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/LogTypes.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.constants
;
public
class
LogTypes
{
public
static
final
String
EMOTION
=
"EMOTION"
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/TableNames.java
View file @
61df0ae6
...
@@ -5,5 +5,6 @@ public class TableNames {
...
@@ -5,5 +5,6 @@ public class TableNames {
public
final
static
String
USER_TABLE
=
"users"
;
public
final
static
String
USER_TABLE
=
"users"
;
public
final
static
String
BABY_TABLE
=
"babies"
;
public
final
static
String
BABY_TABLE
=
"babies"
;
public
final
static
String
DOCUMENT_TABLE
=
"documents"
;
public
final
static
String
DOCUMENT_TABLE
=
"documents"
;
public
final
static
String
ACTIVITY_LOG_TABLE
=
"activity_logs"
;
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dao/ActivityLogDao.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.dao
;
import
com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
ActivityLogDao
extends
JpaRepository
<
ActivityLog
,
Long
>
{
List
<
ActivityLog
>
findAllByOrderByActivityLogIdDesc
();
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/ActivityLogDto.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
import
lombok.*
;
import
java.io.Serializable
;
/**
* DTO for {@link com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog}
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public
class
ActivityLogDto
implements
Serializable
{
private
Long
activityLogId
;
private
String
activityLogType
;
private
String
activityLogDescription
;
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
View file @
61df0ae6
...
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
...
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
java.io.InputStream
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
...
@@ -54,6 +55,7 @@ public class BabyDto {
...
@@ -54,6 +55,7 @@ public class BabyDto {
private
String
notes
;
private
String
notes
;
private
String
uniqKey
;
private
String
uniqKey
;
private
UserDto
user
;
private
UserDto
user
;
private
byte
[]
imageData
;
@NotNull
(
message
=
"Logged user id is required"
)
@NotNull
(
message
=
"Logged user id is required"
)
@NotEmpty
(
message
=
"Logged user id is required"
)
@NotEmpty
(
message
=
"Logged user id is required"
)
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/mappers/ActivityLogMapper.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.mappers
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto
;
import
com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog
;
import
org.mapstruct.*
;
import
java.util.List
;
@Mapper
(
componentModel
=
"spring"
)
public
interface
ActivityLogMapper
{
ActivityLog
toEntity
(
ActivityLogDto
activityLogDto
);
ActivityLogDto
toDto
(
ActivityLog
activityLog
);
List
<
ActivityLogDto
>
listToDto
(
List
<
ActivityLog
>
activityLogs
);
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/model/ActivityLog.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.model
;
import
jakarta.persistence.*
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
TableNames
.
ACTIVITY_LOG_TABLE
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table
(
name
=
ACTIVITY_LOG_TABLE
)
public
class
ActivityLog
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Long
activityLogId
;
private
String
activityLogType
;
private
String
activityLogDescription
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/ActivityLogController.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.rest
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/activity-logs"
)
@Slf4j
public
class
ActivityLogController
{
private
final
ActivityLogService
activityLogService
;
public
ActivityLogController
(
ActivityLogService
activityLogService
)
{
this
.
activityLogService
=
activityLogService
;
}
@GetMapping
public
ResponseEntity
<
List
<
ActivityLogDto
>>
getAllActivityLogs
()
{
log
.
info
(
"Inside activity log controller getAllActivityLogs method"
);
return
activityLogService
.
getAllActivityLogs
();
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/ActivityLogService.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.service
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto
;
import
org.springframework.http.ResponseEntity
;
import
java.util.List
;
public
interface
ActivityLogService
{
ActivityLogDto
saveActivityLog
(
ActivityLogDto
activityLogDto
);
ResponseEntity
<
List
<
ActivityLogDto
>>
getAllActivityLogs
();
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/ActivityLogServiceImpl.java
0 → 100644
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.service.impl
;
import
com.kaluwa.enterprises.babycarebackendservice.dao.ActivityLogDao
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto
;
import
com.kaluwa.enterprises.babycarebackendservice.error.BadRequestAlertException
;
import
com.kaluwa.enterprises.babycarebackendservice.mappers.ActivityLogMapper
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
@Slf4j
public
class
ActivityLogServiceImpl
implements
ActivityLogService
{
private
final
ActivityLogDao
activityLogDao
;
private
final
ActivityLogMapper
activityLogMapper
;
public
ActivityLogServiceImpl
(
ActivityLogDao
activityLogDao
,
ActivityLogMapper
activityLogMapper
)
{
this
.
activityLogDao
=
activityLogDao
;
this
.
activityLogMapper
=
activityLogMapper
;
}
@Override
public
ActivityLogDto
saveActivityLog
(
ActivityLogDto
activityLogDto
)
{
log
.
info
(
"Inside saveActivityLog method in ActivityLogServiceImpl"
);
try
{
return
activityLogMapper
.
toDto
(
activityLogDao
.
save
(
activityLogMapper
.
toEntity
(
activityLogDto
)));
}
catch
(
Exception
e
)
{
log
.
error
(
"Error occurred while saving activity log: {}"
,
e
.
getMessage
());
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"ActivityLog"
,
"errorSavingActivityLog"
);
}
}
@Override
public
ResponseEntity
<
List
<
ActivityLogDto
>>
getAllActivityLogs
()
{
log
.
info
(
"Inside getAllActivityLogs method in ActivityLogServiceImpl"
);
try
{
return
ResponseEntity
.
ok
(
activityLogMapper
.
listToDto
(
activityLogDao
.
findAllByOrderByActivityLogIdDesc
()));
}
catch
(
Exception
e
)
{
log
.
error
(
"Error occurred while fetching activity logs: {}"
,
e
.
getMessage
());
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"ActivityLog"
,
"errorFetchingActivityLogs"
);
}
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
View file @
61df0ae6
...
@@ -9,14 +9,20 @@ import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
...
@@ -9,14 +9,20 @@ import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Document
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Document
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
com.kaluwa.enterprises.babycarebackendservice.service.DocumentService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
DocumentTypes
.
IMAGE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
TableNames
.
BABY_TABLE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
utils
.
Utils
.
uniqKeyGenerator
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
utils
.
Utils
.
uniqKeyGenerator
;
@Service
@Service
...
@@ -25,12 +31,13 @@ public class BabyServiceImpl implements BabyService {
...
@@ -25,12 +31,13 @@ public class BabyServiceImpl implements BabyService {
private
final
BabyDao
babyDao
;
private
final
BabyDao
babyDao
;
private
final
BabyMapper
babyMapper
;
private
final
BabyMapper
babyMapper
;
private
final
DocumentDao
documentDao
;
private
final
DocumentDao
documentDao
;
private
final
DocumentService
documentService
;
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
,
DocumentService
documentService
)
{
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
)
{
this
.
babyDao
=
babyDao
;
this
.
babyDao
=
babyDao
;
this
.
babyMapper
=
babyMapper
;
this
.
babyMapper
=
babyMapper
;
this
.
documentDao
=
documentDao
;
this
.
documentDao
=
documentDao
;
this
.
documentService
=
documentService
;
}
}
@Override
@Override
...
@@ -49,7 +56,19 @@ public class BabyServiceImpl implements BabyService {
...
@@ -49,7 +56,19 @@ public class BabyServiceImpl implements BabyService {
public
List
<
BabyDto
>
getAllBabies
()
{
public
List
<
BabyDto
>
getAllBabies
()
{
log
.
info
(
"Inside baby service getAllBabies method"
);
log
.
info
(
"Inside baby service getAllBabies method"
);
try
{
try
{
return
babyMapper
.
toDtoList
(
babyDao
.
findAll
());
List
<
BabyDto
>
babyList
=
babyMapper
.
toDtoList
(
babyDao
.
findAll
());
babyList
.
forEach
(
babyDto
->
{
Optional
<
Document
>
documentOp
=
documentDao
.
findByTableNameAndUniqKeyAndDocumentType
(
BABY_TABLE
,
babyDto
.
getUniqKey
(),
IMAGE
);
documentOp
.
ifPresent
(
document
->
{
byte
[]
imageData
=
documentService
.
getImage
(
BABY_TABLE
,
babyDto
.
getUniqKey
()).
getBody
();
if
(
imageData
!=
null
)
{
babyDto
.
setImageData
(
imageData
);
}
});
});
return
babyList
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
...
@@ -100,10 +119,8 @@ public class BabyServiceImpl implements BabyService {
...
@@ -100,10 +119,8 @@ public class BabyServiceImpl implements BabyService {
if
(
babyOp
.
isEmpty
())
{
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
}
else
{
Optional
<
Document
>
documentOp
=
documentDao
.
findById
(
babyOp
.
get
().
getDocumentId
());
Optional
<
Document
>
documentOp
=
documentDao
.
findByTableNameAndUniqKeyAndDocumentType
(
BABY_TABLE
,
babyOp
.
get
().
getUniqKey
(),
IMAGE
);
if
(
documentOp
.
isPresent
())
{
documentOp
.
ifPresent
(
document
->
documentDao
.
deleteById
(
document
.
getDocumentId
()));
documentDao
.
deleteById
(
babyOp
.
get
().
getDocumentId
());
}
babyDao
.
deleteById
(
babyId
);
babyDao
.
deleteById
(
babyId
);
ResponseDto
responseDto
=
new
ResponseDto
();
ResponseDto
responseDto
=
new
ResponseDto
();
responseDto
.
setId
(
babyId
);
responseDto
.
setId
(
babyId
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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