use of javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE in project component-runtime by Talend.
the class ComponentResourceTest method getDetailsMeta.
@Test
void getDetailsMeta() {
final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.getJdbcId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
assertEquals(1, details.getDetails().size());
final ComponentDetail detail = details.getDetails().iterator().next();
assertEquals("true", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.password")).findFirst().orElseThrow(() -> new IllegalArgumentException("No credential found")).getMetadata().get("ui::credential"));
assertEquals("0", detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.timeout")).findFirst().orElseThrow(() -> new IllegalArgumentException("No timeout found")).getDefaultValue());
assertNull(detail.getProperties().stream().filter(p -> p.getPath().equals("configuration.connection.url")).findFirst().orElseThrow(() -> new IllegalArgumentException("No url found")).getDefaultValue());
}
use of javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE in project component-runtime by Talend.
the class ComponentResource method getDependency.
/**
* Return a binary of the dependency represented by `id`.
* It can be maven coordinates for dependencies or a component id.
*
* @param id the dependency identifier.
* @return the dependency binary (jar).
*/
@GET
@Path("dependency/{id}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput getDependency(@PathParam("id") final String id) {
final ComponentFamilyMeta.BaseMeta<?> component = componentDao.findById(id);
final File file;
if (component != null) {
// local dep
file = componentManagerService.manager().findPlugin(component.getParent().getPlugin()).orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No plugin matching the id: " + id)).build())).getContainerFile().orElseThrow(() -> new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No dependency matching the id: " + id)).build()));
} else {
// just try to resolve it locally, note we would need to ensure some security here
// .map(Artifact::toPath).map(localDependencyRelativeResolver
final Artifact artifact = Artifact.from(id);
file = componentManagerService.manager().getContainer().resolve(artifact.toPath());
}
if (!file.exists()) {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(APPLICATION_JSON_TYPE).entity(new ErrorPayload(PLUGIN_MISSING, "No file found for: " + id)).build());
}
return output -> {
// 5k
final byte[] buffer = new byte[40960];
try (final InputStream stream = new BufferedInputStream(new FileInputStream(file), buffer.length)) {
int count;
while ((count = stream.read(buffer)) >= 0) {
if (count == 0) {
continue;
}
output.write(buffer, 0, count);
}
}
};
}
use of javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE in project component-runtime by Talend.
the class ComponentResourceTest method getDetails.
@Test
void getDetails() {
final ComponentDetailList details = base.path("component/details").queryParam("identifiers", client.fetchIndex().getComponents().stream().filter(c -> c.getId().getFamily().equals("chain") && c.getId().getName().equals("list")).findFirst().orElseThrow(() -> new IllegalArgumentException("no chain#list component")).getId().getId()).request(APPLICATION_JSON_TYPE).get(ComponentDetailList.class);
assertEquals(1, details.getDetails().size());
final ComponentDetail detail = details.getDetails().iterator().next();
assertEquals("the-test-component", detail.getId().getPlugin());
assertEquals("chain", detail.getId().getFamily());
assertEquals("list", detail.getId().getName());
assertEquals("The List Component", detail.getDisplayName());
final Collection<ActionReference> remoteActions = detail.getActions();
assertEquals(1, remoteActions.size());
final ActionReference action = remoteActions.iterator().next();
assertEquals("default", action.getName());
assertEquals("healthcheck", action.getType());
assertEquals(6, action.getProperties().size());
assertValidation("remote.urls", detail, validation -> validation.getMinItems() == 1);
assertValidation("remote.urls", detail, validation -> validation.getUniqueItems() != null && validation.getUniqueItems());
assertValidation("remote.user.user", detail, validation -> validation.getMinLength() != null && validation.getMinLength() == 2);
assertValidation("remote.user.password", detail, validation -> validation.getMaxLength() != null && validation.getMaxLength() == 8);
assertValidation("remote.user.password", detail, validation -> validation.getRequired() != null && validation.getRequired());
// for now
assertEquals(0, detail.getLinks().size());
/*
* final Link link = detail.getLinks().iterator().next(); assertEquals("Detail", link.getName());
* assertEquals("/component/...", link.getPath());
*/
}
use of javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE in project component-runtime by Talend.
the class Generator method generatedJira.
private static void generatedJira(final File generatedDir, final String username, final String password, final String version) {
if (username == null || username.trim().isEmpty() || "skip".equals(username)) {
log.error("No JIRA credentials, will skip changelog generation");
return;
}
final String project = "TCOMP";
final String jiraBase = "https://jira.talendforge.org";
final File file = new File(generatedDir, "generated_changelog.adoc");
final Client client = ClientBuilder.newClient().register(new JsonbJaxrsProvider<>());
final String auth = "Basic " + Base64.getEncoder().encodeToString((username + ':' + password).getBytes(StandardCharsets.UTF_8));
try {
final WebTarget restApi = client.target(jiraBase + "/rest/api/2").property("http.connection.timeout", 60000L);
final List<JiraVersion> versions = restApi.path("project/{project}/versions").resolveTemplate("project", project).request(APPLICATION_JSON_TYPE).header("Authorization", auth).get(new GenericType<List<JiraVersion>>() {
});
final String currentVersion = version.replace("-SNAPSHOT", "");
final List<JiraVersion> loggedVersions = versions.stream().filter(v -> (v.isReleased() || jiraVersionMatches(currentVersion, v.getName()))).collect(toList());
if (loggedVersions.isEmpty()) {
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("No version found.");
}
return;
}
final String jql = "project=" + project + " AND labels=\"changelog\"" + loggedVersions.stream().map(v -> "fixVersion=" + v.getName()).collect(joining(" OR ", " AND (", ")"));
final Function<Long, JiraIssues> searchFrom = startAt -> restApi.path("search").queryParam("jql", jql).queryParam("startAt", startAt).request(APPLICATION_JSON_TYPE).header("Authorization", auth).get(JiraIssues.class);
final Function<JiraIssues, Stream<JiraIssues>> paginate = new Function<JiraIssues, Stream<JiraIssues>>() {
@Override
public Stream<JiraIssues> apply(final JiraIssues issues) {
final long nextStartAt = issues.getStartAt() + issues.getMaxResults();
final Stream<JiraIssues> fetched = Stream.of(issues);
return issues.getTotal() > nextStartAt ? Stream.concat(fetched, apply(searchFrom.apply(nextStartAt))) : fetched;
}
};
final Set<String> includeStatus = Stream.of("closed", "resolved", "development done", "qa done", "done").collect(toSet());
final Map<String, TreeMap<String, List<JiraIssue>>> issues = Stream.of(searchFrom.apply(0L)).flatMap(paginate).flatMap(i -> ofNullable(i.getIssues()).map(Collection::stream).orElseGet(Stream::empty)).filter(issue -> includeStatus.contains(issue.getFields().getStatus().getName().toLowerCase(ENGLISH))).flatMap(i -> i.getFields().getFixVersions().stream().map(v -> Pair.of(v, i))).collect(groupingBy(pair -> pair.getKey().getName(), () -> new TreeMap<>(versionComparator()), groupingBy(pair -> pair.getValue().getFields().getIssuetype().getName(), TreeMap::new, collectingAndThen(mapping(Pair::getValue, toList()), l -> {
l.sort(comparing(JiraIssue::getKey));
return l;
}))));
final String changelog = issues.entrySet().stream().map(versionnedIssues -> new StringBuilder("\n\n== Version ").append(versionnedIssues.getKey()).append(versionnedIssues.getValue().entrySet().stream().collect((Supplier<StringBuilder>) StringBuilder::new, (builder, issuesByType) -> builder.append("\n\n=== ").append(issuesByType.getKey()).append("\n\n").append(issuesByType.getValue().stream().collect((Supplier<StringBuilder>) StringBuilder::new, // useful
(a, i) -> a.append("- link:").append(jiraBase).append("/browse/").append(i.getKey()).append("[").append(i.getKey()).append("^]").append(": ").append(i.getFields().getSummary()).append("\n"), StringBuilder::append)), StringBuilder::append))).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println(changelog);
}
} finally {
client.close();
}
}
Aggregations