use of org.eclipse.vorto.repository.plugin.generator.GenerationException in project vorto by eclipse.
the class DefaultGeneratorPluginService method incrementMetric.
private void incrementMetric(String serviceKey) {
GeneratorMetric generatorEntity = Optional.ofNullable(generatorMetrics.findByGeneratorKey(serviceKey)).orElseThrow(() -> new GenerationException("Generator plugin with key " + serviceKey + " is not found in metrics database"));
generatorEntity.increaseInvocationCount();
generatorMetrics.save(generatorEntity);
}
use of org.eclipse.vorto.repository.plugin.generator.GenerationException in project vorto by eclipse.
the class DefaultGeneratorPluginService method doGenerateWithApiVersion1.
private GeneratedOutput doGenerateWithApiVersion1(ModelInfo modelInfo, String serviceKey, Map<String, String> requestParams, String baseUrl) {
if (modelInfo == null) {
throw new ModelNotFoundException("Model with the given ID does not exist", null);
}
if (modelInfo.getType() == ModelType.Datatype || modelInfo.getType() == ModelType.Mapping) {
throw new GenerationException("Provided model is neither an information model nor a function block model!");
}
HttpEntity<String> entity = getUserToken().map(token -> {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Bearer " + token);
return new HttpEntity<>("parameters", headers);
}).orElse(null);
ModelId modelId = modelInfo.getId();
ResponseEntity<byte[]> response = restTemplate.exchange(baseUrl + "/rest/generators/{pluginkey}/generate/{namespace}/{name}/{version}" + attachRequestParams(requestParams), HttpMethod.GET, entity, byte[].class, serviceKey, modelId.getNamespace(), modelId.getName(), modelId.getVersion());
return new GeneratedOutput(response.getBody(), extractFileNameFromHeader(response), response.getHeaders().getContentLength());
}
Aggregations