Search in sources :

Example 1 with ModelIdToModelContentConverter

use of org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter in project vorto by eclipse.

the class ModelController method getModelContent.

@PreAuthorize("isAuthenticated() or hasAuthority('model_viewer')")
@GetMapping("/{modelId:.+}/content")
public ModelContent getModelContent(@ApiParam(value = "The modelId of vorto model, e.g. com.mycompany:Car:1.0.0", required = true) @PathVariable final String modelId) {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.modelRepositoryFactory);
    return converter.convert(modelID, Optional.empty());
}
Also used : ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ModelId(org.eclipse.vorto.model.ModelId) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ModelIdToModelContentConverter

use of org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter in project vorto by eclipse.

the class ModelController method getModelContentForTargetPlatform.

@PreAuthorize("isAuthenticated() or hasAuthority('model_viewer')")
@GetMapping("/{modelId:.+}/content/{targetplatformKey}")
public ModelContent getModelContentForTargetPlatform(@ApiParam(value = "The modelId of vorto model, e.g. com.mycompany:Car:1.0.0", required = true) @PathVariable final String modelId, @ApiParam(value = "The key of the targetplatform, e.g. lwm2m", required = true) @PathVariable final String targetplatformKey) {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.modelRepositoryFactory);
    return converter.convert(modelID, Optional.of(targetplatformKey));
}
Also used : ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ModelId(org.eclipse.vorto.model.ModelId) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ModelIdToModelContentConverter

use of org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter in project vorto by eclipse.

the class DefaultGeneratorPluginService method doGenerateWithApiVersion2.

private GeneratedOutput doGenerateWithApiVersion2(ModelId modelId, String serviceKey, Map<String, String> requestParams, String baseUrl) {
    ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.modelRepositoryFactory);
    ModelContent content = converter.convert(modelId, Optional.of(serviceKey));
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Generating with V2. Sending following json content {}", new ObjectMapper().writeValueAsString(content));
        }
    } catch (JsonProcessingException e) {
        LOGGER.trace("Error processing JSON for logging", e);
    }
    ResponseEntity<byte[]> response = restTemplate.exchange(baseUrl + "/api/2/plugins/generators/{pluginkey}" + attachRequestParams(requestParams), HttpMethod.PUT, new HttpEntity<>(content), byte[].class, serviceKey);
    return new GeneratedOutput(response.getBody(), extractFileNameFromHeader(response), response.getHeaders().getContentLength());
}
Also used : ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ModelContent(org.eclipse.vorto.model.ModelContent) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ModelIdToModelContentConverter (org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter)3 ModelId (org.eclipse.vorto.model.ModelId)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ModelContent (org.eclipse.vorto.model.ModelContent)1 GeneratedOutput (org.eclipse.vorto.repository.plugin.generator.GeneratedOutput)1