private static String componentIdOf(DefaultIssue issue, DbIssues.Location location) { if (location.hasComponentId()) { return StringUtils.defaultIfEmpty(location.getComponentId(), issue.componentUuid()); } return issue.componentUuid(); } }
public boolean setIssueMoved(DefaultIssue issue, String newComponentUuid, IssueChangeContext context) { if (!Objects.equals(newComponentUuid, issue.componentUuid())) { issue.setFieldChange(context, FILE, issue.componentUuid(), newComponentUuid); issue.setComponentUuid(newComponentUuid); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; } return false; }
private DefaultIssue mockIssue(String fileUuid) { DefaultIssue issue = mock(DefaultIssue.class); when(issue.componentUuid()).thenReturn(fileUuid); return issue; } }
ComponentDto component(DbSession session, DefaultIssue issue) { return getDbClient().componentDao().selectOrFailByUuid(session, issue.componentUuid()); }
/** * Same as {@link #saveIssue(DbSession, DefaultIssue, IssueChangeContext, String)} but populates the specified * {@link SearchResponseData} with the DTOs (rule and components) retrieved from DB to save the issue. */ public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSession, DefaultIssue issue, IssueChangeContext context, @Nullable String comment, boolean refreshMeasures) { Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey()); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid()); ComponentDto component = getComponent(dbSession, issue, issue.componentUuid()); IssueDto issueDto = doSaveIssue(dbSession, issue, context, comment, rule, project, component); SearchResponseData result = new SearchResponseData(issueDto); rule.ifPresent(r -> result.addRules(singletonList(r))); result.addComponents(singleton(project)); result.addComponents(singleton(component)); if (refreshMeasures) { List<DefaultIssue> changedIssues = result.getIssues().stream().map(IssueDto::toDefaultIssue).collect(MoreCollectors.toList(result.getIssues().size())); issueChangePostProcessor.process(dbSession, changedIssues, singleton(component)); } return result; }
@Override public void onIssue(Component component, DefaultIssue issue) { if (component.getType() != Component.Type.FILE || component.getUuid().equals(issue.componentUuid())) { return; } Optional<OriginalFile> originalFileOptional = movedFilesRepository.getOriginalFile(component); checkState(originalFileOptional.isPresent(), "Issue %s for component %s has a different component key but no original file exist in MovedFilesRepository", issue, component); OriginalFile originalFile = originalFileOptional.get(); checkState(originalFile.getUuid().equals(issue.componentUuid()), "Issue %s doesn't belong to file %s registered as original file of current file %s", issue, originalFile.getUuid(), component); // changes the issue's component uuid, add a change and set issue as changed to enforce it is persisted to DB issueUpdater.setIssueMoved(issue, component.getUuid(), IssueChangeContext.createUser(new Date(analysisMetadataHolder.getAnalysisDate()), null)); // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only issue.setComponentKey(component.getKey()); issue.setModuleUuid(null); issue.setModuleUuidPath(null); } }
public IssueDto saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) { Optional<RuleDefinitionDto> rule = getRuleByKey(session, issue.getRuleKey()); ComponentDto project = getComponent(session, issue, issue.projectUuid()); ComponentDto component = getComponent(session, issue, issue.componentUuid()); return doSaveIssue(session, issue, context, comment, rule, project, component); }
@Test public void onIssue_does_not_alter_issue_if_component_file_but_issue_has_the_same_component_uuid() { DefaultIssue issue = mockIssue(FILE_UUID); underTest.onIssue(FILE, issue); verify(issue).componentUuid(); verifyNoMoreInteractions(issue); }
private Consumer<DefaultIssue> sendNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) { return issue -> { if (bulkChangeData.sendNotification && issue.type() != RuleType.SECURITY_HOTSPOT) { notificationService.scheduleForSending(new IssueChangeNotification() .setIssue(issue) .setAssignee(userDtoByUuid.get(issue.assignee())) .setChangeAuthor(author) .setRuleName(bulkChangeData.rulesByKey.get(issue.ruleKey()).getName()) .setProject(bulkChangeData.projectsByUuid.get(issue.projectUuid())) .setComponent(bulkChangeData.componentsByUuid.get(issue.componentUuid()))); } }; }
@Test public void setIssueMoved_has_no_effect_if_component_uuid_is_not_changed() { String componentUuid = "a"; issue.setComponentUuid(componentUuid); underTest.setIssueMoved(issue, componentUuid, context); assertThat(issue.changes()).isEmpty(); assertThat(issue.componentUuid()).isEqualTo(componentUuid); assertThat(issue.isChanged()).isFalse(); assertThat(issue.updateDate()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); }
public void add(DefaultIssue issue) { boolean isOnLeak = onLeakPredicate.test(issue); distributions.get(RULE_TYPE).increment(issue.type().name(), isOnLeak); String componentUuid = issue.componentUuid(); if (componentUuid != null) { distributions.get(COMPONENT).increment(componentUuid, isOnLeak); } RuleKey ruleKey = issue.ruleKey(); if (ruleKey != null) { distributions.get(RULE).increment(ruleKey.toString(), isOnLeak); } String assigneeUuid = issue.assignee(); if (assigneeUuid != null) { distributions.get(ASSIGNEE).increment(assigneeUuid, isOnLeak); } for (String tag : issue.tags()) { distributions.get(TAG).increment(tag, isOnLeak); } Duration effort = issue.effort(); if (effort != null) { effortStats.add(effort.toMinutes(), isOnLeak); } }
private void assertInitializedExternalIssue(DefaultIssue issue) { assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey()); assertThat(issue.componentKey()).isEqualTo(FILE.getKey()); assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid()); assertThat(issue.resolution()).isNull(); assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN); assertThat(issue.key()).isNull(); assertThat(issue.authorLogin()).isNull(); }
private void assertInitializedIssue(DefaultIssue issue) { assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey()); assertThat(issue.componentKey()).isEqualTo(FILE.getKey()); assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid()); assertThat(issue.resolution()).isNull(); assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN); assertThat(issue.key()).isNull(); assertThat(issue.authorLogin()).isNull(); assertThat(issue.effort()).isNull(); assertThat(issue.effortInMinutes()).isNull(); }
@Test public void setIssueMoved_changes_componentUuid_adds_a_change() { String oldComponentUuid = "a"; String newComponentUuid = "b"; issue.setComponentUuid(oldComponentUuid); underTest.setIssueMoved(issue, newComponentUuid, context); assertThat(issue.changes()).hasSize(1); FieldDiffs fieldDiffs = issue.changes().get(0); assertThat(fieldDiffs.creationDate()).isEqualTo(context.date()); assertThat(fieldDiffs.diffs()).hasSize(1); Map.Entry<String, FieldDiffs.Diff> entry = fieldDiffs.diffs().entrySet().iterator().next(); assertThat(entry.getKey()).isEqualTo("file"); assertThat(entry.getValue().oldValue()).isEqualTo(oldComponentUuid); assertThat(entry.getValue().newValue()).isEqualTo(newComponentUuid); assertThat(issue.componentUuid()).isEqualTo(newComponentUuid); assertThat(issue.isChanged()).isTrue(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(context.date(), Calendar.SECOND)); } }
assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle"); assertThat(issue.language()).isEqualTo("xoo"); assertThat(issue.componentUuid()).isEqualTo("CDEF"); assertThat(issue.projectUuid()).isEqualTo("GHIJ"); assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
raw.setComponentUuid(base.componentUuid()); raw.setComponentKey(base.componentKey()); raw.setModuleUuid(base.moduleUuid());
.containsEntry("AUTHOR_LOGIN", updated.authorLogin()) .containsEntry("CHECKSUM", updated.checksum()) .containsEntry("COMPONENT_UUID", issue.componentUuid()) .containsEntry("EFFORT", updated.effortInMinutes()) .containsEntry("ISSUE_ATTRIBUTES", "fox=bax")
.setIsFromHotspot(issue.isFromHotspot()) .setTags(issue.tags()) .setComponentUuid(issue.componentUuid()) .setComponentKey(issue.componentKey()) .setModuleUuid(issue.moduleUuid())
.setIsFromHotspot(issue.isFromHotspot()) .setTags(issue.tags()) .setComponentUuid(issue.componentUuid()) .setComponentKey(issue.componentKey()) .setModuleUuid(issue.moduleUuid())
public boolean setIssueMoved(DefaultIssue issue, String newComponentUuid, IssueChangeContext context) { if (!Objects.equals(newComponentUuid, issue.componentUuid())) { issue.setFieldChange(context, FILE, issue.componentUuid(), newComponentUuid); issue.setComponentUuid(newComponentUuid); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; } return false; }