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