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)
header['Content-Disposition'] = "attachment; filename=\"#{exporter.bcf_filename}\""
env['api.format'] = :binary
exporter.list_from_api.read
exporter.render!.content.read
end
post do

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

Loading…
Cancel
Save