use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class VortoService method getModel.
public Optional<InformationModel> getModel(String namespace, String name, String version, Optional<String> headerAuth) {
Optional<byte[]> modelResources = downloadUrl(urlForModel(namespace, name, version), headerAuth);
if (!modelResources.isPresent()) {
return Optional.empty();
}
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelResources.get()))).read();
return Optional.of(Utils.toInformationModel(workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get()));
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace 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.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class ModelReaderTest method testFlatInheritanceFBwithDatatypes.
@Test
public void testFlatInheritanceFBwithDatatypes() {
IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/Brightness.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/Light.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/ColorLight.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/TestModel.infomodel"), ModelType.InformationModel).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SomeFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SuperFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SuperSuperFb.fbmodel"), ModelType.Functionblock).read();
InformationModel infomodel = ModelConversionUtils.convertToFlatHierarchy((InformationModel) workspace.get().get(3));
assertEquals("TestModel", infomodel.getName());
Property colorLightProperty = infomodel.getProperties().get(0).getType().getFunctionblock().getStatus().getProperties().stream().filter(p -> p.getName().equals("light")).findFirst().get();
assertNotNull(colorLightProperty);
ObjectPropertyType type = (ObjectPropertyType) colorLightProperty.getType();
Entity colorLight = (Entity) type.getType();
assertEquals(2, colorLight.getProperties().size());
assertEquals(1, colorLight.getReferences().size());
assertEquals(1, infomodel.getProperties().get(0).getType().getReferences().size());
assertEquals("iot.ColorLight", infomodel.getProperties().get(0).getType().getReferences().get(0).getImportedNamespace());
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class ModelReaderTest method testReadInfomodelFromZipFile.
@Test
public void testReadInfomodelFromZipFile() throws Exception {
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("models.zip"))).read();
Model model = workspace.get().stream().filter(p -> p.getName().equals("TI_SensorTag_CC2650")).findAny().get();
assertNotNull(model);
assertTrue(model instanceof InformationModel);
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class ModelReaderTest method testFlatInheritanceFBMultiLevel.
/**
* Tests the flattening mechanism for multi level inheritance in function blocks
*/
@Test
public void testFlatInheritanceFBMultiLevel() {
IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/ParentFbToBeExtended.functionblock"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/TestFb.functionblock"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SubTestFb.functionblock"), ModelType.Functionblock).read();
List<Model> modelList = new ArrayList<>();
workspace.get().forEach(model -> {
modelList.add(ModelConversionUtils.convertToFlatHierarchy(model));
});
FunctionblockModel fbm = (FunctionblockModel) modelList.get(2);
assertEquals("SubTestFb", fbm.getName());
// check status props
Status statusProps = fbm.getFunctionblock().getStatus();
assertEquals(4, statusProps.getProperties().size());
Optional<Property> propFound = statusProps.getProperties().stream().filter(p -> p.getName().equals("myFloatInSubTestFb")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = statusProps.getProperties().stream().filter(p -> p.getName().equals("myFloatInTestFb")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = statusProps.getProperties().stream().filter(p -> p.getName().equals("ParentFloat")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = statusProps.getProperties().stream().filter(p -> p.getName().equals("Parent2ndFloat")).findFirst();
Assert.assertTrue(propFound.isPresent());
// check config props
Configuration config = fbm.getFunctionblock().getConfiguration();
assertEquals(4, config.getProperties().size());
propFound = config.getProperties().stream().filter(p -> p.getName().equals("temperatureSub")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = config.getProperties().stream().filter(p -> p.getName().equals("temperatureTest")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = config.getProperties().stream().filter(p -> p.getName().equals("temperatureParent")).findFirst();
Assert.assertTrue(propFound.isPresent());
propFound = config.getProperties().stream().filter(p -> p.getName().equals("temperatureParent2")).findFirst();
Assert.assertTrue(propFound.isPresent());
}
Aggregations