Class: CapicuaGen::Gaspar::CSRESTFULCatalogFeature

Inherits:
TemplateFeature
  • Object
show all
Includes:
CapicuaGen, CapicuaGen::Gaspar, Melchior
Defined in:
lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb

Overview

Caracteristica generadora para acceso a catalogos de RestFUL creados a traves de entidades de negocio

Instance Method Summary collapse

Methods included from CapicuaGen::Gaspar

#get_about_class_full_name, #get_about_class_name, #get_app_config_file, #get_db_connection_name_method, #get_db_connection_provider_method, #get_db_connection_string_method, #get_entity_data_access_full_name, #get_entity_data_access_name, #get_entity_full_name, #get_entity_interface_full_name, #get_entity_interface_name, #get_entity_name, #get_main_form_class_full_name, #get_main_form_class_name, #get_namespaces, #get_namespaces_text, #get_splash_class_full_name, #get_splash_class_name

Constructor Details

#initialize(values = {}) ⇒ CSRESTFULCatalogFeature

Inicializa la caracteristica



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 43

def initialize(values= {})
  super(values)

  # Configuro los tipos si estos no han sido configurados previamente
  self.types= [:catalog] if self.types.blank?

  # Configuro los templates
  set_template("catalogState", Template.new(:file => 'CatalogState.erb'))
  set_template('catalogs', Template.new(:file => 'Catalogs.erb'))
  set_template('catalogs.svc', Template.new(:file => 'Catalogs.svc.erb'))
  set_template('icatalogs', Template.new(:file => 'ICatalogs.erb'))


end

Instance Method Details

#configure_attributesObject

Configura los atributos personalizados de la caracteristica (antes de establecer el generador)



77
78
79
80
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 77

def configure_attributes()
  self.generation_attributes[:out_dir]  = "#{self.generation_attributes[:out_dir]}/#{self.generation_attributes[:namespace]}/Services" unless self.generation_attributes.has_in_self?(:out_dir)
  self.generation_attributes[:namespace]= "#{self.generation_attributes[:namespace]}.Services" unless self.generation_attributes.has_in_self?(:namespace)
end

#configure_template_targetsObject

Configura los objetivos de las platillas (despues de establecer el generador)



59
60
61
62
63
64
65
66
67
68
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 59

def configure_template_targets

  # Configuro los templates
  set_template_target('catalogState', TemplateTarget.new(:out_file => "CatalogState.cs", :types => :proyect_file))
  set_template_target('catalogs', TemplateTarget.new(:out_file => "Catalogs.svc.cs", :types => :proyect_file, :class_name => 'Catalogs'))
  set_template_target('catalogs.svc', TemplateTarget.new(:out_file => "Catalogs.svc", :types => :proyect_file, :class_name => 'Catalogs'))
  set_template_target('icatalogs', TemplateTarget.new(:out_file => "ICatalogs.cs", :types => :proyect_file, :class_name => 'ICatalogs'))


end

#generateObject

Genera la caracteristica



121
122
123
124
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 121

def generate
  super()
  generate_configuration
end

#generate_configurationObject

Genera las configuraciones necesarias dentro del archivo web.config



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 127

def generate_configuration

  web_config_file= get_app_config_file

  return unless web_config_file

  # Ruta para conseguir el archivo app.config

  xml                          = Nokogiri::XML(File.read(web_config_file))

  # Recupero el nodo
  xpath                        = "system.serviceModel/services/service[@name= '#{self.generation_attributes[:namespace]}.Catalogs']"
  node                         = XMLHelper.get_node_from_xml_document(xml, xpath)

  # Configuro el nodo
  node['name']                 = "#{self.generation_attributes[:namespace]}.Catalogs"

  # Recupero el nodo
  xpath                        = "#{xpath}/endpoint"
  node                         = XMLHelper.get_node_from_xml_document(xml, xpath)

  #Configuro el nodo
  node['binding']              = "webHttpBinding"
  node['contract']             = "#{self.generation_attributes[:namespace]}.ICatalogs"
  node['behaviorConfiguration']= "web"


  # Recupero el nodo
  xpath                        = "system.serviceModel/behaviors/endpointBehaviors/behavior[@name= 'web']"
  path                         = "system.serviceModel/behaviors/endpointBehaviors/behavior"
  node                         = XMLHelper.get_node_from_xml_document(xml, xpath)

  # Configuro el nodo
  node['name']                 = "web"

  xpath        = "system.serviceModel/behaviors/endpointBehaviors/behavior/webHttp"
  path         = "system.serviceModel/behaviors/endpointBehaviors/behavior/webHttp"
  node         = XMLHelper.get_node_from_xml_document(xml, xpath)

  # Formateo el texto
  formatted_xml= XMLHelper.format(xml.to_xml)

  # Guardo el resultado
  File.write(web_config_file, formatted_xml)

end

#get_entity_by_catalog_name(catalog_name) ⇒ Object

Devuelve una entidad en base al nombre de su catalogo



110
111
112
113
114
115
116
117
118
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 110

def get_entity_by_catalog_name(catalog_name)
  # Busco  las caracteristicas que contiene entidades de SQL para una table
  get_tables do |e|
    if catalog_name==get_entity_catalog_name(e.name)
      return e
    end
  end
  return nil
end

#get_entity_catalog_full_name(entity_name) ⇒ Object

Obtiene el nombre completo de un catalogo asociado a una entidad



88
89
90
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 88

def get_entity_catalog_full_name (entity_name)
  return "#{self.generation_attributes[:namespace]}.#{get_entity_catalog_name(entity_name)}"
end

#get_entity_catalog_name(entity_name) ⇒ Object

Obtiene el nombre de un catalogo asociado a una entidad



83
84
85
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 83

def get_entity_catalog_name(entity_name)
  return "#{entity_name}Catalog"
end

#get_entity_catalogs_full_nameObject

Obtiene el nombre completo de todos los catalogos asociados a una entidad



94
95
96
97
98
99
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 94

def get_entity_catalogs_full_name
  # Busco  las caracteristicas que contiene entidades de SQL para una table
  get_tables do |e|
    yield get_entity_catalog_full_name e.name
  end
end

#get_entity_catalogs_nameObject

Obtiene el nombre de todos los catalogos asociados a una entidad



102
103
104
105
106
107
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 102

def get_entity_catalogs_name
  # Busco  las caracteristicas que contiene entidades de SQL para una table
  get_tables do |e|
    yield get_entity_catalog_name e.name
  end
end

#reset_attributesObject

Resetea los atributos personalizados de la caracteristica (antes de establecer el generador)



71
72
73
74
# File 'lib/CapicuaGenGaspar/WCFService/CSRESTFulCatalog/Source/cs_rest_ful_catalog_feature.rb', line 71

def reset_attributes
  self.generation_attributes[:out_dir]  = nil
  self.generation_attributes[:namespace]= nil
end