Commit a896009b authored by dietricf's avatar dietricf
Browse files
parents 8291abe0 825dc3a8
......@@ -20,7 +20,10 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessGrid;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.DecisionTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.*;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.DecideFailureInfoCanceled;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.DecideFailureInfoPlanned;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ShortcutTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.UIStoreFailureInformationTask;
import org.springframework.stereotype.Component;
import static org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.DecisionTask.OutputPort.NO;
......@@ -33,13 +36,13 @@ public class GfiGrid extends ProcessGrid {
public GfiGrid() throws ProcessException {
DecisionTask decidePlanned = new DecideFailureInfoPlanned();
ProcessTask storeEditStatusPlanned = new StoreEditStatusServiceTask( PLANNED );
ProcessTask storeEditStatusPlanned = new ShortcutTask( PLANNED );
ProcessTask enterMessage = register( PLANNED,
new UIStoreFailureInformationTask("State PLANNED UI Task", true));
register( NEW, enterMessage );
ProcessTask storeEditStatusCreated = new StoreEditStatusServiceTask( CREATED );
ProcessTask storeEditStatusCreated = new ShortcutTask( CREATED );
ProcessTask qualifyMessage = register( CREATED,
new UIStoreFailureInformationTask( "State CREATED UI Task", true));
register( UPDATED, qualifyMessage);
......
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.Data;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.repository.StatusRepository;
......@@ -23,4 +24,7 @@ public class GfiProcessEnvironment {
@Autowired
private FailureInformationService failureInformationService;
@Autowired
private FailureInformationMapper failureInformationMapper;
}
......@@ -6,10 +6,8 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessEnvironment;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState;
import org.eclipse.openk.gridfailureinformation.exceptions.InternalServerErrorException;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.model.RefFailureClassification;
import org.eclipse.openk.gridfailureinformation.model.RefStatus;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -37,22 +35,9 @@ public class ProcessHelper {
return refPlannedMeasure.getUuid().equals(dto.getFailureClassificationId());
}
public void setEditStatusAndStore(UUID failureInfoUuid, GfiProcessState state) {
TblFailureInformation obj = environment.getFailureInformationRepository().findByUuid(failureInfoUuid)
.orElseThrow(() -> new NotFoundException("failure.information.not.found"));
Optional<RefStatus> optRefStatus = environment.getStatusRepository().findById(state.getStatusValue());
if( !optRefStatus.isPresent()) {
log.error("RefStatus <"+state.getStatusValue()+"> not found in DB");
throw new InternalServerErrorException("status.not.found");
}
obj.setRefStatusIntern(optRefStatus.get());
obj.setRefStatusExtern(optRefStatus.get());
environment.getFailureInformationRepository().save(obj);
}
public void storeFailureFromViewModel( FailureInformationDto dto ) {
environment.getFailureInformationService().storeFailureInfo(dto, GfiProcessState.NEW);
public FailureInformationDto storeFailureFromViewModel( FailureInformationDto dto ) {
FailureInformationDto savedDto = environment.getFailureInformationService().storeFailureInfo(dto, GfiProcessState.NEW);
return savedDto;
}
public ProcessState getProcessStateFromStatusUuid( UUID statusUuid ) {
......
/*
*******************************************************************************
* 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.bpmn.impl.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.ServiceTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessSubject;
@Log4j2
public class StoreEditStatusServiceTask extends ServiceTask<GfiProcessSubject> {
protected final GfiProcessState stateToSave;
public StoreEditStatusServiceTask(GfiProcessState stateToSave) {
super("Bearbeitungsstatus-Status setzen: "+stateToSave);
this.stateToSave = stateToSave;
}
@Override
protected void onLeaveStep(GfiProcessSubject subject) throws ProcessException {
subject.getProcessHelper().setEditStatusAndStore( subject.getFailureInformationDto().getUuid(), stateToSave );
}
}
......@@ -20,6 +20,7 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.UserInteractionTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessSubject;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
@Log4j2
public class UIStoreFailureInformationTask extends UserInteractionTask<GfiProcessSubject> {
......@@ -49,7 +50,8 @@ public class UIStoreFailureInformationTask extends UserInteractionTask<GfiProces
@Override
protected void onStayInTask(GfiProcessSubject subject) throws ProcessException {
subject.getProcessHelper().storeFailureFromViewModel(subject.getFailureInformationDto());
FailureInformationDto failureInformationDto = subject.getProcessHelper().storeFailureFromViewModel(subject.getFailureInformationDto());
subject.setFailureInformationDto(failureInformationDto);
}
private boolean detectStateChanged( GfiProcessSubject subject ) {
......
......@@ -10,17 +10,17 @@ import java.util.Optional;
@Component
public class TblFailureInformationListener {
@PrePersist
public void failureInformationPrePersist(TblFailureInformation failureInformation) {
failureInformation.setVersionNumber(
Optional.ofNullable(failureInformation.getVersionNumber()).orElse(0L)
+ 1);
}
@PreUpdate
public void failureInformationPreUpdate(TblFailureInformation failureInformation) {
failureInformation.setVersionNumber(
Optional.ofNullable(failureInformation.getVersionNumber()).orElse(0L)
+ 1);
}
// @PrePersist
// public void failureInformationPrePersist(TblFailureInformation failureInformation) {
// failureInformation.setVersionNumber(
// Optional.ofNullable(failureInformation.getVersionNumber()).orElse(0L)
// + 1);
// }
//
// @PreUpdate
// public void failureInformationPreUpdate(TblFailureInformation failureInformation) {
// failureInformation.setVersionNumber(
// Optional.ofNullable(failureInformation.getVersionNumber()).orElse(0L)
// + 1);
// }
}
......@@ -130,13 +130,11 @@ public class FailureInformationService {
}
}
@Transactional
//@Transactional
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto, GfiProcessState initialState) {
failureInfoDto.setUuid(null); // force null here
return processGrid(
storeFailureInfo(failureInfoDto, initialState)
);
return storeFailureInfo(failureInfoDto, initialState);
}
public FailureInformationDto updateFailureInfo(FailureInformationDto failureInfoDto) {
......@@ -148,7 +146,7 @@ public class FailureInformationService {
TblFailureInformation tblFailureInformationToSave = failureInformationMapper.toTblFailureInformation(dto);
if(dto.getUuid() == null ) {
tblFailureInformationToSave.setUuid(UUID.randomUUID());
tblFailureInformationToSave.setVersionNumber(0L);
tblFailureInformationToSave.setVersionNumber(1L);
setFromGridFailureInformationDto(tblFailureInformationToSave, dto);
RefStatus refStatus = statusRepository.findById(initialState.getStatusValue())
......@@ -166,9 +164,14 @@ public class FailureInformationService {
tblFailureInformationToSave.setId(tblFailureInformation.getId());
setFromGridFailureInformationDto(tblFailureInformationToSave, dto);
setVersionNumber(tblFailureInformationToSave);
}
return enrichFailureInfo(failureInformationMapper.toFailureInformationDto(failureInformationRepository.save(tblFailureInformationToSave)));
TblFailureInformation tblFailureInformationSaved = failureInformationRepository.save(tblFailureInformationToSave);
FailureInformationDto failureInformationDto = failureInformationMapper.toFailureInformationDto(tblFailureInformationSaved);
FailureInformationDto enrichedFailureInfo = enrichFailureInfo(failureInformationDto);
return enrichedFailureInfo;
}
......@@ -267,6 +270,12 @@ public class FailureInformationService {
}
}
private void setVersionNumber(TblFailureInformation tblFailureInformation){
List<HtblFailureInformation> hfailureList = histFailureInformationRepository.findByUuid(tblFailureInformation.getUuid());
Long lastVersion = hfailureList.stream().map(HtblFailureInformation::getVersionNumber).max(Comparator.naturalOrder()).orElse(0L) ;
tblFailureInformation.setVersionNumber(lastVersion+1);
}
private FailureInformationDto enrichFailureInfo(FailureInformationDto failureInformationDto) {
// wenn Mittelspannung dann füge Adress-Polygonpunkte für Kartenanzeige hinzu
......@@ -366,7 +375,7 @@ public class FailureInformationService {
condensedFailureInformation.setRefStatusExtern(refStatusNew);
condensedFailureInformation.setCondensed(true);
condensedFailureInformation.setCondensedCount(listSubordinatedFailureInfos.size());
condensedFailureInformation.setVersionNumber(1L);
condensedFailureInformationSaved = failureInformationRepository.save(condensedFailureInformation);
//kennzeichne die Ursprungs-FailureInfos und speichere
......@@ -374,6 +383,7 @@ public class FailureInformationService {
{
tblFailureInformation.setCondensed(false);
tblFailureInformation.setTblFailureInformationCondensed(condensedFailureInformationSaved);
setVersionNumber(tblFailureInformation);
failureInformationRepository.save(tblFailureInformation);
}
}
......@@ -572,7 +582,9 @@ public class FailureInformationService {
addressPolygonPoints.add(twoValues);
}
if(!addressPolygonPoints.isEmpty()) {
failureInformationDto.setAddressPolygonPoints(addressPolygonPoints);
}
}
}
......@@ -25,7 +25,6 @@ import java.util.Optional;
import java.util.UUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@DataJpaTest
......@@ -69,7 +68,7 @@ public class DecideFailureInfoPlannedTest {
FailureInformationDto savedDto = failureInformationService.updateFailureInfo(fiDto);
verify(processHelper, times(1))
.setEditStatusAndStore(any( UUID.class ), eq(GfiProcessState.CREATED));
.storeFailureFromViewModel(any( FailureInformationDto.class ));
}
}
......@@ -33,7 +33,6 @@ 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;
......@@ -92,8 +91,9 @@ public class GfiGridTest {
failureInformationService.updateFailureInfo(dtoToSave);
verify(processHelper, times(1))
.setEditStatusAndStore(any( UUID.class ), eq(GfiProcessState.CREATED));
.storeFailureFromViewModel(any(FailureInformationDto.class));
}
......@@ -110,7 +110,22 @@ public class GfiGridTest {
failureInformationService.updateFailureInfo(dtoToSave);
verify(processHelper, times(1))
.setEditStatusAndStore(eq(dtoToSave.getUuid()), eq(GfiProcessState.CREATED));
.storeFailureFromViewModel(any(FailureInformationDto.class));
}
@Test
public void shouldCallStoreOnlyOnceWhenSavingWithNewCreated() {
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)).storeFailureFromViewModel(any(FailureInformationDto.class));
}
}
......@@ -18,10 +18,7 @@ package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ProcessHelper;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.exceptions.InternalServerErrorException;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.model.RefFailureClassification;
import org.eclipse.openk.gridfailureinformation.model.RefStatus;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.repository.StatusRepository;
......@@ -88,40 +85,6 @@ public class ProcessHelperTest {
assertThrows( InternalServerErrorException.class, () -> processHelper.isFailureInfoPlanned(dto));
}
@Test
public void shouldSetEditAndStore_ExceptionNotFound() {
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.empty());
assertThrows(NotFoundException.class, () -> processHelper.setEditStatusAndStore(UUID.randomUUID(), GfiProcessState.NEW));
}
@Test
public void shouldSetEditAndStore_ExceptionInternalServerError() {
TblFailureInformation tblFailureInformation = MockDataHelper.mockTblFailureInformation();
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of( tblFailureInformation ));
when(statusRepository.findById(GfiProcessState.NEW.getStatusValue())).thenReturn(Optional.empty());
assertThrows(InternalServerErrorException.class, () -> processHelper.setEditStatusAndStore(UUID.randomUUID(), GfiProcessState.NEW));
}
@Test
public void shouldSetEditAndStoreSuccessful() {
TblFailureInformation tblFailureInformation = MockDataHelper.mockTblFailureInformation();
tblFailureInformation.setRefStatusExtern(null);
tblFailureInformation.setRefStatusIntern(null);
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of( tblFailureInformation ));
when(failureInformationRepository.save(any(TblFailureInformation.class))).thenReturn(null);
RefStatus refStatus = MockDataHelper.mockRefStatus();
when(statusRepository.findById(GfiProcessState.NEW.getStatusValue())).thenReturn(Optional.of(refStatus));
processHelper.setEditStatusAndStore(UUID.randomUUID(), GfiProcessState.NEW);
assertEquals(refStatus.getUuid(), tblFailureInformation.getRefStatusExtern().getUuid());
assertEquals(refStatus.getUuid(), tblFailureInformation.getRefStatusIntern().getUuid());
}
@Test
public void shouldGetProcessStateFromStatus_Exception() {
......
......@@ -62,7 +62,7 @@ public class UIStoreFailureInformationTaskTest {
@Test
public void shouldStayInTask() throws ProcessException {
ProcessSubject subject = GfiProcessSubject.of(MockDataHelper.mockFailureInformationDto(), processHelper);
doNothing().when(processHelper).storeFailureFromViewModel(any(FailureInformationDto.class));
//doNothing().when(processHelper).storeFailureFromViewModel(any(FailureInformationDto.class));
UIStoreTaskTester task = new UIStoreTaskTester("Testme", true);
task.leaveStep(subject);
......@@ -76,7 +76,7 @@ public class UIStoreFailureInformationTaskTest {
@Test
public void shouldNotStayInTask() throws ProcessException {
ProcessSubject subject = GfiProcessSubject.of(MockDataHelper.mockFailureInformationDto(), processHelper);
doNothing().when(processHelper).storeFailureFromViewModel(any(FailureInformationDto.class));
//doNothing().when(processHelper).storeFailureFromViewModel(any(FailureInformationDto.class));
UIStoreTaskTester task = new UIStoreTaskTester("Testme", false);
task.leaveStep(subject);
......
......@@ -121,6 +121,7 @@ public class FailureInformationServiceTest {
RefBranch refBranch = MockDataHelper.mockRefBranch();
RefRadius refRadius = MockDataHelper.mockRefRadius();
RefExpectedReason refExpectedReason = MockDataHelper.mockRefExpectedReason();
List<HtblFailureInformation> hFailureList = MockDataHelper.mockHistTblFailureInformationList();
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(fiTbl));
when(branchRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refBranch));
......@@ -129,7 +130,7 @@ public class FailureInformationServiceTest {
when(statusRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refStatus));
when(radiusRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refRadius));
when(expectedReasonRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refExpectedReason));
when(histFailureInformationRepository.countByUuid(any(UUID.class))).thenReturn(5L);
when(histFailureInformationRepository.findByUuid(any(UUID.class))).thenReturn(hFailureList);
when(failureInformationRepository.save(any(TblFailureInformation.class)))
.then((Answer<TblFailureInformation>) invocation -> {
......@@ -182,6 +183,8 @@ public class FailureInformationServiceTest {
TblStation tblStation = MockDataHelper.mockTblStation();
List<TblAddress> addressList = MockDataHelper.mockTblAddressList();
List<HtblFailureInformation> listHistFailureInfos = MockDataHelper.mockHistTblFailureInformationList();
FailureInformationDto fiDto = MockDataHelper.mockFailureInformationDto();
fiDto.setBranchId(null);
fiDto.setFailureClassificationId(null);
......@@ -201,14 +204,21 @@ public class FailureInformationServiceTest {
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);
// when(failureInformationRepository.save(any(TblFailureInformation.class))).thenReturn(fiTbl);
when(stationRepository.findByStationId(anyString())).thenReturn(Optional.of(tblStation));
when(addressRepository.findByStationId(anyString())).thenReturn(addressList);
when(failureInformationRepository.save(any(TblFailureInformation.class)))
.then((Answer<TblFailureInformation>) invocation -> {
Object[] args = invocation.getArguments();
return (TblFailureInformation) args[0];
});
when(histFailureInformationRepository.findByUuid(any(UUID.class))).thenReturn(listHistFailureInfos);
FailureInformationDto savedDto = failureInformationService.updateFailureInfo(fiDto);
assertEquals(fiDto.getUuid(), savedDto.getUuid());
assertEquals(fiTbl.getVersionNumber(), savedDto.getVersionNumber()+1);
assertEquals(listHistFailureInfos.size() + 1, savedDto.getVersionNumber());
assertEquals(fiTbl.getResponsibility(), savedDto.getResponsibility());
assertEquals(fiTbl.getInternExtern(), savedDto.getInternExtern());
assertEquals(fiTbl.getVoltageLevel(), savedDto.getVoltageLevel());
......@@ -226,6 +236,7 @@ public class FailureInformationServiceTest {
assertEquals(fiTbl.getStationCoords(), savedDto.getStationCoords());
assertEquals(fiTbl.getLongitude(), savedDto.getLongitude());
assertEquals(fiTbl.getLatitude(), savedDto.getLatitude());
assertEquals(5, savedDto.getAddressPolygonPoints().size());
}
@Test
......@@ -458,7 +469,7 @@ public class FailureInformationServiceTest {
FailureInformationDto savedDto = failureInformationService.storeFailureInfo(fiDto, GfiProcessState.NEW);
assertNotNull(savedDto.getUuid());
assertEquals(0L, savedDto.getVersionNumber());
assertEquals(1L, savedDto.getVersionNumber());
assertEquals(fiDto.getResponsibility(), savedDto.getResponsibility());
assertEquals(fiDto.getInternExtern(), savedDto.getInternExtern());
assertEquals(fiDto.getVoltageLevel(), savedDto.getVoltageLevel());
......@@ -535,7 +546,7 @@ public class FailureInformationServiceTest {
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());
......@@ -587,7 +598,7 @@ public class FailureInformationServiceTest {
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());
......
......@@ -191,6 +191,7 @@ public class MockDataHelper {
}
public static Page<TblFailureInformation> mockTblFailureInformationPage() {
List<TblFailureInformation> retList = new LinkedList<>();
retList.add( mockTblFailureInformation() );
......@@ -865,6 +866,7 @@ public class MockDataHelper {
return list;
}
public static List<String> mockPostCodes() {
List list = new ArrayList();
......
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