Search in sources :

Example 1 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.

the class XmlRepositoryTest method subDirectoryExpandedCorrectly.

@Test
public void subDirectoryExpandedCorrectly() throws Exception {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
    RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
    final IRepository repository = this.repository;
    final Path expected = Paths.get("artifacttemplates", "http%3A%2F%2Fwww.example.org", "at", "source", "dir1", "dir2", "dir3", "test.txt");
    assertEquals(expected, repository.getRepositoryRoot().relativize(repository.ref2AbsolutePath(ref)));
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) IRepository(org.eclipse.winery.repository.backend.IRepository) Test(org.junit.jupiter.api.Test)

Example 2 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.

the class XmlRepositoryTest method allFilesCorrectlyImported.

@Test
public void allFilesCorrectlyImported() throws Exception {
    this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
    Path workingDir = Files.createTempDirectory("winery");
    final Path subDir = workingDir.resolve(subDirectories);
    Files.createDirectories(subDir);
    Path tempFile = subDir.resolve("test.txt");
    Files.createFile(tempFile);
    BackendUtils.importDirectory(workingDir, this.repository, artifactTemplateSourceDirectoryId);
    RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
    assertTrue(repository.exists(ref));
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) Test(org.junit.jupiter.api.Test)

Example 3 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.

the class FilebasedRepositoryTest method allFilesCorrectlyImported.

@Test
public void allFilesCorrectlyImported() throws Exception {
    this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
    Path workingDir = Files.createTempDirectory("winery");
    final Path subDir = workingDir.resolve(subDirectories);
    Files.createDirectories(subDir);
    Path tempFile = subDir.resolve("test.txt");
    Files.createFile(tempFile);
    BackendUtils.importDirectory(workingDir, this.repository, artifactTemplateSourceDirectoryId);
    RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
    Assert.assertTrue(repository.exists(ref));
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) Test(org.junit.Test)

Example 4 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.

the class FilebasedRepositoryTest method subDirectoryExpandedCorrectly.

@Test
public void subDirectoryExpandedCorrectly() throws Exception {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
    RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
    final FilebasedRepository repository = (FilebasedRepository) this.repository;
    final Path expected = Paths.get("artifacttemplates", "http%3A%2F%2Fwww.example.org", "at", "source", "dir1", "dir2", "dir3", "test.txt");
    Assert.assertEquals(expected, repository.getRepositoryRoot().relativize(repository.ref2AbsolutePath(ref)));
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) Test(org.junit.Test)

Example 5 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.

the class ArtifactTemplateResource method copySourceToFilesResource.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response copySourceToFilesResource(@ApiParam(value = "if data contains a non-empty array than only the files" + " whose names are included are copied ", required = true) ArtifactResourcesApiData data) {
    List<String> artifactList = data.getArtifactNames();
    DirectoryId sourceDir = new ArtifactTemplateSourceDirectoryId((ArtifactTemplateId) this.id);
    FilesResource filesResource = getFilesResource();
    for (RepositoryFileReference ref : RepositoryFactory.getRepository().getContainedFiles(sourceDir)) {
        if (artifactList == null || artifactList.contains(ref.getFileName())) {
            try (InputStream inputStream = RepositoryFactory.getRepository().newInputStream(ref)) {
                String fileName = ref.getFileName();
                String subDirectory = ref.getSubDirectory().map(s -> s.toString()).orElse("");
                filesResource.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 : MimeTypes(org.eclipse.winery.common.constants.MimeTypes) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) HasType(org.eclipse.winery.model.tosca.HasType) AbstractComponentInstanceWithReferencesResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceWithReferencesResource) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) MediaType(javax.ws.rs.core.MediaType) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Status(javax.ws.rs.core.Response.Status) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) Logger(org.slf4j.Logger) IOException(java.io.IOException) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArtifactResourcesApiData(org.eclipse.winery.repository.rest.resources.apiData.ArtifactResourcesApiData) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) IEntityTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.IEntityTemplateResource) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) RestUtils(org.eclipse.winery.repository.rest.RestUtils) IHasName(org.eclipse.winery.repository.rest.resources._support.IHasName) PropertiesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.PropertiesResource) InputStream(java.io.InputStream) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) InputStream(java.io.InputStream) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) IOException(java.io.IOException)

Aggregations

ArtifactTemplateSourceDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId)8 Path (java.nio.file.Path)6 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)4 Test (org.junit.jupiter.api.Test)4 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)3 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)3 IOException (java.io.IOException)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2 IRepository (org.eclipse.winery.repository.backend.IRepository)2 DirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId)2 Test (org.junit.Test)2 ApiParam (io.swagger.annotations.ApiParam)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 List (java.util.List)1 javax.ws.rs (javax.ws.rs)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1