SI-1358, SI-1361 POST UND DELETE Service für channels erstellt
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java
index 44c3516..2a1c474 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/FailureInformationController.java
@@ -23,6 +23,7 @@
import org.eclipse.openk.gridfailureinformation.exceptions.BadRequestException;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationPublicationChannelDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
@@ -153,4 +154,32 @@
return failureInformationService.updateSubordinatedFailureInfos(failureInfoUuid, listSubordinatedUuids);
}
+ @PostMapping("/{failureInfoUuid}/channels")
+ @ApiOperation(value = "Insert eines Veröffentlichungs-Kanals für eine Störungsinfo")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
+ @ApiResponse(code = 404, message = "Störungsinformationen wurden nicht gefunden")})
+ @ResponseStatus(HttpStatus.OK)
+ @Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
+ public FailureInformationPublicationChannelDto insertChannelForFailureInfo(
+ @ApiParam(name="failureInfoUuid", value= "UUID der Störungsinfo", required = true)
+ @PathVariable UUID failureInfoUuid,
+ @RequestParam String publicationChannel) {
+
+ return failureInformationService.insertPublicationChannelForFailureInfo(failureInfoUuid, publicationChannel);
+ }
+
+ @DeleteMapping("/{failureInfoUuid}/channels")
+ @ApiOperation(value = "Insert eines Veröffentlichungs-Kanals für eine Störungsinfo")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
+ @ApiResponse(code = 404, message = "Störungsinformationen wurden nicht gefunden")})
+ @ResponseStatus(HttpStatus.OK)
+ @Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
+ public void deleteChannelForFailureInfo(
+ @ApiParam(name="failureInfoUuid", value= "UUID der Störungsinfo", required = true)
+ @PathVariable UUID failureInfoUuid,
+ @RequestParam String publicationChannel) {
+
+ failureInformationService.deletePublicationChannelForFailureInfo(failureInfoUuid, publicationChannel);
+ }
+
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureInformationPublicationChannelMapper.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureInformationPublicationChannelMapper.java
new file mode 100644
index 0000000..13bcc7c
--- /dev/null
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/FailureInformationPublicationChannelMapper.java
@@ -0,0 +1,39 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.gridfailureinformation.mapper;
+
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationPublicationChannel;
+import org.eclipse.openk.gridfailureinformation.model.TblFailureInformationStation;
+import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationPublicationChannelDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationStationDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+import org.mapstruct.ReportingPolicy;
+
+@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface FailureInformationPublicationChannelMapper {
+ @Mappings({
+ @Mapping(source = "tblFailureInformation.uuid", target = "failureInformationId")
+ })
+ FailureInformationPublicationChannelDto toFailureInformationPublicationChannelDto(TblFailureInformationPublicationChannel tblFailureInformationPublicationChannel);
+
+
+// @Mappings({
+// @Mapping(target = "fkTblFailureInformation", source = "failureInformationId")
+// })
+ TblFailureInformationPublicationChannel toTblFailureInformationPublicationChannel(FailureInformationPublicationChannelDto failureInformationPublicationChannelDto);
+
+}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/model/TblFailureInformationPublicationChannel.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/model/TblFailureInformationPublicationChannel.java
index 3be8bc6..326103b 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/model/TblFailureInformationPublicationChannel.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/model/TblFailureInformationPublicationChannel.java
@@ -15,10 +15,14 @@
package org.eclipse.openk.gridfailureinformation.model;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import javax.persistence.*;
-@Data
+//@Data
+@Getter
+@Setter
@Entity
public class TblFailureInformationPublicationChannel {
@Id
@@ -37,8 +41,4 @@
private boolean published;
-
-// @ManyToOne
-// private Supplier supplier;
-
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationPublicationChannelRepository.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationPublicationChannelRepository.java
index 481e0bd..59fbaf2 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationPublicationChannelRepository.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/FailureInformationPublicationChannelRepository.java
@@ -21,12 +21,16 @@
import org.springframework.stereotype.Repository;
import java.util.List;
+import java.util.Optional;
@Repository
public interface FailureInformationPublicationChannelRepository extends JpaRepository<TblFailureInformationPublicationChannel, Long > {
List<TblFailureInformationPublicationChannel> findByTblFailureInformation(TblFailureInformation tblFailureInformation);
- //List<TblFailureInformationPublicationChannel> findByPublicationChannel(String publicationChannel);
int countByTblFailureInformationAndPublicationChannel(TblFailureInformation tblFailureInformation, String publicationChannel);
+ Optional<TblFailureInformationPublicationChannel> findByTblFailureInformationAndPublicationChannel(TblFailureInformation tblFailureInformation, String publicationChannel);
+ //TblFailureInformationPublicationChannel countByTblFailureInformationAndPublicationChannel(TblFailureInformation tblFailureInformation, String publicationChannel);
+ void deleteByTblFailureInformationAndPublicationChannel(TblFailureInformation tblFailureInformation, String publicationChannel);
+
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
index bdcb5b2..83e05f1 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/FailureInformationService.java
@@ -27,10 +27,12 @@
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
+import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationPublicationChannelMapper;
import org.eclipse.openk.gridfailureinformation.model.*;
import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.util.GrahamScan;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationPublicationChannelDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -58,6 +60,9 @@
private FailureInformationMapper failureInformationMapper;
@Autowired
+ private FailureInformationPublicationChannelMapper failureInformationPublicationChannelMapper;
+
+ @Autowired
private BranchRepository branchRepository;
@Autowired
@@ -225,9 +230,9 @@
resolveExpectedReason(destTblFailureInformation, sourceDto);
resolveCondensed(destTblFailureInformation, sourceDto);
- if(sourceDto.getPublicationChannels() != null){
- updatePublicationChannels(sourceDto, destTblFailureInformation);
- }
+// if(sourceDto.getPublicationChannels() != null){
+// updatePublicationChannels(sourceDto, destTblFailureInformation);
+// }
resolveStationIds(destTblFailureInformation, sourceDto);
resolveDistributionGroups(destTblFailureInformation, sourceDto);
@@ -641,57 +646,93 @@
}
-public List<ArrayList<BigDecimal>> getPolygonCoordinatesForStationUuids (List<UUID> stationUuids) {
+ public List<ArrayList<BigDecimal>> getPolygonCoordinatesForStationUuids (List<UUID> stationUuids) {
- List<TblAddress> allAdresses = new ArrayList<TblAddress>();
- List<ArrayList<BigDecimal>> addressPolygonPoints = new LinkedList<>();
+ List<TblAddress> allAdresses = new ArrayList<TblAddress>();
+ List<ArrayList<BigDecimal>> addressPolygonPoints = new LinkedList<>();
- // Holen der Adressen, die fuer die Stoerungsinformation relevant sind
- for (UUID stationUuid : stationUuids) {
- TblStation tblStation = stationRepository
- .findByUuid(stationUuid)
- .orElse(null);
+ // Holen der Adressen, die fuer die Stoerungsinformation relevant sind
+ for (UUID stationUuid : stationUuids) {
+ TblStation tblStation = stationRepository
+ .findByUuid(stationUuid)
+ .orElse(null);
- if (tblStation == null) {
- log.warn("station " + stationUuid.toString() + "not found ");
- } else {
- List<TblAddress> addressListForStation = addressRepository.findByStationId(tblStation.getStationId());
- if (addressListForStation.isEmpty()) {
- log.debug("Station " + stationUuid.toString() + "has no addresses.");
-
+ if (tblStation == null) {
+ log.warn("station " + stationUuid.toString() + "not found ");
} else {
- allAdresses.addAll(addressListForStation);
+ List<TblAddress> addressListForStation = addressRepository.findByStationId(tblStation.getStationId());
+ if (addressListForStation.isEmpty()) {
+ log.debug("Station " + stationUuid.toString() + "has no addresses.");
+
+ } else {
+ allAdresses.addAll(addressListForStation);
+ }
}
}
- }
- List<Point> addressPoints = new LinkedList<>();
- // Hinzufügen der gefundenen Adressen zur Liste der Adresspunkte
- // (Multiplikation mit 1000000 notwendig zur Erlangung von ganzzahligen Werten für die Übergabe an GrahamScan)
- allAdresses
- .forEach(x -> addressPoints.add
- (new Point((x.getLatitude().setScale(6, RoundingMode.FLOOR).movePointRight(6)).intValue(),
- (x.getLongitude().setScale(6, RoundingMode.FLOOR).movePointRight(6)).intValue())));
+ List<Point> addressPoints = new LinkedList<>();
+ // Hinzufügen der gefundenen Adressen zur Liste der Adresspunkte
+ // (Multiplikation mit 1000000 notwendig zur Erlangung von ganzzahligen Werten für die Übergabe an GrahamScan)
+ allAdresses
+ .forEach(x -> addressPoints.add
+ (new Point((x.getLatitude().setScale(6, RoundingMode.FLOOR).movePointRight(6)).intValue(),
+ (x.getLongitude().setScale(6, RoundingMode.FLOOR).movePointRight(6)).intValue())));
- if (addressPoints.isEmpty()) {
- log.debug("No addresses for the given stations available");
+ if (addressPoints.isEmpty()) {
+ log.debug("No addresses for the given stations available");
+ return addressPolygonPoints;
+ }
+
+ // GrahamScan über die Adresspunkte zum Erhalt der äußeren Punkte, die ein Polygon bilden
+ List<Point> polygonPoints = GrahamScan.getConvexHull(addressPoints);
+
+
+ // Verpacken der Polygonpunkte in eine Liste von Arrays (longitude/latitude) die ins DTO der Störungsmeldung geschrieben wird
+ // (Division durch 1000000 notwendig zur Wiedererlangung der ursprünglichen Werte)
+ for (Point point : polygonPoints) {
+ ArrayList<BigDecimal> twoValues = new ArrayList<>();
+ twoValues.add(BigDecimal.valueOf(point.getX()).movePointLeft(6));
+ twoValues.add(BigDecimal.valueOf(point.getY()).movePointLeft(6));
+ addressPolygonPoints.add(twoValues);
+ }
+
return addressPolygonPoints;
}
- // GrahamScan über die Adresspunkte zum Erhalt der äußeren Punkte, die ein Polygon bilden
- List<Point> polygonPoints = GrahamScan.getConvexHull(addressPoints);
+ public FailureInformationPublicationChannelDto insertPublicationChannelForFailureInfo(UUID failureInfoUuid, String publicationChannel){
+ TblFailureInformation existingTblFailureInformation = failureInformationRepository
+ .findByUuid(failureInfoUuid)
+ .orElseThrow(() -> new NotFoundException(Constants.FAILURE_INFO_UUID_NOT_EXISTING));
- // Verpacken der Polygonpunkte in eine Liste von Arrays (longitude/latitude) die ins DTO der Störungsmeldung geschrieben wird
- // (Division durch 1000000 notwendig zur Wiedererlangung der ursprünglichen Werte)
- for (Point point : polygonPoints) {
- ArrayList<BigDecimal> twoValues = new ArrayList<>();
- twoValues.add(BigDecimal.valueOf(point.getX()).movePointLeft(6));
- twoValues.add(BigDecimal.valueOf(point.getY()).movePointLeft(6));
- addressPolygonPoints.add(twoValues);
+ //check if channel is already existing
+ if(failureInformationPublicationChannelRepository.countByTblFailureInformationAndPublicationChannel(existingTblFailureInformation, publicationChannel)>0){
+ throw new BadRequestException("channel.already.existing");
+ }
+
+ //create new channel
+ TblFailureInformationPublicationChannel tfiPublicationChannelToSave = new TblFailureInformationPublicationChannel();
+ tfiPublicationChannelToSave.setTblFailureInformation(existingTblFailureInformation);
+ tfiPublicationChannelToSave.setPublicationChannel(publicationChannel);
+ tfiPublicationChannelToSave.setPublished(false);
+
+ TblFailureInformationPublicationChannel savedTfiPublicationChannel = failureInformationPublicationChannelRepository.save(tfiPublicationChannelToSave);
+
+ return failureInformationPublicationChannelMapper.toFailureInformationPublicationChannelDto(savedTfiPublicationChannel);
}
- return addressPolygonPoints;
-}
+ public void deletePublicationChannelForFailureInfo(UUID failureInfoUuid, String publicationChannel){
+
+ TblFailureInformation existingTblFailureInformation = failureInformationRepository
+ .findByUuid(failureInfoUuid)
+ .orElseThrow(() -> new NotFoundException(Constants.FAILURE_INFO_UUID_NOT_EXISTING));
+
+ TblFailureInformationPublicationChannel existingTblFailureInformationPublicationChannel = failureInformationPublicationChannelRepository
+ .findByTblFailureInformationAndPublicationChannel(existingTblFailureInformation, publicationChannel)
+ .orElseThrow(() -> new NotFoundException("channel.not.existing"));
+
+ failureInformationPublicationChannelRepository.delete(existingTblFailureInformationPublicationChannel);
+
+ }
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureInformationPublicationChannelDto.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureInformationPublicationChannelDto.java
new file mode 100644
index 0000000..3a4b1a1
--- /dev/null
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/FailureInformationPublicationChannelDto.java
@@ -0,0 +1,31 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2019 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************
+ */
+package org.eclipse.openk.gridfailureinformation.viewmodel;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+@Data
+public class FailureInformationPublicationChannelDto implements Serializable {
+
+ private UUID failureInformationId;
+ private String publicationChannel;
+ boolean published;
+
+}
+
+
diff --git a/gfsBackendService/src/main/resources/messages.properties b/gfsBackendService/src/main/resources/messages.properties
index 565883d..15c74e8 100644
--- a/gfsBackendService/src/main/resources/messages.properties
+++ b/gfsBackendService/src/main/resources/messages.properties
@@ -13,6 +13,7 @@
no.addresses.for.station.id = Für die in der Störungsmeldung angegebene Station existieren keine Adressen.
no.station.id.available=In der \u00fcbergebenen Störungsmeldung ist keine Station angegeben.
could.not.push.rabbitMqMessage =Die \u00fcbergebene Störungsmeldung konnte nicht an RabbitMq übergeben werden.
-channel.not.existing=der \u00fcbergebene Kanal f\u00fcr den Versand einer Nachricht existiert nicht.
+channel.not.existing=der \u00fcbergebene Kanal existiert nicht.
+channel.already.existing=der \u00fcbergebene Kanal existiert bereits für diese Störungsinformation.
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
index c184ce9..3daf77a 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/config/TestConfiguration.java
@@ -157,6 +157,11 @@
FailureInformationDistributionGroupMapper failureInformationDistributionGroupMapper() { return new FailureInformationDistributionGroupMapperImpl(); }
@Bean
+ public FailureInformationPublicationChannelMapper myFailureInformationPublicationChannelMapper() {
+ return new FailureInformationPublicationChannelMapperImpl();
+ }
+
+ @Bean
public VersionService myVersionService() {
return new VersionService();
}