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
Hide 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 @@
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency
>
<groupId>
org.springframework.boot
</groupId
>
<artifactId>
spring-boot-devtools
</artifactId
>
<scope>
runtime
</scope
>
<optional>
true
</optional
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>org.springframework.boot</groupId>--
>
<!-- <artifactId>spring-boot-devtools</artifactId>--
>
<!-- <scope>runtime</scope>--
>
<!-- <optional>true</optional>--
>
<!-- </dependency>--
>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<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;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
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
;
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
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.socket.BinaryMessage
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.WebSocketSession
;
...
...
@@ -14,14 +18,17 @@ import java.util.concurrent.ScheduledExecutorService;
import
java.util.concurrent.TimeUnit
;
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
{
private
WebSocketSession
session
;
private
static
final
String
WEBSOCKET_URL
=
"ws://localhost:8000/ws/emotion"
;
private
static
final
ScheduledExecutorService
scheduler
=
Executors
.
newSingleThreadScheduledExecutor
();
private
ActivityLogService
activityLogService
;
public
WebSocketClient
()
{
public
WebSocketClient
(
ActivityLogService
activityLogService
)
{
this
.
activityLogService
=
activityLogService
;
connectToWebSocket
();
}
...
...
@@ -77,6 +84,16 @@ public class WebSocketClient {
EmotionPrediction
lastPrediction
=
predictions
[
predictions
.
length
-
1
];
// Now you can work with the last prediction
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
);
}
}
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketConfig.java
View file @
61df0ae6
package
com.kaluwa.enterprises.babycarebackendservice.config
;
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
lombok.extern.slf4j.Slf4j
;
import
org.bytedeco.opencv.opencv_core.Algorithm
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.configurationprocessor.json.JSONStringer
;
...
...
@@ -25,6 +29,12 @@ import java.io.IOException;
@Slf4j
public
class
WebSocketConfig
implements
WebSocketConfigurer
{
private
final
ActivityLogService
activityLogService
;
public
WebSocketConfig
(
ActivityLogService
activityLogService
)
{
this
.
activityLogService
=
activityLogService
;
}
@Override
public
void
registerWebSocketHandlers
(
WebSocketHandlerRegistry
registry
)
{
registry
.
addHandler
(
new
VideoFrameHandler
(),
"/emotional/video-process"
).
setAllowedOrigins
(
"*"
);
...
...
@@ -33,7 +43,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Bean
@Qualifier
(
"customWebsocketClient"
)
public
WebSocketClient
customWebSocketClient
()
{
return
new
WebSocketClient
();
return
new
WebSocketClient
(
activityLogService
);
}
@Component
...
...
@@ -56,7 +66,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
sendBinaryMessageToClient
(
binaryData
);
// Optionally, send a text message
EmotionPrediction
emotionPrediction
=
new
EmotionPrediction
();
// E
xample
object
EmotionPrediction
emotionPrediction
=
new
EmotionPrediction
();
// E
mpty
object
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 {
public
final
static
String
USER_TABLE
=
"users"
;
public
final
static
String
BABY_TABLE
=
"babies"
;
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;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.InputStream
;
import
java.time.LocalDate
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
...
...
@@ -54,6 +55,7 @@ public class BabyDto {
private
String
notes
;
private
String
uniqKey
;
private
UserDto
user
;
private
byte
[]
imageData
;
@NotNull
(
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;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Document
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
com.kaluwa.enterprises.babycarebackendservice.service.DocumentService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.List
;
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
;
@Service
...
...
@@ -25,12 +31,13 @@ public class BabyServiceImpl implements BabyService {
private
final
BabyDao
babyDao
;
private
final
BabyMapper
babyMapper
;
private
final
DocumentDao
documentDao
;
private
final
DocumentService
documentService
;
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
)
{
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
,
DocumentService
documentService
)
{
this
.
babyDao
=
babyDao
;
this
.
babyMapper
=
babyMapper
;
this
.
documentDao
=
documentDao
;
this
.
documentService
=
documentService
;
}
@Override
...
...
@@ -49,7 +56,19 @@ public class BabyServiceImpl implements BabyService {
public
List
<
BabyDto
>
getAllBabies
()
{
log
.
info
(
"Inside baby service getAllBabies method"
);
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
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
...
...
@@ -100,10 +119,8 @@ public class BabyServiceImpl implements BabyService {
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
Optional
<
Document
>
documentOp
=
documentDao
.
findById
(
babyOp
.
get
().
getDocumentId
());
if
(
documentOp
.
isPresent
())
{
documentDao
.
deleteById
(
babyOp
.
get
().
getDocumentId
());
}
Optional
<
Document
>
documentOp
=
documentDao
.
findByTableNameAndUniqKeyAndDocumentType
(
BABY_TABLE
,
babyOp
.
get
().
getUniqKey
(),
IMAGE
);
documentOp
.
ifPresent
(
document
->
documentDao
.
deleteById
(
document
.
getDocumentId
()));
babyDao
.
deleteById
(
babyId
);
ResponseDto
responseDto
=
new
ResponseDto
();
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