From bbdd087d7790592569b3d9440d66722c17500852 Mon Sep 17 00:00:00 2001 From: Jeff Storck Date: Wed, 10 Aug 2016 17:44:44 -0400 Subject: [PATCH] NIFI-1876 Implemented PropertyDescriptorDTO merging NIFI-1876 Updated PermissionsDTO to use boolean primitives instead of Boolean objects for read and write permission Removed ISE throwing from EntityFactory, it will rely on null checks instead This closes #694 Signed-off-by: jpercivall --- .../nifi/web/api/dto/AllowableValueDTO.java | 16 +++ .../nifi/web/api/dto/PermissionsDTO.java | 4 +- .../manager/AllowableValueEntityMerger.java | 32 ++++++ .../ControllerServiceEntityMerger.java | 103 +++++++++++++++--- .../manager/ProcessorEntityMerger.java | 19 +++- .../manager/PropertyDescriptorDtoMerger.java | 52 +++++++++ .../manager/ReportingTaskEntityMerger.java | 19 ++++ .../nifi/web/StandardNiFiServiceFacade.java | 1 - .../apache/nifi/web/api/dto/DtoFactory.java | 4 +- .../nifi/web/api/dto/EntityFactory.java | 101 ++++------------- 10 files changed, 250 insertions(+), 101 deletions(-) create mode 100644 nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/AllowableValueEntityMerger.java create mode 100644 nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PropertyDescriptorDtoMerger.java diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AllowableValueDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AllowableValueDTO.java index 24c937eebe..61571537b4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AllowableValueDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AllowableValueDTO.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.nifi.web.api.dto; import com.wordnik.swagger.annotations.ApiModelProperty; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/PermissionsDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/PermissionsDTO.java index 8039cda880..ca00605bed 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/PermissionsDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/PermissionsDTO.java @@ -26,8 +26,8 @@ import javax.xml.bind.annotation.XmlType; @XmlType(name = "permission") public class PermissionsDTO implements ReadablePermission, WritablePermission { - private Boolean canRead; - private Boolean canWrite; + private boolean canRead = false; + private boolean canWrite = false; /** * @return Indicates whether the user can read a given resource. diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/AllowableValueEntityMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/AllowableValueEntityMerger.java new file mode 100644 index 0000000000..64e83f3aeb --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/AllowableValueEntityMerger.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.cluster.manager; + +import org.apache.nifi.web.api.entity.AllowableValueEntity; + +import java.util.Collection; + +public class AllowableValueEntityMerger { + public static void merge(AllowableValueEntity clientAllowableValue, Collection allowableValues) { + for (AllowableValueEntity allowableValue : allowableValues) { + if (clientAllowableValue.getCanRead() && !allowableValue.getCanRead()) { + clientAllowableValue.setAllowableValue(allowableValue.getAllowableValue()); + clientAllowableValue.setCanRead(allowableValue.getCanRead()); + } + } + } +} diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java index 02d8e7e61c..fd9a387ffb 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMerger.java @@ -21,9 +21,11 @@ import org.apache.nifi.controller.service.ControllerServiceState; import org.apache.nifi.web.api.dto.ControllerServiceDTO; import org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO; import org.apache.nifi.web.api.dto.PermissionsDTO; +import org.apache.nifi.web.api.dto.PropertyDescriptorDTO; import org.apache.nifi.web.api.entity.ControllerServiceEntity; import org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -58,6 +60,7 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger> validationErrorMap = new HashMap<>(); final Set referencingComponents = clientDto.getReferencingComponents(); final Map> nodeReferencingComponentsMap = new HashMap<>(); + final Map> propertyDescriptorMap = new HashMap<>(); String state = null; for (final Map.Entry nodeEntry : dtoMap.entrySet()) { @@ -79,6 +82,25 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger descriptors = nodeControllerService.getDescriptors(); + if (descriptors != null) { + descriptors.values().stream().forEach(propertyDescriptor -> { + propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor); + }); + } + } + } + + // merge property descriptors + for (Map propertyDescriptorByNodeId : propertyDescriptorMap.values()) { + final Collection nodePropertyDescriptors = propertyDescriptorByNodeId.values(); + if (!nodePropertyDescriptors.isEmpty()) { + // get the name of the property descriptor and find that descriptor being returned to the client + final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next(); + final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName()); + PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); } } @@ -108,32 +130,34 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger 0) { - final Integer current = activeThreadCounts.get(nodeReferencingComponent.getId()); - if (current == null) { - activeThreadCounts.put(nodeReferencingComponent.getId(), nodeReferencingComponent.getActiveThreadCount()); - } else { - activeThreadCounts.put(nodeReferencingComponent.getId(), nodeReferencingComponent.getActiveThreadCount() + current); + if (nodeReferencingComponentEntity.getPermissions().getCanRead()) { + // handle active thread counts + if (nodeReferencingComponent.getActiveThreadCount() != null && nodeReferencingComponent.getActiveThreadCount() > 0) { + final Integer current = activeThreadCounts.get(nodeReferencingComponent.getId()); + if (current == null) { + activeThreadCounts.put(nodeReferencingComponent.getId(), nodeReferencingComponent.getActiveThreadCount()); + } else { + activeThreadCounts.put(nodeReferencingComponent.getId(), nodeReferencingComponent.getActiveThreadCount() + current); + } } - } - // handle controller service state - final String state = states.get(nodeReferencingComponent.getId()); - if (state == null) { - if (ControllerServiceState.DISABLING.name().equals(nodeReferencingComponent.getState())) { - states.put(nodeReferencingComponent.getId(), ControllerServiceState.DISABLING.name()); - } else if (ControllerServiceState.ENABLING.name().equals(nodeReferencingComponent.getState())) { - states.put(nodeReferencingComponent.getId(), ControllerServiceState.ENABLING.name()); + // handle controller service state + final String state = states.get(nodeReferencingComponent.getId()); + if (state == null) { + if (ControllerServiceState.DISABLING.name().equals(nodeReferencingComponent.getState())) { + states.put(nodeReferencingComponent.getId(), ControllerServiceState.DISABLING.name()); + } else if (ControllerServiceState.ENABLING.name().equals(nodeReferencingComponent.getState())) { + states.put(nodeReferencingComponent.getId(), ControllerServiceState.ENABLING.name()); + } } } // handle read permissions - final PermissionsDTO mergedPermissions = canReads.get(nodeReferencingComponent.getId()); + final PermissionsDTO mergedPermissions = canReads.get(nodeReferencingComponentEntity.getId()); final PermissionsDTO permissions = nodeReferencingComponentEntity.getPermissions(); if (permissions != null) { if (mergedPermissions == null) { - canReads.put(nodeReferencingComponent.getId(), permissions); + canReads.put(nodeReferencingComponentEntity.getId(), permissions); } else { PermissionsDtoMerger.mergePermissions(mergedPermissions, permissions); } @@ -156,6 +180,20 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger nodeEntities = new HashMap<>(); + referencingComponentMap.entrySet().forEach(entry -> { + final NodeIdentifier nodeIdentifier = entry.getKey(); + final Set nodeControllerServiceReferencingComponents = entry.getValue(); + + nodeControllerServiceReferencingComponents.forEach(nodeControllerServiceReferencingComponent -> { + if (referencingComponent.getId() != null && referencingComponent.getId().equals(nodeControllerServiceReferencingComponent.getId())) { + nodeEntities.put(nodeIdentifier, nodeControllerServiceReferencingComponent); + } + }); + }); + + mergeControllerServiceReferencingComponent(referencingComponent, nodeEntities); } else { referencingComponent.setPermissions(permissions); referencingComponent.setComponent(null); @@ -163,4 +201,35 @@ public class ControllerServiceEntityMerger implements ComponentEntityMerger nodeEntities) { + final Map> propertyDescriptorMap = new HashMap<>(); + + final Map> nodeReferencingComponentsMap = new HashMap<>(); + + // aggregate the property descriptors + for (Map.Entry entry : nodeEntities.entrySet()) { + final NodeIdentifier nodeIdentifier = entry.getKey(); + final ControllerServiceReferencingComponentEntity nodeEntity = entry.getValue(); + nodeEntity.getComponent().getDescriptors().values().stream().forEach(propertyDescriptor -> { + propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeIdentifier, propertyDescriptor); + }); + nodeReferencingComponentsMap.put(nodeIdentifier, nodeEntity.getComponent().getReferencingComponents()); + } + + // merge property descriptors + for (Map propertyDescriptorByNodeId : propertyDescriptorMap.values()) { + final Collection nodePropertyDescriptors = propertyDescriptorByNodeId.values(); + if (!nodePropertyDescriptors.isEmpty()) { + // get the name of the property descriptor and find that descriptor being returned to the client + final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next(); + final PropertyDescriptorDTO clientPropertyDescriptor = clientEntity.getComponent().getDescriptors().get(propertyDescriptor.getName()); + PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); + } + } + + final Set referencingComponents = clientEntity.getComponent().getReferencingComponents(); + mergeControllerServiceReferences(referencingComponents, nodeReferencingComponentsMap); + } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ProcessorEntityMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ProcessorEntityMerger.java index f3dbf1b396..2553828a26 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ProcessorEntityMerger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ProcessorEntityMerger.java @@ -18,9 +18,11 @@ package org.apache.nifi.cluster.manager; import org.apache.nifi.cluster.protocol.NodeIdentifier; import org.apache.nifi.web.api.dto.ProcessorDTO; +import org.apache.nifi.web.api.dto.PropertyDescriptorDTO; import org.apache.nifi.web.api.dto.status.ProcessorStatusDTO; import org.apache.nifi.web.api.entity.ProcessorEntity; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -70,14 +72,29 @@ public class ProcessorEntityMerger implements ComponentEntityMerger> validationErrorMap = new HashMap<>(); + final Map> propertyDescriptorMap = new HashMap<>(); for (final Map.Entry nodeEntry : dtoMap.entrySet()) { final ProcessorDTO nodeProcessor = nodeEntry.getValue(); - // merge the validation errors, if authorized + // merge the validation errors and aggregate the property descriptors, if authorized if (nodeProcessor != null) { final NodeIdentifier nodeId = nodeEntry.getKey(); ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeProcessor.getValidationErrors()); + nodeProcessor.getConfig().getDescriptors().values().stream().forEach(propertyDescriptor -> { + propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor); + }); + } + } + + // merge property descriptors + for (Map propertyDescriptorByNodeId : propertyDescriptorMap.values()) { + final Collection nodePropertyDescriptors = propertyDescriptorByNodeId.values(); + if (!nodePropertyDescriptors.isEmpty()) { + // get the name of the property descriptor and find that descriptor being returned to the client + final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next(); + final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getConfig().getDescriptors().get(propertyDescriptor.getName()); + PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PropertyDescriptorDtoMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PropertyDescriptorDtoMerger.java new file mode 100644 index 0000000000..e7ab8812ef --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/PropertyDescriptorDtoMerger.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.cluster.manager; + +import org.apache.nifi.cluster.protocol.NodeIdentifier; +import org.apache.nifi.web.api.dto.PropertyDescriptorDTO; +import org.apache.nifi.web.api.entity.AllowableValueEntity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PropertyDescriptorDtoMerger { + public static void merge(PropertyDescriptorDTO clientPropertyDescriptor, Map dtoMap) { + final Map> allowableValueMap = new HashMap<>(); + + // values are guaranteed to be in order, so map each allowable value for each property descriptor across all node IDs to the index of the value in the descriptor's list of allowable values + for (final Map.Entry nodeEntry : dtoMap.entrySet()) { + final PropertyDescriptorDTO nodePropertyDescriptor = nodeEntry.getValue(); + final List nodePropertyDescriptorAllowableValues = nodePropertyDescriptor.getAllowableValues(); + if (clientPropertyDescriptor != nodePropertyDescriptor && nodePropertyDescriptorAllowableValues != null) { + nodePropertyDescriptorAllowableValues.stream().forEach(allowableValueEntity -> { + allowableValueMap.computeIfAbsent(nodePropertyDescriptorAllowableValues.indexOf(allowableValueEntity), propertyDescriptorToAllowableValue -> new ArrayList<>()) + .add(allowableValueEntity); + }); + } + } + + // for each AllowableValueEntity in this PropertyDescriptorDTO, get the corresponding AVs previously aggregated and merge them. + final List clientPropertyDescriptorAllowableValues = clientPropertyDescriptor.getAllowableValues(); + if (clientPropertyDescriptorAllowableValues != null) { + for (AllowableValueEntity clientAllowableValueEntity : clientPropertyDescriptorAllowableValues) { + AllowableValueEntityMerger.merge(clientAllowableValueEntity, allowableValueMap.get(clientPropertyDescriptorAllowableValues.indexOf(clientAllowableValueEntity))); + } + } + } +} diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ReportingTaskEntityMerger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ReportingTaskEntityMerger.java index 552983dd21..e6bfba3d42 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ReportingTaskEntityMerger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/ReportingTaskEntityMerger.java @@ -17,9 +17,11 @@ package org.apache.nifi.cluster.manager; import org.apache.nifi.cluster.protocol.NodeIdentifier; +import org.apache.nifi.web.api.dto.PropertyDescriptorDTO; import org.apache.nifi.web.api.dto.ReportingTaskDTO; import org.apache.nifi.web.api.entity.ReportingTaskEntity; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -51,6 +53,7 @@ public class ReportingTaskEntityMerger implements ComponentEntityMerger> validationErrorMap = new HashMap<>(); + final Map> propertyDescriptorMap = new HashMap<>(); int activeThreadCount = 0; for (final Map.Entry nodeEntry : dtoMap.entrySet()) { @@ -66,6 +69,22 @@ public class ReportingTaskEntityMerger implements ComponentEntityMerger { + propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor); + }); + } + } + + // merge property descriptors + for (Map propertyDescriptorByNodeId : propertyDescriptorMap.values()) { + final Collection nodePropertyDescriptors = propertyDescriptorByNodeId.values(); + if (!nodePropertyDescriptors.isEmpty()) { + // get the name of the property descriptor and find that descriptor being returned to the client + final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next(); + final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName()); + PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java index a1b662cfcd..34890adc71 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java @@ -1,4 +1,3 @@ -/* /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java index 46cf87cbb8..a7b720a863 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java @@ -2502,7 +2502,9 @@ public final class DtoFactory { dto.setAllowableValues(null); } else { final List allowableValues = new ArrayList<>(); - for (final String serviceIdentifier : controllerServiceProvider.getControllerServiceIdentifiers(serviceDefinition, groupId)) { + final List controllerServiceIdentifiers = new ArrayList<>(controllerServiceProvider.getControllerServiceIdentifiers(serviceDefinition, groupId)); + Collections.sort(controllerServiceIdentifiers, Collator.getInstance(Locale.US)); + for (final String serviceIdentifier : controllerServiceIdentifiers) { final ControllerServiceNode service = controllerServiceProvider.getControllerServiceNode(serviceIdentifier); final boolean isServiceAuthorized = service.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); final String displayName = isServiceAuthorized ? service.getName() : serviceIdentifier; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java index 3e4e79aafa..9ddfaa3b00 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/EntityFactory.java @@ -67,8 +67,6 @@ import java.util.List; public final class EntityFactory { - private static final String NO_PERMISSIONS_MESSAGE = "No permissions were associated with this request"; - public StatusHistoryEntity createStatusHistoryEntity(final StatusHistoryDTO statusHistory, final PermissionsDTO permissions) { final StatusHistoryEntity entity = new StatusHistoryEntity(); entity.setCanRead(permissions.getCanRead()); @@ -85,6 +83,7 @@ public final class EntityFactory { public ProcessorStatusSnapshotEntity createProcessorStatusSnapshotEntity(final ProcessorStatusSnapshotDTO status, final PermissionsDTO permissions) { final ProcessorStatusSnapshotEntity entity = new ProcessorStatusSnapshotEntity(); + entity.setId(status.getId()); entity.setCanRead(permissions.getCanRead()); entity.setProcessorStatusSnapshot(status); // always set the status, as it's always allowed... just need to provide permission context for merging responses return entity; @@ -99,6 +98,7 @@ public final class EntityFactory { public ConnectionStatusSnapshotEntity createConnectionStatusSnapshotEntity(final ConnectionStatusSnapshotDTO status, final PermissionsDTO permissions) { final ConnectionStatusSnapshotEntity entity = new ConnectionStatusSnapshotEntity(); + entity.setId(status.getId()); entity.setCanRead(permissions.getCanRead()); entity.setConnectionStatusSnapshot(status); // always set the status, as it's always allowed... just need to provide permission context for merging responses return entity; @@ -113,6 +113,7 @@ public final class EntityFactory { public ProcessGroupStatusSnapshotEntity createProcessGroupStatusSnapshotEntity(final ProcessGroupStatusSnapshotDTO status, final PermissionsDTO permissions) { final ProcessGroupStatusSnapshotEntity entity = new ProcessGroupStatusSnapshotEntity(); + entity.setId(status.getId()); entity.setCanRead(permissions.getCanRead()); entity.setProcessGroupStatusSnapshot(status); // always set the status, as it's always allowed... just need to provide permission context for merging responses return entity; @@ -127,6 +128,7 @@ public final class EntityFactory { public RemoteProcessGroupStatusSnapshotEntity createRemoteProcessGroupStatusSnapshotEntity(final RemoteProcessGroupStatusSnapshotDTO status, final PermissionsDTO permissions) { final RemoteProcessGroupStatusSnapshotEntity entity = new RemoteProcessGroupStatusSnapshotEntity(); + entity.setId(status.getId()); entity.setCanRead(permissions.getCanRead()); entity.setRemoteProcessGroupStatusSnapshot(status); // always set the status, as it's always allowed... just need to provide permission context for merging responses return entity; @@ -141,21 +143,19 @@ public final class EntityFactory { public PortStatusSnapshotEntity createPortStatusSnapshotEntity(final PortStatusSnapshotDTO status, final PermissionsDTO permissions) { final PortStatusSnapshotEntity entity = new PortStatusSnapshotEntity(); + entity.setId(status.getId()); entity.setCanRead(permissions.getCanRead()); entity.setPortStatusSnapshot(status); // always set the status, as it's always allowed... just need to provide permission context for merging responses return entity; } public ControllerConfigurationEntity createControllerConfigurationEntity(final ControllerConfigurationDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ControllerConfigurationEntity entity = new ControllerConfigurationEntity(); entity.setRevision(revision); entity.setCurrentTime(new Date()); if (dto != null) { entity.setPermissions(permissions); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -163,9 +163,6 @@ public final class EntityFactory { } public ProcessGroupFlowEntity createProcessGroupFlowEntity(final ProcessGroupFlowDTO dto, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ProcessGroupFlowEntity entity = new ProcessGroupFlowEntity(); entity.setProcessGroupFlow(dto); entity.setPermissions(permissions); @@ -175,9 +172,6 @@ public final class EntityFactory { public ProcessorEntity createProcessorEntity(final ProcessorDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final ProcessorStatusDTO status, final List bulletins) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); if (dto != null) { @@ -186,7 +180,7 @@ public final class EntityFactory { entity.setId(dto.getId()); entity.setInputRequirement(dto.getInputRequirement()); entity.setPosition(dto.getPosition()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } @@ -195,9 +189,6 @@ public final class EntityFactory { } public PortEntity createPortEntity(final PortDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final PortStatusDTO status, final List bulletins) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final PortEntity entity = new PortEntity(); entity.setRevision(revision); if (dto != null) { @@ -206,7 +197,7 @@ public final class EntityFactory { entity.setId(dto.getId()); entity.setPosition(dto.getPosition()); entity.setPortType(dto.getType()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } @@ -216,10 +207,6 @@ public final class EntityFactory { public ProcessGroupEntity createProcessGroupEntity(final ProcessGroupDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final ProcessGroupStatusDTO status, final List bulletins) { - - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ProcessGroupEntity entity = new ProcessGroupEntity(); entity.setRevision(revision); entity.setCurrentTime(new Date()); @@ -245,9 +232,6 @@ public final class EntityFactory { } public LabelEntity createLabelEntity(final LabelDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final LabelEntity entity = new LabelEntity(); entity.setRevision(revision); if (dto != null) { @@ -260,7 +244,7 @@ public final class EntityFactory { dimensions.setWidth(dto.getWidth()); entity.setDimensions(dimensions); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -268,16 +252,13 @@ public final class EntityFactory { } public UserEntity createUserEntity(final UserDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final UserEntity entity = new UserEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -285,16 +266,13 @@ public final class EntityFactory { } public TenantEntity createTenantEntity(final TenantDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final TenantEntity entity = new TenantEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -302,16 +280,13 @@ public final class EntityFactory { } public AccessPolicySummaryEntity createAccessPolicySummaryEntity(final AccessPolicySummaryDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final AccessPolicySummaryEntity entity = new AccessPolicySummaryEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -319,16 +294,13 @@ public final class EntityFactory { } public UserGroupEntity createUserGroupEntity(final UserGroupDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final UserGroupEntity entity = new UserGroupEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -336,9 +308,6 @@ public final class EntityFactory { } public AccessPolicyEntity createAccessPolicyEntity(final AccessPolicyDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final AccessPolicyEntity entity = new AccessPolicyEntity(); entity.setRevision(revision); entity.setGenerated(new Date()); @@ -346,7 +315,7 @@ public final class EntityFactory { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -354,16 +323,13 @@ public final class EntityFactory { } public FunnelEntity createFunnelEntity(final FunnelDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final FunnelEntity entity = new FunnelEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); entity.setPosition(dto.getPosition()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -371,9 +337,6 @@ public final class EntityFactory { } public ConnectionEntity createConnectionEntity(final ConnectionDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final ConnectionStatusDTO status) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ConnectionEntity entity = new ConnectionEntity(); entity.setRevision(revision); if (dto != null) { @@ -390,7 +353,7 @@ public final class EntityFactory { entity.setDestinationId(dto.getDestination().getId()); entity.setDestinationGroupId(dto.getDestination().getGroupId()); entity.setDestinationType(dto.getDestination().getType()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -399,10 +362,6 @@ public final class EntityFactory { public RemoteProcessGroupEntity createRemoteProcessGroupEntity(final RemoteProcessGroupDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final RemoteProcessGroupStatusDTO status, final List bulletins) { - - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final RemoteProcessGroupEntity entity = new RemoteProcessGroupEntity(); entity.setRevision(revision); if (dto != null) { @@ -412,7 +371,7 @@ public final class EntityFactory { entity.setPosition(dto.getPosition()); entity.setInputPortCount(dto.getInputPortCount()); entity.setOutputPortCount(dto.getOutputPortCount()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } @@ -421,15 +380,12 @@ public final class EntityFactory { } public RemoteProcessGroupPortEntity createRemoteProcessGroupPortEntity(final RemoteProcessGroupPortDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final RemoteProcessGroupPortEntity entity = new RemoteProcessGroupPortEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setRemoteProcessGroupPort(dto); } } @@ -444,15 +400,12 @@ public final class EntityFactory { } public ReportingTaskEntity createReportingTaskEntity(final ReportingTaskDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final List bulletins) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ReportingTaskEntity entity = new ReportingTaskEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } @@ -462,16 +415,13 @@ public final class EntityFactory { } public ControllerServiceEntity createControllerServiceEntity(final ControllerServiceDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final List bulletins) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ControllerServiceEntity entity = new ControllerServiceEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); entity.setPosition(dto.getPosition()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } @@ -481,16 +431,12 @@ public final class EntityFactory { public ControllerServiceReferencingComponentEntity createControllerServiceReferencingComponentEntity( final ControllerServiceReferencingComponentDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { - - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final ControllerServiceReferencingComponentEntity entity = new ControllerServiceReferencingComponentEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } @@ -499,14 +445,11 @@ public final class EntityFactory { } public FlowBreadcrumbEntity createFlowBreadcrumbEntity(final FlowBreadcrumbDTO dto, final PermissionsDTO permissions) { - if (permissions == null || permissions.getCanRead() == null) { - throw new IllegalStateException(NO_PERMISSIONS_MESSAGE); - } final FlowBreadcrumbEntity entity = new FlowBreadcrumbEntity(); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); - if (permissions.getCanRead()) { + if (permissions != null && permissions.getCanRead()) { entity.setBreadcrumb(dto); } }