use of org.eclipse.vorto.repository.plugin.generator.GeneratedOutput 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());
}
use of org.eclipse.vorto.repository.plugin.generator.GeneratedOutput 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());
}
use of org.eclipse.vorto.repository.plugin.generator.GeneratedOutput in project vorto by eclipse.
the class GeneratedOutputAttachmentHandler method attachGeneratedOutput.
/**
* This method creates a new attachment on the model with the given output of a generator.
*
* @param userContext - The current user context
* @param modelId - the ID of the model used to invoke the generator
* @param serviceKey - the service key of the generator
* @param requestParams - the parameters of the request
* @param response - the output of the generator
* @param plugin - the info about the invoked generator
* @return the generated output that has been saved as attachment. The returned value has a
* different file name than the one in the response parameter, as attachments of generator outputs
* follow a naming convention.
*/
GeneratedOutput attachGeneratedOutput(IUserContext userContext, ModelId modelId, String serviceKey, Map<String, String> requestParams, GeneratedOutput response, GeneratorPluginConfiguration plugin) {
String filename = buildAttachmentFilename(modelId, serviceKey, requestParams, response, plugin);
FileContent fc = new FileContent(filename, response.getContent());
modelRepositoryFactory.getRepositoryByModel(modelId, userContext).attachFileInElevatedSession(modelId, fc, userContext, GeneratedOutputAttachmentHandler.tagsForRequest(plugin, requestParams));
return new GeneratedOutput(response.getContent(), filename, response.getSize());
}
Aggregations