@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 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(); }
@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)); } }
@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); } }