Search in sources :

Example 6 with ModelNotFoundException

use of org.eclipse.vorto.repository.api.exception.ModelNotFoundException 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)

Example 7 with ModelNotFoundException

use of org.eclipse.vorto.repository.api.exception.ModelNotFoundException in project vorto by eclipse.

the class DefaultCommentService method createComment.

public void createComment(Comment comment) {
    final ModelId id = ModelId.fromPrettyFormat(comment.getModelId());
    if (modelRepository.getById(id) != null) {
        comment.setModelId(id.getPrettyFormat());
        comment.setDate(new Date());
        commentRepository.save(comment);
    } else {
        throw new ModelNotFoundException("Model not found", new PathNotFoundException());
    }
}
Also used : ModelNotFoundException(org.eclipse.vorto.repository.api.exception.ModelNotFoundException) PathNotFoundException(javax.jcr.PathNotFoundException) ModelId(org.eclipse.vorto.repository.api.ModelId) Date(java.util.Date)

Aggregations

ModelNotFoundException (org.eclipse.vorto.repository.api.exception.ModelNotFoundException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PathNotFoundException (javax.jcr.PathNotFoundException)4 IOException (java.io.IOException)3 Node (javax.jcr.Node)3 RepositoryException (javax.jcr.RepositoryException)3 ModelId (org.eclipse.vorto.repository.api.ModelId)3 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)3 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)3 ModelIdHelper (org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 InputStream (java.io.InputStream)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URLDecoder (java.net.URLDecoder)1