Search in sources :

Example 16 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 17 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 18 with RepositoryFileReference

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

the class ArtifactTemplateFilesResource method copySourceToFiles.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response copySourceToFiles(@ApiParam(value = "if data contains a non-empty array than only the files" + " whose names are included are copied ", required = true) ArtifactResourcesApiData data) {
    if (Objects.isNull(this.destinationDir)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    List<String> artifactList = data.getArtifactNames();
    for (RepositoryFileReference ref : RepositoryFactory.getRepository().getContainedFiles(this.fileDir)) {
        if (artifactList == null || artifactList.contains(ref.getFileName())) {
            try (InputStream inputStream = RepositoryFactory.getRepository().newInputStream(ref)) {
                String fileName = ref.getFileName();
                String subDirectory = ref.getSubDirectory().map(java.nio.file.Path::toString).orElse("");
                this.destinationDir.putFile(fileName, subDirectory, inputStream);
            } catch (IOException e) {
                LOGGER.debug("The artifact source " + ref.getFileName() + " could not be copied to the files directory.", e);
                return Response.status(Status.INTERNAL_SERVER_ERROR).build();
            }
        }
    }
    return Response.status(Status.CREATED).build();
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) InputStream(java.io.InputStream) IOException(java.io.IOException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 19 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 20 with RepositoryFileReference

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

the class ToscaExportUtil method prepareForExport.

/**
 * Synchronizes the plan model references and adds the plans to the csar (putRefAsReferencedItemInCsar)
 */
private void prepareForExport(IRepository repository, ServiceTemplateId id) throws IOException {
    // ensure that the plans stored locally are the same ones as stored in the definitions
    BackendUtils.synchronizeReferences(id, repository);
    // add all plans as reference in the CSAR
    // the data model is consistent with the repository
    // we crawl through the repository to as putRefAsReferencedItemInCsar expects a repository file reference
    PlansId plansContainerId = new PlansId(id);
    SortedSet<PlanId> nestedPlans = repository.getNestedIds(plansContainerId, PlanId.class);
    for (PlanId planId : nestedPlans) {
        SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(planId);
        // even if we currently support only one file in the directory, we just add everything
        for (RepositoryFileReference ref : containedFiles) {
            putRefAsReferencedItemInCsar(repository, ref);
        }
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) PlanId(org.eclipse.winery.model.ids.elements.PlanId) PlansId(org.eclipse.winery.model.ids.elements.PlansId)

Aggregations

RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)79 IOException (java.io.IOException)33 Path (java.nio.file.Path)24 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 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)9 Test (org.junit.jupiter.api.Test)9 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)8 PlanId (org.eclipse.winery.model.ids.elements.PlanId)8 PlansId (org.eclipse.winery.model.ids.elements.PlansId)8 IRepository (org.eclipse.winery.repository.backend.IRepository)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 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)6