summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-09-25 14:25:28 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-09-26 14:21:47 +0200
commite4635fd7e892cc7f7a91d4d132445c9b85522bf2 (patch)
tree07d31004f7474685e4acc1b85b6287e31e4e0f0a /sonar-server
parent9743ea3db37688360cb3f51dcbe565be79a0c80a (diff)
downloadsonarqube-e4635fd7e892cc7f7a91d4d132445c9b85522bf2.tar.gz
sonarqube-e4635fd7e892cc7f7a91d4d132445c9b85522bf2.zip
SONAR-3871 Initialization of project provisioning
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb63
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb44
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb13
5 files changed, 109 insertions, 25 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
index a7942f193ba..3e910e9353f 100644
--- a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
+++ b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
@@ -23,8 +23,10 @@ import com.google.common.base.Strings;
import org.sonar.api.component.Component;
import org.sonar.api.component.RubyComponentService;
import org.sonar.core.resource.ResourceDao;
+import org.sonar.core.resource.ResourceDto;
import org.sonar.server.util.RubyUtils;
+import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -43,6 +45,15 @@ public class DefaultRubyComponentService implements RubyComponentService {
return resourceDao.findByKey(key);
}
+ public void createComponent(String kee, String name, String scope, String qualifier) {
+ resourceDao.insertOrUpdate(
+ new ResourceDto()
+ .setKey(kee)
+ .setScope(scope)
+ .setQualifier(qualifier)
+ .setCreatedAt(new Date()));
+ }
+
public DefaultComponentQueryResult find(Map<String, Object> params) {
ComponentQuery query = toQuery(params);
List<Component> components = resourceDao.selectProjectsByQualifiers(query.qualifiers());
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
index deb2a8d4f9b..c56891f30c5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
@@ -20,7 +20,7 @@
class Api::ProjectsController < Api::ApiController
before_filter :admin_required, :only => [ :destroy ]
-
+
# PARAMETERS
# subprojects [true|false] : load sub-projects ? Default is false. Ignored if the parameter key is set.
# views [true|false] : load views and sub-views ? Default is false. Ignored if the parameter key is set.
@@ -28,56 +28,69 @@ class Api::ProjectsController < Api::ApiController
# langs (comma-separated list) : filter results by language. Default is empty.
# desc [true|false] : load project description ? Default is false.
# key : id or key of the project (0 or 1 result)
- # search : substring of project name, case insensitive
+ # search : substring of project name, case insensitive
# versions [true,false,last]. Default is false.
-
+
# TODO
# - SQL pagination (LIMIT + OFFSET)
-
+
def index
begin
@show_description=(params[:desc]=='true')
@projects=load_projects
@snapshots_by_pid=load_snapshots_by_project
- respond_to do |format|
+ respond_to do |format|
format.json{ render :json => jsonp(to_json) }
format.xml { render :xml => to_xml }
format.text { render :text => text_not_supported }
end
-
+
rescue Exception => e
logger.error("Fails to execute #{request.url} : #{e.message}")
render_error(e.message)
end
end
-
+
#
# DELETE /api/projects/<key>
# curl -X DELETE http://localhost:9000/api/projects/<key> -v -u admin:admin
#
def destroy
bad_request("Missing project key") unless params[:id].present?
-
+
project = Project.by_key(params[:id])
bad_request("Not valid project") unless project
access_denied unless is_admin?(project)
bad_request("Not valid project") unless java_facade.getResourceTypeBooleanProperty(project.qualifier, 'deletable')
-
+
Project.delete_resource_tree(project)
render_success("Project deleted")
end
-
+
+ #
+ # POST /api/projects/
+ # curl -X POST http://localhost:9000/api/projects/ -d key=project1 -d name='Project One' -v -u admin:admin
+ #
+ def create
+ verify_post_request
+ require_parameters :key, :name
+ access_denied unless has_role?("provisioning")
+
+ Internal.component_api.createComponent(params[:key], params[:name], 'PRJ', 'TRK')
+ render_success("Project %s created" % params[:key])
+ end
+
private
-
+
def load_projects
conditions=['enabled=:enabled']
values={:enabled => true}
-
+
if !params[:langs].blank?
conditions<<'language in (:langs)'
values[:langs]=params[:langs].split(',')
end
-
+
if !params[:key].blank?
begin
id=Integer(params[:key])
@@ -87,12 +100,12 @@ class Api::ProjectsController < Api::ApiController
conditions<<'kee=:key'
values[:key]=params[:key]
end
- else
+ else
if !params[:search].blank?
conditions<<"UPPER(name) like :name"
values[:name]='%' + params[:search].upcase + '%'
end
-
+
scopes=['PRJ']
qualifiers=['TRK']
if params[:views]=='true'
@@ -108,15 +121,15 @@ class Api::ProjectsController < Api::ApiController
values[:scopes]=scopes
values[:qualifiers]=qualifiers
end
-
+
# this is really an advanced optimization !
select_columns='id,kee,name,language,long_name,scope,qualifier,root_id'
select_columns += ',description' if @show_description
-
+
projects=Project.find(:all, :select => select_columns, :conditions => [conditions.join(' AND '), values], :order => 'name')
select_authorized(:user, projects)
end
-
+
def load_snapshots_by_project
select_columns='id,project_id,version,islast,created_at'
if params[:versions]=='true'
@@ -126,7 +139,7 @@ class Api::ProjectsController < Api::ApiController
else
snapshots=[]
end
-
+
snapshots_by_project_id={}
snapshots.each do |s|
snapshots_by_project_id[s.project_id]||=[]
@@ -145,7 +158,7 @@ class Api::ProjectsController < Api::ApiController
hash[:sc]=project.scope
hash[:qu]=project.qualifier
hash[:ds]=project.description if @show_description && project.description
-
+
if @snapshots_by_pid && @snapshots_by_pid[project.id]
versions={}
@snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot|
@@ -162,17 +175,17 @@ class Api::ProjectsController < Api::ApiController
end
json
end
-
+
def to_xml
xml = Builder::XmlMarkup.new(:indent => 0)
- xml.projects do
+ xml.projects do
@projects.each do |project|
- xml.project(:id => project.id.to_s, :key => project.key) do
+ xml.project(:id => project.id.to_s, :key => project.key) do
xml.name(project.name(true))
xml.scope(project.scope)
xml.qualifier(project.qualifier)
xml.desc(project.description) if @show_description && project.description
-
+
if @snapshots_by_pid && @snapshots_by_pid[project.id]
@snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot|
attributes={:sid => snapshot.id.to_s, :last => snapshot.last?}
@@ -185,4 +198,4 @@ class Api::ProjectsController < Api::ApiController
end
end
-end \ No newline at end of file
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb
new file mode 100644
index 00000000000..7e2deb3eca1
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/provisioning_controller.rb
@@ -0,0 +1,44 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+class ProvisioningController < ApplicationController
+
+ SECTION=Navigation::SECTION_CONFIGURATION
+
+ before_filter :admin_required
+
+ def index
+ @tabs = provisionable_qualifiers
+
+ @selected_tab = params[:qualifiers]
+ @selected_tab = 'TRK' unless @tabs.include?(@selected_tab)
+
+ params['pageSize'] = 20
+ params['qualifiers'] = @selected_tab
+
+ @query_results = Internal.component_api.findProvisioned(:qualifiers)
+ end
+
+ private
+
+ def provisionable_qualifiers
+ Java::OrgSonarServerUi::JRubyFacade.getInstance().getQualifiersWithProperty('hasRolePolicy')
+ end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
index c822c46d15b..6d5a385a75d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
@@ -137,6 +137,9 @@
<li class="sidebar-title"><%= message('sidebar.system') -%></li>
<li class="<%= 'active' if controller.controller_path=='backup' -%>"><a href="<%= ApplicationController.root_context -%>/backup"><%= message('backup.page') -%></a>
</li>
+ <li class="<%= 'active' if controller.controller_path=='provisioning' -%>">
+ <a href="<%= ApplicationController.root_context -%>/provisioning"><%= message('provisioning.page') -%></a>
+ </li>
<li class="<%= 'active' if controller.controller_path=='bulk_deletion' -%>">
<a href="<%= ApplicationController.root_context -%>/bulk_deletion"><%= message('bulk_deletion.page') -%></a>
</li>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb
new file mode 100644
index 00000000000..1639ec74647
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/provisioning/index.html.erb
@@ -0,0 +1,13 @@
+<h1 class="marginbottom10"><%= message('provisioning.page') -%></h1>
+
+<ul class="tabs">
+<% @tabs.each do |tab| %>
+ <li>
+ <a href="<%= url_for :action => 'index', :qualifiers => tab %>" <%= "class='selected'" if @selected_tab==tab -%> id="tab-<%= u tab -%>"><%= message('qualifiers.' + tab) -%></a>
+ </li>
+<% end %>
+</ul>
+
+<div class="tabs-panel marginbottom10">
+
+</div>