incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [5/9] git commit: [#7208] ticket:549 Add DOAP API + basic project fields
Date Wed, 12 Mar 2014 20:48:03 GMT
[#7208] ticket:549 Add DOAP API + basic project fields


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/28c1722d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/28c1722d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/28c1722d

Branch: refs/heads/master
Commit: 28c1722d4147819ea0d2b927540b1f52ce7606c9
Parents: cc742e3
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Feb 24 17:23:49 2014 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Mar 12 20:47:54 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py |  6 +++-
 Allura/allura/model/project.py    | 54 ++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/28c1722d/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 6e7e452..2985c55 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -25,7 +25,7 @@ import oauth2 as oauth
 from webob import exc
 from tg import expose, flash, redirect
 from pylons import tmpl_context as c, app_globals as g
-from pylons import request
+from pylons import request, response
 
 from ming.orm import session
 from ming.utils import LazyProperty
@@ -307,4 +307,8 @@ class ProjectRestController(object):
 
     @expose('json:')
     def index(self, **kw):
+        if 'doap' in kw:
+            response.headers['Content-Type'] = ''
+            response.content_type = 'application/rdf+xml'
+            return c.project.doap()
         return c.project.__json__()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/28c1722d/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index c5ffd91..21b8b9c 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -27,6 +27,7 @@ from pylons import tmpl_context as c, app_globals as g
 from pylons import request
 from paste.deploy.converters import asbool
 import formencode as fe
+from datatree import Tree, Node
 
 from ming import schema as S
 from ming.utils import LazyProperty
@@ -983,6 +984,59 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             ]
         )
 
+    def doap(self):
+        root = Node('rdf:RDF', **{
+            'xmlns:rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+            'xmlns:rdfs': "http://www.w3.org/2000/01/rdf-schema#",
+        })
+        p = Node('Project', **{
+            'xmlns': "http://usefulinc.com/ns/doap#",
+            'xmlns:foaf': "http://xmlns.com/foaf/0.1/",
+            'xmlns:sf': "http://sourceforge.net/api/sfelements.rdf#",
+            'xmlns:rss': "http://purl.org/rss/1.0/",
+            'xmlns:dc': "http://dublincore.org/documents/dcmi-namespace/",
+            'xmlns:beer': "http://www.purl.org/net/ontology/beer.owl#",
+            'rdf:about': "http://sourceforge.net/api/project/name/vivo/doap#",
+        })
+        root << p
+        p << Node('name', self.name)
+        p << Node('sf:shortname', self.shortname)
+        p << Node('sf:id', str(self._id))
+        p << Node('sf:private', self.private)
+        p << Node('created', )
+        p << Node('shortdesc', self.short_description, **{'xml:lang': 'en'})
+        p << Node('description', self.description, **{'xml:lang': 'en'})
+        if self.external_homepage:
+            p << Node('homepage', **{'rdf:resource': self.external_homepage})
+
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_audience}}):
+            p << Node('audience', cat.fullname)
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_os}}):
+            p << Node('os', cat.fullname)
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_language}}):
+            p << Node('programming-language', cat.fullname)
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_license}}):
+            p << Node('license', cat.fullname)
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_environment}}):
+            p << Node('sf:environment', cat.fullname)
+        for cat in TroveCategory.query.find({'_id': {'$in': self.trove_root_database}}):
+            p << Node('sf:database', cat.fullname)
+        all_troves = (
+            self.trove_root_database +
+            self.trove_developmentstatus +
+            self.trove_audience +
+            self.trove_license +
+            self.trove_topic +
+            self.trove_os +
+            self.trove_language +
+            self.trove_natlanguage +
+            self.trove_environment
+        )
+        for cat in TroveCategory.query.find({'_id': {'$in': all_troves}}):
+            p << Node('category', **{'rdf:resource': 'http://sourceforge.net/api/trove/index/rdf#%s'
% cat.trove_cat_id})
+
+        return root.render(as_root=True)
+
 
 class AppConfig(MappedClass, ActivityObject):
 


Mime
View raw message