nandorsoma commented on code in PR #6769:
URL: https://github.com/apache/nifi/pull/6769#discussion_r1129108350


##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/preprocess/preprocessors/ConstraintAsnPreprocessor.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.jasn1.preprocess.preprocessors;
+
+import org.apache.nifi.jasn1.preprocess.NiFiASNPreprocessor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ConstraintAsnPreprocessor implements NiFiASNPreprocessor {
+    public static final String OPEN_BRACKET = "(";
+    public static final String CLOSE_BRACKET = ")";
+
+    public static final Pattern ALLOWED = Pattern.compile("^(\\d+\\))(.*)");
+
+    @Override
+    public List<String> preprocessAsn(List<String> lines) {
+        List<String> preprocessedLines = new ArrayList<>();
+
+        AtomicInteger unclosedCounter = new AtomicInteger(0);
+        lines.forEach(line -> {
+            StringBuilder preprocessedLine = new StringBuilder();
+
+            String contentToProcess = line;

Review Comment:
   Could you help me understand why?



##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/preprocess/AsnPreprocessorEngineTest.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.jasn1.preprocess;
+
+import org.apache.nifi.logging.ComponentLog;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.StringJoiner;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class AsnPreprocessorEngineTest {
+    private AsnPreprocessorEngine testSubject;
+    private AsnPreprocessorEngine helper;
+
+    private AsnPreprocessor mockPreprocessor1;
+    private AsnPreprocessor mockPreprocessor2;
+    private List<AsnPreprocessor> preprocessors;
+
+    private ComponentLog log;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        mockPreprocessor1 = mock(AsnPreprocessor.class);
+        mockPreprocessor2 = mock(AsnPreprocessor.class);
+
+        preprocessors = Arrays.asList(
+                mockPreprocessor1,
+                mockPreprocessor2
+        );
+
+        log = mock(ComponentLog.class);
+
+        helper = mock(AsnPreprocessorEngine.class);
+        testSubject = new AsnPreprocessorEngine() {
+            @Override
+            List<String> readAsnLines(ComponentLog componentLog, String 
inputFile, Path inputFilePath) {
+                return helper.readAsnLines(componentLog, inputFile, 
inputFilePath);
+            }
+
+            @Override
+            void writePreprocessedAsn(ComponentLog componentLog, String 
preprocessedAsn, Path preprocessedAsnPath) {
+                helper.writePreprocessedAsn(componentLog, preprocessedAsn, 
preprocessedAsnPath);
+            }
+
+            @Override
+            List<AsnPreprocessor> getPreprocessors() {
+                return preprocessors;
+            }
+        };
+
+        Files.createDirectories(Path.of("target/" + 
this.getClass().getSimpleName()));

Review Comment:
   Did you consider using `@TempDir` feature provided by JUnit5? It is 
experimental, but already used in the project.



##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1Reader.java:
##########
@@ -366,13 +387,13 @@ public void reportError(RecognitionException e) {
             }
         };
 
+        AsnModel model = new AsnModel();
+        parser.module_definitions(model);
+
         if (parseError.get()) {

Review Comment:
   I see, makes sense!



##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1Reader.java:
##########
@@ -193,10 +219,23 @@ protected Collection<ValidationResult> 
customValidate(ValidationContext validati
     @OnEnabled
     public void onEnabled(final ConfigurationContext context) throws 
InitializationException {
         if (context.getProperty(ASN_FILES) != null && 
context.getProperty(ASN_FILES).isSet()) {
-            String[] asnFilesPaths = 
Arrays.stream(context.getProperty(ASN_FILES).evaluateAttributeExpressions().getValue().split(","))
-                .map(String::trim)
-                .toArray(String[]::new);
+            String asnFilesString = 
context.getProperty(ASN_FILES).evaluateAttributeExpressions().getValue();

Review Comment:
   There are still a few lines that are missing finals.



##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/main/java/org/apache/nifi/jasn1/JASN1Reader.java:
##########
@@ -134,17 +135,32 @@ public class JASN1Reader extends 
AbstractConfigurableComponent implements Record
         .required(false)
         .build();
 
+    private static final PropertyDescriptor PREPROCESS_OUTPUT_DIRECTORY = new 
PropertyDescriptor.Builder()
+        .name("additional-preprocesszing-output-directory")
+        .displayName("Additional Preprocessing Output Directory")
+        .description("When set, NiFi will do additional preprocessing steps 
that creates modified versions of the provided ASN files," +
+                " removing unsupported features in a way that makes them less 
strict but otherwise should still be compatible with incoming data." +
+                " The original files will remain intact and new ones will be 
created with the same names in the provided directory." +
+                " For more information about these additional preprocessing 
steps please see Additional Details - Additional Preprocessing.")
+        .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)

Review Comment:
   Any thoughts on this? It is still there but in the new property.



-- 
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]

Reply via email to