diff --git a/src/noosfero-spb/gov_user/lib/public_institution.rb b/src/noosfero-spb/gov_user/lib/public_institution.rb index 33d13eb..b00e0be 100644 --- a/src/noosfero-spb/gov_user/lib/public_institution.rb +++ b/src/noosfero-spb/gov_user/lib/public_institution.rb @@ -2,9 +2,6 @@ class PublicInstitution < Institution validates :governmental_power, :governmental_sphere, :juridical_nature, :presence=>true - validates :acronym, :allow_blank => true, :allow_nil => true, - :uniqueness=>true - validates_format_of( :cnpj, :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, 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 index 0ad8725..c30c093 100755 --- a/src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake +++ b/src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake @@ -15,12 +15,14 @@ namespace :software do end 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 + task :import_sisp => :environment do + + $imported_data = YAML.load_file('script/sisp-catalogo.yml') #TODO change yml folder + $env = Environment.default #TODO change this to correct environment $software_category = Category.find_by_name("Software") $software_category ||= Category.create(:name => "Software", :environment => $env) + $sisp_user = create_sisp_user $created_software={} @@ -30,6 +32,7 @@ namespace :software do sisp = $imported_data[key]['software_info'] + next if sisp['3 - Identificação do software']['Nome'].size <= 2 sw = create_software_and_attrs sisp sw.sisp_url = $imported_data[key]['url'] @@ -39,8 +42,8 @@ namespace :software do set_sisp_hashes sw, sisp if sw.valid? && sw.community.valid? - sw.community.save - sw.save + sw.community.save! + sw.save! print '.' else puts sw.errors.full_messages @@ -49,21 +52,28 @@ namespace :software do end puts "\n Done" + return 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 + + name = name + " copy#{$created_software[identifier]}" if ($created_software[identifier] != 0) identifier = (identifier + "-copy#{$created_software[identifier]}") if ($created_software[identifier] != 0) - #TODO remove - p "created new: #{identifier}" + community = Community.find_or_initialize_by_name(name) community.identifier = identifier + + #p "achei? #{!community.id.nil?}" + #p "nome: #{name}" + #p "iden: #{identifier}" + #p " " + community.save! community end @@ -73,8 +83,7 @@ def create_software_info name, finality = "blank", acronym = "" software_info.community = community software_info.finality = finality software_info.acronym = acronym - software_info.public_software = true - + software_info.save! software_info end @@ -103,38 +112,45 @@ def set_sisp_hashes software, sisp_hash end def create_identifier name - "#{name.to_slug}".truncate(150, :omission => '', :separator => '-') + "#{name.to_slug}".truncate(240, :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.save! 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 + + if name.size <=2 + return nil + end + + institution_community = Community.find_or_initialize_by_identifier(name.to_slug) + + #puts institution_community.inspect + institution = PublicInstitution.find_or_initialize_by_name(name) 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_community.country = "BR" + institution_community.state = "DF" + institution_community.city = "Unknown" + 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.juridical_nature = JuridicalNature.find_or_create_by_name(:name => sisp_hash['1 - Identificação do órgão']['Natureza']) + institution.acronym = sisp_hash['1 - Identificação do órgão']['Sigla'].split[0] + institution.acronym = nil if (institution.acronym.size > 10) + institution.governmental_power = GovernmentalPower.find_or_create_by_name(:name => sisp_hash['1 - Identificação do órgão']['Esfera']) + institution.governmental_sphere = GovernmentalSphere.find_or_create_by_name(:name => sisp_hash['1 - Identificação do órgão']['Abrangência']) + institution.cnpj = nil + institution.corporate_name = name + institution.save! institution end @@ -142,14 +158,21 @@ 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) + if institution.nil? + return nil + end + + comment_system = Comment.new(:body=>"Informações de custo de sistema importadas automaticamente do catálogo SISP.", :author=> $sisp_user.person) + comment_system.source = software_community + comment_system.save! +comment_maintenance = Comment.new(:body=>"Informações de custo de manutenção importadas automaticamente do catálogo SISP.", :author=> $sisp_user.person) + comment_maintenance.source = software_community + comment_maintenance.save! - system_rating = OrganizationRating.create!( + OrganizationRating.create!( :comment => comment_system, - :value => 3, + :value => 1, #TODO see what to put here :person => $sisp_user.person, :organization => software_community, :institution => institution, @@ -157,9 +180,9 @@ def create_ratings community_identifier, sisp_hash :people_benefited => 0 ) - maintenance_rating = OrganizationRating.create!( + OrganizationRating.create!( :comment => comment_maintenance, - :value => 3, + :value => 1, #TODO see what to put here :person => $sisp_user.person, :organization => software_community, :institution => institution, @@ -171,11 +194,9 @@ 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 -- libgit2 0.21.2