use of org.eclipse.vorto.model.Operation in project vorto by eclipse.
the class ModelContentToEcoreConverter method convertFunctionblock.
private org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel convertFunctionblock(FunctionblockModel model, ModelContent context) {
FunctionblockBuilder builder = BuilderUtils.newFunctionblock(new ModelId(ModelType.Functionblock, model.getId().getName(), model.getId().getNamespace(), model.getId().getVersion()));
builder.withCategory(model.getCategory());
builder.withDescription(model.getDescription());
builder.withDisplayName(model.getDisplayName());
builder.withVortolang(model.getVortolang());
if (model.getSuperType() != null)
builder.withSuperType(convertSupertype(model.getSuperType(), model, context));
for (ModelProperty sourceProperty : model.getStatusProperties()) {
Property property = createProperty(sourceProperty, builder, context);
builder.withStatusProperty(property);
}
for (ModelProperty sourceProperty : model.getConfigurationProperties()) {
Property property = createProperty(sourceProperty, builder, context);
builder.withConfiguration(property);
}
for (Operation operation : model.getOperations()) {
builder.withOperation(operation.getName(), createReturnTypeOrNull(operation.getResult(), builder, context), operation.getDescription(), operation.isBreakable(), createParams(operation.getParams(), builder, context));
}
for (ModelEvent event : model.getEvents()) {
EventBuilder eventBuilder = BuilderUtils.newEvent(event.getName());
for (ModelProperty sourceProperty : event.getProperties()) {
Property property = createProperty(sourceProperty, builder, context);
eventBuilder.withProperty(property);
}
builder.withEvent(eventBuilder.build());
}
return builder.build();
}
use of org.eclipse.vorto.model.Operation 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;
}
use of org.eclipse.vorto.model.Operation in project vorto by eclipse.
the class SpecWithOperationRule method createModel.
@Override
protected void createModel() {
FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0"));
Operation operation = new Operation("press");
operation.setTargetPlatformKey("iotbutton");
operation.addStereotype(Stereotype.createOperationTarget("data/key", "Pressed"));
buttonModel.setOperations(Arrays.asList(new Operation[] { operation }));
infomodel.getFunctionblocks().add(ModelProperty.Builder("button", buttonModel).build());
}
Aggregations