mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
package sonia.scm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class BadRequestException extends ExceptionWithContext {
|
||||||
|
public BadRequestException(List<ContextEntry> context, String message) {
|
||||||
|
super(context, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,13 +40,14 @@ import java.util.Collections;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @version 1.6
|
* @version 1.6
|
||||||
*/
|
*/
|
||||||
public class NotSupportedFeatureException extends ExceptionWithContext {
|
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
|
||||||
|
public class FeatureNotSupportedException extends BadRequestException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 256498734456613496L;
|
private static final long serialVersionUID = 256498734456613496L;
|
||||||
|
|
||||||
private static final String CODE = "9SR8G0kmU1";
|
private static final String CODE = "9SR8G0kmU1";
|
||||||
|
|
||||||
public NotSupportedFeatureException(String feature)
|
public FeatureNotSupportedException(String feature)
|
||||||
{
|
{
|
||||||
super(Collections.emptyList(),createMessage(feature));
|
super(Collections.emptyList(),createMessage(feature));
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ package sonia.scm.repository;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
import sonia.scm.FeatureNotSupportedException;
|
||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
|
|
||||||
@@ -167,12 +167,12 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws NotSupportedFeatureException
|
* @throws FeatureNotSupportedException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ImportHandler getImportHandler()
|
public ImportHandler getImportHandler()
|
||||||
{
|
{
|
||||||
throw new NotSupportedFeatureException("import");
|
throw new FeatureNotSupportedException("import");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.Handler;
|
import sonia.scm.Handler;
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
import sonia.scm.FeatureNotSupportedException;
|
||||||
import sonia.scm.plugin.ExtensionPoint;
|
import sonia.scm.plugin.ExtensionPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,9 +59,9 @@ public interface RepositoryHandler
|
|||||||
* @return {@link ImportHandler} for the repository type of this handler
|
* @return {@link ImportHandler} for the repository type of this handler
|
||||||
* @since 1.12
|
* @since 1.12
|
||||||
*
|
*
|
||||||
* @throws NotSupportedFeatureException
|
* @throws FeatureNotSupportedException
|
||||||
*/
|
*/
|
||||||
public ImportHandler getImportHandler() throws NotSupportedFeatureException;
|
public ImportHandler getImportHandler() throws FeatureNotSupportedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns informations about the version of the RepositoryHandler.
|
* Returns informations about the version of the RepositoryHandler.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ package sonia.scm.repository.api;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
import sonia.scm.FeatureNotSupportedException;
|
||||||
import sonia.scm.repository.Feature;
|
import sonia.scm.repository.Feature;
|
||||||
import sonia.scm.repository.spi.DiffCommand;
|
import sonia.scm.repository.spi.DiffCommand;
|
||||||
import sonia.scm.repository.spi.DiffCommandRequest;
|
import sonia.scm.repository.spi.DiffCommandRequest;
|
||||||
@@ -203,7 +203,7 @@ public final class DiffCommandBuilder
|
|||||||
public DiffCommandBuilder setAncestorChangeset(String revision)
|
public DiffCommandBuilder setAncestorChangeset(String revision)
|
||||||
{
|
{
|
||||||
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
||||||
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
|
throw new FeatureNotSupportedException(Feature.INCOMING_REVISION.name());
|
||||||
}
|
}
|
||||||
request.setAncestorChangeset(revision);
|
request.setAncestorChangeset(revision);
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import com.google.common.base.Objects;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
import sonia.scm.FeatureNotSupportedException;
|
||||||
import sonia.scm.cache.Cache;
|
import sonia.scm.cache.Cache;
|
||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
@@ -410,7 +410,7 @@ public final class LogCommandBuilder
|
|||||||
*/
|
*/
|
||||||
public LogCommandBuilder setAncestorChangeset(String ancestorChangeset) {
|
public LogCommandBuilder setAncestorChangeset(String ancestorChangeset) {
|
||||||
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
if (!supportedFeatures.contains(Feature.INCOMING_REVISION)) {
|
||||||
throw new NotSupportedFeatureException(Feature.INCOMING_REVISION.name());
|
throw new FeatureNotSupportedException(Feature.INCOMING_REVISION.name());
|
||||||
}
|
}
|
||||||
request.setAncestorChangeset(ancestorChangeset);
|
request.setAncestorChangeset(ancestorChangeset);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
|
|
||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfigurationStore for configuration objects. <strong>Note:</strong> the default
|
* ConfigurationStore for configuration objects. <strong>Note:</strong> the default
|
||||||
* implementation use JAXB to marshall the configuration objects.
|
* implementation use JAXB to marshall the configuration objects.
|
||||||
@@ -50,7 +54,17 @@ public interface ConfigurationStore<T>
|
|||||||
*
|
*
|
||||||
* @return configuration object from store
|
* @return configuration object from store
|
||||||
*/
|
*/
|
||||||
public T get();
|
T get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the configuration object from store.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return configuration object from store
|
||||||
|
*/
|
||||||
|
default Optional<T> getOptional() {
|
||||||
|
return ofNullable(get());
|
||||||
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
@@ -60,5 +74,5 @@ public interface ConfigurationStore<T>
|
|||||||
*
|
*
|
||||||
* @param object configuration object to store
|
* @param object configuration object to store
|
||||||
*/
|
*/
|
||||||
public void set(T object);
|
void set(T object);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for {@link BlobStore} and {@link DataStore}.
|
* Base class for {@link BlobStore} and {@link DataStore}.
|
||||||
*
|
*
|
||||||
@@ -67,4 +71,16 @@ public interface MultiEntryStore<T> {
|
|||||||
* @return item with the given id
|
* @return item with the given id
|
||||||
*/
|
*/
|
||||||
public T get(String id);
|
public T get(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the item with the given id from the store.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param id id of the item to return
|
||||||
|
*
|
||||||
|
* @return item with the given id
|
||||||
|
*/
|
||||||
|
default Optional<T> getOptional(String id) {
|
||||||
|
return ofNullable(get(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package sonia.scm.user;
|
package sonia.scm.user;
|
||||||
|
|
||||||
|
import sonia.scm.BadRequestException;
|
||||||
import sonia.scm.ContextEntry;
|
import sonia.scm.ContextEntry;
|
||||||
import sonia.scm.ExceptionWithContext;
|
|
||||||
|
|
||||||
public class ChangePasswordNotAllowedException extends ExceptionWithContext {
|
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
|
||||||
|
public class ChangePasswordNotAllowedException extends BadRequestException {
|
||||||
|
|
||||||
private static final String CODE = "9BR7qpDAe1";
|
private static final String CODE = "9BR7qpDAe1";
|
||||||
public static final String WRONG_USER_TYPE = "User of type %s are not allowed to change password";
|
public static final String WRONG_USER_TYPE = "Users of type %s are not allowed to change password";
|
||||||
|
|
||||||
public ChangePasswordNotAllowedException(ContextEntry.ContextBuilder context, String type) {
|
public ChangePasswordNotAllowedException(ContextEntry.ContextBuilder context, String type) {
|
||||||
super(context.build(), String.format(WRONG_USER_TYPE, type));
|
super(context.build(), String.format(WRONG_USER_TYPE, type));
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package sonia.scm.user;
|
package sonia.scm.user;
|
||||||
|
|
||||||
|
import sonia.scm.BadRequestException;
|
||||||
import sonia.scm.ContextEntry;
|
import sonia.scm.ContextEntry;
|
||||||
import sonia.scm.ExceptionWithContext;
|
|
||||||
|
|
||||||
public class InvalidPasswordException extends ExceptionWithContext {
|
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
|
||||||
|
public class InvalidPasswordException extends BadRequestException {
|
||||||
|
|
||||||
private static final String CODE = "8YR7aawFW1";
|
private static final String CODE = "8YR7aawFW1";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package sonia.scm.web;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
|
import static sonia.scm.web.VndMediaType.REPOSITORY;
|
||||||
|
import static sonia.scm.web.VndMediaType.REPOSITORY_COLLECTION;
|
||||||
|
|
||||||
|
public abstract class AbstractRepositoryJsonEnricher extends JsonEnricherBase {
|
||||||
|
|
||||||
|
public AbstractRepositoryJsonEnricher(ObjectMapper objectMapper) {
|
||||||
|
super(objectMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enrich(JsonEnricherContext context) {
|
||||||
|
if (resultHasMediaType(REPOSITORY, context)) {
|
||||||
|
JsonNode repositoryNode = context.getResponseEntity();
|
||||||
|
enrichRepositoryNode(repositoryNode);
|
||||||
|
} else if (resultHasMediaType(REPOSITORY_COLLECTION, context)) {
|
||||||
|
JsonNode repositoryCollectionNode = context.getResponseEntity().get("_embedded").withArray("repositories");
|
||||||
|
repositoryCollectionNode.elements().forEachRemaining(this::enrichRepositoryNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enrichRepositoryNode(JsonNode repositoryNode) {
|
||||||
|
String namespace = repositoryNode.get("namespace").asText();
|
||||||
|
String name = repositoryNode.get("name").asText();
|
||||||
|
|
||||||
|
enrichRepositoryNode(repositoryNode, namespace, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void enrichRepositoryNode(JsonNode repositoryNode, String namespace, String name);
|
||||||
|
|
||||||
|
protected void addLink(JsonNode repositoryNode, String linkName, String link) {
|
||||||
|
JsonNode hrefNode = createObject(singletonMap("href", value(link)));
|
||||||
|
addPropertyNode(repositoryNode.get("_links"), linkName, hrefNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package sonia.scm.web;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.google.common.io.Resources;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class AbstractRepositoryJsonEnricherTest {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
private AbstractRepositoryJsonEnricher linkEnricher;
|
||||||
|
private JsonNode rootNode;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void globalSetUp() {
|
||||||
|
ScmPathInfoStore pathInfoStore = new ScmPathInfoStore();
|
||||||
|
pathInfoStore.set(() -> URI.create("/"));
|
||||||
|
|
||||||
|
linkEnricher = new AbstractRepositoryJsonEnricher(objectMapper) {
|
||||||
|
@Override
|
||||||
|
protected void enrichRepositoryNode(JsonNode repositoryNode, String namespace, String name) {
|
||||||
|
addLink(repositoryNode, "new-link", "/somewhere");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldEnrichRepositories() throws IOException {
|
||||||
|
URL resource = Resources.getResource("sonia/scm/repository/repository-001.json");
|
||||||
|
rootNode = objectMapper.readTree(resource);
|
||||||
|
|
||||||
|
JsonEnricherContext context = new JsonEnricherContext(
|
||||||
|
URI.create("/"),
|
||||||
|
MediaType.valueOf(VndMediaType.REPOSITORY),
|
||||||
|
rootNode
|
||||||
|
);
|
||||||
|
|
||||||
|
linkEnricher.enrich(context);
|
||||||
|
|
||||||
|
String configLink = context.getResponseEntity()
|
||||||
|
.get("_links")
|
||||||
|
.get("new-link")
|
||||||
|
.get("href")
|
||||||
|
.asText();
|
||||||
|
|
||||||
|
assertThat(configLink).isEqualTo("/somewhere");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldEnrichAllRepositories() throws IOException {
|
||||||
|
URL resource = Resources.getResource("sonia/scm/repository/repository-collection-001.json");
|
||||||
|
rootNode = objectMapper.readTree(resource);
|
||||||
|
|
||||||
|
JsonEnricherContext context = new JsonEnricherContext(
|
||||||
|
URI.create("/"),
|
||||||
|
MediaType.valueOf(VndMediaType.REPOSITORY_COLLECTION),
|
||||||
|
rootNode
|
||||||
|
);
|
||||||
|
|
||||||
|
linkEnricher.enrich(context);
|
||||||
|
|
||||||
|
context.getResponseEntity()
|
||||||
|
.get("_embedded")
|
||||||
|
.withArray("repositories")
|
||||||
|
.elements()
|
||||||
|
.forEachRemaining(node -> {
|
||||||
|
String configLink = node
|
||||||
|
.get("_links")
|
||||||
|
.get("new-link")
|
||||||
|
.get("href")
|
||||||
|
.asText();
|
||||||
|
|
||||||
|
assertThat(configLink).isEqualTo("/somewhere");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotModifyObjectsWithUnsupportedMediaType() throws IOException {
|
||||||
|
URL resource = Resources.getResource("sonia/scm/repository/repository-001.json");
|
||||||
|
rootNode = objectMapper.readTree(resource);
|
||||||
|
JsonEnricherContext context = new JsonEnricherContext(
|
||||||
|
URI.create("/"),
|
||||||
|
MediaType.valueOf(VndMediaType.USER),
|
||||||
|
rootNode
|
||||||
|
);
|
||||||
|
|
||||||
|
linkEnricher.enrich(context);
|
||||||
|
|
||||||
|
boolean hasNewPullRequestLink = context.getResponseEntity()
|
||||||
|
.get("_links")
|
||||||
|
.has("new-link");
|
||||||
|
|
||||||
|
assertThat(hasNewPullRequestLink).isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"creationDate": "2018-11-09T09:48:32.732Z",
|
||||||
|
"description": "Handling static webresources made easy",
|
||||||
|
"healthCheckFailures": [],
|
||||||
|
"lastModified": "2018-11-09T09:49:20.973Z",
|
||||||
|
"namespace": "scmadmin",
|
||||||
|
"name": "web-resources",
|
||||||
|
"archived": false,
|
||||||
|
"type": "git",
|
||||||
|
"_links": {
|
||||||
|
"self": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"update": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/permissions/"
|
||||||
|
},
|
||||||
|
"protocol": [
|
||||||
|
{
|
||||||
|
"href": "http://localhost:8081/scm/repo/scmadmin/web-resources",
|
||||||
|
"name": "http"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tags": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/tags/"
|
||||||
|
},
|
||||||
|
"branches": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/branches/"
|
||||||
|
},
|
||||||
|
"changesets": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/changesets/"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/sources/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
{
|
||||||
|
"page": 0,
|
||||||
|
"pageTotal": 1,
|
||||||
|
"_links": {
|
||||||
|
"self": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/?page=0&pageSize=10"
|
||||||
|
},
|
||||||
|
"first": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/?page=0&pageSize=10"
|
||||||
|
},
|
||||||
|
"last": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/?page=0&pageSize=10"
|
||||||
|
},
|
||||||
|
"create": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"_embedded": {
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"creationDate": "2018-11-09T09:48:32.732Z",
|
||||||
|
"description": "Handling static webresources made easy",
|
||||||
|
"healthCheckFailures": [],
|
||||||
|
"lastModified": "2018-11-09T09:49:20.973Z",
|
||||||
|
"namespace": "scmadmin",
|
||||||
|
"name": "web-resources",
|
||||||
|
"archived": false,
|
||||||
|
"type": "git",
|
||||||
|
"_links": {
|
||||||
|
"self": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"update": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/permissions/"
|
||||||
|
},
|
||||||
|
"protocol": [
|
||||||
|
{
|
||||||
|
"href": "http://localhost:8081/scm/repo/scmadmin/web-resources",
|
||||||
|
"name": "http"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tags": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/tags/"
|
||||||
|
},
|
||||||
|
"branches": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/branches/"
|
||||||
|
},
|
||||||
|
"changesets": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/changesets/"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/sources/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"creationDate": "2018-11-09T09:48:32.732Z",
|
||||||
|
"description": "Handling static webresources made easy",
|
||||||
|
"healthCheckFailures": [],
|
||||||
|
"lastModified": "2018-11-09T09:49:20.973Z",
|
||||||
|
"namespace": "scmadmin",
|
||||||
|
"name": "web-resources",
|
||||||
|
"archived": false,
|
||||||
|
"type": "git",
|
||||||
|
"_links": {
|
||||||
|
"self": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"update": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources"
|
||||||
|
},
|
||||||
|
"permissions": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/permissions/"
|
||||||
|
},
|
||||||
|
"protocol": [
|
||||||
|
{
|
||||||
|
"href": "http://localhost:8081/scm/repo/scmadmin/web-resources",
|
||||||
|
"name": "http"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tags": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/tags/"
|
||||||
|
},
|
||||||
|
"branches": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/branches/"
|
||||||
|
},
|
||||||
|
"changesets": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/changesets/"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"href": "http://localhost:8081/scm/api/v2/repositories/scmadmin/web-resources/sources/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package sonia.scm.api.rest;
|
||||||
|
|
||||||
|
import sonia.scm.BadRequestException;
|
||||||
|
import sonia.scm.api.v2.resources.ExceptionWithContextToErrorDtoMapper;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
public class BadRequestExceptionMapper extends ContextualExceptionMapper<BadRequestException> {
|
||||||
|
@Inject
|
||||||
|
public BadRequestExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
|
||||||
|
super(BadRequestException.class, Response.Status.BAD_REQUEST, mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ import org.apache.shiro.SecurityUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.NotFoundException;
|
import sonia.scm.NotFoundException;
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
import sonia.scm.FeatureNotSupportedException;
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
import sonia.scm.api.rest.RestActionUploadResult;
|
import sonia.scm.api.rest.RestActionUploadResult;
|
||||||
import sonia.scm.api.v2.resources.RepositoryResource;
|
import sonia.scm.api.v2.resources.RepositoryResource;
|
||||||
@@ -394,7 +394,7 @@ public class RepositoryImportResource
|
|||||||
|
|
||||||
response = Response.ok(result).build();
|
response = Response.ok(result).build();
|
||||||
}
|
}
|
||||||
catch (NotSupportedFeatureException ex)
|
catch (FeatureNotSupportedException ex)
|
||||||
{
|
{
|
||||||
logger
|
logger
|
||||||
.warn(
|
.warn(
|
||||||
@@ -609,7 +609,7 @@ public class RepositoryImportResource
|
|||||||
types.add(t);
|
types.add(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NotSupportedFeatureException ex)
|
catch (FeatureNotSupportedException ex)
|
||||||
{
|
{
|
||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
{
|
{
|
||||||
@@ -711,7 +711,7 @@ public class RepositoryImportResource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NotSupportedFeatureException ex)
|
catch (FeatureNotSupportedException ex)
|
||||||
{
|
{
|
||||||
throw new WebApplicationException(ex, Response.Status.BAD_REQUEST);
|
throw new WebApplicationException(ex, Response.Status.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package sonia.scm.api.v2;
|
|
||||||
|
|
||||||
import sonia.scm.NotSupportedFeatureException;
|
|
||||||
import sonia.scm.api.rest.ContextualExceptionMapper;
|
|
||||||
import sonia.scm.api.v2.resources.ExceptionWithContextToErrorDtoMapper;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
public class NotSupportedFeatureExceptionMapper extends ContextualExceptionMapper<NotSupportedFeatureException> {
|
|
||||||
@Inject
|
|
||||||
public NotSupportedFeatureExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
|
|
||||||
super(NotSupportedFeatureException.class, Response.Status.BAD_REQUEST, mapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
|
||||||
|
|
||||||
import sonia.scm.api.rest.ContextualExceptionMapper;
|
|
||||||
import sonia.scm.user.ChangePasswordNotAllowedException;
|
|
||||||
import sonia.scm.user.InvalidPasswordException;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
public class ChangePasswordNotAllowedExceptionMapper extends ContextualExceptionMapper<ChangePasswordNotAllowedException> {
|
|
||||||
@Inject
|
|
||||||
public ChangePasswordNotAllowedExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
|
|
||||||
super(ChangePasswordNotAllowedException.class, Response.Status.BAD_REQUEST, mapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
|
||||||
|
|
||||||
import sonia.scm.api.rest.ContextualExceptionMapper;
|
|
||||||
import sonia.scm.user.InvalidPasswordException;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
public class InvalidPasswordExceptionMapper extends ContextualExceptionMapper<InvalidPasswordException> {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public InvalidPasswordExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
|
|
||||||
super(InvalidPasswordException.class, Response.Status.BAD_REQUEST, mapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,9 +4,9 @@ import org.jboss.resteasy.core.Dispatcher;
|
|||||||
import org.jboss.resteasy.mock.MockDispatcherFactory;
|
import org.jboss.resteasy.mock.MockDispatcherFactory;
|
||||||
import sonia.scm.api.rest.AlreadyExistsExceptionMapper;
|
import sonia.scm.api.rest.AlreadyExistsExceptionMapper;
|
||||||
import sonia.scm.api.rest.AuthorizationExceptionMapper;
|
import sonia.scm.api.rest.AuthorizationExceptionMapper;
|
||||||
|
import sonia.scm.api.rest.BadRequestExceptionMapper;
|
||||||
import sonia.scm.api.rest.ConcurrentModificationExceptionMapper;
|
import sonia.scm.api.rest.ConcurrentModificationExceptionMapper;
|
||||||
import sonia.scm.api.v2.NotFoundExceptionMapper;
|
import sonia.scm.api.v2.NotFoundExceptionMapper;
|
||||||
import sonia.scm.api.v2.NotSupportedFeatureExceptionMapper;
|
|
||||||
|
|
||||||
public class DispatcherMock {
|
public class DispatcherMock {
|
||||||
public static Dispatcher createDispatcher(Object resource) {
|
public static Dispatcher createDispatcher(Object resource) {
|
||||||
@@ -18,9 +18,7 @@ public class DispatcherMock {
|
|||||||
dispatcher.getProviderFactory().register(new ConcurrentModificationExceptionMapper(mapper));
|
dispatcher.getProviderFactory().register(new ConcurrentModificationExceptionMapper(mapper));
|
||||||
dispatcher.getProviderFactory().registerProvider(AuthorizationExceptionMapper.class);
|
dispatcher.getProviderFactory().registerProvider(AuthorizationExceptionMapper.class);
|
||||||
dispatcher.getProviderFactory().register(new InternalRepositoryExceptionMapper(mapper));
|
dispatcher.getProviderFactory().register(new InternalRepositoryExceptionMapper(mapper));
|
||||||
dispatcher.getProviderFactory().register(new ChangePasswordNotAllowedExceptionMapper(mapper));
|
dispatcher.getProviderFactory().register(new BadRequestExceptionMapper(mapper));
|
||||||
dispatcher.getProviderFactory().register(new InvalidPasswordExceptionMapper(mapper));
|
|
||||||
dispatcher.getProviderFactory().register(new NotSupportedFeatureExceptionMapper(mapper));
|
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user