Search in sources :

Example 71 with IRepository

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;
}
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 72 with IRepository

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();
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 73 with IRepository

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);
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 74 with IRepository

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);
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 75 with IRepository

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);
}
Also used : ArrayList(java.util.ArrayList) IRepository(org.eclipse.winery.repository.backend.IRepository) Namespace(org.eclipse.winery.model.ids.Namespace)

Aggregations

IRepository (org.eclipse.winery.repository.backend.IRepository)75 TNodeType (org.eclipse.winery.model.tosca.TNodeType)29 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)27 IOException (java.io.IOException)24 QName (javax.xml.namespace.QName)24 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)22 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 HashMap (java.util.HashMap)15 LoggerFactory (org.slf4j.LoggerFactory)15 LinkedHashMap (java.util.LinkedHashMap)14 List (java.util.List)14 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)14 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)14 Collectors (java.util.stream.Collectors)13 POST (javax.ws.rs.POST)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13