V1_0.java [src/java/m/example/simpleservice] Revision:   Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.example.simpleservice;

import csip.ModelDataService;
import javax.ws.rs.Path;
import csip.annotations.*;

/**
 * Fahrenheit conversion.
 *
 * @author od
 */
@Name("simple")
@Description("Example of an simple service")
@Path("m/simpleservice/1.0")
public class V1_0 extends ModelDataService {

    double temp;


    // 1) parse the service input 
    @Override
    protected void preProcess() throws Exception {
        temp = parameter().getDouble("temp");
    }


    // 2) convert the temperature
    @Override
    protected void doProcess() throws Exception {
        temp = temp * (9 / 5) + 32;
        LOG.info("computed temp: " + temp);
    }


    // 3) provide the temperature as a result.
    @Override
    protected void postProcess() throws Exception {
//      putResult("temp", temp, "Temperature", "F");
        results().put("temp", temp, "Temperature", "F");
    }


    public static void onContextInit() {
        System.out.println("Init simple service");
    }


    public static void onContextDestroy() {
        System.out.println("destroy simple service");
    }

}