Search in sources :

Example 31 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class CsarImporter method importIcon.

void importIcon(VisualAppearanceId visId, Path visPath, String fileName, TOSCAMetaFile tmf, Path rootPath, final List<String> errors) {
    Path file = visPath.resolve(fileName);
    if (Files.exists(file)) {
        RepositoryFileReference ref = new RepositoryFileReference(visId, fileName);
        importFile(file, ref, tmf, rootPath, errors);
    }
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference)

Example 32 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class YamlCsarImporter method importArtifact.

private void importArtifact(Path rootPath, TArtifact a, DirectoryId artifactDir, TOSCAMetaFile tmf, final List<String> errors) {
    String fileName = rootPath.resolve(a.getFile()).getFileName().toString();
    RepositoryFileReference ref = new RepositoryFileReference(artifactDir, fileName);
    importFile(rootPath.resolve(a.getFile()), ref, tmf, rootPath, errors);
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference)

Example 33 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class YamlCsarImporter method storeDefs.

private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
    RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
    IRepository repo = RepositoryFactory.getRepository();
    FromCanonical converter = null;
    if (repo instanceof GitBasedRepository) {
        GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
        converter = new FromCanonical((YamlRepository) wrapper.getRepository());
    } else if (repo instanceof YamlRepository) {
        converter = new FromCanonical((YamlRepository) repo);
    }
    if (Objects.nonNull(converter)) {
        YamlWriter writer = new YamlWriter();
        writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 34 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.

the class CsarExporter method addSelfServiceMetaData.

/**
 * Adds all self-service metadata to the targetDir
 *
 * @param entryId   the service template to export for
 * @param targetDir the directory in the CSAR where to put the content to
 * @param refMap    is used later to create the CSAR
 */
private void addSelfServiceMetaData(ServiceTemplateId entryId, String targetDir, Map<CsarContentProperties, CsarEntry> refMap) throws IOException {
    final SelfServiceMetaDataId selfServiceMetaDataId = new SelfServiceMetaDataId(entryId);
    // This method is also called if the directory SELF-SERVICE-Metadata exists without content and even if the directory does not exist at all,
    // but the ServiceTemplate itself exists.
    // The current assumption is that this is enough for an existence.
    // Thus, we have to take care of the case of an empty directory and add a default data.xml
    SelfServiceMetaDataUtils.ensureDataXmlExists(repository, selfServiceMetaDataId);
    CsarContentProperties csarContentProperties = new CsarContentProperties(targetDir + "data.xml");
    refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId)));
    // The schema says that the images have to exist
    // However, at a quick modeling, there might be no images
    // Therefore, we check for existence
    final RepositoryFileReference iconJpgRef = SelfServiceMetaDataUtils.getIconJpgRef(selfServiceMetaDataId);
    if (repository.exists(iconJpgRef)) {
        csarContentProperties = new CsarContentProperties(targetDir + "icon.jpg");
        refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, iconJpgRef));
    }
    final RepositoryFileReference imageJpgRef = SelfServiceMetaDataUtils.getImageJpgRef(selfServiceMetaDataId);
    if (repository.exists(imageJpgRef)) {
        csarContentProperties = new CsarContentProperties(targetDir + "image.jpg");
        refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, imageJpgRef));
    }
    Application application = SelfServiceMetaDataUtils.getApplication(repository, selfServiceMetaDataId);
    // set to true only if changes are applied to application
    boolean isApplicationChanged = false;
    if (application.getCsarName() != null) {
        // clear CSAR name as this may change.
        application.setCsarName(null);
        isApplicationChanged = true;
    }
    if (application.getVersion() == null || !application.getVersion().equals("1.0")) {
        // hack for the OpenTOSCA container to display something
        application.setVersion("1.0");
        isApplicationChanged = true;
    }
    List<String> authors = application.getAuthors();
    if (authors.isEmpty()) {
        authors.add("Winery");
        isApplicationChanged = true;
    }
    if (isApplicationChanged) {
        // make the patches to data.xml permanent
        try {
            BackendUtils.persist(application, SelfServiceMetaDataUtils.getDataXmlRef(selfServiceMetaDataId), MediaTypes.MEDIATYPE_TEXT_XML, repository);
        } catch (IOException e) {
            LOGGER.error("Could not persist patches to data.xml", e);
        }
    }
    Options options = application.getOptions();
    if (options != null) {
        SelfServiceMetaDataId id = new SelfServiceMetaDataId(entryId);
        for (ApplicationOption option : options.getOption()) {
            String url = option.getIconUrl();
            if (Util.isRelativeURI(url)) {
                putRefIntoRefMap(targetDir, refMap, id, url);
            }
            url = option.getPlanInputMessageUrl();
            if (Util.isRelativeURI(url)) {
                putRefIntoRefMap(targetDir, refMap, id, url);
            }
        }
    }
}
Also used : RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) Options(org.eclipse.winery.model.selfservice.Application.Options) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) IOException(java.io.IOException) SelfServiceMetaDataId(org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId) Application(org.eclipse.winery.model.selfservice.Application)

Example 35 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference in project container by OpenTOSCA.

the class WineryExporter method getEntryDefs.

private org.eclipse.winery.model.tosca.TDefinitions getEntryDefs(Csar csar, IRepository repo) {
    Collection<RepositoryFileReference> entryDefRefs = new HashSet<RepositoryFileReference>();
    entryDefRefs.addAll(repo.getContainedFiles(new ServiceTemplateId(new QName(csar.entryServiceTemplate().getTargetNamespace(), csar.entryServiceTemplate().getId()))));
    for (RepositoryFileReference ref : entryDefRefs) {
        if (ref.getFileName().endsWith(".tosca")) {
            try {
                return repo.definitionsFromRef(ref);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) QName(javax.xml.namespace.QName) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) HashSet(java.util.HashSet)

Aggregations

RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)81 IOException (java.io.IOException)33 Path (java.nio.file.Path)26 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)17 QName (javax.xml.namespace.QName)14 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)14 InputStream (java.io.InputStream)13 ArrayList (java.util.ArrayList)12 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)12 IRepository (org.eclipse.winery.repository.backend.IRepository)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 PlanId (org.eclipse.winery.model.ids.elements.PlanId)10 PlansId (org.eclipse.winery.model.ids.elements.PlansId)10 XmlId (org.eclipse.winery.model.ids.XmlId)9 Test (org.junit.jupiter.api.Test)9 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)8 MediaType (org.apache.tika.mime.MediaType)7 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)7 BufferedInputStream (java.io.BufferedInputStream)6 HashMap (java.util.HashMap)6