Search in sources :

Example 11 with IModelWorkspace

use of org.eclipse.vorto.server.commons.reader.IModelWorkspace in project vorto by eclipse.

the class ModelReaderTest method testReadFunctionblockModelsFromZipFile.

@Test
public void testReadFunctionblockModelsFromZipFile() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("models.zip"))).read();
    assertEquals(2, workspace.get().stream().filter(p -> p instanceof FunctionblockModel).collect(Collectors.toList()).size());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Assert.assertNotNull(org.junit.Assert.assertNotNull) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ModelType(org.eclipse.vorto.repository.api.ModelType) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ZipInputStream(java.util.zip.ZipInputStream) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Test(org.junit.Test)

Example 12 with IModelWorkspace

use of org.eclipse.vorto.server.commons.reader.IModelWorkspace in project vorto by eclipse.

the class ModelReaderTest method testReadFromFile.

@Test
public void testReadFromFile() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example_AWSIoTButton_1_0_0.infomodel"), ModelType.InformationModel).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_AWSButtonMapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button1Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button2Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.ipso.smartobjects_Push_button_0_0_1.fbmodel"), ModelType.Functionblock).read();
    InformationModel model = (InformationModel) workspace.get().stream().filter(p -> p instanceof InformationModel).findAny().get();
    assertNotNull(model);
    assertEquals("AWSIoTButton", model.getName());
    assertEquals("AWSButtonMapping", workspace.get().stream().filter(p -> p.getName().equals("AWSButtonMapping")).findAny().get().getName());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Assert.assertNotNull(org.junit.Assert.assertNotNull) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ModelType(org.eclipse.vorto.repository.api.ModelType) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Model(org.eclipse.vorto.core.api.model.model.Model) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) Test(org.junit.Test)

Example 13 with IModelWorkspace

use of org.eclipse.vorto.server.commons.reader.IModelWorkspace in project vorto by eclipse.

the class CodeGenerationController method createInvocationContext.

private InvocationContext createInvocationContext(InformationModel model, String targetPlatform, Map<String, String> requestParams) {
    byte[] mappingResources = downloadMappingModel(model, targetPlatform);
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingResources))).read();
    List<MappingModel> mappingModels = workspace.get().stream().filter(p -> p instanceof MappingModel).map(MappingModel.class::cast).collect(Collectors.toList());
    return new InvocationContext(mappingModels, lookupService, requestParams);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationContext(org.eclipse.vorto.codegen.api.InvocationContext) IModelWorkspace(org.eclipse.vorto.server.commons.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)13 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)13 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Collectors (java.util.stream.Collectors)8 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)8 Model (org.eclipse.vorto.core.api.model.model.Model)8 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)7 List (java.util.List)6 IOException (java.io.IOException)5 Optional (java.util.Optional)5 Test (org.junit.Test)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 IOUtils (org.apache.commons.io.IOUtils)4 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)4 Api (io.swagger.annotations.Api)3 ApiOperation (io.swagger.annotations.ApiOperation)3