-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from t3-innovation-network/staging
Release 07/12/24
- Loading branch information
Showing
106 changed files
with
2,923 additions
and
1,404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.dropdown-container { | ||
z-index: 9999; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
### | ||
# @description: Place all the actions related to mappings | ||
### | ||
module API | ||
module V1 | ||
class MappingExportsController < BaseController | ||
include ConfigurationProfileQueryable | ||
|
||
### | ||
# @description: Returns exported mappings in a given format as binary | ||
### | ||
def index | ||
domains = current_configuration_profile | ||
.domains | ||
.where(id: Array.wrap(params.fetch(:domain_ids, "").split(","))) | ||
|
||
mapping = current_configuration_profile | ||
.mappings | ||
.find_by(id: params[:mapping_id]) | ||
|
||
if domains.empty? && mapping.nil? | ||
render json: { error: "Either domain_ids or mapping_id is required" }, status: :bad_request | ||
return | ||
end | ||
|
||
result = ExportMappings.call( | ||
configuration_profile: current_configuration_profile, | ||
domains:, | ||
format: params[:format], | ||
mapping: | ||
) | ||
|
||
if result.success? | ||
send_data result.data, | ||
filename: result.filename, | ||
type: result.content_type | ||
else | ||
render json: { error: response.error }, status: :unprocessable_entity | ||
end | ||
rescue StandardError => e | ||
Airbrake.notify(e) | ||
render json: { error: e.message }, status: :internal_server_error | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# frozen_string_literal: true | ||
|
||
class ExportMappings | ||
include Interactor | ||
|
||
delegate :configuration_profile, :domains, :format, :mapping, to: :context | ||
|
||
def call | ||
case format | ||
when "csv" then export_csv | ||
when "jsonld" then export_jsonld | ||
when "ttl" then export_turtle | ||
else context.fail!(error: "Unsupported format: `#{format}`") | ||
end | ||
|
||
context.filename = "#{filename}.#{extension}" | ||
end | ||
|
||
def bulk_export? | ||
domains.any? | ||
end | ||
|
||
def filename | ||
@filename ||= | ||
if bulk_export? | ||
domains.map(&:name).map { _1.tr(" ", "+") }.join("_") | ||
else | ||
mapping.export_filename | ||
end | ||
end | ||
|
||
def export_csv | ||
context.content_type = bulk_export? ? "application/zip" : "text/csv" | ||
|
||
context.data = | ||
if bulk_export? | ||
io = StringIO.new | ||
|
||
Zip::OutputStream.write_buffer(io) do |zip| | ||
mappings.each do |mapping| | ||
zip.put_next_entry("#{mapping.export_filename}.csv") | ||
zip.write(Exporters::Mapping.new(mapping).csv) | ||
end | ||
end | ||
|
||
io.rewind | ||
io.string | ||
else | ||
exporter.csv | ||
end | ||
end | ||
|
||
def export_jsonld | ||
context.content_type = "application/ld+json" | ||
context.data = jsonld_data | ||
end | ||
|
||
def export_turtle | ||
context.content_type = "text/turtle" | ||
context.data = turtle_data | ||
end | ||
|
||
def exporter | ||
Exporters::Mapping.new(mapping) | ||
end | ||
|
||
def extension | ||
bulk_export? && format == "csv" ? "zip" : format | ||
end | ||
|
||
def jsonld_data | ||
@jsonld_data ||= if bulk_export? | ||
{ | ||
"@context": Desm::CONTEXT, | ||
"@graph": mappings.map { Exporters::Mapping::JSONLD.new(_1).graph }.flatten.uniq | ||
}.to_json | ||
else | ||
exporter.jsonld.to_json | ||
end | ||
end | ||
|
||
def mappings | ||
@mappings ||= | ||
begin | ||
relation = configuration_profile.mappings.mapped.select(:id) | ||
|
||
if bulk_export? | ||
relation = relation | ||
.joins(:specification) | ||
.where(specifications: { domain_id: domains }) | ||
end | ||
|
||
relation.where!(id: mapping) if mapping.present? | ||
|
||
mappings = Mapping | ||
.where(id: relation) | ||
.includes( | ||
alignments: [ | ||
:predicate, | ||
{ mapped_terms: :property }, | ||
{ spine_term: :property } | ||
], | ||
specification: :domain | ||
) | ||
|
||
if format == "csv" | ||
mappings.includes(:configuration_profile) | ||
else | ||
mappings | ||
end | ||
end | ||
end | ||
|
||
def turtle_data | ||
@turtle_data ||= begin | ||
repository = RDF::Repository.new | ||
|
||
JSON::LD::Reader.new(jsonld_data) do |reader| | ||
reader.each_statement do |statement| | ||
repository << statement | ||
end | ||
end | ||
|
||
RDF::Writer.for(:turtle).buffer do |writer| | ||
repository.each_statement do |statement| | ||
writer << statement | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.