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();
}
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"));
}
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"));
}
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);
}
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)));
}
Aggregations