/** * 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()); }
/** * 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 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); }
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()); }
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; } }
/** * 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 persistComponent(ComponentDto componentDto) { ComponentDto existingComponent = existingComponentDtosByKey.remove(componentDto.getDbKey()); 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.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()); 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; }
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; }