Search in sources :

Example 11 with BuildTriggerDescriptor

use of jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor in project teamcity-rest by JetBrains.

the class DataProvider method getTrigger.

public static BuildTriggerDescriptor getTrigger(final BuildTypeSettings buildType, final String triggerLocator) {
    if (StringUtil.isEmpty(triggerLocator)) {
        throw new BadRequestException("Empty trigger locator is not supported.");
    }
    final Locator locator = new Locator(triggerLocator);
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's trigger id
        final String triggerId = locator.getSingleValue();
        if (StringUtil.isEmpty(triggerId)) {
            throw new BadRequestException("Trigger id cannot be empty.");
        }
        @SuppressWarnings("ConstantConditions") final BuildTriggerDescriptor foundTrigger = buildType.findTriggerById(triggerId);
        if (foundTrigger == null) {
            throw new NotFoundException("No trigger found by id '" + triggerLocator + "' in build type.");
        }
        return foundTrigger;
    }
    throw new BadRequestException("No trigger can be found by locator '" + triggerLocator + "'. Locator should be trigger id.");
}
Also used : BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) ServiceLocator(jetbrains.buildServer.ServiceLocator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Aggregations

BuildTriggerDescriptor (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor)11 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)7 ApiOperation (io.swagger.annotations.ApiOperation)6 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)2 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)2 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)2 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)2 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)2 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 BuildTriggerDescriptorFactory (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptorFactory)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 OperationException (jetbrains.buildServer.server.rest.errors.OperationException)1 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)1 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)1 NotNull (org.jetbrains.annotations.NotNull)1