module Sbuilder ## # collect method, which all module ControllerUtils def dispatchExtendDomain( domainDef ) Utils::Validate.validateProperties( domainDef, Constants::VALIDATION[:domain_extension][:required], Constants::VALIDATION[:domain_extension][:allowed] ) Utils::Validate.oneOf( domainDef, Constants::VALIDATION[:domain_extension][:one_of] ) if !domainDef['cardinality'].nil? then extendDomainWithCardinality( domainDef ) elsif !domainDef['values'].nil? extendDomainWithValues( domainDef ) elsif !domainDef['range'].nil? extendDomainRange( domainDef ) elsif !domainDef['type'].nil? extendDomainWithType( domainDef ) else raise ExtensionException, "Invalid domain definition #{domainDef}" end end ## # Extend domain with (integer) range # # @param [Hash] # @option domainDef [String] range array lenght 2 start-stop # def extendDomainRange( domainDef ) # must be array with length of two, with first element less or equal raise ExtensionException, "Invalid domain range defintion" unless domainDef['range'] && domainDef['range'].is_a?( Array ) && domainDef['range'].length == 2 && domainDef['range'][0] <= domainDef['range'][1] domain = factory.createDomain( Sbuilder::Constants::TYPE_RANGE_DOMAIN ) domain.setName( domainDef['domain'] ) domain.setRange( domainDef['range'][0], domainDef['range'][1] ) # pass to model via controller extendDomain( domain ) end def extendDomainWithType( domainDef ) # @logger.info( "#{__method__}: domainDef=#{domainDef}" ) Utils::Validate.validateProperties( domainDef, Constants::VALIDATION[:domain_extension][:type_required], Constants::VALIDATION[:domain_extension][:type_allowed] ) # create & configure domain = factory.createDomain( Sbuilder::Constants::TYPE_DOMAIN_TYPE ) domain.setName( domainDef['domain'] ) domain.setType( domainDef['type'] ) # pass to model via controller extendDomain( domain ) end def extendDomainWithCardinality( domainDef ) # @logger.info( "#{__method__} domainDef=#{domainDef}" ) # validateProperties( domainDef, @@extensionDoaminProperties ) Utils::Validate.validateProperties( domainDef, Constants::VALIDATION[:domain_extension][:cardinality_required], Constants::VALIDATION[:domain_extension][:cardinality_allowed] ) # create & configure domain = factory.createDomain( Sbuilder::Constants::TYPE_CARDINALITY_DOMAIN ) domain.setName( domainDef['domain'] ) domain.setCardinality( domainDef['cardinality'] ) # pass to model via controller extendDomain( domain ) end # # @param [String] domainName # @param [String:Array] arrOfDomainValues # # Creates 'domainDef' and delegates to 'extendDomainWithValues' # def setApplicationDomainValues( domainName, arrOfDomainValues ) domainDef = { 'domain' => domainName, 'values' => arrOfDomainValues } # add to model addApplicationDomainValue( domainDef ) end def extendDomainWithValues( domainDef ) # @logger.info( "#{__method__} domainDef=#{domainDef}" ) # validateProperties( domainDef, @@extensionValuesProperties ) Utils::Validate.validateProperties( domainDef, Constants::VALIDATION[:domain_extension][:value_required], Constants::VALIDATION[:domain_extension][:value_allowed] ) # create & configure domain = factory.createDomain( Sbuilder::Constants::TYPE_VALUE_DOMAIN ) domain.setName( domainDef['domain'] ) domainDef['values'].each { |value| domain.addValue( value ) } # pass to model via controller extendDomain( domain ) end end end