Search in sources :

Example 1 with Status

use of org.eclipse.vorto.core.api.model.functionblock.Status in project vorto by eclipse.

the class SchemaValidatorTask method generateForFunctionblock.

private void generateForFunctionblock(FunctionBlock fb, InvocationContext context, String targetPath, String jsonFileExt, IGeneratedWriter outputter) {
    if (fb == null) {
        throw new IllegalArgumentException("fb must not be null null");
    }
    String stateTargetPath = targetPath + "/properties";
    String operationTargetPath = targetPath + "/operations";
    String eventTargetPath = targetPath + "/events";
    Configuration configuration = fb.getConfiguration();
    Status status = fb.getStatus();
    Fault fault = fb.getFault();
    if (configuration != null || status != null || fault != null) {
        generateTask(fb, context, outputter, ValidationTaskFactory.getPropertiesValidationTask(jsonFileExt, stateTargetPath));
    }
    generateConfiguration(context, jsonFileExt, outputter, stateTargetPath, configuration);
    generateStatus(context, jsonFileExt, outputter, stateTargetPath, status);
    generateFault(context, jsonFileExt, outputter, stateTargetPath, fault);
    generateEvents(fb, context, jsonFileExt, outputter, eventTargetPath);
    generateOperations(fb, context, jsonFileExt, outputter, operationTargetPath);
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Fault(org.eclipse.vorto.core.api.model.functionblock.Fault)

Example 2 with Status

use of org.eclipse.vorto.core.api.model.functionblock.Status in project vorto by eclipse.

the class TestFunctionBlockFactory method createStatus.

private static Status createStatus() {
    Status status = FunctionblockFactory.eINSTANCE.createStatus();
    status.getProperties().add(createPrimitiveProperty("statusStringParam", PrimitiveType.STRING));
    return status;
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status)

Example 3 with Status

use of org.eclipse.vorto.core.api.model.functionblock.Status in project vorto by eclipse.

the class FunctionBlockXmlTemplate method getContent.

/**
 * Retrieves the content of the XML generation template.
 *
 * @param model the {@link FunctionblockModel}
 * @return generated content for the specified model
 */
public String getContent(final FunctionblockModel model, InvocationContext context) {
    // FB name
    final String name = model.getName();
    try {
        final LWM2M lwm2m = new LWM2M();
        final List<Object> lwm2mObjects = lwm2m.getObject();
        final FunctionBlock functionblock = model.getFunctionblock();
        if (functionblock == null) {
            throw new RuntimeException("This model has no function block.");
        }
        final Object lwm2mObject = new Object();
        // waiting for Issue in
        lwm2mObject.setObjectType("MODefinition");
        // https://github.com/OpenMobileAlliance/OMA-LwM2M-Public-Review/issues
        lwm2mObject.setName(name);
        final IMapped<FunctionblockModel> mappedFunctionblock = context.getMappedElement(model, STEREOTYPE_OBJECT);
        lwm2mObject.setObjectID(Integer.parseInt(mappedFunctionblock.getAttributeValue(OBJECT_ID, "0")));
        lwm2mObject.setObjectURN(mappedFunctionblock.getAttributeValue(OBJECT_URN, "TBD"));
        lwm2mObject.setMultipleInstances(mappedFunctionblock.getAttributeValue(ATTR_MULTIPLE_INSTANCES_MULTIPLE_VALUE, "Single"));
        lwm2mObject.setMandatory(mappedFunctionblock.getAttributeValue(ATTRIBUTE_MANDATORY, "Optional"));
        lwm2mObject.setDescription1(model.getDescription());
        lwm2mObject.setDescription2(mappedFunctionblock.getAttributeValue(ATTRIBUTE_DESCRIPTION2, ""));
        // handle config ------------------------------------------------------
        final Configuration configuration = functionblock.getConfiguration();
        if (configuration != null) {
            final EList<Property> configProps = configuration.getProperties();
            // configuration ==> operations : RW (default)
            handleProperties(lwm2mObject, configProps, "RW", context);
        }
        // handle status ------------------------------------------------------
        final Status status = functionblock.getStatus();
        if (status != null) {
            final EList<Property> statusProps = status.getProperties();
            // status ==> operations : R
            handleProperties(lwm2mObject, statusProps, "R", context);
        }
        // handle operations --------------------------------------------------
        handleOperations(functionblock, lwm2mObject, context);
        // handle fault -------------------------------------------------------
        final Fault fault = functionblock.getFault();
        if (fault != null) {
            final String errMsg = "Unsupported element <fault>" + STR_ABORT_GENERATOR;
            throw new IllegalArgumentException(errMsg);
        }
        // handle events
        final EList<Event> events = functionblock.getEvents();
        if (!events.isEmpty()) {
            final String errMsg = "Unsupported element <events>" + STR_ABORT_GENERATOR;
            throw new IllegalArgumentException(errMsg);
        }
        addSortedResourceIds(name, lwm2mObject);
        lwm2mObjects.add(lwm2mObject);
        return handleMarshalling(lwm2m, name);
    } catch (final RuntimeException e) {
        throw e;
    }
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) LWM2M(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M) Fault(org.eclipse.vorto.core.api.model.functionblock.Fault) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Event(org.eclipse.vorto.core.api.model.functionblock.Event) Object(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Aggregations

Status (org.eclipse.vorto.core.api.model.functionblock.Status)3 Configuration (org.eclipse.vorto.core.api.model.functionblock.Configuration)2 Fault (org.eclipse.vorto.core.api.model.functionblock.Fault)2 LWM2M (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M)1 Object (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 Event (org.eclipse.vorto.core.api.model.functionblock.Event)1 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1