<commit_before>#
# 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 Domgen
  module JaxRS
    module MediaTypeEnabled
      def consumes
        @consumes || [:json, :xml]
      end

      def consumes=(consumes)
        consumes = [consumes] unless consumes.is_a?(Array)
        consumes.each do |media_type|
          Domgen.error("Specified media type '#{media_type}' is not valid") unless valid_media_type?(media_type)
        end
        @consumes = consumes
      end

      def produces
        @produces || [:json, :xml]
      end

      def produces=(produces)
        produces = [produces] unless produces.is_a?(Array)
        produces.each do |media_type|
          Domgen.error("Specified media type '#{media_type}' is not valid") unless valid_media_type?(media_type)
        end
        @produces = produces
      end

      def valid_media_type?(media_type)
        [:json, :xml, :plain].include?(media_type)
      end
    end
  end

  FacetManager.facet(:jaxrs => [:ee]) do |facet|
    facet.enhance(Repository) do
      include Domgen::Java::BaseJavaGenerator

      attr_writer :path

      def path
        @path || 'api'
      end

      java_artifact :abstract_application, :service, :server, :ee, '#{repository.name}JaxRsApplication'
    end

    facet.enhance(Service) do
      include Domgen::JaxRS::MediaTypeEnabled
      include Domgen::Java::BaseJavaGenerator

      def short_service_name
        service.name.to_s =~ /^(.*)Service/ ? service.name.to_s[0..-7] : service.name
      end

      java_artifact :service, :service, :server, :ee, '#{short_service_name}RestService'
      java_artifact :boundary, :service, :server, :ee, '#{service_name}Impl'

      attr_accessor :boundary_extends

      attr_writer :path

      def path
        return @path unless @path.nil?
        return "/#{Domgen::Naming.underscore(short_service_name)}"
      end
    end

    facet.enhance(Method) do
      include Domgen::JaxRS::MediaTypeEnabled

      attr_writer :path

      def path
        if @path<commit_msg>Fix short name so S is not duplicated if service already suffixed with Service<commit_after>#
# 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 Domgen
  module JaxRS
    module MediaTypeEnabled
      def consumes
        @consumes || [:json, :xml]
      end

      def consumes=(consumes)
        consumes = [consumes] unless consumes.is_a?(Array)
        consumes.each do |media_type|
          Domgen.error("Specified media type '#{media_type}' is not valid") unless valid_media_type?(media_type)
        end
        @consumes = consumes
      end

      def produces
        @produces || [:json, :xml]
      end

      def produces=(produces)
        produces = [produces] unless produces.is_a?(Array)
        produces.each do |media_type|
          Domgen.error("Specified media type '#{media_type}' is not valid") unless valid_media_type?(media_type)
        end
        @produces = produces
      end

      def valid_media_type?(media_type)
        [:json, :xml, :plain].include?(media_type)
      end
    end
  end

  FacetManager.facet(:jaxrs => [:ee]) do |facet|
    facet.enhance(Repository) do
      include Domgen::Java::BaseJavaGenerator

      attr_writer :path

      def path
        @path || 'api'
      end

      java_artifact :abstract_application, :service, :server, :ee, '#{repository.name}JaxRsApplication'
    end

    facet.enhance(Service) do
      include Domgen::JaxRS::MediaTypeEnabled
      include Domgen::Java::BaseJavaGenerator

      def short_service_name
        service.name.to_s =~ /^(.*)Service/ ? service.name.to_s[0..-8] : service.name
      end

      java_artifact :service, :service, :server, :ee, '#{short_service_name}RestService'
      java_artifact :boundary, :service, :server, :ee, '#{service_name}Impl'

      attr_accessor :boundary_extends

      attr_writer :path

      def path
        return @path unless @path.nil?
        return "/#{Domgen::Naming.underscore(short_service_name)}"
      end
    end

    facet.enhance(Method) do
      include Domgen::JaxRS::MediaTypeEnabled

      attr_writer :path

      def path
        if @path
{'fraction_non_alphanumeric': 0.09674273454261752, 'fraction_numerical': 0.0023405500292568754, 'mean_word_length': 2.890743550834598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '740776', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1504, 'n_words': 452}