Search in sources :

Example 16 with ScheduleManageException

use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.

the class ScheduleManagerServlet method processScheduleMasterResponse.

/**
 * スケジュールマスタ検索リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processScheduleMasterResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    String masterId = getParameter(req, "search_masterId");
    String masterGroupId = getParameter(req, "search_masterGroupId");
    Exception exception = null;
    List scheduleMasters = null;
    if (masterId != null && masterId.length() != 0) {
        try {
            ScheduleMaster scheduleMaster = scheduleManager.findScheduleMaster(masterId);
            if (scheduleMaster != null) {
                scheduleMasters = new ArrayList(1);
                scheduleMasters.add(scheduleMaster);
            }
        } catch (ScheduleManageException e) {
            exception = e;
        }
    } else if (masterGroupId != null && masterGroupId.length() != 0) {
        try {
            scheduleMasters = scheduleManager.findScheduleMasters(masterGroupId);
        } catch (ScheduleManageException e) {
            exception = e;
        }
    } else {
        try {
            scheduleMasters = scheduleManager.findAllScheduleMasters();
        } catch (ScheduleManageException e) {
            exception = e;
        }
    }
    final StringBuilder buf = new StringBuilder();
    if ("json".equals(responseType)) {
        resp.setContentType("application/json;charset=UTF-8");
        Map jsonMap = new HashMap();
        if (exception == null) {
            jsonMap.put("scheduleMasters", scheduleMasters);
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            exception.printStackTrace(pw);
            pw.flush();
            jsonMap.put("exception", sw.toString());
        }
        buf.append(toStringConverter.convertToObject(jsonConverter.convertToStream(jsonMap)));
    } else {
        resp.setContentType("text/html;charset=UTF-8");
        if (exception != null) {
            buf.append(exception(exception));
        } else {
            buf.append("<html>");
            buf.append(header(HEADER_SCHEDULE_MASTER));
            buf.append("<body>");
            buf.append(scheduleMasterSearchCondition(getCurrentPath(req), masterId, masterGroupId));
            buf.append(scheduleMasters(req, scheduleMasters));
            buf.append("</body>");
            buf.append("</html>");
        }
    }
    resp.getWriter().println(buf.toString());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) ScheduleMaster(jp.ossc.nimbus.service.scheduler2.ScheduleMaster) PrintWriter(java.io.PrintWriter)

Example 17 with ScheduleManageException

use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.

the class ScheduleManagerServlet method processMakeScheduleResponse.

/**
 * スケジュール作成リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processMakeScheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    Date date = null;
    try {
        date = getDateParameter(req, "date", "yyyyMMdd", true);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'date' is illegal." + e.toString());
        return;
    }
    Exception exception = null;
    List schedules = null;
    try {
        schedules = scheduleManager.makeSchedule(date);
    } catch (ScheduleManageException e) {
        exception = e;
    }
    final StringBuilder buf = new StringBuilder();
    if ("json".equals(responseType)) {
        resp.setContentType("application/json;charset=UTF-8");
        Map jsonMap = new HashMap();
        if (exception == null) {
            jsonMap.put("schedules", schedules);
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            exception.printStackTrace(pw);
            pw.flush();
            jsonMap.put("exception", sw.toString());
        }
        buf.append(toStringConverter.convertToObject(jsonConverter.convertToStream(jsonMap)));
    } else {
        if (exception != null) {
            resp.setContentType("text/html;charset=UTF-8");
            buf.append(exception(exception));
        } else {
            processScheduleMasterResponse(req, resp, responseType);
            return;
        }
    }
    resp.getWriter().println(buf.toString());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Date(java.util.Date) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)17 PrintWriter (java.io.PrintWriter)17 StringWriter (java.io.StringWriter)17 ParseException (java.text.ParseException)17 HashMap (java.util.HashMap)17 LinkedHashMap (java.util.LinkedHashMap)17 Map (java.util.Map)17 TreeMap (java.util.TreeMap)17 ServletException (javax.servlet.ServletException)17 ScheduleManageException (jp.ossc.nimbus.service.scheduler2.ScheduleManageException)17 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Date (java.util.Date)9 Iterator (java.util.Iterator)4 ScheduleMaster (jp.ossc.nimbus.service.scheduler2.ScheduleMaster)3 DefaultSchedule (jp.ossc.nimbus.service.scheduler2.DefaultSchedule)2 Calendar (java.util.Calendar)1 DefaultScheduleDepends (jp.ossc.nimbus.service.scheduler2.DefaultScheduleDepends)1 Schedule (jp.ossc.nimbus.service.scheduler2.Schedule)1 ScheduleDepends (jp.ossc.nimbus.service.scheduler2.ScheduleDepends)1