Search in sources :

Example 76 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)

Example 77 with RepositoryFileReference

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

the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.

@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
    assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
    assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
    assertEquals("file.txt", repositoryFileReference.getFileName());
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 78 with RepositoryFileReference

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

the class BackendUtilsTest method repositoryFileReferenceWithSubdirectoryCorrectlyCreated.

@Test
public void repositoryFileReferenceWithSubdirectoryCorrectlyCreated() {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("d1", "d2");
    final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "d1", "d2", "file.txt"), artifactTemplateSourceDirectoryId);
    assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
    assertEquals(Optional.of(subDirectories), repositoryFileReference.getSubDirectory());
    assertEquals("file.txt", repositoryFileReference.getFileName());
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 79 with RepositoryFileReference

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

the class BackendUtilsTestWithGitBackedRepository method getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile.

@Test
public void getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile() throws Exception {
    this.setRevisionTo("origin/plain");
    NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
    // Make some changes to an associated file
    RepositoryFileReference ref = new RepositoryFileReference(id, EncodingUtil.URLdecode("README.md"));
    RepositoryFactory.getRepository().putContentToFile(ref, "someUnguessableContent", MediaType.TEXT_PLAIN);
    List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
    assertTrue(versions.get(0).isEditable());
    List<WineryVersion> collect = versions.stream().filter(item -> !item.isEditable()).collect(Collectors.toList());
    assertEquals(4, collect.size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MediaType(org.apache.tika.mime.MediaType) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) LinkedHashMap(java.util.LinkedHashMap) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) Test(org.junit.jupiter.api.Test) WineryVersion(org.eclipse.winery.common.version.WineryVersion) List(java.util.List) VersionState(org.eclipse.winery.common.version.VersionState) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaDiff(org.eclipse.winery.model.version.ToscaDiff) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

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