mcgilman commented on code in PR #8965:
URL: https://github.com/apache/nifi/pull/8965#discussion_r1847286910
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerServiceResource.java:
##########
@@ -683,6 +686,209 @@ public Response updateControllerService(
);
}
+ @GET
+ @Consumes(MediaType.WILDCARD)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{id}/move-options")
+ @Operation(
+ summary = "Gets the move options for a controller service",
+ responses = @ApiResponse(content = @Content(schema =
@Schema(implementation = ProcessGroupOptionEntity.class))),
+ security = {
+ @SecurityRequirement(name = "Read - /flow")
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(responseCode = "400", description = "NiFi was
unable to complete the request because it was invalid. The request should not
be retried without modification."),
+ @ApiResponse(responseCode = "401", description = "Client
could not be authenticated."),
+ @ApiResponse(responseCode = "403", description = "Client
is not authorized to make this request."),
+ @ApiResponse(responseCode = "404", description = "The
specified resource could not be found."),
+ @ApiResponse(responseCode = "409", description = "The
request was valid but NiFi was not in the appropriate state to process it.")
+ }
+ )
+ public Response getProcessGroupOptions(
+ @Parameter(description = "The controller service id.")
+ @PathParam("id") final String controllerServiceId) {
+
+ if (controllerServiceId == null) {
+ throw new IllegalArgumentException("Controller service id must be
specified.");
+ }
+
+ List<ProcessGroupOptionEntity> options = new ArrayList<>();
+ serviceFacade.authorizeAccess(lookup -> {
+ final NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+ final ComponentAuthorizable authorizableControllerService =
lookup.getControllerService(controllerServiceId);
+
authorizableControllerService.getAuthorizable().authorize(authorizer,
RequestAction.WRITE, user);
+
+ final ControllerServiceDTO controllerServiceDTO =
serviceFacade.getControllerService(controllerServiceId, true).getComponent();
+
+ final ProcessGroupAuthorizable authorizableProcessGroupCurrent =
lookup.getProcessGroup(controllerServiceDTO.getParentGroupId());
+
authorizableProcessGroupCurrent.getAuthorizable().authorize(authorizer,
RequestAction.WRITE, user);
+
+ if (authorizableProcessGroupCurrent.getProcessGroup().getParent()
!= null) {
+ final ProcessGroupAuthorizable authorizableProcessGroupParent
=
lookup.getProcessGroup(authorizableProcessGroupCurrent.getProcessGroup().getParent().getIdentifier());
+
authorizableProcessGroupParent.getAuthorizable().authorize(authorizer,
RequestAction.WRITE, user);
+
+ options.add(generateProcessGroupOption(controllerServiceDTO,
authorizableProcessGroupParent));
+ }
+
+
authorizableProcessGroupCurrent.getProcessGroup().getProcessGroups().forEach(processGroup
-> {
+ final ProcessGroupAuthorizable authorizableProcessGroup =
lookup.getProcessGroup(processGroup.getIdentifier());
+
authorizableProcessGroup.getAuthorizable().authorize(authorizer,
RequestAction.WRITE, user);
+ options.add(generateProcessGroupOption(controllerServiceDTO,
authorizableProcessGroup));
+ });
+ });
+
+ return generateOkResponse(options).build();
+ }
+
+ private ProcessGroupOptionEntity
generateProcessGroupOption(ControllerServiceDTO controllerServiceDTO,
ProcessGroupAuthorizable processGroup) {
+ List<String> conflictingComponents = new ArrayList<>();
+ controllerServiceDTO.getReferencingComponents().forEach(e -> {
+ if (processGroup.getProcessGroup().findProcessor(e.getId()) == null
+ &&
processGroup.getProcessGroup().findControllerService(e.getId(), true, false) ==
null) {
+ conflictingComponents.add("[" + e.getComponent().getName() +
"]");
Review Comment:
If I take away permissions from a component that references the Service I'm
trying to remove this line generates a `NullPointerException`
```
2024-11-18 16:04:51,256 ERROR [NiFi Web Server-76]
o.a.nifi.web.api.config.ThrowableMapper An unexpected error has occurred:
java.lang.NullPointerException: Cannot invoke
"org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO.getName()"
because the return value of
"org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity.getComponent()"
is null. Returning Internal Server Error response.
java.lang.NullPointerException: Cannot invoke
"org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO.getName()"
because the return value of
"org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity.getComponent()"
is null
at
org.apache.nifi.web.api.ControllerServiceResource.lambda$generateProcessGroupOption$18(ControllerServiceResource.java:751)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]