From 1f3009e072a03351de376d382a7e5ee67e130d58 Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Wed, 9 Dec 2015 14:24:39 +0000 Subject: [PATCH] import_sisp task almost done --- import_sisp | 95 ----------------------------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 95 deletions(-) delete mode 100755 import_sisp create mode 100755 src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake diff --git a/import_sisp b/import_sisp deleted file mode 100755 index 8456b27..0000000 --- a/import_sisp +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env ruby -# encoding: UTF-8 - -require_relative '../config/environment' -include Noosfero::SampleDataHelper - -$imported_data = YAML.load_file('script/sisp-catalogo.yml') - -def create_community name - community = Community.new - community.name = name - community.identifier = "sisp-#{name.to_slug}" - community -end - -def create_software_info name, finality = "blank", acronym = "" - community = create_community(name) - software_info = SoftwareInfo.new - software_info.community = community - software_info.finality = finality - software_info.acronym = acronym - software_info.public_software = true - - software_info -end - -def set_software_category software, category_name - category = Category.find_by_name(category_name) - category ||= Category.create(:name => category_name, :parent => $software_category, :environment => $env) - software.community.categories << category -end - -def set_sisp_hashes software, sisp_hash - software.sisp_type = sisp_hash['3 - Identificação do software']['Tipo de Software'] - software.agency_identification = sisp_hash['1 - Identificação do órgão'] - software.softawre_requirements = sisp_hash['10 - Requisitos de software'] - software.hardware_requirements = sisp_hash['11 - Requisitos de Hardware'] - software.documentation = sisp_hash['12 - Documentação'] - software.system_applications = sisp_hash['13 - Aplicações do sistema'] - software.active_versions = sisp_hash['15 - Versões em uso'] - software.estimated_cost = sisp_hash['16 - Custo Estimado'] - software.responsible = sisp_hash['2 - Identificação do responsável no órgão para contato posterior'] - software.responsible_for_acquirement = sisp_hash['4 - Responsáveis pelo Desenvolvimento/Aquisição'] - software.system_info = sisp_hash['5 - Sistema'] - software.development_info = sisp_hash['6 - Características do Desenvolvimento'] - software.maintenance = sisp_hash['7 - Manutenção do Sistema'] - software.standards_adherence = sisp_hash['8 - Aderência a padrões'] - software.plataform = sisp_hash['9 - Ambiente / Plataforma'] -end - -def create_software_attrs sisp_hash - name = sisp_hash['3 - Identificação do software']['Nome'] - identifier = "sisp-#{name.to_slug}" - software = Community.find_by_identifier(identifier) - software = software.software_info if software - software ||= create_software_info(name) - - set_software_category software, sisp_hash['3 - Identificação do software']['Subtipo'] - software.features = sisp_hash['5 - Sistema']['Principais funcionalidades'] - software.finality = sisp_hash['5 - Sistema']['Objetivos do sistema'] - software.objectives = sisp_hash['5 - Sistema']['Objetivos do sistema'] - software.acronym = sisp_hash['3 - Identificação do software']['Sigla'].split[0] - software -end - -$env = Environment.default - -$software_category = Category.find_by_name("Software") -$software_category ||= Category.create(:name => "Software", :environment => $env) - -print 'Creating SISP Softwares: ' -$imported_data.keys.each do |key| - - sisp = $imported_data[key]['software_info'] - - sw = create_software_attrs sisp - - sw.sisp_url = $imported_data[key]['url'] - sw.sisp = true - sw.sisp_id = key.to_i - - set_sisp_hashes sw, sisp - - if sw.valid? && sw.community.valid? - sw.community.save - sw.save - print '.' - else - p sw.errors.full_messages - print 'F' - end -end - -puts "\n Done" - diff --git a/src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake b/src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake new file mode 100755 index 0000000..67dd2ff --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake @@ -0,0 +1,178 @@ +# encoding: UTF-8 + +namespace :software do + desc "Import sisp software from yml" + task :import_sisp_from_yml => :environment do + $imported_data = YAML.load_file('script/sisp-catalogo.yml') + $env = Environment.default + + $software_category = Category.find_by_name("Software") + $software_category ||= Category.create(:name => "Software", :environment => $env) + $sisp_user = create_sisp_user + + $created_software={} + + print 'Creating SISP Softwares: ' + $imported_data.keys.each do |key| + + sisp = $imported_data[key]['software_info'] + + sw = create_software_and_attrs sisp + + sw.sisp_url = $imported_data[key]['url'] + sw.sisp = true + sw.sisp_id = key.to_i + + set_sisp_hashes sw, sisp + + if sw.valid? && sw.community.valid? + sw.community.save + sw.save + print '.' + else + puts sw.errors.full_messages + print 'F' + end + end + + puts "\n Done" + end +end + +def create_community name + community = Community.new + community.name = name + identifier = create_identifier name + + $created_software[identifier]= $created_software[identifier].nil? ? 0 : $created_software[identifier]+1 + identifier = (identifier + "-copy#{$created_software[identifier]}") if ($created_software[identifier] != 0) + + #TODO remove + p "created new: #{identifier}" + + community.identifier = identifier + community +end + +def create_software_info name, finality = "blank", acronym = "" + community = create_community(name) + software_info = SoftwareInfo.new + software_info.community = community + software_info.finality = finality + software_info.acronym = acronym + software_info.public_software = true + + software_info +end + +def set_software_category software, category_name + category = Category.find_by_name(category_name) + category ||= Category.create(:name => category_name, :parent => $software_category, :environment => $env) + software.community.categories << category +end + +def set_sisp_hashes software, sisp_hash + software.sisp_type = sisp_hash['3 - Identificação do software']['Tipo de Software'] + software.agency_identification = sisp_hash['1 - Identificação do órgão'] + software.softawre_requirements = sisp_hash['10 - Requisitos de software'] + software.hardware_requirements = sisp_hash['11 - Requisitos de Hardware'] + software.documentation = sisp_hash['12 - Documentação'] + software.system_applications = sisp_hash['13 - Aplicações do sistema'] + software.active_versions = sisp_hash['15 - Versões em uso'] + software.estimated_cost = sisp_hash['16 - Custo Estimado'] + software.responsible = sisp_hash['2 - Identificação do responsável no órgão para contato posterior'] + software.responsible_for_acquirement = sisp_hash['4 - Responsáveis pelo Desenvolvimento/Aquisição'] + software.system_info = sisp_hash['5 - Sistema'] + software.development_info = sisp_hash['6 - Características do Desenvolvimento'] + software.maintenance = sisp_hash['7 - Manutenção do Sistema'] + software.standards_adherence = sisp_hash['8 - Aderência a padrões'] + software.plataform = sisp_hash['9 - Ambiente / Plataforma'] +end + +def create_identifier name + "#{name.to_slug}".truncate(150, :omission => '', :separator => '-') +end + +def create_sisp_user #TODO change user info + user = User.find_by_login('sisp') + user ||= User.new(:login => 'sisp', :email => 'sisp_user@changeme.com', :password => 'sisp1234', :password_confirmation => 'sisp1234', :environment => $env) + user.activate if !user.activated? + user +end + +def create_institution sisp_hash + + #TODO create_institution if doesnt exist + + name = sisp_hash['1 - Identificação do órgão']['Nome da Empresa/Órgão'] + institution_community = Community::new + institution_community.name = name + institution_community.country = "Brasil" + institution_community.state = "Unknown" #TODO see what to put here + institution_community.city = "Unknown" #TODO see what to put here + institution_community.save + + institution = PublicInstitution.new + institution.community = institution_community + institution.name = name + institution.juridical_nature = sisp_hash['1 - Identificação do órgão']['Natureza'] + institution.acronym = sisp_hash['1 - Identificação do órgão']['Sigla'] #TODO empty if bigger than 10 + institution.governmental_power = sisp_hash['1 - Identificação do órgão']['Abrangência'] + institution.governmental_sphere = sisp_hash['1 - Identificação do órgão']['Esfera'] + institution.cnpj = "Unknown" #TODO see what to put here + institution.corporate_name = name #TODO see what to put here + institution.save + institution + +end + +def create_ratings community_identifier, sisp_hash + software_community = Community.find_by_identifier(community_identifier) + + comment_system = Comment.create!(:body=>"Informações de custo de sistema importadas automaticamente do catálogo SISP.", :target => software_community, :author=> $sisp_user) + comment_maintenance = Comment.create!(:body=>"Informações de custo de manutenção importadas automaticamente do catálogo SISP.", :target => software_community, :author=> $sisp_user) + + institution = create_institution(sisp_hash) + + system_rating = OrganizationRating.create!( + :comment => comment_system, + :value => 3, + :person => $sisp_user.person, + :organization => software_community, + :institution => institution, + :saved_value => sisp_hash['16 - Custo Estimado']['Custo do sistema'], + :people_benefited => 0 +) + + maintenance_rating = OrganizationRating.create!( + :comment => comment_maintenance, + :value => 3, + :person => $sisp_user.person, + :organization => software_community, + :institution => institution, + :saved_value => sisp_hash['16 - Custo Estimado']['Custo de Manutenção'], + :people_benefited => 0 + ) + +end + +def create_software_and_attrs sisp_hash + name = sisp_hash['3 - Identificação do software']['Nome'].truncate(240, :omission => '', :separator => ' ') + identifier = create_identifier name + + #software = Community.find_by_identifier(identifier) + #software = software.software_info if software + #software ||= create_software_info(name) + software = create_software_info(name) + + create_ratings identifier, sisp_hash + + set_software_category software, sisp_hash['3 - Identificação do software']['Subtipo'] + software.features = sisp_hash['5 - Sistema']['Principais funcionalidades'] + software.finality = sisp_hash['5 - Sistema']['Objetivos do sistema'] + software.objectives = sisp_hash['5 - Sistema']['Objetivos do sistema'] + software.acronym = sisp_hash['3 - Identificação do software']['Sigla'].split[0] + software.acronym = "" if (software.acronym.size > 10) + software +end + -- libgit2 0.21.2