Freedom9339 commented on code in PR #7734:
URL: https://github.com/apache/nifi/pull/7734#discussion_r1513374784


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java:
##########
@@ -2939,6 +2939,115 @@ public ControllerServiceEntity 
updateControllerService(final Revision revision,
         return 
entityFactory.createControllerServiceEntity(snapshot.getComponent(), 
dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, 
operatePermissions, bulletinEntities);
     }
 
+    @Override
+    public ControllerServiceEntity moveControllerService(final Revision 
revision, final ControllerServiceDTO controllerServiceDTO, final String 
newProcessGroupID) {
+        // get the component, ensure we have access to it, and perform the 
move request
+        final ControllerServiceNode controllerService = 
controllerServiceDAO.getControllerService(controllerServiceDTO.getId());
+        final RevisionUpdate<ControllerServiceDTO> snapshot = 
updateComponent(revision,
+                controllerService,
+                () -> moveControllerServiceWork(controllerService, 
newProcessGroupID),
+                cs -> {
+                    awaitValidationCompletion(cs);
+                    final ControllerServiceDTO dto = 
dtoFactory.createControllerServiceDto(cs);
+                    final ControllerServiceReference ref = 
controllerService.getReferences();
+                    final ControllerServiceReferencingComponentsEntity 
referencingComponentsEntity = 
createControllerServiceReferencingComponentsEntity(ref);
+                    
dto.setReferencingComponents(referencingComponentsEntity.getControllerServiceReferencingComponents());
+                    return dto;
+                });
+
+        final PermissionsDTO permissions = 
dtoFactory.createPermissionsDto(controllerService);
+        final PermissionsDTO operatePermissions = 
dtoFactory.createPermissionsDto(new OperationAuthorizable(controllerService));
+        final List<BulletinDTO> bulletins = 
dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(controllerServiceDTO.getId()));
+        final List<BulletinEntity> bulletinEntities = 
bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, 
permissions.getCanRead())).collect(Collectors.toList());
+        return 
entityFactory.createControllerServiceEntity(snapshot.getComponent(), 
dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, 
operatePermissions, bulletinEntities);
+    }
+
+    private ControllerServiceNode moveControllerServiceWork(final 
ControllerServiceNode controllerService, final String newProcessGroupID) {
+        final ProcessGroup oldParentGroup = 
controllerService.getProcessGroup();
+        Set<ComponentNode> referencedComponents = 
controllerService.getReferences().getReferencingComponents();
+        isReferencesDisabled(referencedComponents);
+        oldParentGroup.removeControllerService(controllerService);
+        ProcessGroup newParent;
+        if (!oldParentGroup.isRootGroup() && 
oldParentGroup.getParent().getIdentifier().equals(newProcessGroupID)) {
+            // move to parent process group
+            newParent = oldParentGroup.getParent();
+            newParent.addControllerService(controllerService);
+
+            // unset any references the controller services has to other 
controller services that are now out of scope
+            Map<String, String> updatedProps = new HashMap<>();
+            Set<Map.Entry<PropertyDescriptor, PropertyConfiguration>> 
properties = controllerService.getProperties().entrySet();
+            for (var prop : properties) {
+                var value = prop.getValue();
+                if (value !=null) {
+                    ControllerServiceNode controller;
+                    try {
+                        controller = 
controllerServiceDAO.getControllerService((value.getRawValue()));
+                    } catch (Exception e){
+                        continue;
+                    }

Review Comment:
   Fixed, but then removed as it was no longer needed



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to