use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.
the class ClassServiceImpl method getScheduleList.
@Override
public Set<Schedule> getScheduleList(final long classId) throws ClassException {
final Set<Schedule> scheduleSet = 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(String.valueOf(classId)).concat("/").concat("schedule");
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++) {
scheduleSet.add(gson.fromJson(jsonArray.get(ctr).toString(), Schedule.class));
}
return scheduleSet;
} 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 : Class");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return scheduleSet;
} else
throw new ClassException("Server Error");
} catch (ClassException 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.model.Schedule 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.model.Schedule 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.model.Schedule 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.model.Schedule in project classify-system by anverliedoit.
the class ScheduleResource method deleteScheduleById.
@DELETE
@Path("{scheduleId}")
public Response deleteScheduleById(@PathParam("scheduleId") long id) {
try {
ScheduleResourceLinks resourceLinks = new ScheduleResourceLinks(uriInfo);
Schedule schedule = scheduleService.deleteScheduleById(id);
schedule.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(schedule).build();
} catch (ScheduleException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
Aggregations