-
Notifications
You must be signed in to change notification settings - Fork 26
FLPATH-313: get workflow by projectId #294
FLPATH-313: get workflow by projectId #294
Conversation
@RichardW98: This pull request references FLPATH-313 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@RichardW98: This pull request references FLPATH-313 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@@ -231,6 +234,22 @@ public void TestGetStatusWithValidData() throws Exception { | |||
.andExpect(MockMvcResultMatchers.status().isOk()); | |||
} | |||
|
|||
@Test | |||
void TestGetStatusByProjectIdWithValidData() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss the following test:
- where checks that the project is nill? Does it return all projects?
- What happens is getWorkFlowStatusByProjectId return an empty list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- yes it should return all projects which the user is allowed to check
- if it returns empty list then UI won't show any executions in the workflow table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add tests for them
@@ -907,6 +909,27 @@ public void testGetWorkflowParametersWithoutWorkflowOptions() { | |||
assertNull(workflowParameters.getWorkFlowOptions().getNewOptions()); | |||
} | |||
|
|||
@Test | |||
void getWorkFlowStatusByProjectId_when_projectIsFound_then_returnWorkFlowStatus() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to increase testing when no workflows with valid projects and what happens when JPA repo returns nil
@Override | ||
public List<WorkFlowStatusResponseDTO> getWorkFlowStatusByProjectId(UUID projectId) { | ||
return workFlowRepository.findAllByProjectId(projectId).stream() | ||
.map(workFlowExecution -> getWorkFlowStatus(workFlowExecution.getId())).toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the reason for this map?
Could you add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eloycoto stream().map()
allows applying a function to each stream element. So for me, it makes sense to iterate over the element and call getWorkflowStatus
and then collect all results into a List.
However, I agree that a unit test for this method is valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content) }) | ||
@GetMapping("/status") | ||
public ResponseEntity<List<WorkFlowStatusResponseDTO>> getStatusByProjectId( | ||
@RequestParam("projectId") String projectId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projectId should be marked as @NotNull
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content), | ||
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content) }) | ||
@GetMapping("/status") | ||
public ResponseEntity<List<WorkFlowStatusResponseDTO>> getStatusByProjectId( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what is the reason for it, but the generated openapi.json returns a string as a result while I'd expect the type of the return value to be a list.
however, if the project is mandatory in this context, I wonder why not expose the project-status endpoint instead.
if the purpose is to evaluate the project status, then it seems more natural to query for the project resource instead of the workflow, as project status might contain other information relevant to the project's overall status.
What will be the use of the new endpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method return the list of the statuses of all the workflows available in a project (if I understood correctly), maybe renaming the method into getStatusesByProjectId
can ease the understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gciavarrini @masayag new UI design has replaced the project Overview with workflows Overview (https://www.figma.com/file/iu0HAOSoLOESA2GHyxuHLg/parados-mui?node-id=3640-3490). Therefore project-status will not be needed any more, and instead we will need to show all workflow executions' info by project. I will update this pr to include data other than status in the return (e.g. startTime, endTime ...). @wKich has a pr for this in UI: rhdhorchestrator/backstage-parodos#124. please review
projectId.toString())) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$", hasSize(1))).andExpect(MockMvcResultMatchers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if a formatter issue: can you move the last andExpect
to a new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea. it's formatter 😅
@Override | ||
public List<WorkFlowStatusResponseDTO> getWorkFlowStatusByProjectId(UUID projectId) { | ||
return workFlowRepository.findAllByProjectId(projectId).stream() | ||
.map(workFlowExecution -> getWorkFlowStatus(workFlowExecution.getId())).toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eloycoto stream().map()
allows applying a function to each stream element. So for me, it makes sense to iterate over the element and call getWorkflowStatus
and then collect all results into a List.
However, I agree that a unit test for this method is valuable.
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content), | ||
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content) }) | ||
@GetMapping("/status") | ||
public ResponseEntity<List<WorkFlowStatusResponseDTO>> getStatusByProjectId( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method return the list of the statuses of all the workflows available in a project (if I understood correctly), maybe renaming the method into getStatusesByProjectId
can ease the understanding.
7b81873
to
5ff2dcf
Compare
@@ -26,4 +29,8 @@ | |||
*/ | |||
public interface ProjectRepository extends JpaRepository<Project, UUID> { | |||
|
|||
List<Project> findAllByUserUsername(String username); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add tests.
should be fairly simple with https://github.com/parodos-dev/parodos/pull/295/files#diff-43f3718db35688f81c93147df5fad5e6caf4bbdc988a24d007edd32db7a89372 (once it is being merged)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes Thank you for the example ~
ebc3aa0
to
7f3e4b0
Compare
7f3e4b0
to
7c4d6ef
Compare
7c4d6ef
to
e7a540b
Compare
e7a540b
to
f17ccf1
Compare
I renamed 'user' table to 'users' temporarily, will fix it in another pr to standandize table names |
@@ -33,4 +35,8 @@ public interface ProjectService { | |||
|
|||
List<ProjectResponseDTO> getProjects(); | |||
|
|||
List<ProjectResponseDTO> findProjectsByUserName(String userName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, let's keep userName
in lowercase
ldapDetails = (LdapUserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
return ldapDetails.getUsername(); | ||
} | ||
catch (NullPointerException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is expected to generate the NPE?
Could we replace this with if
instead of try-catch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is NPE related to ldapDetails? If so we could check instead of handling this exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SecurityContextHolder.getContext().getAuthentication() might be null. I will change it to if/else
@@ -172,6 +185,26 @@ public synchronized WorkFlowExecution updateWorkFlow(WorkFlowExecution workFlowE | |||
return workFlowRepository.save(workFlowExecution); | |||
} | |||
|
|||
@Override | |||
public List<WorkFlowResponseDTO> getWorkFlowsByProjectId(UUID projectId) { | |||
List<ProjectResponseDTO> projects = projectId == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it less predictable behavior? why not define projectId as @NotNull?
I'm not sure how users are created in the system, but what if the user has workflow in several projects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes then this controller will return all the workflows for this user, not limited to certain projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I think we should separate it into two service call, since the controller makes the decision on which service call to use, based on the input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will separate them
? projectService.findProjectsByUserName(SecurityUtils.getUsername()) | ||
: List.of(projectService.getProjectByIdAndUserName(projectId, SecurityUtils.getUsername())); | ||
return projects.stream().flatMap(project -> workFlowRepository.findAllByProjectId(project.getId()).stream() | ||
.filter(workFlowExecution -> workFlowExecution.getMainWorkFlowExecution() == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot is going on in this method, but in terms of readability, I find its readability being somewhat complex.
do you think it can be refactored a bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will move out the WorkFlowResponseDTO builder
public class ProjectRepositoryTest extends RepositoryTestBase { | ||
|
||
@Autowired | ||
private TestEntityManager entityManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entityManager
is already defined in RepositoryTestBase
as protected
and being used by this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will clean this
f17ccf1
to
ff031ca
Compare
c147156
to
9010b07
Compare
} | ||
|
||
@Override | ||
public List<WorkFlowResponseDTO> getWorkFlows() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps rename to getWorkFlowsForCurrentUser?
or to change the signature to accept username as a parameter and pass it from the caller (controller).
public class WorkFlowResponseDTO { | ||
|
||
private UUID workFlowExecutionId; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
private String projectId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls change to UUID.
6d6d51e
to
f859af3
Compare
f859af3
to
6a74b24
Compare
|
||
// then | ||
assertEquals(exception.getMessage(), String.format("Project with id: %s not found", project.getId())); | ||
assertNotNull(res); | ||
assertEquals(res.getId().toString(), project.getId().toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString() can be removed from both sides
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: masayag, wKich The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
FLPATH-313: get workflow by projectId
Change type
Impacted services
Checklist