use of jetbrains.buildServer.vcs.SVcsRoot 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.vcs.SVcsRoot 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;
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class VcsRootFinder method findSingleItem.
@Nullable
@Override
public SVcsRoot findSingleItem(@NotNull final Locator locator) {
if (locator.isSingleValue()) {
// no dimensions found, assume it's an internal id or external id
return getVcsRootByExternalOrInternalId(locator.getSingleValue());
}
final String id = locator.getSingleDimensionValue(DIMENSION_ID);
if (id != null) {
SVcsRoot root;
if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
root = getVcsRootByExternalOrInternalId(id);
} else {
root = myProjectManager.findVcsRootByExternalId(id);
if (root == null) {
throw new NotFoundException("No VCS root can be found by id '" + id + "'.");
}
// todo: this and other invocations except for in getFilter can be removed as the filter is applied to all items
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
}
return root;
}
Long internalId = locator.getSingleDimensionValueAsLong(INTERNAL_ID);
if (internalId != null) {
SVcsRoot root = myVcsManager.findRootById(internalId);
if (root == null) {
throw new NotFoundException("No VCS root can be found by internal id '" + internalId + "'.");
}
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
return root;
}
String uuid = locator.getSingleDimensionValue(UUID);
if (uuid != null) {
final EntityId<Long> internalVCSRootId = myVcsRootIdentifiersManager.findEntityIdByConfigId(uuid);
if (internalVCSRootId != null) {
SVcsRoot root = myVcsManager.findRootById(internalVCSRootId.getInternalId());
if (root != null) {
checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
return root;
}
}
// protecting against brute force uuid guessing
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
throw new NotFoundException("No VCS root can be found by uuid '" + uuid + "'.");
}
return null;
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class VcsRootRequest method changeProperties.
@PUT
@Path("/{vcsRootLocator}/properties")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update all properties of the matching VCS root.", nickname = "setVcsRootProperties")
public Properties changeProperties(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, Properties properties, @QueryParam("fields") String fields) {
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
vcsRoot.setProperties(properties.getMap());
vcsRoot.schedulePersisting("VCS root changed");
return new Properties(vcsRoot.getProperties(), null, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class VcsRootRequest method setField.
@PUT
@Path("/{vcsRootLocator}/{field}")
@Consumes("text/plain")
@Produces("text/plain")
@ApiOperation(value = "Update a field of the matching VCS root.", nickname = "setVcsRootField")
public String setField(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @PathParam("field") String fieldName, String newValue) {
@NotNull final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
VcsRoot.setFieldValue(vcsRoot, fieldName, newValue, myProjectFinder);
vcsRoot.schedulePersisting("Field with name " + fieldName + " changed in VCS root");
return VcsRoot.getFieldValue(vcsRoot, fieldName, myDataProvider);
}
Aggregations