V1_0.java [src/java/m/watershed/outlet] Revision: default  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.watershed.outlet;

import csip.ModelDataService;
import javax.ws.rs.Path;
import csip.annotations.*;
import java.io.*;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.*;
import csip.api.server.Executable;

/**
 * outlet
 *
 * @author JK (using OD's template)
 */
@Name("outlet")
@Description("Example of outlet")
@Path("m/outlet/1.0")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "/bin/lin-amd64/moveoutletstostrm", type = EXECUTABLE, id = "moveoutletstostrm")

public class V1_0 extends ModelDataService {

    // 2) watershed
    @Override
    protected void doProcess() throws Exception {
        String ip = request().getRemoteAddr();

        String file1 = parameter().getString("flow_8_dir");
        File file_dir = attachments().getFile(file1);
        String flow_8dir_path = file_dir.getPath();

        String file2 = parameter().getString("outlet_shp");
        File file_outlet = attachments().getFile(file2);
        String outlet_pt_path = file_outlet.getPath();

        String file3 = parameter().getString("stream");
        File file_stream = attachments().getFile(file3);
        String stream_path = file_stream.getPath();
        String wd = workspace().getDir().toString();

        //Executable e = resources().getExe("mpirun");
        //File e2 = resources().getFile("moveoutletstostrm");
        Executable e = resources().getExe("moveoutletstostrm");
        //e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-p", flow_8dir_path, "-src", stream_path, "-o", outlet_pt_path, "-om", wd +"/outlet_moved.shp", "-md", 300);        
        e.addArguments("-p", flow_8dir_path, "-src", stream_path, "-o", outlet_pt_path, "-om", wd + "/outlet_moved.shp", "-md", 300);
        e.exec();
    }

    // 3) provide the result.
    @Override
    protected void postProcess() throws Exception {
        File ws = workspace().getDir();
        results().put(new File(ws, "outlet_moved.shx"), "move outlets shx to stream");
        results().put(new File(ws, "outlet_moved.dbf"), "move outlets dbf to stream");
        results().put(new File(ws, "outlet_moved.shp"), "move outlets shp to stream");

    }

}