use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleServiceImpl method updateScheduleById.
@Override
public Schedule updateScheduleById(long id, Schedule newSchedule) throws ScheduleException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(id);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.put(Entity.json(newSchedule));
if (response.getStatus() == 200) {
return (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new ScheduleServiceException(message.getMessage());
} else
throw new ScheduleServiceException("The request might invalid or server is down");
} catch (ScheduleServiceException e) {
throw new ScheduleException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleController method updateScheduleOnClass.
@RequestMapping(value = "c/update", method = RequestMethod.POST)
public String updateScheduleOnClass(@RequestParam("day") String day, @RequestParam("room") String room, @RequestParam("time") String time, @RequestParam("period") String period, @RequestParam("classId") long classId, @RequestParam("scheduleId") long scheduleId, ModelMap modelMap) {
try {
Schedule schedule = new Schedule();
schedule.setDay(day);
schedule.setTime(time);
schedule.setPeriod(period);
schedule.setRoom(room);
schedule = scheduleService.updateScheduleById(scheduleId, schedule);
Set<Schedule> scheduleList = classService.getScheduleList(classId);
modelMap.put("scheduleList", scheduleList);
} catch (ScheduleException | ClassException e) {
e.printStackTrace();
}
return "schedule";
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleController method addScheduleOnClass.
@RequestMapping(value = "c/add", method = RequestMethod.POST)
public String addScheduleOnClass(@RequestParam("day") String day, @RequestParam("room") String room, @RequestParam("time") String time, @RequestParam("period") String period, @RequestParam("classId") long classId, ModelMap modelMap) {
try {
Schedule schedule = new Schedule();
schedule.setDay(day);
schedule.setTime(time);
schedule.setPeriod(period);
schedule.setRoom(room);
schedule = scheduleService.addSchedule(schedule);
classService.addScheduleById(classId, schedule.getId());
Set<Schedule> scheduleList = classService.getScheduleList(classId);
modelMap.put("scheduleList", scheduleList);
} catch (ScheduleException | ClassException e) {
e.printStackTrace();
}
return "schedule";
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleController method addSchedule.
@RequestMapping(value = "add", method = RequestMethod.POST)
public String addSchedule(@RequestParam("day") String day, @RequestParam("room") String room, @RequestParam("time") String time, @RequestParam("period") String period, ModelMap modelMap) {
try {
System.out.println("day : " + day);
System.out.println("room : " + room);
System.out.println("time : " + time);
System.out.println("period : " + period);
Schedule schedule = new Schedule();
schedule.setDay(day);
schedule.setTime(time);
schedule.setPeriod(period);
schedule.setRoom(room);
schedule = scheduleService.addSchedule(schedule);
modelMap.put("schedule", schedule);
} catch (ScheduleException e) {
e.printStackTrace();
}
return "schedule-add";
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleServiceImpl method deleteScheduleById.
@Override
public Schedule deleteScheduleById(final long id) throws ScheduleException {
try {
return new AsyncTask<String, Schedule, Schedule>() {
@Override
protected Schedule doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat(String.valueOf(id));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("DELETE");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
return gson.fromJson(jsonData, Schedule.class);
} else if (httpURLConnection.getResponseCode() == 400) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Schedule");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return null;
} else
throw new ScheduleException("Server Error");
} catch (ScheduleException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
Aggregations