Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Feat: Add membercounter (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: WouterLefever <wouter.lefever@hotmail.com>
  • Loading branch information
2 people authored and jobulcke committed Oct 10, 2023
1 parent 6cc6314 commit cfd28a6
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface MemberService {
List<MemberDto> getMembersInRectangle(Geometry rectangleGeometry, LocalDateTime timestamp, String timePeriod);

MemberDto getMemberById(String memberId);

long getNumberOfMembers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberDto;
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.entities.Member;
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.repositories.MemberRepository;
import be.informatievlaanderen.vsds.demonstrator.member.rest.MemberExceptionHandler;
import be.informatievlaanderen.vsds.demonstrator.member.rest.websocket.WebSocketConfig;
import be.informatievlaanderen.vsds.demonstrator.member.rest.websocket.MessageController;
import org.locationtech.jts.geom.Geometry;
import org.opengis.referencing.operation.TransformException;
import org.opengis.util.FactoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.wololo.jts2geojson.GeoJSONWriter;
import be.informatievlaanderen.vsds.demonstrator.member.rest.websocket.MessageController;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;

@Service
public class MemberServiceImpl implements MemberService {
Expand Down Expand Up @@ -66,4 +63,9 @@ public MemberDto getMemberById(String memberId) {
.map(memberGeometry -> new MemberDto(memberGeometry.getMemberId(), geoJSONWriter.write(memberGeometry.getGeometry()), memberGeometry.getTimestamp()))
.orElseThrow(() -> new ResourceNotFoundException("Member", memberId));
}

@Override
public long getNumberOfMembers() {
return repository.getNumberOfMembers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface MemberRepository {
void saveMember(Member geometry);
List<Member> getMembersByGeometry(Geometry geometry, LocalDateTime startTime, LocalDateTime endTime);
Optional<Member> findByMemberId(String memberId);

long getNumberOfMembers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public Optional<Member> findByMemberId(String memberId) {
.findById(memberId)
.map(entity -> new Member(entity.getMemberId(), entity.getGeometry(), entity.getTimestamp()));
}

@Override
public long getNumberOfMembers() {
return memberGeometryJpaRepo.count();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket;

import be.informatievlaanderen.vsds.demonstrator.member.application.services.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

@Controller
public class MemberCounterController {
private final SimpMessagingTemplate template;
private final MemberService memberService;

@Autowired
public MemberCounterController(SimpMessagingTemplate template, MemberService memberService) {
this.template = template;
this.memberService = memberService;
}

@Scheduled(fixedDelay = 60000)
public void send() {
long counter = memberService.getNumberOfMembers();
this.template.convertAndSend("/broker/membercounter", counter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Controller
public class MessageController {
private SimpMessagingTemplate template;
private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);
private static final Logger log = LoggerFactory.getLogger(MessageController.class);

@Autowired
public MessageController(SimpMessagingTemplate template) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket;

import be.informatievlaanderen.vsds.demonstrator.member.application.services.MemberServiceImpl;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.entities.Member;
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.repositories.MemberRepository;
import be.informatievlaanderen.vsds.demonstrator.member.rest.websocket.MessageController;
import be.informatievlaanderen.vsds.demonstrator.member.rest.websocket.WebSocketConfig;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFParser;
Expand Down Expand Up @@ -140,6 +139,13 @@ void test_saveMember() throws IOException {
verify(repository).saveMember(argThat(result -> result.getMemberId().equals(id)));
}

@Test
void test_getNumberOfMembers() {
service.getNumberOfMembers();

verify(repository).getNumberOfMembers();
}

private List<Member> initMembers() throws ParseException {
final WKTReader reader = new WKTReader();
List<Member> members = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ void test_Saving() {
verify(jpaRepository).save(argThat(entity -> entity.getMemberId().equals(member.getMemberId())));
}

@Test
void test_NumberCount(){
repository.getNumberOfMembers();

verify(jpaRepository).count();
}

private List<MemberEntity> initMembers() throws ParseException {
final WKTReader reader = new WKTReader();
List<MemberEntity> members = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket;

import be.informatievlaanderen.vsds.demonstrator.member.application.services.MemberService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.messaging.simp.SimpMessagingTemplate;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MemberCounterControllerTest {

@Mock
private MemberService memberService;
@Mock
private SimpMessagingTemplate simpMessagingTemplate;
@InjectMocks
private MemberCounterController memberCounterController;

@Test
void test(){
when(memberService.getNumberOfMembers()).thenReturn(76L);
memberCounterController.send();

verify(memberService).getNumberOfMembers();
verify(simpMessagingTemplate).convertAndSend("/broker/membercounter",76L);
}

}
6 changes: 5 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup>
import LeafletMap from './components/map/LeafletMap.vue'
import GlobalHeader from "@/components/headers/GlobalHeader.vue";
import MemberCounter from './components/membercounter/MemberCounter.vue'
</script>

<template>
Expand All @@ -20,7 +21,10 @@ import GlobalHeader from "@/components/headers/GlobalHeader.vue";
</div>

<hr class="divider content-separator">

<div>
<MemberCounter></MemberCounter>
</div>
<hr class="divider content-separator">
<div>
<LeafletMap></LeafletMap>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/graph/KnowledgeGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<svg id="knowledge-graph" class="linked-data-container" v-if="memberId"></svg>
<div class="linked-data-container" v-else>
<img src="../../assets/svgs/Linked%20data.svg" alt="Linked data" class="linked-data-icon"/>
<img src="../../assets/svgs/Linked_data.svg" alt="Linked data" class="linked-data-icon"/>
<h5 class="header5">Linked data</h5>
<small class="small-regular">Klik op een punt op de kaart om de kennisgrafiek te laden</small>
</div>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/headers/GlobalHeader.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div>
<div class="global-header">
<img src="../../assets/svgs/global-header/LOGO%20Vlaanderen%20NIV2.svg" alt="Vlaanderen">
<img class="small-global-header-divider" src="../../assets/svgs/global-header/divider%20globalheader.svg" alt="divider">
<img src="../../assets/svgs/global-header/LOGO_Vlaanderen_NIV2.svg" alt="Vlaanderen">
<img class="small-global-header-divider" src="../../assets/svgs/global-header/divider_globalheader.svg" alt="divider">
<span class="header-title header-font">Vlaamse Smart Data Space</span>
<span class="spacer"></span>
<div id="help-needed">
Expand All @@ -29,7 +29,7 @@
display: flex;
align-items: center;
gap: 5px;
background-image: url("src/assets/svgs/global-header/hulp nodig.svg");
background-image: url("src/assets/svgs/global-header/hulp_nodig.svg");
width: 144px;
height: 44px;
}
Expand Down
53 changes: 53 additions & 0 deletions frontend/src/components/membercounter/MemberCounter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<h1 class="header5 centered">Aantal members: {{ memberCounter }}</h1>
</template>

<script>
import "leaflet/dist/leaflet.css"
import Stomp from "webstomp-client";
export default {
name: "ConnectionState",
data() {
return {
memberCounter: 0,
stompClient: null
};
},
mounted() {
this.connect()
},
methods: {
//websocket
connect() {
this.stompClient = new Stomp.client('ws://localhost:8084/update', {debug: false});
this.stompClient.connect(
{},
() => {
this.stompClient.subscribe("/broker/membercounter", (memberCounter) => {
this.memberCounter = JSON.parse(memberCounter.body)
});
},
error => {
console.log(error);
this.connect()
}
);
},
disconnect() {
if (this.stompClient) {
this.stompClient.disconnect();
}
}
}
};
</script>

<style>
.centered {
text-align: center
}
</style>

0 comments on commit cfd28a6

Please sign in to comment.