Github user brosander commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi/pull/33#discussion_r79610232
  
    --- Diff: 
minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/ConfigSchema.java
 ---
    @@ -96,51 +100,154 @@ public ConfigSchema(Map map) {
             addIssuesIfNotNull(provenanceReportingProperties);
             addIssuesIfNotNull(provenanceRepositorySchema);
     
    +        Set<String> processorIds = new HashSet<>();
             if (processors != null) {
    -            
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_PROCESSOR_NAMES, 
processors.stream().map(ProcessorSchema::getName).collect(Collectors.toList()));
    +            List<String> processorIdList = 
processors.stream().map(ProcessorSchema::getId).collect(Collectors.toList());
    +            checkForDuplicates(this::addValidationIssue, 
FOUND_THE_FOLLOWING_DUPLICATE_PROCESSOR_IDS, processorIdList);
                 for (ProcessorSchema processorSchema : processors) {
                     addIssuesIfNotNull(processorSchema);
                 }
    +            processorIds.addAll(processorIdList);
             }
     
             if (connections != null) {
    -            
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_CONNECTION_NAMES, 
connections.stream().map(ConnectionSchema::getName).collect(Collectors.toList()));
    +            List<String> idList = 
connections.stream().map(ConnectionSchema::getId).filter(s -> 
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toList());
    +            checkForDuplicates(this::addValidationIssue, 
FOUND_THE_FOLLOWING_DUPLICATE_CONNECTION_IDS, idList);
                 for (ConnectionSchema connectionSchema : connections) {
                     addIssuesIfNotNull(connectionSchema);
                 }
             }
     
    +        Set<String> remoteInputPortIds = new HashSet<>();
             if (remoteProcessingGroups != null) {
    -            
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_PROCESSING_GROUP_NAMES,
 
remoteProcessingGroups.stream().map(RemoteProcessingGroupSchema::getName).collect(Collectors.toList()));
    +            checkForDuplicates(this::addValidationIssue, 
FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_PROCESSING_GROUP_NAMES,
    +                    
remoteProcessingGroups.stream().map(RemoteProcessingGroupSchema::getName).collect(Collectors.toList()));
                 for (RemoteProcessingGroupSchema remoteProcessingGroupSchema : 
remoteProcessingGroups) {
                     addIssuesIfNotNull(remoteProcessingGroupSchema);
                 }
    +            List<RemoteProcessingGroupSchema> remoteProcessingGroups = 
getRemoteProcessingGroups();
    +            if (remoteProcessingGroups != null) {
    +                List<String> remoteInputPortIdList = 
remoteProcessingGroups.stream().filter(r -> r.getInputPorts() != null)
    +                        .flatMap(r -> 
r.getInputPorts().stream()).map(RemoteInputPortSchema::getId).collect(Collectors.toList());
    +                checkForDuplicates(this::addValidationIssue, 
FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_INPUT_PORT_IDS, remoteInputPortIdList);
    +                remoteInputPortIds.addAll(remoteInputPortIdList);
    +            }
    +        }
    +
    +        Set<String> duplicateIds = new HashSet<>(processorIds);
    +        duplicateIds.retainAll(remoteInputPortIds);
    +        if (duplicateIds.size() > 0) {
    +            addValidationIssue(FOUND_THE_FOLLOWING_DUPLICATE_IDS + 
duplicateIds.stream().sorted().collect(Collectors.joining(", ")));
    +        }
    +    }
    +
    +    protected List<ProcessorSchema> getProcessorSchemas(List<Map> 
processorMaps) {
    +        if (processorMaps == null) {
    +            return null;
             }
    +        List<ProcessorSchema> processors = 
convertListToType(processorMaps, "processor", ProcessorSchema.class, 
PROCESSORS_KEY);
    +
    +        Map<String, Integer> idMap = 
processors.stream().map(ProcessorSchema::getId).filter(
    +                s -> 
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toMap(Function.identity(), s 
-> 2, Integer::compareTo));
    +
    +        // Set unset ids
    +        processors.stream().filter(connection -> 
StringUtil.isNullOrEmpty(connection.getId())).forEachOrdered(processor -> 
processor.setId(getUniqueId(idMap, processor.getName())));
    +
    +        return processors;
         }
     
    -    private void checkForDuplicateNames(String errorMessagePrefix, 
List<String> names) {
    -        if (names != null) {
    -            Set<String> seenNames = new HashSet<>();
    -            Set<String> duplicateNames = new TreeSet<>();
    -            for (String name : names) {
    -                if (!seenNames.add(name)) {
    -                    duplicateNames.add(name);
    +    protected List<ConnectionSchema> getConnectionSchemas(List<Map> 
connectionMaps) {
    +        if (connectionMaps == null) {
    +            return null;
    +        }
    +        List<ConnectionSchema> connections = 
convertListToType(connectionMaps, "connection", ConnectionSchema.class, 
CONNECTIONS_KEY);
    +        Map<String, Integer> idMap = 
connections.stream().map(ConnectionSchema::getId).filter(
    +                s -> 
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toMap(Function.identity(), s 
-> 2, Integer::compareTo));
    +
    +        Map<String, String> processorNameToIdMap = new HashMap<>();
    +
    +        // We can't look up id by name for names that appear more than once
    +        Set<String> duplicateProcessorNames = new HashSet<>();
    +
    +        List<ProcessorSchema> processors = getProcessors();
    +        if (processors != null) {
    +            processors.stream().forEachOrdered(p -> 
processorNameToIdMap.put(p.getName(), p.getId()));
    +
    +            Set<String> processorNames = new HashSet<>();
    +            
processors.stream().map(ProcessorSchema::getName).forEachOrdered(n -> {
    +                if (!processorNames.add(n)) {
    +                    duplicateProcessorNames.add(n);
                     }
    +            });
    +        }
    +
    +        Set<String> remoteInputPortIds = new HashSet<>();
    +        List<RemoteProcessingGroupSchema> remoteProcessingGroups = 
getRemoteProcessingGroups();
    +        if (remoteProcessingGroups != null) {
    +            
remoteInputPortIds.addAll(remoteProcessingGroups.stream().filter(r -> 
r.getInputPorts() != null)
    +                    .flatMap(r -> 
r.getInputPorts().stream()).map(RemoteInputPortSchema::getId).collect(Collectors.toSet()));
    +        }
    +
    +        Set<String> problematicDuplicateNames = new HashSet<>();
    +        // Set unset ids
    +        connections.stream().filter(connection -> 
StringUtil.isNullOrEmpty(connection.getId())).forEachOrdered(connection -> 
connection.setId(getUniqueId(idMap, connection.getName())));
    +
    +        connections.stream().filter(connection -> 
StringUtil.isNullOrEmpty(connection.getSourceId())).forEach(connection -> {
    +            String sourceName = connection.getSourceName();
    +            if (remoteInputPortIds.contains(sourceName)) {
    +                connection.setSourceId(sourceName);
    +            } else {
    +                if (duplicateProcessorNames.contains(sourceName)) {
    +                    problematicDuplicateNames.add(sourceName);
    +                }
    +                
connection.setSourceId(processorNameToIdMap.get(sourceName));
    --- End diff --
    
    @JPercivall good point, I will try to add a more specific message for that 
case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to