Commit f1c5a0d0 authored by dietricf's avatar dietricf
Browse files

Merge branch 'DEVELOP' of...

Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.backend into SI-585_Grid_ExchPlanned_with_actualized
parents 214f0523 f464751f
......@@ -62,12 +62,18 @@ public class AddressImportService {
}
if (cleanUp) {
Instant cleanUpStart = Instant.now();
log.info("CleanUp START");
addressService.deleteAllAddresses();
stationService.deleteAllStations();
log.info("CleanUp ENDE");
Instant cleanUpEnd = Instant.now();
log.info("CleanUp Duration: " + Duration.between(cleanUpStart, cleanUpEnd));
}
Instant importStart = Instant.now();
log.info("Import START");
log.info("- Import Addresses START");
......@@ -89,8 +95,10 @@ public class AddressImportService {
log.info("- Import PowerStations START");
importPowerStationFile(cleanUp);
log.info("- Import PowerStations END");
log.info("Import END");
Instant importEnd = Instant.now();
log.info("Total Import Duration: " + Duration.between(importStart, importEnd));
synchronized (lock) {
importInWork = Boolean.FALSE;
......
......@@ -27,11 +27,11 @@ adressimport:
cleanup: true
cron: 0 0 0 1 * ?
file:
addresses: /usr/src/cbd/temp/import_files/adressen.csv
power-connections: /usr/src/cbd/temp/import_files/strom_hausanschluss.csv
water-connections: /usr/src/cbd/temp/import_files/wasser_hausanschluss.csv
gas-connections: /usr/src/cbd/temp/import_files/gas_hausanschluss.csv
power-stations: /usr/src/cbd/temp/import_files/strom_station.csv
addresses: /opt/mics/addressImport/importFiles/adressen.csv
power-connections: /opt/mics/addressImport/importFiles/strom_hausanschluss.csv
water-connections: /opt/mics/addressImport/importFiles/wasser_hausanschluss.csv
gas-connections: /opt/mics/addressImport/importFiles/gas_hausanschluss.csv
power-stations: /opt/mics/addressImport/importFiles/strom_station.csv
jwt:
tokenHeader: Authorization
......@@ -97,7 +97,7 @@ spring:
password: gfi_service
server:
port: 9185
port: 9164
max-http-header-size: 262144
servlet:
session:
......@@ -117,4 +117,14 @@ authNAuthService:
listOfServers: http://localhost:8080
cors:
corsEnabled: true
\ No newline at end of file
corsEnabled: true
adressimport:
cleanup: true
cron: 0 0 0 1 * ?
file:
addresses: /opt/mics/addressImport/importFiles/EREP_CSV_ADRESSEN.csv
power-connections: /opt/mics/addressImport/importFiles/EREP_CSV_STROM_HAUSANSCHLUSS.csv
water-connections: /opt/mics/addressImport/importFiles/EREP_CSV_WASSER_HAUSANSCHLUSS.csv
gas-connections: /opt/mics/addressImport/importFiles/EREP_CSV_GAS_HAUSANSCHLUSS.csv
power-stations: /opt/mics/addressImport/importFiles/EREP_CSV_STROM_STATION.csv
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOGS" value="./logs"/>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%c{60}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/addressImport.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %c{60} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/archived/addressImport-%d{yyyy-MM-dd}.gz</fileNamePattern>
<MaxHistory>30</MaxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</root>
<!-- LOG "com.baeldungorg.eclipse.openk.contactbasedata*" at INFO level -->
<logger name="org.eclipse.openk.gridfailureinformation.importadresses" level="info" additivity="false">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</logger>
</configuration>
\ No newline at end of file
......@@ -15,6 +15,7 @@
package org.eclipse.openk.gridfailureinformation.importadresses.config;
import org.eclipse.openk.gridfailureinformation.importadresses.AddressImportApplication;
import org.eclipse.openk.gridfailureinformation.importadresses.jobs.JobManager;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.AddressMapper;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.AddressMapperImpl;
import org.eclipse.openk.gridfailureinformation.importadresses.mapper.StationMapper;
......@@ -55,4 +56,7 @@ public class TestConfiguration {
@Bean
public StationService myStationService() { return new StationService(); }
@Bean
public JobManager jobManager() { return new JobManager(); }
}
/*
*******************************************************************************
* Copyright (c) 2018 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.importadresses.controller;
import org.eclipse.openk.gridfailureinformation.importadresses.AddressImportApplication;
import org.eclipse.openk.gridfailureinformation.importadresses.jobs.JobManager;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(classes = AddressImportApplication.class)
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class AddressImportControllerTest {
@MockBean
private JobManager jobManager;
@Autowired
private MockMvc mockMvc;
@Test
public void shouldTriggerStartImport() throws Exception {
mockMvc.perform(post("/addresses/import"))
.andExpect(status().is2xxSuccessful());
verify(jobManager).triggerStartImport();
}
}
/*
*******************************************************************************
* Copyright (c) 2018 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.importadresses.exceptions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class InternalServerErrorExceptionTest {
@Test
public void testExceptionCreationForCoverage() {
new InternalServerErrorException("testOnly");
Exception innerException = new InternalServerErrorException("inner Exception");
assertEquals( innerException.getMessage(), "inner Exception");
}
}
/*
*******************************************************************************
* Copyright (c) 2018 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.importadresses.jobs;
import org.eclipse.openk.gridfailureinformation.importadresses.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.importadresses.service.AddressImportService;
import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import static java.lang.Boolean.TRUE;
import static java.lang.Boolean.FALSE;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
public class JobManagerTest {
@Autowired
JobManager jobManager;
@MockBean
AddressImportService addressImportService;
@Test
public void shouldTriggerStartImport() {
jobManager.triggerStartImport();
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, TRUE);
}
@Test
public void shouldImportOnTriggerAndSetStartImportBackToFalse() throws Exception {
Whitebox.setInternalState(jobManager, "startImport", TRUE);
try {
Whitebox.invokeMethod(jobManager, "importOnTrigger");
} catch (Exception e) {
e.printStackTrace();
}
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, FALSE);
}
@Test
public void shouldImportOnTriggerAndDontChangeTheValueFromStartImport() {
Whitebox.setInternalState(jobManager, "startImport", FALSE);
try {
Whitebox.invokeMethod(jobManager, "importOnTrigger");
} catch (Exception e) {
e.printStackTrace();
}
Boolean startImport = Whitebox.getInternalState(jobManager, "startImport");
assertEquals(startImport, FALSE);
}
@Test
public void shouldImportAddressdataAndInvokeImportAddresses() {
jobManager.cleanUp = false;
try {
Whitebox.invokeMethod(jobManager, "importAddressdata");
} catch (Exception e) {
e.printStackTrace();
}
verify(addressImportService, times(1)).importAddresses(false);
}
}
/*
*******************************************************************************
* 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.controller;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.AddressService;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Log4j2
@RestController
@RequestMapping("/addresses")
public class AddressController {
@Autowired
private AddressService addressService;
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige aller PLZs")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/postcodes")
public List<String> findAllPostCodes() {
return addressService.getPostcodes();
}
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige eines Orte nach Postleitzahl")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/communities/{postcode}")
public List<String> findAllCommunitiesByPostcode(@PathVariable String postcode) {
return addressService.getCommunities(postcode);
}
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige Ortsteile nach Postleitzahl und Ort")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/districts")
public List<String> findDistricts(
@RequestParam ("postcode") String postcode,
@RequestParam ("community") String community
) {
return addressService.getDistricts(postcode, community);
}
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige Strassen nach Postleitzahl und Ort und Ortsteil (optional)")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/streets")
public List<String> findStreets(
@RequestParam ("postcode") String postcode,
@RequestParam ("community") String community,
@RequestParam ("district") Optional<String> district
) {
return addressService.getStreets(postcode, community, district);
}
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige Strassen nach Postleitzahl und Ort und Strasse")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/housenumbers")
public List<String> findHousenumbers(
@RequestParam ("postcode") String postcode,
@RequestParam ("community") String community,
@RequestParam ("street") String street
) {
return addressService.getHousenumbers(postcode, community, street);
}
}
......@@ -34,6 +34,7 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Log4j2
......@@ -111,7 +112,7 @@ public class FailureInformationController {
})
public ResponseEntity<FailureInformationDto> condenseFailureInfos(@ApiParam("Liste UUIDs der zu verdichtenden Störungen")
@RequestBody List<UUID> listUuids) {
FailureInformationDto condensedGfDto = failureInformationService.condenseFailureInfos(listUuids);
FailureInformationDto condensedGfDto = failureInformationService.condenseFailureInfos(listUuids, Optional.empty());
URI location = ServletUriComponentsBuilder
.fromCurrentRequestUri()
.path("/{uuid}")
......@@ -120,5 +121,26 @@ public class FailureInformationController {
return ResponseEntity.created(location).body(condensedGfDto);
}
@GetMapping("/condensed/{uuid}")
@ApiOperation(value = "Anzeigen von Störungsinformationen, die einer Verdichtung zuzuordnen sind")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
@ApiResponse(code = 404, message = "Störungsinformationen wurden nicht gefunden")})
@ResponseStatus(HttpStatus.OK)
public List<FailureInformationDto> getFailureInformations(@PathVariable UUID uuid) {
return failureInformationService.findFailureInformationsByCondensedUuid(uuid);
}
@PutMapping("/{failureInfoUuid}/condense")
@ApiOperation(value = "Update einer verdichteten Störungsinfo")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
@ApiResponse(code = 404, message = "Störungsinformationen wurden nicht gefunden")})
@ResponseStatus(HttpStatus.OK)
public FailureInformationDto updateSubordinatedFailureInformations(
@ApiParam(name="failureInfoUuid", value= "Liste UUIDs der zu verdichtenden Störungen", required = true)
@PathVariable UUID failureInfoUuid,
@RequestBody List<UUID> listSubordinatedUuids) {
return failureInformationService.updateSubordinatedFailureInfos(failureInfoUuid, listSubordinatedUuids);
}
}
......@@ -17,6 +17,8 @@ package org.eclipse.openk.gridfailureinformation.repository;
import org.eclipse.openk.gridfailureinformation.model.TblAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -30,4 +32,22 @@ public interface AddressRepository extends JpaRepository<TblAddress, Long > {
Optional<TblAddress> findByUuid(UUID uuid);
@Query("select distinct a.postcode from TblAddress a")
List<String> findAllPostcodes();
@Query("select distinct a.community from TblAddress a where postcode = :postcode")
List<String> findCommunitiesByPostcode(@Param("postcode") String postcode);
@Query("select distinct a.district from TblAddress a where postcode = :postcode and community = :community")
List<String> findDistrictsByPostcodeAndCommunity(@Param("postcode") String postcode, @Param("community") String community);
@Query("select distinct a.street from TblAddress a where postcode = :postcode and community = :community")
List<String> findStreetsByPostcodeAndCommunity(@Param("postcode") String postcode, @Param("community") String community);
@Query("select distinct a.street from TblAddress a where postcode = :postcode and community = :community and district = :district")
List<String> findStreetsByPostcodeAndCommunityAndDistrict(@Param("postcode") String postcode, @Param("community") String community, @Param("district") String district);
@Query("select distinct a.housenumber from TblAddress a where postcode = :postcode and community = :community and street = :street")
List<String> findHousenumbersByPostcodeAndCommunityAndStreet(@Param("postcode") String postcode, @Param("community") String community, @Param("street") String street);
}
......@@ -18,7 +18,9 @@ package org.eclipse.openk.gridfailureinformation.repository;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -33,4 +35,7 @@ public interface FailureInformationRepository extends PagingAndSortingRepository
Optional<TblFailureInformation> findByUuid(UUID uuid);
List<TblFailureInformation> findByUuidIn(List<UUID> uuidList);
@Query("select fi from TblFailureInformation fi where fi.tblFailureInformationCondensed.uuid = :uuid")
List<TblFailureInformation> findByFailureInformationCondensedUuid(@Param("uuid") UUID uuid);
}
......@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
......@@ -39,5 +40,33 @@ public class AddressService {
.collect(Collectors.toList());
}
public List<String> getPostcodes(){
return addressRepository.findAllPostcodes();
}
public List<String> getCommunities(String postcode) {
return addressRepository.findCommunitiesByPostcode(postcode);
}
public List<String> getDistricts(String postcode, String community) {
return addressRepository.findDistrictsByPostcodeAndCommunity(postcode, community);
}
public List<String> getStreets(String postcode, String community, Optional<String> district) {
if(!district.isPresent()){
return addressRepository.findStreetsByPostcodeAndCommunity(postcode, community);
}
else{
return addressRepository.findStreetsByPostcodeAndCommunityAndDistrict(postcode, community, district.get());
}
}
public List<String> getHousenumbers(String postcode, String community, String street) {
return addressRepository.findHousenumbersByPostcodeAndCommunityAndStreet(postcode, community, street);
}
}
......@@ -37,10 +37,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
@Log4j2
......@@ -90,6 +87,15 @@ public class FailureInformationService {
return failureInformationRepository.findByTblFailureInformationCondensedIdIsNull(pageable).map(failureInformationMapper::toFailureInformationDto);
}
public List <FailureInformationDto> findFailureInformationsByCondensedUuid(UUID uuid) {
List<TblFailureInformation> fiList = failureInformationRepository.findByFailureInformationCondensedUuid(uuid);
return fiList.stream()
.map(failureInformationMapper::toFailureInformationDto)
.collect(Collectors.toList());