Search in sources :

Example 1 with JobManager

use of massbank.JobManager in project MassBank-web by MassBank.

the class MassBankAPI method getJobResult.

/**
 * 指定したジョブIDの結果を取得します
 */
public ResultSet[] getJobResult(String jobId) throws AxisFault {
    ResultSet[] rsets = null;
    JobManager jobMgr = new JobManager();
    JobInfo info = null;
    try {
        info = jobMgr.getJobInfo(jobId);
    } catch (SQLException ex) {
        throw new AxisFault("System error! [code=120]");
    }
    jobMgr.end();
    if (info != null) {
        ResultSet rset = null;
        ArrayList<ResultSet> rsetList = new ArrayList<ResultSet>();
        String res = info.getResult();
        String[] lines = res.split("\n");
        int cntLine = 0;
        String hit = "";
        for (int l = 0; l < lines.length; l++) {
            String line = lines[l];
            if (!line.equals("")) {
                switch(cntLine) {
                    case 0:
                        rset = new ResultSet();
                        rset.setQueryName(line);
                        break;
                    case 1:
                        hit = line;
                        if (hit.equals("-1")) {
                            Result rs = new Result();
                            rset.addInfo(rs);
                            rset.setNumResults(-1);
                        }
                        break;
                    case 2:
                        break;
                    default:
                        String[] items = line.split("\t");
                        Result rs = new Result();
                        rs.setId(items[0]);
                        rs.setTitle(items[1]);
                        rs.setFormula(items[2]);
                        rs.setExactMass(items[3]);
                        rs.setScore(items[4]);
                        rset.addInfo(rs);
                }
                cntLine++;
            } else {
                if (cntLine > 0) {
                    rsetList.add(rset);
                    cntLine = 0;
                }
            }
        }
        if (cntLine > 0) {
            rsetList.add(rset);
        }
        rsets = (ResultSet[]) rsetList.toArray(new ResultSet[] {});
    } else {
        // 対象ジョブがない場合
        throw new AxisFault("Job Not found");
    }
    return rsets;
}
Also used : AxisFault(org.apache.axis2.AxisFault) JobInfo(massbank.JobInfo) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) JobManager(massbank.JobManager)

Example 2 with JobManager

use of massbank.JobManager in project MassBank-web by MassBank.

the class MassBankAPI method getJobStatus.

/**
 * 指定したジョブIDの情報を取得する
 */
public JobStatus getJobStatus(String jobId) throws AxisFault {
    JobStatus jobStatus = new JobStatus();
    JobManager jobMgr = new JobManager();
    JobInfo info = null;
    try {
        info = jobMgr.getJobInfo(jobId);
    } catch (SQLException ex) {
        throw new AxisFault("System error! [code=110]");
    }
    jobMgr.end();
    if (info != null) {
        jobStatus.setStatus(info.getStatus());
        jobStatus.setRequestDate(info.getTimeStamp());
    } else {
        // 対象ジョブがない場合
        throw new AxisFault("Job Not found");
    }
    return jobStatus;
}
Also used : AxisFault(org.apache.axis2.AxisFault) JobInfo(massbank.JobInfo) SQLException(java.sql.SQLException) JobManager(massbank.JobManager)

Example 3 with JobManager

use of massbank.JobManager in project MassBank-web by MassBank.

the class MassBankAPI method execBatchJob.

/**
 * バッチ処理を行う
 */
public String execBatchJob(String type, String mailAddress, String[] queryStrings, String[] instrumentTypes, String ionMode) throws AxisFault {
    String jobId = "";
    // クエリをテンポラリファイルに書き出す
    String tempFileName = "";
    try {
        tempFileName = queryStrsToTempFile(queryStrings);
    } catch (AxisFault ex) {
        throw ex;
    }
    // ---------------------------------------
    // パラメータチェック
    // ---------------------------------------
    HashMap<String, Object> mapParam = new HashMap<String, Object>();
    // massTypes は強制的にallを指定
    String[] keys = { "instrumentTypes", "massTypes", "ionMode" };
    Object[] vals = { instrumentTypes, new String[] { "all" }, ionMode };
    for (int i = 0; i < keys.length; i++) {
        mapParam.put(keys[i], vals[i]);
    }
    ApiParameter apiParam = new ApiParameter("execBatchJob", mapParam);
    if (!apiParam.check()) {
        // パラメータ不正の場合、SOAPFault を返す
        String errDetail = apiParam.getErrorDetail();
        throw new AxisFault("Invalid parameter : " + errDetail);
    }
    String param = apiParam.getCgiParam();
    if (param.charAt(0) == '&') {
        param = param.substring(1);
    }
    // ジョブ情報をセットする
    MessageContext context = MessageContext.getCurrentMessageContext();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String time = sdf.format(new Date());
    JobInfo jobInfo = new JobInfo();
    jobInfo.setSessionId("");
    jobInfo.setIpAddr((String) context.getProperty(MessageContext.REMOTE_ADDR));
    jobInfo.setMailAddr(mailAddress);
    jobInfo.setTimeStamp(time);
    jobInfo.setQueryFileName("");
    jobInfo.setQueryFileSize("");
    jobInfo.setSearchParam(param);
    jobInfo.setTempName(tempFileName);
    JobManager jobMgr = new JobManager();
    try {
        jobId = jobMgr.addJobInfo(jobInfo);
        jobMgr.end();
    } catch (SQLException ex) {
        throw new AxisFault("System error! [code=100]");
    }
    return jobId;
}
Also used : AxisFault(org.apache.axis2.AxisFault) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) JobManager(massbank.JobManager) Date(java.util.Date) JobInfo(massbank.JobInfo) MessageContext(org.apache.axis2.context.MessageContext) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SQLException (java.sql.SQLException)3 JobInfo (massbank.JobInfo)3 JobManager (massbank.JobManager)3 AxisFault (org.apache.axis2.AxisFault)3 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 MessageContext (org.apache.axis2.context.MessageContext)1