use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processIsMakeScheduleResponse.
/**
* スケジュール作成判定リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processIsMakeScheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String masterId = getParameter(req, "masterId");
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;
}
Date from = null;
try {
from = getDateParameter(req, "from", "yyyyMMdd", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'from' is illegal." + e.toString());
return;
}
Date to = null;
try {
to = getDateParameter(req, "to", "yyyyMMdd", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'to' is illegal." + e.toString());
return;
}
Exception exception = null;
boolean isMake = false;
Map masterIdDayMap = new TreeMap();
try {
if (masterId != null) {
ScheduleMaster scheduleMaster = scheduleManager.findScheduleMaster(masterId);
ScheduleMaker scheduleMaker = scheduleMaster != null ? scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType()) : null;
if (scheduleMaster == null) {
exception = new Exception("scheduleMaster not found. masterId=" + masterId);
} else {
Map dayMap = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), dayMap);
if (from == null && to == null) {
isMake = scheduleMaker.isMakeSchedule(date, scheduleMaster);
dayMap.put(date, isMake ? Boolean.TRUE : Boolean.FALSE);
} else {
if (to == null) {
to = date;
} else if (from == null) {
from = date;
}
Calendar current = Calendar.getInstance();
current.setTime(from);
Calendar toCal = Calendar.getInstance();
toCal.setTime(to);
while (current.before(toCal) || current.equals(toCal)) {
Date today = current.getTime();
isMake = scheduleMaker.isMakeSchedule(today, scheduleMaster);
dayMap.put(today, isMake ? Boolean.TRUE : Boolean.FALSE);
current.add(Calendar.DAY_OF_YEAR, 1);
}
}
}
} else {
List scheduleMasters = scheduleManager.findAllScheduleMasters();
if (from == null && to == null) {
for (int i = 0; i < scheduleMasters.size(); i++) {
ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
ScheduleMaker scheduleMaker = scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType());
isMake = scheduleMaker.isMakeSchedule(date, scheduleMaster);
Map map = (Map) masterIdDayMap.get(scheduleMaster.getId());
if (map == null) {
map = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), map);
}
map.put(date, isMake ? Boolean.TRUE : Boolean.FALSE);
}
} else {
if (to == null) {
to = date;
} else if (from == null) {
from = date;
}
Calendar current = Calendar.getInstance();
current.setTime(from);
Calendar toCal = Calendar.getInstance();
toCal.setTime(to);
while (current.before(toCal) || current.equals(toCal)) {
Date today = current.getTime();
for (int i = 0; i < scheduleMasters.size(); i++) {
ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
ScheduleMaker scheduleMaker = scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType());
isMake = scheduleMaker.isMakeSchedule(today, scheduleMaster);
Map map = (Map) masterIdDayMap.get(scheduleMaster.getId());
if (map == null) {
map = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), map);
}
map.put(today, isMake ? Boolean.TRUE : Boolean.FALSE);
}
current.add(Calendar.DAY_OF_YEAR, 1);
}
}
}
} 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) {
List result = new ArrayList();
Iterator entries = masterIdDayMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Map resultMap = new HashMap(2);
resultMap.put("masterId", entry.getKey());
List resultList = new ArrayList();
Iterator entries2 = ((Map) entry.getValue()).entrySet().iterator();
while (entries2.hasNext()) {
Map.Entry entry2 = (Map.Entry) entries2.next();
Map resultMap2 = new HashMap(2);
resultMap2.put("date", entry2.getKey());
resultMap2.put("isMake", entry2.getValue());
resultList.add(resultMap2);
}
resultMap.put("result", resultList);
result.add(resultMap);
}
jsonMap.put("result", result);
} 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_OTHER));
buf.append("<body>");
buf.append(scheduleMasterIsMakeCondition(getCurrentPath(req), masterId, from, to));
buf.append(scheduleMasterIsMake(getCurrentPath(req), masterIdDayMap));
buf.append("</body>");
buf.append("</html>");
}
}
resp.getWriter().println(buf.toString());
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processDependsResponse.
/**
* 依存しているスケジュール(先行スケジュール)の検索リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processDependsResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String id = getParameter(req, "id");
if (id == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'id' is null.");
return;
}
Exception exception = null;
List schedules = null;
try {
schedules = scheduleManager.findDependsSchedules(id);
} 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 {
resp.setContentType("text/html;charset=UTF-8");
if (exception != null) {
buf.append(exception(exception));
} else {
int[] states = null;
try {
states = getIntParameterValues(req, "state");
} catch (Exception e) {
}
buf.append("<html>");
buf.append(header(HEADER_OTHER));
buf.append("<body>");
try {
buf.append(schedules(req, schedules, states));
} catch (Exception e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter is illegal. " + e.getMessage());
return;
}
buf.append("</body>");
buf.append("</html>");
}
}
resp.getWriter().println(buf.toString());
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processRemoveResponse.
/**
* スケジュール削除リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processRemoveResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String[] id = getParameterValues(req, "id");
String masterId = getParameter(req, "masterId");
String masterGroupId = getParameter(req, "masterGroupId");
String groupId = getParameter(req, "groupId");
Date from = null;
try {
from = getDateParameter(req, "from", "yyyyMMddHHmmssSSS", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'from' is illegal." + e.toString());
return;
}
Date to = null;
try {
to = getDateParameter(req, "to", "yyyyMMddHHmmssSSS", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'to' is illegal." + e.toString());
return;
}
int[] states = null;
try {
states = getIntParameterValues(req, "state");
} catch (NumberFormatException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'state' is illegal." + e.toString());
return;
}
boolean isChanged = false;
Exception exception = null;
if (id != null) {
try {
for (int i = 0; i < id.length; i++) {
isChanged |= scheduleManager.removeSchedule(id[i]);
}
} catch (ScheduleManageException e) {
exception = e;
}
} else {
if (!isRemoveAllEnabled() && from == null && to == null && (states == null || states.length == 0) && masterId == null) {
resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
return;
}
try {
isChanged = scheduleManager.removeSchedule(from, to, states, masterId, masterGroupId, groupId);
} 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("result", isChanged ? Boolean.TRUE : Boolean.FALSE);
} 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 {
processScheduleResponse(req, resp, responseType);
return;
}
}
resp.getWriter().println(buf.toString());
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processChangeControlStateResponse.
/**
* スケジュール制御状態変更リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processChangeControlStateResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String[] id = getParameterValues(req, "id");
if (id == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'id' is null.");
return;
}
int[] oldState = getIntParameterValues(req, "oldState");
int[] newState = getIntParameterValues(req, "newState");
if (newState == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'newState' is null.");
return;
}
Map isChanged = new LinkedHashMap();
Exception exception = null;
try {
if (oldState == null) {
for (int i = 0; i < id.length; i++) {
if (scheduleManager.changeControlState(id[i], newState[i])) {
isChanged.put(id[i], Boolean.TRUE);
} else {
isChanged.put(id[i], Boolean.FALSE);
}
}
} else {
for (int i = 0; i < id.length; i++) {
if (scheduleManager.changeControlState(id[i], oldState[i], newState[i])) {
isChanged.put(id[i], Boolean.TRUE);
} else {
isChanged.put(id[i], Boolean.FALSE);
}
}
}
} 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) {
List result = new ArrayList();
Iterator entries = isChanged.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Map map = new HashMap(2);
map.put("id", entry.getKey());
map.put("result", entry.getValue());
result.add(map);
}
jsonMap.put("result", result);
} 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 {
processScheduleResponse(req, resp, responseType);
return;
}
}
resp.getWriter().println(buf.toString());
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processScheduleResponse.
/**
* スケジュール検索リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processScheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String id = getParameter(req, "search_id");
String groupId = getParameter(req, "search_groupId");
String masterId = getParameter(req, "search_masterId");
String masterGroupId = getParameter(req, "search_masterGroupId");
Date from = null;
try {
from = getDateParameter(req, "search_from", "yyyyMMddHHmmssSSS", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'search_from' is illegal." + e.toString());
return;
}
Date to = null;
try {
to = getDateParameter(req, "search_to", "yyyyMMddHHmmssSSS", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'search_to' is illegal." + e.toString());
return;
}
int[] states = null;
try {
states = getIntParameterValues(req, "search_state");
} catch (NumberFormatException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'search_state' is illegal." + e.toString());
return;
}
Exception exception = null;
List schedules = null;
if (id != null && id.length() != 0) {
try {
Schedule schedule = scheduleManager.findSchedule(id);
schedules = new ArrayList(1);
schedules.add(schedule);
} catch (ScheduleManageException e) {
exception = e;
}
} else {
final String action = getParameter(req, "action");
if (action == null && from == null && to == null && states == null && masterId == null && masterGroupId == null && groupId == null) {
states = new int[] { Schedule.STATE_INITIAL, Schedule.STATE_RETRY };
}
try {
schedules = scheduleManager.findSchedules(from, to, states, masterId, masterGroupId, groupId);
} 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 {
resp.setContentType("text/html;charset=UTF-8");
if (exception != null) {
buf.append(exception(exception));
} else {
buf.append("<html>");
buf.append(header(HEADER_SCHEDULE));
buf.append("<body>");
buf.append(scheduleSearchCondition(getCurrentPath(req), id, groupId, masterId, masterGroupId, from, to, states));
try {
buf.append(schedules(req, schedules, states));
} catch (Exception e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter is illegal. " + e.getMessage());
return;
}
buf.append("</body>");
buf.append("</html>");
}
}
resp.getWriter().println(buf.toString());
}
Aggregations