mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Adjust to repository storage with id
This commit is contained in:
@@ -543,7 +543,8 @@ public class RepositoryImportResource
|
||||
|
||||
try
|
||||
{
|
||||
repository = new Repository(null, type, name);
|
||||
// TODO #8783
|
||||
// repository = new Repository(null, type, name);
|
||||
manager.create(repository);
|
||||
}
|
||||
catch (RepositoryAlreadyExistsException ex)
|
||||
@@ -738,7 +739,8 @@ public class RepositoryImportResource
|
||||
{
|
||||
for (String repositoryName : repositoryNames)
|
||||
{
|
||||
Repository repository = manager.get(type, repositoryName);
|
||||
// TODO #8783
|
||||
Repository repository = null; //manager.get(type, repositoryName);
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
|
||||
@@ -561,42 +561,6 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} with the specified type and name.
|
||||
*
|
||||
* @param type the type of the repository
|
||||
* @param name the name of the repository
|
||||
*
|
||||
* @return the {@link Repository} with the specified type and name
|
||||
*/
|
||||
@GET
|
||||
@Path("{type: [a-z]+}/{name: .*}")
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 404, condition = "not found, no repository with the specified type and name available"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(Repository.class)
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response getByTypeAndName(@PathParam("type") String type,
|
||||
@PathParam("name") String name)
|
||||
{
|
||||
Response response;
|
||||
Repository repository = repositoryManager.get(type, name);
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
prepareForReturn(repository);
|
||||
response = Response.ok(repository).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Changeset} from the given repository
|
||||
* with the specified revision.
|
||||
|
||||
@@ -42,14 +42,29 @@ import com.google.inject.Singleton;
|
||||
import org.apache.shiro.concurrent.SubjectAwareExecutorService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.*;
|
||||
import sonia.scm.ArgumentIsInvalidException;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
import sonia.scm.util.*;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
@@ -105,7 +120,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
executorService.shutdown();
|
||||
|
||||
for (RepositoryHandler handler : handlerMap.values()) {
|
||||
@@ -115,13 +130,12 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
|
||||
public void create(Repository repository, boolean initRepository)
|
||||
throws RepositoryException {
|
||||
logger.info("create repository {} of type {}", repository.getName(),
|
||||
repository.getType());
|
||||
logger.info("create repository {} of type {}", repository.getNamespaceAndName(), repository.getType());
|
||||
|
||||
RepositoryPermissions.create().check();
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
if (repositoryDAO.contains(repository)) {
|
||||
if (repositoryDAO.contains(repository.getNamespaceAndName())) {
|
||||
throw RepositoryAlreadyExistsException.create(repository);
|
||||
}
|
||||
|
||||
@@ -190,8 +204,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
Repository oldRepository = repositoryDAO.get(repository.getType(),
|
||||
repository.getName());
|
||||
Repository oldRepository = repositoryDAO.get(repository.getNamespaceAndName());
|
||||
|
||||
if (oldRepository != null) {
|
||||
RepositoryPermissions.modify(oldRepository).check();
|
||||
@@ -212,8 +225,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
AssertUtil.assertIsNotNull(repository);
|
||||
RepositoryPermissions.read(repository).check();
|
||||
|
||||
Repository fresh = repositoryDAO.get(repository.getType(),
|
||||
repository.getName());
|
||||
Repository fresh = repositoryDAO.get(repository.getNamespaceAndName());
|
||||
|
||||
if (fresh != null) {
|
||||
fresh.copyProperties(repository);
|
||||
@@ -240,11 +252,12 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository get(String type, String name) {
|
||||
AssertUtil.assertIsNotEmpty(type);
|
||||
AssertUtil.assertIsNotEmpty(name);
|
||||
public Repository get(NamespaceAndName namespaceAndName) {
|
||||
AssertUtil.assertIsNotNull(namespaceAndName);
|
||||
AssertUtil.assertIsNotEmpty(namespaceAndName.getNamespace());
|
||||
AssertUtil.assertIsNotEmpty(namespaceAndName.getName());
|
||||
|
||||
Repository repository = repositoryDAO.get(type, name);
|
||||
Repository repository = repositoryDAO.get(namespaceAndName);
|
||||
|
||||
if (repository != null) {
|
||||
RepositoryPermissions.read(repository).check();
|
||||
@@ -325,7 +338,27 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getFromTypeAndUri(String type, String uri) {
|
||||
public Repository getFromUri(String uri) {
|
||||
AssertUtil.assertIsNotEmpty(uri);
|
||||
|
||||
if (uri.startsWith(HttpUtil.SEPARATOR_PATH)) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
|
||||
int typeSeparator = uri.indexOf(HttpUtil.SEPARATOR_PATH);
|
||||
Repository repository = null;
|
||||
|
||||
if (typeSeparator > 0) {
|
||||
String type = uri.substring(0, typeSeparator);
|
||||
|
||||
uri = uri.substring(typeSeparator + 1);
|
||||
repository = getFromTypeAndUri(type, uri);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
private Repository getFromTypeAndUri(String type, String uri) {
|
||||
if (Strings.isNullOrEmpty(type)) {
|
||||
throw new ArgumentIsInvalidException("argument type is required");
|
||||
}
|
||||
@@ -362,27 +395,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getFromUri(String uri) {
|
||||
AssertUtil.assertIsNotEmpty(uri);
|
||||
|
||||
if (uri.startsWith(HttpUtil.SEPARATOR_PATH)) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
|
||||
int typeSeperator = uri.indexOf(HttpUtil.SEPARATOR_PATH);
|
||||
Repository repository = null;
|
||||
|
||||
if (typeSeperator > 0) {
|
||||
String type = uri.substring(0, typeSeperator);
|
||||
|
||||
uri = uri.substring(typeSeperator + 1);
|
||||
repository = getFromTypeAndUri(type, uri);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryHandler getHandler(String type) {
|
||||
return handlerMap.get(type);
|
||||
|
||||
@@ -32,14 +32,15 @@
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* RepositoryMatcher is able to check if a repository matches the requested path.
|
||||
@@ -83,9 +84,24 @@ public final class RepositoryMatcher {
|
||||
}
|
||||
|
||||
private boolean isPathMatching(Repository repository, String path) {
|
||||
return getPathMatcherForType(repository.getType()).isPathMatching(repository, path);
|
||||
|
||||
String namespace = extractNamespace(path);
|
||||
String remainingPath = path.substring(namespace.length() + 1);
|
||||
|
||||
return getPathMatcherForType(repository.getType()).isPathMatching(repository, remainingPath);
|
||||
}
|
||||
|
||||
|
||||
private String extractNamespace(String path) {
|
||||
if (path.startsWith(HttpUtil.SEPARATOR_PATH)) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
int namespaceSeparator = path.indexOf(HttpUtil.SEPARATOR_PATH);
|
||||
if (namespaceSeparator > 0) {
|
||||
return path.substring(0, namespaceSeparator);
|
||||
}
|
||||
throw new IllegalArgumentException("no namespace in path " + path);
|
||||
}
|
||||
|
||||
private RepositoryPathMatcher getPathMatcherForType(String type) {
|
||||
RepositoryPathMatcher pathMatcher = pathMatchers.get(type);
|
||||
if (pathMatcher == null) {
|
||||
|
||||
Reference in New Issue
Block a user