private final PropertiesDao propertiesDao;
private final Actions actions;
- public ActionService(DbClient dbClient, IssueService issueService, IssueStorage issueStorage, IssueUpdater updater, Settings settings, PropertiesDao propertiesDao, Actions actions) {
+ public ActionService(DbClient dbClient, IssueService issueService, IssueStorage issueStorage, IssueUpdater updater, Settings settings, PropertiesDao propertiesDao,
+ Actions actions) {
this.dbClient = dbClient;
this.issueService = issueService;
this.issueStorage = issueStorage;
public List<Issue> search(List<String> issueKeys) {
// Load from index to check permission
List<Issue> authorizedIndexIssues = search(IssueQuery.builder().issueKeys(issueKeys).build(), new QueryContext().setMaxLimit()).getHits();
- // return ;
List<String> authorizedIssueKeys = newArrayList(Iterables.transform(authorizedIndexIssues, new Function<Issue, String>() {
@Override
public String apply(@Nullable Issue input) {
esSearch.setQuery(esQuery);
}
- // Sample Functional aggregation
- // esSearch.addAggregation(AggregationBuilders.sum("totalDuration")
- // .field(IssueNormalizer.IssueField.DEBT.field()));
-
SearchResponse response = getClient().execute(esSearch);
return new Result<Issue>(this, response);
}
private void writeIssue(DbSession session, DefaultIssue issue, JsonWriter json) {
String actionPlanKey = issue.actionPlanKey();
- ActionPlan actionPlan = actionPlanService.findByKey(actionPlanKey, UserSession.get());
+ ActionPlan actionPlan = actionPlanKey != null ? actionPlanService.findByKey(actionPlanKey, UserSession.get()) : null;
Duration debt = issue.debt();
Rule rule = ruleService.getNonNullByKey(issue.ruleKey());
Date updateDate = issue.updateDate();
private void addComponents(DbSession session, DefaultIssue issue, JsonWriter json) {
// component, module and project can be null if they were removed
ComponentDto component = dbClient.componentDao().getNullableByKey(session, issue.componentKey());
- ComponentDto subProject = component != null ? dbClient.componentDao().getNullableById(component.subProjectId(), session) : null;
+ Long subProjectId = component != null ? component.subProjectId() : null;
+ ComponentDto subProject = subProjectId != null ? dbClient.componentDao().getNullableById(subProjectId, session) : null;
ComponentDto project = component != null ? dbClient.componentDao().getNullableById(component.projectId(), session) : null;
String projectName = project != null ? project.longName() != null ? project.longName() : project.name() : null;
}
@Override
- protected void doContextResponse(Request request, QueryContext context, Result<Issue> result, JsonWriter json) {
+ @CheckForNull
+ protected Collection<String> possibleFields() {
+ return null;
+ }
+ @Override
+ protected void doContextResponse(Request request, QueryContext context, Result<Issue> result, JsonWriter json) {
// Insert the projects and component name;
Set<RuleKey> ruleKeys = new HashSet<RuleKey>();
Set<String> projectKeys = new HashSet<String>();
Set<String> componentKeys = new HashSet<String>();
Set<String> actionPlanKeys = new HashSet<String>();
List<String> userLogins = new ArrayList<String>();
- //
- // DbSession session = dbClient.openSession(false);
+
for (Issue issue : result.getHits()) {
ruleKeys.add(issue.ruleKey());
projectKeys.add(issue.projectKey());
return null;
}
- @CheckForNull
public Collection<org.sonar.api.rules.Rule> findByIds(Collection<Integer> ruleIds) {
List<org.sonar.api.rules.Rule> rules = newArrayList();
if (ruleIds.isEmpty()) {
return rules;
}
- @CheckForNull
public Collection<org.sonar.api.rules.Rule> findByKeys(Collection<RuleKey> ruleKeys) {
List<org.sonar.api.rules.Rule> rules = newArrayList();
if (ruleKeys.isEmpty()) {
}
@CheckForNull
+ @Override
public DOMAIN getNullableByKey(KEY key) {
GetRequestBuilder request = client.prepareGet()
.setType(this.getIndexType())
public interface Index<DOMAIN, DTO extends Dto<KEY>, KEY extends Serializable> extends Startable, ServerComponent {
@CheckForNull
- DOMAIN getByKey(KEY item);
+ DOMAIN getNullableByKey(KEY key);
String getIndexType();
/**
* Generic options for search web services
+ *
+ * TODO {@link org.sonar.server.search.ws.SearchRequestHandler} should be used instead
*/
public class SearchOptions {
import javax.annotation.CheckForNull;
import java.util.Collection;
-import java.util.List;
+import java.util.Iterator;
import java.util.Map;
public abstract class SearchRequestHandler<QUERY, DOMAIN> implements RequestHandler {
- public static final String PARAM_TEXT_QUERY = "q";
public static final String PARAM_PAGE = "p";
public static final String PARAM_PAGE_SIZE = "ps";
public static final String PARAM_FIELDS = "f";
public static final String PARAM_FACETS = "facets";
- private List<String> fields;
-
private final String actionName;
- /**
- * The fields to be returned in JSON response. <code>null</code> means that
- * all the fields must be returned.
- */
- @CheckForNull
- public List<String> fields() {
- return fields;
- }
-
protected SearchRequestHandler(String actionName) {
this.actionName = actionName;
}
protected abstract void doDefinition(WebService.NewAction action);
+ @CheckForNull
+ protected abstract Collection<String> possibleFields();
+
public final void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(this.actionName)
.setHandler(this);
.setBooleanPossibleValues()
.setDefaultValue("false");
- WebService.NewParam newParam = action
- .createParam(PARAM_FIELDS)
- .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default.");
-
- // .setPossibleValues(possibleFields);
- // if (possibleFields != null && possibleFields.size() > 1) {
- // Iterator<String> it = possibleFields.iterator();
- // newParam.setExampleValue(String.format("%s,%s", it.next(), it.next()));
- // }
+ Collection<String> possibleFields = possibleFields();
+ WebService.NewParam paramFields = action.createParam(PARAM_FIELDS)
+ .setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default.")
+ .setPossibleValues(possibleFields);
+ if (possibleFields != null && possibleFields.size() > 1) {
+ Iterator<String> it = possibleFields.iterator();
+ paramFields.setExampleValue(String.format("%s,%s", it.next(), it.next()));
+ }
this.doDefinition(action);
}
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.db.IssueDto;
import org.sonar.core.rule.RuleDto;
}
public static void assertIsEquivalent(IssueDto dto, Issue issue) {
-
assertThat(issue).isNotNull();
assertThat(dto).isNotNull();
+ assertThat(issue.key()).isEqualTo(dto.getKey());
assertThat(issue.actionPlanKey()).isEqualTo(dto.getActionPlanKey());
assertThat(issue.assignee()).isEqualTo(dto.getAssignee());
assertThat(issue.authorLogin()).isEqualTo(dto.getAuthorLogin());
assertThat(issue.line()).isEqualTo(dto.getLine());
assertThat(issue.message()).isEqualTo(dto.getMessage());
assertThat(issue.reporter()).isEqualTo(dto.getReporter());
- assertThat(issue.key()).isEqualTo(dto.getKey());
-
- // assertThat(issue.updateDate()).isEqualTo(dto.getIssueUpdateDate());
+ assertThat(issue.language()).isEqualTo(dto.getLanguage());
assertThat(issue.status()).isEqualTo(dto.getStatus());
assertThat(issue.severity()).isEqualTo(dto.getSeverity());
+
+ assertThat(issue.attributes()).isEqualTo(KeyValueFormat.parse(dto.getIssueAttributes()));
+
+ assertThat(issue.creationDate()).isEqualTo(dto.getIssueCreationDate());
+ assertThat(issue.updateDate()).isEqualTo(dto.getIssueUpdateDate());
+ assertThat(issue.closeDate()).isEqualTo(dto.getIssueCloseDate());
}
}
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.issue.IssueTesting;
import org.sonar.server.issue.db.IssueDao;
import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
db.issueDao().insert(session, issue);
session.commit();
- assertThat(index.getByKey(issue.getKey())).isNotNull();
+ Issue result = index.getByKey(issue.getKey());
+ IssueTesting.assertIsEquivalent(issue, result);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void is_new_field_is_not_available() throws Exception {
+ IssueDto issue = createIssue();
+ db.issueDao().insert(session, issue);
+ session.commit();
+
+ Issue result = index.getByKey(issue.getKey());
+ result.isNew();
}
@Test(expected = NotFoundException.class)
return false;
}
- public boolean setProject(DefaultIssue issue, @Nullable String projectKey, IssueChangeContext context) {
+ public boolean setProject(DefaultIssue issue, String projectKey, IssueChangeContext context) {
if (!Objects.equal(projectKey, issue.projectKey())) {
issue.setProjectKey(projectKey);
issue.setUpdateDate(context.date());
}
public static IssueDto toDtoForInsert(DefaultIssue issue, Long componentId, Long rootComponentId, Integer ruleId, Date now) {
+ String projectKey = issue.projectKey();
return new IssueDto()
.setKee(issue.key())
.setLine(issue.line())
return this;
}
- /**
- * The project key is not always populated, that's why it's not present in the Issue API
- */
- @CheckForNull
public String projectKey() {
return projectKey;
}
- public DefaultIssue setProjectKey(@Nullable String projectKey) {
+ public DefaultIssue setProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}
return value;
}
-// @CheckForNull
-// private WebService.Param getDefinition(String key){
-// WebService.Param definition = action.param(key);
-// if (definition == null) {
-// return action.
-// }
-// }
-
@CheckForNull
@Override
public List<String> paramAsStrings(String key) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.server.ws.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;