Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
C
CUREX
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alberto Blázquez Herranz
CUREX
Commits
c3927661
Commit
c3927661
authored
Dec 22, 2020
by
David Fernandez Lobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notification
parent
12a79968
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
1 deletion
+158
-1
src/main/java/adt/mainnode/controller/NotificationController.java
.../java/adt/mainnode/controller/NotificationController.java
+53
-0
src/main/java/adt/mainnode/controller/WebController.java
src/main/java/adt/mainnode/controller/WebController.java
+1
-0
src/main/java/adt/mainnode/dto/NotificationDto.java
src/main/java/adt/mainnode/dto/NotificationDto.java
+38
-0
src/main/java/adt/mainnode/entity/Notification.java
src/main/java/adt/mainnode/entity/Notification.java
+26
-0
src/main/java/adt/mainnode/repository/NotificationRepository.java
.../java/adt/mainnode/repository/NotificationRepository.java
+8
-0
src/main/java/adt/mainnode/service/NotificationService.java
src/main/java/adt/mainnode/service/NotificationService.java
+31
-0
src/main/resources/application.yml
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/adt/mainnode/controller/NotificationController.java
0 → 100644
View file @
c3927661
package
adt
.
mainnode
.
controller
;
import
adt.mainnode.entity.Credentials
;
import
adt.mainnode.entity.Notification
;
import
adt.mainnode.repository.CredentialsRepository
;
import
adt.mainnode.service.NotificationService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
@RestController
@RequestMapping
(
"notifications"
)
@Api
(
value
=
"/notifications"
,
//"/asset",
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
tags
=
{
"Notifications"
}
)
@Slf4j
public
class
NotificationController
{
private
final
CredentialsRepository
credentialsRepository
;
private
final
NotificationService
notificationService
;
@Autowired
public
NotificationController
(
CredentialsRepository
credentialsRepository
,
NotificationService
notificationService
){
this
.
credentialsRepository
=
credentialsRepository
;
this
.
notificationService
=
notificationService
;
}
@CrossOrigin
@ApiOperation
(
value
=
"Save a new set of notification"
,
response
=
Boolean
.
class
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
@PostMapping
(
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
boolean
saveAssets
(
HttpServletResponse
response
,
@RequestBody
Notification
notification
,
@RequestParam
String
token
)
{
Credentials
credential
=
credentialsRepository
.
findByToken
(
token
);
if
(
credential
!=
null
&&
credential
.
getStatus
().
equals
(
"OPERATIVE"
))
{
if
(
credential
.
getAvailableEndpoint
().
contains
(
"(POST) notifications/"
))
{
log
.
info
(
"New notification received"
);
notificationService
.
saveNotification
(
notification
,
credential
);
return
true
;
}
}
return
false
;
}
}
src/main/java/adt/mainnode/controller/WebController.java
View file @
c3927661
...
...
@@ -92,6 +92,7 @@ public class WebController {
arr
.
add
(
"(POST) nlp/"
);
arr
.
add
(
"(GET) virt_query/"
);
arr
.
add
(
"(POST) event/"
);
arr
.
add
(
"(POST) notifications/"
);
arr
.
add
(
"Visualization Service"
);
user_types
=
new
ArrayList
<
String
>();
...
...
src/main/java/adt/mainnode/dto/NotificationDto.java
0 → 100644
View file @
c3927661
package
adt
.
mainnode
.
dto
;
import
adt.mainnode.entity.Notification
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
@Data
@Entity
public
class
NotificationDto
{
@Id
@GeneratedValue
private
Long
id
;
@JsonProperty
(
"Node_Id"
)
private
String
node_Id
;
@JsonProperty
(
"Ip"
)
private
String
ip
;
@JsonProperty
(
"port"
)
private
String
port
;
@JsonProperty
(
"timestamp"
)
private
double
timestamp
;
public
static
NotificationDto
createNotification
(
Notification
notification
,
String
node_Id
){
NotificationDto
result
=
new
NotificationDto
();
result
.
setIp
(
notification
.
getIp
());
result
.
setPort
(
notification
.
getPort
());
result
.
setTimestamp
(
notification
.
getTimestamp
());
result
.
setNode_Id
(
node_Id
);
return
result
;
}
}
src/main/java/adt/mainnode/entity/Notification.java
0 → 100644
View file @
c3927661
package
adt
.
mainnode
.
entity
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
@Data
@Entity
public
class
Notification
{
@Id
@GeneratedValue
private
Long
id
;
@JsonProperty
(
"Ip"
)
private
String
ip
;
@JsonProperty
(
"port"
)
private
String
port
;
@JsonProperty
(
"timestamp"
)
private
double
timestamp
;
}
src/main/java/adt/mainnode/repository/NotificationRepository.java
0 → 100644
View file @
c3927661
package
adt
.
mainnode
.
repository
;
import
adt.mainnode.dto.NotificationDto
;
import
adt.mainnode.entity.Notification
;
import
org.springframework.data.jpa.repository.JpaRepository
;
public
interface
NotificationRepository
extends
JpaRepository
<
NotificationDto
,
String
>
{
}
src/main/java/adt/mainnode/service/NotificationService.java
0 → 100644
View file @
c3927661
package
adt
.
mainnode
.
service
;
import
adt.mainnode.dto.NotificationDto
;
import
adt.mainnode.entity.Credentials
;
import
adt.mainnode.entity.Node
;
import
adt.mainnode.entity.Notification
;
import
adt.mainnode.repository.NodeRepository
;
import
adt.mainnode.repository.NotificationRepository
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
@Slf4j
public
class
NotificationService
{
private
final
NodeRepository
nodeRepository
;
private
final
NotificationRepository
notificationRepository
;
@Autowired
public
NotificationService
(
NodeRepository
nodeRepository
,
NotificationRepository
notificationRepository
){
this
.
nodeRepository
=
nodeRepository
;
this
.
notificationRepository
=
notificationRepository
;
}
public
void
saveNotification
(
Notification
notification
,
Credentials
credential
){
Node
node
=
nodeRepository
.
findByNodeId
(
credential
.
getName
());
NotificationDto
notificationDto
=
NotificationDto
.
createNotification
(
notification
,
node
.
getNodeId
());
//TODO Hacer en la web la visualizacion de la notificacion
notificationRepository
.
save
(
notificationDto
);
}
}
src/main/resources/application.yml
View file @
c3927661
logging
:
file
:
logs/mainNode.log
debug
:
true
#
debug: true
spring
:
datasource
:
...
...
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