use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class JsonBasedMultiNamespaceManager method loadNamespacePropertiesFromFile.
private Map<IRepository, Map<String, NamespaceProperties>> loadNamespacePropertiesFromFile() {
Map<IRepository, Map<String, NamespaceProperties>> result = new HashMap<>();
Map<String, NamespaceProperties> nsProps = new HashMap<>();
for (IRepository repo : this.repository.getRepositories()) {
RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId());
File file = repo.ref2AbsolutePath(ref).toFile();
try {
if (file.exists()) {
TypeReference<HashMap<String, NamespaceProperties>> hashMapTypeReference = new TypeReference<HashMap<String, NamespaceProperties>>() {
};
nsProps = JacksonProvider.mapper.readValue(file, hashMapTypeReference);
}
} catch (IOException e) {
LOGGER.debug("Error while loading the namespace file.", e);
throw new RuntimeException();
}
result.put(repo, nsProps);
}
return result;
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class JsonBasedMultiNamespaceManager method addAllPermanent.
@Override
public void addAllPermanent(Collection<NamespaceProperties> properties) {
properties.forEach(prop -> {
IRepository repository = RepositoryUtils.getRepositoryByNamespace(prop.getNamespace(), this.repository);
repository.getNamespaceManager().setNamespaceProperties(prop.getNamespace(), prop);
});
this.repository.updateNamespaces();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class MultiRepositoryManager method addRepositoryToFile.
/**
* If the repository is a MultiRepository, this method will copy the repositories into the repository. If the
* repository is not a MultiRepository, it will be transformed into one first.
*
* @param repositories the list of repositories copied into the MultiRepository
*/
public void addRepositoryToFile(List<RepositoryProperties> repositories) {
IRepository repo = RepositoryFactory.getRepository();
if (!(repo instanceof MultiRepository)) {
initializeRepositoryListForMultiRepositoryAndReconfigureFactory(repositories);
repo = RepositoryFactory.getRepository();
}
((MultiRepository) repo).addRepositoryToFile(repositories);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class MultiRepository method putContentToFile.
@Override
public void putContentToFile(RepositoryFileReference ref, String content, MediaType mediaType) throws IOException {
IRepository repository = RepositoryUtils.getRepositoryByRef(ref, this);
repository.putContentToFile(ref, content, mediaType);
addNamespacesToRepository(repository, ref);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class RepositoryUtils method getRepositoriesById.
private static Optional<List<IRepository>> getRepositoriesById(GenericId id, MultiRepository multiRepository) {
List<IRepository> repositoryList = new ArrayList<>();
Optional<Namespace> optNamespace = getNamespaceById(id);
if (optNamespace.isPresent()) {
for (IRepository repo : multiRepository.getRepositoriesMap().keySet()) {
for (String ns : multiRepository.getRepositoriesMap().get(repo)) {
String idNamespace = optNamespace.get().getDecoded();
if (idNamespace.equals(ns)) {
repositoryList.add(repo);
}
}
}
if (!repositoryList.isEmpty()) {
return Optional.of(repositoryList);
}
for (IRepository repo : multiRepository.getRepositoriesCommonNamespace().keySet()) {
for (Namespace ns : multiRepository.getRepositoriesCommonNamespace().get(repo)) {
String idNamespace = optNamespace.get().getDecoded();
String repoNamespace = ns.getDecoded();
if (idNamespace.contains(repoNamespace)) {
repositoryList.add(repo);
}
}
}
}
return repositoryList.isEmpty() ? Optional.of(Collections.singletonList(multiRepository.getRepository())) : Optional.of(repositoryList);
}
Aggregations