Search in sources :

Example 1 with Constraint

use of org.eclipse.vorto.model.Constraint in project vorto by eclipse.

the class ModelContentToEcoreConverter method createProperty.

private Property createProperty(ModelProperty sourceProperty, ModelBuilder<?> builder, ModelContent context) {
    Property property = DatatypeFactory.eINSTANCE.createProperty();
    property.setName(sourceProperty.getName());
    property.setType(createPropertyType(sourceProperty.getType(), builder, context));
    property.setDescription(sourceProperty.getDescription());
    Presence presence = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createPresence();
    presence.setMandatory(sourceProperty.isMandatory());
    property.setPresence(presence);
    property.setMultiplicity(sourceProperty.isMultiple());
    org.eclipse.vorto.core.api.model.datatype.ConstraintRule rule = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createConstraintRule();
    for (Constraint constraint : sourceProperty.getConstraints()) {
        org.eclipse.vorto.core.api.model.datatype.Constraint eConstraint = org.eclipse.vorto.core.api.model.datatype.DatatypeFactory.eINSTANCE.createConstraint();
        eConstraint.setConstraintValues(constraint.getValue());
        eConstraint.setType(ConstraintIntervalType.valueOf(constraint.getType().name()));
        rule.getConstraints().add(eConstraint);
    }
    property.setConstraintRule(rule);
    return property;
}
Also used : Constraint(org.eclipse.vorto.model.Constraint) Presence(org.eclipse.vorto.core.api.model.datatype.Presence) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 2 with Constraint

use of org.eclipse.vorto.model.Constraint in project vorto by eclipse.

the class ModelDtoFactory method createProperty.

private static ModelProperty createProperty(Property property, Optional<MappingModel> mappingModel) {
    ModelProperty p = new ModelProperty();
    p.setDescription(property.getDescription());
    p.setMandatory(property.getPresence() != null ? property.getPresence().isMandatory() : true);
    p.setMultiple(property.isMultiplicity());
    p.setName(property.getName());
    p.setType(createReferenceType(property.getType()));
    if (property.getConstraintRule() != null && property.getConstraintRule().getConstraints() != null) {
        List<Constraint> constraints = property.getConstraintRule().getConstraints().stream().map(c -> createConstraint(c)).collect(Collectors.toList());
        p.setConstraints(constraints);
    }
    if (property.getPropertyAttributes() != null) {
        List<IPropertyAttribute> attributes = property.getPropertyAttributes().stream().map(a -> createAttribute(a)).collect(Collectors.toList());
        p.setAttributes(attributes);
    }
    if (mappingModel.isPresent()) {
        p.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getPropertyRule(p.getName(), mappingModel.get().getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                p.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                p.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return p;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) EntitySource(org.eclipse.vorto.core.api.model.mapping.EntitySource) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) ReturnType(org.eclipse.vorto.model.ReturnType) Event(org.eclipse.vorto.core.api.model.functionblock.Event) EntityPropertySource(org.eclipse.vorto.core.api.model.mapping.EntityPropertySource) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ModelInfoDto(org.eclipse.vorto.repository.web.api.v1.dto.ModelInfoDto) Map(java.util.Map) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) EnumAttributePropertyType(org.eclipse.vorto.model.EnumAttributePropertyType) Operation(org.eclipse.vorto.model.Operation) AbstractModel(org.eclipse.vorto.model.AbstractModel) EnumLiteral(org.eclipse.vorto.model.EnumLiteral) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) InfoModelPropertySource(org.eclipse.vorto.core.api.model.mapping.InfoModelPropertySource) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) List(java.util.List) DictionaryType(org.eclipse.vorto.model.DictionaryType) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) BooleanAttributeProperty(org.eclipse.vorto.model.BooleanAttributeProperty) OperationSource(org.eclipse.vorto.core.api.model.mapping.OperationSource) ModelEvent(org.eclipse.vorto.model.ModelEvent) Optional(java.util.Optional) IPropertyAttribute(org.eclipse.vorto.model.IPropertyAttribute) Constraint(org.eclipse.vorto.model.Constraint) EnumAttributeProperty(org.eclipse.vorto.model.EnumAttributeProperty) ConstraintType(org.eclipse.vorto.model.ConstraintType) Param(org.eclipse.vorto.model.Param) IUserContext(org.eclipse.vorto.repository.core.IUserContext) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionBlockAttributeSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockAttributeSource) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) Model(org.eclipse.vorto.core.api.model.model.Model) IReferenceType(org.eclipse.vorto.model.IReferenceType) Property(org.eclipse.vorto.core.api.model.datatype.Property) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) EntityModel(org.eclipse.vorto.model.EntityModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) Enum(org.eclipse.vorto.core.api.model.datatype.Enum) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) ModelProperty(org.eclipse.vorto.model.ModelProperty) InfoModelAttributeSource(org.eclipse.vorto.core.api.model.mapping.InfoModelAttributeSource) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) EnumSource(org.eclipse.vorto.core.api.model.mapping.EnumSource) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) Source(org.eclipse.vorto.core.api.model.mapping.Source) ModelType(org.eclipse.vorto.model.ModelType) Stereotype(org.eclipse.vorto.model.Stereotype) FaultSource(org.eclipse.vorto.core.api.model.mapping.FaultSource) EnumModel(org.eclipse.vorto.model.EnumModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BooleanAttributePropertyType(org.eclipse.vorto.model.BooleanAttributePropertyType) Comment(org.eclipse.vorto.repository.domain.Comment) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) IPropertyAttribute(org.eclipse.vorto.model.IPropertyAttribute) Constraint(org.eclipse.vorto.model.Constraint) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) ModelProperty(org.eclipse.vorto.model.ModelProperty) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 3 with Constraint

use of org.eclipse.vorto.model.Constraint in project vorto by eclipse.

the class SpecWithConstraintConfigMapping method createVoltageFb.

private FunctionblockModel createVoltageFb() {
    FunctionblockModel voltageModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:Voltage:1.0.0"));
    ModelProperty sensorValueProperty = new ModelProperty();
    sensorValueProperty.setMandatory(true);
    sensorValueProperty.setName("sensor_value");
    sensorValueProperty.setType(PrimitiveType.FLOAT);
    Constraint constraint = new Constraint(ConstraintType.MAX, "5000");
    sensorValueProperty.setConstraints(Arrays.asList(constraint));
    sensorValueProperty.setTargetPlatformKey("iotbutton");
    sensorValueProperty.addStereotype(Stereotype.createWithXpath("number:toFloat(string:substring(batteryVoltage,0,string:length(batteryVoltage)-2))"));
    ModelProperty sensorUnitsProperty = new ModelProperty();
    sensorUnitsProperty.setMandatory(false);
    sensorUnitsProperty.setName("sensor_units");
    sensorUnitsProperty.setType(PrimitiveType.STRING);
    sensorUnitsProperty.setTargetPlatformKey("iotbutton");
    sensorUnitsProperty.addStereotype(Stereotype.createWithXpath("string:substring(batteryVoltage,string:length(batteryVoltage)-2)"));
    voltageModel.setConfigurationProperties(Arrays.asList(new ModelProperty[] { sensorValueProperty, sensorUnitsProperty }));
    return voltageModel;
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Constraint(org.eclipse.vorto.model.Constraint) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 4 with Constraint

use of org.eclipse.vorto.model.Constraint in project vorto by eclipse.

the class ModelDtoFactory method createParam.

private static Param createParam(org.eclipse.vorto.core.api.model.functionblock.Param p, Optional<MappingModel> mappingModel) {
    Param param = new Param();
    param.setDescription(p.getDescription());
    param.setMultiple(p.isMultiplicity());
    param.setName(p.getName());
    if (p instanceof PrimitiveParam) {
        PrimitiveType pt = ((PrimitiveParam) p).getType();
        param.setType(org.eclipse.vorto.model.PrimitiveType.valueOf(pt.name()));
        if (((PrimitiveParam) p).getConstraintRule() != null && ((PrimitiveParam) p).getConstraintRule().getConstraints() != null) {
            List<Constraint> constraints = ((PrimitiveParam) p).getConstraintRule().getConstraints().stream().map(c -> createConstraint(c)).collect(Collectors.toList());
            param.setConstraints(constraints);
        }
    } else if (p instanceof DictonaryParam) {
        param.setType(createReferenceType(((DictonaryParam) p).getType()));
    } else {
        param.setType(createModelId(((RefParam) p).getType()));
    }
    if (mappingModel.isPresent()) {
        param.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getParamRule(((org.eclipse.vorto.core.api.model.functionblock.Operation) p.eContainer()).getName(), param.getName(), mappingModel.get().getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                param.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                param.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return param;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) EntitySource(org.eclipse.vorto.core.api.model.mapping.EntitySource) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) ReturnType(org.eclipse.vorto.model.ReturnType) Event(org.eclipse.vorto.core.api.model.functionblock.Event) EntityPropertySource(org.eclipse.vorto.core.api.model.mapping.EntityPropertySource) PropertyAttribute(org.eclipse.vorto.core.api.model.datatype.PropertyAttribute) BooleanPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ModelInfoDto(org.eclipse.vorto.repository.web.api.v1.dto.ModelInfoDto) Map(java.util.Map) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) EnumAttributePropertyType(org.eclipse.vorto.model.EnumAttributePropertyType) Operation(org.eclipse.vorto.model.Operation) AbstractModel(org.eclipse.vorto.model.AbstractModel) EnumLiteral(org.eclipse.vorto.model.EnumLiteral) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) InfoModelPropertySource(org.eclipse.vorto.core.api.model.mapping.InfoModelPropertySource) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) List(java.util.List) DictionaryType(org.eclipse.vorto.model.DictionaryType) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) BooleanAttributeProperty(org.eclipse.vorto.model.BooleanAttributeProperty) OperationSource(org.eclipse.vorto.core.api.model.mapping.OperationSource) ModelEvent(org.eclipse.vorto.model.ModelEvent) Optional(java.util.Optional) IPropertyAttribute(org.eclipse.vorto.model.IPropertyAttribute) Constraint(org.eclipse.vorto.model.Constraint) EnumAttributeProperty(org.eclipse.vorto.model.EnumAttributeProperty) ConstraintType(org.eclipse.vorto.model.ConstraintType) Param(org.eclipse.vorto.model.Param) IUserContext(org.eclipse.vorto.repository.core.IUserContext) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionBlockAttributeSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockAttributeSource) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) Model(org.eclipse.vorto.core.api.model.model.Model) IReferenceType(org.eclipse.vorto.model.IReferenceType) Property(org.eclipse.vorto.core.api.model.datatype.Property) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) EntityModel(org.eclipse.vorto.model.EntityModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) Enum(org.eclipse.vorto.core.api.model.datatype.Enum) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference) ModelProperty(org.eclipse.vorto.model.ModelProperty) InfoModelAttributeSource(org.eclipse.vorto.core.api.model.mapping.InfoModelAttributeSource) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) EnumSource(org.eclipse.vorto.core.api.model.mapping.EnumSource) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) EnumLiteralPropertyAttribute(org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) Source(org.eclipse.vorto.core.api.model.mapping.Source) ModelType(org.eclipse.vorto.model.ModelType) Stereotype(org.eclipse.vorto.model.Stereotype) FaultSource(org.eclipse.vorto.core.api.model.mapping.FaultSource) EnumModel(org.eclipse.vorto.model.EnumModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) BooleanAttributePropertyType(org.eclipse.vorto.model.BooleanAttributePropertyType) Comment(org.eclipse.vorto.repository.domain.Comment) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) Constraint(org.eclipse.vorto.model.Constraint) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) Param(org.eclipse.vorto.model.Param) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Aggregations

Property (org.eclipse.vorto.core.api.model.datatype.Property)3 Constraint (org.eclipse.vorto.model.Constraint)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)2 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)2 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)2 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)2 EnumLiteralPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute)2 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)2 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)2 PrimitiveType (org.eclipse.vorto.core.api.model.datatype.PrimitiveType)2 PropertyAttribute (org.eclipse.vorto.core.api.model.datatype.PropertyAttribute)2 PropertyType (org.eclipse.vorto.core.api.model.datatype.PropertyType)2 DictonaryParam (org.eclipse.vorto.core.api.model.functionblock.DictonaryParam)2 Event (org.eclipse.vorto.core.api.model.functionblock.Event)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2