class Project < ActiveRecord::Base
include Comparable
include Resourceable
-
+
has_many :snapshots
has_many :processed_snapshots, :class_name => 'Snapshot', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc'
has_many :events, :foreign_key => 'resource_id', :order => 'event_date DESC'
end
def self.delete_project(project)
+ if project
Snapshot.update_all(['islast=?', false], ['(root_project_id=? OR project_id=?) AND islast=?', project.id, project.id, true])
Project.delete_all(['id=? OR root_id=? or copy_resource_id=?', project.id, project.id, project.id])
+ end
end
-
+
def project
root||self
end
-
+
def root_project
- @root_project ||=
- begin
- parent_module(self)
- end
+ @root_project ||=
+ begin
+ parent_module(self)
+ end
end
-
+
def last_snapshot
@last_snapshot ||=
- begin
- snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id})
- if snapshot
- snapshot.project=self
+ begin
+ snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id})
+ if snapshot
+ snapshot.project=self
+ end
+ snapshot
end
- snapshot
- end
end
-
+
def events_with_snapshot
- events.select{|event| !event.snapshot_id.nil?}
+ events.select { |event| !event.snapshot_id.nil? }
end
-
+
def key
kee
end
def links
project_links
end
-
+
def link(type)
# to_a avoids conflicts with ActiveRecord:Base.find
- links.to_a.find{ |l| l.link_type==type}
- end
-
+ links.to_a.find { |l| l.link_type==type }
+ end
+
def custom_links
- links.select {|l| l.custom?}
+ links.select { |l| l.custom? }
end
-
+
def standard_links
- links.reject {|l| l.custom?}
+ links.reject { |l| l.custom? }
end
def chart_measures(metric_id)
sql = Project.send(:sanitize_sql, ['select s.created_at as created_at, m.value as value ' +
- ' from project_measures m, snapshots s ' +
- ' where s.id=m.snapshot_id and ' +
- " s.status='%s' and " +
- ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id] ) +
- ' and m.rule_id IS NULL and m.rule_priority IS NULL' +
- ' order by s.created_at'
- create_chart_measures( Project.connection.select_all( sql ), 'created_at', 'value' )
+ ' from project_measures m, snapshots s ' +
+ ' where s.id=m.snapshot_id and ' +
+ " s.status='%s' and " +
+ ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) +
+ ' and m.rule_id IS NULL and m.rule_priority IS NULL' +
+ ' order by s.created_at'
+ create_chart_measures(Project.connection.select_all(sql), 'created_at', 'value')
end
def <=>(other)
def fullname
name
end
-
+
def branch
if project? || module?
s=kee.split(':')
if s.size>=3
return s[2]
- end
+ end
end
nil
end
# when regular active record impl return string typed objects
if results.first[date_column_name].class == Time
results.each do |hash|
- chart_measures << ChartMeasure.new( hash[date_column_name], hash[value_column_name] )
+ chart_measures << ChartMeasure.new(hash[date_column_name], hash[value_column_name])
end
else
results.each do |hash|
- chart_measures << ChartMeasure.new( Time.parse( hash[date_column_name] ), hash[value_column_name].to_d )
+ chart_measures << ChartMeasure.new(Time.parse(hash[date_column_name]), hash[value_column_name].to_d)
end
end
end
chart_measures
end
-
+
def parent_module(current_module)
current_module.root ? parent_module(current_module.root) : current_module
end
-
+
end
connector.execute(query);
}
- public void delete(DeleteQuery<?> query) {
+ public void delete(DeleteQuery query) {
connector.execute(query);
}
* @return JSON response or null if 404 NOT FOUND error
* @since 2.2
*/
- public abstract String execute(DeleteQuery<?> query);
+ public abstract String execute(DeleteQuery query);
/**
* @return JSON response or null if 404 NOT FOUND error
return executeRequest(newPutRequest(query));
}
- public String execute(DeleteQuery<?> query) {
+ public String execute(DeleteQuery query) {
return executeRequest(newDeleteRequest(query));
}
return method;
}
- private HttpMethodBase newDeleteRequest(DeleteQuery<?> query) {
+ private HttpMethodBase newDeleteRequest(DeleteQuery query) {
HttpMethodBase method = new DeleteMethod(server.getHost() + query.getUrl());
initRequest(method, query);
return method;
return executeRequest(newPutMethod(query));
}
- public String execute(DeleteQuery<?> query) {
+ public String execute(DeleteQuery query) {
return executeRequest(newDeleteMethod(query));
}
return get;
}
- private HttpDelete newDeleteMethod(DeleteQuery<?> query) {
+ private HttpDelete newDeleteMethod(DeleteQuery query) {
HttpDelete delete = new HttpDelete(server.getHost() + query.getUrl());
initRequest(delete, query);
return delete;
*
* @since 2.2
*/
-public abstract class DeleteQuery<MODEL extends Model> extends AbstractQuery<MODEL> {
+public abstract class DeleteQuery extends AbstractQuery {
}
*/
package org.sonar.wsclient.services;
-public class FavouriteDeleteQuery extends DeleteQuery<Favourite> {
+public class FavouriteDeleteQuery extends DeleteQuery {
private String idOrKey;
/**
* @since 2.10
*/
-public final class ManualMeasureDeleteQuery extends DeleteQuery<ManualMeasure> {
+public final class ManualMeasureDeleteQuery extends DeleteQuery {
private String resourceKey;
private String metricKey;
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.11
+ */
+public final class ProjectDeleteQuery extends DeleteQuery {
+
+ private String key;
+ private static final String BASE_URL = "/api/projects/";
+
+ private ProjectDeleteQuery(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder();
+ url.append(BASE_URL);
+ url.append(encode(key));
+ return url.toString();
+ }
+
+ public static ProjectDeleteQuery create(String projectKeyOrId) {
+ return new ProjectDeleteQuery(projectKeyOrId);
+ }
+}
/**
* @since 2.6
*/
-public class PropertyDeleteQuery extends DeleteQuery<Property> {
+public class PropertyDeleteQuery extends DeleteQuery {
private String key;
private String resourceKeyOrId;
/**
* @since 2.2
*/
-public class UserPropertyDeleteQuery extends DeleteQuery<Property> {
+public class UserPropertyDeleteQuery extends DeleteQuery {
private String key;
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+import org.sonar.wsclient.Sonar;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ProjectDeleteQueryTest extends QueryTestCase {
+
+ @Test
+ public void testUrl() {
+ ProjectDeleteQuery query = ProjectDeleteQuery.create("my:project");
+ assertThat(query.getUrl(), is("/api/projects/my%3Aproject"));
+ }
+
+}
\ No newline at end of file