From d7069b5a2e7859ab14c5a909d5e5fc6bc84b80cb Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Thu, 3 Jan 2013 07:41:53 +0000 Subject: Improve app hosting management app, restructure UI and refactor REST services and data model to use an SQL database. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428193 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/hosting/server/apps.py | 67 ++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'sca-cpp/trunk/hosting/server/apps.py') diff --git a/sca-cpp/trunk/hosting/server/apps.py b/sca-cpp/trunk/hosting/server/apps.py index 064701a7df..5b0c1b8831 100644 --- a/sca-cpp/trunk/hosting/server/apps.py +++ b/sca-cpp/trunk/hosting/server/apps.py @@ -16,96 +16,103 @@ # under the License. # App collection implementation -from time import strftime from util import * +from atomutil import * from sys import debug # Convert an id to an app id def appid(id): - return ("apps", car(id), "app.stats") + return ("apps", car(id), "app.info") # Put an app into the apps db -def put(id, app, user, cache, dashboard, store, composites, pages): +def put(id, app, user, cache, dashboard, store, composites, pages, icons): debug('apps.py::put::id', id) debug('apps.py::put::app', app) # Update an app - eid = cadr(assoc("'id", car(app))) + eid = entryid(app) if car(id) == eid: # Check app author - eapp = cache.get(appid(id)); - if (not (isNil(eapp) or eapp is None)) and (cadr(assoc("'author", car(eapp))) != user.get(())): - debug('apps.py::put', 'different author', cadr(assoc("'author", car(eapp)))) + eapp = cache.get(appid(id)) + if (not isNil(eapp)) and (author(eapp) != user.get(())): + debug('apps.py::put', 'different author', author(eapp)) return False # Update the app in the apps db - appentry = (("'entry", assoc("'title", car(app)), ("'id", car(id)), ("'author", user.get(())), ("'updated", strftime('%b %d, %Y')), assoc("'content", car(app))),) + appentry = mkentry(title(app), car(id), user.get(()), now(), content(app)) debug('apps.py::put::appentry', appentry) cache.put(appid(id), appentry) dashboard.put(id, appentry) # Create new page and composite if necessary - if isNil(eapp) or eapp is None: - comp = (("'entry", ("'title", car(id)), ("'id", car(id))),) - composites.put(id, comp); - page = (("'entry", ("'title", car(id)), ("'id", car(id))),) - pages.put(id, comp); + if isNil(eapp): + comp = mkentry(car(id), car(id), user.get(()), now(), ()) + composites.put(id, comp) + page = mkentry(car(id), car(id), user.get(()), now(), ()) + pages.put(id, page) + icon = mkentry(car(id), car(id), user.get(()), now(), ()) + icons.put(id, icon) return True return True # Check app author - eapp = cache.get(appid(id)); - if (not (isNil(eapp) or eapp is None)) and (cadr(assoc("'author", car(eapp))) != user.get(())): - debug('apps.py::put', 'different author', cadr(assoc("'author", car(eapp)))) + eapp = cache.get(appid(id)) + if (not isNil(eapp)) and (author(eapp) != user.get(())): + debug('apps.py::put', 'different author', author(eapp)) return False - # Clone an app - appentry = (("'entry", assoc("'title", car(app)), ("'id", car(id)), ("'author", user.get(())), ("'updated", strftime('%b %d, %Y')), assoc("'content", car(app))),) + # Get app to clone + capp = cache.get(appid((eid,))) + if isNil(capp): + debug('apps.py::put', 'cloned app not found', (eid,)) + return False + + # Clone app + appentry = mkentry(title(app), car(id), user.get(()), now(), content(app)) debug('apps.py::put::appentry', appentry) cache.put(appid(id), appentry) composites.put(id, composites.get((eid,))) pages.put(id, pages.get((eid,))) + icons.put(id, icons.get((eid,))) dashboard.put(id, appentry) return True # Get an app from the apps db -def get(id, user, cache, dashboard, store, composites, pages): +def get(id, user, cache, dashboard, store, composites, pages, icons): debug('apps.py::get::id', id) if isNil(id): return (("'feed", ("'title", "Apps"), ("'id", "apps")),) # Get the requested app - app = cache.get(appid(id)); - if isNil(app) or app is None: + app = cache.get(appid(id)) + if isNil(app): debug('apps.py::get', 'app not found', id) - - # Return a default new app - return (("'entry", ("'title", car(id)), ("'id", car(id)), ("'author", user.get(())), ("'updated", strftime('%b %d, %Y')), ("'content", ("'stats", ("'description", '')))),) + return None # Return the app debug('apps.py::get::app', app) return app # Delete an app from the apps db -def delete(id, user, cache, dashboard, store, composites, pages): +def delete(id, user, cache, dashboard, store, composites, pages, icons): debug('apps.py::delete::id', id) # Get the requested app - app = cache.get(appid(id)); - if isNil(app) or app is None: + app = cache.get(appid(id)) + if isNil(app): debug('apps.py::delete', 'app not found', id) return False # Check app author - author = cadr(assoc("'author", car(app))) - if author != user.get(()): - debug('apps.py::delete', 'different author', author) + if author(app) != user.get(()): + debug('apps.py::delete', 'different author', author(app)) return False # Delete the app, its composite and page dashboard.delete(id) composites.delete(id) pages.delete(id) + icons.delete(id) cache.delete(appid(id)) return True -- cgit v1.2.3