Search in sources :

Example 1 with GenerationException

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);
}
Also used : GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException)

Example 2 with GenerationException

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());
}
Also used : Arrays(java.util.Arrays) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) IGeneratorPluginService(org.eclipse.vorto.repository.plugin.generator.IGeneratorPluginService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ArrayList(java.util.ArrayList) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Service(org.springframework.stereotype.Service) Map(java.util.Map) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) RestTemplate(org.springframework.web.client.RestTemplate) OAuth2AuthenticationDetails(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) HttpHeaders(org.springframework.http.HttpHeaders) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ModelId(org.eclipse.vorto.model.ModelId) ModelType(org.eclipse.vorto.model.ModelType) GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) List(java.util.List) ModelContent(org.eclipse.vorto.model.ModelContent) HttpEntity(org.springframework.http.HttpEntity) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) Authentication(org.springframework.security.core.Authentication) GeneratorPluginInfo(org.eclipse.vorto.plugin.generator.GeneratorPluginInfo) HttpHeaders(org.springframework.http.HttpHeaders) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

GenerationException (org.eclipse.vorto.repository.plugin.generator.GenerationException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ModelContent (org.eclipse.vorto.model.ModelContent)1 ModelId (org.eclipse.vorto.model.ModelId)1 ModelType (org.eclipse.vorto.model.ModelType)1 GeneratorPluginInfo (org.eclipse.vorto.plugin.generator.GeneratorPluginInfo)1 ModelIdToModelContentConverter (org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter)1 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)1 IModelRepositoryFactory (org.eclipse.vorto.repository.core.IModelRepositoryFactory)1