private static ComponentDto nonExistentComponentDot() { return new ComponentDto().setUuid("does_not_exist").setProjectUuid("unknown"); }
/** * Applies to a node of type either DIRECTORY or FILE */ private static void setParentModuleProperties(ComponentDto componentDto, PathAwareVisitor.Path<ComponentDtoHolder> path) { componentDto.setProjectUuid(path.root().getDto().uuid()); ComponentDto parentModule = from(path.getCurrentPath()) .filter(ParentModulePathElement.INSTANCE) .first() .get() .getElement().getDto(); componentDto.setUuidPath(formatUuidPathFromParent(path.parent().getDto())); componentDto.setRootUuid(parentModule.uuid()); componentDto.setModuleUuid(parentModule.uuid()); componentDto.setModuleUuidPath(parentModule.moduleUuidPath()); }
db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(), db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(), db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(), db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(), db.components().insertComponent(newPrivateProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(), };
/** * Applies to a node of type either MODULE, SUBVIEW, PROJECT_VIEW */ private void setRootAndParentModule(ComponentDto res, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto rootDto = path.root().getDto(); res.setRootUuid(rootDto.uuid()); res.setProjectUuid(rootDto.uuid()); ComponentDto parentModule = path.parent().getDto(); res.setUuidPath(formatUuidPathFromParent(parentModule)); res.setModuleUuid(parentModule.uuid()); res.setModuleUuidPath(parentModule.moduleUuidPath() + res.uuid() + UUID_PATH_SEPARATOR); } }
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 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; }
private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); dbClient.componentDao().insert(db.getSession(), componentDto); return componentDto; }
@Test public void fail_if_project_of_module_does_not_exist() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project).setProjectUuid("unknown")); expectedException.expect(IllegalStateException.class); expectedException.expectMessage(format("Project uuid of component uuid '%s' does not exist", module.uuid())); call(ws.newRequest().setParam(PARAM_PROJECT_KEY, module.getDbKey())); }
private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() .setOrganizationUuid("org1") .setDbKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid); dbClient.componentDao().insert(db.getSession(), componentDto); return componentDto; }
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 newChildComponent(String uuid, ComponentDto moduleOrProject, ComponentDto parent) { checkArgument(moduleOrProject.isPrivate() == parent.isPrivate(), "private flag inconsistent between moduleOrProject (%s) and parent (%s)", moduleOrProject.isPrivate(), parent.isPrivate()); return new ComponentDto() .setOrganizationUuid(parent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(formatUuidPathFromParent(parent)) .setProjectUuid(moduleOrProject.projectUuid()) .setRootUuid(moduleOrProject.uuid()) .setModuleUuid(moduleOrProject.uuid()) .setModuleUuidPath(moduleOrProject.moduleUuidPath()) .setMainBranchProjectUuid(moduleOrProject.getMainBranchProjectUuid()) .setCreatedAt(new Date()) .setEnabled(true) .setPrivate(moduleOrProject.isPrivate()); }
.setUuidPath(uuid + ".") .setRootUuid(uuid) .setProjectUuid(uuid) .setScope(scope) .setModuleUuid(moduleUuid)
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); }
/** * Applies to a node of type either DIRECTORY or FILE */ private static void setParentModuleProperties(ComponentDto componentDto, PathAwareVisitor.Path<ComponentDtoHolder> path) { componentDto.setProjectUuid(path.root().getDto().uuid()); ComponentDto parentModule = from(path.getCurrentPath()) .filter(ParentModulePathElement.INSTANCE) .first() .get() .getElement().getDto(); componentDto.setUuidPath(formatUuidPathFromParent(path.parent().getDto())); componentDto.setRootUuid(parentModule.uuid()); componentDto.setModuleUuid(parentModule.uuid()); componentDto.setModuleUuidPath(parentModule.moduleUuidPath()); }
private ComponentDto insertIntoProjectsTable(DbSession dbSession, String branchUuid) { String mainBranchProjectUuid = analysisMetadataHolder.getProject().getUuid(); ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, mainBranchProjectUuid); ComponentDto branchDto = project.copy(); branchDto.setUuid(branchUuid); branchDto.setProjectUuid(branchUuid); branchDto.setRootUuid(branchUuid); branchDto.setUuidPath(UUID_PATH_OF_ROOT); branchDto.setModuleUuidPath(UUID_PATH_SEPARATOR + branchUuid + UUID_PATH_SEPARATOR); branchDto.setMainBranchProjectUuid(mainBranchProjectUuid); branchDto.setDbKey(treeRootHolder.getRoot().getKey()); branchDto.setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(dbSession, branchDto); return branchDto; } }
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; }
/** * Applies to a node of type either MODULE, SUBVIEW, PROJECT_VIEW */ private void setRootAndParentModule(ComponentDto res, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto rootDto = path.root().getDto(); res.setRootUuid(rootDto.uuid()); res.setProjectUuid(rootDto.uuid()); ComponentDto parentModule = path.parent().getDto(); res.setUuidPath(formatUuidPathFromParent(parentModule)); res.setModuleUuid(parentModule.uuid()); res.setModuleUuidPath(parentModule.moduleUuidPath() + res.uuid() + UUID_PATH_SEPARATOR); } }
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; }
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { checkBranchFormat(newComponent.qualifier(), newComponent.branch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch()); 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) .setDeprecatedKey(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; }