Fix BCF exporter

pull/9782/head
Oliver Günther 3 years ago
parent 83bd71d085
commit c73d4e4f69
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 2
      modules/bim/lib/api/bim/bcf_xml/v1/bcf_xml_api.rb
  2. 24
      modules/bim/lib/open_project/bim/bcf_xml/exporter.rb

@ -73,7 +73,7 @@ module API
exporter = ::OpenProject::Bim::BcfXml::Exporter.new(updated_query.result) exporter = ::OpenProject::Bim::BcfXml::Exporter.new(updated_query.result)
header['Content-Disposition'] = "attachment; filename=\"#{exporter.bcf_filename}\"" header['Content-Disposition'] = "attachment; filename=\"#{exporter.bcf_filename}\""
env['api.format'] = :binary env['api.format'] = :binary
exporter.list_from_api.read exporter.render!.content.read
end end
post do post do

@ -12,23 +12,16 @@ module OpenProject::Bim::BcfXml
User.current User.current
end end
def list def self.key
Dir.mktmpdir do |dir| :bcf
files = create_bcf! dir
zip = zip_folder dir, files
yield success(zip)
end
rescue StandardError => e
Rails.logger.error "Failed to export work package list #{e} #{e.message}"
raise e
end end
def list_from_api def render!
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
files = create_bcf! dir files = create_bcf! dir
zip_folder dir, files zip = zip_folder dir, files
success(zip)
end end
rescue StandardError => e rescue StandardError => e
Rails.logger.error "Failed to export work package list #{e} #{e.message}" Rails.logger.error "Failed to export work package list #{e} #{e.message}"
@ -36,7 +29,7 @@ module OpenProject::Bim::BcfXml
end end
def success(zip) def success(zip)
WorkPackage::Exporter::Result::Success Exports::Result
.new format: :xls, .new format: :xls,
content: zip, content: zip,
title: bcf_filename, title: bcf_filename,
@ -59,10 +52,11 @@ module OpenProject::Bim::BcfXml
def zip_folder(dir, files) def zip_folder(dir, files)
zip_file = File.join(dir, bcf_filename) zip_file = File.join(dir, bcf_filename)
Zip::File.open(zip_file, Zip::File::CREATE) do |zip| Zip::OutputStream.open(zip_file.path) do |zos|
files.each do |file| files.each do |file|
name = file.sub("#{dir}/", "") name = file.sub("#{dir}/", "")
zip.add name, file zos.put_next_entry(name)
zos.print File.read(file)
end end
end end

Loading…
Cancel
Save