Search in sources :

Example 71 with RepositoryFileReference

use of org.eclipse.winery.repository.common.RepositoryFileReference 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)

Example 72 with RepositoryFileReference

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

the class CsarExporter method addLicenseAndReadmeFiles.

protected void addLicenseAndReadmeFiles(DefinitionsChildId entryId, Map<CsarContentProperties, CsarEntry> refMap) {
    final RepositoryFileReference licenseRef = new RepositoryFileReference(entryId, Constants.LICENSE_FILE_NAME);
    if (repository.exists(licenseRef)) {
        refMap.put(new CsarContentProperties(BackendUtils.getPathInsideRepo(licenseRef)), new RepositoryRefBasedCsarEntry(repository, licenseRef));
    }
    final RepositoryFileReference readmeRef = new RepositoryFileReference(entryId, Constants.README_FILE_NAME);
    if (repository.exists(readmeRef)) {
        refMap.put(new CsarContentProperties(BackendUtils.getPathInsideRepo(readmeRef)), new RepositoryRefBasedCsarEntry(repository, readmeRef));
    }
}
Also used : RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference)

Example 73 with RepositoryFileReference

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

the class CsarExporter method addNamespacePrefixes.

/**
 * Writes the configured mapping namespace prefix -> namespace to the archive
 * <p>
 * This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using JAXB and stored in
 * the NamespacesResource
 */
private void addNamespacePrefixes(Map<CsarContentProperties, CsarEntry> refMap) {
    // ensure that the namespaces are saved as json
    SortedSet<RepositoryFileReference> references = repository.getContainedFiles(new NamespacesId());
    references.forEach(repositoryFileReference -> {
        if (repositoryFileReference.getFileName().toLowerCase().endsWith(Constants.SUFFIX_JSON)) {
            CsarContentProperties csarContentProperties = new CsarContentProperties(CsarExporter.PATH_TO_NAMESPACES_JSON);
            refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, repositoryFileReference));
        }
    });
}
Also used : RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId)

Example 74 with RepositoryFileReference

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

the class CsarExporter method putRefIntoRefMap.

private void putRefIntoRefMap(String targetDir, Map<CsarContentProperties, CsarEntry> refMap, GenericId id, String fileName) {
    RepositoryFileReference ref = new RepositoryFileReference(id, fileName);
    if (repository.exists(ref)) {
        CsarContentProperties csarContentProperties = new CsarContentProperties(targetDir + fileName);
        refMap.put(csarContentProperties, new RepositoryRefBasedCsarEntry(repository, ref));
    } else {
        CsarExporter.LOGGER.error("Data corrupt: pointing to non-existent file " + ref);
    }
}
Also used : RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference)

Example 75 with RepositoryFileReference

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

the class YamlToscaExportUtil method prepareServiceTemplateForExport.

/**
 * Prepares artifacts in Service Template
 */
private void prepareServiceTemplateForExport(IRepository repository, ServiceTemplateId id, TDefinitions entryDefinitions) throws IOException {
    BackendUtils.synchronizeReferences(id, repository);
    TServiceTemplate st = repository.getElement(id);
    String serviceTemplatePath = BackendUtils.getPathInsideRepo(id);
    if (Objects.nonNull(st.getTopologyTemplate())) {
        for (TNodeTemplate nodeTemplate : st.getTopologyTemplate().getNodeTemplates()) {
            List<TArtifact> artifacts = nodeTemplate.getArtifacts();
            if (Objects.nonNull(artifacts)) {
                // update file paths in the exported service template
                artifacts.forEach(a -> {
                    UrlValidator customValidator = new UrlValidator();
                    if (customValidator.isValid(a.getFile())) {
                        LOGGER.info("Specified file is a valid URL, start processing the reference");
                        try {
                            String templateArtifactPath = nodeTemplate.getId() + "/" + a.getName();
                            String pathInsideRepo = putRemoteRefAsReferencedItemInCsar(new URL(a.getFile()), serviceTemplatePath, templateArtifactPath);
                            updatePathsInTopologyTemplateArtifacts(entryDefinitions, nodeTemplate, a, pathInsideRepo);
                        } catch (MalformedURLException e) {
                            LOGGER.warn("Supplied URL is invalid: {}", e.getMessage());
                        }
                    } else {
                        Path p = Paths.get("files", nodeTemplate.getId(), a.getId());
                        RepositoryFileReference ref = new RepositoryFileReference(id, p, a.getFile());
                        try {
                            if (repository.exists(ref)) {
                                putRefAsReferencedItemInCsar(repository, ref);
                                String pathInsideRepo = BackendUtils.getPathInsideRepo(ref);
                                updatePathsInTopologyTemplateArtifacts(entryDefinitions, nodeTemplate, a, pathInsideRepo);
                            }
                        } catch (Exception e) {
                            LOGGER.warn("Could not add artifact reference: {}", e.getMessage());
                        }
                    }
                });
            // TODO: update "primary" field in the exported service template
            }
        }
    }
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TArtifact(org.eclipse.winery.model.tosca.TArtifact) UrlValidator(org.apache.commons.validator.routines.UrlValidator) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

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