Search in sources :

Example 1 with DictionaryPropertyType

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

the class ModelContentToEcoreConverter method createReturnTypeOrNull.

private ReturnType createReturnTypeOrNull(org.eclipse.vorto.model.ReturnType result, FunctionblockBuilder builder, ModelContent context) {
    if (result == null) {
        return null;
    } else {
        if (result.getType() instanceof PrimitiveType) {
            ReturnPrimitiveType type = FunctionblockFactory.eINSTANCE.createReturnPrimitiveType();
            type.setMultiplicity(result.isMultiple());
            type.setReturnType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) result.getType()).name()));
            return type;
        } else if (result.getType() instanceof org.eclipse.vorto.model.ModelId) {
            ReturnObjectType type = FunctionblockFactory.eINSTANCE.createReturnObjectType();
            type.setMultiplicity(result.isMultiple());
            Type convertedType = ((Type) convert(context.getModels().get((org.eclipse.vorto.model.ModelId) result.getType()), context, Optional.empty()));
            builder.withReference(ModelIdFactory.newInstance(convertedType));
            type.setReturnType(convertedType);
            return type;
        } else if (result.getType() instanceof DictionaryType) {
            ReturnDictonaryType type = FunctionblockFactory.eINSTANCE.createReturnDictonaryType();
            type.setMultiplicity(result.isMultiple());
            type.setReturnType((DictionaryPropertyType) createPropertyType(result.getType(), builder, context));
            return type;
        } else {
            return null;
        }
    }
}
Also used : ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) 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) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) Infomodel(org.eclipse.vorto.model.Infomodel) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) DictionaryType(org.eclipse.vorto.model.DictionaryType)

Example 2 with DictionaryPropertyType

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithoutParameters.

@Test
public void testConvertFunctionblockWithDictionaryTypeWithoutParameters() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(null, null)).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);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Infomodel(org.eclipse.vorto.model.Infomodel) DictionaryType(org.eclipse.vorto.model.DictionaryType) Test(org.junit.Test)

Example 3 with DictionaryPropertyType

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

the class ModelDtoFactory method createOperation.

private static Operation createOperation(org.eclipse.vorto.core.api.model.functionblock.Operation o, Optional<MappingModel> mappingModel) {
    Operation operation = new Operation(o.getName());
    operation.setBreakable(o.isBreakable());
    operation.setDescription(o.getDescription());
    operation.setParams(o.getParams().stream().map(p -> createParam(p, mappingModel)).collect(Collectors.toList()));
    if (o.getReturnType() != null) {
        ReturnType returnType = new ReturnType();
        returnType.setMultiple(o.getReturnType().isMultiplicity());
        if (o.getReturnType() instanceof ReturnPrimitiveType) {
            returnType.setPrimitive(true);
            PrimitiveType pt = ((ReturnPrimitiveType) o.getReturnType()).getReturnType();
            returnType.setType(org.eclipse.vorto.model.PrimitiveType.valueOf(pt.name()));
        } else if (o.getReturnType() instanceof ReturnObjectType) {
            returnType.setPrimitive(false);
            returnType.setType(createModelId(((ReturnObjectType) o.getReturnType()).getReturnType()));
        } else if (o.getReturnType() instanceof ReturnDictonaryType) {
            returnType.setPrimitive(false);
            returnType.setMultiple(true);
            DictionaryPropertyType dt = ((ReturnDictonaryType) o.getReturnType()).getReturnType();
            returnType.setType(new DictionaryType(createReferenceType(dt.getKeyType()), createReferenceType(dt.getValueType())));
        }
        operation.setResult(returnType);
    }
    if (mappingModel.isPresent()) {
        operation.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getOperationRule(operation.getName(), mappingModel.get().getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                operation.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                operation.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return operation;
}
Also used : ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) Operation(org.eclipse.vorto.model.Operation) ReturnType(org.eclipse.vorto.model.ReturnType) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) DictionaryType(org.eclipse.vorto.model.DictionaryType)

Example 4 with DictionaryPropertyType

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

the class ModelContentDeserializationTest method testDeserializeWithDictionaryType.

@Test
public void testDeserializeWithDictionaryType() throws Exception {
    ModelContent content = ObjectMapperFactory.getInstance().readValue(new ClassPathResource("json/TestModelContent_dictionary.json").getInputStream(), ModelContent.class);
    assertNotNull(content);
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    FunctionblockModel model = (FunctionblockModel) converter.convert(content, Optional.empty());
    assertNotNull(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ModelContent(org.eclipse.vorto.model.ModelContent) ModelContentToEcoreConverter(org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 5 with DictionaryPropertyType

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

the class ModelConversionUtils method copyProperty.

private static Property copyProperty(Property property) {
    Property newProperty = DatatypeFactory.eINSTANCE.createProperty();
    newProperty.setName(property.getName());
    newProperty.setPresence(property.getPresence());
    newProperty.setMultiplicity(property.isMultiplicity());
    newProperty.setDescription(property.getDescription());
    newProperty.setConstraintRule(property.getConstraintRule());
    if (property.getType() instanceof PrimitivePropertyType) {
        PrimitivePropertyType newPrimitiveType = DatatypeFactory.eINSTANCE.createPrimitivePropertyType();
        PrimitivePropertyType oldPrimitiveType = (PrimitivePropertyType) property.getType();
        newPrimitiveType.setType(oldPrimitiveType.getType());
        newProperty.setType(newPrimitiveType);
    } else if (property.getType() instanceof ObjectPropertyType) {
        ObjectPropertyType newObjectType = DatatypeFactory.eINSTANCE.createObjectPropertyType();
        ObjectPropertyType oldObjectType = (ObjectPropertyType) property.getType();
        newObjectType.setType(oldObjectType.getType());
        newProperty.setType(newObjectType);
    } else if (property.getType() instanceof DictionaryPropertyType) {
        DictionaryPropertyType newObjectType = DatatypeFactory.eINSTANCE.createDictionaryPropertyType();
        DictionaryPropertyType oldObjectType = (DictionaryPropertyType) property.getType();
        newObjectType.setKeyType(oldObjectType.getKeyType());
        newObjectType.setValueType(oldObjectType.getValueType());
        newProperty.setType(newObjectType);
    }
    EList<org.eclipse.vorto.core.api.model.datatype.PropertyAttribute> oldPropertyAtributeList = property.getPropertyAttributes();
    EList<PropertyAttribute> newPropertyAtributeList = new BasicEList<PropertyAttribute>();
    for (org.eclipse.vorto.core.api.model.datatype.PropertyAttribute oldProp : oldPropertyAtributeList) {
        if (oldProp instanceof BooleanPropertyAttribute) {
            BooleanPropertyAttribute newPropertyAtribute = DatatypeFactory.eINSTANCE.createBooleanPropertyAttribute();
            newPropertyAtribute.setType(((BooleanPropertyAttribute) oldProp).getType());
            newPropertyAtribute.setValue((((BooleanPropertyAttribute) oldProp).isValue()));
            newPropertyAtributeList.add(newPropertyAtribute);
        } else {
            EnumLiteralPropertyAttribute newPropertyAtribute = DatatypeFactory.eINSTANCE.createEnumLiteralPropertyAttribute();
            newPropertyAtribute.setType(((EnumLiteralPropertyAttribute) oldProp).getType());
            newPropertyAtribute.setValue((((EnumLiteralPropertyAttribute) oldProp).getValue()));
            newPropertyAtributeList.add(newPropertyAtribute);
        }
    }
    newProperty.getPropertyAttributes().addAll(newPropertyAtributeList);
    return newProperty;
}
Also used : ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) BasicEList(org.eclipse.emf.common.util.BasicEList) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property)

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