public static void merge(PropertyDescriptorDTO clientPropertyDescriptor, Map<NodeIdentifier, PropertyDescriptorDTO> dtoMap) { final Map<Integer, List<AllowableValueEntity>> 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<NodeIdentifier, PropertyDescriptorDTO> nodeEntry : dtoMap.entrySet()) { final PropertyDescriptorDTO nodePropertyDescriptor = nodeEntry.getValue(); final List<AllowableValueEntity> nodePropertyDescriptorAllowableValues = nodePropertyDescriptor.getAllowableValues(); if (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<AllowableValueEntity> clientPropertyDescriptorAllowableValues = clientPropertyDescriptor.getAllowableValues(); if (clientPropertyDescriptorAllowableValues != null) { for (AllowableValueEntity clientAllowableValueEntity : clientPropertyDescriptorAllowableValues) { AllowableValueEntityMerger.merge(clientAllowableValueEntity, allowableValueMap.get(clientPropertyDescriptorAllowableValues.indexOf(clientAllowableValueEntity))); } } } }
private Map<String,ComponentDescriptor> buildComponentDescriptorMap(final ProcessorConfigDTO processorConfig){ final Map<String, ComponentDescriptor> descriptors = new HashMap<>(); for(String key : processorConfig.getDescriptors().keySet()){ PropertyDescriptorDTO descriptor = processorConfig.getDescriptors().get(key); List<AllowableValueEntity> allowableValuesEntity = descriptor.getAllowableValues(); Map<String,String> allowableValues = new HashMap<>(); if(allowableValuesEntity != null) { for (AllowableValueEntity allowableValueEntity : allowableValuesEntity) { final AllowableValueDTO allowableValueDTO = allowableValueEntity.getAllowableValue(); allowableValues.put(allowableValueDTO.getValue(), allowableValueDTO.getDisplayName()); } } ComponentDescriptor componentDescriptor = new ComponentDescriptor.Builder() .name(descriptor.getName()) .displayName(descriptor.getDisplayName()) .defaultValue(descriptor.getDefaultValue()) .allowableValues(allowableValues) .build(); descriptors.put(key,componentDescriptor); } return descriptors; }