Search in sources :

Example 31 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class MultiRepository method addNamespacesToRepository.

private void addNamespacesToRepository(IRepository repository, GenericId id) {
    if (id instanceof DefinitionsChildId) {
        Namespace namespace = ((DefinitionsChildId) id).getNamespace();
        String ns = namespace.getDecoded();
        IRepository r = determineRepositoryRef(repository);
        Set<String> set = repositoryGlobal.get(r);
        set.add(ns);
        repositoryGlobal.put(r, set);
        String pns;
        try {
            if (this.localRepository.getRepository() instanceof XmlRepository) {
                pns = namespace.getEncoded().substring(0, namespace.getEncoded().lastIndexOf(RepositoryUtils.getUrlSeparatorEncoded()));
            } else {
                pns = namespace.getEncoded();
            }
        } catch (UnsupportedEncodingException ex) {
            LOGGER.error("Error when generating the namespace", ex);
            return;
        }
        Set<Namespace> setPre = repositoryCommonNamespace.get(r);
        setPre.add(new Namespace(pns, true));
        repositoryCommonNamespace.put(r, setPre);
    }
}
Also used : XmlRepository(org.eclipse.winery.repository.xml.XmlRepository) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IRepository(org.eclipse.winery.repository.backend.IRepository) Namespace(org.eclipse.winery.model.ids.Namespace)

Example 32 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class TemplatesOfOneType method getJSON.

/**
 * returns a list of all implementations of a type using the getAllImplementations method
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON() {
    Collection<? extends DefinitionsChildId> allImplementations = this.getAllImplementations();
    List<QNameApiData> res = new ArrayList<>(allImplementations.size());
    QNameConverter adapter = new QNameConverter();
    for (DefinitionsChildId id : allImplementations) {
        res.add(adapter.marshal(id.getQName()));
    }
    return Response.ok().entity(res).build();
}
Also used : QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList) QNameConverter(org.eclipse.winery.repository.rest.resources.apiData.converter.QNameConverter) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class CsarExporter method writeSelfContainedCsar.

public void writeSelfContainedCsar(IRepository repository, DefinitionsChildId entryId, OutputStream output, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException, InterruptedException, AccountabilityException, ExecutionException {
    SelfContainmentPackager selfContainmentPackager = new SelfContainmentPackager(repository);
    DefinitionsChildId newServiceTemplateId = selfContainmentPackager.createSelfContainedVersion(entryId);
    exportConfiguration.put(CsarExportConfiguration.INCLUDE_DEPENDENCIES.name(), true);
    this.writeCsar(newServiceTemplateId, output, exportConfiguration);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager)

Example 34 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class CsarExporter method addManifest.

private String addManifest(DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
    String entryDefinitionsReference = CsarExporter.getDefinitionsPathInsideCSAR(repository, id);
    out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
    StringBuilder stringBuilder = new StringBuilder();
    // Setting Versions
    stringBuilder.append(TOSCA_META_VERSION).append(": 1.0").append("\n");
    stringBuilder.append(CSAR_VERSION).append(": 1.0").append("\n");
    stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
    // Winery currently is unaware of tDefinitions, therefore, we use the
    // name of the service template
    stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
    stringBuilder.append("\n");
    assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
    // Setting other files, mainly files belonging to artifacts
    for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
        final CsarEntry csarEntry = item.getValue();
        final CsarContentProperties fileProperties = item.getKey();
        stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
        String mimeType;
        if (csarEntry instanceof DocumentBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_XSD;
        } else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
        } else {
            mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
        }
        stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
        if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name()) && Objects.nonNull(fileProperties.getFileHash())) {
            stringBuilder.append(HASH).append(": ").append(fileProperties.getFileHash()).append("\n");
        }
        if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name()) && Objects.nonNull(fileProperties.getImmutableAddress())) {
            stringBuilder.append(IMMUTABLE_ADDRESS).append(": ").append(fileProperties.getImmutableAddress()).append("\n");
        }
        stringBuilder.append("\n");
    }
    String manifestString = stringBuilder.toString();
    out.write(manifestString.getBytes());
    out.closeEntry();
    return manifestString;
}
Also used : SortedSet(java.util.SortedSet) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) LoggerFactory(org.slf4j.LoggerFactory) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) DirectoryStream(java.nio.file.DirectoryStream) ServiceTemplateSelfServiceFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ServiceTemplateSelfServiceFilesDirectoryId) SelfServiceMetaDataUtils(org.eclipse.winery.repository.backend.SelfServiceMetaDataUtils) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager) IdNames(org.eclipse.winery.model.ids.IdNames) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Duration(java.time.Duration) Map(java.util.Map) TOSCA_META_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_VERSION) GenericId(org.eclipse.winery.model.ids.GenericId) Util(org.eclipse.winery.repository.common.Util) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CREATED_BY(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CREATED_BY) ENTRY_DEFINITIONS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.ENTRY_DEFINITIONS) Collection(java.util.Collection) Constants(org.eclipse.winery.common.Constants) IMMUTABLE_ADDRESS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS) Options(org.eclipse.winery.model.selfservice.Application.Options) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) CSAR_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) HASH(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.HASH) NAME(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.NAME) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) ZipOutputStream(java.util.zip.ZipOutputStream) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) LocalDateTime(java.time.LocalDateTime) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) Application(org.eclipse.winery.model.selfservice.Application) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) OutputStream(java.io.OutputStream) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Environments(org.eclipse.winery.common.configuration.Environments) GitInfo(org.eclipse.winery.repository.GitInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ExecutionException(java.util.concurrent.ExecutionException) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) Paths(java.nio.file.Paths) SelfServiceMetaDataId(org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId) HashingUtil(org.eclipse.winery.common.HashingUtil) Git(org.eclipse.jgit.api.Git) InputStream(java.io.InputStream) CONTENT_TYPE(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CONTENT_TYPE) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) ZipEntry(java.util.zip.ZipEntry) Map(java.util.Map) HashMap(java.util.HashMap) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)

Example 35 with DefinitionsChildId

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

DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)77 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)29 Test (org.junit.jupiter.api.Test)21 QName (javax.xml.namespace.QName)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)16 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 HashMap (java.util.HashMap)15 IRepository (org.eclipse.winery.repository.backend.IRepository)14 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13 Path (java.nio.file.Path)12 Map (java.util.Map)12 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)12 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 InputStream (java.io.InputStream)10 HashSet (java.util.HashSet)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10