Commit 21dc91b6 authored by dietricf's avatar dietricf
Browse files

SI-352 Grid first version

parent 8b941ddd
This diff is collapsed.
......@@ -50,6 +50,11 @@ public abstract class DecisionTask<T extends ProcessSubject> extends BaseTask<T>
}
}
@Override
protected void onEnterStep(T model) throws ProcessException {
}
@Override
protected void onLeaveStep(T model) throws ProcessException {
throw new ProcessException("onLeaveStep must not be called on a decision task object");
......
......@@ -16,14 +16,37 @@
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.extern.log4j.Log4j2;
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.DecideFailureInfoPlanned;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.StoreEditStatusServiceTask;
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;
import static org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.DecisionTask.OutputPort.YES;
import static org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState.*;
@Log4j2
@Component
public class GfiGrid extends ProcessGrid {
public GfiGrid() {
// TODO: Create the Grid here
public GfiGrid() throws ProcessException {
DecisionTask decidePlanned = register( NEW, new DecideFailureInfoPlanned());
ProcessTask storeEditStatusPlanned = new StoreEditStatusServiceTask( PLANNED );
ProcessTask enterMessage = register( PLANNED,
new UIStoreFailureInformationTask("State PLANNED UI Task", true));
ProcessTask storeEditStatusCreated = new StoreEditStatusServiceTask( CREATED );
ProcessTask qualifyMessage = register( CREATED,
new UIStoreFailureInformationTask( "State CREATED UI Task", true));
decidePlanned.connectOutputTo( YES, storeEditStatusPlanned );
decidePlanned.connectOutputTo( NO, storeEditStatusCreated );
storeEditStatusPlanned.connectOutputTo(enterMessage);
enterMessage.connectOutputTo( storeEditStatusCreated );
storeEditStatusCreated.connectOutputTo( qualifyMessage );
}
}
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.Data;
import org.eclipse.openk.gridfailureinformation.repository.FailureClassificationRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.repository.StatusRepository;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Data
public class GfiProcessEnvironment {
@Autowired
private FailureClassificationRepository failureClassificationRepository;
@Autowired
private FailureInformationRepository failureInformationRepository;
@Autowired
private StatusRepository statusRepository;
@Autowired
private FailureInformationService failureInformationService;
}
......@@ -20,29 +20,53 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
@Log4j2
public enum GfiProcessState implements ProcessState {
NEW (0),
APPLIED (1),
CANCELED (2),
UNDEFINED_ (-1); // NOSONAR
NEW (0),
CREATED (1),
PLANNED (2),
CREATED_PLANNED (3),
QUALIFIED (4),
CANCELED (5),
QUALIFIED_PUBLISHED (6),
WITHDRAWN (7),
UPDATED (8),
QUALIFIED_UPDATED (9),
COMPLETED (10),
UNDEFINED_ (-1); // NOSONAR
private final int statusValue;
private final long statusValue;
GfiProcessState(int statusValue ) {
GfiProcessState(long statusValue ) {
this.statusValue = statusValue;
}
public int getStatusValue() {
public long getStatusValue() {
return statusValue;
}
public static ProcessState fromValue( int statusValue ) { // NOSONAR complexity high but simple
switch( statusValue ) {
public static ProcessState fromValue( long statusValue ) { // NOSONAR complexity high but simple
switch( (int)statusValue ) {
case 0:
return NEW;
case 1:
return APPLIED;
return CREATED;
case 2:
return PLANNED;
case 3:
return CREATED_PLANNED;
case 4:
return QUALIFIED;
case 5:
return CANCELED;
case 6:
return QUALIFIED_PUBLISHED;
case 7:
return WITHDRAWN;
case 8:
return UPDATED;
case 9:
return QUALIFIED_UPDATED;
case 10:
return COMPLETED;
default:
log.error("Invalid statusValue:"+statusValue);
return UNDEFINED_;
......
......@@ -19,6 +19,7 @@ import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ProcessHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
@Log4j2
......@@ -26,19 +27,19 @@ import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
public class GfiProcessSubject implements ProcessSubject {
private FailureInformationDto failureInformationDto;
private String changeUser;
private ProcessState stateInDb;
private String jwt;
private ProcessHelper processHelper;
private GfiProcessSubject() {}
private GfiProcessSubject(FailureInformationDto failureInformationDto, String changeUser ) {
private GfiProcessSubject(FailureInformationDto failureInformationDto, ProcessHelper processHelper ) {
this.failureInformationDto = failureInformationDto;
this.changeUser = changeUser;
this.processHelper = processHelper;
}
public static GfiProcessSubject of(FailureInformationDto failureInformationDto, String changeUser ) {
return new GfiProcessSubject(failureInformationDto, changeUser);
public static GfiProcessSubject of(FailureInformationDto failureInformationDto, ProcessHelper processHelper ) {
return new GfiProcessSubject(failureInformationDto, processHelper);
}
}
/*
*******************************************************************************
* 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.DecisionTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessSubject;
@Log4j2
public class DecideFailureInfoPlanned extends DecisionTask<GfiProcessSubject> {
public DecideFailureInfoPlanned() {
super("Decision: Ist die Störungsinformation geplant?");
}
@Override
public OutputPort decide(GfiProcessSubject subject) throws ProcessException {
boolean isFailureInfoPlanned = subject.getProcessHelper().isFailureInfoPlanned(
subject.getFailureInformationDto());
String loggerOutput1 = "Decide: ";
if( isFailureInfoPlanned ) {
log.debug(loggerOutput1 + getDescription()+"\" -> Firing YES");
return OutputPort.YES;
}
else {
log.debug(loggerOutput1 + getDescription()+"\" -> Firing NO");
return OutputPort.NO;
}
}
}
package org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
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;
import org.springframework.stereotype.Component;
import java.util.Optional;
import java.util.UUID;
@Log4j2
@RequiredArgsConstructor
@Component
public class ProcessHelper {
@Autowired
private GfiProcessEnvironment environment;
@Value("${process.definitions.classification.plannedMeasureDbid}")
long plannedMeasureDbId;
public ProcessHelper(GfiProcessEnvironment environment) {
this.environment = environment;
}
public boolean isFailureInfoPlanned(FailureInformationDto dto) {
RefFailureClassification refPlannedMeasure = environment.getFailureClassificationRepository()
.findById(plannedMeasureDbId)
.orElseThrow(() -> new InternalServerErrorException("planned.measure.obj.not.found"));
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);
}
public ProcessState getProcessStateFromStatusUuid( UUID statusUuid ) {
Optional<RefStatus> optRefStatus = environment.getStatusRepository().findByUuid(statusUuid);
if( !optRefStatus.isPresent()) {
log.error("RefStatus <"+statusUuid+"> not found in DB");
throw new InternalServerErrorException("status.uuid.not.found");
}
return GfiProcessState.fromValue(optRefStatus.get().getId());
}
}
/*
*******************************************************************************
* 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 );
}
}
/*
*******************************************************************************
* 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.ProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.UserInteractionTask;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessSubject;
@Log4j2
public class UIStoreFailureInformationTask extends UserInteractionTask<GfiProcessSubject> {
private final boolean stayIfStateUnchanged;
public UIStoreFailureInformationTask(String description, boolean stayIfStateUnchanged) {
super(description);
this.stayIfStateUnchanged = stayIfStateUnchanged;
}
@Override
protected void onLeaveStep(GfiProcessSubject subject) throws ProcessException {
subject.getProcessHelper().storeFailureFromViewModel(subject.getFailureInformationDto());
}
@Override
protected void onEnterStep(GfiProcessSubject subject) throws ProcessException {
// nothing to do here
}
@Override
protected boolean isStayInThisTask(GfiProcessSubject subject){
return stayIfStateUnchanged && !detectStateChanged( subject );
}
@Override
protected void onStayInTask(GfiProcessSubject subject) throws ProcessException {
subject.getProcessHelper().storeFailureFromViewModel(subject.getFailureInformationDto());
}
private boolean detectStateChanged( GfiProcessSubject subject ) {
ProcessState stateFromObj = subject.getProcessHelper().getProcessStateFromStatusUuid(
subject.getFailureInformationDto().getStatusExternId());
return stateFromObj != subject.getStateInDb();
}
}
package org.eclipse.openk.gridfailureinformation.listener;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.springframework.stereotype.Component;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Optional;
@Component
public class TblFailureInformationListener {
@PreUpdate
@PrePersist
public void failureInformationPreUpdate(TblFailureInformation failureInformation ) {
failureInformation.setVersionNumber(
Optional.ofNullable(failureInformation.getVersionNumber()).orElse(0L)
+ 1);
}
}
......@@ -15,6 +15,7 @@
package org.eclipse.openk.gridfailureinformation.model;
import lombok.Data;
import org.eclipse.openk.gridfailureinformation.listener.TblFailureInformationListener;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
......@@ -28,7 +29,10 @@ import java.util.UUID;
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@EntityListeners({
AuditingEntityListener.class,
TblFailureInformationListener.class
})
public class TblFailureInformation {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tbl_failure_information_id_seq")
......
......@@ -18,6 +18,7 @@ package org.eclipse.openk.gridfailureinformation.repository;
import org.eclipse.openk.gridfailureinformation.model.RefStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
......@@ -28,4 +29,6 @@ public interface StatusRepository extends JpaRepository<RefStatus, Long > {
List<RefStatus> findAll();
Optional<RefStatus> findByUuid(UUID uuid);
Optional<RefStatus> findById( Long id );
}
......@@ -15,9 +15,16 @@
package org.eclipse.openk.gridfailureinformation.service;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiGrid;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessSubject;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ProcessHelper;
import org.eclipse.openk.gridfailureinformation.exceptions.InternalServerErrorException;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.model.HtblFailureInformation;
import org.eclipse.openk.gridfailureinformation.model.RefStatus;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
......@@ -29,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
@Log4j2
@Service
public class FailureInformationService {
......@@ -54,6 +61,12 @@ public class FailureInformationService {
@Autowired
private StatusRepository statusRepository;
@Autowired
private GfiGrid grid;
@Autowired
private ProcessHelper processHelper;
public FailureInformationDto findFailureInformation( UUID uuid ) {
return failureInformationMapper.toFailureInformationDto(
failureInformationRepository.findByUuid( uuid )
......@@ -64,32 +77,60 @@ public class FailureInformationService {
return failureInformationRepository.findAll(pageable).map(failureInformationMapper::toFailureInformationDto);
}
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto){
TblFailureInformation tblFailureInformationToSave = failureInformationMapper.toTblFailureInformation(failureInfoDto);
tblFailureInformationToSave.setUuid(UUID.randomUUID());
tblFailureInformationToSave.setVersionNumber(1L);
setFromGridFailureInformationDto(tblFailureInformationToSave, failureInfoDto);
return failureInformationMapper.toFailureInformationDto(failureInformationRepository.save(tblFailureInformationToSave));
@Transactional
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto) {
failureInfoDto.setUuid(null); // force null here
return processGrid(
storeFailureInfo(failureInfoDto)
);
}
@Transactional
public FailureInformationDto updateFailureInfo(FailureInformationDto failureInfoDto) {
TblFailureInformation tblFailureInformation = failureInformationRepository.findByUuid(failureInfoDto.getUuid())
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
return processGrid(failureInfoDto);
}
@Transactional
public FailureInformationDto storeFailureInfo(FailureInformationDto dto) {
TblFailureInformation tblFailureInformationToSave = failureInformationMapper.toTblFailureInformation(dto);
if(dto.getUuid() == null ) {
tblFailureInformationToSave.setUuid(UUID.randomUUID());
tblFailureInformationToSave.setVersionNumber(1L);
setFromGridFailureInformationDto(tblFailureInformationToSave, dto);
RefStatus statusNew = statusRepository.findById(Long.valueOf(GfiProcessState.NEW.getStatusValue()))
.orElseThrow(() -> new NotFoundException("ref.status.not.found"));
tblFailureInformationToSave.setRefStatusIntern(statusNew);
tblFailureInformationToSave.setRefStatusExtern(statusNew);
}
else {
TblFailureInformation tblFailureInformation = failureInformationRepository.findByUuid(dto.getUuid())
.orElseThrow(() -> new NotFoundException("failure.info.uuid.not.existing"));
tblFailureInformationToSave = failureInformationMapper.toTblFailureInformation(dto);
tblFailureInformationToSave.setId(tblFailureInformation.getId());
setFromGridFailureInformationDto(tblFailureInformationToSave, dto);
}
return failureInformationMapper.toFailureInformationDto(failureInformationRepository.save(tblFailureInformationToSave));