use of org.eclipse.vorto.repository.plugin.FileContentResource in project vorto by eclipse.
the class RemoteImporter method convert.
@Override
protected List<ModelResource> convert(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<byte[]> conversionResult = restTemplate.postForEntity(this.endpointUrl + "/api/2/plugins/importers/{pluginkey}/file_conversion", requestEntity, byte[].class, this.info.getKey());
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(conversionResult.getBody()))).read();
List<ModelResource> resources = new ArrayList<>();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels(context.getTargetNamespace().get()).execute();
for (Model model : changeSet.get()) {
resources.add(new ModelResource(model));
}
return resources;
}
use of org.eclipse.vorto.repository.plugin.FileContentResource 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