Merge with develop branch

This commit is contained in:
Sebastian Sdorra
2020-11-18 10:07:28 +01:00
80 changed files with 2147 additions and 220 deletions

View File

@@ -45,6 +45,6 @@ public class BranchChangesetCollectionToDtoMapper extends ChangesetCollectionToD
}
private String createSelfLink(Repository repository, String branch) {
return resourceLinks.branch().history(repository.getNamespaceAndName(), branch);
return resourceLinks.branch().history(repository.getNamespace(), repository.getName(), branch);
}
}

View File

@@ -30,7 +30,6 @@ import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Link;
import de.otto.edison.hal.Links;
import sonia.scm.repository.Branch;
import sonia.scm.repository.NamespaceAndName;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryPermissions;
@@ -55,11 +54,11 @@ public class BranchCollectionToDtoMapper {
public HalRepresentation map(Repository repository, Collection<Branch> branches) {
return new HalRepresentation(
createLinks(repository),
embedDtos(getBranchDtoList(repository.getNamespace(), repository.getName(), branches)));
embedDtos(getBranchDtoList(repository, branches)));
}
public List<BranchDto> getBranchDtoList(String namespace, String name, Collection<Branch> branches) {
return branches.stream().map(branch -> branchToDtoMapper.map(branch, new NamespaceAndName(namespace, name))).collect(toList());
public List<BranchDto> getBranchDtoList(Repository repository, Collection<Branch> branches) {
return branches.stream().map(branch -> branchToDtoMapper.map(branch, repository)).collect(toList());
}
private Links createLinks(Repository repository) {

View File

@@ -47,6 +47,7 @@ import sonia.scm.web.VndMediaType;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -57,6 +58,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.URI;
import java.util.Optional;
import static sonia.scm.AlreadyExistsException.alreadyExists;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@@ -132,7 +134,7 @@ public class BranchRootResource {
.stream()
.filter(branch -> branchName.equals(branch.getName()))
.findFirst()
.map(branch -> branchToDtoMapper.map(branch, namespaceAndName))
.map(branch -> branchToDtoMapper.map(branch, repositoryService.getRepository()))
.map(Response::ok)
.orElseThrow(() -> notFound(entity("branch", branchName).in(namespaceAndName)))
.build();
@@ -247,7 +249,7 @@ public class BranchRootResource {
branchCommand.from(parentName);
}
Branch newBranch = branchCommand.branch(branchName);
return Response.created(URI.create(resourceLinks.branch().self(namespaceAndName, newBranch.getName()))).build();
return Response.created(URI.create(resourceLinks.branch().self(namespace, name, newBranch.getName()))).build();
}
}
@@ -308,4 +310,50 @@ public class BranchRootResource {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
/**
* Deletes a branch.
*
* <strong>Note:</strong> This method requires "repository" privilege.
*
* @param branch the name of the branch to delete.
*/
@DELETE
@Path("{branch}")
@Operation(summary = "Delete branch", description = "Deletes the given branch.", tags = "Repository")
@ApiResponse(responseCode = "204", description = "delete success or nothing to delete")
@ApiResponse(responseCode = "400", description = "the default branch cannot be deleted")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user has no privileges to modify the repository")
@ApiResponse(
responseCode = "500",
description = "internal server error",
content = @Content(
mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class)
)
)
public Response delete(@PathParam("namespace") String namespace,
@PathParam("name") String name,
@PathParam("branch") String branch) {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
RepositoryPermissions.modify(repositoryService.getRepository()).check();
Optional<Branch> branchToBeDeleted = repositoryService.getBranchesCommand().getBranches().getBranches().stream()
.filter(b -> b.getName().equalsIgnoreCase(branch))
.findFirst();
if (branchToBeDeleted.isPresent()) {
if (branchToBeDeleted.get().isDefaultBranch()) {
return Response.status(400).build();
} else {
repositoryService.getBranchCommand().delete(branch);
}
}
} catch (IOException e) {
return Response.serverError().build();
}
return Response.noContent().build();
}
}

View File

@@ -32,6 +32,8 @@ import org.mapstruct.Mapping;
import org.mapstruct.ObjectFactory;
import sonia.scm.repository.Branch;
import sonia.scm.repository.NamespaceAndName;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryPermissions;
import sonia.scm.web.EdisonHalAppender;
import javax.inject.Inject;
@@ -46,16 +48,21 @@ public abstract class BranchToBranchDtoMapper extends HalAppenderMapper {
private ResourceLinks resourceLinks;
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
public abstract BranchDto map(Branch branch, @Context NamespaceAndName namespaceAndName);
public abstract BranchDto map(Branch branch, @Context Repository repository);
@ObjectFactory
BranchDto createDto(@Context NamespaceAndName namespaceAndName, Branch branch) {
BranchDto createDto(@Context Repository repository, Branch branch) {
NamespaceAndName namespaceAndName = new NamespaceAndName(repository.getNamespace(), repository.getName());
Links.Builder linksBuilder = linkingTo()
.self(resourceLinks.branch().self(namespaceAndName, branch.getName()))
.single(linkBuilder("history", resourceLinks.branch().history(namespaceAndName, branch.getName())).build())
.self(resourceLinks.branch().self(repository.getNamespace(), repository.getName(), branch.getName()))
.single(linkBuilder("history", resourceLinks.branch().history(repository.getNamespace(), repository.getName(), branch.getName())).build())
.single(linkBuilder("changeset", resourceLinks.changeset().changeset(namespaceAndName.getNamespace(), namespaceAndName.getName(), branch.getRevision())).build())
.single(linkBuilder("source", resourceLinks.source().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), branch.getRevision())).build());
if (!branch.isDefaultBranch() && RepositoryPermissions.modify(repository).isPermitted()) {
linksBuilder.single(linkBuilder("delete", resourceLinks.branch().delete(repository.getNamespace(), repository.getName(), branch.getName())).build());
}
Embedded.Builder embeddedBuilder = Embedded.embeddedBuilder();
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), branch, namespaceAndName);

View File

@@ -56,7 +56,7 @@ class ChangesetCollectionToDtoMapperBase extends PagedCollectionToDtoMapper<Chan
private BranchReferenceDto createBranchReferenceDto(Repository repository, String branchName) {
BranchReferenceDto branchReferenceDto = new BranchReferenceDto();
branchReferenceDto.setName(branchName);
branchReferenceDto.add(Links.linkingTo().self(resourceLinks.branch().self(repository.getNamespaceAndName(), branchName)).build());
branchReferenceDto.add(Links.linkingTo().self(resourceLinks.branch().self(repository.getNamespace(), repository.getName(), branchName)).build());
return branchReferenceDto;
}
}

View File

@@ -0,0 +1,49 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sonia.scm.util.ValidationUtil;
import javax.validation.constraints.Pattern;
import java.util.List;
/**
* This class is currently only used in the openapi scheme
*/
@Getter
@Setter
@NoArgsConstructor
public class CreateGroupDto {
@Pattern(regexp = ValidationUtil.REGEX_NAME)
private String name;
private String description;
private String type;
private List<String> members;
private boolean external;
}

View File

@@ -39,6 +39,6 @@ public class DefaultBranchLinkProvider implements BranchLinkProvider {
@Override
public String get(NamespaceAndName namespaceAndName, String branch) {
return resourceLinks.branch().self(namespaceAndName, branch);
return resourceLinks.branch().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), branch);
}
}

View File

@@ -132,7 +132,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
}
}
if (repositoryService.isSupported(Command.BRANCHES)) {
embeddedBuilder.with("branches", branchCollectionToDtoMapper.getBranchDtoList(namespace, name,
embeddedBuilder.with("branches", branchCollectionToDtoMapper.getBranchDtoList(repository,
getListOfObjects(source.getBranches(), branchName -> Branch.normalBranch(branchName, source.getId()))));
}

View File

@@ -34,20 +34,22 @@ import sonia.scm.ExceptionWithContext;
import java.util.Optional;
@Mapper
public abstract class ExceptionWithContextToErrorDtoMapper {
public interface ExceptionWithContextToErrorDtoMapper {
@Mapping(target = "errorCode", source = "code")
@Mapping(target = "transactionId", ignore = true)
@Mapping(target = "violations", ignore = true)
public abstract ErrorDto map(ExceptionWithContext exception);
ErrorDto map(ExceptionWithContext exception);
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") // is ok for mapping
public String mapOptional(Optional<String> optionalString) {
default String mapOptional(Optional<String> optionalString) {
return optionalString.orElse(null);
}
@AfterMapping
void setTransactionId(@MappingTarget ErrorDto dto) {
default void setTransactionId(@MappingTarget ErrorDto dto) {
dto.setTransactionId(MDC.get("transaction_id"));
}
ErrorDto.AdditionalMessageDto map(ExceptionWithContext.AdditionalMessage message);
}

View File

@@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import sonia.scm.group.Group;
import sonia.scm.group.GroupManager;
@@ -121,7 +123,30 @@ public class GroupCollectionResource {
@POST
@Path("")
@Consumes(VndMediaType.GROUP)
@Operation(summary = "Create group", description = "Creates a new group.", tags = "Group", operationId = "group_create")
@Operation(
summary = "Create group",
description = "Creates a new group.",
tags = "Group",
operationId = "group_create",
requestBody = @RequestBody(
content = @Content(
mediaType = VndMediaType.GROUP,
schema = @Schema(implementation = CreateGroupDto.class),
examples = {
@ExampleObject(
name = "Create an group with a description",
value = "{\n \"name\":\"manager\",\n \"description\":\"Manager group with full read access\"\n}",
summary = "Create a simple group"
),
@ExampleObject(
name = "Create an internal group with two members",
value = "{\n \"name\":\"Admins\",\n \"description\":\"SCM-Manager admins\",\n \"external\":false,\n \"members\":[\"scmadmin\",\"c.body\"]\n}",
summary = "Create group with members"
)
}
)
)
)
@ApiResponse(
responseCode = "201",
description = "create success",

View File

@@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import sonia.scm.security.PermissionAssigner;
import sonia.scm.security.PermissionDescriptor;
@@ -104,7 +106,22 @@ public class GroupPermissionResource {
@PUT
@Path("")
@Consumes(VndMediaType.PERMISSION_COLLECTION)
@Operation(summary = "Update Group permissions", description = "Sets permissions for a group. Overwrites all existing permissions.", tags = {"Group", "Permissions"})
@Operation(
summary = "Update Group permissions",
description = "Sets permissions for a group. Overwrites all existing permissions.",
tags = {"Group", "Permissions"},
requestBody = @RequestBody(
content = @Content(
mediaType = VndMediaType.PERMISSION_COLLECTION,
schema = @Schema(implementation = PermissionListDto.class),
examples = @ExampleObject(
name = "Add read permissions for all repositories and pull requests",
value = "{\n \"permissions\":[\"repository:read,pull:*\",\"repository:readPullRequest:*\"]\n}",
summary = "Simple update group permissions"
)
)
)
)
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "400", description = "invalid body")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@@ -116,6 +133,7 @@ public class GroupPermissionResource {
mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class)
))
@ApiResponse(responseCode = "409", description = "conflict, group has been modified concurrently")
@ApiResponse(
responseCode = "500",
description = "internal server error",

View File

@@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import sonia.scm.group.Group;
import sonia.scm.group.GroupManager;
@@ -135,7 +137,22 @@ public class GroupResource {
@PUT
@Path("")
@Consumes(VndMediaType.GROUP)
@Operation(summary = "Update group", description = "Modifies a group.", tags = "Group")
@Operation(
summary = "Update group",
description = "Modifies a group.",
tags = "Group",
requestBody = @RequestBody(
content = @Content(
mediaType = VndMediaType.GROUP,
schema = @Schema(implementation = UpdateGroupDto.class),
examples = @ExampleObject(
name = "Update a group description",
value = "{\n \"name\":\"manager\",\n \"description\":\"Group of managers with full read access\",\n \"lastModified\":\"2020-06-05T14:42:49.000Z\",\n \"type\":\"xml\"\n}",
summary = "Update a group"
)
)
)
)
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "400", description = "invalid body, e.g. illegal change of id/group name")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@@ -147,6 +164,7 @@ public class GroupResource {
mediaType = VndMediaType.ERROR_TYPE,
schema = @Schema(implementation = ErrorDto.class)
))
@ApiResponse(responseCode = "409", description = "conflict, group has been modified concurrently")
@ApiResponse(
responseCode = "500",
description = "internal server error",

View File

@@ -24,14 +24,14 @@
package sonia.scm.api.v2.resources;
import sonia.scm.repository.NamespaceAndName;
import sonia.scm.security.gpg.UserPublicKeyResource;
import javax.inject.Inject;
import java.net.URI;
import java.net.URISyntaxException;
@SuppressWarnings("squid:S1192") // string literals should not be duplicated
@SuppressWarnings("squid:S1192")
// string literals should not be duplicated
class ResourceLinks {
private final ScmPathInfoStore scmPathInfoStore;
@@ -273,13 +273,13 @@ class ResourceLinks {
}
AutoCompleteLinks autoComplete() {
return new AutoCompleteLinks (scmPathInfoStore.get());
return new AutoCompleteLinks(scmPathInfoStore.get());
}
static class AutoCompleteLinks {
static class AutoCompleteLinks {
private final LinkBuilder linkBuilder;
AutoCompleteLinks (ScmPathInfo pathInfo) {
AutoCompleteLinks(ScmPathInfo pathInfo) {
linkBuilder = new LinkBuilder(pathInfo, AutoCompleteResource.class);
}
@@ -485,17 +485,21 @@ class ResourceLinks {
branchLinkBuilder = new LinkBuilder(pathInfo, RepositoryRootResource.class, RepositoryResource.class, BranchRootResource.class);
}
String self(NamespaceAndName namespaceAndName, String branch) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespaceAndName.getNamespace(), namespaceAndName.getName()).method("branches").parameters().method("get").parameters(branch).href();
String self(String namespace, String name, String branch) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("branches").parameters().method("get").parameters(branch).href();
}
public String history(NamespaceAndName namespaceAndName, String branch) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespaceAndName.getNamespace(), namespaceAndName.getName()).method("branches").parameters().method("history").parameters(branch).href();
public String history(String namespace, String name, String branch) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("branches").parameters().method("history").parameters(branch).href();
}
public String create(String namespace, String name) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("branches").parameters().method("create").parameters().href();
}
public String delete(String namespace, String name, String branch) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("branches").parameters().method("delete").parameters(branch).href();
}
}
public IncomingLinks incoming() {
@@ -510,11 +514,11 @@ class ResourceLinks {
}
public String changesets(String namespace, String name) {
return toTemplateParams(incomingLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("incoming").parameters().method("incomingChangesets").parameters("source","target").href());
return toTemplateParams(incomingLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("incoming").parameters().method("incomingChangesets").parameters("source", "target").href());
}
public String changesets(String namespace, String name, String source, String target) {
return incomingLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("incoming").parameters().method("incomingChangesets").parameters(source,target).href();
return incomingLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("incoming").parameters().method("incomingChangesets").parameters(source, target).href();
}
public String diff(String namespace, String name) {
@@ -591,6 +595,7 @@ class ResourceLinks {
ModificationsLinks(ScmPathInfo pathInfo) {
modificationsLinkBuilder = new LinkBuilder(pathInfo, RepositoryRootResource.class, RepositoryResource.class, ModificationsRootResource.class);
}
String self(String namespace, String name, String revision) {
return modificationsLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("modifications").parameters().method("get").parameters(revision).href();
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import org.mapstruct.AfterMapping;
@@ -32,46 +32,29 @@ import org.slf4j.MDC;
import sonia.scm.ScmConstraintViolationException;
import sonia.scm.ScmConstraintViolationException.ScmConstraintViolation;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public abstract class ScmViolationExceptionToErrorDtoMapper {
public interface ScmViolationExceptionToErrorDtoMapper {
@Mapping(target = "errorCode", ignore = true)
@Mapping(target = "transactionId", ignore = true)
@Mapping(target = "context", ignore = true)
public abstract ErrorDto map(ScmConstraintViolationException exception);
ErrorDto map(ScmConstraintViolationException exception);
@AfterMapping
void setTransactionId(@MappingTarget ErrorDto dto) {
default void setTransactionId(@MappingTarget ErrorDto dto) {
dto.setTransactionId(MDC.get("transaction_id"));
}
@AfterMapping
void mapViolations(ScmConstraintViolationException exception, @MappingTarget ErrorDto dto) {
List<ErrorDto.ConstraintViolationDto> violations =
exception.getViolations()
.stream()
.map(this::createViolationDto)
.collect(Collectors.toList());
dto.setViolations(violations);
}
private ErrorDto.ConstraintViolationDto createViolationDto(ScmConstraintViolation violation) {
ErrorDto.ConstraintViolationDto constraintViolationDto = new ErrorDto.ConstraintViolationDto();
constraintViolationDto.setMessage(violation.getMessage());
constraintViolationDto.setPath(violation.getPropertyPath());
return constraintViolationDto;
}
@Mapping(source = "propertyPath", target = "path")
ErrorDto.ConstraintViolationDto map(ScmConstraintViolation violation);
@AfterMapping
void setErrorCode(@MappingTarget ErrorDto dto) {
default void setErrorCode(@MappingTarget ErrorDto dto) {
dto.setErrorCode("3zR9vPNIE1");
}
@AfterMapping
void setMessage(@MappingTarget ErrorDto dto) {
default void setMessage(@MappingTarget ErrorDto dto) {
dto.setMessage("input violates conditions (see violation list)");
}
}

View File

@@ -0,0 +1,53 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sonia.scm.util.ValidationUtil;
import javax.validation.constraints.Pattern;
import java.time.Instant;
import java.util.List;
/**
* This class is currently only used in the openapi scheme
*/
@Getter
@Setter
@NoArgsConstructor
public class UpdateGroupDto {
@Pattern(regexp = ValidationUtil.REGEX_NAME)
private String name;
private String description;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Instant lastModified;
private String type;
private List<String> members;
private boolean external;
}

View File

@@ -52,6 +52,7 @@ import java.io.OutputStream;
import java.net.*;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
@@ -206,7 +207,7 @@ public class DefaultAdvancedHttpClient extends AdvancedHttpClient
try {
DefaultAdvancedHttpResponse response = doRequest(request);
span.label("status", response.getStatus());
if (!response.isSuccessful()) {
if (isFailedRequest(request, response)) {
span.failed();
}
return response;
@@ -219,6 +220,13 @@ public class DefaultAdvancedHttpClient extends AdvancedHttpClient
}
}
private boolean isFailedRequest(BaseHttpRequest<?> request, AdvancedHttpResponse responseStatus) {
if (Arrays.stream(request.getAcceptedStatus()).anyMatch(code -> code == responseStatus.getStatus())) {
return false;
}
return !responseStatus.isSuccessful();
}
@Nonnull
private DefaultAdvancedHttpResponse doRequest(BaseHttpRequest<?> request) throws IOException {
HttpURLConnection connection = openConnection(request, new URL(request.getUrl()));