ToOMS_V1_0.java [src/java/m/prms/conv] Revision: default  Date:
package m.prms.conv;

import csip.ModelDataService;
import csip.api.server.ServiceException;
import csip.annotations.*;
import java.io.File;
import javax.ws.rs.Path;
import oms3.io.CSProperties;

/**
 * PRMS/OMS Resource conversion.
 *
 * @author od
 */
@Name("PRMS")
@Description("Parameter file converter MMS -> OMS")
@State(State.UNSTABLE)
@Author(org = "USGS")
@Author(org = "CSU")
@Category("Hydrology")
@Path("m/mms_to_oms/params/convert/1.0")
public class ToOMS_V1_0 extends ModelDataService {

  static final String FILE = "file";


  @Override
  protected void doProcess() throws Exception {

    File f = formdata().getFile(FILE);
    File result = null;
    if (f.toString().endsWith("statvar")) {
      result = Convert.fromStatvar(f);
    } else if (f.toString().endsWith("param")) {
      result = Convert.fromParam(f);

      String name = result.getName();
      File result_asspreadsheet = new File(f.getParentFile(), name.substring(0, name.indexOf('.')) + "-spreadsheet.csv");

      CSProperties p = ToOMS_Reformat_V1_0.readParameter(result);
      ToOMS_Reformat_V1_0.writeParameterFile(result_asspreadsheet, p);
      results().put(result_asspreadsheet);

    } else if (f.toString().endsWith("data")) {
      result = Convert.fromData(f);
    } else {
      throw new ServiceException("Error: cannot convert: " + f);
    }
    results().put(result);
  }

}