Commit 4ac62ce2 authored by Ina Curdt's avatar Ina Curdt
Browse files

SI-559 neues DB-Script, SI-548 PUT Service verdichtete Stoerinfos

parent a3a31ac0
......@@ -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}")
......@@ -128,4 +129,18 @@ public class FailureInformationController {
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);
}
}
......@@ -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
......@@ -234,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(condensedUuid.isPresent()){
condensedFailureInformation = failureInformationRepository
.findByUuid(condensedUuid.get())
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
}
else{
condensedFailureInformation = new TblFailureInformation();
condensedFailureInformation.setUuid(UUID.randomUUID());
}
if(checkSameBranch(listFailureInfos)){
TblFailureInformation condensedFailureInformationToSave = new TblFailureInformation();
condensedFailureInformationToSave.setRefBranch(listFailureInfos.get(0).getRefBranch());
List<TblFailureInformation> listSubordinatedFailureInfos= failureInformationRepository.findByUuidIn(listUuids);
setVoltageLevel(listFailureInfos, condensedFailureInformationToSave);
setEarliestStartdate(listFailureInfos, condensedFailureInformationToSave);
setLatestEnddate(listFailureInfos, condensedFailureInformationToSave);
setExpectedReason(listFailureInfos, condensedFailureInformationToSave);
setCity(listFailureInfos, condensedFailureInformationToSave);
setStreet(listFailureInfos, condensedFailureInformationToSave);
setDistrict(listFailureInfos, condensedFailureInformationToSave);
setRadius(listFailureInfos, condensedFailureInformationToSave);
if(checkSameBranch(listSubordinatedFailureInfos)){
//setze restliche Felder und speichere condensed failureInfo
condensedFailureInformationToSave.setUuid(UUID.randomUUID());
condensedFailureInformationToSave.setVersionNumber(1L);
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);
......@@ -322,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){
......@@ -337,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){
......@@ -352,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){
......@@ -367,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){
......@@ -412,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;
......@@ -163,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)
......
......@@ -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,7 +506,7 @@ 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());
......@@ -553,7 +553,7 @@ 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());
......
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