use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleServiceImpl method getScheduleListByTeacherId.
@Override
public Set<Schedule> getScheduleListByTeacherId(final long teacherId) throws ScheduleException {
final Set<Schedule> scheduleList = new HashSet<>();
try {
return new AsyncTask<String, Set<Schedule>, Set<Schedule>>() {
@Override
protected Set<Schedule> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("/").concat("1").concat("?teacherId=").concat(String.valueOf(teacherId));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
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;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
scheduleList.add(gson.fromJson(jsonArray.get(ctr).toString(), Schedule.class));
}
return scheduleList;
} else if (httpURLConnection.getResponseCode() == 404) {
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 scheduleList;
} else
throw new ScheduleException("Server Error");
} catch (ScheduleException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleDaoImpl method updateScheduleById.
@Override
public Schedule updateScheduleById(long id, Schedule newSchedule) throws ScheduleException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Schedule schedule = session.get(Schedule.class, id);
if (schedule == null)
throw new ScheduleDaoException("Schedule with id : " + id + " does not exist");
if (newSchedule == null)
throw new ScheduleDaoException("You tried to update student with a null value");
if (!(newSchedule.getDay() != null ? newSchedule.getDay() : "").trim().isEmpty())
schedule.setDay(newSchedule.getDay());
if (!(newSchedule.getRoom() != null ? newSchedule.getRoom() : "").trim().isEmpty())
schedule.setRoom(newSchedule.getRoom());
if (!(newSchedule.getTime() != null ? newSchedule.getTime() : "").trim().isEmpty()) {
if (!timeHelperBean.isValid(newSchedule.getTime().trim()))
throw new ScheduleDaoException("Schedule's time is invalid");
schedule.setTime(newSchedule.getTime());
}
if (!(newSchedule.getPeriod() != null ? newSchedule.getPeriod() : "").trim().isEmpty()) {
if (!timeHelperBean.isValid(newSchedule.getPeriod().trim()))
throw new ScheduleDaoException("Schedule's period is invalid");
schedule.setPeriod(newSchedule.getPeriod());
}
session.getTransaction().commit();
session.close();
return schedule;
} catch (ScheduleDaoException e) {
session.close();
throw new ScheduleException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleDaoImpl method getScheduleList.
@Override
public List<Schedule> getScheduleList() throws ScheduleException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Schedule> scheduleList = new ArrayList<>();
Query query = session.createQuery("from Schedule");
for (Object scheduleObj : query.list()) scheduleList.add((Schedule) scheduleObj);
session.getTransaction().commit();
session.close();
return scheduleList;
} catch (ScheduleDaoException e) {
session.close();
throw new ScheduleException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleDaoImpl method getScheduleById.
@Override
public Schedule getScheduleById(long id) throws ScheduleException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Schedule schedule = session.get(Schedule.class, id);
if (schedule == null)
throw new ScheduleDaoException("Schedule with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return schedule;
} catch (ScheduleDaoException e) {
session.close();
throw new ScheduleException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.
the class ScheduleDaoImpl method addSchedule.
@Override
public Schedule addSchedule(Schedule schedule) throws ScheduleException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
if (schedule == null)
throw new ScheduleDaoException("You tried to add schedule with a null value");
if (schedule.getDay() == null)
throw new ScheduleDaoException("Schedule's day is required");
if (schedule.getDay().trim().equals(""))
throw new ScheduleDaoException("Schedule can't have an empty day");
if (schedule.getTime() == null)
throw new ScheduleDaoException("Schedule's time is required");
if (schedule.getTime().trim().equals(""))
throw new ScheduleDaoException("Schedule can't have an empty time");
if (!timeHelperBean.isValid(schedule.getTime().trim()))
throw new ScheduleDaoException("Schedule's time is invalid");
if (schedule.getPeriod() == null)
throw new ScheduleDaoException("Schedule's period is required");
if (schedule.getPeriod().trim().equals(""))
throw new ScheduleDaoException("Schedule can't have an empty period");
if (!timeHelperBean.isValid(schedule.getPeriod().trim()))
throw new ScheduleDaoException("Schedule's period is invalid");
session.save(schedule);
session.getTransaction().commit();
session.close();
return schedule;
} catch (ScheduleDaoException e) {
session.close();
throw new ScheduleException(e.getMessage());
}
}
Aggregations