Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Set Workflow definition id format to UUID
Browse files Browse the repository at this point in the history
As part of validating the correctness of API parameters, both requests
and responses are updated for the workflow definition resource.

Signed-off-by: Moti Asayag <[email protected]>
  • Loading branch information
masayag authored and openshift-merge-robot committed May 4, 2023
1 parent 32aaebc commit 7c9181c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
6 changes: 4 additions & 2 deletions workflow-service/generated/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"name" : "id",
"required" : true,
"schema" : {
"type" : "string"
"type" : "string",
"format" : "uuid"
}
} ],
"responses" : {
Expand Down Expand Up @@ -487,7 +488,8 @@
"type" : "string"
},
"id" : {
"type" : "string"
"type" : "string",
"format" : "uuid"
},
"name" : {
"type" : "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ public ResponseEntity<List<WorkFlowDefinitionResponseDTO>> getWorkFlowDefinition
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content) })
@GetMapping("/{id}")
public ResponseEntity<WorkFlowDefinitionResponseDTO> getWorkFlowDefinitionById(@PathVariable String id) {
WorkFlowDefinitionResponseDTO response = workFlowDefinitionService
.getWorkFlowDefinitionById(UUID.fromString(id));
public ResponseEntity<WorkFlowDefinitionResponseDTO> getWorkFlowDefinitionById(@PathVariable UUID id) {
WorkFlowDefinitionResponseDTO response = workFlowDefinitionService.getWorkFlowDefinitionById(id);
if (response == null) {
return ResponseEntity.notFound().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.redhat.parodos.workflow.util.WorkFlowDTOUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
* Workflow task definition response dto
Expand All @@ -51,7 +51,7 @@
@NoArgsConstructor
public class WorkDefinitionResponseDTO {

private String id;
private UUID id;

private String name;

Expand Down Expand Up @@ -91,14 +91,14 @@ public WorkDefinitionResponseDTOBuilder parameterFromString(String parameters) {

public static WorkDefinitionResponseDTO fromWorkFlowDefinitionEntity(WorkFlowDefinition wd,
List<WorkFlowWorkDefinition> dependencies) {
return WorkDefinitionResponseDTO.builder().id(wd.getId().toString()).workType(WorkType.WORKFLOW.name())
.name(wd.getName()).parameterFromString(wd.getParameters()).processingType(wd.getProcessingType())
.works(new ArrayList<>()).numberOfWorkUnits(dependencies.size()).build();
return WorkDefinitionResponseDTO.builder().id(wd.getId()).workType(WorkType.WORKFLOW.name()).name(wd.getName())
.parameterFromString(wd.getParameters()).processingType(wd.getProcessingType()).works(new ArrayList<>())
.numberOfWorkUnits(dependencies.size()).build();
}

public static WorkDefinitionResponseDTO fromWorkFlowTaskDefinition(WorkFlowTaskDefinition wdt) {
return WorkDefinitionResponseDTO.builder().id(wdt.getId().toString()).workType(WorkType.TASK.name())
.name(wdt.getName()).parameterFromString(wdt.getParameters())
return WorkDefinitionResponseDTO.builder().id(wdt.getId()).workType(WorkType.TASK.name()).name(wdt.getName())
.parameterFromString(wdt.getParameters())
.outputs(WorkFlowDTOUtil.readStringAsObject(wdt.getOutputs(), new TypeReference<>() {
}, List.of())).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<WorkDefinitionResponseDTO> convert(
List<WorkFlowTaskDefinition> source = context.getSource();
return source.stream().map(workFlowTaskDefinition -> {
try {
return WorkDefinitionResponseDTO.builder().id(workFlowTaskDefinition.getId().toString())
return WorkDefinitionResponseDTO.builder().id(workFlowTaskDefinition.getId())
.name(workFlowTaskDefinition.getName())
.outputs(objectMapper.readValue(workFlowTaskDefinition.getOutputs(), new TypeReference<>() {
})).parameterFromString(workFlowTaskDefinition.getParameters()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void getWorksFromWorkDefinition(List<WorkFlowWorkDefinition> workFlowWor
return;
}
switch (workType) {
case TASK:
case TASK -> {
Optional<WorkFlowTaskDefinition> wdt = workFlowTaskDefinitionRepository
.findById(workFlowWorkDefinition.getWorkDefinitionId());
if (wdt.isEmpty()) {
Expand All @@ -248,8 +248,8 @@ private void getWorksFromWorkDefinition(List<WorkFlowWorkDefinition> workFlowWor
return;
}
responseDTOs.add(WorkDefinitionResponseDTO.fromWorkFlowTaskDefinition(wdt.get()));
break;
case WORKFLOW:
}
case WORKFLOW -> {
Optional<WorkFlowDefinition> wd = workFlowDefinitionRepository
.findById(workFlowWorkDefinition.getWorkDefinitionId());
if (wd.isEmpty()) {
Expand All @@ -259,12 +259,11 @@ private void getWorksFromWorkDefinition(List<WorkFlowWorkDefinition> workFlowWor
}
List<WorkFlowWorkDefinition> wdWorkFlowWorkDependencies = workFlowWorkRepository
.findByWorkFlowDefinitionIdOrderByCreateDateAsc(wd.get().getId());

responseDTOs.add(WorkDefinitionResponseDTO.fromWorkFlowDefinitionEntity(wd.get(),
wdWorkFlowWorkDependencies));
break;
default:
return;
}
default -> {
}
}
});

Expand All @@ -276,11 +275,11 @@ private List<WorkDefinitionResponseDTO> buildWorkFlowWorksDTOs(WorkFlowDefinitio
Map<String, Integer> workFlowWorksStartIndex = new HashMap<>();

// add workflow
workDefinitionResponseDTOs.add(WorkDefinitionResponseDTO.builder().id(workFlowDefinition.getId().toString())
.workType(WorkType.WORKFLOW.name()).name(workFlowDefinition.getName())
.parameterFromString(workFlowDefinition.getParameters())
.processingType(workFlowDefinition.getProcessingType()).works(new ArrayList<>())
.numberOfWorkUnits(workFlowWorkDefinitions.size()).build());
workDefinitionResponseDTOs.add(
WorkDefinitionResponseDTO.builder().id(workFlowDefinition.getId()).workType(WorkType.WORKFLOW.name())
.name(workFlowDefinition.getName()).parameterFromString(workFlowDefinition.getParameters())
.processingType(workFlowDefinition.getProcessingType()).works(new ArrayList<>())
.numberOfWorkUnits(workFlowWorkDefinitions.size()).build());
workFlowWorksStartIndex.put(workFlowDefinition.getName(), 1);

// add workflowWorkUnits
Expand All @@ -296,8 +295,7 @@ private List<WorkDefinitionResponseDTO> buildWorkFlowWorksDTOs(WorkFlowDefinitio
workDefinitionResponseDTOs.size());

List<WorkFlowWorkDefinition> workFlowWorkUnits1Definition = workFlowWorkRepository
.findByWorkFlowDefinitionIdOrderByCreateDateAsc(
UUID.fromString(workDefinitionResponseDTOs.get(i).getId()))
.findByWorkFlowDefinitionIdOrderByCreateDateAsc(workDefinitionResponseDTOs.get(i).getId())
.stream().sorted(Comparator.comparing(WorkFlowWorkDefinition::getCreateDate))
.collect(Collectors.toList());
this.getWorksFromWorkDefinition(workFlowWorkUnits1Definition, workDefinitionResponseDTOs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.redhat.parodos.workflow.definition.controller;

import java.util.List;
import java.util.UUID;

import com.redhat.parodos.ControllerMockClient;
import com.redhat.parodos.workflow.definition.dto.WorkDefinitionResponseDTO;
import com.redhat.parodos.workflow.definition.dto.WorkFlowDefinitionResponseDTO;
Expand All @@ -17,9 +20,6 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import java.util.UUID;
import java.util.List;

@SpringBootTest
@DirtiesContext
@AutoConfigureMockMvc
Expand Down Expand Up @@ -126,8 +126,8 @@ private WorkFlowDefinitionResponseDTO createSampleWorkFlowDefinition(String name

private WorkDefinitionResponseDTO createSampleWorkFlowTaskDefinition(String name) {
String parameters = "{\"param1\": {\"description\": \"param1\"}}";
return WorkDefinitionResponseDTO.builder().id(UUID.randomUUID().toString()).name(name)
.parameterFromString(parameters).build();
return WorkDefinitionResponseDTO.builder().id(UUID.randomUUID()).name(name).parameterFromString(parameters)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testFromWorkFlowTaskDefinition() {
WorkDefinitionResponseDTO result = WorkDefinitionResponseDTO.fromWorkFlowTaskDefinition(wdt);

// then
assertEquals(result.getId(), id.toString());
assertEquals(id, result.getId());
assertEquals(result.getWorkType(), WorkType.TASK.name());
assertEquals(result.getName(), "foo");

Expand Down Expand Up @@ -60,7 +60,7 @@ public void testFromWorkFlowTaskDefinitionWithParameters() {
WorkDefinitionResponseDTO result = WorkDefinitionResponseDTO.fromWorkFlowDefinitionEntity(wd, dependencies);

// then
assertEquals(result.getId(), id.toString());
assertEquals(id, result.getId());
assertEquals(result.getWorkType(), WorkType.WORKFLOW.name());
assertEquals(result.getName(), "foo");

Expand Down

0 comments on commit 7c9181c

Please sign in to comment.