mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-05 03:40:56 +01:00
rollback changes on branches overview
This commit is contained in:
@@ -52,14 +52,14 @@ public class BranchCollectionToDtoMapper {
|
||||
this.branchToDtoMapper = branchToDtoMapper;
|
||||
}
|
||||
|
||||
public HalRepresentation map(Repository repository, Collection<Branch> branches, boolean fullInformation) {
|
||||
public HalRepresentation map(Repository repository, Collection<Branch> branches) {
|
||||
return new HalRepresentation(
|
||||
createLinks(repository),
|
||||
embedDtos(getBranchDtoList(repository.getNamespace(), repository.getName(), branches, fullInformation)));
|
||||
embedDtos(getBranchDtoList(repository.getNamespace(), repository.getName(), branches)));
|
||||
}
|
||||
|
||||
public List<BranchDto> getBranchDtoList(String namespace, String name, Collection<Branch> branches, boolean fullInformation) {
|
||||
return branches.stream().map(branch -> branchToDtoMapper.map(branch, new NamespaceAndName(namespace, name), fullInformation)).collect(toList());
|
||||
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());
|
||||
}
|
||||
|
||||
private Links createLinks(Repository repository) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Links;
|
||||
@@ -35,11 +34,11 @@ import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@SuppressWarnings("java:S2160") // we do not need this for dto
|
||||
public class BranchDto extends HalRepresentation {
|
||||
|
||||
private static final String VALID_CHARACTERS_AT_START_AND_END = "\\w-,;\\]{}@&+=$#`|<>";
|
||||
@@ -52,10 +51,6 @@ public class BranchDto extends HalRepresentation {
|
||||
private String name;
|
||||
private String revision;
|
||||
private boolean defaultBranch;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Instant lastModified;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private PersonDto lastModifier;
|
||||
|
||||
BranchDto(Links links, Embedded embedded) {
|
||||
super(links, embedded);
|
||||
|
||||
@@ -133,7 +133,7 @@ public class BranchRootResource {
|
||||
.stream()
|
||||
.filter(branch -> branchName.equals(branch.getName()))
|
||||
.findFirst()
|
||||
.map(branch -> branchToDtoMapper.map(branch, namespaceAndName, fullInformation))
|
||||
.map(branch -> branchToDtoMapper.map(branch, namespaceAndName))
|
||||
.map(Response::ok)
|
||||
.orElseThrow(() -> notFound(entity("branch", branchName).in(namespaceAndName)))
|
||||
.build();
|
||||
@@ -300,12 +300,11 @@ public class BranchRootResource {
|
||||
))
|
||||
public Response getAll(
|
||||
@PathParam("namespace") String namespace,
|
||||
@PathParam("name") String name,
|
||||
@QueryParam("fullInformation") @DefaultValue("false") boolean fullInformation
|
||||
@PathParam("name") String name
|
||||
) throws IOException {
|
||||
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
||||
Branches branches = repositoryService.getBranchesCommand().getBranches();
|
||||
return Response.ok(branchCollectionToDtoMapper.map(repositoryService.getRepository(), branches.getBranches(), fullInformation)).build();
|
||||
return Response.ok(branchCollectionToDtoMapper.map(repositoryService.getRepository(), branches.getBranches())).build();
|
||||
} catch (CommandNotSupportedException ex) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
@@ -30,19 +30,11 @@ import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.web.EdisonHalAppender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
import static de.otto.edison.hal.Link.linkBuilder;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
@@ -53,16 +45,11 @@ public abstract class BranchToBranchDtoMapper extends HalAppenderMapper {
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
@Inject
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
public abstract BranchDto map(Branch branch, @Context NamespaceAndName namespaceAndName, boolean fullInformation);
|
||||
|
||||
abstract PersonDto map(Person person);
|
||||
public abstract BranchDto map(Branch branch, @Context NamespaceAndName namespaceAndName);
|
||||
|
||||
@ObjectFactory
|
||||
BranchDto createDto(@Context NamespaceAndName namespaceAndName, Branch branch, boolean fullInformation) {
|
||||
BranchDto createDto(@Context NamespaceAndName namespaceAndName, Branch branch) {
|
||||
Links.Builder linksBuilder = linkingTo()
|
||||
.self(resourceLinks.branch().self(namespaceAndName, branch.getName()))
|
||||
.single(linkBuilder("history", resourceLinks.branch().history(namespaceAndName, branch.getName())).build())
|
||||
@@ -71,22 +58,7 @@ public abstract class BranchToBranchDtoMapper extends HalAppenderMapper {
|
||||
|
||||
Embedded.Builder embeddedBuilder = Embedded.embeddedBuilder();
|
||||
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), branch, namespaceAndName);
|
||||
BranchDto branchDto = new BranchDto(linksBuilder.build(), embeddedBuilder.build());
|
||||
|
||||
if (fullInformation) {
|
||||
try (RepositoryService service = serviceFactory.create(namespaceAndName)) {
|
||||
Changeset latestChangeset = service.getLogCommand().setBranch(branch.getName()).getChangesets().getChangesets().get(0);
|
||||
branchDto.setLastModified(Instant.ofEpochMilli(latestChangeset.getDate()));
|
||||
branchDto.setLastModifier(map(latestChangeset.getAuthor()));
|
||||
} catch (IOException e) {
|
||||
throw new InternalRepositoryException(
|
||||
ContextEntry.ContextBuilder.entity(Branch.class, branch.getName()),
|
||||
"Could not read latest changeset for branch",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return branchDto;
|
||||
return new BranchDto(linksBuilder.build(), embeddedBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
|
||||
}
|
||||
if (repositoryService.isSupported(Command.BRANCHES)) {
|
||||
embeddedBuilder.with("branches", branchCollectionToDtoMapper.getBranchDtoList(namespace, name,
|
||||
getListOfObjects(source.getBranches(), branchName -> Branch.normalBranch(branchName, source.getId())), false));
|
||||
getListOfObjects(source.getBranches(), branchName -> Branch.normalBranch(branchName, source.getId()))));
|
||||
}
|
||||
|
||||
if (repositoryService.isSupported(Command.DIFF_RESULT)) {
|
||||
|
||||
Reference in New Issue
Block a user