Search in sources :

Example 1 with GenerationException

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());
}
Also used : ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) GeneratedOutput(org.eclipse.vorto.repository.api.generation.GeneratedOutput) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) GenerationException(org.eclipse.vorto.repository.api.exception.GenerationException)

Aggregations

ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)1 GenerationException (org.eclipse.vorto.repository.api.exception.GenerationException)1 ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)1 GeneratedOutput (org.eclipse.vorto.repository.api.generation.GeneratedOutput)1 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)1