Class PlanManagerImpl

java.lang.Object
com.atlassian.bamboo.plan.PlanManagerImpl
All Implemented Interfaces:
PlanManager

public class PlanManagerImpl extends Object implements PlanManager
  • Constructor Details

    • PlanManagerImpl

      public PlanManagerImpl(@NotNull @NotNull PlanDao planDao, @NotNull @NotNull BambooLicenseManager bambooLicenseManager, @NotNull @NotNull com.atlassian.event.api.EventPublisher eventPublisher, @NotNull @NotNull ProjectManager projectManager, @NotNull @NotNull PlanScheduler planScheduler)
  • Method Details

    • getPlanById

      @Nullable public @Nullable Plan getPlanById(long id) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its id
      Specified by:
      getPlanById in interface PlanManager
      Parameters:
      id - of the plan
      Returns:
      plan with the given id, null if it doesn't exist
      Throws:
      IncorrectPlanTypeException - if plan cannot be found
    • getPlanById

      @Nullable public <T extends Plan> T getPlanById(long id, Class<T> planType) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its id and Class
      Specified by:
      getPlanById in interface PlanManager
      Parameters:
      id - of the plan
      planType - - the type of the plan to retrieve
      Returns:
      plan with the given id, if found AND is of the correct type.
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type
    • getPlanByOid

      @Nullable public <T extends Plan> T getPlanByOid(BambooEntityOid oid, Class<T> planType) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its oid and Class
      Specified by:
      getPlanByOid in interface PlanManager
      Parameters:
      oid - of the plan
      planType - - the type of the plan to retrieve
      Returns:
      plan with the given oid, if found AND is of the correct type.
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type
    • getPlanByKey

      @Nullable public @Nullable Plan getPlanByKey(@NotNull @NotNull String planKey) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its planKey
      Specified by:
      getPlanByKey in interface PlanManager
      Parameters:
      planKey - of the plan to find
      Returns:
      plan by the id if found, otherwise null
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type (should never happen)
    • getPlanByKey

      @Nullable public <T extends Plan> T getPlanByKey(@NotNull @NotNull String planKey, Class<T> planType) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its planKey and Class
      Specified by:
      getPlanByKey in interface PlanManager
      Parameters:
      planKey - to search for
      planType - - the type of the plan to retrieve
      Returns:
      plan with the given plan key, if found AND is of the correct type.
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type
    • getPlanIdentifierForPermissionCheckingByKey

      public PlanIdentifier getPlanIdentifierForPermissionCheckingByKey(@NotNull @NotNull String planKey)
      Description copied from interface: PlanManager
      Returns a Plan skeleton skeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi

      If Job key is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only for TopLevelPlans

      Specified by:
      getPlanIdentifierForPermissionCheckingByKey in interface PlanManager
      Parameters:
      planKey - of the plan to find
      Returns:
      plan by the id if found, otherwise null
    • getPlanClass

      public Class<? extends Plan> getPlanClass(@NotNull @NotNull PlanKey planKey)
      Specified by:
      getPlanClass in interface PlanManager
    • getPlanByKeyIfOfType

      public <T extends Plan> T getPlanByKeyIfOfType(@NotNull @NotNull PlanKey planKey, @NotNull @NotNull Class<T> planType)
      Description copied from interface: PlanManager
      Returns a Plan by its planKey and if it's of the type Class. Does not throw IncorrectPlanTypeException. Should only be used when the type of the plan can not be known.
      Specified by:
      getPlanByKeyIfOfType in interface PlanManager
      Parameters:
      planKey - to search for
      planType - the type of the plan to retrieve
      Returns:
      null if the plan doesn't exist, or it's not of the found type
    • getPlanByKey

      public Plan getPlanByKey(@NotNull @NotNull PlanKey planKey) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its PlanKey
      Specified by:
      getPlanByKey in interface PlanManager
      Parameters:
      planKey - to search for
      Returns:
      plan
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type (should never happen)
    • assertPlanPermission

      public boolean assertPlanPermission(@NotNull @NotNull PlanIdentifier plan)
      Description copied from interface: PlanManager
      Used to validate user permission for plan.
      Specified by:
      assertPlanPermission in interface PlanManager
      Parameters:
      plan - to check the permissions of
      Returns:
      true if the current user has read(?) permissions on the plan
    • getPlanByKey

      public <T extends Plan> T getPlanByKey(@NotNull @NotNull PlanKey planKey, Class<T> planType) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Returns a Plan by its PlanKey and Class
      Specified by:
      getPlanByKey in interface PlanManager
      Parameters:
      planKey - to search for
      planType - - the type of the plan to retrieve
      Returns:
      plan with the given key, if found AND is of the correct type.
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type
    • isChainNameConflicting

      public boolean isChainNameConflicting(@NotNull @NotNull String projectKey, long planIdToIgnore, @NotNull @NotNull String planName)
      Description copied from interface: PlanManager
      Verifies whether a Chain name is unique with the given project

      Specified by:
      isChainNameConflicting in interface PlanManager
      Parameters:
      projectKey - of the project to look for the plan in
      planIdToIgnore - the id of the plan that has to be ignored during lookup (when you're saving a Plan, you should supply the plan id here)
      planName - - name of the plan inside the project: this is just the plan component of the name (i.e does not include the project component)
      Returns:
      true if the name is in conflict
    • isPlanKeyConflicting

      public boolean isPlanKeyConflicting(@NotNull @NotNull PlanKey planKey)
      Description copied from interface: PlanManager
      Verifies whether a Plan key is unique within whole Bamboo installation
      Specified by:
      isPlanKeyConflicting in interface PlanManager
      Parameters:
      planKey - key of the plan to be searched for in the database
      Returns:
      true if plan key is conflicting
    • isPlanKeyConflicting

      public boolean isPlanKeyConflicting(@NotNull @NotNull PlanKey planKey, long planIdToIgnore)
      Description copied from interface: PlanManager
      Verifies whether a Plan key is unique within whole Bamboo installation
      Specified by:
      isPlanKeyConflicting in interface PlanManager
      planIdToIgnore - id of plan which we want to set key for, if the key is used by that plan, it's not really conflicting
      Returns:
      true if plan key is conflicting
    • getPlanByPartialKeyAndName

      @Nullable public <T extends Plan> T getPlanByPartialKeyAndName(@NotNull @NotNull PlanKey partialPlanKey, @NotNull @NotNull String planName, Class<T> planType) throws IncorrectPlanTypeException
      Description copied from interface: PlanManager
      Used for Job validation. Should update to be a specialised method
      Specified by:
      getPlanByPartialKeyAndName in interface PlanManager
      Throws:
      IncorrectPlanTypeException - if plan cannot be found with the correct type
    • getAllPlans

      @NotNull public @NotNull List<TopLevelPlan> getAllPlans()
      Description copied from interface: PlanManager
      Returns all TopLevelPlan's
      Specified by:
      getAllPlans in interface PlanManager
      Returns:
      plans
    • getAllPlansUnrestricted

      @NotNull public @NotNull List<TopLevelPlan> getAllPlansUnrestricted()
      Description copied from interface: PlanManager
      Returns all TopLevelPlan's ignoring permissions
      Specified by:
      getAllPlansUnrestricted in interface PlanManager
      Returns:
    • getAllPlans

      @NotNull public <T extends Plan> @NotNull List<T> getAllPlans(Class<T> planType)
      Description copied from interface: PlanManager
      Returns all Plan's filtered by Class. Does not include plans marked for deletion.
      Specified by:
      getAllPlans in interface PlanManager
      Parameters:
      planType - - the type of the plan to retrieve
      Returns:
      plans sorted by DescriptionProvider.getName()
    • getAllPlanKeys

      @NotNull public <T extends Plan> @NotNull List<PlanKey> getAllPlanKeys(Class<T> planType)
      Description copied from interface: PlanManager
      Returns keys of all Plan's filtered by Class. Does not include plans marked for deletion.
      Specified by:
      getAllPlanKeys in interface PlanManager
      Parameters:
      planType - - the type of the plan to retrieve
      Returns:
      plan keys
    • getAllPlans

      @NotNull public <T extends Plan> @NotNull List<T> getAllPlans(Class<T> planType, int firstResult, int maxResults)
      Description copied from interface: PlanManager
      Returns all Plan's filtered by Class. Does not include plans marked for deletion.
      Specified by:
      getAllPlans in interface PlanManager
      Parameters:
      planType - - the type of the plan to retrieve
      firstResult - firstResult for a paginated results
      maxResults - maximum number of results to return
      Returns:
      plans sorted by DescriptionProvider.getName()
    • getAllChainsAndJobsUnrestricted

      @NotNull public @NotNull List<Chain> getAllChainsAndJobsUnrestricted()
      Description copied from interface: PlanManager
      WARNING this is probably a bad idea from a performance perspective, only do this if you're going to traverse through all the ChainStage and Job of all Chains returned.
      Specified by:
      getAllChainsAndJobsUnrestricted in interface PlanManager
      Returns:
    • getPlansByProject

      @NotNull public @NotNull List<TopLevelPlan> getPlansByProject(Project project)
      Description copied from interface: PlanManager
      Returns all TopLevelPlan's filtered by Project Result of this method is filtered by Acegi.
      Specified by:
      getPlansByProject in interface PlanManager
      Parameters:
      project - - that the plans will belong to
      Returns:
      TopLevelPlan plans contained within the given project
    • getPlansByProject

      @NotNull public <T extends Plan> @NotNull List<T> getPlansByProject(Project project, Class<T> planType)
      Description copied from interface: PlanManager
      Returns all Plan's filtered by Project and Class
      Specified by:
      getPlansByProject in interface PlanManager
      Parameters:
      project - - that the plans will belong to
      planType - - the type of the plan to retrieve
      Returns:
      plans contained within the given project and of the given type
    • getAllPlansByProject

      @NotNull public <T extends Plan> @NotNull List<T> getAllPlansByProject(Project project, Class<T> planType)
      Description copied from interface: PlanManager
      Returns all Plan's filtered by Project and Class, including the plans marked for deletion.
      Specified by:
      getAllPlansByProject in interface PlanManager
      Parameters:
      project - - that the plans will belong to
      planType - - the type of the plan to retrieve
      Returns:
      plans contained within the given project and of the given type
    • getPlanIdentifiersForProject

      @NotNull public <T extends Plan> @NotNull List<PlanIdentifier> getPlanIdentifiersForProject(@NotNull @NotNull ProjectIdentifier project, @NotNull @NotNull Class<T> planType, boolean includeMarkedForDeletion)
      Description copied from interface: PlanManager
      Retrieve a list of plans for a given project. Only minimal data about the plans is returned.
      Specified by:
      getPlanIdentifiersForProject in interface PlanManager
      Parameters:
      project - to get plans for
      planType - to filter plans by
      includeMarkedForDeletion - set to true if you want to return plans marked for deletion
      Returns:
      PlanIdentifiers meeting the above criteria.
    • getProjectPlanMap

      @NotNull public <T extends Plan> @NotNull Map<Project,Collection<T>> getProjectPlanMap(Class<T> planType, boolean includeEmptyProjects)
      Description copied from interface: PlanManager
      Return mapping of Project to Plan of given type
      Specified by:
      getProjectPlanMap in interface PlanManager
      Parameters:
      planType - type of plan to be selected from DB
      includeEmptyProjects - should empty projects be included in result
      Returns:
      mapping of Project to Plan of given type
    • getPlanCount

      public int getPlanCount()
      Specified by:
      getPlanCount in interface PlanManager
      Returns:
      How many Buildable's exists
    • getPlanCount

      public <T extends Plan> int getPlanCount(Class<T> planType)
      Description copied from interface: PlanManager
      How many plans filtered by Class currently exist
      Specified by:
      getPlanCount in interface PlanManager
      Parameters:
      planType - - the type of the plan to retrieve
      Returns:
      how many plans exist in the datbase
    • getPlanCount

      public int getPlanCount(@NotNull @NotNull ProjectIdentifier projectIdentifier)
      Description copied from interface: PlanManager
      How many plans currently exist in a project.
      Specified by:
      getPlanCount in interface PlanManager
      Parameters:
      projectIdentifier - identifier of the project
      Returns:
      number of plans in the project, excluding ones marked for deletion
    • savePlan

      public void savePlan(@NotNull @NotNull Plan plan)
      Description copied from interface: PlanManager
      Saves the Plan
      Specified by:
      savePlan in interface PlanManager
      Parameters:
      plan - to be saved
    • savePlanWithSchedulesStopped

      public void savePlanWithSchedulesStopped(@NotNull @NotNull Plan plan)
      Description copied from interface: PlanManager
      Saves the Plan while polling jobs are stopped.
      Specified by:
      savePlanWithSchedulesStopped in interface PlanManager
    • createPlan

      public void createPlan(@NotNull @NotNull Plan plan)
      Description copied from interface: PlanManager
      Same as savePlan, but create permissions used instead of edit permissions.
      Specified by:
      createPlan in interface PlanManager
    • setPlanSuspendedState

      public void setPlanSuspendedState(PlanKey planKey, boolean isSuspended)
      Specified by:
      setPlanSuspendedState in interface PlanManager
    • isPlanCreationAllowed

      public boolean isPlanCreationAllowed()
      Check whether or not a plan can be created or not (based on licensing etc) USE SPARINGLY!!!
      Specified by:
      isPlanCreationAllowed in interface PlanManager
      Returns:
      true if a plan can be created otherwise false;
    • triggerConfigUpdatedEventsForPlansInProject

      public void triggerConfigUpdatedEventsForPlansInProject(@NotNull @NotNull Project project)
      Description copied from interface: PlanManager
      Triggers updated events for every plan in a project regardless of permissions.
      Specified by:
      triggerConfigUpdatedEventsForPlansInProject in interface PlanManager
      Parameters:
      project - to trigger event for.
    • deletePlan

      public void deletePlan(@NotNull @NotNull Plan plan)
      Description copied from interface: PlanManager
      Removes the plan object from the database. Does not do any other clean up work at all Please use the DeletionService rather than using this method directly
      Specified by:
      deletePlan in interface PlanManager
      Parameters:
      plan - to delete.
    • getAllPlansMarkedForDeletion

      @NotNull public <T extends Plan> @NotNull Collection<T> getAllPlansMarkedForDeletion(Class<T> planType)
      Description copied from interface: PlanManager
      Returns a list of Plans that are ImmutableDeletable.isMarkedForDeletion() for the given type
      Specified by:
      getAllPlansMarkedForDeletion in interface PlanManager
      Returns:
      plansMarkedForDeletion
    • markPlansForDeletion

      public void markPlansForDeletion(PlanKey planKey)
      Description copied from interface: PlanManager
      Efficiently marks a plan to be deleted
      Specified by:
      markPlansForDeletion in interface PlanManager
    • syncDeletionStatusOfJobs

      public void syncDeletionStatusOfJobs()
      Description copied from interface: PlanManager
      Performs a cleanup task to mark Job objects that have a Plan or ChainStage that is marked to be deleted, but it itself was not marked as deleted.
      Specified by:
      syncDeletionStatusOfJobs in interface PlanManager
    • syncDeletionStatusOfPlans

      public void syncDeletionStatusOfPlans()
      Description copied from interface: PlanManager
      Performs a cleanup task to mark Plan objects that have a Project that is marked to be deleted, but is not marked as deleted.
      Specified by:
      syncDeletionStatusOfPlans in interface PlanManager
    • syncDeletionStatusOfChainBranches

      public void syncDeletionStatusOfChainBranches()
      Description copied from interface: PlanManager
      Performs a cleanup task to mark ChainBranch objects that have a master Plan that is marked to be deleted, but is not marked as deleted.
      Specified by:
      syncDeletionStatusOfChainBranches in interface PlanManager
    • removeStages

      public void removeStages(@NotNull @NotNull PlanKey key, @NotNull @NotNull Collection<Long> stageIds)
      Description copied from interface: PlanManager
      Remove the tages from the plan specified. key must be for a Chain
      Specified by:
      removeStages in interface PlanManager
    • filterFavouritedPlans

      @NotNull public @NotNull Set<ImmutableChain> filterFavouritedPlans(@NotNull @NotNull Collection<? extends ImmutableChain> plans, @NotNull @NotNull com.atlassian.user.User user)
      Description copied from interface: PlanManager
      Return a set of Plans that are a subset of the given TopLevelPlans collection that are favourited by the User. Plans are not filtered by read permission.
      Specified by:
      filterFavouritedPlans in interface PlanManager
      Parameters:
      plans - to filter
      user - to return the favourites of
      Returns:
      a set of Chains that are a subset of the given TopLevelPlans collection that are favourited by the User
    • getFavouritePlans

      public Set<ImmutableChain> getFavouritePlans(@NotNull @NotNull com.atlassian.user.User user)
      Specified by:
      getFavouritePlans in interface PlanManager
    • getFavouritePlansIds

      @NotNull public @NotNull Set<Long> getFavouritePlansIds(@NotNull @NotNull com.atlassian.user.User user)
      Description copied from interface: PlanManager
      Return a collection of Favourite plan ids.
      Specified by:
      getFavouritePlansIds in interface PlanManager
      Returns:
      favouritePlansIds