@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); } }
private Collection<? extends DefaultIssue> migrateIssuesToTheRoot(List<DefaultIssue> issuesOnModule, String modulePath) { for (DefaultIssue i : issuesOnModule) { // changes the issue's component uuid, add a change and set issue as changed to enforce it is persisted to DB IssueChangeContext context = IssueChangeContext.createUser(new Date(analysisMetadataHolder.getAnalysisDate()), null); if (StringUtils.isNotBlank(modulePath)) { issueUpdater.setMessage(i, "[" + modulePath + "] " + i.getMessage(), context); } issueUpdater.setIssueMoved(i, component.getUuid(), context); // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only i.setComponentKey(component.getKey()); i.setModuleUuid(null); i.setModuleUuidPath(null); } return issuesOnModule; } }
@Test public void onIssue_update_component_and_module_fields_to_component_and_flag_issue_has_changed() { MovedFilesRepository.OriginalFile originalFile = new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key"); DefaultIssue issue = mockIssue(originalFile.getUuid()); when(movedFilesRepository.getOriginalFile(FILE)) .thenReturn(Optional.of(originalFile)); underTest.onIssue(FILE, issue); verify(issue).setComponentUuid(FILE.getUuid()); verify(issue).setComponentKey(FILE.getKey()); verify(issue).setModuleUuid(null); verify(issue).setModuleUuidPath(null); verify(issue).setChanged(true); ArgumentCaptor<IssueChangeContext> issueChangeContextCaptor = ArgumentCaptor.forClass(IssueChangeContext.class); verify(issue).setFieldChange(issueChangeContextCaptor.capture(), eq("file"), eq(originalFile.getUuid()), eq(FILE.getUuid())); assertThat(issueChangeContextCaptor.getValue().date()).isEqualTo(new Date(ANALYSIS_DATE)); assertThat(issueChangeContextCaptor.getValue().userUuid()).isNull(); assertThat(issueChangeContextCaptor.getValue().scan()).isFalse(); }
@Test public void set_issue() { UserDto assignee = newUserDto(); DefaultIssue issue = new DefaultIssue() .setKey("ABCD") .setAssigneeUuid(assignee.getUuid()) .setMessage("Remove this useless method") .setComponentKey("MyService") .setCurrentChange(new FieldDiffs().setDiff("resolution", "FALSE-POSITIVE", "FIXED")); IssueChangeNotification result = notification.setIssue(issue).setAssignee(assignee); assertThat(result.getFieldValue("key")).isEqualTo("ABCD"); assertThat(result.getFieldValue("message")).isEqualTo("Remove this useless method"); assertThat(result.getFieldValue("old.resolution")).isEqualTo("FALSE-POSITIVE"); assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED"); assertThat(result.getFieldValue("assignee")).isEqualTo(assignee.getLogin()); }
@Test public void should_get_all_issues() { DefaultIssue issueOnModule = new DefaultIssue().setKey("1").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core"); DefaultIssue issueInModule = new DefaultIssue().setKey("2").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action"); DefaultIssue resolvedIssueInModule = new DefaultIssue().setKey("3").setRuleKey(SQUID_RULE_KEY).setComponentKey("org.apache:struts-core:Action") .setResolution(Issue.RESOLUTION_FIXED); DefaultIssue issueOnRoot = new DefaultIssue().setKey("4").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts"); DefaultIssue issueInRoot = new DefaultIssue().setKey("5").setRuleKey(SQUID_RULE_KEY).setSeverity(Severity.CRITICAL).setComponentKey("org.apache:struts:FileInRoot"); when(cache.all()).thenReturn(Arrays.<TrackedIssue>asList( toTrackedIssue(issueOnRoot), toTrackedIssue(issueInRoot), toTrackedIssue(issueOnModule), toTrackedIssue(issueInModule), toTrackedIssue(resolvedIssueInModule) )); // unresolved issues List<Issue> issues = Lists.newArrayList(projectIssues.issues()); assertThat(issues).containsOnly(issueOnRoot, issueInRoot, issueInModule, issueOnModule); List<Issue> resolvedIssues = Lists.newArrayList(projectIssues.resolvedIssues()); assertThat(resolvedIssues).containsOnly(resolvedIssueInModule); }
private DefaultIssue init(DefaultIssue issue) { issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setComponentUuid(component.getUuid()); issue.setComponentKey(component.getKey()); issue.setProjectUuid(treeRootHolder.getRoot().getUuid()); issue.setProjectKey(treeRootHolder.getRoot().getKey()); return issue; }
@Test public void set_issue_with_current_change_having_no_old_value() { DefaultIssue issue = new DefaultIssue() .setKey("ABCD") .setAssigneeUuid("simon") .setMessage("Remove this useless method") .setComponentKey("MyService"); IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", null, "FIXED"))); assertThat(result.getFieldValue("old.resolution")).isNull(); assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED"); result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", "", "FIXED"))); assertThat(result.getFieldValue("old.resolution")).isNull(); assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED"); }
@Test public void test_setters_and_getters() throws Exception { issue.setKey("ABCD") .setComponentKey("org.sample.Sample") .setProjectKey("Sample") .setRuleKey(RuleKey.of("squid", "S100"))
@Test public void set_issue_with_current_change_having_no_new_value() { DefaultIssue issue = new DefaultIssue() .setKey("ABCD") .setAssigneeUuid("simon") .setMessage("Remove this useless method") .setComponentKey("MyService"); IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", null))); assertThat(result.getFieldValue("old.assignee")).isEqualTo("john"); assertThat(result.getFieldValue("new.assignee")).isNull(); result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("assignee", "john", ""))); assertThat(result.getFieldValue("old.assignee")).isEqualTo("john"); assertThat(result.getFieldValue("new.assignee")).isNull(); }
@Test public void severity_changed_by_user_should_be_kept() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setComponentKey("struts:org.apache.struts.Action") .setNew(false) .setStatus(STATUS_OPEN); // Changed by scan issue.setSeverity(Severity.BLOCKER); issue.setManualSeverity(false); // Issue as seen and changed by end-user IssueDto dbIssue = new IssueDto() .setKee("ABCDE") .setStatus(STATUS_OPEN) .setSeverity(Severity.INFO) .setManualSeverity(true); new UpdateConflictResolver().mergeFields(dbIssue, issue); assertThat(issue.severity()).isEqualTo(Severity.INFO); assertThat(issue.manualSeverity()).isTrue(); } }
.setKey("ABCDE") .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setComponentKey("struts:org.apache.struts.Action") .setNew(false);
raw.setComponentKey(base.componentKey()); raw.setModuleUuid(base.moduleUuid()); raw.setModuleUuidPath(base.moduleUuidPath());
issue.setAssigneeUuid(assigneeUuid); issue.setAttributes(KeyValueFormat.parse(MoreObjects.firstNonNull(issueAttributes, ""))); issue.setComponentKey(componentKey); issue.setComponentUuid(componentUuid); issue.setModuleUuid(moduleUuid);
.setComponentKey("struts:Action") .setProjectKey("struts");
@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.getPublicKey()); issue.setModuleUuid(null); issue.setModuleUuidPath(null); } }
private DefaultIssue init(DefaultIssue issue) { issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setComponentUuid(component.getUuid()); issue.setComponentKey(component.getPublicKey()); issue.setProjectUuid(treeRootHolder.getRoot().getUuid()); issue.setProjectKey(treeRootHolder.getRoot().getPublicKey()); return issue; }
public void mergeExistingOpenIssue(DefaultIssue raw, DefaultIssue base) { raw.setKey(base.key()); raw.setNew(false); copyFields(raw, base); if (base.manualSeverity()) { raw.setManualSeverity(true); raw.setSeverity(base.severity()); } else { updater.setPastSeverity(raw, base.severity(), changeContext); } // set component/module related fields from base in case current component has been moved // (in which case base issue belongs to original file and raw issue to component) raw.setComponentUuid(base.componentUuid()); raw.setComponentKey(base.componentKey()); raw.setModuleUuid(base.moduleUuid()); raw.setModuleUuidPath(base.moduleUuidPath()); // fields coming from raw updater.setPastLine(raw, base.getLine()); updater.setPastLocations(raw, base.getLocations()); updater.setPastMessage(raw, base.getMessage(), changeContext); updater.setPastGap(raw, base.gap(), changeContext); updater.setPastEffort(raw, base.effort(), changeContext); }
issue.setAssignee(assignee); issue.setAttributes(KeyValueFormat.parse(MoreObjects.firstNonNull(issueAttributes, ""))); issue.setComponentKey(componentKey); issue.setComponentUuid(componentUuid); issue.setModuleUuid(moduleUuid);