Search in sources :

Example 1 with FileContentResource

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ArrayList(java.util.ArrayList) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) ZipInputStream(java.util.zip.ZipInputStream) ModelResource(org.eclipse.vorto.repository.core.ModelResource) ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.eclipse.vorto.core.api.model.model.Model) FileContentResource(org.eclipse.vorto.repository.plugin.FileContentResource) ChangeSet(org.eclipse.vorto.model.refactor.ChangeSet) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 2 with FileContentResource

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()));
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ValidationReport(org.eclipse.vorto.repository.importer.ValidationReport) FileContentResource(org.eclipse.vorto.repository.plugin.FileContentResource) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

FileContentResource (org.eclipse.vorto.repository.plugin.FileContentResource)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 MultiValueMap (org.springframework.util.MultiValueMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 ZipInputStream (java.util.zip.ZipInputStream)1 Model (org.eclipse.vorto.core.api.model.model.Model)1 ModelId (org.eclipse.vorto.model.ModelId)1 ChangeSet (org.eclipse.vorto.model.refactor.ChangeSet)1 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)1 ModelResource (org.eclipse.vorto.repository.core.ModelResource)1 ValidationReport (org.eclipse.vorto.repository.importer.ValidationReport)1 IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)1