use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.
the class SqlConnectorMetaDataExtension method meta.
@Override
public Optional<MetaData> meta(final Map<String, Object> properties) {
final String sqlStatement = (String) properties.get("query");
MetaData metaData = EMPTY_METADATA;
if (sqlStatement != null) {
try (Connection connection = SqlSupport.createConnection(properties)) {
final DatabaseMetaData meta = connection.getMetaData();
final String defaultSchema = DatabaseMetaDataHelper.getDefaultSchema(meta.getDatabaseProductName(), String.valueOf(properties.get("user")));
final String schemaPattern = (String) properties.getOrDefault("schema-pattern", defaultSchema);
final SqlStatementParser parser = new SqlStatementParser(connection, schemaPattern, sqlStatement);
final SqlStatementMetaData sqlStatementMetaData = parseStatement(parser);
metaData = new DefaultMetaData(null, null, sqlStatementMetaData);
} catch (final SQLException e) {
throw new SyndesisServerException(e.getMessage(), e);
}
}
return Optional.of(metaData);
}
use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.
the class IconGenerator method generate.
public static String generate(final String template, final String name) {
Mustache mustache;
try {
mustache = MUSTACHE_FACTORY.compile("/icon-generator/" + template + ".svg.mustache");
} catch (final MustacheNotFoundException e) {
LOG.warn("Unable to load icon template for: `{}`, will use default template", template);
LOG.debug("Unable to load icon template for: {}", template, e);
mustache = MUSTACHE_FACTORY.compile("/icon-generator/default.svg.mustache");
}
final Map<String, String> data = new HashMap<>();
final String color = COLORS[(int) (Math.random() * COLORS.length)];
data.put("color", color);
data.put("letter", LETTERS.get(Character.toUpperCase(name.charAt(0))));
try (StringWriter icon = new StringWriter()) {
mustache.execute(icon, data).flush();
final String trimmed = trimXml(icon.toString());
return "data:image/svg+xml," + ESCAPER.escape(trimmed);
} catch (final IOException e) {
throw new SyndesisServerException("Unable to generate icon from template `" + template + "`, for name: " + name, e);
}
}
use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.
the class JsonSupport method toJsonObject.
public static String toJsonObject(Object... fields) {
try {
StringWriter w = new StringWriter();
JsonGenerator jg = new JsonFactory().createGenerator(w);
jg.writeStartObject();
for (int i = 0; i + 1 < fields.length; i += 2) {
Object key = fields[i];
Object value = fields[i + 1];
if (key != null && value != null) {
jg.writeFieldName(key.toString());
if (value instanceof Boolean) {
jg.writeBoolean((Boolean) value);
} else if (value instanceof Number) {
jg.writeNumber(((Number) value).longValue());
} else {
jg.writeString(value.toString());
}
}
}
jg.writeEndObject();
jg.close();
return w.toString();
} catch (java.io.IOException e) {
throw new SyndesisServerException(e);
}
}
use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.
the class ConnectorIconHandler method get.
@GET
@SuppressWarnings("PMD.CyclomaticComplexity")
public Response get() {
String connectorIcon = connector.getIcon();
if (connectorIcon == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (connectorIcon.startsWith("db:")) {
String connectorIconId = connectorIcon.substring(3);
Icon icon = getDataManager().fetch(Icon.class, connectorIconId);
if (icon == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final StreamingOutput streamingOutput = (out) -> {
try (BufferedSink sink = Okio.buffer(Okio.sink(out));
Source source = Okio.source(iconDao.read(connectorIconId))) {
sink.writeAll(source);
}
};
return Response.ok(streamingOutput, icon.getMediaType()).build();
} else if (connectorIcon.startsWith("extension:")) {
String iconFile = connectorIcon.substring(10);
Optional<InputStream> extensionIcon = connector.getDependencies().stream().filter(Dependency::isExtension).map(Dependency::getId).findFirst().flatMap(extensionId -> extensionDataManager.getExtensionIcon(extensionId, iconFile));
if (extensionIcon.isPresent()) {
final StreamingOutput streamingOutput = (out) -> {
final BufferedSink sink = Okio.buffer(Okio.sink(out));
sink.writeAll(Okio.source(extensionIcon.get()));
sink.close();
};
return Response.ok(streamingOutput, extensionDataManager.getExtensionIconMediaType(iconFile)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
}
// font awesome class name), return 404
if (connectorIcon.startsWith("data:") || !connectorIcon.contains("/")) {
return Response.status(Response.Status.NOT_FOUND).build();
}
final OkHttpClient httpClient = new OkHttpClient();
try {
final okhttp3.Response externalResponse = httpClient.newCall(new Request.Builder().get().url(connectorIcon).build()).execute();
final String contentType = externalResponse.header(CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM);
final String contentLength = externalResponse.header(CONTENT_LENGTH);
final StreamingOutput streamingOutput = (out) -> {
final BufferedSink sink = Okio.buffer(Okio.sink(out));
sink.writeAll(externalResponse.body().source());
sink.close();
};
final Response.ResponseBuilder actualResponse = Response.ok(streamingOutput, contentType);
if (!StringUtils.isEmpty(contentLength)) {
actualResponse.header(CONTENT_LENGTH, contentLength);
}
return actualResponse.build();
} catch (final IOException e) {
throw new SyndesisServerException(e);
}
}
use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.
the class SQLMetricsProviderImpl method rollup.
private IntegrationMetricsSummary rollup(List<IntegrationMetricsSummary> metricsSummaryList) {
Long totalMessages = 0L;
Long totalErrors = 0L;
Optional<Date> totalLastProcessed = Optional.empty();
Optional<Date> totalStart = Optional.empty();
for (IntegrationMetricsSummary summary : metricsSummaryList) {
totalMessages += summary.getMessages();
totalErrors += summary.getErrors();
if (totalLastProcessed.isPresent()) {
totalLastProcessed = summary.getLastProcessed().isPresent() && totalLastProcessed.get().before(summary.getLastProcessed().get()) ? totalLastProcessed : summary.getLastProcessed();
} else {
totalLastProcessed = summary.getLastProcessed();
}
try {
totalStart = Optional.of(dateFormat.parse(openShiftClient.pods().withLabelSelector(SELECTOR).list().getItems().get(0).getStatus().getStartTime()));
} catch (ParseException e) {
throw new SyndesisServerException(e.getMessage(), e);
}
}
return new IntegrationMetricsSummary.Builder().metricsProvider("sql").messages(totalMessages).errors(totalErrors).lastProcessed(totalLastProcessed).start(totalStart).build();
}
Aggregations