kevdoran commented on a change in pull request #3536: NIFI-6380: Introduced the 
notion of Parameters and Parameter Contexts…
URL: https://github.com/apache/nifi/pull/3536#discussion_r300025065
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java
 ##########
 @@ -0,0 +1,279 @@
+/*
+ * 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.parameter;
+
+import org.apache.nifi.authorization.Resource;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.authorization.resource.ResourceFactory;
+import org.apache.nifi.authorization.resource.ResourceType;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ComponentNode;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.controller.PropertyConfiguration;
+import org.apache.nifi.controller.service.ControllerServiceNode;
+import org.apache.nifi.controller.service.ControllerServiceState;
+import org.apache.nifi.groups.ProcessGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class StandardParameterContext implements ParameterContext {
+    private static final Logger logger = 
LoggerFactory.getLogger(StandardParameterContext.class);
+
+    private final String id;
+    private final ParameterReferenceManager parameterReferenceManager;
+
+    private String name;
+    private long version = 0L;
+    private final Map<ParameterDescriptor, Parameter> parameters = new 
LinkedHashMap<>();
+    private volatile String description;
+
+    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    private final Lock readLock = rwLock.readLock();
+    private final Lock writeLock = rwLock.writeLock();
+
+
+    public StandardParameterContext(final String id, final String name, final 
ParameterReferenceManager parameterReferenceManager) {
+        this.id = Objects.requireNonNull(id);
+        this.name = Objects.requireNonNull(name);
+        this.parameterReferenceManager = parameterReferenceManager;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return id;
+    }
+
+    public String getName() {
+        readLock.lock();
+        try {
+            return name;
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public void setName(final String name) {
+        writeLock.lock();
+        try {
+            this.version++;
+            this.name = name;
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    public void setParameters(final Set<Parameter> updatedParameters) {
+        writeLock.lock();
+        try {
+            this.version++;
+
+            verifyCanSetParameters(updatedParameters);
+
+            for (final Parameter parameter : updatedParameters) {
+                if (parameter.getValue() == null) {
+                    parameters.remove(parameter.getDescriptor());
 
 Review comment:
   Alternatively, as we expect at least the sensitive flag to always be 
populated, do we want to say that the front end should pass a fully specified 
object for parameter creation or update, and that just passing the parameter 
name with no other field indicates deletion?
   
   That is...
   
   **Indicate update value of param1:**
   ```
   {
       "name": "param1"
       "sensitive": "true"
       "description": "My existing, unchanged description."
       "value": "newSecretValue"
   }
   ```
   
   **Indicate update description of param1 (don't modify value):**
   ```
   {
       "name": "param1"
       "sensitive": "true"
       "description": "My updated description"
   }
   ```
   
   **Indicate delete param1:**
   ```
   {
       "name": "param1"
   }
   ```
   
   And sensitivity and name are both immutable, right?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to