Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.backend into SI-381_get_adresses
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGrid.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGrid.java index 37d81e5..cba6653 100644 --- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGrid.java +++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGrid.java
@@ -31,13 +31,19 @@ @Component public class GfiGrid extends ProcessGrid { public GfiGrid() throws ProcessException { - DecisionTask decidePlanned = register( NEW, new DecideFailureInfoPlanned()); + DecisionTask decidePlanned = new DecideFailureInfoPlanned(); + ProcessTask storeEditStatusPlanned = new StoreEditStatusServiceTask( PLANNED ); + ProcessTask enterMessage = register( PLANNED, new UIStoreFailureInformationTask("State PLANNED UI Task", true)); + register( NEW, enterMessage ); + ProcessTask storeEditStatusCreated = new StoreEditStatusServiceTask( CREATED ); ProcessTask qualifyMessage = register( CREATED, new UIStoreFailureInformationTask( "State CREATED UI Task", true)); + register( UPDATED, qualifyMessage); + DecisionTask decideCanceled = new DecideFailureInfoCanceled(); ProcessTask storeEditStatusQualified = new ShortcutTask( QUALIFIED ); ProcessTask storeEditStatusCanceled = new ShortcutTask( CANCELED );
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/StationController.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/StationController.java new file mode 100644 index 0000000..f8db4c2 --- /dev/null +++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/StationController.java
@@ -0,0 +1,46 @@ +/* + ******************************************************************************* + * 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.StationService; +import org.eclipse.openk.gridfailureinformation.viewmodel.StationDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.annotation.Secured; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Log4j2 +@RestController +@RequestMapping("/stations") +public class StationController { + + @Autowired + private StationService stationService; + + @Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"}) + @ApiOperation(value = "Anzeige aller Stationen") + @ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")}) + @GetMapping + public List<StationDto> findStations() { + return stationService.getStations(); + } +}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/StationRepository.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/StationRepository.java index aacd5ca..99b93ec 100644 --- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/StationRepository.java +++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/StationRepository.java
@@ -17,6 +17,8 @@ import org.eclipse.openk.gridfailureinformation.model.TblStation; 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,5 +32,7 @@ Optional<TblStation> findByUuid(UUID uuid); + @Query("select s from TblStation s where s.stationId = :stationid and s.stationName = :stationname") + List<TblStation> findStationsByIdAndName(@Param("stationid") String stationid, @Param("stationname") String stationname); }
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/StationService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/StationService.java index 0100a00..03d2cf8 100644 --- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/StationService.java +++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/StationService.java
@@ -11,7 +11,7 @@ * * SPDX-License-Identifier: EPL-2.0 ******************************************************************************* -*/ + */ package org.eclipse.openk.gridfailureinformation.service; import org.eclipse.openk.gridfailureinformation.mapper.StationMapper; @@ -34,10 +34,15 @@ public List<StationDto> getStations() { return stationRepository.findAll().stream() - .map( stationMapper::toStationDto ) + .map(stationMapper::toStationDto) .collect(Collectors.toList()); } + public List<StationDto> getStationsByIdAndName(String stationId, String stationName) { + return stationRepository.findStationsByIdAndName(stationId, stationName).stream() + .map(stationMapper::toStationDto) + .collect(Collectors.toList()); + } }
diff --git a/gfsBackendService/src/main/resources/application_localdev.yml b/gfsBackendService/src/main/resources/application_localdev.yml index 6d8f61a..9500bf2 100644 --- a/gfsBackendService/src/main/resources/application_localdev.yml +++ b/gfsBackendService/src/main/resources/application_localdev.yml
@@ -39,7 +39,7 @@ jwt: tokenHeader: Authorization - useStaticJwt: false + useStaticJwt: true staticJwt: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJIYlI3Z2pobmE2eXJRZnZJTWhUSV9tY2g3ZmtTQWVFX3hLTjBhZVl0bjdjIn0.eyJqdGkiOiJlMmQ2YjE3Zi1iMWUyLTQxMzUtOTM1YS0zOWRiMmFkMzE5MjYiLCJleHAiOjE1ODYwMTI1MzUsIm5iZiI6MCwiaWF0IjoxNTg2MDEyMjM1LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvRWxvZ2Jvb2siLCJhdWQiOiJlbG9nYm9vay1iYWNrZW5kIiwic3ViIjoiMzMzMmRmOWItYmYyMy00Nzg5LThmMmQtM2JhZTM2MzA4YzNkIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZWxvZ2Jvb2stYmFja2VuZCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjYxMzRmN2RhLTdlNjQtNDJjNy05NjYyLTY0ZGNhZTk1MjQ5YSIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiKiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiZ3JpZC1mYWlsdXJlLXF1YWxpZmllciIsImdyaWQtZmFpbHVyZS1jcmVhdG9yIiwiZ3JpZC1mYWlsdXJlLWFjY2VzcyIsImdyaWQtZmFpbHVyZS1hZG1pbiIsImdyaWQtZmFpbHVyZS1wdWJsaXNoZXIiXX0sInJlc291cmNlX2FjY2VzcyI6e30sIm5hbWUiOiJTdGF0aWMgSldUIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidGVzdHVzZXJfZ2ZpX3N0YXRpY2p3dCIsImdpdmVuX25hbWUiOiJTdGF0aWMiLCJmYW1pbHlfbmFtZSI6IkpXVCJ9.SWpekZHxlDNWbaaZ2fHlts00c1Xi6yIb0ZMr9f8ujSI_6LVYuHx8FTt6g9tinyVcx5gQKfrooRW28Cdq1EVuexNtTtZ7ciKk4iEo_kgqUgRvHCwO7HQl2igpoGErheYD0kj3-u4Te6NPHKtXWIEfGyl0ZQBD2c4vtaCTQAy5Ilb146G7p_IcLYaZgpJPlGG0Bf2oZ0UqTQsrXxRJkXWARDz8D4lIrN84lAbqNlPlSZDN-8xp_z6mXgWpvgeZuFoYHItJMg2cjR0SXH-ycbWVXctRNQJfTWR0acIhp_nB_Xe6JlUx2vls99EVw-WUrd0hc8Y9658HdeyktvpQLDxP2g services:
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/DecideFailureInfoPlannedTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/DecideFailureInfoPlannedTest.java index 48dfe7f..ee789c2 100644 --- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/DecideFailureInfoPlannedTest.java +++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/DecideFailureInfoPlannedTest.java
@@ -59,25 +59,4 @@ .setEditStatusAndStore(any( UUID.class ), eq(GfiProcessState.CREATED)); } - @Test - public void shouldcall_DecideFailureInfoPlanned_Result_Planned() { - RefStatus refStatus = MockDataHelper.mockRefStatus(); - refStatus.setId(GfiProcessState.NEW.getStatusValue()); - - FailureInformationDto fiDto = MockDataHelper.mockFailureInformationDto(); - fiDto.setStatusInternId(UUID.randomUUID()); - - TblFailureInformation fiTbl = MockDataHelper.mockTblFailureInformation(); - fiTbl.setId(777L); - - when(processHelper.isFailureInfoPlanned(any( FailureInformationDto.class ))).thenReturn(true); - when(statusRepository.findByUuid(any( UUID.class ))).thenReturn(Optional.of(refStatus)); - when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(fiTbl)); - when(failureInformationRepository.save(any(TblFailureInformation.class))).thenReturn(fiTbl); - - FailureInformationDto savedDto = failureInformationService.updateFailureInfo(fiDto); - - verify(processHelper, times(1)) - .setEditStatusAndStore(any( UUID.class ), eq(GfiProcessState.PLANNED)); - } }
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGridTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGridTest.java index 5e2ac16..301302e 100644 --- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGridTest.java +++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/GfiGridTest.java
@@ -16,13 +16,47 @@ package org.eclipse.openk.gridfailureinformation.bpmn.impl; import org.eclipse.openk.gridfailureinformation.bpmn.base.*; +import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ProcessHelper; +import org.eclipse.openk.gridfailureinformation.config.TestConfiguration; +import org.eclipse.openk.gridfailureinformation.model.RefStatus; +import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation; +import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository; +import org.eclipse.openk.gridfailureinformation.repository.StatusRepository; +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.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; + +import java.util.Optional; +import java.util.UUID; import static org.hibernate.validator.internal.util.Contracts.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.*; + +@DataJpaTest +@ContextConfiguration(classes = {TestConfiguration.class}) public class GfiGridTest { + @Qualifier("myFailureInformationService") + @Autowired + private FailureInformationService failureInformationService; + + @MockBean + private ProcessHelper processHelper; + @MockBean + private StatusRepository statusRepository; + @MockBean + private FailureInformationRepository failureInformationRepository; + @Test public void testProcessGrid() throws ProcessException { ProcessGridImpl theGrid = new ProcessGridImpl(); @@ -46,4 +80,37 @@ assertNotNull(grid); } + @Test + public void shouldEndInQualifyMessageWhenStoredWithCreatedFromDBStateNew() { + FailureInformationDto dtoToSave = MockDataHelper.mockFailureInformationDto(); + TblFailureInformation failureFromDB = MockDataHelper.mockTblFailureInformation(); + RefStatus refStatusFromDB = MockDataHelper.mockRefStatus(); + refStatusFromDB.setId(GfiProcessState.NEW.getStatusValue()); + + when( failureInformationRepository.findByUuid(eq(dtoToSave.getUuid()))).thenReturn(Optional.of(failureFromDB)); + when( statusRepository.findByUuid(eq(failureFromDB.getRefStatusIntern().getUuid()))).thenReturn(Optional.of(refStatusFromDB)); + + failureInformationService.updateFailureInfo(dtoToSave); + + verify(processHelper, times(1)) + .setEditStatusAndStore(any( UUID.class ), eq(GfiProcessState.CREATED)); + + } + + @Test + public void shouldEndInQualifyMessageWhenStoredWithCreatedFromDBStatePlanned() { + FailureInformationDto dtoToSave = MockDataHelper.mockFailureInformationDto(); + TblFailureInformation failureFromDB = MockDataHelper.mockTblFailureInformation(); + RefStatus refStatusFromDB = MockDataHelper.mockRefStatus(); + refStatusFromDB.setId(GfiProcessState.PLANNED.getStatusValue()); + + when( failureInformationRepository.findByUuid(eq(dtoToSave.getUuid()))).thenReturn(Optional.of(failureFromDB)); + when( statusRepository.findByUuid(eq(failureFromDB.getRefStatusIntern().getUuid()))).thenReturn(Optional.of(refStatusFromDB)); + + failureInformationService.updateFailureInfo(dtoToSave); + + verify(processHelper, times(1)) + .setEditStatusAndStore(eq(dtoToSave.getUuid()), eq(GfiProcessState.CREATED)); + + } }
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/UIStoreFailureInformationTaskTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/UIStoreFailureInformationTaskTest.java index 91da7ec..2a46923 100644 --- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/UIStoreFailureInformationTaskTest.java +++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/bpmn/impl/UIStoreFailureInformationTaskTest.java
@@ -86,4 +86,6 @@ assertTrue(task.onLeaveStepCalled); } + + }