All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.model.structure.StructureService.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.structure

import net.nemerosa.ontrack.common.Document
import net.nemerosa.ontrack.model.Ack
import net.nemerosa.ontrack.model.pagination.PaginatedList
import org.springframework.security.access.AccessDeniedException
import java.util.*
import java.util.function.BiFunction
import java.util.function.Predicate

interface StructureService {

    val projectStatusViews: List

    val projectStatusViewsForFavourites: List

    val projectFavourites: List

    val projectList: List

    // Projects

    fun newProject(project: Project): Project

    fun getProject(projectId: ID): Project

    fun saveProject(project: Project)

    fun disableProject(project: Project): Project

    fun enableProject(project: Project): Project

    fun deleteProject(projectId: ID): Ack

    // Branches

    fun getBranch(branchId: ID): Branch

    fun getBranchesForProject(projectId: ID): List

    fun newBranch(branch: Branch): Branch

    fun getBranchStatusViews(projectId: ID): List

    fun getBranchStatusView(branch: Branch): BranchStatusView

    fun saveBranch(branch: Branch)

    fun disableBranch(branch: Branch): Branch

    fun enableBranch(branch: Branch): Branch

    fun deleteBranch(branchId: ID): Ack

    // Builds

    fun newBuild(build: Build): Build

    fun saveBuild(build: Build): Build

    fun getBuild(buildId: ID): Build

    // TODO Replace by Build?
    fun findBuildByName(project: String, branch: String, build: String): Optional

    fun getEarliestPromotionsAfterBuild(build: Build): BranchStatusView

    /**
     * Finds a build on a branch whose name is the closest. It assumes that build names
     * are in a numeric format.
     */
    // TODO Replace by Build?
    fun findBuildAfterUsingNumericForm(id: ID, buildName: String): Optional

    /**
     * Gets an aggregated view of a build, with its promotion runs, validation stamps and decorations.
     */
    fun getBuildView(build: Build, withDecorations: Boolean): BuildView

    fun getLastBuildForBranch(branch: Branch): Build?

    /**
     * Gets the number of builds for a branch.
     */
    fun getBuildCount(branch: Branch): Int

    fun deleteBuild(buildId: ID): Ack

    // TODO Replace by Build?
    fun getPreviousBuild(buildId: ID): Optional

    // TODO Replace by Build?
    fun getNextBuild(buildId: ID): Optional

    /**
     * Build links
     */

    fun addBuildLink(fromBuild: Build, toBuild: Build)

    fun deleteBuildLink(fromBuild: Build, toBuild: Build)

    fun getBuildLinksFrom(build: Build): List

    /**
     * Gets the builds which use the given one.
     *
     * @param build  Source build
     * @param offset Offset for pagination
     * @param size   Page size for pagination
     * @param filter Optional filter on the builds
     * @return List of builds which use the given one
     */
    fun getBuildsUsing(build: Build, offset: Int, size: Int, filter: (Build) -> Boolean = { true }): PaginatedList


    @Deprecated("Use {@link #getBuildsUsing(Build, int, int)} instead")
    fun getBuildLinksTo(build: Build): List

    fun searchBuildsLinkedTo(projectName: String, buildPattern: String): List

    fun editBuildLinks(build: Build, form: BuildLinkForm)

    fun isLinkedFrom(build: Build, project: String, buildPattern: String): Boolean

    fun isLinkedTo(build: Build, project: String, buildPattern: String): Boolean

    /**
     * Looks for the first build which matches a given predicate.
     *
     * @param branchId       Branch to look builds into
     * @param buildPredicate Predicate for a match
     * @param sortDirection  Build search direction
     * @return Build if found, empty otherwise
     */
    // TODO Replace by Build?
    fun findBuild(branchId: ID, buildPredicate: Predicate, sortDirection: BuildSortDirection): Optional

    // TODO Replace by Build?
    fun getLastBuild(branchId: ID): Optional

    fun buildSearch(projectId: ID, form: BuildSearchForm): List

    fun getValidationStampRunViewsForBuild(build: Build): List

    // Promotion levels

    fun getPromotionLevelListForBranch(branchId: ID): List

    fun newPromotionLevel(promotionLevel: PromotionLevel): PromotionLevel

    fun getPromotionLevel(promotionLevelId: ID): PromotionLevel

    fun getPromotionLevelImage(promotionLevelId: ID): Document

    fun setPromotionLevelImage(promotionLevelId: ID, document: Document?)

    fun savePromotionLevel(promotionLevel: PromotionLevel)

    fun deletePromotionLevel(promotionLevelId: ID): Ack

    fun reorderPromotionLevels(branchId: ID, reordering: Reordering)

    fun newPromotionLevelFromPredefined(branch: Branch, predefinedPromotionLevel: PredefinedPromotionLevel): PromotionLevel

    fun getOrCreatePromotionLevel(branch: Branch, promotionLevelId: Int?, promotionLevelName: String?): PromotionLevel

    // Promotion runs

    fun newPromotionRun(promotionRun: PromotionRun): PromotionRun

    fun getPromotionRun(promotionRunId: ID): PromotionRun

    // TODO Replace by PromotionLevel?
    fun findPromotionLevelByName(project: String, branch: String, promotionLevel: String): Optional

    fun getPromotionRunsForBuild(buildId: ID): List

    fun getLastPromotionRunsForBuild(buildId: ID): List

    // TODO Replace by PromotionRun?
    fun getLastPromotionRunForBuildAndPromotionLevel(build: Build, promotionLevel: PromotionLevel): Optional

    fun getPromotionRunsForBuildAndPromotionLevel(build: Build, promotionLevel: PromotionLevel): List

    fun getLastPromotionRunForPromotionLevel(promotionLevel: PromotionLevel): PromotionRun?

    fun getPromotionRunView(promotionLevel: PromotionLevel): PromotionRunView

    fun deletePromotionRun(promotionRunId: ID): Ack

    // TODO Replace by PromotionRun?
    fun getEarliestPromotionRunAfterBuild(promotionLevel: PromotionLevel, build: Build): Optional

    fun getPromotionRunsForPromotionLevel(promotionLevelId: ID): List

    /**
     * Bulk update of all promotion levels in other projects/branches and in predefined promotion levels,
     * following the model designed by the promotion level ID.
     *
     * @param promotionLevelId ID of the promotion level model
     * @return Result of the update
     */
    fun bulkUpdatePromotionLevels(promotionLevelId: ID): Ack

    // Validation stamps

    fun getValidationStampListForBranch(branchId: ID): List

    fun newValidationStamp(validationStamp: ValidationStamp): ValidationStamp

    fun getValidationStamp(validationStampId: ID): ValidationStamp

    // TODO Replace by ValidationStamp?
    fun findValidationStampByName(project: String, branch: String, validationStamp: String): Optional

    fun getValidationStampImage(validationStampId: ID): Document

    fun setValidationStampImage(validationStampId: ID, document: Document?)

    fun saveValidationStamp(validationStamp: ValidationStamp)

    fun deleteValidationStamp(validationStampId: ID): Ack

    fun reorderValidationStamps(branchId: ID, reordering: Reordering)

    fun newValidationStampFromPredefined(branch: Branch, stamp: PredefinedValidationStamp): ValidationStamp

    fun getOrCreateValidationStamp(branch: Branch, validationStampName: String): ValidationStamp

    /**
     * Bulk update of all validation stamps in other projects/branches and in predefined validation stamps,
     * following the model designed by the validation stamp ID.
     *
     * @param validationStampId ID of the validation stamp model
     * @return Result of the update
     */
    fun bulkUpdateValidationStamps(validationStampId: ID): Ack

    // Validation runs

    fun newValidationRun(build: Build, validationRunRequest: ValidationRunRequest): ValidationRun

    fun getValidationRun(validationRunId: ID): ValidationRun


    @Deprecated("Use {@link #getValidationRunsForBuild(ID, int, int)} instead.")
    fun getValidationRunsForBuild(buildId: ID): List

    /**
     * Gets the list of validation runs for a build.
     *
     * @param buildId ID of the build
     * @param offset  Offset in the list
     * @param count   Maximum number of elements to return
     * @return List of validation runs
     */
    fun getValidationRunsForBuild(buildId: ID, offset: Int, count: Int): List

    /**
     * Gets the number of validation runs for a build.
     *
     * @param buildId ID of the build
     * @return Number of validation runs
     */
    fun getValidationRunsCountForBuild(buildId: ID): Int


    @Deprecated("Use {@link #getValidationRunsForBuildAndValidationStamp(ID, ID, int, int)} instead.")
    fun getValidationRunsForBuildAndValidationStamp(buildId: ID, validationStampId: ID): List

    /**
     * Gets the list of validation runs for a build and a validation stamp.
     *
     * @param buildId           ID of the build
     * @param validationStampId ID of the validation stamp
     * @param offset            Offset in the list
     * @param count             Maximum number of elemnts to return
     * @return List of validation runs
     */
    fun getValidationRunsForBuildAndValidationStamp(buildId: ID, validationStampId: ID, offset: Int, count: Int): List

    fun getValidationRunsForValidationStamp(validationStampId: ID, offset: Int, count: Int): List

    fun newValidationRunStatus(validationRun: ValidationRun, runStatus: ValidationRunStatus): ValidationRun

    /**
     * Gets the total number of validation runs for a build and a validation stamp
     *
     * @param buildId           ID of the build
     * @param validationStampId ID of the validation stamp
     * @return Number of validation runs for the validation stamp
     */
    fun getValidationRunsCountForBuildAndValidationStamp(buildId: ID, validationStampId: ID): Int

    /**
     * Gets the total number of validation runs for a validation stamp
     *
     * @param validationStampId ID of the validation stamp
     * @return Number of validation runs for the validation stamp
     */
    fun getValidationRunsCountForValidationStamp(validationStampId: ID): Int

    // Entity searches by name

    // TODO Replace by Project?
    fun findProjectByName(project: String): Optional

    /**
     * Gets the project by its name if authorized to access it. If it does exist, but the user is
     * not authorized to see it, throws an [AccessDeniedException]
     *
     * @param project Name of the project to look for
     * @return Project if it exists and is authorized, or null if if does not exist
     * @throws AccessDeniedException If the project does exist but the user has no access to it
     */
    fun findProjectByNameIfAuthorized(project: String): Project?

    // TODO Replace by Branch?
    fun findBranchByName(project: String, branch: String): Optional

    fun entityLoader(): BiFunction

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy