mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-06 11:46:10 +02:00
enhance repository initializer api with creation context
This commit is contained in:
@@ -147,7 +147,7 @@ public class RepositoryCollectionResource {
|
||||
mediaType = VndMediaType.ERROR_TYPE,
|
||||
schema = @Schema(implementation = ErrorDto.class)
|
||||
))
|
||||
public Response create(@Valid RepositoryDto repository, @QueryParam("initialize") boolean initialize) {
|
||||
public Response create(@Valid RepositoryCreationDto repository, @QueryParam("initialize") boolean initialize) {
|
||||
AtomicReference<Repository> reference = new AtomicReference<>();
|
||||
Response response = adapter.create(repository,
|
||||
() -> createModelObjectFromDto(repository),
|
||||
@@ -156,7 +156,7 @@ public class RepositoryCollectionResource {
|
||||
return resourceLinks.repository().self(r.getNamespace(), r.getName());
|
||||
});
|
||||
if (initialize) {
|
||||
repositoryInitializer.initialize(reference.get());
|
||||
repositoryInitializer.initialize(reference.get(), repository.getCreationContext());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class RepositoryCreationDto extends RepositoryDto {
|
||||
private Map<String, JsonNode> creationContext;
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.CharSource;
|
||||
import org.slf4j.Logger;
|
||||
@@ -38,6 +39,7 @@ import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
@@ -55,10 +57,14 @@ public class RepositoryInitializer {
|
||||
}
|
||||
|
||||
public void initialize(Repository repository) {
|
||||
initialize(repository, null);
|
||||
}
|
||||
|
||||
public void initialize(Repository repository, Map<String, JsonNode> creationContext) {
|
||||
try (RepositoryService service = serviceFactory.create(repository)) {
|
||||
ModifyCommandBuilder modifyCommandBuilder = service.getModifyCommand();
|
||||
|
||||
InitializerContextImpl initializerContext = new InitializerContextImpl(repository, modifyCommandBuilder);
|
||||
InitializerContextImpl initializerContext = new InitializerContextImpl(repository, modifyCommandBuilder, creationContext);
|
||||
|
||||
for (RepositoryContentInitializer initializer : contentInitializers) {
|
||||
initializer.initialize(initializerContext);
|
||||
@@ -77,10 +83,12 @@ public class RepositoryInitializer {
|
||||
|
||||
private final Repository repository;
|
||||
private final ModifyCommandBuilder builder;
|
||||
private final Map<String, JsonNode> creationContext;
|
||||
|
||||
InitializerContextImpl(Repository repository, ModifyCommandBuilder builder) {
|
||||
InitializerContextImpl(Repository repository, ModifyCommandBuilder builder, Map<String, JsonNode> creationContext) {
|
||||
this.repository = repository;
|
||||
this.builder = builder;
|
||||
this.creationContext = creationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +96,11 @@ public class RepositoryInitializer {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, JsonNode> getCreationContext() {
|
||||
return creationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryContentInitializer.CreateFile create(String path) {
|
||||
return new CreateFileImpl(this, builder.useDefaultPath(true).createFile(path).setOverwrite(true));
|
||||
|
||||
Reference in New Issue
Block a user