Search in sources :

Example 1 with Operation

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();
}
Also used : EventBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EventBuilder) FunctionblockBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.FunctionblockBuilder) ModelProperty(org.eclipse.vorto.model.ModelProperty) Operation(org.eclipse.vorto.model.Operation) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelEvent(org.eclipse.vorto.model.ModelEvent) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 2 with Operation

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;
}
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 3 with 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());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Operation(org.eclipse.vorto.model.Operation)

Aggregations

Operation (org.eclipse.vorto.model.Operation)3 EventBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.EventBuilder)1 FunctionblockBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.FunctionblockBuilder)1 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)1 PrimitiveType (org.eclipse.vorto.core.api.model.datatype.PrimitiveType)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 ReturnDictonaryType (org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType)1 ReturnObjectType (org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)1 ReturnPrimitiveType (org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)1 DictionaryType (org.eclipse.vorto.model.DictionaryType)1 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)1 ModelEvent (org.eclipse.vorto.model.ModelEvent)1 ModelProperty (org.eclipse.vorto.model.ModelProperty)1 ReturnType (org.eclipse.vorto.model.ReturnType)1