Search in sources :

Example 1 with NamespaceProperties

use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.

the class TopologyTemplateResource method getNewVersionList.

@GET
@Path("newversions")
@Produces(MediaType.APPLICATION_JSON)
public List<NewVersionListElement> getNewVersionList() {
    IRepository repository = RepositoryFactory.getRepository();
    Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
    Map<QName, List<WineryVersion>> versionElements = new HashMap<>();
    for (TNodeTemplate node : this.topologyTemplate.getNodeTemplates()) {
        if (nodeTypes.containsKey(node.getType())) {
            NodeTypeId nodeTypeId = new NodeTypeId(node.getType());
            if (!versionElements.containsKey(nodeTypeId.getQName())) {
                List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(nodeTypeId, repository).stream().filter(wineryVersion -> {
                    QName qName = VersionSupport.getDefinitionInTheGivenVersion(nodeTypeId, wineryVersion).getQName();
                    NamespaceProperties namespaceProperties = repository.getNamespaceManager().getNamespaceProperties(qName.getNamespaceURI());
                    return !(namespaceProperties.isGeneratedNamespace() || ModelUtilities.isFeatureType(qName, nodeTypes));
                }).collect(Collectors.toList());
                versionElements.put(nodeTypeId.getQName(), versionList);
            }
        }
    }
    return versionElements.entrySet().stream().map(qNameListEntry -> new NewVersionListElement(qNameListEntry.getKey(), qNameListEntry.getValue())).collect(Collectors.toList());
}
Also used : UpdateInfo(org.eclipse.winery.repository.rest.resources.apiData.UpdateInfo) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) AvailableFeaturesApiData(org.eclipse.winery.repository.rest.resources.apiData.AvailableFeaturesApiData) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) InvalidParameterException(java.security.InvalidParameterException) Consumes(javax.ws.rs.Consumes) SolutionStrategy(org.eclipse.winery.model.adaptation.problemsolving.SolutionStrategy) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) PlacementUtils(org.eclipse.winery.model.adaptation.placement.PlacementUtils) URI(java.net.URI) TEntityType(org.eclipse.winery.model.tosca.TEntityType) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) Context(javax.ws.rs.core.Context) SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TopologyAndErrorList(org.eclipse.winery.model.adaptation.enhance.TopologyAndErrorList) Allocation(org.eclipse.winery.repository.targetallocation.Allocation) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CompositionData(org.eclipse.winery.repository.rest.resources._support.dataadapter.composeadapter.CompositionData) NewVersionListElement(org.eclipse.winery.repository.rest.resources.apiData.NewVersionListElement) Objects(java.util.Objects) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) AllocationRequest(org.eclipse.winery.repository.targetallocation.util.AllocationRequest) AbstractComponentInstanceResourceContainingATopology(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResourceContainingATopology) GET(javax.ws.rs.GET) Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) EnhancementUtils(org.eclipse.winery.model.adaptation.enhance.EnhancementUtils) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) HasTags(org.eclipse.winery.model.tosca.HasTags) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) PropertyDiffList(org.eclipse.winery.repository.rest.resources.apiData.PropertyDiffList) PUT(javax.ws.rs.PUT) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) Collections(java.util.Collections) SolutionFactory(org.eclipse.winery.model.adaptation.problemsolving.SolutionFactory) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QName(javax.xml.namespace.QName) TNodeType(org.eclipse.winery.model.tosca.TNodeType) NewVersionListElement(org.eclipse.winery.repository.rest.resources.apiData.NewVersionListElement) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) TopologyAndErrorList(org.eclipse.winery.model.adaptation.enhance.TopologyAndErrorList) List(java.util.List) ArrayList(java.util.ArrayList) PropertyDiffList(org.eclipse.winery.repository.rest.resources.apiData.PropertyDiffList) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with NamespaceProperties

use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.

the class MultiRepository method fixNamespaces.

private void fixNamespaces(IRepository repository) {
    SortedSet<DefinitionsChildId> defChildren = repository.getAllDefinitionsChildIds();
    Collection<NamespaceProperties> namespaceProperties = new ArrayList<>();
    for (DefinitionsChildId value : defChildren) {
        namespaceProperties.add(new NamespaceProperties(value.getNamespace().getDecoded(), value.getNamespace().getDecoded().replace(".", ""), "", false));
    }
    repository.getNamespaceManager().addAllPermanent(namespaceProperties);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) ArrayList(java.util.ArrayList)

Example 3 with NamespaceProperties

use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.

the class CsarImporter method importNamespacePrefixes.

/**
 * Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
 * extracted using JAXB and stored in the NamespacesResource
 *
 * @param rootPath the root path of the extracted CSAR
 */
private void importNamespacePrefixes(Path rootPath) {
    NamespaceManager namespaceManager = targetRepository.getNamespaceManager();
    Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
    Path json = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_JSON);
    if (Files.exists(properties) || Files.exists(json)) {
        NamespaceManager localNamespaceManager;
        if (Files.exists(properties)) {
            PropertiesConfiguration pconf = new PropertiesConfiguration();
            try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) {
                pconf.read(propertyReader);
                localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf);
            } catch (IOException | ConfigurationException e) {
                CsarImporter.LOGGER.debug(e.getMessage(), e);
                return;
            }
        } else {
            localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
        }
        for (String s : localNamespaceManager.getAllNamespaces().keySet()) {
            boolean addToStorage = false;
            String namespace = s;
            if (namespaceManager.hasPermanentProperties(namespace)) {
                String storedPrefix = namespaceManager.getPrefix(namespace);
                // QUICK HACK to check whether the prefix is a generated one
                // We assume we know the internal generation routine
                Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
                if (m.matches()) {
                    // the stored prefix is a generated one
                    // replace it by the one stored in the exported properties
                    addToStorage = true;
                }
            } else {
                addToStorage = true;
            }
            if (addToStorage) {
                String prefix = localNamespaceManager.getPrefix(namespace);
                namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
            }
        }
    }
}
Also used : Path(java.nio.file.Path) JsonBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.JsonBasedNamespaceManager) ConfigurationBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ConfigurationBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager) Matcher(java.util.regex.Matcher) PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) JsonBasedNamespaceManager(org.eclipse.winery.repository.backend.filebased.JsonBasedNamespaceManager) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) BufferedReader(java.io.BufferedReader)

Example 4 with NamespaceProperties

use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.

the class EnhancementUtils method generateNewGeneratedNamespace.

private static String generateNewGeneratedNamespace(QName qName) {
    NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
    String namespace = qName.getNamespaceURI().concat(GENERATED_NS_SUFFIX);
    NamespaceProperties namespaceProperties = namespaceManager.getNamespaceProperties(namespace);
    namespaceProperties.setGeneratedNamespace(true);
    namespaceManager.setNamespaceProperties(namespace, namespaceProperties);
    return namespace;
}
Also used : NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties)

Example 5 with NamespaceProperties

use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties 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)

Aggregations

NamespaceProperties (org.eclipse.winery.repository.backend.filebased.NamespaceProperties)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 InvalidParameterException (java.security.InvalidParameterException)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1