Search in sources :

Example 6 with DictionaryPropertyType

use of org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType in project vorto by eclipse.

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters.

@Test
public void testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(PrimitiveType.STRING, PrimitiveType.INT)).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    assertEquals(1, model.getFunctionblock().getStatus().getProperties().size());
    assertTrue(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
    assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getKeyType() instanceof PrimitivePropertyType);
    assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getValueType() instanceof PrimitivePropertyType);
}
Also used : PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DictionaryType(org.eclipse.vorto.model.DictionaryType) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Infomodel(org.eclipse.vorto.model.Infomodel) Test(org.junit.Test)

Example 7 with DictionaryPropertyType

use of org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType in project vorto by eclipse.

the class ModelContentToEcoreConverter method createPropertyType.

private PropertyType createPropertyType(IReferenceType referenceType, ModelBuilder<?> builder, ModelContent context) {
    if (referenceType instanceof PrimitiveType) {
        PrimitivePropertyType primitive = DatatypeFactory.eINSTANCE.createPrimitivePropertyType();
        primitive.setType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) referenceType).name()));
        return primitive;
    } else if (referenceType instanceof org.eclipse.vorto.model.ModelId) {
        IModel referencedModel = context.getModels().get((org.eclipse.vorto.model.ModelId) referenceType);
        Type convertedReference = (Type) convert(referencedModel, context, Optional.empty());
        builder.withReference(ModelIdFactory.newInstance(convertedReference));
        ObjectPropertyType objType = DatatypeFactory.eINSTANCE.createObjectPropertyType();
        objType.setType(convertedReference);
        return objType;
    } else if (referenceType instanceof DictionaryType) {
        DictionaryType dictionaryType = (DictionaryType) referenceType;
        DictionaryPropertyType dictionary = DatatypeFactory.eINSTANCE.createDictionaryPropertyType();
        if (dictionaryType.getKey() != null) {
            dictionary.setKeyType(createPropertyType(dictionaryType.getKey(), builder, context));
        }
        if (dictionaryType.getValue() != null) {
            dictionary.setValueType(createPropertyType(dictionaryType.getValue(), builder, context));
        }
        return dictionary;
    } else {
        throw new UnsupportedOperationException("Reference type is not valie");
    }
}
Also used : IModel(org.eclipse.vorto.model.IModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DictionaryType(org.eclipse.vorto.model.DictionaryType) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) Type(org.eclipse.vorto.core.api.model.datatype.Type) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) DictionaryType(org.eclipse.vorto.model.DictionaryType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) ConstraintIntervalType(org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType) IReferenceType(org.eclipse.vorto.model.IReferenceType) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) Infomodel(org.eclipse.vorto.model.Infomodel) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 8 with DictionaryPropertyType

use of org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType in project vorto by eclipse.

the class ModelContentToEcoreConverter method createParams.

private Param[] createParams(List<org.eclipse.vorto.model.Param> params, ModelBuilder<?> builder, ModelContent context) {
    List<Param> ecoreParams = new ArrayList<>();
    for (org.eclipse.vorto.model.Param param : params) {
        if (param.getType() instanceof PrimitiveType) {
            PrimitiveParam type = FunctionblockFactory.eINSTANCE.createPrimitiveParam();
            type.setMultiplicity(param.isMultiple());
            type.setName(param.getName());
            type.setType((org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) param.getType()).name())));
            ecoreParams.add(type);
        } else if (param.getType() instanceof org.eclipse.vorto.model.ModelId) {
            RefParam type = FunctionblockFactory.eINSTANCE.createRefParam();
            type.setMultiplicity(param.isMultiple());
            type.setName(param.getName());
            type.setType((Type) convert(context.getModels().get((org.eclipse.vorto.model.ModelId) param.getType()), context, Optional.empty()));
            ecoreParams.add(type);
        } else if (param.getType() instanceof DictionaryType) {
            DictonaryParam type = FunctionblockFactory.eINSTANCE.createDictonaryParam();
            type.setName(param.getName());
            type.setMultiplicity(param.isMultiple());
            type.setType((DictionaryPropertyType) createPropertyType(param.getType(), builder, context));
            ecoreParams.add(type);
        } else {
            return null;
        }
    }
    return ecoreParams.toArray(new Param[ecoreParams.size()]);
}
Also used : RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ArrayList(java.util.ArrayList) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) DictionaryType(org.eclipse.vorto.model.DictionaryType) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) Type(org.eclipse.vorto.core.api.model.datatype.Type) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) DictionaryType(org.eclipse.vorto.model.DictionaryType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) ConstraintIntervalType(org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType) IReferenceType(org.eclipse.vorto.model.IReferenceType) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) Param(org.eclipse.vorto.core.api.model.functionblock.Param) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) Infomodel(org.eclipse.vorto.model.Infomodel) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType)

Aggregations

DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)8 DictionaryType (org.eclipse.vorto.model.DictionaryType)6 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)5 Infomodel (org.eclipse.vorto.model.Infomodel)5 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)4 ReturnDictonaryType (org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType)4 ReturnObjectType (org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)4 ReturnPrimitiveType (org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType)4 ConstraintIntervalType (org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType)3 PropertyType (org.eclipse.vorto.core.api.model.datatype.PropertyType)3 Type (org.eclipse.vorto.core.api.model.datatype.Type)3 ReturnType (org.eclipse.vorto.core.api.model.functionblock.ReturnType)3 ModelType (org.eclipse.vorto.core.api.model.model.ModelType)3 IReferenceType (org.eclipse.vorto.model.IReferenceType)3 PrimitiveType (org.eclipse.vorto.model.PrimitiveType)3 Test (org.junit.Test)3 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)2 ArrayList (java.util.ArrayList)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1