use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class UserRequest method getGroup.
@GET
@Path("/{userLocator}/groups/{groupLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get a user group of the matching user.", nickname = "getUserGroup")
public Group getGroup(@ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @PathParam("groupLocator") String groupLocator, @QueryParam("fields") String fields) {
if (TeamCityProperties.getBooleanOrTrue(UserFinder.REST_CHECK_ADDITIONAL_PERMISSIONS_ON_USERS_AND_GROUPS)) {
myUserFinder.checkViewAllUsersPermission();
}
SUser user = myUserFinder.getItem(userLocator, true);
SUserGroup group = myBeanContext.getSingletonService(UserGroupFinder.class).getGroup(groupLocator);
if (!user.getUserGroups().contains(group)) {
throw new NotFoundException("User does not belong to the group");
}
return new Group(group, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method deleteVcsRootEntry.
@DELETE
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@ApiOperation(value = "Remove a VCS root of the matching build configuration.", nickname = "deleteVcsRoot")
public void deleteVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
// todo: extract builType/VCS root id retrieving logic into single method
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
// this assumes VCS root id are unique throughout the server
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
}
buildType.get().removeVcsRoot(vcsRoot);
buildType.persist("VCS root detached");
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method getVcsRootEntry.
@GET
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get a VCS root of the matching build configuration.", nickname = "getVcsRoot")
public VcsRootEntry getVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @QueryParam("fields") String fields) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
}
return new VcsRootEntry(vcsRoot, buildType, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class BuildTypeRequest method getAgentRequirement.
public static Requirement getAgentRequirement(@NotNull final BuildTypeOrTemplate buildType, @Nullable final String agentRequirementLocator) {
if (StringUtil.isEmpty(agentRequirementLocator)) {
throw new BadRequestException("Empty agent requirement locator is not supported.");
}
final Locator locator = new Locator(agentRequirementLocator);
final String requirementId;
if (locator.isSingleValue()) {
requirementId = locator.getSingleValue();
} else {
requirementId = locator.getSingleDimensionValue("id");
}
locator.checkLocatorFullyProcessed();
if (StringUtil.isEmpty(requirementId)) {
throw new BadRequestException("Cannot find id in agent requirement locator '" + agentRequirementLocator + "'");
}
for (Requirement requirement : buildType.get().getRequirements()) {
String id = requirement.getId();
if (requirementId.equals(id != null ? id : requirement.getPropertyName())) {
return requirement;
}
}
// may be it is a property name: use obsolete pre-TeamCity 10 logic
for (Requirement requirement : buildType.get().getRequirements()) {
if (requirementId.equals(requirement.getPropertyName())) {
LOG.debug("Found agent requirement by parameter name '" + requirementId + "' instead of id." + (requirement.getId() != null ? " This behavior is obsolete, use id (" + requirement.getId() + ") instead of parameter name." : ""));
return requirement;
}
}
throw new NotFoundException("Could not find agent requirement by id '" + requirementId + "' in " + buildType.getText() + " with id '" + buildType.getId() + "'");
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class ProjectFinder method findSingleItem.
@Nullable
@Override
public SProject findSingleItem(@NotNull final Locator locator) {
if (locator.isSingleValue()) {
// no dimensions found, assume it's a name or internal id or external id
SProject project = null;
@SuppressWarnings("ConstantConditions") @NotNull final String singleValue = locator.getSingleValue();
project = myProjectManager.findProjectByExternalId(singleValue);
if (project != null) {
return project;
}
final List<SProject> projectsByName = findProjectsByName(null, singleValue, true);
if (projectsByName.size() == 1) {
return projectsByName.get(0);
}
project = myProjectManager.findProjectById(singleValue);
if (project != null) {
return project;
}
throw new NotFoundException("No project found by name or internal/external id '" + singleValue + "'.");
}
String id = locator.getSingleDimensionValue(DIMENSION_ID);
if (id != null) {
SProject project = myProjectManager.findProjectByExternalId(id);
if (project == null) {
if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
project = myProjectManager.findProjectById(id);
if (project == null) {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "' in compatibility mode. Project cannot be found by external or internal id '" + id + "'.");
}
} else {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by external id '" + id + "'.");
}
}
return project;
}
String internalId = locator.getSingleDimensionValue(DIMENSION_INTERNAL_ID);
if (internalId != null) {
SProject project = myProjectManager.findProjectById(internalId);
if (project == null) {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by internal id '" + internalId + "'.");
}
return project;
}
String uuid = locator.getSingleDimensionValue(DIMENSION_UUID);
if (!StringUtil.isEmpty(uuid)) {
SProject project = myProjectManager.findProjectByConfigId(uuid);
if (project == null) {
// protecting against brute force uuid guessing
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by uuid '" + uuid + "'.");
}
return project;
}
String buildLocator = locator.getSingleDimensionValue(BUILD);
if (!StringUtil.isEmpty(buildLocator)) {
BuildPromotion build = myServiceLocator.getSingletonService(BuildPromotionFinder.class).getItem(buildLocator);
SBuildType buildType = build.getBuildType();
if (buildType != null) {
return buildType.getProject();
}
}
String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
if (!StringUtil.isEmpty(buildTypeLocator)) {
BuildTypeOrTemplate buildType = myServiceLocator.getSingletonService(BuildTypeFinder.class).getItem(buildTypeLocator);
return buildType.getProject();
}
String vcsRootLocator = locator.getSingleDimensionValue(VCS_ROOT);
if (!StringUtil.isEmpty(vcsRootLocator)) {
SVcsRoot vcsRoot = myServiceLocator.getSingletonService(VcsRootFinder.class).getItem(vcsRootLocator);
return vcsRoot.getProject();
}
return null;
}
Aggregations