mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Rename creationContext to contextEntries
This commit is contained in:
@@ -64,14 +64,15 @@ public interface RepositoryContentInitializer {
|
||||
CreateFile create(String path);
|
||||
|
||||
/**
|
||||
* Find the the context object with the given key and unmarshalls it to the given type.
|
||||
* Returns the the context entry with the given key and unmarshalls it to the given type.
|
||||
* It no entry with the given key is available an empty optional is returned.
|
||||
*
|
||||
* @param key key of the context object
|
||||
* @param type type of the context object
|
||||
* @return context object or empty optional
|
||||
* @return context entry or empty optional
|
||||
* @since 2.5.0
|
||||
*/
|
||||
default <T> Optional<T> oneByType(String key, Class<T> type) {
|
||||
default <T> Optional<T> getEntry(String key, Class<T> type) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export type Repository = {
|
||||
};
|
||||
|
||||
export type RepositoryCreation = Repository & {
|
||||
creationContext: { [key: string]: any };
|
||||
contextEntries: { [key: string]: any };
|
||||
};
|
||||
|
||||
export type RepositoryCollection = PagedCollection & {
|
||||
|
||||
@@ -72,7 +72,7 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
type: "",
|
||||
contact: "",
|
||||
description: "",
|
||||
creationContext: {},
|
||||
contextEntries: {},
|
||||
_links: {}
|
||||
},
|
||||
initRepository: false,
|
||||
@@ -88,7 +88,7 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
repository: {
|
||||
...repository,
|
||||
creationContext: {}
|
||||
contextEntries: {}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -135,8 +135,8 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
repository: {
|
||||
...this.state.repository,
|
||||
creationContext: {
|
||||
...this.state.repository.creationContext,
|
||||
contextEntries: {
|
||||
...this.state.repository.contextEntries,
|
||||
[key]: value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class RepositoryCollectionResource {
|
||||
return resourceLinks.repository().self(r.getNamespace(), r.getName());
|
||||
});
|
||||
if (initialize) {
|
||||
repositoryInitializer.initialize(reference.get(), repository.getCreationContext());
|
||||
repositoryInitializer.initialize(reference.get(), repository.getContextEntries());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -36,12 +36,12 @@ import java.util.Map;
|
||||
@Getter
|
||||
@Setter
|
||||
public class RepositoryCreationDto extends RepositoryDto {
|
||||
private Map<String, JsonNode> creationContext;
|
||||
private Map<String, JsonNode> contextEntries;
|
||||
|
||||
public Map<String, JsonNode> getCreationContext() {
|
||||
if (creationContext == null) {
|
||||
public Map<String, JsonNode> getContextEntries() {
|
||||
if (contextEntries == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return creationContext;
|
||||
return contextEntries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ public class RepositoryInitializer {
|
||||
this.contentInitializers = Priorities.sortInstances(contentInitializerSet);
|
||||
}
|
||||
|
||||
public void initialize(Repository repository, Map<String, JsonNode> creationContext) {
|
||||
public void initialize(Repository repository, Map<String, JsonNode> contextEntries) {
|
||||
try (RepositoryService service = serviceFactory.create(repository)) {
|
||||
ModifyCommandBuilder modifyCommandBuilder = service.getModifyCommand();
|
||||
|
||||
InitializerContextImpl initializerContext = new InitializerContextImpl(repository, modifyCommandBuilder, creationContext);
|
||||
InitializerContextImpl initializerContext = new InitializerContextImpl(repository, modifyCommandBuilder, contextEntries);
|
||||
|
||||
for (RepositoryContentInitializer initializer : contentInitializers) {
|
||||
initializer.initialize(initializerContext);
|
||||
@@ -81,14 +81,14 @@ public class RepositoryInitializer {
|
||||
|
||||
private final Repository repository;
|
||||
private final ModifyCommandBuilder builder;
|
||||
private final Map<String, JsonNode> creationContext;
|
||||
private final Map<String, JsonNode> contextEntries;
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
InitializerContextImpl(Repository repository, ModifyCommandBuilder builder, Map<String, JsonNode> creationContext) {
|
||||
InitializerContextImpl(Repository repository, ModifyCommandBuilder builder, Map<String, JsonNode> contextEntries) {
|
||||
this.repository = repository;
|
||||
this.builder = builder;
|
||||
this.creationContext = creationContext;
|
||||
this.contextEntries = contextEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,8 +97,8 @@ public class RepositoryInitializer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> oneByType(String key, Class<T> type) {
|
||||
JsonNode node = creationContext.get(key);
|
||||
public <T> Optional<T> getEntry(String key, Class<T> type) {
|
||||
JsonNode node = contextEntries.get(key);
|
||||
if (node != null) {
|
||||
return Optional.of(mapper.convertValue(node, type));
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ class RepositoryInitializerTest {
|
||||
doThrow(new IOException("epic fail")).when(contentLoader).withData(any(ByteSource.class));
|
||||
|
||||
RepositoryInitializer initializer = new RepositoryInitializer(repositoryServiceFactory, ImmutableSet.of(new ReadmeContentInitializer()));
|
||||
Map<String, JsonNode> creationContext = Collections.emptyMap();
|
||||
assertThrows(InternalRepositoryException.class, () -> initializer.initialize(repository, creationContext));
|
||||
Map<String, JsonNode> contextEntries = Collections.emptyMap();
|
||||
assertThrows(InternalRepositoryException.class, () -> initializer.initialize(repository, contextEntries));
|
||||
|
||||
verify(repositoryService).close();
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class RepositoryInitializerTest {
|
||||
|
||||
@Override
|
||||
public void initialize(InitializerContext context) throws IOException {
|
||||
Optional<Named> named = context.oneByType("named", Named.class);
|
||||
Optional<Named> named = context.getEntry("named", Named.class);
|
||||
if (named.isPresent()) {
|
||||
context.create(named.get().getName() + ".md").from("# Named file");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user