Search in sources :

Example 1 with ProjectModel

use of org.talend.sdk.component.starter.server.model.ProjectModel in project component-runtime by Talend.

the class ProjectResource method createZip.

@POST
@Path("zip/form")
@Produces("application/zip")
public Response createZip(@FormParam("project") final String compressedModel, @Context final Providers providers) {
    final MessageBodyReader<ProjectModel> jsonReader = providers.getMessageBodyReader(ProjectModel.class, ProjectModel.class, NO_ANNOTATION, APPLICATION_JSON_TYPE);
    final ProjectModel model;
    try (final InputStream gzipInputStream = new ByteArrayInputStream(Base64.getUrlDecoder().decode(compressedModel))) {
        model = jsonReader.readFrom(ProjectModel.class, ProjectModel.class, NO_ANNOTATION, APPLICATION_JSON_TYPE, new MultivaluedHashMap<>(), gzipInputStream);
    } catch (final IOException e) {
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorMessage(e.getMessage())).type(APPLICATION_JSON_TYPE).build());
    }
    final String filename = ofNullable(model.getArtifact()).orElse("zip") + ".zip";
    return Response.ok().entity((StreamingOutput) out -> {
        generator.generate(toRequest(model), out);
        out.flush();
    }).header("Content-Disposition", "inline; filename=" + filename).build();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) BufferedInputStream(java.io.BufferedInputStream) Produces(javax.ws.rs.Produces) ErrorMessage(org.talend.sdk.component.starter.server.model.ErrorMessage) Path(javax.ws.rs.Path) GithubProject(org.talend.sdk.component.starter.server.model.GithubProject) Collections.singletonList(java.util.Collections.singletonList) MediaType(javax.ws.rs.core.MediaType) Collectors.toMap(java.util.stream.Collectors.toMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) Map(java.util.Map) ENGLISH(java.util.Locale.ENGLISH) ZipEntry(java.util.zip.ZipEntry) ProjectGenerator(org.talend.sdk.component.starter.server.service.ProjectGenerator) Context(javax.ws.rs.core.Context) Providers(javax.ws.rs.ext.Providers) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Collections.emptyList(java.util.Collections.emptyList) StandardOpenOption(java.nio.file.StandardOpenOption) StreamingOutput(javax.ws.rs.core.StreamingOutput) NullProgressMonitor(org.eclipse.jgit.lib.NullProgressMonitor) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) FileUtils(org.eclipse.jgit.util.FileUtils) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Writer(java.io.Writer) Annotation(java.lang.annotation.Annotation) PostConstruct(javax.annotation.PostConstruct) WebApplicationException(javax.ws.rs.WebApplicationException) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) ApplicationScoped(javax.enterprise.context.ApplicationScoped) CreateProjectRequest(org.talend.sdk.component.starter.server.model.github.CreateProjectRequest) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) GET(javax.ws.rs.GET) Client(javax.ws.rs.client.Client) Entity.entity(javax.ws.rs.client.Entity.entity) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ClientBuilder(javax.ws.rs.client.ClientBuilder) StarterConfiguration(org.talend.sdk.component.starter.server.configuration.StarterConfiguration) FactoryConfiguration(org.talend.sdk.component.starter.server.model.FactoryConfiguration) Collections.emptyMap(java.util.Collections.emptyMap) FormParam(javax.ws.rs.FormParam) POST(javax.ws.rs.POST) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) FileWriter(java.io.FileWriter) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) File(java.io.File) CreateProjectResponse(org.talend.sdk.component.starter.server.model.github.CreateProjectResponse) TimeUnit(java.util.concurrent.TimeUnit) Result(org.talend.sdk.component.starter.server.model.Result) Collectors.toList(java.util.stream.Collectors.toList) TreeMap(java.util.TreeMap) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) BufferedReader(java.io.BufferedReader) Git(org.eclipse.jgit.api.Git) Comparator(java.util.Comparator) ProjectRequest(org.talend.sdk.component.starter.server.service.domain.ProjectRequest) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) WebApplicationException(javax.ws.rs.WebApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) ErrorMessage(org.talend.sdk.component.starter.server.model.ErrorMessage) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with ProjectModel

use of org.talend.sdk.component.starter.server.model.ProjectModel in project component-runtime by Talend.

the class ProjectResourceTest method formProject.

@Test
void formProject(final WebTarget target) throws IOException {
    final ProjectModel projectModel = new ProjectModel();
    projectModel.setBuildType("Gradle");
    final Map<String, String> files = createZip(projectModel, model -> target.path("project/zip/form").queryParam("compressionType", "gzip").request(MediaType.APPLICATION_JSON_TYPE).accept("application/zip").post(Entity.entity(new Form().param("project", Base64.getEncoder().encodeToString(jsonb.toJson(projectModel).getBytes(StandardCharsets.UTF_8))), APPLICATION_FORM_URLENCODED_TYPE), InputStream.class));
    assertTrue(files.containsKey("application/build.gradle"));
}
Also used : Form(javax.ws.rs.core.Form) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Resources.resourceFileToString(org.talend.sdk.component.starter.server.service.Resources.resourceFileToString) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectModel

use of org.talend.sdk.component.starter.server.model.ProjectModel in project component-runtime by Talend.

the class ProjectResourceTest method beamFacetProcessorOutput.

@Test
void beamFacetProcessorOutput(final WebTarget target) throws IOException {
    final ProjectModel projectModel = new ProjectModel();
    projectModel.setPackageBase("com.foo");
    projectModel.setFacets(singletonList("Apache Beam"));
    {
        final ProjectModel.Processor proc = new ProjectModel.Processor();
        proc.setName("tIn");
        {
            final ProjectModel.NamedModel in = new ProjectModel.NamedModel();
            in.setName("__default__");
            in.setGeneric(true);
            proc.setInputStructures(singletonList(in));
        }
        {
            final ProjectModel.NamedModel out = new ProjectModel.NamedModel();
            out.setName("__default__");
            out.setGeneric(true);
            proc.setOutputStructures(singletonList(out));
        }
        projectModel.setProcessors(singletonList(proc));
    }
    final Map<String, String> files = createZip(projectModel, target);
    assertEquals(resourceFileToString("generated/ProjectResourceTest/beamFacetProcessorOutput/TInProcessorBeamTest.java"), files.get("application/src/test/java/com/foo/processor/TInProcessorBeamTest.java"));
}
Also used : Resources.resourceFileToString(org.talend.sdk.component.starter.server.service.Resources.resourceFileToString) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectModel

use of org.talend.sdk.component.starter.server.model.ProjectModel in project component-runtime by Talend.

the class ProjectResourceTest method gradleTestingProject.

@Test
void gradleTestingProject(final WebTarget target) throws IOException {
    final ProjectModel projectModel = new ProjectModel();
    projectModel.setBuildType("Gradle");
    projectModel.setFacets(singletonList("Talend Component Kit Testing"));
    final String buildFile = createZip(projectModel, target).get("application/build.gradle");
    assertTrue(buildFile.contains("group: 'org.talend.sdk.component', name: 'component-runtime-junit', version: '" + Versions.KIT + "'"), buildFile);
}
Also used : Resources.resourceFileToString(org.talend.sdk.component.starter.server.service.Resources.resourceFileToString) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectModel

use of org.talend.sdk.component.starter.server.model.ProjectModel in project component-runtime by Talend.

the class ProjectResourceTest method wadlFacetMaven.

@Test
void wadlFacetMaven(final WebTarget target) throws IOException {
    final ProjectModel projectModel = new ProjectModel();
    projectModel.setFacets(singletonList("WADL Client Generation"));
    final Map<String, String> files = createZip(projectModel, target);
    assertWadl(files);
    Stream.of("    <dependency>\n" + "      <groupId>org.apache.cxf</groupId>\n" + "      <artifactId>cxf-rt-rs-client</artifactId>\n" + "      <version>3.2.4</version>\n" + "      <scope>compile</scope>\n" + "    </dependency>", "      <plugin>\n" + "        <groupId>org.apache.cxf</groupId>\n" + "        <artifactId>cxf-wadl2java-plugin</artifactId>\n" + "        <version>3.2.4</version>\n" + "        <executions>\n" + "          <execution>\n" + "            <id>generate-http-client-from-wadl</id>\n" + "            <phase>generate-sources</phase>\n" + "            <goals>\n" + "              <goal>wadl2java</goal>\n" + "            </goals>\n" + "          </execution>\n" + "        </executions>\n" + "        <configuration>\n" + "          <wadlOptions>\n" + "            <wadlOption>\n" + "              <wadl>${project.basedir}/src/main/resources/wadl/client.xml</wadl>\n" + "              <packagename>com.application.client.wadl</packagename>\n" + "            </wadlOption>\n" + "          </wadlOptions>\n" + "        </configuration>\n" + "      </plugin>").forEach(string -> assertTrue(files.get("application/pom.xml").contains(string)));
}
Also used : Resources.resourceFileToString(org.talend.sdk.component.starter.server.service.Resources.resourceFileToString) ProjectModel(org.talend.sdk.component.starter.server.model.ProjectModel) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectModel (org.talend.sdk.component.starter.server.model.ProjectModel)12 Test (org.junit.jupiter.api.Test)10 Resources.resourceFileToString (org.talend.sdk.component.starter.server.service.Resources.resourceFileToString)10 InputStream (java.io.InputStream)2 ZipInputStream (java.util.zip.ZipInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Writer (java.io.Writer)1 Annotation (java.lang.annotation.Annotation)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 ArrayList (java.util.ArrayList)1