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;
}
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;
}
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;
}
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;
}
Aggregations