Commit 19a6208cff22262e9a8d770e08629b1f429ebb73
1 parent
525bb1ef
Exists in
sisp_simple_version
update migrations and create import_sisp script
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Luciano Prestes <lucanopcbr@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
3 changed files
with
117 additions
and
16 deletions
Show diff stats
| @@ -0,0 +1,95 @@ | @@ -0,0 +1,95 @@ | ||
| 1 | +#!/usr/bin/env ruby | ||
| 2 | +# encoding: UTF-8 | ||
| 3 | + | ||
| 4 | +require_relative '../config/environment' | ||
| 5 | +include Noosfero::SampleDataHelper | ||
| 6 | + | ||
| 7 | +$imported_data = YAML.load_file('script/sisp-catalogo.yml') | ||
| 8 | + | ||
| 9 | +def create_community name | ||
| 10 | + community = Community.new | ||
| 11 | + community.name = name | ||
| 12 | + community.identifier = "sisp-#{name.to_slug}" | ||
| 13 | + community | ||
| 14 | +end | ||
| 15 | + | ||
| 16 | +def create_software_info name, finality = "blank", acronym = "" | ||
| 17 | + community = create_community(name) | ||
| 18 | + software_info = SoftwareInfo.new | ||
| 19 | + software_info.community = community | ||
| 20 | + software_info.finality = finality | ||
| 21 | + software_info.acronym = acronym | ||
| 22 | + software_info.public_software = true | ||
| 23 | + | ||
| 24 | + software_info | ||
| 25 | +end | ||
| 26 | + | ||
| 27 | +def set_software_category software, category_name | ||
| 28 | + category = Category.find_by_name(category_name) | ||
| 29 | + category ||= Category.create(:name => category_name, :parent => $software_category, :environment => $env) | ||
| 30 | + software.community.categories << category | ||
| 31 | +end | ||
| 32 | + | ||
| 33 | +def set_sisp_hashes software, sisp_hash | ||
| 34 | + software.sisp_type = sisp_hash['3 - Identificação do software']['Tipo de Software'] | ||
| 35 | + software.agency_identification = sisp_hash['1 - Identificação do órgão'] | ||
| 36 | + software.softawre_requirements = sisp_hash['10 - Requisitos de software'] | ||
| 37 | + software.hardware_requirements = sisp_hash['11 - Requisitos de Hardware'] | ||
| 38 | + software.documentation = sisp_hash['12 - Documentação'] | ||
| 39 | + software.system_applications = sisp_hash['13 - Aplicações do sistema'] | ||
| 40 | + software.active_versions = sisp_hash['15 - Versões em uso'] | ||
| 41 | + software.estimated_cost = sisp_hash['16 - Custo Estimado'] | ||
| 42 | + software.responsible = sisp_hash['2 - Identificação do responsável no órgão para contato posterior'] | ||
| 43 | + software.responsible_for_acquirement = sisp_hash['4 - Responsáveis pelo Desenvolvimento/Aquisição'] | ||
| 44 | + software.system_info = sisp_hash['5 - Sistema'] | ||
| 45 | + software.development_info = sisp_hash['6 - Características do Desenvolvimento'] | ||
| 46 | + software.maintenance = sisp_hash['7 - Manutenção do Sistema'] | ||
| 47 | + software.standards_adherence = sisp_hash['8 - Aderência a padrões'] | ||
| 48 | + software.plataform = sisp_hash['9 - Ambiente / Plataforma'] | ||
| 49 | +end | ||
| 50 | + | ||
| 51 | +def create_software_attrs sisp_hash | ||
| 52 | + name = sisp_hash['3 - Identificação do software']['Nome'] | ||
| 53 | + identifier = "sisp-#{name.to_slug}" | ||
| 54 | + software = Community.find_by_identifier(identifier) | ||
| 55 | + software = software.software_info if software | ||
| 56 | + software ||= create_software_info(name) | ||
| 57 | + | ||
| 58 | + set_software_category software, sisp_hash['3 - Identificação do software']['Subtipo'] | ||
| 59 | + software.features = sisp_hash['5 - Sistema']['Principais funcionalidades'] | ||
| 60 | + software.finality = sisp_hash['5 - Sistema']['Objetivos do sistema'] | ||
| 61 | + software.objectives = sisp_hash['5 - Sistema']['Objetivos do sistema'] | ||
| 62 | + software.acronym = sisp_hash['3 - Identificação do software']['Sigla'].split[0] | ||
| 63 | + software | ||
| 64 | +end | ||
| 65 | + | ||
| 66 | +$env = Environment.default | ||
| 67 | + | ||
| 68 | +$software_category = Category.find_by_name("Software") | ||
| 69 | +$software_category ||= Category.create(:name => "Software", :environment => $env) | ||
| 70 | + | ||
| 71 | +print 'Creating SISP Softwares: ' | ||
| 72 | +$imported_data.keys.each do |key| | ||
| 73 | + | ||
| 74 | + sisp = $imported_data[key]['software_info'] | ||
| 75 | + | ||
| 76 | + sw = create_software_attrs sisp | ||
| 77 | + | ||
| 78 | + sw.sisp_url = $imported_data[key]['url'] | ||
| 79 | + sw.sisp = true | ||
| 80 | + sw.sisp_id = key.to_i | ||
| 81 | + | ||
| 82 | + set_sisp_hashes sw, sisp | ||
| 83 | + | ||
| 84 | + if sw.valid? && sw.community.valid? | ||
| 85 | + sw.community.save | ||
| 86 | + sw.save | ||
| 87 | + print '.' | ||
| 88 | + else | ||
| 89 | + p sw.errors.full_messages | ||
| 90 | + print 'F' | ||
| 91 | + end | ||
| 92 | +end | ||
| 93 | + | ||
| 94 | +puts "\n Done" | ||
| 95 | + |
src/noosfero-spb/software_communities/db/migrate/20151125175514_change_software_info_structure.rb
| 1 | class ChangeSoftwareInfoStructure < ActiveRecord::Migration | 1 | class ChangeSoftwareInfoStructure < ActiveRecord::Migration |
| 2 | def up | 2 | def up |
| 3 | change_table :software_infos do |t| | 3 | change_table :software_infos do |t| |
| 4 | + t.text :sisp_url | ||
| 4 | t.text :agency_identification | 5 | t.text :agency_identification |
| 5 | t.text :softawre_requirements | 6 | t.text :softawre_requirements |
| 6 | t.text :hardware_requirements | 7 | t.text :hardware_requirements |
| @@ -16,24 +17,29 @@ class ChangeSoftwareInfoStructure < ActiveRecord::Migration | @@ -16,24 +17,29 @@ class ChangeSoftwareInfoStructure < ActiveRecord::Migration | ||
| 16 | t.text :standards_adherence | 17 | t.text :standards_adherence |
| 17 | t.text :plataform | 18 | t.text :plataform |
| 18 | t.text :sisp_type | 19 | t.text :sisp_type |
| 20 | + t.integer :sisp_id | ||
| 19 | end | 21 | end |
| 22 | + | ||
| 23 | + change_column :software_infos, :finality, :text | ||
| 20 | end | 24 | end |
| 21 | 25 | ||
| 22 | def down | 26 | def down |
| 23 | - remove_column :agency_identification | ||
| 24 | - remove_column :softawre_requirements | ||
| 25 | - remove_column :hardware_requirements | ||
| 26 | - remove_column :documentation | ||
| 27 | - remove_column :system_applications | ||
| 28 | - remove_column :active_versions | ||
| 29 | - remove_column :estimated_cost | ||
| 30 | - remove_column :responsible | ||
| 31 | - remove_column :responsible_for_acquirement | ||
| 32 | - remove_column :system_info | ||
| 33 | - remove_column :development_info | ||
| 34 | - remove_column :maintenance | ||
| 35 | - remove_column :standards_adherence | ||
| 36 | - remove_column :plataform | ||
| 37 | - remove_column :sisp_type | 27 | + remove_column :software_infos, :agency_identification |
| 28 | + remove_column :software_infos, :softawre_requirements | ||
| 29 | + remove_column :software_infos, :hardware_requirements | ||
| 30 | + remove_column :software_infos, :documentation | ||
| 31 | + remove_column :software_infos, :system_applications | ||
| 32 | + remove_column :software_infos, :active_versions | ||
| 33 | + remove_column :software_infos, :estimated_cost | ||
| 34 | + remove_column :software_infos, :responsible | ||
| 35 | + remove_column :software_infos, :responsible_for_acquirement | ||
| 36 | + remove_column :software_infos, :system_info | ||
| 37 | + remove_column :software_infos, :development_info | ||
| 38 | + remove_column :software_infos, :maintenance | ||
| 39 | + remove_column :software_infos, :standards_adherence | ||
| 40 | + remove_column :software_infos, :plataform | ||
| 41 | + remove_column :software_infos, :sisp_type | ||
| 42 | + remove_column :software_infos, :sisp_id | ||
| 43 | + remove_column :software_infos, :sisp_url | ||
| 38 | end | 44 | end |
| 39 | end | 45 | end |
src/noosfero-spb/software_communities/lib/software_info.rb
| @@ -81,7 +81,7 @@ class SoftwareInfo < ActiveRecord::Base | @@ -81,7 +81,7 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 81 | 81 | ||
| 82 | has_one :software_categories | 82 | has_one :software_categories |
| 83 | 83 | ||
| 84 | - validates_length_of :finality, :maximum => 120 | 84 | + validates_length_of :finality, :maximum => 4000 |
| 85 | validates_length_of :objectives, :maximum => 4000 | 85 | validates_length_of :objectives, :maximum => 4000 |
| 86 | validates_length_of :features, :maximum => 4000 | 86 | validates_length_of :features, :maximum => 4000 |
| 87 | validates_presence_of :finality, :community | 87 | validates_presence_of :finality, :community |