Class | BaselineProcess
In: | app/models/baseline_process.rb
Parent: | Site

Copyright (c) 2006 Logica

### Methods

export_csv find_2scan new_from_upload scan4content unused_folders url validate validate_on_create

### Attributes

file | [RW] | during creation of a new static Site this stores the zip-file that contains the content

### Public Class methods

find_2scan()

Return collection of Baseline Processes that need to scanned

[Source]

        # File app/models/baseline_process.rb, line 46
    46:   def self.find_2scan
    47:     return BaselineProcess.find(:all, :conditions => ['content_scanned_on is null'], :order => "title ASC")
    48:   end

new_from_upload(params = nil)

Method new_upload to process a upload of content for a baseline process

[Source]

        # File app/models/baseline_process.rb, line 23
    23:   def self.new_from_upload(params = nil)
    24:     logger.info("Site.new_upload #{params.inspect}")
    25:     site = BaselineProcess.new(params)
    26:     unless site.file.blank?
    27:       site.errors.add(:file, 'can\'t be blank') if  site.file.original_filename.blank?
    28:       site.errors.add(:file, 'needs to be a zip file') if site.file.original_filename.downcase.reverse[0..3] != 'piz.'
    29:       site.errors.add(:file, 'needs to be named using only characters, numbers, dots and underscores') unless site.file.original_filename =~ /\A[._a-zA-Z0-9]+\z/
    30:       site.folder = site.file.original_filename[0..site.file.original_filename.length-4]
    31:       logger.info("Foldername for Baseline Process will be #{site.folder}")
    32:       site.errors.add(:folder, 'already exists') if  File.exists?(site.path) && !site.folder.blank?
    33:       site.errors.add(:folder, 'is already being used by a Baseline Process') if  !BaselineProcess.find(:first, :conditions => ['folder =?', site.folder]).nil?
    34:       if site.errors.empty?
    35:         logger.debug("Writing upload zip to #{site.path2zip}")
    36:         File.open(site.path2zip, "wb") { |f| f.write(site.file.read) }
    37:         site.unzip_upload
    38:       end
    39:     else
    40:       site.errors.add(:file, 'no zip file was selected for upload')
    41:     end
    42:     return site
    43:   end

unused_folders()

Method unused_folders returns folders with content that have not been used to create a BaselineProcess

[Source]

        # File app/models/baseline_process.rb, line 69
    69:   def self.unused_folders
    70:     sites_path = "#{ENV['EPFWIKI_ROOT_DIR']}#{ENV['EPFWIKI_PUBLIC_FOLDER']}/#{ENV['EPFWIKI_SITES_FOLDER']}"
    71:     File.makedirs(sites_path)
    72:     entries = Dir.entries(sites_path) - ['.', '..', 'compare', '.svn']
    73:     folders = []
    74:     entries.each do |entry|
    75:       if File.ftype(File.expand_path(entry, sites_path)) == 'directory'
    76:         folders << entry
    77:       end
    78:     end
    79:     used_folders = BaselineProcess.find(:all, :conditions => ['obsolete_on is null']).collect {|bp| bp.folder}
    80:     return folders - used_folders
    81:   end

### Public Instance methods

export_csv()

[Source]

         # File app/models/baseline_process.rb, line 92
     92:   def export_csv
     93:     path_csv = "#{self.path}.csv"
     94:     logger.info("Exporting #{self.title} to csv #{path_csv}")
     95:     self.scan4content if !self.content_scanned_on
     96:     csv_file = File.new(path_csv, 'w')
     97:     csv_file.puts("\"" + ['Plugin', 'UMA Type', 'Element Type', 'Presentation Name', 'Name', 'Relative path', 'URL'].join("\";\"") + "\"")
     98:     self.pages.each do |page|
     99:       plugin_name = page.rel_path.split('/')[0]
    100:       type = page.uma_type
    101:       name = page.uma_name
    102:       url = "http://#{ENV['EPFWIKI_HOST']}/#{self.rel_path}/#{page.rel_path}"
    103:       csv_file.puts("\"" + [plugin_name, type, page.uma_type, page.presentation_name, name, page.rel_path, url].join("\";\"") + "\"")
    104:     end
    105:     csv_file.close
    106:   end

scan4content()

Method scan4content scans the site folder for pages that can be wikified

[Source]

        # File app/models/baseline_process.rb, line 51
    51:   def scan4content
    52:     logger.info("Scanning content in site #{self.title}")
    53:     self.pages = []
    54:     if self.content_scanned_on.nil?
    55:       files = self.files_wikifiable
    56:       self.wikifiable_files_count = files.size # TODO obsolete?
    57:       files.each do |f|
    58:         page = BaselineProcessPage.new(:rel_path => f.gsub(self.path + '/', ''), :site => self, :tool => 'EPFC', :status => 'N.A.')
    59:         self.pages << page
    60:       end
    61:       self.content_scanned_on = Time.now
    62:       self.save!
    63:     else
    64:       logger.info("Content has already been scanned!")
    65:     end
    66:   end

url(absolute = false, request_host = ENV['EPFWIKI_HOST'])

[Source]

        # File app/models/baseline_process.rb, line 83
    83:   def url(absolute = false, request_host = ENV['EPFWIKI_HOST'])
    84:     s = "/#{ENV['EPFWIKI_SITES_FOLDER']}/#{self.folder}/"
    85:     s = "http://#{request_host}#{s}" if absolute
    86:     s
    87:   end

validate()

[Source]

         # File app/models/baseline_process.rb, line 108
    108:   def validate
    109:     errors.add(:folder, 'doesn\'t exist') if self.folder.nil? || !File.exists?(self.path)
    110:     errors.add(:folder, "does not seem to contain a valid site, no index.htm or index.html was found") if !File.exists?(self.path + '/index.htm') && !File.exists?(self.path + '/index.html')
    111:   end

validate_on_create()

[Source]

         # File app/models/baseline_process.rb, line 113
    113:   def validate_on_create
    114:     logger.debug('Validate on create')
    115:     errors.add(:folder, 'was already used to create a baseline process') if !self.folder.nil? && BaselineProcess.find_all_by_folder(self.folder).size > 0
    116:   end

[Validate]