Search in sources :

Example 11 with Namespace

use of org.eclipse.winery.model.ids.Namespace in project winery by eclipse.

the class ServiceTemplateComplianceRuleRuleChecker method getRuleIds.

public List<ComplianceRuleId> getRuleIds(TServiceTemplate serviceTemplate) {
    List<ComplianceRuleId> complianceRules = new ArrayList<>();
    Namespace namespace = new Namespace(serviceTemplate.getTargetNamespace(), false);
    Collection<Namespace> componentsNamespaces = RepositoryFactory.getRepository().getComponentsNamespaces(ComplianceRuleId.class);
    List<Namespace> relevantNamespaces = componentsNamespaces.stream().filter(ns -> namespace.getDecoded().startsWith(ns.getDecoded().split("/compliancerules")[0])).collect(Collectors.toList());
    for (Namespace space : relevantNamespaces) {
        complianceRules.addAll((Collection<? extends ComplianceRuleId>) RepositoryFactory.getRepository().getAllIdsInNamespace(ComplianceRuleId.class, space));
    }
    return complianceRules;
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) GraphMapping(org.jgrapht.GraphMapping) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) IRepository(org.eclipse.winery.repository.backend.IRepository) Map(java.util.Map) NonNull(org.eclipse.jdt.annotation.NonNull) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) ArrayList(java.util.ArrayList) Namespace(org.eclipse.winery.model.ids.Namespace)

Example 12 with Namespace

use of org.eclipse.winery.model.ids.Namespace in project winery by eclipse.

the class MultiRepository method generateCommonNamespace.

private static HashSet<Namespace> generateCommonNamespace(Collection<String> repositoryNamespaces) {
    HashSet<Namespace> setNS = new HashSet<>();
    repositoryNamespaces.forEach(ns -> {
        Namespace namespace = new Namespace(ns, false);
        if (namespace.getEncoded().contains("%2F")) {
            String pns = namespace.getEncoded();
            if (namespace.getEncoded().lastIndexOf("%2F") > 15) {
                pns = namespace.getEncoded().substring(0, namespace.getEncoded().lastIndexOf("%2F"));
            }
            setNS.add(new Namespace(pns, true));
        }
    });
    return setNS;
}
Also used : Namespace(org.eclipse.winery.model.ids.Namespace) HashSet(java.util.HashSet)

Example 13 with Namespace

use of org.eclipse.winery.model.ids.Namespace 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

Namespace (org.eclipse.winery.model.ids.Namespace)13 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 IRepository (org.eclipse.winery.repository.backend.IRepository)5 Path (java.nio.file.Path)4 QName (javax.xml.namespace.QName)4 XmlId (org.eclipse.winery.model.ids.XmlId)4 Map (java.util.Map)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2 JAXBException (javax.xml.bind.JAXBException)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)2 EntityTemplateId (org.eclipse.winery.model.ids.definitions.EntityTemplateId)2