Search in sources :

Example 6 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId 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 7 with ArtifactTemplateSourceDirectoryId

use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId 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 8 with ArtifactTemplateSourceDirectoryId

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

the class GenericArtifactsResource method generateImplementationArtifact.

/**
 * Generates the implementation artifact using the implementation artifact generator. Also sets the properties
 * according to the requirements of OpenTOSCA.
 */
private Response generateImplementationArtifact(String interfaceName, String javaPackage, UriInfo uriInfo, ArtifactTemplateId artifactTemplateId) {
    assert (this instanceof ImplementationArtifactsResource);
    IRepository repository = RepositoryFactory.getRepository();
    QName type = RestUtils.getType(this.res);
    EntityTypeId typeId = getTypeId(type).orElseThrow(IllegalStateException::new);
    TInterface i = findInterface(typeId, interfaceName).orElseThrow(IllegalStateException::new);
    Path workingDir;
    try {
        workingDir = Files.createTempDirectory("winery");
    } catch (IOException e2) {
        LOGGER.debug("Could not create temporary directory", e2);
        return Response.serverError().entity("Could not create temporary directory").build();
    }
    URI artifactTemplateFilesUri = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(artifactTemplateId)).resolve("files");
    URL artifactTemplateFilesUrl;
    try {
        artifactTemplateFilesUrl = artifactTemplateFilesUri.toURL();
    } catch (MalformedURLException e2) {
        LOGGER.debug("Could not convert URI to URL", e2);
        return Response.serverError().entity("Could not convert URI to URL").build();
    }
    String name = this.generateName(typeId, interfaceName);
    Generator gen = new Generator(i, javaPackage, artifactTemplateFilesUrl, name, workingDir.toFile());
    Path targetPath;
    try {
        targetPath = gen.generateProject();
    } catch (Exception e) {
        LOGGER.debug("IA generator failed", e);
        return Response.serverError().entity("IA generator failed").build();
    }
    DirectoryId fileDir = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    try {
        BackendUtils.importDirectory(targetPath, repository, fileDir);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
    // clean up
    FileUtils.forceDelete(workingDir);
    this.storeProperties(artifactTemplateId, typeId, name);
    URI url = uriInfo.getBaseUri().resolve(Util.getUrlPath(artifactTemplateId));
    return Response.created(url).build();
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) WebApplicationException(javax.ws.rs.WebApplicationException) TInterface(org.eclipse.winery.model.tosca.TInterface) QName(javax.xml.namespace.QName) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) WebApplicationException(javax.ws.rs.WebApplicationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) EntityTypeId(org.eclipse.winery.model.ids.definitions.EntityTypeId) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) IRepository(org.eclipse.winery.repository.backend.IRepository) Generator(org.eclipse.winery.generators.ia.Generator)

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