use of org.eclipse.vorto.repository.api.exception.GenerationException in project vorto by eclipse.
the class GenerationDelegateProxyService method generate.
@Override
public GeneratedOutput generate(ModelId modelId, String serviceKey, Map<String, String> requestParams) {
ModelInfo modelResource = modelRepositoryService.getById(modelId);
if (modelResource == null) {
throw new ModelNotFoundException("Model with the given ID does not exist", null);
}
if (modelResource.getType() == ModelType.Datatype || modelResource.getType() == ModelType.Mapping) {
throw new GenerationException("Provided model is neither an information model nor a function block model!");
}
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
Generator generatorEntity = getGenerator(serviceKey);
if (generatorEntity == null) {
throw new GenerationException("Generator with key " + serviceKey + " is not a registered generator");
}
generatorEntity.increaseInvocationCount();
this.registeredGeneratorsRepository.save(generatorEntity);
ResponseEntity<byte[]> entity = restTemplate.getForEntity(generatorEntity.getGenerationEndpointUrl() + attachRequestParams(requestParams), byte[].class, modelId.getNamespace(), modelId.getName(), modelId.getVersion());
return new GeneratedOutput(entity.getBody(), extractFileNameFromHeader(entity), entity.getHeaders().getContentLength());
}
Aggregations