<commit_before>#
# Copyright (C) 2010-2016 dtk contributors
#
# This file is part of the dtk project.
#
# Licensed 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.
#

module DTK
  module CommandAndControlAdapter::Ec2::Reified
    class Target
      # Using violations to fill in values of target components and validate them
      class ViolationProcessor
        def self.validate_and_fill_in_values(target_service, params = {})
          new(target_service).validate_and_fill_in_values!(params)
        end
        
        def initialize(target_service)
          @reified_target = Target.new(target_service)
        end

        def validate_and_fill_in_values!(params = {})
          ret = []
          any_unset_attributes = params[:any_unset_attributes]
          
          # Get all relevant components
          ndx_components = ComponentType.all.inject({}) do |h, cmp_type|
            h.merge(cmp_type => @reified_target.get_all_components_of_type(cmp_type))
          end
          
          missing_cmp_types = ComponentType.all.select { |cmp_type| ndx_components[cmp_type].empty? }
          unless missing_cmp_types.empty?
            missing_cmp_names = missing_cmp_types.map{ |cmp_type| ComponentType.name(cmp_type) }
            return [Violation::TargetServiceCmpsMissing.new(missing_cmp_names)]
          end        
          
          return ret if any_unset_attributes

          # validate_and_fill_in_values each reified_component
          # Need to do this in following order due to using earlier in oredr components to fil in gaps of ;ater ones
          # Do this first for iam_user and stop theersince error will be invalid credentials

          iam_user_viols = ndx_components[:iam_user].map { |reified_component| reified_component.validate_and_fill_in_values! }.flatten(1)
          ret += iam_user_viols
          return ret unless iam_user_viols.empty?
          ordered_cmp_type = [:vpc_subnet, :vpc, :security_group]
          ordered_cmp_type.each do |cmp_type|
            ndx_components[cmp_type].each do |reified_component|
              ret += reified_component.validate_and_fill_in_values!
            end<commit_msg>Removed auto-generation of vpc subnet and security group on server side It is expected that vpc related components handle this in puppet code<commit_after>#
# Copyright (C) 2010-2016 dtk contributors
#
# This file is part of the dtk project.
#
# Licensed 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.
#

module DTK
  module CommandAndControlAdapter::Ec2::Reified
    class Target
      # Using violations to fill in values of target components and validate them
      class ViolationProcessor
        def self.validate_and_fill_in_values(target_service, params = {})
          new(target_service).validate_and_fill_in_values!(params)
        end
        
        def initialize(target_service)
          @reified_target = Target.new(target_service)
        end

        def validate_and_fill_in_values!(params = {})
          ret = []
          any_unset_attributes = params[:any_unset_attributes]
          
          # Get all relevant components
          ndx_components = ComponentType.all.inject({}) do |h, cmp_type|
            h.merge(cmp_type => @reified_target.get_all_components_of_type(cmp_type))
          end
          
          missing_cmp_types = ComponentType.all.select { |cmp_type| ndx_components[cmp_type].empty? }
          unless missing_cmp_types.empty?
            missing_cmp_names = missing_cmp_types.map{ |cmp_type| ComponentType.name(cmp_type) }
            return [Violation::TargetServiceCmpsMissing.new(missing_cmp_names)]
          end        
          
          return ret if any_unset_attributes

          # validate_and_fill_in_values each reified_component
          # Need to do this in following order due to using earlier in oredr components to fil in gaps of ;ater ones
          # Do this first for iam_user and stop theersince error will be invalid credentials

          iam_user_viols = ndx_components[:iam_user].map { |reified_component| reified_component.validate_and_fill_in_values! }.flatten(1)
          ret += iam_user_viols
          return ret unless iam_user_viols.empty?
          ordered_cmp_type = [:vpc]
          ordered_cmp_type.each do |cmp_type|
            ndx_components[cmp_type].each do |reified_component|
              ret += reified_component.validate_and_fill_in_values!
            end
{'fraction_non_alphanumeric': 0.06519316493313522, 'fraction_numerical': 0.005200594353640416, 'mean_word_length': 2.9653902798232696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1923635', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1472, 'n_words': 453}