[yast-commit] r57314 - in /trunk/devtools: devtools/skeletons/rest-plugin/ devtools/skeletons/rest-plugin/app/ devtools/skeletons/rest-plugin/app/controllers/ devtools/skeletons/rest-plugin/app/models/ devtools/...

Author: lslezak Date: Mon May 25 17:34:26 2009 New Revision: 57314 URL: http://svn.opensuse.org/viewcvs/yast?rev=57314&view=rev Log: - added new skeleton 'rest-plugin' for webservice plugins, initial version Added: trunk/devtools/devtools/skeletons/rest-plugin/ trunk/devtools/devtools/skeletons/rest-plugin/MIT-LICENSE trunk/devtools/devtools/skeletons/rest-plugin/README trunk/devtools/devtools/skeletons/rest-plugin/Rakefile trunk/devtools/devtools/skeletons/rest-plugin/app/ trunk/devtools/devtools/skeletons/rest-plugin/app/controllers/ trunk/devtools/devtools/skeletons/rest-plugin/app/controllers/XXpkgXX_controller.rb trunk/devtools/devtools/skeletons/rest-plugin/app/models/ trunk/devtools/devtools/skeletons/rest-plugin/app/models/XXpkgXX.rb trunk/devtools/devtools/skeletons/rest-plugin/config/ trunk/devtools/devtools/skeletons/rest-plugin/config/resources/ trunk/devtools/devtools/skeletons/rest-plugin/config/resources/XXpkgXX.yml trunk/devtools/devtools/skeletons/rest-plugin/init.rb trunk/devtools/devtools/skeletons/rest-plugin/install.rb trunk/devtools/devtools/skeletons/rest-plugin/package/ trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.changes trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.spec trunk/devtools/devtools/skeletons/rest-plugin/rakelib/ trunk/devtools/devtools/skeletons/rest-plugin/rakelib/XXpkgXX_tasks.rake trunk/devtools/devtools/skeletons/rest-plugin/rakelib/include.rake trunk/devtools/devtools/skeletons/rest-plugin/test/ trunk/devtools/devtools/skeletons/rest-plugin/test/XXpkgXX_test.rb trunk/devtools/devtools/skeletons/rest-plugin/test/test_helper.rb trunk/devtools/devtools/skeletons/rest-plugin/uninstall.rb Modified: trunk/devtools/package/yast2-devtools.changes Added: trunk/devtools/devtools/skeletons/rest-plugin/MIT-LICENSE URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/MIT-LICENSE (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/MIT-LICENSE Mon May 25 17:34:26 2009 @@ -0,0 +1,20 @@ +Copyright (c) 2009 Novell + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Added: trunk/devtools/devtools/skeletons/rest-plugin/README URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/README (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/README Mon May 25 17:34:26 2009 @@ -0,0 +1,13 @@ +XXPkgXX +=========== + +REST API for XXPkgXX Yast module. + + +Example +======= + +Get list of all items: +http://localhost:8080/XXpkgXX.xml + +Copyright (c) 2009 Novell, released under the MIT license Added: trunk/devtools/devtools/skeletons/rest-plugin/Rakefile URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/Rakefile (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/Rakefile Mon May 25 17:34:26 2009 @@ -0,0 +1,33 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require 'rake/packagetask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the XXPkgXX plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the XXPkgXX plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'XXPkgXX' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +desc 'Generate tarball package' +Rake::PackageTask.new('www', :noversion) do |p| + p.need_tar_bz2 = true + p.package_dir = 'package' + p.package_files.include('**/*') + p.package_files.exclude('package') +end + Added: trunk/devtools/devtools/skeletons/rest-plugin/app/controllers/XXpkgXX_controller.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/app/controllers/XXpkgXX_controller.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/app/controllers/XXpkgXX_controller.rb Mon May 25 17:34:26 2009 @@ -0,0 +1,139 @@ + +require "XXpkgXX" + +class XXPkgXXController < ApplicationController + + # the user must be logged in + before_filter :login_required + + # GET /XXpkgXX + # GET /XXpkgXX.xml + # GET /XXpkgXX.json + def index + # read all items + # FIXME: use the correct permission ID according to XXPkgXX::find_all function +# if !permission_check("org.opensuse.yast.modules.yapi.XXpkgXX.list") +# render ErrorResult.error(403, 1, "no permission") and return +# end +# FIXME: ^^^^ uncomment this block!! + + @items = XXPkgXX.find_all + + respond_to do |format| + format.html { render :xml => @items, :location => "none" } #return xml only + format.xml { render :xml => @items, :location => "none" } + format.json { render :json => @items.to_json, :location => "none" } + end + end + + # GET /XXpkgXX/id + # GET /XXpkgXX/id.xml + # GET /XXpkgXX/id.json + # return properties of one item + def show + # FIXME: use the correct permission ID according to XXPkgXX::find function +# if !permission_check("org.opensuse.yast.modules.yapi.XXpkgXX.get") +# render ErrorResult.error(403, 1, "no permission") and return +# end +# FIXME: ^^^^ uncomment this block!! + + @item = XXPkgXX.new + @item.name = params[:id] + + if !@item.find + render ErrorResult.error(404, 2, "item not found") and return + end + + respond_to do |format| + format.html { render :xml => @item, :location => "none" } #return xml only + format.xml { render :xml => @item, :location => "none" } + format.json { render :json => @item.to_json, :location => "none" } + end + end + + # POST /XXpkgXX + # POST /XXpkgXX.xml + # POST /XXpkgXX.json + # create a new item + def create + @item = XXPkgXX.new + + # FIXME: use the correct permission ID according to XXPkgXX::add function + if !permission_check("org.opensuse.yast.modules.yapi.XXpkgXX.add") + render ErrorResult.error(403, 1, "no permission") and return + else + if !@item.update_attributes(params[:id]) + render ErrorResult.error(404, 2, "input error") and return + end + + if !@item.name.blank? + if !@item.add + render ErrorResult.error(404, 3, "adding share failed") and return + end + else + render ErrorResult.error(404, 4, "empty share name") and return + end + end + + respond_to do |format| + format.html { render :xml => @item, :location => "none" } #return xml only + format.xml { render :xml => @item, :location => "none" } + format.json { render :json => @item.to_json, :location => "none" } + end + end + + # PUT /XXpkgXX/id + # PUT /XXpkgXX/id.xml + # PUT /XXpkgXX/id.json + # update one item + def update + # FIXME: use the correct permission ID according to XXPkgXX::edit function + if !permission_check("org.opensuse.yast.modules.yapi.XXpkgXX.edit") + render ErrorResult.error(403, 1, "no permission") and return + end + + @item = XXPkgXX.find(params[:id][:name]) + + render ErrorResult.error(403, 1, "share not found") and return if @item.properties.blank? + + if !@item.update_attributes(params[:id]) + render ErrorResult.error(404, 2, "input error") and return + end + + if !@item.edit + render ErrorResult.error(404, 3, "editing share failed") and return + end + + respond_to do |format| + format.html { render :xml => @item, :location => "none" } #return xml only + format.xml { render :xml => @item, :location => "none" } + format.json { render :json => @item.to_json, :location => "none" } + end + end + + # DELETE /XXpkgXX/id + # DELETE /XXpkgXX/id.xml + # DELETE /XXpkgXX/id.json + # delete one item + def destroy + # FIXME: use the correct permission ID according to XXPkgXX::delete function + if !permission_check("org.opensuse.yast.modules.yapi.XXpkgXX.delete") + render ErrorResult.error(403, 1, "no permission") and return + end + + @item = XXPkgXX.new + @item.name = params[:id] + + if !@item.delete + render ErrorResult.error(404, 2, "delete failed") and return + end + + respond_to do |format| + format.html { render :xml => @item, :location => "none" } #return xml only + format.xml { render :xml => @item, :location => "none" } + format.json { render :json => @item.to_json, :location => "none" } + end + end + +end + Added: trunk/devtools/devtools/skeletons/rest-plugin/app/models/XXpkgXX.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/app/models/XXpkgXX.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/app/models/XXpkgXX.rb Mon May 25 17:34:26 2009 @@ -0,0 +1,147 @@ + +# import YastService class +require "yast_service" + +# models XXPkgXX objects +class XXPkgXX + + # FIXME: adapt to your model, add members to store all needed properties + attr_accessor :name, + :parameters + + def initialize + # unique identification (name, ID number, ...) + @name = nil + + # attributes + # FIXME: adapt to your model, add as many members as needed... + # initialize them to a default or empty values + @parameters = nil + end + + def XXPkgXX.find_all() + # read IDs of all existing items + + # FIXME: Use the correct Yast function call, e.g. + # items = YastService.Call("YaPI::XXPkgXX::List") + + items = [ "first", "second", "last" ] # FIXME: remove this dummy line + + # FIXME optionaly sort the result + items.sort! + + result = [ ] + + # convert the list of items to list of objects + items.each { |p| + item = XXPkgXX.new + + # set only ID, the other parameters should have default or empty values + item.name = p + + result << item + } + + return result + end + + def find + # cannot find invalid object + return false if @name.blank? + + # get properties of the object + + # FIXME: Use the correct Yast function call, e.g. + # properties = YastService.Call("YaPI::XXPkgXX::Get", @name) + + properties = { :p1 => "foo", :p2 => "bar" } # FIXME: remove this dummy line + + # check the value + if properties.nil? || properties == {} + @parameters = nil + return false + else + # FIXME update all class members + @parameters = properties + return true + end + end + + def update_attributes(attribs) + if attribs.has_key?(:name) + new_name = attribs[:name] + + # FIXME: valide the option + if new_name.class != :String + return false + end + + @name = new_name + end + + if attribs.has_key?(:parameters) + new_params = attribs[:parameters] + + # FIXME: valide the option + if new_params.class != :Hash + return false + end + + @parameters = new_params + end + + # FIXME: update all properties here... + + return true + end + + def add + # FIXME: Use the correct Yast function call, e.g. + # return YastService.Call("YaPI::XXPkgXX::Add", @name, @parameters) if !@name.blank? + + return false + end + + def edit + # FIXME: Use the correct Yast function call, e.g. + # return YastService.Call("YaPI::XXPkgXX::Edit", @name, @parameters) if !@name.blank? + + return false + end + + def delete + # FIXME: Use the correct Yast function call, e.g. + # return YastService.Call("YaPI::XXPkgXX::Delete", @name) if !@name.blank? + + return false + end + + # FIXME: export all members in XML + def to_xml( options = {} ) + return nil if @name.nil? + + xml = options[:builder] ||= Builder::XmlMarkup.new(options) + xml.instruct! unless options[:skip_instruct] + + xml.XXpkgXX do + xml.tag!(:name, @name) + + if !@parameters.blank? + # FIXME: Note: the first parameter of tag! is tag name, the second is value, + # the result is <parameters>[value of @parameter]</parameters> + # see http://api.rubyonrails.org/classes/Builder/XmlMarkup.html + xml.tag!(:parameters, @parameters) + end + end + end + + # export the object in JSON format + # reuse the XML builder functionality + def to_json( options = {} ) + hash = Hash.from_xml(to_xml()) + return hash.to_json + end + +end + +# vim: ft=ruby Added: trunk/devtools/devtools/skeletons/rest-plugin/config/resources/XXpkgXX.yml URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/config/resources/XXpkgXX.yml (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/config/resources/XXpkgXX.yml Mon May 25 17:34:26 2009 @@ -0,0 +1,2 @@ +interface: org.opensuse.yast.system.XXpkgXX +controller: XXpkgXX Added: trunk/devtools/devtools/skeletons/rest-plugin/init.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/init.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/init.rb Mon May 25 17:34:26 2009 @@ -0,0 +1 @@ +# Include hook code here Added: trunk/devtools/devtools/skeletons/rest-plugin/install.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/install.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/install.rb Mon May 25 17:34:26 2009 @@ -0,0 +1 @@ +# Install hook code here Added: trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.changes (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.changes Mon May 25 17:34:26 2009 @@ -0,0 +1,4 @@ +------------------------------------------------------------------- +XXdateXX - XXemailXX + +- initial version Added: trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.spec URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.spec (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/package/yast2-webservice-XXpkgXX.spec Mon May 25 17:34:26 2009 @@ -0,0 +1,67 @@ +# +# spec file for package yast2-webservice-XXpkgXX +# +# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. +# This file and all modifications and additions to the pristine +# package are under the same license as the package itself. +# +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + +%define pkg_user yastws +%define plugin_name XXpkgXX + +Name: yast2-webservice-XXpkgXX +PreReq: yast2-webservice +Provides: yast2-webservice:/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app/controllers/XXpkgXX_controller.rb +License: MIT +Group: Productivity/Networking/Web/Utilities +Autoreqprov: on +Version: 0.0.1 +Release: 0 +Summary: YaST2 - Webservice - REST API for XXPkgXX Yast module +Source: www.tar.bz2 +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildArch: noarch + + + +%description +YaST2 - Webservice - REST based interface for YaST XXPkgXX module. +Authors: +-------- + XXmaintainerXX <XXemailXX> + +%prep +%setup -q -n www + +%build + +%install + +# +# Install all web and frontend parts. +# +mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} +cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%dir /srv/www/%{pkg_user} +%dir /srv/www/%{pkg_user}/vendor +%dir /srv/www/%{pkg_user}/vendor/plugins +%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name} +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/MIT-LICENSE +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/tasks +/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/test + Added: trunk/devtools/devtools/skeletons/rest-plugin/rakelib/XXpkgXX_tasks.rake URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/rakelib/XXpkgXX_tasks.rake (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/rakelib/XXpkgXX_tasks.rake Mon May 25 17:34:26 2009 @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :XXpkgXX do +# # Task goes here +# end Added: trunk/devtools/devtools/skeletons/rest-plugin/rakelib/include.rake URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/rakelib/include.rake (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/rakelib/include.rake Mon May 25 17:34:26 2009 @@ -0,0 +1,10 @@ + +# import global .rake files for plugins +if File.exist? "#{File.dirname(__FILE__)}/../../../webservice/lib/tasks/webservice/" + # use delopemnt files if we are in git repository + Dir["#{File.dirname(__FILE__)}/../../../webservice/lib/tasks/webservice/*.rake"].each { |ext| load ext } +else + # use the files from yast2-webservice package + Dir["/srv/www/yastws/lib/tasks/webservice/*.rake"].each { |ext| load ext } +end + Added: trunk/devtools/devtools/skeletons/rest-plugin/test/XXpkgXX_test.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/test/XXpkgXX_test.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/test/XXpkgXX_test.rb Mon May 25 17:34:26 2009 @@ -0,0 +1,8 @@ +require 'test_helper' + +class XXPkgXXTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end Added: trunk/devtools/devtools/skeletons/rest-plugin/test/test_helper.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/test/test_helper.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/test/test_helper.rb Mon May 25 17:34:26 2009 @@ -0,0 +1,3 @@ +require 'rubygems' +require 'active_support' +require 'active_support/test_case' \ No newline at end of file Added: trunk/devtools/devtools/skeletons/rest-plugin/uninstall.rb URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/devtools/skeletons/rest-... ============================================================================== --- trunk/devtools/devtools/skeletons/rest-plugin/uninstall.rb (added) +++ trunk/devtools/devtools/skeletons/rest-plugin/uninstall.rb Mon May 25 17:34:26 2009 @@ -0,0 +1 @@ +# Uninstall hook code here Modified: trunk/devtools/package/yast2-devtools.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/devtools/package/yast2-devtools.c... ============================================================================== --- trunk/devtools/package/yast2-devtools.changes (original) +++ trunk/devtools/package/yast2-devtools.changes Mon May 25 17:34:26 2009 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Mon May 25 17:32:05 CEST 2009 - lslezak@suse.cz + +- added new skeleton 'rest-plugin' for webservice plugins, + initial version + +------------------------------------------------------------------- Wed May 20 17:23:49 CEST 2009 - lslezak@suse.cz - create-new-package - fixed syntax error (missing semicolon) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
lslezak@svn.opensuse.org