import com.google.common.collect.Maps;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.BooleanUtils;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.IssueComment;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.KeyValueFormat;
import org.sonar.server.es.BaseDoc;
-public class IssueDoc extends BaseDoc implements Issue {
+public class IssueDoc extends BaseDoc {
public IssueDoc(Map<String, Object> fields) {
super(fields);
return projectUuid();
}
- @Override
public String key() {
return getField(IssueIndexDefinition.FIELD_ISSUE_KEY);
}
- @Override
- public String componentKey() {
- throw new IllegalStateException("componentKey is not available on server side");
- }
-
- @Override
public String componentUuid() {
return getField(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID);
}
return getField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH);
}
- @Override
- public String projectKey() {
- throw new IllegalStateException("projectKey is not available on server side");
- }
-
- @Override
public String projectUuid() {
return getField(IssueIndexDefinition.FIELD_ISSUE_PROJECT_UUID);
}
- @Override
public RuleKey ruleKey() {
return RuleKey.parse(getField(IssueIndexDefinition.FIELD_ISSUE_RULE_KEY));
}
- @Override
public String language() {
return getField(IssueIndexDefinition.FIELD_ISSUE_LANGUAGE);
}
- @Override
public String severity() {
return getField(IssueIndexDefinition.FIELD_ISSUE_SEVERITY);
}
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_CHECKSUM);
}
- @Override
@CheckForNull
public String message() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_MESSAGE);
}
- @Override
@CheckForNull
public Integer line() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_LINE);
}
- /**
- * @deprecated since 5.5, replaced by {@link #gap()}
- */
- @Deprecated
- @Override
- @CheckForNull
- public Double effortToFix() {
- throw new UnsupportedOperationException("effortToFix is replaced by gap");
- }
-
- @Override
- @CheckForNull
- public Double gap() {
- return getNullableField(IssueIndexDefinition.FIELD_ISSUE_GAP);
- }
-
- @Override
public String status() {
return getField(IssueIndexDefinition.FIELD_ISSUE_STATUS);
}
- @Override
@CheckForNull
public String resolution() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_RESOLUTION);
}
- /**
- * @deprecated since 5.5
- */
- @Deprecated
- @Override
- @CheckForNull
- public String reporter() {
- throw new UnsupportedOperationException("manual issue feature has been dropped");
- }
-
- @Override
@CheckForNull
public String assignee() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE);
/**
* Functional date
*/
- @Override
public Date creationDate() {
return getFieldAsDate(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT);
}
/**
* Functional date
*/
- @Override
public Date updateDate() {
return getFieldAsDate(IssueIndexDefinition.FIELD_ISSUE_FUNC_UPDATED_AT);
}
- @Override
@CheckForNull
public Date closeDate() {
return getNullableFieldAsDate(IssueIndexDefinition.FIELD_ISSUE_FUNC_CLOSED_AT);
}
- @Override
- @CheckForNull
- public String attribute(String key) {
- return attributes().get(key);
- }
-
- @Override
- public Map<String, String> attributes() {
- String data = getNullableField(IssueIndexDefinition.FIELD_ISSUE_ATTRIBUTES);
- if (data == null) {
- return Collections.emptyMap();
- } else {
- return KeyValueFormat.parse(data);
- }
- }
-
- @Override
@CheckForNull
public String authorLogin() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_AUTHOR_LOGIN);
}
- @Override
- @CheckForNull
- public String actionPlanKey() {
- // since 5.5, action plan is dropped. Kept for API compatibility
- return null;
- }
-
public RuleType type() {
return RuleType.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_TYPE));
}
- @Override
- public List<IssueComment> comments() {
- throw new IllegalStateException("Comments are not availables in index");
- }
-
- @Override
- public boolean isNew() {
- throw new IllegalStateException("isNew is only available for batch");
- }
-
- /**
- * @deprecated since 5.5, replaced by {@link #effort()}
- */
- @Override
- @CheckForNull
- @Deprecated
- public Duration debt() {
- throw new UnsupportedOperationException("debt is replaced by effort");
- }
-
- @Override
@CheckForNull
public Duration effort() {
Number effort = getNullableField(IssueIndexDefinition.FIELD_ISSUE_EFFORT);
return this;
}
- public IssueDoc setGap(@Nullable Double d) {
- setField(IssueIndexDefinition.FIELD_ISSUE_GAP, d);
- return this;
- }
-
public IssueDoc setStatus(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_STATUS, s);
return this;
return this;
}
- public Date getTechnicalUpdateDate() {
- return getFieldAsDate(IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT);
- }
-
- public IssueDoc setTechnicalUpdateDate(@Nullable Date d) {
- setField(IssueIndexDefinition.FIELD_ISSUE_TECHNICAL_UPDATED_AT, d);
- return this;
- }
-
public IssueDoc setFuncCloseDate(@Nullable Date d) {
setField(IssueIndexDefinition.FIELD_ISSUE_FUNC_CLOSED_AT, d);
return this;
}
- public IssueDoc setAttributes(@Nullable String s) {
- setField(IssueIndexDefinition.FIELD_ISSUE_ATTRIBUTES, s);
- return this;
- }
-
public IssueDoc setAuthorLogin(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_AUTHOR_LOGIN, s);
return this;
return this;
}
- @Override
@CheckForNull
- public Collection<String> tags() {
+ public Collection<String> getTags() {
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_TAGS);
}
public static final IndexType INDEX_TYPE_ISSUE = new IndexType("issues", "issue");
public static final String FIELD_ISSUE_ASSIGNEE = "assignee";
- public static final String FIELD_ISSUE_ATTRIBUTES = "attributes";
public static final String FIELD_ISSUE_AUTHOR_LOGIN = "authorLogin";
public static final String FIELD_ISSUE_COMPONENT_UUID = "component";
public static final String FIELD_ISSUE_EFFORT = "effort";
- public static final String FIELD_ISSUE_GAP = "gap";
public static final String FIELD_ISSUE_FILE_PATH = "filePath";
/**
* Functional date
public static final String FIELD_ISSUE_CHECKSUM = "checksum";
public static final String FIELD_ISSUE_TAGS = "tags";
public static final String FIELD_ISSUE_TYPE = "type";
- /**
- * Technical date
- */
- public static final String FIELD_ISSUE_TECHNICAL_UPDATED_AT = "updatedAt";
private final Configuration config;
type.requireProjectAuthorization();
type.stringFieldBuilder(FIELD_ISSUE_ASSIGNEE).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- type.stringFieldBuilder(FIELD_ISSUE_ATTRIBUTES).disableNorms().disableSearch().build();
type.stringFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().build();
type.stringFieldBuilder(FIELD_ISSUE_COMPONENT_UUID).disableNorms().build();
type.createLongField(FIELD_ISSUE_EFFORT);
- type.createDoubleField(FIELD_ISSUE_GAP);
type.stringFieldBuilder(FIELD_ISSUE_FILE_PATH).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
type.createDateTimeField(FIELD_ISSUE_FUNC_CREATED_AT);
type.createDateTimeField(FIELD_ISSUE_FUNC_UPDATED_AT);
type.createByteField(FIELD_ISSUE_SEVERITY_VALUE);
type.stringFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
type.stringFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
- type.createDateTimeField(FIELD_ISSUE_TECHNICAL_UPDATED_AT);
type.stringFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
}
}
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.CheckForNull;
// column 1
"i.kee",
"root.uuid",
- "i.updated_at",
"i.assignee",
- "i.gap",
- "i.issue_attributes",
"i.line",
"i.message",
"i.resolution",
"i.severity",
-
- // column 11
"i.manual_severity",
"i.checksum",
"i.status",
+
+ // column 11
"i.effort",
"i.author_login",
"i.issue_close_date",
"i.issue_update_date",
"r.plugin_name",
"r.plugin_rule_key",
-
- // column 21
"r.language",
"p.uuid",
"p.module_uuid_path",
+
+ // column 21
"p.path",
"p.scope",
"p.organization_uuid",
// all the fields must be present, even if value is null
doc.setKey(key);
doc.setProjectUuid(projectUuid);
- doc.setTechnicalUpdateDate(new Date(rs.getLong(3)));
- doc.setAssignee(rs.getString(4));
- doc.setGap(DatabaseUtils.getDouble(rs, 5));
- doc.setAttributes(rs.getString(6));
- doc.setLine(DatabaseUtils.getInt(rs, 7));
- doc.setMessage(rs.getString(8));
- doc.setResolution(rs.getString(9));
- doc.setSeverity(rs.getString(10));
- doc.setManualSeverity(rs.getBoolean(11));
- doc.setChecksum(rs.getString(12));
- doc.setStatus(rs.getString(13));
- doc.setEffort(getLong(rs, 14));
- doc.setAuthorLogin(rs.getString(15));
- doc.setFuncCloseDate(longToDate(getLong(rs, 16)));
- doc.setFuncCreationDate(longToDate(getLong(rs, 17)));
- doc.setFuncUpdateDate(longToDate(getLong(rs, 18)));
- String ruleRepo = rs.getString(19);
- String ruleKey = rs.getString(20);
+ doc.setAssignee(rs.getString(3));
+ doc.setLine(DatabaseUtils.getInt(rs, 4));
+ doc.setMessage(rs.getString(5));
+ doc.setResolution(rs.getString(6));
+ doc.setSeverity(rs.getString(7));
+ doc.setManualSeverity(rs.getBoolean(8));
+ doc.setChecksum(rs.getString(9));
+ doc.setStatus(rs.getString(10));
+ doc.setEffort(getLong(rs, 11));
+ doc.setAuthorLogin(rs.getString(12));
+ doc.setFuncCloseDate(longToDate(getLong(rs, 13)));
+ doc.setFuncCreationDate(longToDate(getLong(rs, 14)));
+ doc.setFuncUpdateDate(longToDate(getLong(rs, 15)));
+ String ruleRepo = rs.getString(16);
+ String ruleKey = rs.getString(17);
doc.setRuleKey(RuleKey.of(ruleRepo, ruleKey).toString());
- doc.setLanguage(rs.getString(21));
- doc.setComponentUuid(rs.getString(22));
- String moduleUuidPath = rs.getString(23);
+ doc.setLanguage(rs.getString(18));
+ doc.setComponentUuid(rs.getString(19));
+ String moduleUuidPath = rs.getString(20);
doc.setModuleUuid(extractModule(moduleUuidPath));
doc.setModuleUuidPath(moduleUuidPath);
- String scope = rs.getString(25);
- String filePath = extractFilePath(rs.getString(24), scope);
+ String scope = rs.getString(22);
+ String filePath = extractFilePath(rs.getString(21), scope);
doc.setFilePath(filePath);
doc.setDirectoryPath(extractDirPath(doc.filePath(), scope));
- doc.setOrganizationUuid(rs.getString(26));
- String tags = rs.getString(27);
+ doc.setOrganizationUuid(rs.getString(23));
+ String tags = rs.getString(24);
doc.setTags(ImmutableList.copyOf(IssueIteratorForSingleChunk.TAGS_SPLITTER.split(tags == null ? "" : tags)));
- doc.setType(RuleType.valueOf(rs.getInt(28)));
+ doc.setType(RuleType.valueOf(rs.getInt(25)));
return doc;
}
doc.setAuthorLogin("roger");
doc.setLanguage("xoo");
doc.setComponentUuid("FILE_1");
- doc.setGap(3.14);
doc.setFilePath("src/Foo.xoo");
doc.setDirectoryPath("/src");
doc.setMessage("the message");
doc.setModuleUuidPath("MODULE_1");
doc.setProjectUuid("PROJECT_1");
doc.setLine(42);
- doc.setAttributes(null);
doc.setStatus(Issue.STATUS_OPEN);
doc.setResolution(null);
doc.setSeverity(Severity.MAJOR);
doc.setFuncCreationDate(DateUtils.parseDate("2014-09-04"));
doc.setFuncUpdateDate(DateUtils.parseDate("2014-12-04"));
doc.setFuncCloseDate(null);
- doc.setTechnicalUpdateDate(DateUtils.parseDate("2014-12-04"));
return doc;
}
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.es.SearchOptions;
-import org.sonar.server.es.SearchResult;
-import org.sonar.server.issue.index.IssueDoc;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
-import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
tester.get(IssueIndexer.class).index(asList(issue.getKey()));
return issue;
}
-
- private Issue getIssueByKey(String key) {
- SearchResult<IssueDoc> result = issueIndex.search(IssueQuery.builder().issueKeys(newArrayList(key)).build(), new SearchOptions());
- return result.getDocs().get(0);
- }
}
*/
package org.sonar.server.issue.index;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import java.util.Date;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
.setEffort(100L);
indexIssues(issue);
- Issue loaded = getByKey(issue.key());
+ IssueDoc loaded = getByKey(issue.key());
assertThat(loaded).isNotNull();
assertThat(loaded.key()).isEqualTo("ISSUE1");
assertThat(loaded.effort()).isEqualTo(Duration.create(100L));
}
- private Issue getByKey(String key) {
+ private IssueDoc getByKey(String key) {
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().issueKeys(newArrayList(key)).build(), new SearchOptions());
return result.getDocs().get(0);
}
- @Test
- public void get_by_key_with_attributes() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
- ComponentDto file = newFileDto(project, null);
- IssueDoc issue = newDoc("ISSUE1", file).setAttributes((KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234"))));
- indexIssues(issue);
-
- Issue result = getByKey(issue.key());
- assertThat(result.attribute("jira-issue-key")).isEqualTo("SONAR-1234");
- }
-
- @Test(expected = IllegalStateException.class)
- public void comments_field_is_not_available() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
- ComponentDto file = newFileDto(project, null);
- IssueDoc issue = newDoc("ISSUE1", file);
- indexIssues(issue);
-
- Issue result = getByKey(issue.key());
- result.comments();
- }
-
- @Test(expected = IllegalStateException.class)
- public void is_new_field_is_not_available() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
- ComponentDto file = newFileDto(project, null);
- IssueDoc issue = newDoc("ISSUE1", file);
- indexIssues(issue);
-
- Issue result = getByKey(issue.key());
- result.isNew();
- }
-
@Test
public void filter_by_keys() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.NoSuchElementException;
import org.apache.commons.lang.StringUtils;
assertThat(doc.organizationUuid()).isEqualTo(org.getUuid());
// functional date
assertThat(doc.updateDate().getTime()).isEqualTo(issue.getIssueUpdateTime());
- // technical date
- assertThat(doc.getTechnicalUpdateDate().getTime()).isEqualTo(issue.getUpdatedAt());
}
@Test
public void index_issue_without_parent_should_work() {
IssueDoc issueDoc = new IssueDoc();
issueDoc.setKey("key");
- issueDoc.setTechnicalUpdateDate(new Date());
issueDoc.setProjectUuid("non-exitsing-parent");
new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbTester.getDbClient()))
.index(asList(issueDoc).iterator());
assertThat(issue.modulePath()).isEqualTo(".PROJECT1.");
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
- assertThat(issue.tags()).containsOnly("tag1", "tag2", "tag3");
+ assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
- assertThat(issue.gap()).isEqualTo(2d);
- assertThat(issue.attribute("JIRA")).isEqualTo("http://jira.com");
assertThat(issue.type().getDbConstant()).isEqualTo(2);
}
assertThat(issue.modulePath()).isEqualTo(".PROJECT1.");
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
- assertThat(issue.tags()).containsOnly("tag1", "tag2", "tag3");
+ assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);
assertThat(issue.modulePath()).isEqualTo(".PROJECT1.MODULE1.");
assertThat(issue.directoryPath()).isNull();
assertThat(issue.filePath()).isNull();
- assertThat(issue.tags()).containsOnly("tag1", "tag2", "tag3");
+ assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(2);
assertThat(issue.modulePath()).isEqualTo(".PROJECT1.");
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
- assertThat(issue.tags()).isEmpty();
+ assertThat(issue.getTags()).isEmpty();
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);
assertThat(issue.modulePath()).isEqualTo(".PROJECT1.MODULE1.");
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java");
- assertThat(issue.tags()).isEmpty();
+ assertThat(issue.getTags()).isEmpty();
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);
}