resolved conflicts
This commit is contained in:
@@ -20,11 +20,13 @@ import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
import net.gepafin.tendermanagement.repositories.FlowEdgesRepository;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import net.gepafin.tendermanagement.service.FormService;
|
||||
import net.gepafin.tendermanagement.util.DateTimeUtil;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -47,10 +49,11 @@ public class FlowDao {
|
||||
@Autowired
|
||||
private FormService formService;
|
||||
|
||||
public FlowResponseBean createFlow(FlowRequestBean flowRequestBean, Long callId) {
|
||||
public FlowResponseBean createOrUpdateFlow(FlowRequestBean flowRequestBean, Long callId) {
|
||||
validateFlowRequestBean(flowRequestBean);
|
||||
CallEntity call = setInitialAndFinalFormInCall(flowRequestBean, callId);
|
||||
checkIfFlowExits(callId);
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
checkIfFlowExits(call);
|
||||
call= setInitialAndFinalFormInCall(flowRequestBean, call);
|
||||
validateFlowRequest(flowRequestBean);
|
||||
List<FlowDataEntity> flowDataEntities = createFlowData(flowRequestBean,call);
|
||||
List<FlowEdgesEntity> flowEdgesEntities = createFlowEdges(flowRequestBean,call);
|
||||
@@ -59,24 +62,30 @@ public class FlowDao {
|
||||
}
|
||||
|
||||
public void validateFlowRequestBean(FlowRequestBean flowRequestBean){
|
||||
if(flowRequestBean.getFlowData()==null || flowRequestBean.getFlowEdges()==null){
|
||||
if (flowRequestBean.getFlowEdges() == null || flowRequestBean.getFlowEdges().isEmpty()) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.FLOW_REQUEST_NOT_PROPER));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfFlowExits(Long callId) {
|
||||
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(callId);
|
||||
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(callId);
|
||||
if (!flowDataEntities.isEmpty() || !flowEdgesEntities.isEmpty()) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.FLOW_ALREADY_EXISTS));
|
||||
public void checkIfFlowExits(CallEntity call) {
|
||||
List<FlowDataEntity> flowDataEntities = flowDataRepository.findByCallId(call.getId());
|
||||
List<FlowEdgesEntity> flowEdgesEntities = flowEdgesRepository.findByCallId(call.getId());
|
||||
if (Boolean.FALSE.equals(flowDataEntities.isEmpty()) || Boolean.FALSE.equals(flowEdgesEntities.isEmpty())) {
|
||||
call.setInitialForm(null);
|
||||
call.setFinalForm(null);
|
||||
call=callRepository.save(call);
|
||||
flowDataRepository.deleteAll(flowDataEntities);
|
||||
flowEdgesRepository.deleteAll(flowEdgesEntities);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateFlowRequest(FlowRequestBean flowRequestBean) {
|
||||
formService.validateForm(flowRequestBean.getInitialForm());
|
||||
formService.validateForm(flowRequestBean.getFinalForm());
|
||||
if(flowRequestBean.getFlowData()!=null && !flowRequestBean.getFlowData().isEmpty()) {
|
||||
flowRequestBean.getFlowData().forEach(flowData -> formService.validateForm(flowData.getFormId()));
|
||||
}
|
||||
}
|
||||
|
||||
private List<FlowEdgesResponseBean> createFlowEdgesResponseBean(List<FlowEdgesEntity> flowEdgesEntities) {
|
||||
List<FlowEdgesResponseBean> flowEdgesResponseBeans = flowEdgesEntities.stream()
|
||||
@@ -96,20 +105,23 @@ public class FlowDao {
|
||||
return flowResponseBean;
|
||||
}
|
||||
|
||||
private CallEntity setInitialAndFinalFormInCall(FlowRequestBean flowRequestBean, Long callId) {
|
||||
CallEntity call = callService.validateCall(callId);
|
||||
private CallEntity setInitialAndFinalFormInCall(FlowRequestBean flowRequestBean, CallEntity call) {
|
||||
call.setInitialForm(flowRequestBean.getInitialForm());
|
||||
call.setFinalForm(flowRequestBean.getFinalForm());
|
||||
call.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||
call = callRepository.save(call);
|
||||
return call;
|
||||
}
|
||||
|
||||
public List<FlowDataEntity> createFlowData(FlowRequestBean flowRequestBean, CallEntity call) {
|
||||
if (flowRequestBean.getFlowData() != null || !flowRequestBean.getFlowEdges().isEmpty()) {
|
||||
List<FlowDataEntity> flowDataEntities = flowRequestBean.getFlowData().stream()
|
||||
.map(flowDataRequestBean -> createFlowDataEntity(flowDataRequestBean, call))
|
||||
.collect(Collectors.toList());
|
||||
return flowDataRepository.saveAll(flowDataEntities);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FlowDataEntity createFlowDataEntity(FlowDataRequestBean flowDataRequestBean,CallEntity call) {
|
||||
FlowDataEntity flowDataEntity = new FlowDataEntity();
|
||||
@@ -129,6 +141,7 @@ public class FlowDao {
|
||||
|
||||
public FlowEdgesEntity createFlowEdgesEntity(FlowEdgesRequestBean flowEdgesRequestBean,CallEntity call) {
|
||||
FlowEdgesEntity flowEdgesEntity = new FlowEdgesEntity();
|
||||
flowEdgesEntity.setTrackingId(flowEdgesRequestBean.getId());
|
||||
flowEdgesEntity.setSourceId(Long.valueOf(flowEdgesRequestBean.getSource()));
|
||||
flowEdgesEntity.setTargetId(Long.valueOf(flowEdgesRequestBean.getTarget()));
|
||||
flowEdgesEntity.setType(flowEdgesRequestBean.getType());
|
||||
@@ -147,7 +160,7 @@ public class FlowDao {
|
||||
|
||||
public FlowEdgesResponseBean convertFlowEdgesEntityToFlowEdgesResponseBean(FlowEdgesEntity flowEdgesEntity) {
|
||||
FlowEdgesResponseBean flowEdgesResponseBean = new FlowEdgesResponseBean();
|
||||
flowEdgesResponseBean.setId(flowEdgesEntity.getId());
|
||||
flowEdgesResponseBean.setId(flowEdgesEntity.getTrackingId());
|
||||
flowEdgesResponseBean.setType(flowEdgesEntity.getType());
|
||||
flowEdgesResponseBean.setSource(String.valueOf(flowEdgesEntity.getSourceId()));
|
||||
flowEdgesResponseBean.setTarget(String.valueOf(flowEdgesEntity.getTargetId()));
|
||||
@@ -163,7 +176,7 @@ public class FlowDao {
|
||||
List<FlowEdgesResponseBean> flowEdgesResponseBeans=createFlowEdgesResponseBean(flowEdgesEntities);
|
||||
flowResponseBean.setFlowData(flowDataResponseBeans);
|
||||
flowResponseBean.setFlowEdges(flowEdgesResponseBeans);
|
||||
if(flowResponseBean.getFlowData().isEmpty() || flowResponseBean.getFlowEdges().isEmpty()){
|
||||
if( flowResponseBean.getFlowEdges().isEmpty()){
|
||||
return null;
|
||||
}
|
||||
flowResponseBean.setCallId(call.getId());
|
||||
|
||||
@@ -25,4 +25,7 @@ public class FlowEdgesEntity extends BaseEntity {
|
||||
@Column(name="CALL_ID")
|
||||
private Long callId;
|
||||
|
||||
@Column(name="TRACKING_ID")
|
||||
private String trackingId;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import lombok.Data;
|
||||
@Data
|
||||
public class FlowEdgesRequestBean {
|
||||
|
||||
private String id;
|
||||
|
||||
private String source;
|
||||
|
||||
private String target;
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.security.core.parameters.P;
|
||||
|
||||
@Data
|
||||
public class FlowEdgesResponseBean {
|
||||
private Long id;
|
||||
private String id;
|
||||
|
||||
private String source;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
|
||||
public interface FlowService {
|
||||
|
||||
public FlowResponseBean createFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId);
|
||||
public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId);
|
||||
|
||||
public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.gepafin.tendermanagement.model.response.FlowResponseBean;
|
||||
import net.gepafin.tendermanagement.service.FlowService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class FlowServiceImpl implements FlowService {
|
||||
@@ -15,11 +16,13 @@ public class FlowServiceImpl implements FlowService {
|
||||
private FlowDao flowDao;
|
||||
|
||||
@Override
|
||||
public FlowResponseBean createFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
return flowDao.createFlow(flowRequestBean,callId);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public FlowResponseBean createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
return flowDao.createOrUpdateFlow(flowRequestBean,callId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@org.springframework.transaction.annotation.Transactional(readOnly = true)
|
||||
public FlowResponseBean getFlowByCallId(HttpServletRequest request, Long callId) {
|
||||
return flowDao.getFlowByCallId(callId);
|
||||
}
|
||||
|
||||
@@ -15,17 +15,14 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
public interface FlowApi {
|
||||
|
||||
@Operation(summary = "Api to create flow",
|
||||
@Operation(summary = "Api to create or update flow",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -34,9 +31,9 @@ public interface FlowApi {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@PostMapping(value = "/call/{callId}",
|
||||
@PutMapping(value = "/call/{callId}",
|
||||
produces = { "application/json" })
|
||||
ResponseEntity<Response<FlowResponseBean>> createFlow(HttpServletRequest request,
|
||||
ResponseEntity<Response<FlowResponseBean>> createOrUpdateFlow(HttpServletRequest request,
|
||||
@Parameter(description = " Flow request object", required = true) @Valid @RequestBody FlowRequestBean flowRequestBean,
|
||||
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);
|
||||
|
||||
|
||||
@@ -26,15 +26,13 @@ public class FlowApiController implements FlowApi {
|
||||
private FlowService flowService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public ResponseEntity<Response<FlowResponseBean>> createFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
FlowResponseBean flowResponseBean=flowService.createFlow(httpServletRequest,flowRequestBean,callId);
|
||||
public ResponseEntity<Response<FlowResponseBean>> createOrUpdateFlow(HttpServletRequest httpServletRequest, FlowRequestBean flowRequestBean, Long callId) {
|
||||
FlowResponseBean flowResponseBean=flowService.createOrUpdateFlow(httpServletRequest,flowRequestBean,callId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(flowResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.FLOW_CREATED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public ResponseEntity<Response<FlowResponseBean>> getFlowByCallId(HttpServletRequest request, Long callId) {
|
||||
FlowResponseBean flowResponseBean=flowService.getFlowByCallId(request,callId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
|
||||
@@ -651,4 +651,10 @@
|
||||
path="classpath:db/dump/inserted_form_field_data_13_09_2024.sql" />
|
||||
</changeSet>
|
||||
|
||||
|
||||
<changeSet id="12-09-2024_1" author="Rajesh Khore">
|
||||
<addColumn tableName="flow_edges">
|
||||
<column name="tracking_id" type="VARCHAR(255)"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
||||
Reference in New Issue
Block a user