Search in sources :

Example 1 with NamespacesId

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;
}
Also used : NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) IOException(java.io.IOException)

Example 2 with NamespacesId

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;
}
Also used : HashMap(java.util.HashMap) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) IOException(java.io.IOException) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IRepository(org.eclipse.winery.repository.backend.IRepository) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 3 with NamespacesId

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));
        }
    });
}
Also used : RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId)

Aggregations

NamespacesId (org.eclipse.winery.model.ids.admin.NamespacesId)3 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)3 IOException (java.io.IOException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Configuration (org.apache.commons.configuration2.Configuration)1 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 NamespaceManager (org.eclipse.winery.repository.backend.NamespaceManager)1 NamespaceProperties (org.eclipse.winery.repository.backend.filebased.NamespaceProperties)1 RepositoryRefBasedCsarEntry (org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry)1