Skip to content

Commit

Permalink
[api] provide product listing in own xml structure, sort by cpe and e…
Browse files Browse the repository at this point in the history
…xport it as well
  • Loading branch information
adrianschroeter committed Feb 11, 2014
1 parent 9cc0f22 commit c469b8b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/api/api/productlist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<productlist count="1">
<product name="simple" cpe="cpe:/a:OBS_Fuzzies:simple:11.2" originproject="home:tom:temporary" mtime="1392135042"/>
</productlist>

39 changes: 39 additions & 0 deletions docs/api/api/productlist.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<xs:annotation>
<xs:documentation>
This schema specifies the format of product listing.
</xs:documentation>
</xs:annotation>

<xs:element name="productlist">
<xs:annotation>
<xs:documentation>
Product listing.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="product" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="count" type="xs:int"/>
</xs:complexType>
</xs:element>

<xs:element name="product">
<xs:annotation>
<xs:documentation>
One entry in the listing.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="cpe" type="xs:string"/>
<xs:attribute name="originproject" type="xs:string"/>
<xs:attribute name="mtime" type="xs:string"/>
</xs:complexType>
</xs:element>

</xs:schema>
8 changes: 4 additions & 4 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def render_project_productlist
if params.has_key? :expand
products = @project.expand_all_products
else
products = Product.joins(:package).where("packages.project_id = ? and packages.name = '_product'", @project.id).pluck(:name, :package_id)
products = Product.joins(:package).where("packages.project_id = ? and packages.name = '_product'", @project.id).pluck(:name, :cpe, :package_id)
end
products = @project.map_products_to_packages(products)
output = String.new
output << "<directory count='#{products.length}'>\n"
output << products.map { |p| p[1].nil? ? " <entry name=\"#{p[0]}\"/>\n" : " <entry name=\"#{p[0]}\" originproject=\"#{p[1]}\" mtime=\"#{p[2]}\"/>\n" }.join
output << "</directory>\n"
output << "<productlist count='#{products.length}'>\n"
output << products.map { |p| " <product name=\"#{p[0]}\" cpe=\"#{p[1]}\" originproject=\"#{p[2]}\" mtime=\"#{p[3]}\"/>\n" }.join
output << "</productlist>\n"
output
end

Expand Down
16 changes: 8 additions & 8 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -923,17 +923,17 @@ def expand_all_packages
# return array of [:name, :package_id] tuples for all products
# this function is making the products uniq
def expand_all_products( p_map = Hash.new )
products = Product.joins(:package).where("packages.project_id = ? and packages.name = '_product'", self.id).pluck(:name, :package_id)
products.each { |name, package_id| p_map[name] = 1 } # existing packages map
products = Product.joins(:package).where("packages.project_id = ? and packages.name = '_product'", self.id).pluck(:name, :cpe, :package_id)
products.each { |name, cpe, package_id| p_map[cpe] = 1 } # existing packages map
# second path, all packages from indirect linked projects
self.linkedprojects.each do |lp|
if lp.linked_db_project.nil?
# FIXME: this is a remote project
else
lp.linked_db_project.expand_all_products(p_map).each do |name, package_id|
unless p_map[name]
products << [name, package_id]
p_map[name] = 1
lp.linked_db_project.expand_all_products(p_map).each do |name, cpe, package_id|
unless p_map[cpe]
products << [name, cpe, package_id]
p_map[cpe] = 1
end
end
end
Expand Down Expand Up @@ -965,8 +965,8 @@ def map_packages_to_projects(packages)
def map_products_to_packages(packages)
ret = []
packages.each do |p|
package = Package.find_by_id p[1]
ret << [p[0], package.project.name, package.updated_at.to_i]
package = Package.find_by_id p[2]
ret << [p[0], p[1], package.project.name, package.updated_at.to_i]
end
ret
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/backend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_validate_bsxml
configuration directory_view download_counter download_counter_summary download_stats group
highest_rated issue_tracker latest_added latest_updated message messages most_active
newest_stats packageresult projectresult projects rating redirect_stats status_message
status_messages tagcloud taglist tags updated_timestamp distributions).include? schema
status_messages tagcloud taglist tags updated_timestamp distributions productlist).include? schema
# no backend schema exists
next
elsif schema == "binarylist"
Expand Down
8 changes: 4 additions & 4 deletions src/api/test/functional/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def test_simple_product_file
# product views in a project
get "/source/home:tom:temporary?view=productlist"
assert_response :success
assert_xml_tag :tag => "entry",
:attributes => { :name => "simple", :originproject => "home:tom:temporary" }
assert_xml_tag :tag => "product",
:attributes => { :name => "simple", :cpe => "cpe:/a:OBS_Fuzzies:simple:11.2", :originproject => "home:tom:temporary" }
get "/source/home:tom:temporary?view=productlist&expand=1"
assert_response :success
assert_xml_tag :tag => "entry",
:attributes => { :name => "simple", :originproject => "home:tom:temporary" }
assert_xml_tag :tag => "product",
:attributes => { :name => "simple", :cpe => "cpe:/a:OBS_Fuzzies:simple:11.2", :originproject => "home:tom:temporary" }

# product views in a package
get "/source/home:tom:temporary/_product?view=issues"
Expand Down

0 comments on commit c469b8b

Please sign in to comment.