mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Merge branch 'develop' into feature/packaging
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.MDC;
|
||||
import sonia.scm.api.v2.resources.ErrorDto;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.util.Collections;
|
||||
|
||||
@Provider
|
||||
public class InvalidFormatExceptionMapper implements ExceptionMapper<InvalidFormatException> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InvalidFormatExceptionMapper.class);
|
||||
|
||||
private static final String ERROR_CODE = "2qRyyaVcJ1";
|
||||
|
||||
@Override
|
||||
public Response toResponse(InvalidFormatException exception) {
|
||||
LOG.trace("got invalid format in json: {}", exception.getMessage());
|
||||
ErrorDto errorDto = new ErrorDto();
|
||||
errorDto.setMessage("invalid format in json content: " + exception.getMessage());
|
||||
errorDto.setContext(Collections.emptyList());
|
||||
errorDto.setErrorCode(ERROR_CODE);
|
||||
errorDto.setTransactionId(MDC.get("transaction_id"));
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(errorDto)
|
||||
.type(VndMediaType.ERROR_TYPE)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,11 @@
|
||||
* 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.github.sdorra.spotter.ContentTypes;
|
||||
import com.github.sdorra.spotter.Language;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.DiffFile;
|
||||
@@ -42,7 +41,7 @@ import java.util.OptionalInt;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
/**
|
||||
* TODO conflicts, copy and rename
|
||||
* TODO conflicts
|
||||
*/
|
||||
class DiffResultToDiffResultDtoMapper {
|
||||
|
||||
@@ -83,18 +82,29 @@ class DiffResultToDiffResultDtoMapper {
|
||||
String oldPath = file.getOldPath();
|
||||
|
||||
String path;
|
||||
if (isFilePath(newPath) && isFileNull(oldPath)) {
|
||||
path = newPath;
|
||||
dto.setType("add");
|
||||
} else if (isFileNull(newPath) && isFilePath(oldPath)) {
|
||||
path = oldPath;
|
||||
dto.setType("delete");
|
||||
} else if (isFilePath(newPath) && isFilePath(oldPath)) {
|
||||
path = newPath;
|
||||
dto.setType("modify");
|
||||
} else {
|
||||
// TODO copy and rename?
|
||||
throw new IllegalStateException("no file without path");
|
||||
switch (file.getChangeType()) {
|
||||
case ADD:
|
||||
path = newPath;
|
||||
dto.setType("add");
|
||||
break;
|
||||
case DELETE:
|
||||
path = oldPath;
|
||||
dto.setType("delete");
|
||||
break;
|
||||
case RENAME:
|
||||
path = newPath;
|
||||
dto.setType("rename");
|
||||
break;
|
||||
case MODIFY:
|
||||
path = newPath;
|
||||
dto.setType("modify");
|
||||
break;
|
||||
case COPY:
|
||||
path = newPath;
|
||||
dto.setType("copy");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown change type: " + file.getChangeType());
|
||||
}
|
||||
|
||||
dto.setNewPath(newPath);
|
||||
@@ -116,14 +126,6 @@ class DiffResultToDiffResultDtoMapper {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private boolean isFilePath(String path) {
|
||||
return !isFileNull(path);
|
||||
}
|
||||
|
||||
private boolean isFileNull(String path) {
|
||||
return Strings.isNullOrEmpty(path) || "/dev/null".equals(path);
|
||||
}
|
||||
|
||||
private DiffResultDto.HunkDto mapHunk(Hunk hunk) {
|
||||
DiffResultDto.HunkDto dto = new DiffResultDto.HunkDto();
|
||||
dto.setContent(hunk.getRawHeader());
|
||||
|
||||
@@ -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 de.otto.edison.hal.HalRepresentation;
|
||||
@@ -54,10 +54,21 @@ public class ModificationsDto extends HalRepresentation {
|
||||
*/
|
||||
private List<String> removed;
|
||||
|
||||
/**
|
||||
* Mapping of renamed files
|
||||
*/
|
||||
private List<RenamedDto> renamed;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("squid:S1185") // We want to have this method available in this package
|
||||
protected HalRepresentation add(Links links) {
|
||||
return super.add(links);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class RenamedDto {
|
||||
private String oldPath;
|
||||
private String newPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 de.otto.edison.hal.Links;
|
||||
@@ -30,7 +30,11 @@ import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.repository.Added;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Modified;
|
||||
import sonia.scm.repository.Removed;
|
||||
import sonia.scm.repository.Renamed;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -52,4 +56,18 @@ public abstract class ModificationsToDtoMapper {
|
||||
.self(resourceLinks.modifications().self(repository.getNamespace(), repository.getName(), target.getRevision()));
|
||||
target.add(linksBuilder.build());
|
||||
}
|
||||
|
||||
String map(Added added) {
|
||||
return added.getPath();
|
||||
}
|
||||
|
||||
String map(Removed removed) {
|
||||
return removed.getPath();
|
||||
}
|
||||
|
||||
String map(Modified modified) {
|
||||
return modified.getPath();
|
||||
}
|
||||
|
||||
abstract ModificationsDto.RenamedDto map(Renamed renamed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user