Search in sources :

Example 1 with Filename

use of org.eclipse.winery.repository.backend.constants.Filename in project winery by eclipse.

the class ToscaExportUtil method specifyImports.

private TDefinitions specifyImports(IRepository repository, DefinitionsChildId tcId, Collection<DefinitionsChildId> referencedDefinitionsChildIds) {
    TDefinitions entryDefinitions = repository.getDefinitions(tcId);
    // BEGIN: Definitions modification
    // the "imports" collection contains the imports of Definitions, not of other definitions
    // the other definitions are stored in entryDefinitions.getImport()
    // we modify the internal definitions object directly. It is not written back to the storage. Therefore, we do not need to clone it
    // the imports (pointing to not-definitions (xsd, wsdl, ...)) already have a correct relative URL. (quick hack)
    URI uri = (URI) this.exportConfiguration.get(CsarExportConfiguration.REPOSITORY_URI.name());
    if (uri != null) {
        // we are in the plain-XML mode, the URLs of the imports have to be adjusted
        for (TImport i : entryDefinitions.getImport()) {
            String loc = i.getLocation();
            if (!loc.startsWith("../")) {
                LOGGER.warn("Location is not relative for id " + tcId.toReadableString());
            }
            loc = loc.substring(3);
            loc = uri + loc;
            // now the location is an absolute URL
            i.setLocation(loc);
        }
    }
    // files of imports have to be added to the CSAR, too
    for (TImport i : entryDefinitions.getImport()) {
        String loc = i.getLocation();
        if (Util.isRelativeURI(loc)) {
            // locally stored, add to CSAR
            GenericImportId iid = new GenericImportId(i);
            String fileName = IdUtil.getLastURIPart(loc);
            fileName = EncodingUtil.URLdecode(fileName);
            RepositoryFileReference ref = new RepositoryFileReference(iid, fileName);
            putRefAsReferencedItemInCsar(repository, ref);
        }
    }
    Set<DefinitionsChildId> collect = referencedDefinitionsChildIds.stream().filter(id -> id instanceof NodeTypeImplementationId).collect(Collectors.toSet());
    if (collect.stream().anyMatch(DefinitionsChildId::isSelfContained)) {
        if (this.exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name())) {
            referencedDefinitionsChildIds.removeAll(collect.stream().filter(id -> !id.isSelfContained()).collect(Collectors.toList()));
        } else if (collect.size() > 1 && collect.stream().anyMatch(id -> !id.isSelfContained())) {
            referencedDefinitionsChildIds.removeAll(collect.stream().filter(DefinitionsChildId::isSelfContained).collect(Collectors.toList()));
        }
    }
    // adjust imports: add imports of definitions to it
    Collection<TImport> imports = new ArrayList<>();
    for (DefinitionsChildId id : referencedDefinitionsChildIds) {
        this.addToImports(repository, id, imports);
    }
    entryDefinitions.getImport().addAll(imports);
    // END: Definitions modification
    return entryDefinitions;
}
Also used : PlansId(org.eclipse.winery.model.ids.elements.PlansId) SortedSet(java.util.SortedSet) IdUtil(org.eclipse.winery.model.ids.IdUtil) LoggerFactory(org.slf4j.LoggerFactory) QNames(org.eclipse.winery.model.tosca.constants.QNames) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) Document(org.w3c.dom.Document) Map(java.util.Map) Util(org.eclipse.winery.repository.common.Util) URI(java.net.URI) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) Filename(org.eclipse.winery.repository.backend.constants.Filename) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) Set(java.util.Set) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) TopologyGraphElementEntityTypeId(org.eclipse.winery.model.ids.definitions.TopologyGraphElementEntityTypeId) QName(javax.xml.namespace.QName) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) XMLConstants(javax.xml.XMLConstants) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TImport(org.eclipse.winery.model.tosca.TImport) OutputStream(java.io.OutputStream) VisualAppearanceId(org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId) Logger(org.slf4j.Logger) PlanId(org.eclipse.winery.model.ids.elements.PlanId) IOException(java.io.IOException) EntityTypeId(org.eclipse.winery.model.ids.definitions.EntityTypeId) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TImport(org.eclipse.winery.model.tosca.TImport) ArrayList(java.util.ArrayList) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) URI(java.net.URI) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 Collectors (java.util.stream.Collectors)1 XMLConstants (javax.xml.XMLConstants)1 QName (javax.xml.namespace.QName)1 EncodingUtil (org.eclipse.winery.model.ids.EncodingUtil)1 IdUtil (org.eclipse.winery.model.ids.IdUtil)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 EntityTypeId (org.eclipse.winery.model.ids.definitions.EntityTypeId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)1