Search in sources :

Example 16 with NotFoundException

use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.

the class BuildTypeUtil method changeParameterType.

public static void changeParameterType(final String parameterName, @Nullable final String newRawTypeValue, @NotNull final EntityWithModifiableParameters parametrizedEntity, @NotNull final ServiceLocator serviceLocator) {
    if (StringUtil.isEmpty(parameterName)) {
        throw new BadRequestException("Parameter name cannot be empty.");
    }
    Parameter parameter = parametrizedEntity.getParameter(parameterName);
    if (parameter == null) {
        throw new NotFoundException("Parameter with name '" + parameterName + "' not found");
    }
    final ParameterFactory parameterFactory = getParameterFactory(serviceLocator);
    final String newValue = parameterFactory.isSecureParameter(parameter.getControlDescription()) ? "" : parameter.getValue();
    if (newRawTypeValue != null) {
        parametrizedEntity.addParameter(parameterFactory.createTypedParameter(parameterName, newValue, newRawTypeValue));
    } else {
        parametrizedEntity.addParameter(parameterFactory.createSimpleParameter(parameterName, newValue));
    }
}
Also used : ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Example 17 with NotFoundException

use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.

the class PropEntitySnapshotDep method getSnapshotDep.

public static Dependency getSnapshotDep(@NotNull final BuildTypeSettings buildType, @Nullable final String snapshotDepLocator, @NotNull final BuildTypeFinder buildTypeFinder) {
    if (StringUtil.isEmpty(snapshotDepLocator)) {
        throw new BadRequestException("Empty snapshot dependency locator is not supported.");
    }
    final Locator locator = new Locator(snapshotDepLocator, Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME, "buildType");
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's id of the dependency (build type external id)
        final String snapshotDepId = locator.getSingleValue();
        // todo (TeamCity) seems like no way to get snapshot dependency by source build type
        Dependency foundDependency = getSnapshotDepOrNull(buildType, snapshotDepId);
        if (foundDependency != null) {
            return foundDependency;
        }
        // fall back to internal id for compatibility
        foundDependency = getSnapshotDepByInternalIdOrNull(buildType, snapshotDepId);
        if (foundDependency != null) {
            return foundDependency;
        }
    }
    String buildTypeLocator = locator.getSingleDimensionValue("buildType");
    if (buildTypeLocator != null) {
        final String externalId = buildTypeFinder.getBuildType(null, buildTypeLocator, false).getExternalId();
        final Dependency foundDependency = getSnapshotDepOrNull(buildType, externalId);
        if (foundDependency != null) {
            return foundDependency;
        }
        throw new NotFoundException("No snapshot dependency found to build type with external id '" + externalId + "'.");
    }
    locator.checkLocatorFullyProcessed();
    throw new NotFoundException("No snapshot dependency found by locator '" + snapshotDepLocator + "'. Locator should be existing dependency source build type external id.");
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Dependency(jetbrains.buildServer.serverSide.dependency.Dependency)

Example 18 with NotFoundException

use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.

the class Build method getFieldValue.

@Nullable
public static String getFieldValue(@NotNull final BuildPromotion buildPromotion, @Nullable final String field, @NotNull final BeanContext beanContext) {
    final Build build = new Build(buildPromotion, Fields.ALL, beanContext);
    if ("number".equals(field)) {
        // supporting number here in addition to BuildRequest as this method is used from other requests classes as well
        return build.getNumber();
    } else if ("status".equals(field)) {
        return build.getStatus();
    } else if ("statusText".equals(field)) {
        return build.getStatusText();
    } else if ("id".equals(field)) {
        return String.valueOf(build.getId());
    } else if ("state".equals(field)) {
        return build.getState().toString();
    } else if ("failedToStart".equals(field)) {
        return String.valueOf(build.isFailedToStart());
    } else if ("startEstimateDate".equals(field)) {
        return build.getStartEstimate();
    } else if (FINISH_ESTIMATE.equals(field)) {
        return build.getFinishEstimate();
    } else if ("percentageComplete".equals(field)) {
        return String.valueOf(build.getPercentageComplete());
    } else if ("personal".equals(field)) {
        return String.valueOf(build.isPersonal());
    } else if ("usedByOtherBuilds".equals(field)) {
        return String.valueOf(build.isUsedByOtherBuilds());
    } else if ("queuedDate".equals(field)) {
        return build.getQueuedDate();
    } else if ("startDate".equals(field)) {
        return build.getStartDate();
    } else if ("finishDate".equals(field)) {
        return build.getFinishDate();
    } else if ("buildTypeId".equals(field)) {
        return build.getBuildTypeId();
    } else if ("buildTypeInternalId".equals(field)) {
        return buildPromotion.getBuildTypeId();
    } else if ("branchName".equals(field)) {
        return build.getBranchName();
    } else if ("branch".equals(field)) {
        Branch branch = buildPromotion.getBranch();
        return branch == null ? "" : branch.getName();
    } else if ("defaultBranch".equals(field)) {
        return String.valueOf(build.getDefaultBranch());
    } else if ("unspecifiedBranch".equals(field)) {
        return String.valueOf(build.getUnspecifiedBranch());
    } else if (PROMOTION_ID.equals(field) || "promotionId".equals(field)) {
        // Experimental support only
        return (String.valueOf(build.getPromotionId()));
    } else if ("modificationId".equals(field)) {
        // Experimental support only
        return String.valueOf(buildPromotion.getLastModificationId());
    } else if ("chainModificationId".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).getChainModificationId());
    } else if ("commentText".equals(field)) {
        // Experimental support only
        final Comment comment = build.getComment();
        return comment == null ? null : comment.text;
    } else if ("collectChangesError".equals(field)) {
        // Experimental support only
        return ((BuildPromotionEx) buildPromotion).getCollectChangesError();
    } else if ("changesCollectingInProgress".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).isChangesCollectingInProgress());
    } else if ("changeCollectingNeeded".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).isChangeCollectingNeeded());
    } else if ("revision".equals(field)) {
        // Experimental support only
        final List<BuildRevision> revisions = buildPromotion.getRevisions();
        return revisions.size() != 1 ? String.valueOf(revisions.get(0).getRevision()) : null;
    } else if ("settingsHash".equals(field)) {
        // Experimental support only to get settings digest
        return new String(Hex.encodeHex(((BuildPromotionEx) buildPromotion).getSettingsDigest(false)));
    } else if ("currentSettingsHash".equals(field)) {
        // Experimental support only to get settings digest
        return new String(Hex.encodeHex(((BuildPromotionEx) buildPromotion).getBuildSettings().getDigest()));
    }
    final SBuild associatedBuild = buildPromotion.getAssociatedBuild();
    final SQueuedBuild queuedBuild = buildPromotion.getQueuedBuild();
    if ("triggeredBy.username".equals(field)) {
        // Experimental support only
        if (associatedBuild != null) {
            final SUser user = associatedBuild.getTriggeredBy().getUser();
            return user == null ? null : user.getUsername();
        }
        if (queuedBuild != null) {
            final SUser user = queuedBuild.getTriggeredBy().getUser();
            return user == null ? null : user.getUsername();
        }
        return null;
    } else if ("triggeredBy.raw".equals(field)) {
        // Experimental support only
        if (associatedBuild != null) {
            return associatedBuild.getTriggeredBy().getRawTriggeredBy();
        }
        if (queuedBuild != null) {
            return queuedBuild.getTriggeredBy().getRawTriggeredBy();
        }
        return null;
    }
    throw new NotFoundException("Field '" + field + "' is not supported. Supported are: number, status, statusText, id, startDate, finishDate, buildTypeId, branchName.");
}
Also used : BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) Branch(jetbrains.buildServer.serverSide.Branch) SUser(jetbrains.buildServer.users.SUser) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with NotFoundException

use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.

the class Build method getSubmittedBuildType.

private SBuildType getSubmittedBuildType(@NotNull ServiceLocator serviceLocator, @Nullable final SVcsModification personalChange, @Nullable final SUser currentUser) {
    if (submittedBuildType == null) {
        if (submittedBuildTypeId == null) {
            throw new BadRequestException("No 'buildType' element in the posted entry.");
        }
        SBuildType buildType = serviceLocator.getSingletonService(ProjectManager.class).findBuildTypeByExternalId(submittedBuildTypeId);
        if (buildType == null) {
            throw new NotFoundException("No build type found by submitted id '" + submittedBuildTypeId + "'");
        }
        return buildType;
    }
    final BuildTypeOrTemplate buildTypeFromPosted = submittedBuildType.getBuildTypeFromPosted(serviceLocator.findSingletonService(BuildTypeFinder.class));
    final SBuildType regularBuildType = buildTypeFromPosted.getBuildType();
    if (regularBuildType == null) {
        throw new BadRequestException("Found template instead on build type. Only build types can run builds.");
    }
    if (personalChange == null) {
        return regularBuildType;
    }
    if (currentUser == null) {
        throw new BadRequestException("Cannot trigger a personal build while no current user is present. Please specify credentials of a valid and non-special user.");
    }
    return ((BuildTypeEx) regularBuildType).createPersonalBuildType(currentUser, personalChange.getId());
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Example 20 with NotFoundException

use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.

the class TestFinder method findSingleItem.

@Override
@Nullable
public STest findSingleItem(@NotNull final Locator locator) {
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's id
        final Long parsedId = locator.getSingleValueAsLong();
        if (parsedId == null) {
            throw new BadRequestException("Expecting id, found empty value.");
        }
        STest item = findTest(parsedId);
        if (item == null) {
            throw new NotFoundException("No test can be found by id '" + parsedId + "' on the entire server.");
        }
        return item;
    }
    // dimension-specific item search
    Long id = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
    if (id != null) {
        STest item = findTest(id);
        if (item == null) {
            throw new NotFoundException("No test" + " can be found by " + DIMENSION_ID + " '" + id + "' on the entire server.");
        }
        return item;
    }
    String nameDimension = locator.getSingleDimensionValue(NAME);
    if (nameDimension != null) {
        ValueCondition nameCondition = ParameterCondition.createValueConditionFromPlainValueOrCondition(nameDimension);
        String constantName = nameCondition.getConstantValueIfSimpleEqualsCondition();
        if (constantName == null) {
            return null;
        }
        final Long testNameId = myTestName2Index.findTestNameId(new TestName(constantName));
        if (testNameId == null) {
            throw new NotFoundException("No test can be found by " + NAME + " '" + constantName + "' on the entire server.");
        }
        STest test = findTest(testNameId);
        if (test == null) {
            throw new NotFoundException("No test can be found by id corresponding to " + NAME + " '" + constantName + "' on the entire server.");
        }
        return test;
    }
    return null;
}
Also used : TestName(jetbrains.buildServer.tests.TestName) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)47 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)26 ApiOperation (io.swagger.annotations.ApiOperation)19 NotNull (org.jetbrains.annotations.NotNull)14 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)13 ServiceLocator (jetbrains.buildServer.ServiceLocator)10 SUser (jetbrains.buildServer.users.SUser)10 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)10 Nullable (org.jetbrains.annotations.Nullable)8 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)7 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Converter (jetbrains.buildServer.util.Converter)4 RevisionsNotFoundException (jetbrains.buildServer.vcs.impl.RevisionsNotFoundException)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 SUserGroup (jetbrains.buildServer.groups.SUserGroup)3 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)3 Permission (jetbrains.buildServer.serverSide.auth.Permission)3