@Test public void set_component() { IssueChangeNotification result = notification.setComponent(new ComponentDto().setDbKey("MyService").setLongName("My Service")); assertThat(result.getFieldValue("componentName")).isEqualTo("My Service"); assertThat(result.getFieldValue("componentKey")).isEqualTo("MyService"); }
public ComponentDto createForDirectory(Component directory, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(directory); res.setScope(Scopes.DIRECTORY); res.setQualifier(Qualifiers.DIRECTORY); res.setName(directory.getShortName()); res.setLongName(directory.getName()); res.setPath(directory.getName()); setParentModuleProperties(res, path); return res; }
@Test public void setters_and_getters() { ComponentDto componentDto = new ComponentDto() .setId(1L) .setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java") .setName("RequestContext.java") .setLongName("org.struts.RequestContext") .setQualifier("FIL") .setScope("FIL") .setLanguage("java") .setDescription("desc") .setPath("src/org/struts/RequestContext.java") .setCopyComponentUuid("uuid_5") .setRootUuid("uuid_3"); assertThat(componentDto.getId()).isEqualTo(1L); assertThat(componentDto.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(componentDto.getBranch()).isNull(); assertThat(componentDto.name()).isEqualTo("RequestContext.java"); assertThat(componentDto.longName()).isEqualTo("org.struts.RequestContext"); assertThat(componentDto.qualifier()).isEqualTo("FIL"); assertThat(componentDto.scope()).isEqualTo("FIL"); assertThat(componentDto.path()).isEqualTo("src/org/struts/RequestContext.java"); assertThat(componentDto.language()).isEqualTo("java"); assertThat(componentDto.description()).isEqualTo("desc"); assertThat(componentDto.getRootUuid()).isEqualTo("uuid_3"); assertThat(componentDto.getCopyResourceUuid()).isEqualTo("uuid_5"); assertThat(componentDto.isPrivate()).isFalse(); }
private ComponentDto createForProjectView(Component projectView, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(projectView); res.setScope(Scopes.FILE); res.setQualifier(Qualifiers.PROJECT); res.setName(projectView.getName()); res.setLongName(res.name()); res.setCopyComponentUuid(projectView.getProjectViewAttributes().getProjectUuid()); setRootAndParentModule(res, path); return res; }
public ComponentDto createForFile(Component file, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(file); res.setScope(Scopes.FILE); res.setQualifier(getFileQualifier(file)); res.setName(file.getShortName()); res.setLongName(file.getName()); res.setPath(file.getName()); res.setLanguage(file.getFileAttributes().getLanguageKey()); setParentModuleProperties(res, path); return res; }
private void sendIssueChangeNotification(long issueCreatedAt) { UserDto user = db.users().insertUser(); ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); RuleDefinitionDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot); underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = forClass(IssueChangeNotification.class); verify(notificationService).deliver(issueChangeNotificationCaptor.capture()); IssueChangeNotification issueChangeNotification = issueChangeNotificationCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("message")).isEqualTo(issue.message()); assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(ruleDefinitionDto.getName()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.longName()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getKey()); assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getKey()); assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName()); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(user.getLogin()); }
private ComponentDto createForSubView(Component subView, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(subView); res.setScope(Scopes.PROJECT); res.setQualifier(Qualifiers.SUBVIEW); res.setName(subView.getName()); res.setDescription(subView.getDescription()); res.setLongName(res.name()); res.setCopyComponentUuid(subView.getSubViewAttributes().getOriginalViewUuid()); setRootAndParentModule(res, path); return res; }
public static ComponentDto newSubView(ComponentDto viewOrSubView, String uuid, String key) { return newModuleDto(uuid, viewOrSubView) .setDbKey(key) .setName(key) .setLongName(key) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.SUBVIEW) .setPath(null); }
@Test public void dont_send_issues_change_notification_for_hotspot() { UserDto user = db.users().insertUser(); ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); RuleDefinitionDto ruleDefinitionDto = newRule(); DefaultIssue issue = prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); verify(notificationService, never()).deliver(any()); verifyStatistics(context, 0, 0, 0); }
public static ComponentDto newFileDto(ComponentDto module, @Nullable ComponentDto directory, String fileUuid) { String filename = "NAME_" + fileUuid; String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename; return newChildComponent(fileUuid, module, directory == null ? module : directory) .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) .setLanguage("xoo"); }
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) { String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/"; return newChildComponent(uuid, module, module) .setDbKey(generateKey(key, module)) .setName(path) .setLongName(path) .setPath(path) .setScope(Scopes.DIRECTORY) .setQualifier(Qualifiers.DIRECTORY); }
public ComponentDto createForProject(Component project) { ComponentDto res = createBase(project); res.setScope(Scopes.PROJECT); res.setQualifier(Qualifiers.PROJECT); res.setName(project.getName()); res.setLongName(res.name()); res.setDescription(project.getDescription()); res.setProjectUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); return res; }
private ComponentDto persistComponent(ComponentDto componentDto) { ComponentDto existingComponent = existingComponentDtosByUuids.remove(componentDto.uuid()); if (existingComponent == null) { dbClient.componentDao().insert(dbSession, componentDto); return componentDto; } Optional<ComponentUpdateDto> update = compareForUpdate(existingComponent, componentDto); if (update.isPresent()) { ComponentUpdateDto updateDto = update.get(); dbClient.componentDao().update(dbSession, updateDto); // update the fields in memory in order the PathAwareVisitor.Path // to be up-to-date existingComponent.setDbKey(updateDto.getBKey()); existingComponent.setCopyComponentUuid(updateDto.getBCopyComponentUuid()); existingComponent.setDescription(updateDto.getBDescription()); existingComponent.setEnabled(updateDto.isBEnabled()); existingComponent.setUuidPath(updateDto.getBUuidPath()); existingComponent.setLanguage(updateDto.getBLanguage()); existingComponent.setLongName(updateDto.getBLongName()); existingComponent.setModuleUuid(updateDto.getBModuleUuid()); existingComponent.setModuleUuidPath(updateDto.getBModuleUuidPath()); existingComponent.setName(updateDto.getBName()); existingComponent.setPath(updateDto.getBPath()); // We don't have a b_scope. The applyBChangesForRootComponentUuid query is using a case ... when to infer scope from the qualifier existingComponent.setScope(componentDto.scope()); existingComponent.setQualifier(updateDto.getBQualifier()); } return existingComponent; }
private ComponentDto createForView(Component view) { ComponentDto res = createBase(view); res.setScope(Scopes.PROJECT); res.setQualifier(view.getViewAttributes().getType().getQualifier()); res.setName(view.getName()); res.setDescription(view.getDescription()); res.setLongName(res.name()); res.setProjectUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); return res; }
public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) { return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject) .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR) .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject)) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setPath("module") .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) .setLanguage(null); }
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { checkNotNull(project.getId(), "The project need to be persisted before creating this technical project."); return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) .setScope(Scopes.FILE) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null); }
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch()); checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch); String uuid = Uuids.create(); ComponentDto component = new ComponentDto() .setOrganizationUuid(newComponent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(ComponentDto.UUID_PATH_OF_ROOT) .setRootUuid(uuid) .setModuleUuid(null) .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR) .setProjectUuid(uuid) .setDbKey(keyWithBranch) .setName(newComponent.name()) .setLongName(newComponent.name()) .setScope(Scopes.PROJECT) .setQualifier(newComponent.qualifier()) .setPrivate(newComponent.isPrivate()) .setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(session, component); return component; }
public static ComponentDto newProjectBranch(ComponentDto project, BranchDto branchDto) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP)); checkArgument(project.getMainBranchProjectUuid() == null); String branchName = branchDto.getKey(); String branchSeparator = branchDto.getBranchType() == PULL_REQUEST ? PULL_REQUEST_SEPARATOR : BRANCH_KEY_SEPARATOR; String uuid = branchDto.getUuid(); return new ComponentDto() .setUuid(uuid) .setOrganizationUuid(project.getOrganizationUuid()) .setUuidPath(UUID_PATH_OF_ROOT) .setProjectUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) // name of the branch is not mandatory on the main branch .setDbKey(branchName != null ? project.getDbKey() + branchSeparator + branchName : project.getKey()) .setMainBranchProjectUuid(project.uuid()) .setName(project.name()) .setLongName(project.longName()) .setDescription(project.description()) .setScope(project.scope()) .setQualifier(project.qualifier()) .setPath(null) .setLanguage(null) .setEnabled(true) .setPrivate(project.isPrivate()); } }
private static ComponentDto newProjectDto(String organizationUuid, String uuid, boolean isPrivate) { return new ComponentDto() .setOrganizationUuid(organizationUuid) .setUuid(uuid) .setUuidPath(UUID_PATH_OF_ROOT) .setProjectUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) .setDbKey("KEY_" + uuid) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setDescription("DESCRIPTION_" + uuid) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null) .setEnabled(true) .setPrivate(isPrivate); }
@Test public void update_view_name_and_longName() { ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now); persistComponents(viewDto); treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build()); underTest.execute(new TestComputationStepContext()); // commit functional transaction -> copies B-fields to A-fields dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), viewDto.uuid()); dbTester.commit(); assertRowsCountInTableProjects(1); ComponentDto newViewDto = getComponentFromDb(VIEW_KEY); assertDtoIsView(newViewDto); }