Commit 1f3009e072a03351de376d382a7e5ee67e130d58
1 parent
19a6208c
Exists in
sisp_simple_version
import_sisp task almost done
Showing
2 changed files
with
178 additions
and
95 deletions
Show diff stats
import_sisp
| ... | ... | @@ -1,95 +0,0 @@ |
| 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/lib/tasks/import_sisp_software.rake
0 → 100755
| ... | ... | @@ -0,0 +1,178 @@ |
| 1 | +# encoding: UTF-8 | |
| 2 | + | |
| 3 | +namespace :software do | |
| 4 | + desc "Import sisp software from yml" | |
| 5 | + task :import_sisp_from_yml => :environment do | |
| 6 | + $imported_data = YAML.load_file('script/sisp-catalogo.yml') | |
| 7 | + $env = Environment.default | |
| 8 | + | |
| 9 | + $software_category = Category.find_by_name("Software") | |
| 10 | + $software_category ||= Category.create(:name => "Software", :environment => $env) | |
| 11 | + $sisp_user = create_sisp_user | |
| 12 | + | |
| 13 | + $created_software={} | |
| 14 | + | |
| 15 | + print 'Creating SISP Softwares: ' | |
| 16 | + $imported_data.keys.each do |key| | |
| 17 | + | |
| 18 | + sisp = $imported_data[key]['software_info'] | |
| 19 | + | |
| 20 | + sw = create_software_and_attrs sisp | |
| 21 | + | |
| 22 | + sw.sisp_url = $imported_data[key]['url'] | |
| 23 | + sw.sisp = true | |
| 24 | + sw.sisp_id = key.to_i | |
| 25 | + | |
| 26 | + set_sisp_hashes sw, sisp | |
| 27 | + | |
| 28 | + if sw.valid? && sw.community.valid? | |
| 29 | + sw.community.save | |
| 30 | + sw.save | |
| 31 | + print '.' | |
| 32 | + else | |
| 33 | + puts sw.errors.full_messages | |
| 34 | + print 'F' | |
| 35 | + end | |
| 36 | + end | |
| 37 | + | |
| 38 | + puts "\n Done" | |
| 39 | + end | |
| 40 | +end | |
| 41 | + | |
| 42 | +def create_community name | |
| 43 | + community = Community.new | |
| 44 | + community.name = name | |
| 45 | + identifier = create_identifier name | |
| 46 | + | |
| 47 | + $created_software[identifier]= $created_software[identifier].nil? ? 0 : $created_software[identifier]+1 | |
| 48 | + identifier = (identifier + "-copy#{$created_software[identifier]}") if ($created_software[identifier] != 0) | |
| 49 | + | |
| 50 | + #TODO remove | |
| 51 | + p "created new: #{identifier}" | |
| 52 | + | |
| 53 | + community.identifier = identifier | |
| 54 | + community | |
| 55 | +end | |
| 56 | + | |
| 57 | +def create_software_info name, finality = "blank", acronym = "" | |
| 58 | + community = create_community(name) | |
| 59 | + software_info = SoftwareInfo.new | |
| 60 | + software_info.community = community | |
| 61 | + software_info.finality = finality | |
| 62 | + software_info.acronym = acronym | |
| 63 | + software_info.public_software = true | |
| 64 | + | |
| 65 | + software_info | |
| 66 | +end | |
| 67 | + | |
| 68 | +def set_software_category software, category_name | |
| 69 | + category = Category.find_by_name(category_name) | |
| 70 | + category ||= Category.create(:name => category_name, :parent => $software_category, :environment => $env) | |
| 71 | + software.community.categories << category | |
| 72 | +end | |
| 73 | + | |
| 74 | +def set_sisp_hashes software, sisp_hash | |
| 75 | + software.sisp_type = sisp_hash['3 - Identificação do software']['Tipo de Software'] | |
| 76 | + software.agency_identification = sisp_hash['1 - Identificação do órgão'] | |
| 77 | + software.softawre_requirements = sisp_hash['10 - Requisitos de software'] | |
| 78 | + software.hardware_requirements = sisp_hash['11 - Requisitos de Hardware'] | |
| 79 | + software.documentation = sisp_hash['12 - Documentação'] | |
| 80 | + software.system_applications = sisp_hash['13 - Aplicações do sistema'] | |
| 81 | + software.active_versions = sisp_hash['15 - Versões em uso'] | |
| 82 | + software.estimated_cost = sisp_hash['16 - Custo Estimado'] | |
| 83 | + software.responsible = sisp_hash['2 - Identificação do responsável no órgão para contato posterior'] | |
| 84 | + software.responsible_for_acquirement = sisp_hash['4 - Responsáveis pelo Desenvolvimento/Aquisição'] | |
| 85 | + software.system_info = sisp_hash['5 - Sistema'] | |
| 86 | + software.development_info = sisp_hash['6 - Características do Desenvolvimento'] | |
| 87 | + software.maintenance = sisp_hash['7 - Manutenção do Sistema'] | |
| 88 | + software.standards_adherence = sisp_hash['8 - Aderência a padrões'] | |
| 89 | + software.plataform = sisp_hash['9 - Ambiente / Plataforma'] | |
| 90 | +end | |
| 91 | + | |
| 92 | +def create_identifier name | |
| 93 | + "#{name.to_slug}".truncate(150, :omission => '', :separator => '-') | |
| 94 | +end | |
| 95 | + | |
| 96 | +def create_sisp_user #TODO change user info | |
| 97 | + user = User.find_by_login('sisp') | |
| 98 | + user ||= User.new(:login => 'sisp', :email => 'sisp_user@changeme.com', :password => 'sisp1234', :password_confirmation => 'sisp1234', :environment => $env) | |
| 99 | + user.activate if !user.activated? | |
| 100 | + user | |
| 101 | +end | |
| 102 | + | |
| 103 | +def create_institution sisp_hash | |
| 104 | + | |
| 105 | + #TODO create_institution if doesnt exist | |
| 106 | + | |
| 107 | + name = sisp_hash['1 - Identificação do órgão']['Nome da Empresa/Órgão'] | |
| 108 | + institution_community = Community::new | |
| 109 | + institution_community.name = name | |
| 110 | + institution_community.country = "Brasil" | |
| 111 | + institution_community.state = "Unknown" #TODO see what to put here | |
| 112 | + institution_community.city = "Unknown" #TODO see what to put here | |
| 113 | + institution_community.save | |
| 114 | + | |
| 115 | + institution = PublicInstitution.new | |
| 116 | + institution.community = institution_community | |
| 117 | + institution.name = name | |
| 118 | + institution.juridical_nature = sisp_hash['1 - Identificação do órgão']['Natureza'] | |
| 119 | + institution.acronym = sisp_hash['1 - Identificação do órgão']['Sigla'] #TODO empty if bigger than 10 | |
| 120 | + institution.governmental_power = sisp_hash['1 - Identificação do órgão']['Abrangência'] | |
| 121 | + institution.governmental_sphere = sisp_hash['1 - Identificação do órgão']['Esfera'] | |
| 122 | + institution.cnpj = "Unknown" #TODO see what to put here | |
| 123 | + institution.corporate_name = name #TODO see what to put here | |
| 124 | + institution.save | |
| 125 | + institution | |
| 126 | + | |
| 127 | +end | |
| 128 | + | |
| 129 | +def create_ratings community_identifier, sisp_hash | |
| 130 | + software_community = Community.find_by_identifier(community_identifier) | |
| 131 | + | |
| 132 | + comment_system = Comment.create!(:body=>"Informações de custo de sistema importadas automaticamente do catálogo SISP.", :target => software_community, :author=> $sisp_user) | |
| 133 | + comment_maintenance = Comment.create!(:body=>"Informações de custo de manutenção importadas automaticamente do catálogo SISP.", :target => software_community, :author=> $sisp_user) | |
| 134 | + | |
| 135 | + institution = create_institution(sisp_hash) | |
| 136 | + | |
| 137 | + system_rating = OrganizationRating.create!( | |
| 138 | + :comment => comment_system, | |
| 139 | + :value => 3, | |
| 140 | + :person => $sisp_user.person, | |
| 141 | + :organization => software_community, | |
| 142 | + :institution => institution, | |
| 143 | + :saved_value => sisp_hash['16 - Custo Estimado']['Custo do sistema'], | |
| 144 | + :people_benefited => 0 | |
| 145 | +) | |
| 146 | + | |
| 147 | + maintenance_rating = OrganizationRating.create!( | |
| 148 | + :comment => comment_maintenance, | |
| 149 | + :value => 3, | |
| 150 | + :person => $sisp_user.person, | |
| 151 | + :organization => software_community, | |
| 152 | + :institution => institution, | |
| 153 | + :saved_value => sisp_hash['16 - Custo Estimado']['Custo de Manutenção'], | |
| 154 | + :people_benefited => 0 | |
| 155 | + ) | |
| 156 | + | |
| 157 | +end | |
| 158 | + | |
| 159 | +def create_software_and_attrs sisp_hash | |
| 160 | + name = sisp_hash['3 - Identificação do software']['Nome'].truncate(240, :omission => '', :separator => ' ') | |
| 161 | + identifier = create_identifier name | |
| 162 | + | |
| 163 | + #software = Community.find_by_identifier(identifier) | |
| 164 | + #software = software.software_info if software | |
| 165 | + #software ||= create_software_info(name) | |
| 166 | + software = create_software_info(name) | |
| 167 | + | |
| 168 | + create_ratings identifier, sisp_hash | |
| 169 | + | |
| 170 | + set_software_category software, sisp_hash['3 - Identificação do software']['Subtipo'] | |
| 171 | + software.features = sisp_hash['5 - Sistema']['Principais funcionalidades'] | |
| 172 | + software.finality = sisp_hash['5 - Sistema']['Objetivos do sistema'] | |
| 173 | + software.objectives = sisp_hash['5 - Sistema']['Objetivos do sistema'] | |
| 174 | + software.acronym = sisp_hash['3 - Identificação do software']['Sigla'].split[0] | |
| 175 | + software.acronym = "" if (software.acronym.size > 10) | |
| 176 | + software | |
| 177 | +end | |
| 178 | + | ... | ... |