Skip to content

Instantly share code, notes, and snippets.

@emailrhoads
Last active October 12, 2020 18:27
Show Gist options
  • Select an option

  • Save emailrhoads/679e0cc5b1ab1246f3a2dc13b2e2e7e9 to your computer and use it in GitHub Desktop.

Select an option

Save emailrhoads/679e0cc5b1ab1246f3a2dc13b2e2e7e9 to your computer and use it in GitHub Desktop.
[Stub LQA Calls] #pegasus
# To read a bunch of inputs
loans = File.read("lqa_AM.txt");
larray = loans.split("\r\n");
# To read a single input
larray = [File.read("breaking_uldd.xml").squish]
# desired output format ///
[{:OriginalXML=>
"<MESSAGE xmlns=\"http://www.mismo.org/residential/2009/schemas\" MISMOReferenceModelIdentifier=\"3.0.0.263.12\"><ABOUT_VERSIONS><ABOUT_VERSION><AboutVersionIdentifier>FRE 4.0.0</AboutVersionIdentifier><CreatedDa ... "}]
# end output format
formatted_res = larray.map{ |e| { :OriginalXML => e }};
# Create the methods you'll need
def self.create_deal_only_xml(uld_xml_hash)
deals_only = uld_xml_hash.map do |r|
xml = Nokogiri::XML(r[:OriginalXML])
xml.css('//DEAL').to_xml
end
deals_only.join("\n")
end
def self.correct_namespace_on_other(query_response)
query_response.map do |response_uldd|
noko_fragment = Nokogiri::XML.parse(response_uldd[:OriginalXML])
mismo_ns = 'http://www.mismo.org/residential/2009/schemas'
nodes = noko_fragment.xpath("//ns:OTHER", 'ns' => mismo_ns)
recursively_set_namespace_prefix(nodes, "ULDD")
{ OriginalXML: noko_fragment.to_xml.squish }
end
end
def self.recursively_set_namespace_prefix(nodeset, namespace)
nodeset.each do |node|
node.name = "#{namespace}:#{node.name}"
recursively_set_namespace_prefix(node.children, namespace) if
node.children.any?
end
end
# Package it up
query_response = formatted_res;
namespaced_others = correct_namespace_on_other(query_response);
deal_only_xml = create_deal_only_xml(namespaced_others);
to_submit = {
deal_only_xml: deal_only_xml,
query_response: query_response
};
submission = Pegasus::FreddieLqa::SubmissionFile.build(
to_submit[:deal_only_xml]
);
# Ship it off
response = Pegasus::FreddieLqa::Submitter.send(submission)
resp_file = Pegasus::FreddieLqa::Downloader.get(response)
# Record the response if you want it.
File.write("resp_file.txt", resp_file);
# Record to the Data Mart
status,
errors_in_file = Pegasus::FreddieLqa::ResponseFileRecorder.
recorded_without_file_errors?(resp_file)
# Get the response XML
response_file = resp_file
unpacked = Freddie::Lqa::Client.unpack_response_file(response_file)
unpacked_response_file = unpacked
client = Pegasus::SqlServer.get_connection('IMDB_')
escaped = client.escape(unpacked_response_file)
File.write('issue.xml', escaped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment