Search in sources :

Example 1 with Configuration

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;
}
Also used : Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration)

Example 2 with 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;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) java.util(java.util) BasicEList(org.eclipse.emf.common.util.BasicEList) ModelIdFactory(org.eclipse.vorto.core.api.model.model.ModelIdFactory) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) PropertyTypeImpl(org.eclipse.internal.xtend.type.baseimpl.types.PropertyTypeImpl) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) EcoreEList(org.eclipse.emf.ecore.util.EcoreEList) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ModelFactory(org.eclipse.vorto.core.api.model.model.ModelFactory) Function(java.util.function.Function) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Model(org.eclipse.vorto.core.api.model.model.Model) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DatatypePackage(org.eclipse.vorto.core.api.model.datatype.DatatypePackage) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockFactory(org.eclipse.vorto.core.api.model.functionblock.FunctionblockFactory) DatatypeFactory(org.eclipse.vorto.core.api.model.datatype.DatatypeFactory) MeasurementSystem(com.ibm.icu.util.LocaleData.MeasurementSystem) TreeIterator(org.eclipse.emf.common.util.TreeIterator) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ConfigurationImpl(org.eclipse.vorto.core.api.model.functionblock.impl.ConfigurationImpl) EObject(org.eclipse.emf.ecore.EObject) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Status(org.eclipse.vorto.core.api.model.functionblock.Status) BooleanAttribute(com.ibm.icu.text.DateFormat.BooleanAttribute) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BasicEList(org.eclipse.emf.common.util.BasicEList) EObject(org.eclipse.emf.ecore.EObject) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Example 3 with Configuration

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;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) java.util(java.util) BasicEList(org.eclipse.emf.common.util.BasicEList) ModelIdFactory(org.eclipse.vorto.core.api.model.model.ModelIdFactory) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) PropertyTypeImpl(org.eclipse.internal.xtend.type.baseimpl.types.PropertyTypeImpl) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) EcoreEList(org.eclipse.emf.ecore.util.EcoreEList) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ModelFactory(org.eclipse.vorto.core.api.model.model.ModelFactory) Function(java.util.function.Function) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Model(org.eclipse.vorto.core.api.model.model.Model) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DatatypePackage(org.eclipse.vorto.core.api.model.datatype.DatatypePackage) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockFactory(org.eclipse.vorto.core.api.model.functionblock.FunctionblockFactory) DatatypeFactory(org.eclipse.vorto.core.api.model.datatype.DatatypeFactory) MeasurementSystem(com.ibm.icu.util.LocaleData.MeasurementSystem) TreeIterator(org.eclipse.emf.common.util.TreeIterator) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ConfigurationImpl(org.eclipse.vorto.core.api.model.functionblock.impl.ConfigurationImpl) EObject(org.eclipse.emf.ecore.EObject) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Status(org.eclipse.vorto.core.api.model.functionblock.Status) BooleanAttribute(com.ibm.icu.text.DateFormat.BooleanAttribute) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) Status(org.eclipse.vorto.core.api.model.functionblock.Status) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Example 4 with Configuration

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);
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Fault(org.eclipse.vorto.core.api.model.functionblock.Fault)

Example 5 with Configuration

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());
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) BeforeClass(org.junit.BeforeClass) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Collectors(java.util.stream.Collectors) ModelType(org.eclipse.vorto.model.ModelType) ModelConversionUtils(org.eclipse.vorto.core.api.model.ModelConversionUtils) Model(org.eclipse.vorto.core.api.model.model.Model) ArrayList(java.util.ArrayList) List(java.util.List) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Property(org.eclipse.vorto.core.api.model.datatype.Property) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Status(org.eclipse.vorto.core.api.model.functionblock.Status) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Optional(java.util.Optional) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) Assert(org.junit.Assert) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ArrayList(java.util.ArrayList) Property(org.eclipse.vorto.core.api.model.datatype.Property) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Aggregations

Configuration (org.eclipse.vorto.core.api.model.functionblock.Configuration)6 Status (org.eclipse.vorto.core.api.model.functionblock.Status)5 Property (org.eclipse.vorto.core.api.model.datatype.Property)4 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)4 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)4 Collectors (java.util.stream.Collectors)3 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)3 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)3 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)3 Model (org.eclipse.vorto.core.api.model.model.Model)3 BooleanAttribute (com.ibm.icu.text.DateFormat.BooleanAttribute)2 MeasurementSystem (com.ibm.icu.util.LocaleData.MeasurementSystem)2 java.util (java.util)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 BasicEList (org.eclipse.emf.common.util.BasicEList)2 EList (org.eclipse.emf.common.util.EList)2 TreeIterator (org.eclipse.emf.common.util.TreeIterator)2 EObject (org.eclipse.emf.ecore.EObject)2