Search in sources :

Example 1 with Operation

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

the class CoAPGenerator method generate.

public IGenerationResult generate(InformationModel infomodel, InvocationContext mappingContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
    /*
		/ Generate the client part...
		*/
    String CLIENT_PROJ = infomodel.getName() + COAP_CLIENT_PROJECT_SUFFIX;
    initPaths(CLIENT_PROJ);
    generator.addTask(new CoAPClientInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPMethodTemplate(coapClientPath, COAP_CLIENT_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ClientDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ClientDemoApp", CLIENT_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
        if (fb.getStatus() != null) {
            for (Property property : fb.getStatus().getProperties()) {
                generateForProperty(property, zipOutputter);
            }
        }
        this.generateForClientFunctionBlock(fbp.getType(), zipOutputter);
    }
    /*
		/ Generate the server part...
		*/
    String SERVER_PROJ = infomodel.getName() + COAP_SERVER_PROJECT_SUFFIX;
    initPaths(SERVER_PROJ);
    generator.addTask(new CoAPServerGeneratorTask(COAP_SERVER_NAME, COAP_SERVER_PACKAGE, JAVA_FILE_EXTENSION, coapServerPath, JAVA_INTERFACE_PREFIX + COAP_REQUEST_HANDLER_NAME, COAP_REQUEST_HANDLER_PACKAGE));
    generator.addTask(new CoAPServerIMRequestHandlerGeneratorTask(COAP_REQUEST_HANDLER_NAME, JAVA_FILE_EXTENSION, coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE, JAVA_INTERFACE_PREFIX, COAP_PRIM_TYPE_WRAPPER_SUFFIX, IM_PACKAGE, DT_PACKAGE, getOpParamSetPackage(), getPrimitiveParamWrapperPackage()));
    generator.addTask(new JavaInformationModelGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, JAVA_IMPL_SUFFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new JavaInformationModelInterfaceGeneratorTask(JAVA_FILE_EXTENSION, imTargetPath, IM_PACKAGE, JAVA_INTERFACE_PREFIX, GETTER_PREFIX, SETTER_PREFIX, FB_INTERFACE_PACKAGE, FB_IMPL_PACKAGE));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ICoAPRequestHandlerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new JsonTransformerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new URIAnalyzerTemplate(coapRequestHandlerPath, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new ResourceTemplate(coapServerPath, COAP_SERVER_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new LinkTemplate(coapServerPath, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CoAPServerDemoAppTemplate(coapDemoPath, COAP_DEMO_PACKAGE, COAP_REQUEST_HANDLER_PACKAGE, COAP_SERVER_PACKAGE)));
    generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate("artifact", COAP_DEMO_PACKAGE + ".ServerDemoApp", SERVER_PROJ)));
    generator.generate(infomodel, mappingContext, zipOutputter);
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        this.generateForFunctionBlock(fbp.getType(), zipOutputter);
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            generateForEntity(entity, zipOutputter);
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            generateForEnum(en, zipOutputter);
        }
        for (Operation op : fb.getOperations()) {
            generateForOperation(op, zipOutputter);
        }
    }
    return zipOutputter;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) ICoAPRequestHandlerTemplate(org.eclipse.vorto.codegen.coap.server.templates.ICoAPRequestHandlerTemplate) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ClientTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientTemplate) ClientDemoAppTemplate(org.eclipse.vorto.codegen.coap.client.templates.ClientDemoAppTemplate) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) JavaInformationModelInterfaceGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelInterfaceGeneratorTask) JavaInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelGeneratorTask) PomFileTemplate(org.eclipse.vorto.codegen.coap.common.templates.PomFileTemplate) CoAPServerDemoAppTemplate(org.eclipse.vorto.codegen.coap.server.templates.CoAPServerDemoAppTemplate) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) CoAPClientInformationModelGeneratorTask(org.eclipse.vorto.codegen.coap.client.tasks.CoAPClientInformationModelGeneratorTask) CoAPServerIMRequestHandlerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerIMRequestHandlerGeneratorTask) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) ChainedCodeGeneratorTask(org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask) CoAPMethodTemplate(org.eclipse.vorto.codegen.coap.client.templates.CoAPMethodTemplate) URIAnalyzerTemplate(org.eclipse.vorto.codegen.coap.server.templates.URIAnalyzerTemplate) ResourceTemplate(org.eclipse.vorto.codegen.coap.server.templates.ResourceTemplate) CoAPServerGeneratorTask(org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerGeneratorTask) JsonTransformerTemplate(org.eclipse.vorto.codegen.coap.server.templates.JsonTransformerTemplate) LinkTemplate(org.eclipse.vorto.codegen.coap.server.templates.LinkTemplate)

Example 2 with Operation

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

the class TestFunctionBlockFactory method createOnOperation.

public static Operation createOnOperation() {
    Operation operation = FunctionblockFactory.eINSTANCE.createOperation();
    operation.setName("on");
    operation.setDescription("Turn device on");
    return operation;
}
Also used : Operation(org.eclipse.vorto.core.api.model.functionblock.Operation)

Example 3 with Operation

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

the class TestFunctionBlockFactory method createToggleOperation.

private static Operation createToggleOperation() {
    Operation operation = FunctionblockFactory.eINSTANCE.createOperation();
    operation.setName("Toggle");
    operation.setDescription("Toggle device");
    return operation;
}
Also used : Operation(org.eclipse.vorto.core.api.model.functionblock.Operation)

Example 4 with Operation

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

the class TestFunctionBlockFactory method createOffOperation.

private static Operation createOffOperation() {
    Operation operation = FunctionblockFactory.eINSTANCE.createOperation();
    operation.setName("Off");
    operation.setDescription("Turn device off");
    return operation;
}
Also used : Operation(org.eclipse.vorto.core.api.model.functionblock.Operation)

Example 5 with Operation

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

the class FunctionBlockXmlTemplate method handleOperations.

private void handleOperations(final FunctionBlock functionblock, final Object lwm2mObject, final InvocationContext context) {
    final EList<Operation> operations = functionblock.getOperations();
    for (final Operation operation : operations) {
        if (!context.getMappedElement(operation, STEREOTYPE_RESOURCE).isMapped()) {
            continue;
        }
        final Item item = new Item();
        handleMappingRulesForOperations(lwm2mObject, operation, item, context);
        // handle name
        final String operName = operation.getName();
        // 1:1 mapping
        item.setName(operName);
        // handle operation ==> operations : E
        item.setOperations("E");
        // handle description
        String operDescr = operation.getDescription();
        if (null == operDescr) {
            // as default
            operDescr = "";
        }
        item.setDescription(operDescr);
        // handle operation parameters
        final EList<Param> params = operation.getParams();
        if (!params.isEmpty()) {
            final String errMsg = "Unsupported operation <" + operName + "> with parameter(s) - Generator only supports One-way operations without parameter(s)!";
            throw new IllegalArgumentException(errMsg);
        }
        final ReturnType returnType = operation.getReturnType();
        if (returnType != null) {
            final String errMsg = "Unsupported operation <" + operName + "> with return Type - Generator only supports One-way operations without parameter(s)!";
            throw new IllegalArgumentException(errMsg);
        }
        checkResourceIdConflictAndFillSet(item);
    }
}
Also used : Item(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item) Param(org.eclipse.vorto.core.api.model.functionblock.Param) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType)

Aggregations

Operation (org.eclipse.vorto.core.api.model.functionblock.Operation)5 ChainedCodeGeneratorTask (org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask)1 GenerationResultZip (org.eclipse.vorto.codegen.api.GenerationResultZip)1 CoAPClientInformationModelGeneratorTask (org.eclipse.vorto.codegen.coap.client.tasks.CoAPClientInformationModelGeneratorTask)1 ClientDemoAppTemplate (org.eclipse.vorto.codegen.coap.client.templates.ClientDemoAppTemplate)1 ClientTemplate (org.eclipse.vorto.codegen.coap.client.templates.ClientTemplate)1 CoAPMethodTemplate (org.eclipse.vorto.codegen.coap.client.templates.CoAPMethodTemplate)1 JavaInformationModelGeneratorTask (org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelGeneratorTask)1 JavaInformationModelInterfaceGeneratorTask (org.eclipse.vorto.codegen.coap.common.tasks.JavaInformationModelInterfaceGeneratorTask)1 PomFileTemplate (org.eclipse.vorto.codegen.coap.common.templates.PomFileTemplate)1 CoAPServerGeneratorTask (org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerGeneratorTask)1 CoAPServerIMRequestHandlerGeneratorTask (org.eclipse.vorto.codegen.coap.server.tasks.CoAPServerIMRequestHandlerGeneratorTask)1 CoAPServerDemoAppTemplate (org.eclipse.vorto.codegen.coap.server.templates.CoAPServerDemoAppTemplate)1 ICoAPRequestHandlerTemplate (org.eclipse.vorto.codegen.coap.server.templates.ICoAPRequestHandlerTemplate)1 JsonTransformerTemplate (org.eclipse.vorto.codegen.coap.server.templates.JsonTransformerTemplate)1 LinkTemplate (org.eclipse.vorto.codegen.coap.server.templates.LinkTemplate)1 ResourceTemplate (org.eclipse.vorto.codegen.coap.server.templates.ResourceTemplate)1 URIAnalyzerTemplate (org.eclipse.vorto.codegen.coap.server.templates.URIAnalyzerTemplate)1 Item (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1