use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class Group method setGroupParents.
public static void setGroupParents(@NotNull final SUserGroup group, @NotNull final Set<SUserGroup> newParents, final boolean revertOnError, @NotNull final ServiceLocator serviceLocator) {
// workaround for TW-52253
serviceLocator.getSingletonService(PermissionChecker.class).getServerActionChecker().checkCanEditUserGroup(group);
Set<SUserGroup> currentParents = group.getParentGroups().stream().map(userGroup -> (SUserGroup) userGroup).collect(Collectors.toSet());
currentParents.stream().filter(userGroup -> !newParents.contains(userGroup)).forEach(userGroup -> userGroup.removeSubgroup(group));
try {
newParents.stream().filter(userGroup -> !currentParents.contains(userGroup)).forEach(userGroup -> userGroup.addSubgroup(group));
} catch (CycleDetectedException e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw new BadRequestException("Error encountered while trying to set new parent groups", e);
} catch (AccessDeniedException e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw e;
} catch (Exception e) {
if (revertOnError)
setGroupParents(group, currentParents, false, serviceLocator);
throw new OperationException("Error encountered while trying to set new parent groups", e);
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class Project method setFieldValueAndPersist.
public static void setFieldValueAndPersist(final SProject project, final String field, final String value, @NotNull final ServiceLocator serviceLocator) {
if ("name".equals(field)) {
if (StringUtil.isEmpty(value)) {
throw new BadRequestException("Project name cannot be empty.");
}
project.setName(value);
project.schedulePersisting("Project name changed");
return;
} else if ("id".equals(field)) {
if (StringUtil.isEmpty(value)) {
throw new BadRequestException("Project id cannot be empty.");
}
project.setExternalId(value);
return;
} else if ("description".equals(field)) {
project.setDescription(value);
project.schedulePersisting("Project description changed");
return;
} else if ("archived".equals(field)) {
project.setArchived(Boolean.parseBoolean(value), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser());
return;
} else if ("readOnlyUI".equals(field) && TeamCityProperties.getBoolean("rest.projectRequest.allowSetReadOnlyUI")) {
boolean editable = !Boolean.parseBoolean(value);
((ProjectEx) project).setEditable(editable);
project.schedulePersisting("Project editing is " + (editable ? "enabled" : "disabled"));
return;
}
throw new BadRequestException("Setting field '" + field + "' is not supported. Supported are: name, description, archived");
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class PropEntitiesProjectFeature method setTo.
public boolean setTo(@NotNull final SProject project, @NotNull final ServiceLocator serviceLocator) {
Storage original = new Storage(project);
removeAll(project);
try {
if (propEntities != null) {
for (PropEntityProjectFeature entity : propEntities) {
entity.addToInternal(project, serviceLocator);
}
}
return true;
} catch (Exception e) {
original.apply(project);
throw new BadRequestException("Error replacing items", e);
}
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class ProjectRequest method createEmptyBuildType.
@POST
@Path("/{projectLocator}/buildTypes")
@Produces({ "application/xml", "application/json" })
@Consumes({ "text/plain" })
@ApiOperation(hidden = true, value = "Use createBuildType instead")
public BuildType createEmptyBuildType(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, String name, @QueryParam("fields") String fields) {
SProject project = myProjectFinder.getItem(projectLocator);
if (StringUtil.isEmpty(name)) {
throw new BadRequestException("Build type name cannot be empty.");
}
final SBuildType buildType = project.createBuildType(name);
buildType.schedulePersisting("A new build configuration is created");
return new BuildType(new BuildTypeOrTemplate(buildType), new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.server.rest.errors.BadRequestException in project teamcity-rest by JetBrains.
the class ProjectRequest method createEmptyBuildTypeTemplate.
@POST
@Path("/{projectLocator}/templates")
@Produces({ "application/xml", "application/json" })
@Consumes({ "text/plain" })
@ApiOperation(hidden = true, value = "Use createBuildTypeTemplate instead")
public BuildType createEmptyBuildTypeTemplate(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, String name, @QueryParam("fields") String fields) {
SProject project = myProjectFinder.getItem(projectLocator, true);
if (StringUtil.isEmpty(name)) {
throw new BadRequestException("Build type template name cannot be empty.");
}
final BuildTypeTemplate buildType = project.createBuildTypeTemplate(name);
buildType.schedulePersisting("A new build configuration template is created");
return new BuildType(new BuildTypeOrTemplate(buildType), new Fields(fields), myBeanContext);
}
Aggregations