Commit b10c31ae authored by Dimitrios Chalepakis's avatar Dimitrios Chalepakis
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-379_ImportAdressen
parents 051948f5 1b0a450c
......@@ -9,7 +9,9 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
public class AddressImportApplication {
public static void main(String[] args) {
SpringApplication.run(AddressImportApplication.class, args);
// passing through args is a security issue at sonar. As long as we don't know what for, we won't passthrough
// any arg
SpringApplication.run(AddressImportApplication.class, new String[0]);
}
}
......@@ -72,6 +72,7 @@ public class AddressService {
} catch (Exception ex) {
log.error(ex);
log.warn("Adresse [sdo_x1= " + addressDto.getSdox1()
+ ", sdo_y1= " + addressDto.getSdoy1()
+ ", g3e_fid=" + addressDto.getG3efid()
......
......@@ -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);
}
}
......@@ -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);
}
......@@ -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());
}
@Transactional
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto) {
failureInfoDto.setUuid(null); // force null here
return processGrid(
......@@ -225,47 +231,116 @@ public class FailureInformationService {
}
}
public FailureInformationDto updateSubordinatedFailureInfos(UUID condensedUuid, List<UUID> subordinatedUuidList){
//find condensed FailureInfo:
TblFailureInformation existingFailureInfoCondensed = failureInformationRepository
.findByUuid(condensedUuid)
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
// pruefen, ob in der uebergebenen Liste unterzuordnender FailureInfos Teile einer anderen Verdichtung sind
if (containsAlienSubordinatedFailureInfos(condensedUuid, subordinatedUuidList)) {
throw new BadRequestException("failure.info.already.subordinated");
}
//alle bislang untergeordneten failureInfos finden und Fremdschluessel loeschen
List<TblFailureInformation> subordinatedFailureInfosList = failureInformationRepository.findByFailureInformationCondensedUuid(condensedUuid);
subordinatedFailureInfosList
.stream()
.forEach(x -> x.setTblFailureInformationCondensed(null));
//condenseFailureInfos fuer existierende FailureInfo aufrufen
return condenseFailureInfos(subordinatedUuidList, Optional.of(condensedUuid));
}
private boolean containsAlienSubordinatedFailureInfos(UUID condensedUuid, List<UUID> subordinatedUuidList){
List<TblFailureInformation> futureSubordinateFailureInfoList = failureInformationRepository
.findByUuidIn(subordinatedUuidList);
List filteredList = futureSubordinateFailureInfoList.stream()
.filter(x->x.getTblFailureInformationCondensed() == null || x.getTblFailureInformationCondensed().getUuid() != condensedUuid )
.collect(Collectors.toList());
if(filteredList.size() == futureSubordinateFailureInfoList.size()){
return false;
}
else{
return true;
}
}
private boolean containsSubordinatedFailureInfos(List<UUID> subordinatedUuidList){
List<TblFailureInformation> futureSubordinateFailureInfoList = failureInformationRepository
.findByUuidIn(subordinatedUuidList);
List filteredList = futureSubordinateFailureInfoList.stream()
.filter(x->x.getTblFailureInformationCondensed() == null)
.collect(Collectors.toList());
if(filteredList.size() == futureSubordinateFailureInfoList.size()){
return false;
}
else{
return true;
}
}
@Transactional
public FailureInformationDto condenseFailureInfos(List<UUID> listUuids){
public FailureInformationDto condenseFailureInfos(List<UUID> listUuids, Optional<UUID> condensedUuid){
TblFailureInformation condensedFailureInformation;
TblFailureInformation condensedFailureInformationSaved;
if(listUuids.isEmpty()){
throw new BadRequestException("empty.array");
throw new BadRequestException("empty.array.for.subordinated.failure.infos");
}
TblFailureInformation condensedFailureInformationSaved;
List<TblFailureInformation> listFailureInfos= failureInformationRepository.findByUuidIn(listUuids);
// pruefen, ob in der uebergebenen Liste unterzuordnender FailureInfos Teile einer anderen Verdichtung sind
if (containsSubordinatedFailureInfos(listUuids)) {
throw new BadRequestException("failure.info.already.subordinated");
}
if(checkSameBranch(listFailureInfos)){
TblFailureInformation condensedFailureInformationToSave = new TblFailureInformation();
condensedFailureInformationToSave.setRefBranch(listFailureInfos.get(0).getRefBranch());
if(condensedUuid.isPresent()){
condensedFailureInformation = failureInformationRepository
.findByUuid(condensedUuid.get())
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
}
else{
condensedFailureInformation = new TblFailureInformation();
condensedFailureInformation.setUuid(UUID.randomUUID());
}
setVoltageLevel(listFailureInfos, condensedFailureInformationToSave);
setEarliestStartdate(listFailureInfos, condensedFailureInformationToSave);
setLatestEnddate(listFailureInfos, condensedFailureInformationToSave);
setExpectedReason(listFailureInfos, condensedFailureInformationToSave);
setCity(listFailureInfos, condensedFailureInformationToSave);
setStreet(listFailureInfos, condensedFailureInformationToSave);
setDistrict(listFailureInfos, condensedFailureInformationToSave);
setRadius(listFailureInfos, condensedFailureInformationToSave);
List<TblFailureInformation> listSubordinatedFailureInfos= failureInformationRepository.findByUuidIn(listUuids);
//setze restliche Felder und speichere condensed failureInfo
condensedFailureInformationToSave.setUuid(UUID.randomUUID());
condensedFailureInformationToSave.setVersionNumber(1L);
if(checkSameBranch(listSubordinatedFailureInfos)){
condensedFailureInformation.setRefBranch(listSubordinatedFailureInfos.get(0).getRefBranch());
setVoltageLevel(listSubordinatedFailureInfos, condensedFailureInformation);
setEarliestStartdate(listSubordinatedFailureInfos, condensedFailureInformation);
setLatestEnddate(listSubordinatedFailureInfos, condensedFailureInformation);
setExpectedReason(listSubordinatedFailureInfos, condensedFailureInformation);
setCity(listSubordinatedFailureInfos, condensedFailureInformation);
setStreet(listSubordinatedFailureInfos, condensedFailureInformation);
setDistrict(listSubordinatedFailureInfos, condensedFailureInformation);
setRadius(listSubordinatedFailureInfos, condensedFailureInformation);
//TODO: welche Status sollen hier eingesetzt werden? Bislang wird "neu" gesetzt
RefStatus refStatusNew = statusRepository
.findByStatus("neu")
.orElseThrow(() -> new NotFoundException("status.not.existing"));
.findByStatus("neu")
.orElseThrow(() -> new NotFoundException("status.not.existing"));
condensedFailureInformationToSave.setRefStatusIntern(refStatusNew);
condensedFailureInformationToSave.setRefStatusExtern(refStatusNew);
condensedFailureInformationToSave.setCondensed(true);
condensedFailureInformationToSave.setCondensedCount(listFailureInfos.size());
condensedFailureInformation.setRefStatusIntern(refStatusNew);
condensedFailureInformation.setRefStatusExtern(refStatusNew);
condensedFailureInformation.setCondensed(true);
condensedFailureInformation.setCondensedCount(listSubordinatedFailureInfos.size());
condensedFailureInformationSaved = failureInformationRepository.save(condensedFailureInformationToSave);
condensedFailureInformationSaved = failureInformationRepository.save(condensedFailureInformation);
//kennzeichne die Ursprungs-FailureInfos und speichere
for( TblFailureInformation tblFailureInformation: listFailureInfos )
for( TblFailureInformation tblFailureInformation: listSubordinatedFailureInfos )
{
tblFailureInformation.setCondensed(false);
tblFailureInformation.setTblFailureInformationCondensed(condensedFailureInformationSaved);
......@@ -313,6 +388,9 @@ public class FailureInformationService {
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setStreet(firstStreet);
}
else{
condensedFailureInformation.setStreet(null);
}
}
private void setDistrict(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
......@@ -328,6 +406,9 @@ public class FailureInformationService {
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setDistrict(firstDistrict);
}
else{
condensedFailureInformation.setDistrict(null);
}
}
private void setCity(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
......@@ -343,6 +424,9 @@ public class FailureInformationService {
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setCity(firstCity);
}
else{
condensedFailureInformation.setCity(null);
}
}
private void setExpectedReason(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
......@@ -358,6 +442,9 @@ public class FailureInformationService {
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setRefExpectedReason(listFailureInfos.get(0).getRefExpectedReason());
}
else{
condensedFailureInformation.setRefExpectedReason(null);
}
}
private void setLatestEnddate(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
......@@ -403,6 +490,9 @@ public class FailureInformationService {
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInfo.setVoltageLevel(firstVoltageLevel);
}
else{
condensedFailureInfo.setVoltageLevel(null);
}
}
}
......@@ -6,7 +6,8 @@ failure.type.uuid.not.existing=Die \u00fcbergebene UUID eines Fehlertyps existie
status.not.existing=Die \u00fcbergebene Beschreibung eines Status existiert nicht.
radius.not.existing=Die \u00fcbergebene Beschreibung eines Radius existiert nicht.
failure.info.uuid.not.existing=Die \u00fcbergebene UUID einer Störungsmeldung existiert nicht.
failure.infos.have.different.branches=Die \u00fcbergebenen Störungsinformationen haben unterschiedliche Sparten.
empty.array=Der \u00fcbergebene Array ist leer.
failure.infos.have.different.branches=Die \u00fcbergebenen unterlagerten Störungsinformationen haben unterschiedliche Sparten.
empty.array.for.subordinated.failure.infos=Der \u00fcbergebene Array für unterlagerte Störungsmeldungen ist leer.
failure.info.already.subordinated=Mindestens eine der \u00fcbergebenen unterlagerten Störungsinformationen ist bereits Teil einer anderen Verdichtung.
......@@ -33,6 +33,7 @@ import org.springframework.test.web.servlet.MockMvc;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static org.hamcrest.Matchers.is;
......@@ -40,6 +41,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.web.servlet.function.RequestPredicates.contentType;
@SpringBootTest(classes = GridFailureInformationApplication.class)
@AutoConfigureMockMvc
......@@ -162,7 +164,7 @@ public class FailureInformationControllerTest {
FailureInformationDto failureInformationDto = MockDataHelper.mockFailureInformationDto();
when (failureInformationService.condenseFailureInfos(any(List.class))).thenReturn(failureInformationDto);
when (failureInformationService.condenseFailureInfos(any(List.class), any(Optional.class))).thenReturn(failureInformationDto);
mockMvc.perform(post("/grid-failure-informations/condense")
.contentType(MediaType.APPLICATION_JSON)
......@@ -170,4 +172,15 @@ public class FailureInformationControllerTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void shouldFindSubordinateFailureInfosByCondensedUuid() throws Exception{
List<FailureInformationDto> fiList = MockDataHelper.mockGridFailureInformationDtos();
when (failureInformationService.findFailureInformationsByCondensedUuid(any(UUID.class))).thenReturn(fiList);
mockMvc.perform(get("/grid-failure-informations/condensed/{uuid}", UUID.randomUUID().toString()))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
}
\ No newline at end of file
......@@ -478,7 +478,7 @@ public class FailureInformationServiceTest {
when(failureInformationRepository.findByUuidIn(any(List.class))).thenReturn(listFailureInfos);
assertThrows(OperationDeniedException.class, () -> failureInformationService.condenseFailureInfos(uuidList));
assertThrows(OperationDeniedException.class, () -> failureInformationService.condenseFailureInfos(uuidList, Optional.empty()));
}
@Test
......@@ -506,10 +506,10 @@ public class FailureInformationServiceTest {
return (TblFailureInformation) args[0];
});
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList);
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList, Optional.empty());
assertNotNull(savedCondensedFailureInfoDto.getUuid());
assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//TODO: status (2x) und radius überprüfen
assertEquals(tblFailureInformation1.getStreet(), savedCondensedFailureInfoDto.getStreet());
assertEquals(tblFailureInformation1.getDistrict(), savedCondensedFailureInfoDto.getDistrict());
......@@ -553,10 +553,10 @@ public class FailureInformationServiceTest {
return (TblFailureInformation) args[0];
});
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList);
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList, Optional.empty());
assertNotNull(savedCondensedFailureInfoDto.getUuid());
assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//TODO: status (2x) und radius überprüfen
assertEquals(null, savedCondensedFailureInfoDto.getStreet());
assertEquals(null, savedCondensedFailureInfoDto.getDistrict());
......@@ -568,4 +568,20 @@ public class FailureInformationServiceTest {
}
@Test
public void shouldReturnSubordinateFailureInfos(){
List<TblFailureInformation> fiMockList = MockDataHelper.mockTblFailureInformationList();
when(failureInformationRepository.findByFailureInformationCondensedUuid(any(UUID.class))).thenReturn(fiMockList);
List<FailureInformationDto> fiDtoList = failureInformationService.findFailureInformationsByCondensedUuid(UUID.randomUUID());
assertEquals( fiDtoList.size(), fiMockList.size() );
assertEquals( fiDtoList.get(0).getResponsibility(), fiMockList .get(0).getResponsibility());
}
}
......@@ -159,6 +159,7 @@ public class MockDataHelper {
obj.setFailureEndPlanned(Date.valueOf("2022-09-02"));
obj.setFailureEndResupplied(Date.valueOf("2022-09-03"));
obj.setStreet("Hügelpfad");
obj.setDistrict("Süd");
obj.setCity("Schlumpfhausen");
......@@ -189,6 +190,7 @@ public class MockDataHelper {
return obj;
}
public static Page<TblFailureInformation> mockTblFailureInformationPage() {
List<TblFailureInformation> retList = new LinkedList<>();
retList.add( mockTblFailureInformation() );
......@@ -197,6 +199,8 @@ public class MockDataHelper {
return new PageImpl<>(retList, Pageable.unpaged(), retList.size());
}
public static List<FailureInformationDto> mockGridFailureInformationDtos() {
List<FailureInformationDto> retList = new LinkedList<>();
retList.add( mockFailureInformationDto() );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment