use of org.eclipse.vorto.core.api.model.functionblock.Configuration in project vorto by eclipse.
the class TestFunctionBlockFactory method createConfiguration.
private static Configuration createConfiguration() {
Configuration configuration = FunctionblockFactory.eINSTANCE.createConfiguration();
configuration.getProperties().add(createPrimitiveProperty("configStringParam", PrimitiveType.STRING));
return configuration;
}
use of org.eclipse.vorto.core.api.model.functionblock.Configuration in project vorto by eclipse.
the class ModelConversionUtils method getFlatConfigProperties.
private static List<Property> getFlatConfigProperties(FunctionblockModel fbm) {
EList<Property> properties = new BasicEList<Property>();
TreeIterator<EObject> iter = fbm.eAllContents();
while (iter.hasNext()) {
EObject obj = iter.next();
if (obj instanceof Property) {
Property property = (Property) obj;
if (property.eContainer() instanceof Configuration) {
properties.add(copyProperty(property));
if (property.getType() instanceof ObjectPropertyType) {
ObjectPropertyType objectType = (ObjectPropertyType) property.getType();
if (objectType.getType() instanceof Entity) {
// only flatten entities
Entity entity = (Entity) ((ObjectPropertyType) property.getType()).getType();
EList<Property> entityProperties = getFlatProperties(entity);
entity.getProperties().addAll(entityProperties);
if (entity.getSuperType() != null) {
removeSuperTypeModelReference(entity);
}
entity.getProperties().stream().filter(p -> p.getType() instanceof ObjectPropertyType).forEach(p -> createReference(entity, (ObjectPropertyType) p.getType()));
}
}
}
}
}
if (fbm.getSuperType() != null) {
properties.addAll(getFlatConfigProperties(fbm.getSuperType()));
}
return properties;
}
use of org.eclipse.vorto.core.api.model.functionblock.Configuration in project vorto by eclipse.
the class ModelConversionUtils method convertToFlatHierarchy.
public static FunctionblockModel convertToFlatHierarchy(FunctionblockModel fbm) {
FunctionBlock fb = fbm.getFunctionblock();
// Consolidate all properties
List<Property> configproperties = getFlatConfigProperties(fbm);
List<Property> statusProperties = getFlatStatusProperties(fbm);
List<Property> allProperties = new ArrayList();
allProperties.addAll(configproperties);
allProperties.addAll(statusProperties);
// remove super type reference
if (fbm.getSuperType() != null) {
removeSuperTypeModelReference(fbm);
}
allProperties.stream().filter(p -> p.getType() instanceof ObjectPropertyType).forEach(p -> createReference(fbm, (ObjectPropertyType) p.getType()));
// set status properties
Status status = FunctionblockFactory.eINSTANCE.createStatus();
status.getProperties().addAll(removeDuplicates(statusProperties));
fb.setStatus(status);
// set configuration properties
Configuration configuration = FunctionblockFactory.eINSTANCE.createConfiguration();
configuration.getProperties().addAll(removeDuplicates(configproperties));
fb.setConfiguration(configuration);
// Consolidate all operations
List<Operation> operations = getFlatOperations(fbm);
fb.getOperations().clear();
fb.getOperations().addAll(operations);
return fbm;
}
use of org.eclipse.vorto.core.api.model.functionblock.Configuration in project vorto by eclipse.
the class SchemaValidatorTask method generateForFunctionblock.
private void generateForFunctionblock(FunctionBlock fb, InvocationContext context, String targetPath, String jsonFileExt, IGeneratedWriter outputter) {
if (fb == null) {
throw new IllegalArgumentException("fb must not be null null");
}
String stateTargetPath = targetPath + "/properties";
String operationTargetPath = targetPath + "/operations";
String eventTargetPath = targetPath + "/events";
Configuration configuration = fb.getConfiguration();
Status status = fb.getStatus();
Fault fault = fb.getFault();
if (configuration != null || status != null || fault != null) {
generateTask(fb, context, outputter, ValidationTaskFactory.getPropertiesValidationTask(jsonFileExt, stateTargetPath));
}
generateConfiguration(context, jsonFileExt, outputter, stateTargetPath, configuration);
generateStatus(context, jsonFileExt, outputter, stateTargetPath, status);
generateFault(context, jsonFileExt, outputter, stateTargetPath, fault);
generateEvents(fb, context, jsonFileExt, outputter, eventTargetPath);
generateOperations(fb, context, jsonFileExt, outputter, operationTargetPath);
}
use of org.eclipse.vorto.core.api.model.functionblock.Configuration 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