Commit 29bab923 authored by Ina Curdt's avatar Ina Curdt
Browse files

SI-127

parents 641dd156 31ba4eff
FROM openjdk:8-jre-alpine
COPY /target/contact-base-data.jar /usr/src/cbd/
WORKDIR usr/src/cbd
CMD ["java", "-jar", "-Dspring.config.name=application_localdev", "contact-base-data.jar"]
\ No newline at end of file
FROM openjdk:8-jre-alpine
COPY /target/contact-base-data.jar /usr/src/cbd/
COPY /target/grid-failure-Information.backend.service.jar /usr/src/cbd/
WORKDIR usr/src/cbd
CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure", "contact-base-data.jar"]
\ No newline at end of file
CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure", "grid-failure-Information.backend.service.jar"]
\ No newline at end of file
This diff is collapsed.
......@@ -15,9 +15,20 @@
package org.eclipse.openk.gridfailureinformation.constants;
public final class Constants {
public static final String VOLTAGE_LEVEL_NS = "NS";
public static final String VOLTAGE_LEVEL_MS = "MS";
public static final String VOLTAGE_LEVEL_HS = "HS";
public static final String PRESSURE_LEVEL_ND = "ND";
public static final String PRESSURE_LEVEL_MD = "MD";
public static final String PRESSURE_LEVEL_HD = "HD";
public static final String DB_VERSION_NOT_PRESENT = "DB-Version-not_present";
public static final String INTERNAL_SHORT = "I";
public static final String EXTERNAL_SHORT = "E";
private Constants() {
// empty Constructor for the sake of SONAR
}
public static final String DB_VERSION_NOT_PRESENT = "DB-Version-not_present";
}
......@@ -19,9 +19,9 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.service.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
......
......@@ -18,8 +18,9 @@ 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.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.exceptions.BadRequestException;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
......@@ -36,19 +37,19 @@ import java.util.UUID;
@Log4j2
@RestController
@RequestMapping("/grid-failure-informations")
public class GridFailureInformationController {
public class FailureInformationController {
@Value("${gridFailureInformation.maxListSize}")
int maxListSize;
@Autowired
private GridFailureInformationService gridFailureInformationService;
private FailureInformationService failureInformationService;
@ApiOperation(value = "Anzeigen aller Störungsinformationen")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping
public List<GridFailureInformationDto> findFailureInfos() {
return gridFailureInformationService.findFailureInformations(PageRequest.of(0, maxListSize)).getContent();
public List<FailureInformationDto> findFailureInfos() {
return failureInformationService.findFailureInformations(PageRequest.of(0, maxListSize)).getContent();
}
@PostMapping
......@@ -57,9 +58,9 @@ public class GridFailureInformationController {
@ApiResponse(code = 201, message = "Störungsinformation erfolgreich angelegt"),
@ApiResponse(code = 500, message = "Konnte nicht durchgeführt werden")
})
public ResponseEntity<GridFailureInformationDto> insertFailureInfo(
@Validated @RequestBody GridFailureInformationDto gfDto) {
GridFailureInformationDto savedgfDto = gridFailureInformationService.insertGridFailure(gfDto);
public ResponseEntity<FailureInformationDto> insertFailureInfo(
@Validated @RequestBody FailureInformationDto gfDto) {
FailureInformationDto savedgfDto = failureInformationService.insertFailureInfo(gfDto);
URI location = ServletUriComponentsBuilder
.fromCurrentRequestUri()
.path("/{uuid}")
......@@ -68,22 +69,21 @@ public class GridFailureInformationController {
return ResponseEntity.created(location).body(savedgfDto);
}
// @PutMapping("/{contactUuid}")
// @Secured({"ROLE_KON-ADMIN", "ROLE_KON-WRITER"})
// @ApiOperation(value = "Ändern einer externen Person")
// @ApiResponses(value = {
// @ApiResponse(code = 200, message = "Firma wurde aktualisiert"),
// @ApiResponse(code = 400, message = "Ungültige Eingabe"),
// @ApiResponse(code = 404, message = "Nicht gefunden")})
// public ResponseEntity updateCompany(@PathVariable UUID contactUuid, @Validated @RequestBody CompanyDto companyDto) {
//
// if (!companyDto.getContactUuid().equals(contactUuid)) {
// throw new BadRequestException("invalid.uuid.path.object");
// }
//
// companyService.updateCompany(companyDto);
// return ResponseEntity.ok().build();
// }
@PutMapping("/{failureInfoUuid}")
@ApiOperation(value = "Ändern einer Störungsinformation")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Störungsinformation wurde aktualisiert"),
@ApiResponse(code = 400, message = "Ungültige Eingabe"),
@ApiResponse(code = 404, message = "Nicht gefunden")})
public ResponseEntity updateFailureInfo(@PathVariable UUID failureInfoUuid, @Validated @RequestBody FailureInformationDto failureInfoDto) {
if (!failureInfoDto.getUuid().equals(failureInfoUuid)) {
throw new BadRequestException("invalid.uuid.path.object");
}
failureInformationService.updateFailureInfo(failureInfoDto);
return ResponseEntity.ok().build();
}
......
......@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.mapper;
import org.eclipse.openk.gridfailureinformation.model.RefBranch;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
......
......@@ -15,7 +15,7 @@
package org.eclipse.openk.gridfailureinformation.mapper;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
......@@ -36,7 +36,7 @@ public interface GridFailureInformationMapper {
@Mapping(source = "refBranch.name", target = "branch"),
@Mapping(source = "refBranch.colorCode", target = "branchColorCode")
})
GridFailureInformationDto toGridFailureInformationDto(TblFailureInformation tblFailureInformation);
FailureInformationDto toFailureInformationDto(TblFailureInformation tblFailureInformation);
@Mappings({
@Mapping(target = "refFailureClassification.uuid", source = "failureClassificationId"),
......@@ -51,7 +51,7 @@ public interface GridFailureInformationMapper {
@Mapping(target = "refBranch.name", source = "branch"),
@Mapping(target = "refBranch.colorCode", source = "branchColorCode")
})
TblFailureInformation toRefFailureInformation(GridFailureInformationDto gridFailureInformationDto);
TblFailureInformation toTblFailureInformation(FailureInformationDto FailureInformationDto);
}
......@@ -19,8 +19,11 @@ import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import java.util.UUID;
@Repository
public interface FailureInformationRepository extends JpaRepository<TblFailureInformation, Long > {
Optional<TblFailureInformation> findByUuid(UUID uuid);
}
......@@ -20,7 +20,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMap
import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......
......@@ -19,7 +19,7 @@ import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -30,7 +30,7 @@ import java.util.UUID;
@Service
public class GridFailureInformationService {
public class FailureInformationService {
@Autowired
private FailureInformationRepository failureInformationRepository;
......@@ -51,18 +51,32 @@ public class GridFailureInformationService {
private GridFailureInformationMapper gridFailureInformationMapper;
public Page<GridFailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toGridFailureInformationDto);
public Page<FailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toFailureInformationDto);
}
public GridFailureInformationDto insertGridFailure(GridFailureInformationDto gfiDto){
TblFailureInformation tblGfiToSave = gridFailureInformationMapper.toRefFailureInformation(gfiDto);
tblGfiToSave.setUuid(UUID.randomUUID());
setFromGridFailureInformationDto(tblGfiToSave, gfiDto);
return gridFailureInformationMapper.toGridFailureInformationDto(failureInformationRepository.save(tblGfiToSave));
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto){
TblFailureInformation tblFailureInformationToSave = gridFailureInformationMapper.toTblFailureInformation(failureInfoDto);
tblFailureInformationToSave.setUuid(UUID.randomUUID());
setFromGridFailureInformationDto(tblFailureInformationToSave, failureInfoDto);
return gridFailureInformationMapper.toFailureInformationDto(failureInformationRepository.save(tblFailureInformationToSave));
}
private void setFromGridFailureInformationDto( TblFailureInformation destTblFailureInformation, GridFailureInformationDto sourceDto ) {
public FailureInformationDto updateFailureInfo(FailureInformationDto failureInfoDto) {
TblFailureInformation tblFailureInformation = failureInformationRepository.findByUuid(failureInfoDto.getUuid())
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
TblFailureInformation tblFailureInformationToSave = gridFailureInformationMapper.toTblFailureInformation(failureInfoDto);
tblFailureInformationToSave.setId(tblFailureInformation.getId());
setFromGridFailureInformationDto(tblFailureInformationToSave, failureInfoDto);
TblFailureInformation savedFailureInformation = failureInformationRepository.save(tblFailureInformationToSave);
return gridFailureInformationMapper.toFailureInformationDto(savedFailureInformation);
}
private void setFromGridFailureInformationDto( TblFailureInformation destTblFailureInformation, FailureInformationDto sourceDto ) {
if( sourceDto.getBranchId() != null ) {
destTblFailureInformation.setRefBranch( branchRepository
......
/*
*******************************************************************************
* 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 com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.UUID;
@Data
public class FailureClassificationDto implements Serializable {
@JsonProperty("id")
private UUID uuid;
private String classification;
private String description;
}
......@@ -22,7 +22,7 @@ import java.util.Date;
import java.util.UUID;
@Data
public class GridFailureInformationDto implements Serializable {
public class FailureInformationDto implements Serializable {
@JsonProperty("id")
private UUID uuid;
private String responsibility;
......
/*
*******************************************************************************
* 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 com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.UUID;
@Data
public class FailureTypeDto implements Serializable {
@JsonProperty("id")
private UUID uuid;
private String type;
private String description;
}
/*
*******************************************************************************
* 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 com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.UUID;
@Data
public class StatusDto implements Serializable {
@JsonProperty("id")
private UUID uuid;
private String status;
private boolean isInternal;
private boolean isExternal;
}
......@@ -4,5 +4,6 @@ branch.uuid.not.existing=Die \u00fcbergebene UUID einer Branche existiert nicht.
failure.classification.uuid.not.existing=Die \u00fcbergebene UUID einer Fehlerklassifizierung existiert nicht.
failure.type.uuid.not.existing=Die \u00fcbergebene UUID eines Fehlertyps existiert nicht.
status.uuid.not.existing=Die \u00fcbergebene UUID eines Status existiert nicht.
failure.info.uuid.not.existing=Die \u00fcbergebene UUID einer Störungsmeldung existiert nicht.
......@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.config;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.mapper.*;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.service.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.VersionService;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
......@@ -46,13 +46,13 @@ public class TestConfiguration {
}
@Bean
public BranchService myBranchService() {
return new BranchService();
public FailureInformationService myGridFailureInformationService() {
return new FailureInformationService();
}
@Bean
public GridFailureInformationService myGridFailureInformationService() {
return new GridFailureInformationService();
public BranchService myBranchService() {
return new BranchService();
}
}
/*
*******************************************************************************
* 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 com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
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.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import java.util.Date;
import java.util.UUID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(classes = GridFailureInformationApplication.class)
@AutoConfigureMockMvc
public class FailureInformationControllerTest {
@MockBean
private FailureInformationService failureInformationService;
@Autowired
private MockMvc mockMvc;
@Test
public void shouldFindFailureInfos() throws Exception {
Page<FailureInformationDto> page = MockDataHelper.mpckGridFailureInformationDtoPage();
when(failureInformationService.findFailureInformations(any(Pageable.class))).thenReturn(page);
mockMvc.perform(get("/grid-failure-informations"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Test
public void shouldUpdateFailureInformation() throws Exception {
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
when( failureInformationService.updateFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
mockMvc.perform(put("/grid-failure-informations/{failureInfoUuid}", failureInfoDto.getUuid().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(failureInfoDto)))
.andExpect(status().is2xxSuccessful());
}
@Test
public void shouldNotUpdateFailureInformationDueToException() throws Exception {
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
when( failureInformationService.updateFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
// provide different exception in url and object
mockMvc.perform(put("/grid-failure-informations/{failureInfoUuid}", UUID.randomUUID().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(failureInfoDto)))
.andExpect(status().isBadRequest());
}
@Test
public void shouldInsertFailureInformation() throws Exception {
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
when( failureInformationService.insertFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
mockMvc.perform(post("/grid-failure-informations")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(failureInfoDto)))
.andExpect(jsonPath("$.responsibility", is(failureInfoDto.getResponsibility())))
.andExpect(jsonPath("$.internExtern", is(failureInfoDto.getInternExtern())))
.andExpect(jsonPath("$.voltageLevel", is(failureInfoDto.getVoltageLevel())))
.andExpect(jsonPath("$.pressureLevel", is(failureInfoDto.getPressureLevel())))
.andExpect(jsonPath("$.failureBegin", is(failureInfoDto.getFailureBegin().toString())))
.andExpect(jsonPath("$.failureEndPlanned", is(failureInfoDto.getFailureEndPlanned().toString())))
.andExpect(jsonPath("$.failureEndResupplied", is(failureInfoDto.getFailureEndResupplied().toString())))
.andExpect(jsonPath("$.probableReason", is(failureInfoDto.getProbableReason())))
.andExpect(jsonPath("$.internalRemark", is(failureInfoDto.getInternalRemark())))
.andExpect(jsonPath("$.postcode", is(failureInfoDto.getPostcode())))
.andExpect(jsonPath("$.city", is(failureInfoDto.getCity())))
.andExpect(jsonPath("$.district", is(failureInfoDto.getDistrict())))
.andExpect(jsonPath("$.street", is(failureInfoDto.getStreet())))
.andExpect(jsonPath("$.housenumber", is(failureInfoDto.getHousenumber())))
.andExpect(jsonPath("$.stationDescription", is(failureInfoDto.getStationDescription())))
.andExpect(jsonPath("$.stationCoords", is(failureInfoDto.getStationCoords())))
.andExpect(jsonPath("$.radius", is(failureInfoDto.getRadius())))
.andExpect(jsonPath("$.failureClassificationId", is(failureInfoDto.getFailureClassificationId().toString())))
.andExpect(jsonPath("$.failureClassification", is(failureInfoDto.getFailureClassification())))
.andExpect(jsonPath("$.failureTypeId", is(failureInfoDto.getFailureTypeId().toString())))
.andExpect(jsonPath("$.statusInternId", is(failureInfoDto.getStatusInternId().toString())))
.andExpect(jsonPath("$.statusExternId", is(failureInfoDto.getStatusExternId().toString())))
.andExpect(jsonPath("$.branchId", is(failureInfoDto.getBranchId().toString())))
.andExpect(jsonPath("$.branch", is(failureInfoDto.getBranch())))
.andExpect(jsonPath("$.branchColorCode", is(failureInfoDto.getBranchColorCode())))
.andExpect(status().is2xxSuccessful());
}
}
\ No newline at end of file
/*
*******************************************************************************
* 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.
*