use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelImporterTest method testUploadFileWithoutVortolang.
@Test
public void testUploadFileWithoutVortolang() throws Exception {
IUserContext alex = createUserContext("alex", "playground");
UploadModelResult uploadResult = this.importer.upload(FileUpload.create("ColorEnum.type", IOUtils.toByteArray(new ClassPathResource("sample_models/model_without_vortolang.type").getInputStream())), Context.create(alex, Optional.empty()));
assertEquals(true, uploadResult.isValid());
List<ModelInfo> imported = this.importer.doImport(uploadResult.getHandleId(), Context.create(alex, Optional.empty()));
IModelRepository repository = repositoryFactory.getRepository(alex);
String content = new String(repository.getFileContent(imported.get(0).getId(), Optional.empty()).get().getContent(), "utf-8");
System.out.println(content);
assertTrue(content.contains("vortolang 1.0"));
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class GeneralSearchTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
testInfrastructure = new SearchTestInfrastructure();
ModelInfo datatype = testInfrastructure.importModel("Color.type", testInfrastructure.getDefaultUser());
}
use of org.eclipse.vorto.repository.core.ModelInfo 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.core.ModelInfo in project vorto by eclipse.
the class DefaultGeneratorPluginService method generate.
@Override
public GeneratedOutput generate(IUserContext userContext, ModelId modelId, String serviceKey, Map<String, String> requestParams) {
incrementMetric(serviceKey);
IModelRepository repository = modelRepositoryFactory.getRepositoryByModel(modelId);
ModelInfo modelInfo = repository.getById(modelId);
GeneratorPluginConfiguration plugin = getPluginInfo(serviceKey, false);
if (modelInfo.isReleased() && hasGeneratorProductionTag(plugin)) {
return generatedOutputAttachmentHandler.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).orElseGet(() -> generateAndAttachOutput(userContext, modelInfo, serviceKey, requestParams, plugin));
}
return doGenerate(modelInfo, serviceKey, requestParams, plugin);
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class RemoteImporter method validate.
@Override
protected List<ValidationReport> validate(FileUpload fileUpload, Context context) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new FileContentResource(fileUpload));
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<org.eclipse.vorto.plugin.importer.ValidationReport> validationResult = restTemplate.postForEntity(this.endpointUrl + "/api/2/plugins/importers/{pluginkey}/file_validation", requestEntity, org.eclipse.vorto.plugin.importer.ValidationReport.class, this.info.getKey());
org.eclipse.vorto.plugin.importer.ValidationReport result = validationResult.getBody();
if (result.isValid()) {
ModelInfo modelInfo = new ModelInfo(new ModelId(fileUpload.getName(), context.getTargetNamespace().get(), "1.0.0"), org.eclipse.vorto.model.ModelType.Functionblock);
ValidationReport report = modelValidationHelper.validateModelCreation(modelInfo, context.getUser());
return Arrays.asList(report);
} else {
return Arrays.asList(ValidationReport.invalid(result.getMessage()));
}
}
Aggregations