use of org.eclipse.winery.model.ids.admin.NamespacesId in project winery by eclipse.
the class AbstractFileBasedRepository method getNamespaceManager.
@Override
public NamespaceManager getNamespaceManager() {
NamespaceManager manager;
RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId());
manager = new JsonBasedNamespaceManager(ref2AbsolutePath(ref).toFile(), isLocal);
Configuration configuration = this.getConfiguration(new NamespacesId());
if (!configuration.isEmpty()) {
ConfigurationBasedNamespaceManager old = new ConfigurationBasedNamespaceManager(configuration);
manager.replaceAll(old.getAllNamespaces());
try {
forceDelete(BackendUtils.getRefOfConfiguration(new NamespacesId()));
} catch (IOException e) {
LOGGER.error("Could not remove old namespace configuration.", e);
}
}
return manager;
}
use of org.eclipse.winery.model.ids.admin.NamespacesId 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.model.ids.admin.NamespacesId in project winery by eclipse.
the class CsarExporter method addNamespacePrefixes.
/**
* Writes the configured mapping namespace prefix -> namespace to the archive
* <p>
* This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using JAXB and stored in
* the NamespacesResource
*/
private void addNamespacePrefixes(Map<CsarContentProperties, CsarEntry> refMap) {
// ensure that the namespaces are saved as json
SortedSet<RepositoryFileReference> references = repository.getContainedFiles(new NamespacesId());
references.forEach(repositoryFileReference -> {
if (repositoryFileReference.getFileName().toLowerCase().endsWith(Constants.SUFFIX_JSON)) {
CsarContentProperties csarContentProperties = new CsarContentProperties(CsarExporter.PATH_TO_NAMESPACES_JSON);
refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, repositoryFileReference));
}
});
}
Aggregations