mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Bootstrap v2 version to get repositories
This commit is contained in:
@@ -46,7 +46,6 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.BlameResult;
|
||||
import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
@@ -120,19 +119,15 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryManager
|
||||
* @param repositoryManager
|
||||
* @param servicefactory
|
||||
* @param healthChecker
|
||||
*/
|
||||
@Inject
|
||||
public RepositoryResource(ScmConfiguration configuration,
|
||||
RepositoryManager repositoryManager,
|
||||
public RepositoryResource(RepositoryManager repositoryManager,
|
||||
RepositoryServiceFactory servicefactory, HealthChecker healthChecker)
|
||||
{
|
||||
super(repositoryManager);
|
||||
this.configuration = configuration;
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.servicefactory = servicefactory;
|
||||
this.healthChecker = healthChecker;
|
||||
@@ -1103,9 +1098,6 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private final HealthChecker healthChecker;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.time.Instant;
|
||||
abstract class BaseMapper<T extends ModelObject, D extends HalRepresentation> {
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
public abstract D map(T user);
|
||||
public abstract D map(T modelObject);
|
||||
|
||||
Instant mapTime(Long epochMilli) {
|
||||
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class HealthCheckFailureDto {
|
||||
private String description;
|
||||
private String summary;
|
||||
private String url;
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public class MapperModule extends AbstractModule {
|
||||
bind(GroupToGroupDtoMapper.class).to(Mappers.getMapper(GroupToGroupDtoMapper.class).getClass());
|
||||
bind(GroupCollectionToDtoMapper.class);
|
||||
|
||||
bind(RepositoryToRepositoryDtoMapper.class).to(Mappers.getMapper(RepositoryToRepositoryDtoMapper.class).getClass());
|
||||
|
||||
bind(UriInfoStore.class).in(ServletScopes.REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class PermissionDto {
|
||||
private String type;
|
||||
private String name;
|
||||
private boolean groupPermission;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Setter
|
||||
public class RepositoryDto extends HalRepresentation {
|
||||
|
||||
private String id;
|
||||
private String contact;
|
||||
private Instant creationDate;
|
||||
private String description;
|
||||
private List<HealthCheckFailureDto> healthCheckFailures;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Instant lastModified;
|
||||
private String namespace;
|
||||
private String name;
|
||||
private List<PermissionDto> permissions;
|
||||
@XmlElement(name = "public")
|
||||
private boolean publicReadable = false;
|
||||
private boolean archived = false;
|
||||
private String type;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class RepositoryResource {
|
||||
|
||||
private final RepositoryToRepositoryDtoMapper repositoryToDtoMapper;
|
||||
|
||||
private final ResourceManagerAdapter<Repository, RepositoryDto, RepositoryException> adapter;
|
||||
|
||||
@Inject
|
||||
public RepositoryResource(RepositoryToRepositoryDtoMapper repositoryToDtoMapper, RepositoryManager manager) {
|
||||
this.repositoryToDtoMapper = repositoryToDtoMapper;
|
||||
this.adapter = new ResourceManagerAdapter<>(manager);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("")
|
||||
@Produces(VndMediaType.REPOSITORY)
|
||||
@TypeHint(RepositoryDto.class)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
|
||||
@ResponseCode(code = 403, condition = "not authorized, the current user has no privileges to read the repository"),
|
||||
@ResponseCode(code = 404, condition = "not found, no repository with the specified name available in the namespace"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
return adapter.get("31QwjAKOK2", repositoryToDtoMapper::map);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* RESTful Web Service Resource to manage repositories.
|
||||
*/
|
||||
@Path(RepositoryRootResource.REPOSITORIES_PATH_V2)
|
||||
public class RepositoryRootResource {
|
||||
static final String REPOSITORIES_PATH_V2 = "v2/repositories/";
|
||||
|
||||
private final Provider<RepositoryResource> repositoryResource;
|
||||
|
||||
@Inject
|
||||
public RepositoryRootResource(Provider<RepositoryResource> repositoryResource) {
|
||||
this.repositoryResource = repositoryResource;
|
||||
}
|
||||
|
||||
@Path("{namespace}/{name}")
|
||||
public RepositoryResource getRepositoryResource() {
|
||||
return repositoryResource.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.mapstruct.Mapper;
|
||||
import sonia.scm.repository.HealthCheckFailure;
|
||||
import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
// Mapstruct does not support parameterized (i.e. non-default) constructors. Thus, we need to use field injection.
|
||||
@SuppressWarnings("squid:S3306")
|
||||
@Mapper
|
||||
public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Repository, RepositoryDto> {
|
||||
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
abstract HealthCheckFailureDto toDto(HealthCheckFailure failure);
|
||||
|
||||
abstract PermissionDto toDto(Permission permission);
|
||||
}
|
||||
Reference in New Issue
Block a user