Package com.atlassian.bamboo.plan
Class PlanManagerImpl
- java.lang.Object
-
- com.atlassian.bamboo.plan.PlanManagerImpl
-
- All Implemented Interfaces:
PlanManager
public class PlanManagerImpl extends Object implements PlanManager
-
-
Constructor Summary
Constructors Constructor Description PlanManagerImpl(@NotNull PlanDao planDao, @NotNull BambooLicenseManager bambooLicenseManager, @NotNull com.atlassian.event.api.EventPublisher eventPublisher, @NotNull ProjectManager projectManager, @NotNull PlanScheduler planScheduler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanassertPlanPermission(@NotNull PlanIdentifier plan)Used to validate user permission for plan.voidcreatePlan(@NotNull Plan plan)Same as savePlan, but create permissions used instead of edit permissions.voiddeletePlan(@NotNull Plan plan)Removes the plan object from the database.@NotNull Set<ImmutableChain>filterFavouritedPlans(@NotNull Collection<? extends ImmutableChain> plans, @NotNull com.atlassian.user.User user)Return a set ofPlans that are a subset of the givenTopLevelPlans collection that are favourited by theUser.@NotNull List<Chain>getAllChainsAndJobsUnrestricted()WARNING this is probably a bad idea from a performance perspective, only do this if you're going to traverse through all theChainStageandJobof allChains returned.<T extends Plan>
@NotNull List<PlanKey>getAllPlanKeys(Class<T> planType)@NotNull List<TopLevelPlan>getAllPlans()Returns allTopLevelPlan's<T extends Plan>
@NotNull List<T>getAllPlans(Class<T> planType)<T extends Plan>
@NotNull List<T>getAllPlans(Class<T> planType, int firstResult, int maxResults)<T extends Plan>
@NotNull List<T>getAllPlansByProject(Project project, Class<T> planType)<T extends Plan>
@NotNull Collection<T>getAllPlansMarkedForDeletion(Class<T> planType)Returns a list ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given type@NotNull List<TopLevelPlan>getAllPlansUnrestricted()Returns allTopLevelPlan's ignoring permissionsSet<ImmutableChain>getFavouritePlans(@NotNull com.atlassian.user.User user)@NotNull Set<Long>getFavouritePlansIds(@NotNull com.atlassian.user.User user)Return a collection of Favourite plan ids.@Nullable PlangetPlanById(long id)Returns aPlanby its id<T extends Plan>
TgetPlanById(long id, Class<T> planType)PlangetPlanByKey(@NotNull PlanKey planKey)<T extends Plan>
TgetPlanByKey(@NotNull PlanKey planKey, Class<T> planType)@Nullable PlangetPlanByKey(@NotNull String planKey)Returns aPlanby its planKey<T extends Plan>
TgetPlanByKey(@NotNull String planKey, Class<T> planType)<T extends Plan>
TgetPlanByKeyIfOfType(@NotNull PlanKey planKey, @NotNull Class<T> planType)<T extends Plan>
TgetPlanByOid(BambooEntityOid oid, Class<T> planType)<T extends Plan>
TgetPlanByPartialKeyAndName(@NotNull PlanKey partialPlanKey, @NotNull String planName, Class<T> planType)Used for Job validation.Class<? extends Plan>getPlanClass(@NotNull PlanKey planKey)intgetPlanCount()intgetPlanCount(@NotNull ProjectIdentifier projectIdentifier)How many plans currently exist in aproject.<T extends Plan>
intgetPlanCount(Class<T> planType)How many plans filtered byClasscurrently existPlanIdentifiergetPlanIdentifierForPermissionCheckingByKey(@NotNull String planKey)Returns aPlanskeleton skeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi<T extends Plan>
@NotNull List<PlanIdentifier>getPlanIdentifiersForProject(@NotNull ProjectIdentifier project, @NotNull Class<T> planType, boolean includeMarkedForDeletion)Retrieve a list of plans for a given project.@NotNull List<TopLevelPlan>getPlansByProject(Project project)Returns allTopLevelPlan's filtered byProjectResult of this method is filtered by Acegi.<T extends Plan>
@NotNull List<T>getPlansByProject(Project project, Class<T> planType)<T extends Plan>
@NotNull Map<Project,Collection<T>>getProjectPlanMap(Class<T> planType, boolean includeEmptyProjects)booleanisChainNameConflicting(@NotNull String projectKey, long planIdToIgnore, @NotNull String planName)Verifies whether aChainname is unique with the given projectbooleanisPlanCreationAllowed()Check whether or not a plan can be created or not (based on licensing etc) USE SPARINGLY!!!booleanisPlanKeyConflicting(@NotNull PlanKey planKey)Verifies whether aPlankey is unique within whole Bamboo installationbooleanisPlanKeyConflicting(@NotNull PlanKey planKey, long planIdToIgnore)Verifies whether aPlankey is unique within whole Bamboo installationvoidmarkPlansForDeletion(PlanKey planKey)Efficiently marks a plan to be deletedvoidremoveStages(@NotNull PlanKey key, @NotNull Collection<Long> stageIds)Remove the tages from the plan specified. key must be for aChainvoidsavePlan(@NotNull Plan plan)Saves thePlanvoidsavePlanWithSchedulesStopped(@NotNull Plan plan)Saves thePlanwhile polling jobs are stopped.voidsetPlanSuspendedState(PlanKey planKey, boolean isSuspended)voidsyncDeletionStatusOfChainBranches()Performs a cleanup task to markChainBranchobjects that have a masterPlanthat is marked to be deleted, but is not marked as deleted.voidsyncDeletionStatusOfJobs()Performs a cleanup task to markJobobjects that have aPlanorChainStagethat is marked to be deleted, but it itself was not marked as deleted.voidsyncDeletionStatusOfPlans()voidtriggerConfigUpdatedEventsForPlansInProject(@NotNull Project project)Triggers updated events for every plan in a project regardless of permissions.
-
-
-
Constructor Detail
-
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 Detail
-
getPlanById
@Nullable public @Nullable Plan getPlanById(long id) throws IncorrectPlanTypeException
Description copied from interface:PlanManagerReturns aPlanby its id- Specified by:
getPlanByIdin interfacePlanManager- 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- Specified by:
getPlanByIdin interfacePlanManager- Parameters:
id- of the planplanType- - 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- Specified by:
getPlanByOidin interfacePlanManager- Parameters:
oid- of the planplanType- - 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:PlanManagerReturns aPlanby its planKey- Specified by:
getPlanByKeyin interfacePlanManager- 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- Specified by:
getPlanByKeyin interfacePlanManager- Parameters:
planKey- to search forplanType- - 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:PlanManagerReturns aPlanskeleton skeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using AcegiIf
Jobkey is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only forTopLevelPlans- Specified by:
getPlanIdentifierForPermissionCheckingByKeyin interfacePlanManager- 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:
getPlanClassin interfacePlanManager
-
getPlanByKeyIfOfType
public <T extends Plan> T getPlanByKeyIfOfType(@NotNull @NotNull PlanKey planKey, @NotNull @NotNull Class<T> planType)
Description copied from interface:PlanManagerReturns aPlanby its planKey and if it's of the typeClass. Does not throwIncorrectPlanTypeException. Should only be used when the type of the plan can not be known.- Specified by:
getPlanByKeyIfOfTypein interfacePlanManager- Parameters:
planKey- to search forplanType- 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- Specified by:
getPlanByKeyin interfacePlanManager- 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:PlanManagerUsed to validate user permission for plan.- Specified by:
assertPlanPermissionin interfacePlanManager- 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- Specified by:
getPlanByKeyin interfacePlanManager- Parameters:
planKey- to search forplanType- - 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:PlanManagerVerifies whether aChainname is unique with the given project- Specified by:
isChainNameConflictingin interfacePlanManager- Parameters:
projectKey- of the project to look for the plan inplanIdToIgnore- 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:PlanManagerVerifies whether aPlankey is unique within whole Bamboo installation- Specified by:
isPlanKeyConflictingin interfacePlanManager- 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:PlanManagerVerifies whether aPlankey is unique within whole Bamboo installation- Specified by:
isPlanKeyConflictingin interfacePlanManagerplanIdToIgnore- 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:PlanManagerUsed for Job validation. Should update to be a specialised method- Specified by:
getPlanByPartialKeyAndNamein interfacePlanManager- Throws:
IncorrectPlanTypeException- if plan cannot be found with the correct type
-
getAllPlans
@NotNull public @NotNull List<TopLevelPlan> getAllPlans()
Description copied from interface:PlanManagerReturns allTopLevelPlan's- Specified by:
getAllPlansin interfacePlanManager- Returns:
- plans
-
getAllPlansUnrestricted
@NotNull public @NotNull List<TopLevelPlan> getAllPlansUnrestricted()
Description copied from interface:PlanManagerReturns allTopLevelPlan's ignoring permissions- Specified by:
getAllPlansUnrestrictedin interfacePlanManager- Returns:
-
getAllPlans
@NotNull public <T extends Plan> @NotNull List<T> getAllPlans(Class<T> planType)
Description copied from interface:PlanManager- Specified by:
getAllPlansin interfacePlanManager- 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- Specified by:
getAllPlanKeysin interfacePlanManager- 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- Specified by:
getAllPlansin interfacePlanManager- Parameters:
planType- - the type of the plan to retrievefirstResult- firstResult for a paginated resultsmaxResults- maximum number of results to return- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getAllChainsAndJobsUnrestricted
@NotNull public @NotNull List<Chain> getAllChainsAndJobsUnrestricted()
Description copied from interface:PlanManagerWARNING this is probably a bad idea from a performance perspective, only do this if you're going to traverse through all theChainStageandJobof allChains returned.- Specified by:
getAllChainsAndJobsUnrestrictedin interfacePlanManager- Returns:
-
getPlansByProject
@NotNull public @NotNull List<TopLevelPlan> getPlansByProject(Project project)
Description copied from interface:PlanManagerReturns allTopLevelPlan's filtered byProjectResult of this method is filtered by Acegi.- Specified by:
getPlansByProjectin interfacePlanManager- Parameters:
project- - that the plans will belong to- Returns:
TopLevelPlanplans 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- Specified by:
getPlansByProjectin interfacePlanManager- Parameters:
project- - that the plans will belong toplanType- - 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- Specified by:
getAllPlansByProjectin interfacePlanManager- Parameters:
project- - that the plans will belong toplanType- - 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:PlanManagerRetrieve a list of plans for a given project. Only minimal data about the plans is returned.- Specified by:
getPlanIdentifiersForProjectin interfacePlanManager- Parameters:
project- to get plans forplanType- to filter plans byincludeMarkedForDeletion- 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- Specified by:
getProjectPlanMapin interfacePlanManager- Parameters:
planType- type of plan to be selected from DBincludeEmptyProjects- should empty projects be included in result- Returns:
- mapping of
ProjecttoPlanof given type
-
getPlanCount
public int getPlanCount()
- Specified by:
getPlanCountin interfacePlanManager- Returns:
- How many
Buildable's exists
-
getPlanCount
public <T extends Plan> int getPlanCount(Class<T> planType)
Description copied from interface:PlanManagerHow many plans filtered byClasscurrently exist- Specified by:
getPlanCountin interfacePlanManager- 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:PlanManagerHow many plans currently exist in aproject.- Specified by:
getPlanCountin interfacePlanManager- 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:PlanManagerSaves thePlan- Specified by:
savePlanin interfacePlanManager- Parameters:
plan- to be saved
-
savePlanWithSchedulesStopped
public void savePlanWithSchedulesStopped(@NotNull @NotNull Plan plan)Description copied from interface:PlanManagerSaves thePlanwhile polling jobs are stopped.- Specified by:
savePlanWithSchedulesStoppedin interfacePlanManager
-
createPlan
public void createPlan(@NotNull @NotNull Plan plan)Description copied from interface:PlanManagerSame as savePlan, but create permissions used instead of edit permissions.- Specified by:
createPlanin interfacePlanManager
-
setPlanSuspendedState
public void setPlanSuspendedState(PlanKey planKey, boolean isSuspended)
- Specified by:
setPlanSuspendedStatein interfacePlanManager
-
isPlanCreationAllowed
public boolean isPlanCreationAllowed()
Check whether or not a plan can be created or not (based on licensing etc) USE SPARINGLY!!!- Specified by:
isPlanCreationAllowedin interfacePlanManager- Returns:
- true if a plan can be created otherwise false;
-
triggerConfigUpdatedEventsForPlansInProject
public void triggerConfigUpdatedEventsForPlansInProject(@NotNull @NotNull Project project)Description copied from interface:PlanManagerTriggers updated events for every plan in a project regardless of permissions.- Specified by:
triggerConfigUpdatedEventsForPlansInProjectin interfacePlanManager- Parameters:
project- to trigger event for.
-
deletePlan
public void deletePlan(@NotNull @NotNull Plan plan)Description copied from interface:PlanManagerRemoves the plan object from the database. Does not do any other clean up work at all Please use theDeletionServicerather than using this method directly- Specified by:
deletePlanin interfacePlanManager- Parameters:
plan- to delete.
-
getAllPlansMarkedForDeletion
@NotNull public <T extends Plan> @NotNull Collection<T> getAllPlansMarkedForDeletion(Class<T> planType)
Description copied from interface:PlanManagerReturns a list ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given type- Specified by:
getAllPlansMarkedForDeletionin interfacePlanManager- Returns:
- plansMarkedForDeletion
-
markPlansForDeletion
public void markPlansForDeletion(PlanKey planKey)
Description copied from interface:PlanManagerEfficiently marks a plan to be deleted- Specified by:
markPlansForDeletionin interfacePlanManager
-
syncDeletionStatusOfJobs
public void syncDeletionStatusOfJobs()
Description copied from interface:PlanManagerPerforms a cleanup task to markJobobjects that have aPlanorChainStagethat is marked to be deleted, but it itself was not marked as deleted.- Specified by:
syncDeletionStatusOfJobsin interfacePlanManager
-
syncDeletionStatusOfPlans
public void syncDeletionStatusOfPlans()
Description copied from interface:PlanManagerPerforms a cleanup task to markPlanobjects that have aProjectthat is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfPlansin interfacePlanManager
-
syncDeletionStatusOfChainBranches
public void syncDeletionStatusOfChainBranches()
Description copied from interface:PlanManagerPerforms a cleanup task to markChainBranchobjects that have a masterPlanthat is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfChainBranchesin interfacePlanManager
-
removeStages
public void removeStages(@NotNull @NotNull PlanKey key, @NotNull @NotNull Collection<Long> stageIds)Description copied from interface:PlanManagerRemove the tages from the plan specified. key must be for aChain- Specified by:
removeStagesin interfacePlanManager
-
filterFavouritedPlans
@NotNull public @NotNull Set<ImmutableChain> filterFavouritedPlans(@NotNull @NotNull Collection<? extends ImmutableChain> plans, @NotNull @NotNull com.atlassian.user.User user)
Description copied from interface:PlanManagerReturn a set ofPlans that are a subset of the givenTopLevelPlans collection that are favourited by theUser. Plans are not filtered by read permission.- Specified by:
filterFavouritedPlansin interfacePlanManager- Parameters:
plans- to filteruser- to return the favourites of- Returns:
- a set of
Chains that are a subset of the givenTopLevelPlans collection that are favourited by theUser
-
getFavouritePlans
public Set<ImmutableChain> getFavouritePlans(@NotNull @NotNull com.atlassian.user.User user)
- Specified by:
getFavouritePlansin interfacePlanManager
-
getFavouritePlansIds
@NotNull public @NotNull Set<Long> getFavouritePlansIds(@NotNull @NotNull com.atlassian.user.User user)
Description copied from interface:PlanManagerReturn a collection of Favourite plan ids.- Specified by:
getFavouritePlansIdsin interfacePlanManager- Returns:
- favouritePlansIds
-
-