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

Commit

Permalink
Chore/cleanup (#44)
Browse files Browse the repository at this point in the history
* chore: clean up of some code in several places

* WIP

* chore: package renaming + little coverage increase

* feat: increased coverage + formatting by IntelliJ

* feat: comments adjusted

* fix: application layer had a dependency on the presentation layer

* chore: cleanup
  • Loading branch information
jobulcke authored Oct 30, 2023
1 parent edd73ab commit 93ed147
Show file tree
Hide file tree
Showing 54 changed files with 536 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class EventStreamConfig {
private String timestampPath;
private String timezoneId;
private Map<String, String> propertyPredicates;

public String getMemberType() {
return memberType;
}
Expand All @@ -31,7 +32,7 @@ public void setTimestampPath(String timestampPath) {
}

public Map<String, String> getPropertyPredicates() {
if(propertyPredicates == null) {
if (propertyPredicates == null) {
propertyPredicates = new HashMap<>();
}
return propertyPredicates;
Expand All @@ -42,7 +43,7 @@ public void setPropertyPredicates(Map<String, String> propertyPredicates) {
}

public ZoneId getTimezoneId() {
if(timezoneId == null) {
if (timezoneId == null) {
return ZoneOffset.UTC;
}
return ZoneId.of(timezoneId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.exceptions;

public class MemberTypeException extends RuntimeException {
private final String collection;
private final String memberType;

public MemberTypeException(String collection, String memberType) {
this.collection = collection;
this.memberType = memberType;

}

@Override
public String getMessage() {
return "Member of collection %s was not of expected type %s".formatted(collection, memberType);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.exceptions;

public class MissingCollectionException extends RuntimeException{
public class MissingCollectionException extends RuntimeException {
private final String collectionName;

public MissingCollectionException(String collectionName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.exceptions;

public class NoGeometryProvidedException extends RuntimeException {
@Override
public String getMessage() {
return "No geometry could be found in the provided member";
}
@Override
public String getMessage() {
return "No geometry could be found in the provided member";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class ResourceNotFoundException extends RuntimeException {
private final String type;
private final String id;

public ResourceNotFoundException(String type, String id) {
this.type = type;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.services;

import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.IngestedMemberDto;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.LineChartDto;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberDto;
import be.informatievlaanderen.vsds.demonstrator.member.rest.dtos.LineChartDto;
import org.locationtech.jts.geom.Geometry;

import java.time.LocalDateTime;
Expand All @@ -11,11 +11,12 @@
public interface MemberService {
void ingestMember(IngestedMemberDto ingestedMemberDto);

List<MemberDto> getMembersInRectangle(Geometry rectangleGeometry, String collectionName, LocalDateTime timestamp, String timePeriod);
List<MemberDto> getMembersInRectangle(Geometry rectangleGeometry, String collectionName, LocalDateTime timestamp);

MemberDto getMemberById(String memberId);

long getNumberOfMembers();

long getNumberOfMembersByCollection(String collection);

LineChartDto getLineChartDtos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.MissingCollectionException;
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.ResourceNotFoundException;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.IngestedMemberDto;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.LineChartDto;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberDto;
import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberIngestedEvent;
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.domain.member.valueobjects.Dataset;
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.valueobjects.HourCount;
import be.informatievlaanderen.vsds.demonstrator.member.domain.member.valueobjects.LineChart;
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.dtos.LineChartDto;
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.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.wololo.jts2geojson.GeoJSONWriter;

Expand All @@ -33,14 +34,14 @@ public class MemberServiceImpl implements MemberService {
private final GeoJSONWriter geoJSONWriter = new GeoJSONWriter();
private final MemberRepository repository;
private final StreamsConfig streams;
private final MessageController messageController;
private final ApplicationEventPublisher eventPublisher;
private static final Logger log = LoggerFactory.getLogger(MemberServiceImpl.class);


public MemberServiceImpl(MemberRepository repository, StreamsConfig streams, MessageController messageController) {
public MemberServiceImpl(MemberRepository repository, StreamsConfig streams, ApplicationEventPublisher eventPublisher) {
this.repository = repository;
this.streams = streams;
this.messageController = messageController;
this.eventPublisher = eventPublisher;
}

@Override
Expand All @@ -51,7 +52,7 @@ public void ingestMember(IngestedMemberDto ingestedMemberDto) {
Member member = ingestedMemberDto.getMember(eventStreamConfig);
repository.saveMember(member);
MemberDto memberDto = new MemberDto(member.getMemberId(), geoJSONWriter.write(member.getGeometry()), ingestedMemberDto.getCollection(), member.getTimestamp(), member.getIsVersionOf(), member.getProperties());
messageController.send(memberDto);
eventPublisher.publishEvent(new MemberIngestedEvent(memberDto));

log.info("new member ingested");
} catch (FactoryException | TransformException e) {
Expand All @@ -60,7 +61,7 @@ public void ingestMember(IngestedMemberDto ingestedMemberDto) {
}

@Override
public List<MemberDto> getMembersInRectangle(Geometry rectangleGeometry, String collectionName, LocalDateTime timestamp, String timePeriod) {
public List<MemberDto> getMembersInRectangle(Geometry rectangleGeometry, String collectionName, LocalDateTime timestamp) {
return repository.getMembersByGeometry(rectangleGeometry, collectionName, LocalDateTime.now().minusDays(7), timestamp)
.stream()
.collect(Collectors.groupingBy(Member::getIsVersionOf, Collectors.maxBy(Comparator.comparing(Member::getTimestamp))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import be.informatievlaanderen.vsds.demonstrator.member.application.config.EventStreamConfig;
import be.informatievlaanderen.vsds.demonstrator.member.application.config.StreamsConfig;
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.MembertypeException;
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.MemberTypeException;
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.MissingCollectionException;
import org.apache.jena.rdf.model.Model;
import org.springframework.stereotype.Service;

import static org.apache.jena.rdf.model.ResourceFactory.createProperty;
import static org.apache.jena.rdf.model.ResourceFactory.createResource;

@Service
public class MemberValidatorImpl implements MemberValidator {
private static final String RDF_SYNTAX_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";

private final StreamsConfig streams;

Expand All @@ -20,13 +24,12 @@ public MemberValidatorImpl(StreamsConfig streams) {
public void validate(Model member, String collectionName) {
EventStreamConfig streamConfig = streams.getStream(collectionName)
.orElseThrow(() -> new MissingCollectionException(collectionName));
if (!testMembertype(member, streamConfig.getMemberType())) {
throw new MembertypeException("todo", streamConfig.getMemberType());
if (!testMemberType(member, streamConfig.getMemberType())) {
throw new MemberTypeException(collectionName, streamConfig.getMemberType());
}
}

private boolean testMembertype(Model member, String memberType) {
//TODO
return true;
private boolean testMemberType(Model member, String memberType) {
return member.listStatements(null, createProperty(RDF_SYNTAX_TYPE), createResource(memberType)).hasNext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import org.opengis.referencing.operation.TransformException;
import org.opengis.util.FactoryException;

import java.time.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.dtos;
package be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects;

import be.informatievlaanderen.vsds.demonstrator.member.presentation.dtos.DataSetDto;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public MemberDto(String memberId, Geometry geojsonGeometry, String collection, L
public String getMemberId() {
return memberId;
}

public String getCollection() {
return collection;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects;

import org.jetbrains.annotations.NotNull;

public class MemberIngestedEvent {
private final MemberDto memberDto;

public MemberIngestedEvent(@NotNull MemberDto memberDto) {
this.memberDto = memberDto;
}

public MemberDto getMemberDto() {
return memberDto;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package be.informatievlaanderen.vsds.demonstrator.member.custom;

import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.IngestedMemberDto;
import jakarta.annotation.PostConstruct;
import org.apache.jena.datatypes.TypeMapper;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Statement;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.apache.jena.rdf.model.ResourceFactory.*;

Expand All @@ -38,7 +35,7 @@ private void initializeMeetpunten() {
.build();
String content = WebClient.builder().exchangeStrategies(strategies).baseUrl("http://miv.opendata.belfla.be/miv/configuratie/xml").build().get().retrieve()
.bodyToMono(String.class).block();
Document doc = Jsoup.parse(content, "", Parser.xmlParser());
Document doc = Jsoup.parse(Objects.requireNonNull(content), "", Parser.xmlParser());
for (Element e : doc.select("meetpunt")) {
String meetpuntId = e.attr("unieke_id");
String wkt = "POINT (" + e.select("lengtegraad_EPSG_4326").get(0).text().replace(",", ".") + " " + e.select("breedtegraad_EPSG_4326").get(0).text().replace(",", ".") + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

public interface MemberRepository {
void saveMember(Member geometry);

List<Member> getMembersByGeometry(Geometry geometry, String collectionName, LocalDateTime startTime, LocalDateTime endTime);

Optional<Member> findByMemberId(String memberId);

long getNumberOfMembers();

List<Member> findMembersByCollectionAfterLocalDateTime(String collection, LocalDateTime localDateTime);

long getNumberOfMembersByCollection(String collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ public class Dataset {
private final String collection;
private final long membersOutsideTimeFrame;
private final HourCount hourCount;

public Dataset(String collection, long membersOutsideTimeFrame, HourCount hourCount) {
this.collection=collection;
this.collection = collection;
this.membersOutsideTimeFrame = membersOutsideTimeFrame;
this.hourCount=hourCount;
this.hourCount = hourCount;
}

public String getCollection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public HourCount(List<Member> memberList) {
this.memberList = memberList;
}

public Map<LocalDateTime, Integer> getMemberCountByHour(){
public Map<LocalDateTime, Integer> getMemberCountByHour() {
return memberList
.stream()
.map(Member::getTimestamp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package be.informatievlaanderen.vsds.demonstrator.member.domain.member.valueobjects;

import be.informatievlaanderen.vsds.demonstrator.member.rest.dtos.DataSetDto;
import be.informatievlaanderen.vsds.demonstrator.member.presentation.dtos.DataSetDto;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@Entity(name = "member_entity")
@Table(indexes = {
@Index(columnList = "collection"),
@Index(columnList = "timestamp")
@Index(columnList = "collection"),
@Index(columnList = "timestamp")
})
public class MemberEntity {
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public long getNumberOfMembers() {
@Override
public List<Member> findMembersByCollectionAfterLocalDateTime(String collection, LocalDateTime localDateTime) {
return memberGeometryJpaRepo
.findByCollectionAndTimestampAfter(collection,localDateTime)
.findByCollectionAndTimestampAfter(collection, localDateTime)
.stream()
.map(MemberEntity::toDomainObject)
.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.dtos;
package be.informatievlaanderen.vsds.demonstrator.member.presentation.dtos;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.dtos;
package be.informatievlaanderen.vsds.demonstrator.member.presentation.dtos;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.dtos;
package be.informatievlaanderen.vsds.demonstrator.member.presentation.dtos;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest;
package be.informatievlaanderen.vsds.demonstrator.member.presentation.rest;

import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.InvalidGeometryProvidedException;
import be.informatievlaanderen.vsds.demonstrator.member.application.exceptions.NoGeometryProvidedException;
Expand Down
Loading

0 comments on commit 93ed147

Please sign in to comment.